diff --git a/Source/Modules/FileHandlers/LMConsolidator.h b/Source/Modules/FileHandlers/LMConsolidator.h index e8050175..1007c92b 100644 --- a/Source/Modules/FileHandlers/LMConsolidator.h +++ b/Source/Modules/FileHandlers/LMConsolidator.h @@ -35,6 +35,7 @@ namespace vChewing { class LMConsolidator { public: + static bool CheckPragma(const char *path); static bool FixEOF(const char *path); static bool ConsolidateContent(const char *path, bool shouldsort); }; diff --git a/Source/Modules/FileHandlers/LMConsolidator.mm b/Source/Modules/FileHandlers/LMConsolidator.mm index 1e90e70f..f3d5e223 100644 --- a/Source/Modules/FileHandlers/LMConsolidator.mm +++ b/Source/Modules/FileHandlers/LMConsolidator.mm @@ -20,6 +20,27 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH namespace vChewing { +constexpr std::string_view FORMATTED_PRAGMA_HEADER + = "# π™΅π™Ύπšπ™Όπ™°πšƒ πš˜πš›πš.πšŠπšπšŽπš•πš’πšŽπš›π™Έπš—πš–πšž.πšŸπšŒπš‘πšŽπš πš’πš—πš.πšžπšœπšŽπš›π™»πšŠπš—πšπšžπšŠπšπšŽπ™Όπš˜πšπšŽπš•π™³πšŠπšπšŠ.πšπš˜πš›πš–πšŠπšπšπšŽπš"; + +// HEADER VERIFIER. CREDIT: Shiki Suen +bool LMConsolidator::CheckPragma(const char *path) +{ + ifstream zfdCheckPragma(path); + if (zfdCheckPragma.good()) + { + string firstLine; + getline(zfdCheckPragma, firstLine); + syslog(LOG_CONS, "HEADER SEEN ||%s", firstLine.c_str()); + if (firstLine != FORMATTED_PRAGMA_HEADER) { + syslog(LOG_CONS, "HEADER VERIFICATION FAILED. START IN-PLACE CONSOLIDATING PROCESS."); + return false; + } + } + syslog(LOG_CONS, "HEADER VERIFICATION SUCCESSFUL."); + return true; +} + // EOF FIXER. CREDIT: Shiki Suen. bool LMConsolidator::FixEOF(const char *path) { @@ -51,6 +72,10 @@ bool LMConsolidator::FixEOF(const char *path) // CONTENT CONSOLIDATOR. CREDIT: Shiki Suen. bool LMConsolidator::ConsolidateContent(const char *path, bool shouldsort) { + if (LMConsolidator::CheckPragma(path) && !shouldsort){ + return true; + } + ifstream zfdContentConsolidatorIncomingStream(path); vectorvecEntry; while(!zfdContentConsolidatorIncomingStream.eof())