From baa0cbf116c77ebee5c9c1e6f64623daea1b584e Mon Sep 17 00:00:00 2001 From: Daniel White Date: Tue, 27 Sep 2022 13:12:18 -0600 Subject: [PATCH 1/3] Fixes #2405 --- .../Legacy/String/PrintStringIntoString.cc | 48 ++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/Modules/Legacy/String/PrintStringIntoString.cc b/src/Modules/Legacy/String/PrintStringIntoString.cc index 11f54e3426..790d800088 100644 --- a/src/Modules/Legacy/String/PrintStringIntoString.cc +++ b/src/Modules/Legacy/String/PrintStringIntoString.cc @@ -72,29 +72,24 @@ PrintStringIntoString::execute() std::string str; std::vector buffer(256); - bool lastport = false; - - - auto stringH = getOptionalInput(Format); - + bool lastport = false; + auto stringH = getOptionalInput(Format); auto state = get_state(); // check for port input and in none use gui input if (stringH && *stringH) { - state -> setValue(FormatString, (*stringH) -> value()); + state->setValue(FormatString, (*stringH)->value()); } - format = state -> getValue(FormatString).toString(); - + format = state->getValue(FormatString).toString(); - // Get the dynamic handles auto stringsH = getOptionalDynamicInputs(Input); if (needToExecute()) { size_t i = 0; - while(i < format.size()) + while (i < format.size()) { if (format[i] == '%') { @@ -102,7 +97,7 @@ PrintStringIntoString::execute() { error("Improper format string '%' is last character"); return; - } + } if (format[i+1] == '%') { @@ -125,34 +120,33 @@ PrintStringIntoString::execute() std::string fstr = format.substr(i,j-i+1); + if ((format[j] == 's')||(format[j] == 'S')||(format[j] == 'c')||(format[j] == 'C')) { - str = ""; - if (lastport == false) { - if (inputport == stringsH.size()) - { - lastport = true; - } - else + str = ""; + if (!lastport) { - if (stringsH.size() == static_cast(inputport)) + if (inputport == stringsH.size()) { lastport = true; } else { - currentstring = stringsH[inputport]; inputport++; - if (currentstring) + if (stringsH.size() == static_cast(inputport)) + { + lastport = true; + } + else { - str = currentstring->value(); + currentstring = stringsH[inputport]; inputport++; + if (currentstring) + { + str = currentstring->value(); + } } } } } - } - - if ((format[j] == 's')||(format[j] == 'S')||(format[j] == 'c')||(format[j] == 'C')) - { // We put the %s %S back in the string so it can be filled out lateron // By a different module @@ -209,7 +203,7 @@ PrintStringIntoString::execute() output += format[i++]; } } - + StringHandle handle(new String(output)); sendOutput(Output, handle); } From 3ff7f7c2f545a2138d17891ed023e61c8cecb64a Mon Sep 17 00:00:00 2001 From: Dan White Date: Mon, 3 Oct 2022 13:49:59 -0600 Subject: [PATCH 2/3] Closes #2407 --- src/Interface/Application/SCIRunMainWindow.cc | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Interface/Application/SCIRunMainWindow.cc b/src/Interface/Application/SCIRunMainWindow.cc index 14683914c8..d25c70d1fe 100644 --- a/src/Interface/Application/SCIRunMainWindow.cc +++ b/src/Interface/Application/SCIRunMainWindow.cc @@ -51,6 +51,7 @@ #include #include #include +#include #ifdef BUILD_WITH_PYTHON #include @@ -398,12 +399,45 @@ QString SCIRunMainWindow::strippedName(const QString& fullFileName) return info.fileName(); } +namespace +{ +bool fileExistCheck(const std::string& filename) +{ + bool fileExists; + //TODO: boost upgrade to 1.80 should remove the need for the try/catch--see issue #2407 + try + { + fileExists = boost::filesystem::exists(filename); + } + catch (...) + { + fileExists = false; + } + return fileExists; +} + +bool superFileExistCheck(const std::string& filename) +{ + auto check = std::async([filename]() { return fileExistCheck(filename); }); + auto status = check.wait_for(std::chrono::seconds(1)); + if (status == std::future_status::ready) + return check.get(); + return false; +} +} + void SCIRunMainWindow::updateRecentFileActions() { QMutableStringListIterator i(recentFiles_); - while (i.hasNext()) { - if (!QFile::exists(i.next())) + while (i.hasNext()) + { + const auto file = i.next().toStdString(); + + if (!superFileExistCheck(file)) + { + logWarning("Network file {} not found, removing entry from recent list.", file); i.remove(); + } } for (int j = 0; j < MaxRecentFiles; ++j) From c80769fce0c63dca181d4c3669997da767d0c10a Mon Sep 17 00:00:00 2001 From: Dan White Date: Mon, 10 Oct 2022 13:24:37 -0600 Subject: [PATCH 3/3] Update src/Modules/Legacy/String/PrintStringIntoString.cc --- src/Modules/Legacy/String/PrintStringIntoString.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Modules/Legacy/String/PrintStringIntoString.cc b/src/Modules/Legacy/String/PrintStringIntoString.cc index 790d800088..28ecba2053 100644 --- a/src/Modules/Legacy/String/PrintStringIntoString.cc +++ b/src/Modules/Legacy/String/PrintStringIntoString.cc @@ -138,7 +138,7 @@ PrintStringIntoString::execute() } else { - currentstring = stringsH[inputport]; inputport++; + currentstring = stringsH[inputport++]; if (currentstring) { str = currentstring->value();