| 280 | } |
| 281 | |
| 282 | std::shared_ptr<Material> |
| 283 | MaterialLibraryLocal::saveMaterial(const std::shared_ptr<Material>& material, |
| 284 | const QString& path, |
| 285 | bool overwrite, |
| 286 | bool saveAsCopy, |
| 287 | bool saveInherited) |
| 288 | { |
| 289 | QString filePath = getLocalPath(path); |
| 290 | QFile file(filePath); |
| 291 | |
| 292 | QFileInfo info(file); |
| 293 | QDir fileDir(info.path()); |
| 294 | if (!fileDir.exists()) { |
| 295 | if (!fileDir.mkpath(info.path())) { |
| 296 | Base::Console().error("Unable to create directory path '%s'\n", |
| 297 | info.path().toStdString().c_str()); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | if (info.exists()) { |
| 302 | if (!overwrite) { |
| 303 | Base::Console().error("File already exists '%s'\n", info.path().toStdString().c_str()); |
| 304 | throw MaterialExists(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { |
| 309 | QTextStream stream(&file); |
| 310 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 311 | stream.setCodec("UTF-8"); |
| 312 | #endif |
| 313 | stream.setGenerateByteOrderMark(true); |
| 314 | |
| 315 | // Write the contents |
| 316 | material->setName(info.fileName().remove(QStringLiteral(".FCMat"), Qt::CaseInsensitive)); |
| 317 | material->setLibrary(getptr()); |
| 318 | material->setDirectory(getRelativePath(path)); |
| 319 | material->save(stream, overwrite, saveAsCopy, saveInherited); |
| 320 | } |
| 321 | |
| 322 | return addMaterial(material, path); |
| 323 | } |
| 324 | |
| 325 | bool MaterialLibraryLocal::fileExists(const QString& path) const |
| 326 | { |