diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index c740e8416..2a5a230bc 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -874,7 +874,6 @@ void SetUserPath(const std::string& path) { g_paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP); g_paths.emplace(UserPath::StatesDir, user_path + STATES_DIR DIR_SEP); g_paths.emplace(UserPath::IconsDir, user_path + ICONS_DIR DIR_SEP); - g_paths.emplace(UserPath::PlayTimeDir, user_path + LOG_DIR DIR_SEP); g_default_paths = g_paths; } diff --git a/src/common/file_util.h b/src/common/file_util.h index 57a1d67e1..6910f7223 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -51,7 +51,6 @@ enum class UserPath { LoadDir, LogDir, NANDDir, - PlayTimeDir, RootDir, SDMCDir, ShaderDir, diff --git a/src/common/play_time_manager.cpp b/src/common/play_time_manager.cpp index c8b94ee08..e4cb9a628 100644 --- a/src/common/play_time_manager.cpp +++ b/src/common/play_time_manager.cpp @@ -20,19 +20,27 @@ struct PlayTimeElement { PlayTime play_time; }; +#define PLAY_TIME_FILENAME "play_time.bin" + std::string GetCurrentUserPlayTimePath() { - return FileUtil::GetUserPath(FileUtil::UserPath::PlayTimeDir) + DIR_SEP + "play_time.bin"; + return FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + DIR_SEP + PLAY_TIME_FILENAME; } [[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db) { - const auto filename = GetCurrentUserPlayTimePath(); + const auto filepath = GetCurrentUserPlayTimePath(); + const auto old_filepath = + FileUtil::GetUserPath(FileUtil::UserPath::LogDir) + DIR_SEP + PLAY_TIME_FILENAME; + + if (FileUtil::Exists(old_filepath) && !FileUtil::Exists(filepath)) { + static_cast(FileUtil::Rename(old_filepath, filepath)); + } out_play_time_db.clear(); - if (FileUtil::Exists(filename)) { - FileUtil::IOFile file{filename, "rb"}; + if (FileUtil::Exists(filepath)) { + FileUtil::IOFile file{filepath, "rb"}; if (!file.IsOpen()) { - LOG_ERROR(Frontend, "Failed to open play time file: {}", filename); + LOG_ERROR(Frontend, "Failed to open play time file: {}", filepath); return false; } @@ -54,11 +62,11 @@ std::string GetCurrentUserPlayTimePath() { } [[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db) { - const auto filename = GetCurrentUserPlayTimePath(); + const auto filepath = GetCurrentUserPlayTimePath(); - FileUtil::IOFile file{filename, "wb"}; + FileUtil::IOFile file{filepath, "wb"}; if (!file.IsOpen()) { - LOG_ERROR(Frontend, "Failed to open play time file: {}", filename); + LOG_ERROR(Frontend, "Failed to open play time file: {}", filepath); return false; }