From cf5ffa4c75051f70738d05679d303f49edd808c8 Mon Sep 17 00:00:00 2001 From: Maxime Gervais Date: Fri, 25 Oct 2024 00:56:58 +0200 Subject: [PATCH] CLI: Add ability to append values to text fields with += Signed-off-by: Maxime Gervais --- Source/CLI/CLI_Help.cpp | 6 +- Source/CLI/CommandLine_Parser.cpp | 13 ++++- Source/Common/Core.cpp | 91 ++++++++++++++++++++++++++++++- Source/Common/Core.h | 3 + 4 files changed, 104 insertions(+), 9 deletions(-) diff --git a/Source/CLI/CLI_Help.cpp b/Source/CLI/CLI_Help.cpp index dd4d2339..9c0b8609 100644 --- a/Source/CLI/CLI_Help.cpp +++ b/Source/CLI/CLI_Help.cpp @@ -121,9 +121,9 @@ std::string Help() ToDisplay<<"--MaxMomentaryLoudness= specified bext max mnomentary loudness"<second.In_Core.end()) Handler->second.In_Core[Ztring().From_UTF8(In_Core_Item->first).MakeLowerCase().To_UTF8()]=In_Core_Item->second; } - + + for (map::iterator In_Core_Item=Handler_Default.In_Core_Append.begin(); In_Core_Item!=Handler_Default.In_Core_Append.end(); In_Core_Item++) + { + map::iterator Handler_in_Core_Item=Handler->second.In_Core_Append.find(Ztring().From_UTF8(In_Core_Item->first).MakeLowerCase().To_UTF8()); + if (Handler_in_Core_Item==Handler->second.In_Core_Append.end()) + Handler->second.In_Core_Append[Ztring().From_UTF8(In_Core_Item->first).MakeLowerCase().To_UTF8()]=In_Core_Item->second; + } + //Special Characters if (SpecialChars_Enabled) { @@ -359,6 +366,16 @@ float Core::Menu_File_Open_Files_Finish_Middle () Field->second.FindAndReplace(__T("\\0"), __T("\0"), 0, Ztring_Recursive); Field->second.FindAndReplace(__T("|SC1|"), __T("\\"), 0, Ztring_Recursive); } + + for (map::iterator Field=Handler->second.In_Core_Append.begin(); Field!=Handler->second.In_Core_Append.end(); Field++) + { + Field->second.FindAndReplace(__T("\\\\"), __T("|SC1|"), 0, Ztring_Recursive); + Field->second.FindAndReplace(__T("\\r"), __T("\r"), 0, Ztring_Recursive); + Field->second.FindAndReplace(__T("\\n"), __T("\n"), 0, Ztring_Recursive); + Field->second.FindAndReplace(__T("\\t"), __T("\t"), 0, Ztring_Recursive); + Field->second.FindAndReplace(__T("\\0"), __T("\0"), 0, Ztring_Recursive); + Field->second.FindAndReplace(__T("|SC1|"), __T("\\"), 0, Ztring_Recursive); + } } //Reading @@ -392,13 +409,20 @@ float Core::Menu_File_Open_Files_Finish_Middle () } //Modifying file with --xxx values - if (!Handler->second.In_Core.empty()) + if (!Handler->second.In_Core.empty() || !Handler->second.In_Core_Append.empty()) { for (map::iterator In_Core_Item=Handler->second.In_Core.begin(); In_Core_Item!=Handler->second.In_Core.end(); In_Core_Item++) { Handler->second.Riff->Set(In_Core_Item->first, In_Core_Item->second.To_UTF8(), Rules); StdAll(Handler); } + + for (map::iterator In_Core_Item=Handler->second.In_Core_Append.begin(); In_Core_Item!=Handler->second.In_Core_Append.end(); In_Core_Item++) + { + string Value=Handler->second.Riff->Get(In_Core_Item->first); + Handler->second.Riff->Set(In_Core_Item->first, Value + In_Core_Item->second.To_UTF8(), Rules); + StdAll(Handler); + } } else if (Handler->second.In_Core_Remove) { @@ -1262,7 +1286,13 @@ bool Core::In_Core_Add (const string &FileName, const string &Field, const strin return true; if (File::Exists(Ztring().From_UTF8(FileName))) + { + map::iterator ToErase=Handlers[FileName].In_Core_Append.find(Field); + if (ToErase!=Handlers[FileName].In_Core_Append.end()) + Handlers[FileName].In_Core_Append.erase(ToErase); + Handlers[FileName].In_Core[Field]=Ztring().From_UTF8(Value); + } else { //Handling wildcards @@ -1271,7 +1301,13 @@ bool Core::In_Core_Add (const string &FileName, const string &Field, const strin List.push_back(Ztring().From_UTF8(FileName)); for (size_t Pos=0; Pos::iterator ToErase=Handlers[List[Pos].To_UTF8()].In_Core_Append.find(Field); + if (ToErase!=Handlers[List[Pos].To_UTF8()].In_Core_Append.end()) + Handlers[FileName].In_Core_Append.erase(ToErase); + Handlers[List[Pos].To_UTF8()].In_Core[Field]=Ztring().From_UTF8(Value); + } } return true; @@ -1282,7 +1318,11 @@ bool Core::In_Core_Add (const string &Field, const string &Value) { if (Value=="NOCHANGE") return true; - + + map::iterator ToErase=Handler_Default.In_Core_Append.find(Field); + if (ToErase!=Handler_Default.In_Core_Append.end()) + Handler_Default.In_Core_Append.erase(ToErase); + Handler_Default.In_Core[Field]=Ztring().From_UTF8(Value); return true; @@ -1294,6 +1334,51 @@ bool Core::In_Chunk_Remove(const string &Field) Handler_Default.In_Chunks_Remove.push_back(Ztring().From_UTF8(Field)); return true; } + +//--------------------------------------------------------------------------- +bool Core::In_Core_Append(const string &FileName, const string &Field, const string &Value) +{ + if (Value=="NOCHANGE") + return true; + + if (File::Exists(Ztring().From_UTF8(FileName))) + { + map::iterator ToErase=Handlers[FileName].In_Core.find(Field); + if (ToErase!=Handlers[FileName].In_Core.end()) + Handlers[FileName].In_Core.erase(ToErase); + + Handlers[FileName].In_Core_Append[Field]=Ztring().From_UTF8(Value); + } + else + { + //Handling wildcards + ZtringList List=Dir::GetAllFileNames(Ztring().From_UTF8(FileName)); + if (List.empty()) + List.push_back(Ztring().From_UTF8(FileName)); + + for (size_t Pos=0; Pos::iterator ToErase=Handlers[List[Pos].To_UTF8()].In_Core.find(Field); + if (ToErase!=Handlers[List[Pos].To_UTF8()].In_Core.end()) + Handlers[FileName].In_Core.erase(ToErase); + Handlers[List[Pos].To_UTF8()].In_Core_Append[Field]=Ztring().From_UTF8(Value); + } + } + + return true; +} + +//--------------------------------------------------------------------------- +bool Core::In_Core_Append(const string &Field, const string &Value) +{ + map::iterator ToErase=Handler_Default.In_Core.find(Field); + if (ToErase!=Handler_Default.In_Core.end()) + Handler_Default.In_Core.erase(ToErase); + + Handler_Default.In_Core_Append[Field]=Ztring().From_UTF8(Value); + + return true; +} //--------------------------------------------------------------------------- string Core::Out_Core_Read (const string &FileName, const string &Field) { diff --git a/Source/Common/Core.h b/Source/Common/Core.h index bcd2084a..3a6bc263 100644 --- a/Source/Common/Core.h +++ b/Source/Common/Core.h @@ -108,6 +108,8 @@ class Core : public Thread bool In_Core_Add (const string &FileName, const string &Field, const string &Value); bool In_Core_Add (const string &Field, const string &Value); bool In_Chunk_Remove (const string &Field); + bool In_Core_Append (const string &FileName, const string &Field, const string &Value); + bool In_Core_Append (const string &Field, const string &Value); string Out_Core_Read (const string &FileName, const string &Field); //Configuration @@ -186,6 +188,7 @@ class Core : public Thread { Riff_Handler *Riff; map In_Core; + map In_Core_Append; bool In_Core_Remove; bool In__PMX_Remove; bool In__PMX_XML;