| 25 | } |
| 26 | |
| 27 | void PDFFile::loadFromConfig(const filesystem::path &filepath) { |
| 28 | configFilepath = filepath; // save filepath for latter use with writeToConfig |
| 29 | |
| 30 | // Use boardview file path as default PDF file path, with ext replaced with .pdf |
| 31 | path = filepath; |
| 32 | path.replace_extension("pdf"); |
| 33 | |
| 34 | if (!filesystem::exists(filepath)) { // Config file doesn't exist, do not attempt to read or write it and load images |
| 35 | SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Board configuration file %s does not exist", filepath.generic_string().c_str()); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading PDF file path from board configuration file: %s", filepath.generic_string().c_str()); |
| 40 | |
| 41 | auto configDir = filesystem::weakly_canonical(filepath).parent_path(); |
| 42 | |
| 43 | Confparse confparse{}; |
| 44 | confparse.Load(filepath); |
| 45 | |
| 46 | |
| 47 | std::string pdfFilePathStr{confparse.ParseStr("PDFFilePath", "")}; |
| 48 | if (!pdfFilePathStr.empty()) |
| 49 | path = configDir/filesystem::u8path(pdfFilePathStr); |
| 50 | |
| 51 | writeToConfig(filepath); |
| 52 | } |
| 53 | |
| 54 | void PDFFile::writeToConfig(const filesystem::path &filepath) { |
| 55 | if (filepath.empty()) // No destination file to save to |