MCPcopy Create free account
hub / github.com/EasyRPG/Player / BuildImportCandidateList

Method BuildImportCandidateList

src/meta.cpp:148–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146
147
148std::vector<Meta::FileItem> Meta::BuildImportCandidateList(const FilesystemView& parent_fs, std::string_view child_path, std::string_view parent_game_name, int pivot_map_id) const {
149 // Scan each folder, looking for an ini file
150 // For now, this only works with "standard" folder layouts, since we need Game files + Save files
151 std::vector<Meta::FileItem> res;
152
153 // Try to read the game name. Note that we assume the games all have the same encoding (and use Player::encoding)
154 bool is_match = false;
155
156 // NOTE: FindFile doesn't work outside the root of the FileSystemView, so we use Exists() and pass a relative path.
157 // This will likely only work on Native filesystems; the Exists(".") attempts to sanity check this.
158 auto child_tree = parent_fs.Subtree(child_path);
159 if (child_tree.Exists(".")) {
160 // Try to match the parent game name.
161 std::string lmtPath = child_tree.GetSubPath() + "/" + TREEMAP_NAME;
162 std::string crcLMT = crc32file(lmtPath);
163 std::string crcLDB = "*";
164
165 if (parent_game_name.find(crcLMT)==0) {
166 if (parent_game_name == crcLMT + "/" + crcLDB) {
167 is_match = true;
168 } else {
169 std::string ldbPath = child_tree.GetSubPath() + "/" + DATABASE_NAME;
170 crcLDB = crc32file(ldbPath);
171 if (parent_game_name == crcLMT + "/" + crcLDB) {
172 is_match = true;
173 }
174 }
175 }
176 }
177
178 if (is_match) {
179 // Scan over every possible save file and see if any match.
180 for (int saveId = 0; saveId < 15; saveId++) {
181 std::stringstream ss;
182 ss << "Save" << (saveId <= 8 ? "0" : "") << (saveId + 1) << ".lsd";
183
184 // Check for an existing, non-corrupt file with the right mapID
185 // Note that corruptness is checked later (in window_savefile.cpp)
186 if (child_tree.Exists(ss.str())) {
187 auto filePath= child_tree.GetSubPath() + "/" + ss.str();
188 std::unique_ptr<lcf::rpg::Save> savegame = lcf::LSD_Reader::Load(filePath, Player::encoding);
189 if (savegame != nullptr) {
190 if (savegame->party_location.map_id == pivot_map_id || pivot_map_id==0) {
191 FileItem item;
192 item.full_path = filePath;
193 item.short_path = FileFinder::MakeCanonical(child_path, 1);
194 item.file_id = saveId + 1;
195 res.push_back(item);
196 }
197 }
198 }
199 }
200 }
201 return res;
202}
203
204std::string Meta::GetLdbAlias() const {
205 if (!Empty()) {

Callers

nothing calls this directly

Calls 4

crc32fileFunction · 0.85
SubtreeMethod · 0.80
GetSubPathMethod · 0.80
ExistsMethod · 0.45

Tested by

no test coverage detected