| 297 | } |
| 298 | |
| 299 | CSMDoc::Document::Document(const Files::ConfigurationManager& configuration, std::vector<std::filesystem::path> files, |
| 300 | bool isNew, const std::filesystem::path& savePath, const std::filesystem::path& resDir, ToUTF8::FromType encoding, |
| 301 | const Files::PathContainer& dataPaths, const std::vector<std::string>& archives) |
| 302 | : mSavePath(savePath) |
| 303 | , mContentFiles(std::move(files)) |
| 304 | , mNew(isNew) |
| 305 | , mData(encoding, dataPaths, archives, resDir) |
| 306 | , mTools(*this, encoding) |
| 307 | , mProjectPath((configuration.getUserDataPath() / "projects") / (savePath.filename().u8string() + u8".project")) |
| 308 | , mSavingOperation(nullptr) |
| 309 | , mSaving(nullptr) |
| 310 | , mResDir(resDir) |
| 311 | , mRunner(mProjectPath) |
| 312 | , mDirty(false) |
| 313 | , mIdCompletionManager(mData) |
| 314 | { |
| 315 | if (mContentFiles.empty()) |
| 316 | throw std::runtime_error("Empty content file sequence"); |
| 317 | |
| 318 | if (mNew || !std::filesystem::exists(mProjectPath)) |
| 319 | { |
| 320 | auto filtersPath = configuration.getUserDataPath() / "defaultfilters"; |
| 321 | |
| 322 | std::ofstream destination(mProjectPath, std::ios::out | std::ios::binary); |
| 323 | if (!destination.is_open()) |
| 324 | throw std::runtime_error("Can not create project file: " + Files::pathToUnicodeString(mProjectPath)); |
| 325 | destination.exceptions(std::ios::failbit | std::ios::badbit); |
| 326 | |
| 327 | if (!std::filesystem::exists(filtersPath)) |
| 328 | filtersPath = mResDir / "defaultfilters"; |
| 329 | |
| 330 | std::ifstream source(filtersPath, std::ios::in | std::ios::binary); |
| 331 | if (!source.is_open()) |
| 332 | throw std::runtime_error("Can not read filters file: " + Files::pathToUnicodeString(filtersPath)); |
| 333 | source.exceptions(std::ios::failbit | std::ios::badbit); |
| 334 | |
| 335 | destination << source.rdbuf(); |
| 336 | } |
| 337 | |
| 338 | if (mNew) |
| 339 | { |
| 340 | if (mContentFiles.size() == 1) |
| 341 | createBase(); |
| 342 | } |
| 343 | |
| 344 | addOptionalGmsts(); |
| 345 | addOptionalGlobals(); |
| 346 | addOptionalMagicEffects(); |
| 347 | |
| 348 | connect(&mUndoStack, &QUndoStack::cleanChanged, this, &Document::modificationStateChanged); |
| 349 | |
| 350 | connect(&mTools, &CSMTools::Tools::progress, this, qOverload<int, int, int>(&Document::progress)); |
| 351 | connect(&mTools, &CSMTools::Tools::done, this, &Document::operationDone); |
| 352 | connect(&mTools, &CSMTools::Tools::done, this, &Document::operationDone2); |
| 353 | connect(&mTools, &CSMTools::Tools::mergeDone, this, &Document::mergeDone); |
| 354 | |
| 355 | mSavingOperation = new Saving(*this, mProjectPath, encoding); |
| 356 | mSaving = new OperationHolder(this, mSavingOperation); |
nothing calls this directly
no test coverage detected