From 2b60d2b87ee2914242c7d376de4729183b162ecf Mon Sep 17 00:00:00 2001 From: Person Date: Mon, 30 Nov 2020 19:32:02 -0800 Subject: [PATCH] --Bug fixes -Remove illegal characters from filenames. --- Data/examples/tyrantwave_base_forms.flame | 6 +++--- Source/EmberCommon/EmberCommon.h | 20 ++++++++++++++++++-- Source/Fractorium/FractoriumMenus.cpp | 8 +++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Data/examples/tyrantwave_base_forms.flame b/Data/examples/tyrantwave_base_forms.flame index 6a795a6..5c84d44 100644 --- a/Data/examples/tyrantwave_base_forms.flame +++ b/Data/examples/tyrantwave_base_forms.flame @@ -276,7 +276,7 @@ 6E19308C2842863556994868B94C5FB1687C5E9EB7A29A98 - + @@ -392,7 +392,7 @@ 6E19308C2842863556994868B94C5FB1687C5E9EB7A29A98 - + @@ -436,7 +436,7 @@ FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - + diff --git a/Source/EmberCommon/EmberCommon.h b/Source/EmberCommon/EmberCommon.h index 2b3f523..c5418a1 100644 --- a/Source/EmberCommon/EmberCommon.h +++ b/Source/EmberCommon/EmberCommon.h @@ -309,6 +309,22 @@ static void Rgba32ToRgba32Exr(v4F* rgba, float* r, float* g, float* b, float* a, } } +/// +/// Returns a string with all illegal file path characters removed. +/// +/// The path to remove illegal characters from +/// The cleaned full file path and name. +static string CleanPath(const string& filename) +{ + static string illegalChars = "\\/:*?\"<>|"; + auto tempfilename = filename; + + for (auto& ch : illegalChars) + tempfilename.erase(remove(tempfilename.begin(), tempfilename.end(), ch), tempfilename.end()); + + return tempfilename; +} + /// /// Make a filename for a single render. This is used in EmberRender. /// @@ -340,7 +356,7 @@ static string MakeSingleFilename(const string& path, const string& out, const st filename = fnstream.str(); } - return filename; + return CleanPath(filename); } /// @@ -356,7 +372,7 @@ static string MakeAnimFilename(const string& path, const string& prefix, const s { ostringstream fnstream; fnstream << path << prefix << setfill('0') << setprecision(0) << fixed << setw(padding) << ftime << suffix << format; - return fnstream.str(); + return CleanPath(fnstream.str()); } /// diff --git a/Source/Fractorium/FractoriumMenus.cpp b/Source/Fractorium/FractoriumMenus.cpp index bdc15fd..bfe8907 100644 --- a/Source/Fractorium/FractoriumMenus.cpp +++ b/Source/Fractorium/FractoriumMenus.cpp @@ -85,7 +85,7 @@ void FractoriumEmberController::NewFlock(size_t count) m_SheepTools->Random(ember, *filteredVariationsRef, static_cast(QTIsaac::LockedFrand(-2, 2)), 0, 8); ParamsToEmber(ember); ember.m_Index = i; - ember.m_Name = m_EmberFile.m_Filename.toStdString() + "_" + ToString(i + 1ULL).toStdString(); + ember.m_Name = CleanPath(m_EmberFile.m_Filename.toStdString() + "_" + ToString(i + 1ULL).toStdString()); m_EmberFile.m_Embers.push_back(ember); } @@ -311,6 +311,8 @@ void FractoriumEmberController::OpenAndPrepFiles(const QStringList& filenames //Also ensure it has a name. if (embers[i].m_Name == "" || embers[i].m_Name == "No name") embers[i].m_Name = ToString(i).toStdString(); + else + embers[i].m_Name = CleanPath(embers[i].m_Name); embers[i].m_Quality = m_Fractorium->m_QualitySpin->value(); embers[i].m_Supersample = m_Fractorium->m_SupersampleSpin->value(); @@ -710,6 +712,8 @@ void FractoriumEmberController::PasteXmlAppend() //Also ensure it has a name. if (embers[i].m_Name == "" || embers[i].m_Name == "No name") embers[i].m_Name = ToString(embers[i].m_Index).toStdString(); + else + embers[i].m_Name = CleanPath(embers[i].m_Name); m_EmberFile.m_Embers.push_back(embers[i]);//Will invalidate the pointers contained in the EmberTreeWidgetItems, UpdateLibraryTree() will resync. } @@ -767,6 +771,8 @@ void FractoriumEmberController::PasteXmlOver() //Also ensure it has a name. if (it.m_Name == "" || it.m_Name == "No name") it.m_Name = ToString(it.m_Index).toStdString(); + else + it.m_Name = CleanPath(it.m_Name); } m_EmberFile.MakeNamesUnique();