From ef566a3adffe51b10ada266f2559de3023a7aaf8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Feb 2016 18:21:57 -0800 Subject: [PATCH 1/3] SaveState: Clean up some constant usage. --- Core/SaveState.cpp | 6 ++---- Core/SaveState.h | 4 +++- UI/EmuScreen.cpp | 2 +- UI/PauseScreen.cpp | 2 +- Windows/MainWindowMenu.cpp | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index f0e0e3aaf8..b9a0321ba0 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -289,8 +289,6 @@ namespace SaveState return !rewindStates.Empty(); } - static const char *STATE_EXTENSION = "ppst"; - static const char *SCREENSHOT_EXTENSION = "jpg"; // Slot utilities std::string AppendSlotTitle(const std::string &filename, const std::string &title) { @@ -381,7 +379,7 @@ namespace SaveState void NextSlot() { I18NCategory *sy = GetI18NCategory("System"); - g_Config.iCurrentStateSlot = (g_Config.iCurrentStateSlot + 1) % SaveState::SAVESTATESLOTS; + g_Config.iCurrentStateSlot = (g_Config.iCurrentStateSlot + 1) % NUM_SLOTS; std::string msg = StringFromFormat("%s: %d", sy->T("Savestate Slot"), g_Config.iCurrentStateSlot + 1); osm.Show(msg); NativeMessageReceived("slotchanged", ""); @@ -458,7 +456,7 @@ namespace SaveState int GetNewestSlot(const std::string &gameFilename) { int newestSlot = -1; tm newestDate = {0}; - for (int i = 0; i < SAVESTATESLOTS; i++) { + for (int i = 0; i < NUM_SLOTS; i++) { std::string fn = GenerateSaveSlotFilename(gameFilename, i, STATE_EXTENSION); if (File::Exists(fn)) { tm time; diff --git a/Core/SaveState.h b/Core/SaveState.h index 6b09c566d1..fa6220b224 100644 --- a/Core/SaveState.h +++ b/Core/SaveState.h @@ -25,7 +25,9 @@ namespace SaveState { typedef std::function Callback; - const int SAVESTATESLOTS = 5; + static const int NUM_SLOTS = 5; + static const char *STATE_EXTENSION = "ppst"; + static const char *SCREENSHOT_EXTENSION = "jpg"; void Init(); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 65d9297058..e01fed3431 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -266,7 +266,7 @@ void EmuScreen::sendMessage(const char *message, const char *value) { int curSlot = SaveState::GetCurrentSlot(); std::string fn; if (SaveState::HasSaveInSlot(gamePath_, curSlot)) { - fn = SaveState::GenerateSaveSlotFilename(gamePath_, curSlot, "jpg"); + fn = SaveState::GenerateSaveSlotFilename(gamePath_, curSlot, SaveState::SCREENSHOT_EXTENSION); } saveStatePreview_->SetFilename(fn); diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index ca43c32fd9..abce83ca07 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -180,7 +180,7 @@ private: SaveSlotView::SaveSlotView(const std::string &gameFilename, int slot, UI::LayoutParams *layoutParams) : UI::LinearLayout(UI::ORIENT_HORIZONTAL, layoutParams), gamePath_(gameFilename), slot_(slot) { using namespace UI; - screenshotFilename_ = SaveState::GenerateSaveSlotFilename(gamePath_, slot, "jpg"); + screenshotFilename_ = SaveState::GenerateSaveSlotFilename(gamePath_, slot, SaveState::SCREENSHOT_EXTENSION); PrioritizedWorkQueue *wq = g_gameInfoCache->WorkQueue(); Add(new Spacer(5)); diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index bfb1059e9b..47c737821c 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -1139,8 +1139,8 @@ namespace MainWindow { if (g_Config.iCurrentStateSlot < 0) g_Config.iCurrentStateSlot = 0; - else if (g_Config.iCurrentStateSlot >= SaveState::SAVESTATESLOTS) - g_Config.iCurrentStateSlot = SaveState::SAVESTATESLOTS - 1; + else if (g_Config.iCurrentStateSlot >= SaveState::NUM_SLOTS) + g_Config.iCurrentStateSlot = SaveState::NUM_SLOTS - 1; for (int i = 0; i < ARRAY_SIZE(savestateSlot); i++) { CheckMenuItem(menu, savestateSlot[i], MF_BYCOMMAND | ((i == g_Config.iCurrentStateSlot) ? MF_CHECKED : MF_UNCHECKED)); From 5451334b38a2366c43601ee6284c53bf31e65279 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Feb 2016 18:22:40 -0800 Subject: [PATCH 2/3] VFS: Support local paths on Windows too. This fixes cases where local paths are read from, but not within the registered VFS paths. For example, save state icons. --- ext/native/file/zip_read.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/native/file/zip_read.cpp b/ext/native/file/zip_read.cpp index 4264b6e78e..cdaa85bd74 100644 --- a/ext/native/file/zip_read.cpp +++ b/ext/native/file/zip_read.cpp @@ -1,6 +1,7 @@ -#include -#include #include +#include +#include +#include #ifdef USING_QT_UI #include @@ -332,7 +333,9 @@ void VFSShutdown() { } uint8_t *VFSReadFile(const char *filename, size_t *size) { - if (filename[0] == '/') { + bool isUnixLocal = filename[0] == '/'; + bool isWindowsLocal = isalpha(filename[0]) && filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'); + if (isUnixLocal || isWindowsLocal) { // Local path, not VFS. ILOG("Not a VFS path: %s . Reading local file.", filename); return ReadLocalFile(filename, size); From ee27d838ddab38c2af99a2c1bd76f45d055ad0a5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 29 Feb 2016 00:32:31 -0800 Subject: [PATCH 3/3] VFS: Only use Windows paths on Windows, cleanup. --- ext/native/file/zip_read.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/native/file/zip_read.cpp b/ext/native/file/zip_read.cpp index cdaa85bd74..90f7dcf160 100644 --- a/ext/native/file/zip_read.cpp +++ b/ext/native/file/zip_read.cpp @@ -332,10 +332,18 @@ void VFSShutdown() { num_entries = 0; } +static bool IsLocalPath(const char *path) { + bool isUnixLocal = path[0] == '/'; +#ifdef _WIN32 + bool isWindowsLocal = isalpha(path[0]) && path[1] == ':'; +#else + bool isWindowsLocal = false; +#endif + return isUnixLocal || isWindowsLocal; +} + uint8_t *VFSReadFile(const char *filename, size_t *size) { - bool isUnixLocal = filename[0] == '/'; - bool isWindowsLocal = isalpha(filename[0]) && filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\'); - if (isUnixLocal || isWindowsLocal) { + if (IsLocalPath(filename)) { // Local path, not VFS. ILOG("Not a VFS path: %s . Reading local file.", filename); return ReadLocalFile(filename, size); @@ -364,11 +372,7 @@ uint8_t *VFSReadFile(const char *filename, size_t *size) { } bool VFSGetFileListing(const char *path, std::vector *listing, const char *filter) { -#ifdef _WIN32 - if (path[1] == ':') { -#else - if (path[0] == '/') { -#endif + if (IsLocalPath(path)) { // Local path, not VFS. ILOG("Not a VFS path: %s . Reading local directory.", path); getFilesInDir(path, listing, filter); @@ -395,11 +399,7 @@ bool VFSGetFileListing(const char *path, std::vector *listing, const c } bool VFSGetFileInfo(const char *path, FileInfo *info) { -#ifdef _WIN32 - if (path[1] == ':') { -#else - if (path[0] == '/') { -#endif + if (IsLocalPath(path)) { // Local path, not VFS. ILOG("Not a VFS path: %s . Getting local file info.", path); return getFileInfo(path, info);