| 72 | } |
| 73 | |
| 74 | FilesystemView FileFinder::Save() { |
| 75 | if (save_fs) { |
| 76 | // This means the save filesystem was overwritten |
| 77 | if (!save_fs.IsFeatureSupported(Filesystem::Feature::Write)) { |
| 78 | Output::Error("{} is not a valid save path (not writable)", GetFullFilesystemPath(save_fs)); |
| 79 | } |
| 80 | return save_fs; |
| 81 | } |
| 82 | |
| 83 | if (!game_fs) { |
| 84 | // Filesystem not initialized yet (happens on startup) |
| 85 | return {}; |
| 86 | } |
| 87 | |
| 88 | // Not overwritten, check if game fs is writable. If not redirect the write operation. |
| 89 | if (!game_fs.IsFeatureSupported(Filesystem::Feature::Write)) { |
| 90 | // When the Project path equals the Save path (this means the path was not configured) |
| 91 | // and the filesystem has no write support do a redirection to a folder with ".save" appended |
| 92 | FilesystemView parent = game_fs; |
| 93 | FilesystemView redir; |
| 94 | std::vector<std::string> comps; |
| 95 | for (;;) { |
| 96 | comps.emplace_back(parent.GetSubPath()); |
| 97 | comps.emplace_back(parent.GetBasePath()); |
| 98 | parent = parent.GetOwner().GetParent(); |
| 99 | if (!parent) { |
| 100 | break; |
| 101 | } |
| 102 | if (parent.IsFeatureSupported(Filesystem::Feature::Write)) { |
| 103 | comps.back() += ".save"; |
| 104 | std::reverse(comps.begin(), comps.end()); |
| 105 | std::string save_path = MakePath(lcf::MakeSpan(comps)); |
| 106 | if (!parent.IsDirectory(save_path, true)) { |
| 107 | parent.MakeDirectory(save_path, true); |
| 108 | } |
| 109 | redir = parent.Subtree(save_path); |
| 110 | |
| 111 | if (!redir) { |
| 112 | Output::Error("Invalid save directory {}", save_path); |
| 113 | } |
| 114 | |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if (!redir) { |
| 120 | Output::Error("No suitable save directory found"); |
| 121 | } |
| 122 | |
| 123 | return redir; |
| 124 | } |
| 125 | |
| 126 | return game_fs; |
| 127 | } |
| 128 | |
| 129 | void FileFinder::SetSaveFilesystem(FilesystemView filesystem) { |
| 130 | save_fs = filesystem; |
nothing calls this directly
no test coverage detected