diff --git a/src/model_editor/PathWatcher.cpp b/src/model_editor/PathWatcher.cpp index 1309c899e..efa930828 100644 --- a/src/model_editor/PathWatcher.cpp +++ b/src/model_editor/PathWatcher.cpp @@ -15,13 +15,17 @@ /// constructor PathWatcher::PathWatcher(const openstudio::path& p, int msec) - : m_enabled(true), m_exists(openstudio::filesystem::exists(p)), m_dirty(false), m_checksum(openstudio::checksum(p)), m_path(p), m_msec(msec) { + : m_enabled(true), m_exists(false), m_dirty(false), m_checksum(openstudio::checksum(p)), m_path(p), m_msec(msec) { + + boost::system::error_code ec; + m_exists = openstudio::filesystem::exists(p, ec); + // make sure a QApplication exists openstudio::Application::instance().application(false); openstudio::Application::instance().processEvents(); const bool isDirectory = - (openstudio::filesystem::is_directory(p) || openstudio::toString(p.filename()) == "." || openstudio::toString(p.filename()) == "/"); + (openstudio::filesystem::is_directory(p, ec) || openstudio::toString(p.filename()) == "." || openstudio::toString(p.filename()) == "/"); if (isDirectory) { LOG_FREE_AND_THROW("openstudio.PathWatcher", "Watching Directory '" << openstudio::toString(p) << "' is not supported"); @@ -71,7 +75,8 @@ bool PathWatcher::dirty() const { } void PathWatcher::clearState() { - m_exists = openstudio::filesystem::exists(m_path); + boost::system::error_code ec; + m_exists = openstudio::filesystem::exists(m_path, ec); m_dirty = false; m_checksum = openstudio::checksum(m_path); } @@ -87,7 +92,8 @@ void PathWatcher::fileChanged(const QString& path) { } void PathWatcher::checkFile() { - bool exists = openstudio::filesystem::exists(m_path); + boost::system::error_code ec; + bool exists = openstudio::filesystem::exists(m_path, ec); std::string checksum = openstudio::checksum(m_path); if (checksum == "00000000") { diff --git a/src/openstudio_app/OpenStudioApp.cpp b/src/openstudio_app/OpenStudioApp.cpp index ac561f9bf..6b8e813bb 100644 --- a/src/openstudio_app/OpenStudioApp.cpp +++ b/src/openstudio_app/OpenStudioApp.cpp @@ -171,7 +171,8 @@ OpenStudioApp::OpenStudioApp(int& argc, char** argv) std::stringstream webenginePath; webenginePath << QCoreApplication::applicationDirPath().toStdString(); webenginePath << "/../Frameworks/QtWebEngineCore.framework/Versions/A/Helpers/QtWebEngineProcess.app/Contents/MacOS/QtWebEngineProcess"; - if (filesystem::exists(filesystem::path(webenginePath.str()))) { + boost::system::error_code ec; + if (filesystem::exists(filesystem::path(webenginePath.str()), ec)) { setenv("QTWEBENGINEPROCESS_PATH", webenginePath.str().c_str(), true); } @@ -1102,9 +1103,10 @@ void OpenStudioApp::versionUpdateMessageBox(const osversion::VersionTranslator& }; for (const auto& scriptfolder : scriptfolders) { - if (openstudio::filesystem::exists(scriptfolder)) { + boost::system::error_code ec; + if (openstudio::filesystem::exists(scriptfolder, ec)) { removedScriptDirs = true; - openstudio::filesystem::remove_all(scriptfolder); + openstudio::filesystem::remove_all(scriptfolder, ec); } } } @@ -1149,9 +1151,7 @@ void OpenStudioApp::readSettings() { setLastPath(settings.value("lastPath", QDir::homePath()).toString()); setDviewPath(openstudio::toPath(settings.value("dviewPath", "").toString())); m_currLang = settings.value("language", "en").toString(); - LOG_FREE(Debug, "OpenStudioApp", - "\n\n\nm_currLang=[" << m_currLang.toStdString() << "]" - << "\n\n\n"); + LOG_FREE(Debug, "OpenStudioApp", "\n\n\nm_currLang=[" << m_currLang.toStdString() << "]" << "\n\n\n"); if (m_currLang.isEmpty()) { m_currLang = "en"; } @@ -1554,7 +1554,8 @@ void OpenStudioApp::loadShoeboxModel() { auto filePath = resourcesPath() / toPath("ShoeboxModel/ShoeboxExample.osm"); boost::optional model_; - if (openstudio::filesystem::is_regular_file(filePath)) { + boost::system::error_code ec; + if (openstudio::filesystem::is_regular_file(filePath, ec)) { model_ = versionTranslator.loadModel(filePath); } else if (isOpenStudioApplicationRunningFromBuildDirectory()) { filePath = getOpenStudioCoalitionMeasuresSourceDirectory() / toPath("models/ShoeboxExample.osm"); @@ -1714,7 +1715,8 @@ void OpenStudioApp::setDviewPath(const openstudio::path& t_dviewPath) { LOG_FREE(Debug, "OpenStudioApp", "setDViewPath t_dviewPath is not empty."); // check if exists? - if (openstudio::filesystem::exists(t_dviewPath) && !openstudio::filesystem::is_directory(t_dviewPath)) { + boost::system::error_code ec; + if (openstudio::filesystem::exists(t_dviewPath, ec) && !openstudio::filesystem::is_directory(t_dviewPath, ec)) { m_dviewPath = t_dviewPath; } else { LOG_FREE(Error, "OpenStudioApp", "setDViewPath: t_dviewPath doesn't not appear to be valid: '" << t_dviewPath << "'."); diff --git a/src/openstudio_lib/ApplyMeasureNowDialog.cpp b/src/openstudio_lib/ApplyMeasureNowDialog.cpp index e435a3b6c..0f9f9fb12 100644 --- a/src/openstudio_lib/ApplyMeasureNowDialog.cpp +++ b/src/openstudio_lib/ApplyMeasureNowDialog.cpp @@ -380,9 +380,7 @@ void ApplyMeasureNowDialog::runMeasure() { if (OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI()) { arguments << "classic"; } - arguments << "run" - << "-m" - << "-w" << toQString(*tempWorkflowJSONPath); + arguments << "run" << "-m" << "-w" << toQString(*tempWorkflowJSONPath); LOG(Debug, "openstudioExePath='" << toString(openstudioExePath) << "'"); LOG(Debug, "run arguments" << arguments.join(";").toStdString()); @@ -408,7 +406,8 @@ void ApplyMeasureNowDialog::displayResults() { this->okButton()->setText(ACCEPT_CHANGES); this->okButton()->show(); - if (boost::filesystem::exists(*m_reloadPath)) { + boost::system::error_code ec; + if (boost::filesystem::exists(*m_reloadPath, ec)) { this->okButton()->setEnabled(true); } else { this->okButton()->setEnabled(false); diff --git a/src/openstudio_lib/LocationTabView.cpp b/src/openstudio_lib/LocationTabView.cpp index cf9dcd884..234c2657e 100644 --- a/src/openstudio_lib/LocationTabView.cpp +++ b/src/openstudio_lib/LocationTabView.cpp @@ -722,6 +722,7 @@ void LocationView::onWeatherFileBtnClicked() { if (!previousEPWPath.empty()) { if (previousEPWPath.filename() != newPath.filename()) { + // inside try/catch, allow exception if (openstudio::filesystem::exists(previousEPWPath)) { openstudio::filesystem::remove_all(previousEPWPath); } @@ -762,7 +763,8 @@ void LocationView::onWeatherFileBtnClicked() { } catch (...) { - openstudio::filesystem::remove_all(newPath); + boost::system::error_code ec; + openstudio::filesystem::remove_all(newPath, ec); QMessageBox box(QMessageBox::Warning, tr("Failed To Set Weather File"), tr("Failed To Set Weather File To ") + fileName, QMessageBox::Ok); box.setDetailedText(toQString(ss.string())); diff --git a/src/openstudio_lib/OSDocument.cpp b/src/openstudio_lib/OSDocument.cpp index f280c9f81..c8bd04539 100644 --- a/src/openstudio_lib/OSDocument.cpp +++ b/src/openstudio_lib/OSDocument.cpp @@ -150,7 +150,8 @@ OSDocument::OSDocument(const openstudio::model::Model& library, const openstudio if (!m_savePath.isEmpty()) { auto p = toPath(m_savePath); modelTempDirPath = model::initializeModel(*model, p); - m_mainWindow->setWindowTitle(toQString(p.filename()) + "[*]"); + m_mainWindow->setWindowFilePath(m_savePath); + m_mainWindow->setWindowTitle(m_savePath + "[*]"); } else { modelTempDirPath = model::initializeModel(*model); m_mainWindow->setWindowTitle("Untitled[*]"); @@ -930,12 +931,13 @@ bool OSDocument::fixWeatherFileInTemp(bool opening) { epwPathAbsolute = true; epwInUserPath = *weatherFilePath; - if (boost::filesystem::exists(epwInUserPath)) { + boost::system::error_code ec; + if (boost::filesystem::exists(epwInUserPath, ec)) { epwInUserPathChecksum = checksum(epwInUserPath); } epwInTempPath = tempFilesDir / epwInUserPath.filename(); - if (boost::filesystem::exists(epwInTempPath)) { + if (boost::filesystem::exists(epwInTempPath, ec)) { epwInTempPathChecksum = checksum(epwInTempPath); } @@ -946,11 +948,12 @@ bool OSDocument::fixWeatherFileInTemp(bool opening) { // Look in temp model "resources" and "resources/files" epwInTempPath = tempResourcesDir / *weatherFilePath; - if (boost::filesystem::exists(epwInTempPath)) { + boost::system::error_code ec; + if (boost::filesystem::exists(epwInTempPath, ec)) { epwInTempPathChecksum = checksum(epwInTempPath); } else { epwInTempPath = tempFilesDir / *weatherFilePath; - if (boost::filesystem::exists(epwInTempPath)) { + if (boost::filesystem::exists(epwInTempPath, ec)) { epwInTempPathChecksum = checksum(epwInTempPath); } } @@ -966,12 +969,12 @@ bool OSDocument::fixWeatherFileInTemp(bool opening) { // Expected location is companion_folder/files epwInUserPath = searchFilesDir / *weatherFilePath; - if (boost::filesystem::exists(epwInUserPath)) { + if (boost::filesystem::exists(epwInUserPath, ec)) { epwInUserPathChecksum = checksum(epwInUserPath); } else { // Just in case, we look in the companion_folder epwInUserPath = searchCompanionDir / *weatherFilePath; - if (boost::filesystem::exists(epwInUserPath)) { + if (boost::filesystem::exists(epwInUserPath, ec)) { epwInUserPathChecksum = checksum(epwInUserPath); } } @@ -1098,7 +1101,8 @@ bool OSDocument::fixWeatherFileInTemp(bool opening) { if (doCopy) { LOG(Debug, "Removing weather file at " << copyDest); - boost::filesystem::remove_all(copyDest); + boost::system::error_code ec; + boost::filesystem::remove_all(copyDest, ec); LOG(Debug, "Removing weather file complete"); } @@ -1510,9 +1514,10 @@ bool OSDocument::saveAs() { // remove old model if (!m_savePath.isEmpty()) { openstudio::path oldModelPath = toPath(m_modelTempDir) / toPath(m_savePath).filename(); - if (boost::filesystem::exists(oldModelPath)) { + boost::system::error_code ec; + if (boost::filesystem::exists(oldModelPath, ec)) { LOG(Debug, "Removing " << oldModelPath << " starting"); - boost::filesystem::remove(oldModelPath); + boost::filesystem::remove(oldModelPath, ec); LOG(Debug, "Removing " << oldModelPath << " complete"); } } @@ -1631,8 +1636,8 @@ boost::optional OSDocument::getComponent(const OSItemId& itemI } #endif - - //OS_ASSERT(openstudio::filesystem::exists(oscPath)); + //std::error_code ec; + //OS_ASSERT(openstudio::filesystem::exists(oscPath, ec)); osversion::VersionTranslator translator; //translator.setAllowNewerVersions(false); // DLM: allow to open newer versions? @@ -1734,9 +1739,7 @@ void OSDocument::updateWindowFilePath() { } else { // m_mainWindow->setWindowTitle(); m_mainWindow->setWindowFilePath(m_savePath); - QFileInfo fi(m_savePath); - QString fileName = fi.fileName(); - m_mainWindow->setWindowTitle(fileName + "[*]"); + m_mainWindow->setWindowTitle(m_savePath + "[*]"); } } diff --git a/src/openstudio_lib/OSItem.cpp b/src/openstudio_lib/OSItem.cpp index 323865f60..c0b5fa2e7 100644 --- a/src/openstudio_lib/OSItem.cpp +++ b/src/openstudio_lib/OSItem.cpp @@ -152,7 +152,8 @@ OSItem* OSItem::makeItem(const OSItemId& itemId, OSItemType osItemType) { result = new ModelObjectItem(*modelObject, itemId.isDefaulted(), osItemType); } else { openstudio::path p = openstudio::toPath(itemId.itemId()); - if (openstudio::filesystem::exists(p)) { + boost::system::error_code ec; + if (openstudio::filesystem::exists(p, ec)) { result = new ScriptItem(p, osItemType); } } diff --git a/src/openstudio_lib/ResultsTabView.cpp b/src/openstudio_lib/ResultsTabView.cpp index 4445cdfea..9d6920ff9 100644 --- a/src/openstudio_lib/ResultsTabView.cpp +++ b/src/openstudio_lib/ResultsTabView.cpp @@ -194,7 +194,8 @@ void ResultsView::searchForExistingResults(const openstudio::path& t_runDir, con std::vector reports; // Check that the directory does exists first - if (openstudio::filesystem::is_directory(t_runDir) && openstudio::filesystem::exists(t_runDir)) { + boost::system::error_code ec; + if (openstudio::filesystem::is_directory(t_runDir, ec) && openstudio::filesystem::exists(t_runDir, ec)) { for (openstudio::filesystem::recursive_directory_iterator end, dir(t_runDir); dir != end; ++dir) { openstudio::path p = *dir; if (openstudio::toString(p.filename()) == "eplusout.sql") { @@ -210,7 +211,7 @@ void ResultsView::searchForExistingResults(const openstudio::path& t_runDir, con LOG(Debug, "Looking for existing results in: " << openstudio::toString(t_reportsDir)); // Check that the directory does exists first - if (openstudio::filesystem::is_directory(t_reportsDir) && openstudio::filesystem::exists(t_reportsDir)) { + if (openstudio::filesystem::is_directory(t_reportsDir, ec) && openstudio::filesystem::exists(t_reportsDir, ec)) { for (openstudio::filesystem::directory_iterator end, dir(t_reportsDir); dir != end; ++dir) { openstudio::path p = *dir; if (openstudio::toString(p.extension()) == ".html" || openstudio::toString(p.extension()) == ".htm") { diff --git a/src/openstudio_lib/ScheduleFileInspectorView.cpp b/src/openstudio_lib/ScheduleFileInspectorView.cpp index 150ab0e7c..746d5d236 100644 --- a/src/openstudio_lib/ScheduleFileInspectorView.cpp +++ b/src/openstudio_lib/ScheduleFileInspectorView.cpp @@ -323,9 +323,7 @@ void ScheduleFileInspectorView::attach(openstudio::model::ScheduleFile& sch) { m_columnSeparator->bind( *m_sch, static_cast(&openstudio::toString), // ScheduleFile::columnSeparatorValues does not exist: https://github.com/NREL/OpenStudio/issues/5246 - []() { - return std::vector{"Comma", "Tab", "Space", "Semicolon"}; - }, + []() { return std::vector{"Comma", "Tab", "Space", "Semicolon"}; }, std::bind(&model::ScheduleFile::columnSeparator, m_sch.get_ptr()), [this](const std::string& value) -> bool { bool result = m_sch->setColumnSeparator(value); @@ -424,7 +422,8 @@ void ScheduleFileInspectorView::refreshContent() { openstudio::path fpath = m_sch->externalFile().filePath(); m_contentLines->clear(); - if (openstudio::filesystem::is_regular_file(fpath)) { + boost::system::error_code ec; + if (openstudio::filesystem::is_regular_file(fpath, ec)) { const int rowstoSkipatTop = m_sch->rowstoSkipatTop(); const int colNum = m_sch->columnNumber() - 1; // Turn 1-indexed to 0-indexed diff --git a/src/openstudio_lib/ScriptItem.cpp b/src/openstudio_lib/ScriptItem.cpp index 845dc5d28..960a23189 100644 --- a/src/openstudio_lib/ScriptItem.cpp +++ b/src/openstudio_lib/ScriptItem.cpp @@ -128,9 +128,10 @@ void ScriptItem::saveArgumentsToDb() { void ScriptItem::deleteDb() { m_removed = true; - if (openstudio::filesystem::exists(argsDbPath())) { - openstudio::filesystem::remove(argsDbPath()); - openstudio::filesystem::remove(toPath(toString((argsDbPath())) + "-journal")); + boost::system::error_code ec; + if (openstudio::filesystem::exists(argsDbPath(), ec)) { + openstudio::filesystem::remove(argsDbPath(), ec); + openstudio::filesystem::remove(toPath(toString((argsDbPath())) + "-journal"), ec); } } diff --git a/src/shared_gui_components/BCLMeasureDialog.cpp b/src/shared_gui_components/BCLMeasureDialog.cpp index c13544bb5..4569cfcbe 100644 --- a/src/shared_gui_components/BCLMeasureDialog.cpp +++ b/src/shared_gui_components/BCLMeasureDialog.cpp @@ -176,9 +176,10 @@ boost::optional BCLMeasureDialog::createMeasure() { openstudio::path measureDir = umd / toPath(folderName); // prompt user ??? - if (openstudio::filesystem::exists(measureDir)) { + boost::system::error_code ec; + if (openstudio::filesystem::exists(measureDir, ec)) { int i = 1; - while (openstudio::filesystem::exists(measureDir)) { + while (openstudio::filesystem::exists(measureDir, ec)) { folderName = toQString(lowerClassName).append(" ").append(QString::number(i)).append("/"); measureDir = umd / toPath(folderName); ++i; diff --git a/src/shared_gui_components/WorkflowController.cpp b/src/shared_gui_components/WorkflowController.cpp index 7338485ed..74ee5f764 100644 --- a/src/shared_gui_components/WorkflowController.cpp +++ b/src/shared_gui_components/WorkflowController.cpp @@ -176,8 +176,9 @@ void MeasureStepController::removeItemForStep(MeasureStep step) { // remove the measure if (canDeleteMeasure) { boost::optional measureDir = m_app->currentModel()->workflowJSON().findMeasure(step.measureDirName()); - if (measureDir && openstudio::filesystem::exists(*measureDir)) { - openstudio::filesystem::remove_all(*measureDir); + boost::system::error_code ec; + if (measureDir && openstudio::filesystem::exists(*measureDir, ec)) { + openstudio::filesystem::remove_all(*measureDir, ec); } }