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) diff --git a/src/Modules/Legacy/String/PrintStringIntoString.cc b/src/Modules/Legacy/String/PrintStringIntoString.cc index 11f54e3426..28ecba2053 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++]; + 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); }