From 2618f2ed39dc9eebf5abe3c564d47b01436652ec Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 1 Jan 2014 16:45:37 -0800 Subject: [PATCH] Add a simple extract file command. Mostly useful for quickly/easily extracting pmf/atrac/etc. files. --- UI/MainScreen.cpp | 4 ++-- Windows/WndMainWindow.cpp | 34 ++++++++++++++++++++++++++++++++++ Windows/ppsspp.rc | 3 ++- Windows/resource.h | 1 + 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index d820bb6f8c..26138817ac 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -559,7 +559,7 @@ bool GameBrowser::IsCurrentPathPinned() { } const std::vector GameBrowser::GetPinnedPaths() { -#ifdef _WIN32 +#ifndef _WIN32 static const std::string sepChars = "/"; #else static const std::string sepChars = "/\\"; @@ -587,7 +587,7 @@ const std::vector GameBrowser::GetPinnedPaths() { } const std::string GameBrowser::GetBaseName(const std::string &path) { -#ifdef _WIN32 +#ifndef _WIN32 static const std::string sepChars = "/"; #else static const std::string sepChars = "/\\"; diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index f8f043577a..bbdadab4b1 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -35,6 +35,7 @@ #include "util/text/utf8.h" #include "Core/Debugger/SymbolMap.h" +#include "Windows/InputBox.h" #include "Windows/OpenGLBase.h" #include "Windows/Debugger/Debugger_Disasm.h" #include "Windows/Debugger/Debugger_MemoryDlg.h" @@ -48,6 +49,7 @@ #include "Core/Config.h" #include "Core/MIPS/JitCommon/JitCommon.h" #include "Core/MIPS/JitCommon/JitBlockCache.h" +#include "Core/FileSystems/MetaFileSystem.h" #include "Windows/EmuThread.h" #include "resource.h" @@ -1389,6 +1391,38 @@ namespace MainWindow memoryWindow[0]->Show(true); break; + case ID_DEBUG_EXTRACTFILE: + { + std::string filename; + if (!InputBox_GetString(hInst, hwndMain, L"Disc filename", filename, filename)) { + break; + } + + const char *lastSlash = strrchr(filename.c_str(), '/'); + if (lastSlash) { + fn = lastSlash + 1; + } else { + fn = ""; + } + + PSPFileInfo info = pspFileSystem.GetFileInfo(filename); + if (!info.exists) { + MessageBox(hwndMain, L"File does not exist.", L"Sorry",0); + } else if (info.type == FILETYPE_DIRECTORY) { + MessageBox(hwndMain, L"Cannot extract directories.", L"Sorry",0); + } else if (W32Util::BrowseForFileName(false, hWnd, L"Save file as...", 0, L"0All files\0*.*\0\0", L"", fn)) { + FILE *fp = fopen(fn.c_str(), "wb"); + u32 handle = pspFileSystem.OpenFile(filename, FILEACCESS_READ, ""); + u8 buffer[4096]; + while (pspFileSystem.ReadFile(handle, buffer, sizeof(buffer)) > 0) { + fwrite(buffer, sizeof(buffer), 1, fp); + } + pspFileSystem.CloseFile(handle); + fclose(fp); + } + } + break; + case ID_DEBUG_LOG: LogManager::GetInstance()->GetConsoleListener()->Show(LogManager::GetInstance()->GetConsoleListener()->Hidden()); break; diff --git a/Windows/ppsspp.rc b/Windows/ppsspp.rc index bb4fc54d84..e6f93373d2 100644 --- a/Windows/ppsspp.rc +++ b/Windows/ppsspp.rc @@ -407,7 +407,8 @@ BEGIN MENUITEM SEPARATOR MENUITEM "Disassembly", ID_DEBUG_DISASSEMBLY MENUITEM "GE Debugger...", ID_DEBUG_GEDEBUGGER - MENUITEM "Log Console", ID_DEBUG_LOG + MENUITEM "Extract File...", ID_DEBUG_EXTRACTFILE + MENUITEM "Log Console", ID_DEBUG_LOG MENUITEM "Memory View...", ID_DEBUG_MEMORYVIEW END diff --git a/Windows/resource.h b/Windows/resource.h index 6c74e1ed1c..c746f0ebb1 100644 --- a/Windows/resource.h +++ b/Windows/resource.h @@ -298,6 +298,7 @@ #define ID_MEMVIEW_COPYVALUE_16 40142 #define ID_MEMVIEW_COPYVALUE_32 40143 #define ID_EMULATION_SWITCH_UMD 40144 +#define ID_DEBUG_EXTRACTFILE 40145 // Dummy option to let the buffered rendering hotkey cycle through all the options. #define ID_OPTIONS_BUFFEREDRENDERINGDUMMY 40500