diff --git a/Source/CLI/CLI_Help.cpp b/Source/CLI/CLI_Help.cpp index b7c256d8..dd4d2339 100644 --- a/Source/CLI/CLI_Help.cpp +++ b/Source/CLI/CLI_Help.cpp @@ -173,6 +173,11 @@ std::string Help() ToDisplay<<"--MD5-Verify Verify MD5 for audio data"<second.In_cue__XML=In_cue__XML; Handler->second.In_cue__FileName=In_cue__FileName; Handler->second.In_CSET_Remove=In_CSET_Remove; + Handler->second.In_Chunks_Remove= Handler_Default.In_Chunks_Remove; //Settings - Adding default Core values if the Core value does not exist yet (from --xxx=) for (map::iterator In_Core_Item=Handler_Default.In_Core.begin(); In_Core_Item!=Handler_Default.In_Core.end(); In_Core_Item++) @@ -384,6 +385,12 @@ float Core::Menu_File_Open_Files_Finish_Middle () bool IsModified_Old=Handler->second.Riff->IsModified_Get(); + for (size_t Pos=0; Possecond.In_Chunks_Remove.size(); Pos++) + { + Handler->second.Riff->Remove_Chunk(Handler->second.In_Chunks_Remove[Pos].To_UTF8()); + StdAll(Handler); + } + //Modifying file with --xxx values if (!Handler->second.In_Core.empty()) { @@ -1281,6 +1288,12 @@ bool Core::In_Core_Add (const string &Field, const string &Value) return true; } +//--------------------------------------------------------------------------- +bool Core::In_Chunk_Remove(const string &Field) +{ + Handler_Default.In_Chunks_Remove.push_back(Ztring().From_UTF8(Field)); + 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 c3143833..bcd2084a 100644 --- a/Source/Common/Core.h +++ b/Source/Common/Core.h @@ -107,6 +107,7 @@ class Core : public Thread void Batch_Launch_End (); //Detailed version 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); string Out_Core_Read (const string &FileName, const string &Field); //Configuration @@ -199,6 +200,7 @@ class Core : public Thread bool In_cue__XML; string In_cue__FileName; bool In_CSET_Remove; + ZtringList In_Chunks_Remove; handler() { diff --git a/Source/Riff/Riff_Base.cpp b/Source/Riff/Riff_Base.cpp index 80ad6443..10d62e19 100644 --- a/Source/Riff/Riff_Base.cpp +++ b/Source/Riff/Riff_Base.cpp @@ -19,6 +19,7 @@ #ifdef MACSTORE #include "Common/Mac_Helpers.h" #include "ZenLib/Dir.h" +#include "Riff_Base.h" #endif using namespace std; @@ -273,6 +274,9 @@ void Riff_Base::Modify (int32u Chunk_Name_1, int32u Chunk_Name_2, int32u Chunk_N //--------------------------------------------------------------------------- void Riff_Base::Modify_Internal_Subs (int32u Chunk_Name_1, int32u Chunk_Name_2, int32u Chunk_Name_3) { + if (Chunk.Content.IsRemovable) + return; + //Special case: multiples chunks if (Global->adtl && (Chunk_Name_1==Elements::WAVE_adtl_labl || Chunk_Name_1==Elements::WAVE_adtl_note diff --git a/Source/Riff/Riff_Base.h b/Source/Riff/Riff_Base.h index 20ccc29b..adcad975 100644 --- a/Source/Riff/Riff_Base.h +++ b/Source/Riff/Riff_Base.h @@ -560,7 +560,7 @@ protected : //--------------------------------------------------------------------------- //Read/Write virtual void Read_Internal (); - virtual void Modify_Internal () {} + virtual void Modify_Internal () {}; virtual size_t Insert_Internal (int32u) {return Subs.size();} virtual void Write_Internal () ; void Write_Internal (const int8u* Buffer, size_t Buffer_Size); diff --git a/Source/Riff/Riff_Chunks_WAVE_CSET.cpp b/Source/Riff/Riff_Chunks_WAVE_CSET.cpp index 592acd7f..fbc3abfe 100644 --- a/Source/Riff/Riff_Chunks_WAVE_CSET.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_CSET.cpp @@ -48,6 +48,9 @@ void Riff_WAVE_CSET::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_CSET::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (!Global->CSET) { Chunk.Content.IsRemovable=true; diff --git a/Source/Riff/Riff_Chunks_WAVE_INFO_xxxx.cpp b/Source/Riff/Riff_Chunks_WAVE_INFO_xxxx.cpp index b82b4f47..da819f09 100644 --- a/Source/Riff/Riff_Chunks_WAVE_INFO_xxxx.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_INFO_xxxx.cpp @@ -97,6 +97,9 @@ void Riff_WAVE_INFO_xxxx::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_INFO_xxxx::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + string Field=Ztring().From_CC4(Chunk.Header.Name).MakeUpperCase().To_UTF8(); if (Global->INFO->Strings[Field].empty()) { diff --git a/Source/Riff/Riff_Chunks_WAVE_MD5_.cpp b/Source/Riff/Riff_Chunks_WAVE_MD5_.cpp index 5b388864..4c8007d5 100644 --- a/Source/Riff/Riff_Chunks_WAVE_MD5_.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_MD5_.cpp @@ -43,6 +43,9 @@ void Riff_WAVE_MD5_::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_MD5_::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (!Global->EmbedMD5_AuthorizeOverWritting && !(Global->MD5Stored && !Global->MD5Stored->Strings["md5stored"].empty())) return; //Should never happen (test in Riff_Handler), but in case of. diff --git a/Source/Riff/Riff_Chunks_WAVE__PMX.cpp b/Source/Riff/Riff_Chunks_WAVE__PMX.cpp index e538f91e..d27da7c7 100644 --- a/Source/Riff/Riff_Chunks_WAVE__PMX.cpp +++ b/Source/Riff/Riff_Chunks_WAVE__PMX.cpp @@ -39,6 +39,9 @@ void Riff_WAVE__PMX::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE__PMX::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (Global->XMP==NULL || Global->XMP->Strings["xmp"].empty()) { diff --git a/Source/Riff/Riff_Chunks_WAVE_aXML.cpp b/Source/Riff/Riff_Chunks_WAVE_aXML.cpp index 56e0cf6f..41f86b8f 100644 --- a/Source/Riff/Riff_Chunks_WAVE_aXML.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_aXML.cpp @@ -39,6 +39,9 @@ void Riff_WAVE_axml::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_axml::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (Global->aXML==NULL || Global->aXML->Strings["axml"].empty()) { diff --git a/Source/Riff/Riff_Chunks_WAVE_adtl_labl.cpp b/Source/Riff/Riff_Chunks_WAVE_adtl_labl.cpp index 7c92570a..0d765d11 100644 --- a/Source/Riff/Riff_Chunks_WAVE_adtl_labl.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_adtl_labl.cpp @@ -45,6 +45,9 @@ void Riff_WAVE_adtl_labl::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_adtl_labl::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (!Global->adtl || Global->adtl->labels.empty() || Global->adtl->labelsIndex>=Global->adtl->labels.size()) { Chunk.Content.IsRemovable=true; diff --git a/Source/Riff/Riff_Chunks_WAVE_adtl_ltxt.cpp b/Source/Riff/Riff_Chunks_WAVE_adtl_ltxt.cpp index 458f3289..9495e573 100644 --- a/Source/Riff/Riff_Chunks_WAVE_adtl_ltxt.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_adtl_ltxt.cpp @@ -51,6 +51,9 @@ void Riff_WAVE_adtl_ltxt::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_adtl_ltxt::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (!Global->adtl || Global->adtl->texts.empty() || Global->adtl->textsIndex>=Global->adtl->texts.size()) { Chunk.Content.IsRemovable=true; diff --git a/Source/Riff/Riff_Chunks_WAVE_adtl_note.cpp b/Source/Riff/Riff_Chunks_WAVE_adtl_note.cpp index 63442e94..cab63088 100644 --- a/Source/Riff/Riff_Chunks_WAVE_adtl_note.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_adtl_note.cpp @@ -44,6 +44,9 @@ void Riff_WAVE_adtl_note::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_adtl_note::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (!Global->adtl || Global->adtl->notes.empty() || Global->adtl->notesIndex>=Global->adtl->notes.size()) { Chunk.Content.IsRemovable=true; diff --git a/Source/Riff/Riff_Chunks_WAVE_bext.cpp b/Source/Riff/Riff_Chunks_WAVE_bext.cpp index 2bc20cb5..84fff92c 100644 --- a/Source/Riff/Riff_Chunks_WAVE_bext.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_bext.cpp @@ -237,6 +237,9 @@ void Riff_WAVE_bext::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_bext::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (Global->bext==NULL || (Global->bext->Strings["description"].empty() && Global->bext->Strings["originator"].empty() diff --git a/Source/Riff/Riff_Chunks_WAVE_cue_.cpp b/Source/Riff/Riff_Chunks_WAVE_cue_.cpp index bef7b28a..e615be34 100644 --- a/Source/Riff/Riff_Chunks_WAVE_cue_.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_cue_.cpp @@ -70,6 +70,9 @@ void Riff_WAVE_cue_::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_cue_::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (Global->cue_==NULL || Global->cue_->points.empty()) { Chunk.Content.IsRemovable=true; diff --git a/Source/Riff/Riff_Chunks_WAVE_iXML.cpp b/Source/Riff/Riff_Chunks_WAVE_iXML.cpp index fb906dd3..403efa21 100644 --- a/Source/Riff/Riff_Chunks_WAVE_iXML.cpp +++ b/Source/Riff/Riff_Chunks_WAVE_iXML.cpp @@ -39,6 +39,9 @@ void Riff_WAVE_iXML::Read_Internal () //--------------------------------------------------------------------------- void Riff_WAVE_iXML::Modify_Internal () { + if (Chunk.Content.IsRemovable) + return; + if (Global->iXML==NULL || Global->iXML->Strings["ixml"].empty()) { diff --git a/Source/Riff/Riff_Handler.cpp b/Source/Riff/Riff_Handler.cpp index 4d3cb234..04959521 100644 --- a/Source/Riff/Riff_Handler.cpp +++ b/Source/Riff/Riff_Handler.cpp @@ -1509,6 +1509,14 @@ bool Riff_Handler::Remove(const string &Field) return Remove_Internal(Field); } +//--------------------------------------------------------------------------- +bool Riff_Handler::Remove_Chunk(const string &Field) +{ + CriticalSectionLocker CSL(CS); + + return Remove_Chunk_Internal(Field); +} + //--------------------------------------------------------------------------- bool Riff_Handler::Remove_Internal(const string &Field) { @@ -1564,6 +1572,74 @@ bool Riff_Handler::Remove_Internal(const string &Field) return Set(Field, string(), *Chunk_Strings, Chunk_Name2_Get(Field), Chunk_Name3_Get(Field)); } +//--------------------------------------------------------------------------- +bool Riff_Handler::Remove_Chunk_Helper(Riff_Base* Parent, const string& Path, vector& ParentsCC4) +{ + if (!Parent || Path.empty()) + return false; + + size_t Separator=Path.find_first_of('/'); + string Field=Path.substr(0, Separator); + + if (Field.empty()) // handle duplicate slashes + return Remove_Chunk_Helper(Parent, Path.substr(Separator+1), ParentsCC4); + + if (Field.size()!=4) + { + Errors<<"Invalid chunk identifier: "<Subs.size(); Pos++) + { + if (Parent->Subs[Pos]->Header_Name_Get()==CC4) + { + if (Separator==string::npos) + { + Parent->Subs[Pos]->Chunk.Content.IsRemovable=true; + } + else + { + if (!Remove_Chunk_Helper(Parent->Subs[Pos], Path.substr(Separator+1), ParentsCC4)) + return false; + } + } + } + + return true; +} + +//--------------------------------------------------------------------------- +bool Riff_Handler::Remove_Chunk_Internal(const string &Field) +{ + //Integrity + if (Chunks==NULL) + { + Errors<<"(No file name): Internal error"< CC4; + bool ToReturn=Remove_Chunk_Helper(Chunks, "WAVE/" + Field, CC4); + Chunks->Modify(CC4.size()>0?CC4[0]:NULL, CC4.size()>1?CC4[1]:NULL, CC4.size()>2?CC4[2]:NULL); + + return ToReturn; +} + //--------------------------------------------------------------------------- bool Riff_Handler::IsModified(const string &Field) { diff --git a/Source/Riff/Riff_Handler.h b/Source/Riff/Riff_Handler.h index f17fef03..c9f43057 100644 --- a/Source/Riff/Riff_Handler.h +++ b/Source/Riff/Riff_Handler.h @@ -96,6 +96,7 @@ class Riff_Handler string Get (const string &Field); bool Set (const string &Field, const string &Value, rules Rules); bool Remove (const string &Field); + bool Remove_Chunk (const string &Field); string History (const string &Field); bool IsOriginal (const string &Field, const string &Value); bool IsValid (const string &Field, const string &Value, rules Rules, bool IgnoreCoherency=false); @@ -163,6 +164,8 @@ class Riff_Handler string Get_Internal (const string &Field); bool Set_Internal (const string &Field, const string &Value, rules Rules); bool Remove_Internal (const string &Field); + bool Remove_Chunk_Helper (Riff_Base *Parent, const string &Path, vector& ParentsCC4); + bool Remove_Chunk_Internal (const string &Field); bool IsValid_Internal (const string &Field, const string &Value, rules Rules, bool IgnoreCoherency=false); bool IsOriginal_Internal (const string &Field, const string &Value); bool IsModified_Internal (const string &Field);