#include #include #include #include #include #include #include using namespace std; void ConsoleAndLogfileOuput(std::string_view, bool); std::list ReadFileIntoList_ls(const std::string&); void CopyFileToDestinationQt(const std::string&, const std::string&); void MergeSegmentUniqueIdentifierLine(const std::vector&, const std::list&, const std::list&); std::list::iterator MergeSegmentIdentifierInTheMiddle_lsit( std::list::iterator, const std::string&, const std::string&, const std::string&, const std::list&); void OfstreamToDestination(const std::list&, const std::string&); std::list::iterator PartialMergeIdentifierInTheMiddle_lsit( std::list::iterator UppDelim_mit2, std::string UppDelim_s, std::string Identifier_s, std::string LowDelim_s, std::list& InstallationFile_ils2) { auto Identifier_mit = UppDelim_mit2; for (Identifier_mit++; (*Identifier_mit).find(Identifier_s) == std::string::npos; Identifier_mit++) { } auto Identifier_riit = std::find_if( InstallationFile_ils2.rbegin(), InstallationFile_ils2.rend(), [&Identifier_mit](const std::string& str) { return str.find(*Identifier_mit) != std::string::npos; }); if (Identifier_riit != InstallationFile_ils2.rend()) { auto Identifier_iit = std::prev(Identifier_riit.base()); auto UppDelimStart_iit = Identifier_iit; for (UppDelimStart_iit--; (*UppDelimStart_iit).find(UppDelim_s) == std::string::npos; UppDelimStart_iit--) { } for (UppDelim_mit2++; (*UppDelim_mit2).find(LowDelim_s) == std::string::npos; UppDelim_mit2++) { std::string LineIdentifier_s = *UppDelim_mit2; unsigned long long FirstAlphanumericPos = LineIdentifier_s.find_first_not_of(" \t\r\v\n"); unsigned long long DelimeterPos = LineIdentifier_s.find("="); LineIdentifier_s = LineIdentifier_s.substr( FirstAlphanumericPos, DelimeterPos - FirstAlphanumericPos + 1); auto UppDelim_iit = UppDelimStart_iit; for (UppDelim_iit++; (*UppDelim_iit).find(LowDelim_s) == std::string::npos; UppDelim_iit++) { if ((*UppDelim_iit).find(LineIdentifier_s) != std::string::npos) { *UppDelim_iit = *UppDelim_mit2; break; } } } return UppDelim_mit2; } for (; (*UppDelim_mit2).find(LowDelim_s) == std::string::npos; UppDelim_mit2++) { } return UppDelim_mit2; } int MergeFileCreatureinfo(const std::string& MergeFilePath, const std::string& InstallationFilePath, const std::string& FileName) { ConsoleAndLogfileOuput( ">"s + FileName + "< ... is being scanned right now. ", false); std::list MergeFile_mls = ReadFileIntoList_ls(MergeFilePath); std::list InstallationFile_ils = ReadFileIntoList_ls(InstallationFilePath); if (InstallationFile_ils.size() == 0) { QString InstallationFilePathQt = QString::fromStdString(InstallationFilePath); QDir("").mkpath(QFileInfo(InstallationFilePathQt).absolutePath()); CopyFileToDestinationQt(MergeFilePath, InstallationFilePath); ConsoleAndLogfileOuput( "Base File hasnt been found. The full file has been copied over.", true); return 0; } std::vector Keywords_v = {"SMT_DEFAULT =", "SMT_HERO ="}; MergeSegmentUniqueIdentifierLine(Keywords_v, MergeFile_mls, InstallationFile_ils); for (auto UppDelim_mit = MergeFile_mls.begin(); UppDelim_mit != MergeFile_mls.end(); UppDelim_mit++) { if ((*UppDelim_mit).find("newCreatureInfo =") != std::string::npos) { if ((*UppDelim_mit).find("MODMERGE = \"partial replace\"") != std::string::npos) { // Insert PartialMergeIdentifierInTheMiddle_lsit() continue; } UppDelim_mit = MergeSegmentIdentifierInTheMiddle_lsit( UppDelim_mit, "newCreatureInfo =", "type =", "mgr.creatureInfoCreate(", InstallationFile_ils); } } OfstreamToDestination(InstallationFile_ils, InstallationFilePath); ConsoleAndLogfileOuput( ">" + FileName + "< has been scanned and merged for elements found.", true); return 0; }