MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / initializeModelTempDir

Function initializeModelTempDir

src/model/FileOperations.cpp:153–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151 }
152
153 bool initializeModelTempDir(const openstudio::path& osmPath, const openstudio::path& modelTempDir) {
154 bool result = true;
155
156 if (osmPath.empty() || !openstudio::filesystem::exists(osmPath)) {
157
158 LOG_FREE(Debug, "initializeModelTempDir", "OSM path '" << toString(osmPath) << "' is empty or does not exist");
159 result = false;
160
161 } else {
162 openstudio::path fileName = osmPath.filename();
163 openstudio::path destination = modelTempDir / fileName;
164 LOG_FREE(Debug, "initializeModelTempDir", "Copying '" << toString(osmPath) << "' to '" << toString(destination) << "'");
165
166 // copy osm file
167 bool test = true;
168 try {
169 openstudio::filesystem::copy_file(osmPath, destination);
170 test = true;
171 } catch (const std::exception& e) {
172 LOG_FREE(Error, "initializeModelTempDir",
173 "Could not copy osm from '" << toString(osmPath) << "' to '" << toString(destination) << "' error" << e.what());
174 test = false;
175 }
176
177 // Copy all files from existing resources dir into temp dir when opening
178 openstudio::path sourceDir = getCompanionFolder(osmPath);
179 openstudio::path destDir = modelTempDir / toPath("resources");
180 if (openstudio::filesystem::exists(sourceDir)) {
181 LOG_FREE(Debug, "initializeModelTempDir", "Copying '" << toString(sourceDir) << "' to '" << toString(destDir) << "'");
182
183 test = replaceDir(sourceDir, destDir);
184 if (!test) {
185 LOG_FREE(Error, "initializeModelTempDir", "Could not copy '" << toString(sourceDir) << "' to '" << toString(destDir) << "'");
186 result = false;
187 }
188 }
189 }
190
191 return result;
192 }
193
194 bool updateModelTempDir(openstudio::model::Model& /*model*/, const openstudio::path& modelTempDir) {
195 bool modified = false;

Callers 1

initializeModelFunction · 0.85

Calls 6

getCompanionFolderFunction · 0.85
replaceDirFunction · 0.85
filenameMethod · 0.80
toStringFunction · 0.50
toPathFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected