diff --git a/src/filefinder.cpp b/src/filefinder.cpp index e87679d8c9..cc6b9004cc 100644 --- a/src/filefinder.cpp +++ b/src/filefinder.cpp @@ -320,6 +320,40 @@ bool FileFinder::IsRPG2kProjectWithRenames(const FilesystemView& fs) { return !FileExtGuesser::GetRPG2kProjectWithRenames(fs).Empty(); } +bool FileFinder::OpenViewToEasyRpgFile(FilesystemView& fs) { + auto files = fs.ListDirectory(); + if (!files) { + return false; + } + + int items = 0; + std::string filename; + + for (auto& file : *files) { + if (StringView(file.second.name).ends_with(".easyrpg")) { + ++items; + if (items == 2) { + // Contains more than one game + return false; + } + filename = file.second.name; + } + } + + if (filename.empty()) { + return false; + } + + // One candidate to check + auto ep_fs = fs.Create(filename); + if (FileFinder::IsValidProject(ep_fs)) { + fs = ep_fs; + return true; + } else { + return false; + } +} + bool FileFinder::HasSavegame() { return GetSavegames() > 0; } diff --git a/src/filefinder.h b/src/filefinder.h index 125a305bb6..f7cfe62293 100644 --- a/src/filefinder.h +++ b/src/filefinder.h @@ -253,19 +253,19 @@ namespace FileFinder { bool IsSupportedArchiveExtension(std::string path); /** - * @param p tree Tree to check + * @param p fs Tree to check * @return Whether the tree contains a valid RPG2k(3) or EasyRPG project */ bool IsValidProject(const FilesystemView& fs); /** - * @param p tree Tree to check + * @param p fs Tree to check * @return Whether the tree contains a valid RPG2k(3) project */ bool IsRPG2kProject(const FilesystemView& fs); /** - * @param p tree Tree to check + * @param p fs Tree to check * @return Whether the tree contains a valid EasyRPG project */ bool IsEasyRpgProject(const FilesystemView& fs); @@ -274,11 +274,20 @@ namespace FileFinder { * Determines if the directory in question represents an RPG2k project with non-standard * database, map tree, or map file names. * - * @param tree The directory tree in question + * @param fs The directory tree in question * @return true if this is likely an RPG2k project; false otherwise */ bool IsRPG2kProjectWithRenames(const FilesystemView& fs); + /** + * Determines if the directory contains a single file/directory ending in ".easyrpg" for use in the + * autostart feature. + * + * @param fs The directory tree to check. Is replaced with a view to the game for autorun. + * @return true when autorun is possible, fs contains the new view; when false fs is not modified + */ + bool OpenViewToEasyRpgFile(FilesystemView& fs); + /** * Checks whether the save directory contains any savegame with name * SaveXX.lsd (XX from 00 to 15). diff --git a/src/scene_gamebrowser.cpp b/src/scene_gamebrowser.cpp index dde9e24c00..5a0b700569 100644 --- a/src/scene_gamebrowser.cpp +++ b/src/scene_gamebrowser.cpp @@ -199,7 +199,7 @@ void Scene_GameBrowser::BootGame() { return; } - if (!FileFinder::IsValidProject(fs)) { + if (!FileFinder::IsValidProject(fs) && !FileFinder::OpenViewToEasyRpgFile(fs)) { // Not a game: Open as directory load_window->SetVisible(false); game_loading = false; diff --git a/src/scene_logo.cpp b/src/scene_logo.cpp index 145181c3ac..e81f1ce4e8 100644 --- a/src/scene_logo.cpp +++ b/src/scene_logo.cpp @@ -147,7 +147,8 @@ bool Scene_Logo::DetectGame() { } #endif - if (FileFinder::IsValidProject(fs)) { + if (FileFinder::IsValidProject(fs) || FileFinder::OpenViewToEasyRpgFile(fs)) { + FileFinder::SetGameFilesystem(fs); Player::CreateGameObjects(); detected_game = true; }