Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt at a fix for multi-game functionality #3080

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,27 @@ std::vector<Meta::FileItem> Meta::SearchImportPaths(const FilesystemView& parent


std::vector<Meta::FileItem> Meta::BuildImportCandidateList(const FilesystemView& parent_fs, StringView child_path, StringView parent_game_name, int pivot_map_id) const {
(void)parent_fs;
(void)child_path;
(void)parent_game_name;
(void)pivot_map_id;

// Scan each folder, looking for an ini file
// For now, this only works with "standard" folder layouts, since we need Game files + Save files
std::vector<Meta::FileItem> res;
#if 0
FIXME

// Try to read the game name. Note that we assume the games all have the same encoding (and use Player::encoding)
auto child_full_path = child_path;
auto child_tree = FileFinder::CreateDirectoryTree(child_full_path);
bool is_match = false;
if (child_tree != nullptr) {
// Try to match the parent game name
std::string lmtPath = child_tree->FindFile(TREEMAP_NAME);

// NOTE: FindFile doesn't work outside the root of the FileSystemView, so we use Exists() and pass a relative path.
// This will likely only work on Native filesystems; the Exists(".") attempts to sanity check this.
auto child_tree = parent_fs.Subtree(child_path);
if (child_tree.Exists(".")) {
// Try to match the parent game name.
std::string lmtPath = child_tree.GetSubPath() + "/" + TREEMAP_NAME;
std::string crcLMT = crc32file(lmtPath);
std::string crcLDB = "*";

if (parent_game_name.find(crcLMT)==0) {
if (parent_game_name == crcLMT + "/" + crcLDB) {
is_match = true;
} else {
std::string ldbPath = child_tree->FindFile(DATABASE_NAME);
std::string ldbPath = child_tree.GetSubPath() + "/" + DATABASE_NAME;
crcLDB = crc32file(ldbPath);
if (parent_game_name == crcLMT + "/" + crcLDB) {
is_match = true;
Expand All @@ -182,13 +179,13 @@ std::vector<Meta::FileItem> Meta::BuildImportCandidateList(const FilesystemView&

// Check for an existing, non-corrupt file with the right mapID
// Note that corruptness is checked later (in window_savefile.cpp)
std::string file = child_tree->FindFile(ss.str());
if (!file.empty()) {
std::unique_ptr<lcf::rpg::Save> savegame = lcf::LSD_Reader::Load(file, Player::encoding);
if (child_tree.Exists(ss.str())) {
auto filePath= child_tree.GetSubPath() + "/" + ss.str();
std::unique_ptr<lcf::rpg::Save> savegame = lcf::LSD_Reader::Load(filePath, Player::encoding);
if (savegame != nullptr) {
if (savegame->party_location.map_id == pivot_map_id || pivot_map_id==0) {
FileItem item;
item.full_path = file;
item.full_path = filePath;
item.short_path = FileFinder::MakeCanonical(child_path, 1);
item.file_id = saveId + 1;
res.push_back(item);
Expand All @@ -197,7 +194,6 @@ std::vector<Meta::FileItem> Meta::BuildImportCandidateList(const FilesystemView&
}
}
}
#endif
return res;
}

Expand Down
10 changes: 6 additions & 4 deletions src/scene_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void Scene_Import::Start() {
index = latest_slot;
top_index = std::max(0, index - 2);

Scene_File::Start();

Refresh();
Update();
}
Expand All @@ -85,7 +87,7 @@ void Scene_Import::vUpdate() {
return;
}

Scene_File::Update();
Scene_File::vUpdate();
}

void Scene_Import::UpdateScanAndProgress() {
Expand All @@ -104,16 +106,16 @@ void Scene_Import::UpdateScanAndProgress() {

// Gather the list of children, if it does not exist.
if (children.empty()) {
/*FIXME if (Main_Data::GetSavePath() == Main_Data::GetProjectPath()) {
auto parentPath = FileFinder::MakePath(Main_Data::GetSavePath(), "..");
std::string parentPath = FileFinder::Save().MakePath("../");
if (FileFinder::Save().Exists("../")) {
parent_fs = FileFinder::Root().Create(parentPath);
if (parent_fs) {
children = Player::meta->GetImportChildPaths(parent_fs);
}
}
if (children.empty()) {
FinishScan();
}*/
}
} else if (curr_child_id < children.size()) {
auto candidates = Player::meta->SearchImportPaths(parent_fs, children[curr_child_id]);
files.insert(files.end(), candidates.begin(), candidates.end());
Expand Down
Loading