Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/model_editor/PathWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
Expand All @@ -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") {
Expand Down
18 changes: 10 additions & 8 deletions src/openstudio_app/OpenStudioApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -1554,7 +1554,8 @@ void OpenStudioApp::loadShoeboxModel() {

auto filePath = resourcesPath() / toPath("ShoeboxModel/ShoeboxExample.osm");
boost::optional<openstudio::model::Model> 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");
Expand Down Expand Up @@ -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 << "'.");
Expand Down
7 changes: 3 additions & 4 deletions src/openstudio_lib/ApplyMeasureNowDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/openstudio_lib/LocationTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()));
Expand Down
33 changes: 18 additions & 15 deletions src/openstudio_lib/OSDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[*]");
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -1631,8 +1636,8 @@ boost::optional<model::Component> 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?
Expand Down Expand Up @@ -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 + "[*]");
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/openstudio_lib/OSItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/openstudio_lib/ResultsTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ void ResultsView::searchForExistingResults(const openstudio::path& t_runDir, con
std::vector<openstudio::path> 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") {
Expand All @@ -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") {
Expand Down
7 changes: 3 additions & 4 deletions src/openstudio_lib/ScheduleFileInspectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ void ScheduleFileInspectorView::attach(openstudio::model::ScheduleFile& sch) {
m_columnSeparator->bind<std::string>(
*m_sch, static_cast<std::string (*)(const std::string&)>(&openstudio::toString),
// ScheduleFile::columnSeparatorValues does not exist: https://github.com/NREL/OpenStudio/issues/5246
[]() {
return std::vector<std::string>{"Comma", "Tab", "Space", "Semicolon"};
},
[]() { return std::vector<std::string>{"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);
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/openstudio_lib/ScriptItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/shared_gui_components/BCLMeasureDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ boost::optional<openstudio::BCLMeasure> 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;
Expand Down
5 changes: 3 additions & 2 deletions src/shared_gui_components/WorkflowController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ void MeasureStepController::removeItemForStep(MeasureStep step) {
// remove the measure
if (canDeleteMeasure) {
boost::optional<openstudio::path> 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);
}
}

Expand Down
Loading