From ecbef7a2ff0e4cf8ca4a03ffc4bf43f3cda4ef55 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 19 Sep 2015 14:28:43 +0200 Subject: [PATCH] Remove easy_file.cpp/h. Minor cleanups. --- CMakeLists.txt | 2 - Common/FileUtil.h | 6 +-- Windows/WindowsHost.cpp | 82 +++++++++++----------------- ext/native/Android.mk | 1 - ext/native/ext/vjson/json.cpp | 1 - ext/native/file/CMakeLists.txt | 1 - ext/native/file/chunk_file.cpp | 56 +++++++++---------- ext/native/file/chunk_file.h | 5 +- ext/native/file/easy_file.cpp | 89 ------------------------------- ext/native/file/easy_file.h | 58 -------------------- ext/native/file/file_util.h | 1 + ext/native/native.vcxproj | 2 - ext/native/native.vcxproj.filters | 6 --- 13 files changed, 63 insertions(+), 247 deletions(-) delete mode 100644 ext/native/file/easy_file.cpp delete mode 100644 ext/native/file/easy_file.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b84cd2e126..a62fdff293 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -894,8 +894,6 @@ add_library(native STATIC ext/native/ext/vjson/block_allocator.h ext/native/file/chunk_file.cpp ext/native/file/chunk_file.h - ext/native/file/easy_file.cpp - ext/native/file/easy_file.h ext/native/file/fd_util.cpp ext/native/file/fd_util.h ext/native/file/file_util.cpp diff --git a/Common/FileUtil.h b/Common/FileUtil.h index db550b4371..d903a1ba24 100644 --- a/Common/FileUtil.h +++ b/Common/FileUtil.h @@ -33,8 +33,7 @@ inline struct tm* localtime_r(const time_t *clock, struct tm *result) { } #endif -namespace File -{ +namespace File { // FileSystem tree node/ struct FSTEntry @@ -107,8 +106,7 @@ const std::string &GetExeDirectory(); // simple wrapper for cstdlib file functions to // hopefully will make error checking easier // and make forgetting an fclose() harder -class IOFile : NonCopyable -{ +class IOFile : NonCopyable { public: IOFile(); IOFile(std::FILE* file); diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index 207363f6fc..36a64fba6a 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -88,6 +88,22 @@ WindowsHost::WindowsHost(HWND mainWindow, HWND displayWindow) SetConsolePosition(); } +void WindowsHost::SetConsolePosition() { + HWND console = GetConsoleWindow(); + if (console != NULL && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1) + SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER); +} + +void WindowsHost::UpdateConsolePosition() { + RECT rc; + HWND console = GetConsoleWindow(); + if (console != NULL && GetWindowRect(console, &rc) && !IsIconic(console)) + { + g_Config.iConsoleWindowX = rc.left; + g_Config.iConsoleWindowY = rc.top; + } +} + bool WindowsHost::InitGraphics(std::string *error_message) { switch (g_Config.iGPUBackend) { case GPU_BACKEND_OPENGL: @@ -111,8 +127,7 @@ void WindowsHost::ShutdownGraphics() { PostMessage(mainWindow_, WM_CLOSE, 0, 0); } -void WindowsHost::SetWindowTitle(const char *message) -{ +void WindowsHost::SetWindowTitle(const char *message) { std::wstring winTitle = ConvertUTF8ToWString(std::string("PPSSPP ") + PPSSPP_GIT_VERSION); if (message != nullptr) { winTitle.append(ConvertUTF8ToWString(" - ")); @@ -123,56 +138,47 @@ void WindowsHost::SetWindowTitle(const char *message) PostMessage(mainWindow_, MainWindow::WM_USER_WINDOW_TITLE_CHANGED, 0, 0); } -void WindowsHost::InitSound() -{ +void WindowsHost::InitSound() { } // UGLY! extern WindowsAudioBackend *winAudioBackend; -void WindowsHost::UpdateSound() -{ +void WindowsHost::UpdateSound() { if (winAudioBackend) winAudioBackend->Update(); } -void WindowsHost::ShutdownSound() -{ +void WindowsHost::ShutdownSound() { } -void WindowsHost::UpdateUI() -{ +void WindowsHost::UpdateUI() { PostMessage(mainWindow_, MainWindow::WM_USER_UPDATE_UI, 0, 0); } -void WindowsHost::UpdateScreen() -{ +void WindowsHost::UpdateScreen() { PostMessage(mainWindow_, MainWindow::WM_USER_UPDATE_SCREEN, 0, 0); } -void WindowsHost::UpdateMemView() -{ +void WindowsHost::UpdateMemView() { for (int i = 0; i < numCPUs; i++) if (memoryWindow[i]) PostDialogMessage(memoryWindow[i], WM_DEB_UPDATE); } -void WindowsHost::UpdateDisassembly() -{ +void WindowsHost::UpdateDisassembly() { for (int i = 0; i < numCPUs; i++) if (disasmWindow[i]) PostDialogMessage(disasmWindow[i], WM_DEB_UPDATE); } -void WindowsHost::SetDebugMode(bool mode) -{ +void WindowsHost::SetDebugMode(bool mode) { for (int i = 0; i < numCPUs; i++) if (disasmWindow[i]) PostDialogMessage(disasmWindow[i], WM_DEB_SETDEBUGLPARAM, 0, (LPARAM)mode); } -void WindowsHost::PollControllers(InputState &input_state) -{ +void WindowsHost::PollControllers(InputState &input_state) { bool doPad = true; for (auto iter = this->input.begin(); iter != this->input.end(); iter++) { @@ -202,8 +208,7 @@ void WindowsHost::PollControllers(InputState &input_state) //if (fabsf(my) > 0.1f) NativeAxis(axisY); } -void WindowsHost::BootDone() -{ +void WindowsHost::BootDone() { symbolMap.SortSymbols(); SendMessage(mainWindow_, WM_USER + 1, 0, 0); @@ -211,16 +216,14 @@ void WindowsHost::BootDone() Core_EnableStepping(!g_Config.bAutoRun); } -static std::string SymbolMapFilename(const char *currentFilename, char* ext) -{ +static std::string SymbolMapFilename(const char *currentFilename, char* ext) { FileInfo info; std::string result = currentFilename; // can't fail, definitely exists if it gets this far getFileInfo(currentFilename, &info); - if (info.isDirectory) - { + if (info.isDirectory) { #ifdef _WIN32 char* slash = "\\"; #else @@ -240,8 +243,7 @@ static std::string SymbolMapFilename(const char *currentFilename, char* ext) } } -bool WindowsHost::AttemptLoadSymbolMap() -{ +bool WindowsHost::AttemptLoadSymbolMap() { bool result1 = symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".ppmap").c_str()); // Load the old-style map file. if (!result1) @@ -250,13 +252,11 @@ bool WindowsHost::AttemptLoadSymbolMap() return result1 || result2; } -void WindowsHost::SaveSymbolMap() -{ +void WindowsHost::SaveSymbolMap() { symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart.c_str(),".ppmap").c_str()); } -bool WindowsHost::IsDebuggingEnabled() -{ +bool WindowsHost::IsDebuggingEnabled() { #ifdef _DEBUG return true; #else @@ -264,24 +264,6 @@ bool WindowsHost::IsDebuggingEnabled() #endif } -void WindowsHost::SetConsolePosition() -{ - HWND console = GetConsoleWindow(); - if (console != NULL && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1) - SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER); -} - -void WindowsHost::UpdateConsolePosition() -{ - RECT rc; - HWND console = GetConsoleWindow(); - if (console != NULL && GetWindowRect(console, &rc) && !IsIconic(console)) - { - g_Config.iConsoleWindowX = rc.left; - g_Config.iConsoleWindowY = rc.top; - } -} - // http://msdn.microsoft.com/en-us/library/aa969393.aspx HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc) { HRESULT hres; diff --git a/ext/native/Android.mk b/ext/native/Android.mk index 5a1c5901a4..7248e605b8 100644 --- a/ext/native/Android.mk +++ b/ext/native/Android.mk @@ -39,7 +39,6 @@ LOCAL_SRC_FILES :=\ ext/vjson/json.cpp \ ext/vjson/block_allocator.cpp \ file/fd_util.cpp \ - file/easy_file.cpp \ file/chunk_file.cpp \ file/file_util.cpp \ file/path.cpp \ diff --git a/ext/native/ext/vjson/json.cpp b/ext/native/ext/vjson/json.cpp index 6dc65bff45..0be8aed2ab 100644 --- a/ext/native/ext/vjson/json.cpp +++ b/ext/native/ext/vjson/json.cpp @@ -2,7 +2,6 @@ #include #include #include "json.h" -#include "file/easy_file.h" #include "file/zip_read.h" #include "file/vfs.h" diff --git a/ext/native/file/CMakeLists.txt b/ext/native/file/CMakeLists.txt index 794d6660c4..26be767209 100644 --- a/ext/native/file/CMakeLists.txt +++ b/ext/native/file/CMakeLists.txt @@ -1,5 +1,4 @@ set(SRCS - easy_file.cpp chunk_file.cpp zip_read.cpp file_util.cpp diff --git a/ext/native/file/chunk_file.cpp b/ext/native/file/chunk_file.cpp index 0e39a9799f..7fb050abb0 100644 --- a/ext/native/file/chunk_file.cpp +++ b/ext/native/file/chunk_file.cpp @@ -1,6 +1,7 @@ #include "base/logging.h" #include "file/chunk_file.h" #include "file/zip_read.h" +#include "file/file_util.h" //#define CHUNKDEBUG @@ -27,12 +28,12 @@ ChunkFile::ChunkFile(const char *filename, bool _read) { return; } - if (file.open(filename, FILE_WRITE)) { - didFail=false; - eof=file.fileSize(); + file = openCFile(filename, "wb"); + if (file) { + didFail = false; + eof = 0; } else { - didFail=true; - return; + didFail = true; } } @@ -48,42 +49,36 @@ ChunkFile::ChunkFile(const uint8_t *read_data, int data_size) { } ChunkFile::~ChunkFile() { - if (fastMode) - delete [] data; - else - file.close(); + if (fastMode) { + delete[] data; + } else { + fclose(file); + } } int ChunkFile::readInt() { if (data && pos +#include #include "base/basictypes.h" -#include "file/easy_file.h" inline uint32_t flipID(uint32_t id) { return ((id>>24)&0xFF) | ((id>>8)&0xFF00) | ((id<<8)&0xFF0000) | ((id<<24)&0xFF000000); @@ -49,7 +48,7 @@ public: private: std::string fn; - LAMEFile file; + FILE *file; struct ChunkInfo { int startLocation; int parentStartLocation; diff --git a/ext/native/file/easy_file.cpp b/ext/native/file/easy_file.cpp deleted file mode 100644 index f34ef45a47..0000000000 --- a/ext/native/file/easy_file.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include - -#include "base/basictypes.h" -#include "file/easy_file.h" - -LAMEFile::LAMEFile() : file_(NULL), isOpen(false), size_(0) { -} - -LAMEFile::~LAMEFile() { } - -bool LAMEFile::open(const char *filename, eFileMode mode) { - file_ = fopen(filename, mode == FILE_READ ? "rb" : "wb"); - - if (!file_) { - isOpen = false; - } else { - isOpen = true; - if (mode == FILE_READ) { - fseek(file_, 0, SEEK_END); - size_ = ftell(file_); - fseek(file_, 0, SEEK_SET); - } - } - return isOpen; -} - -void LAMEFile::close() { - if (isOpen) { - //close the file and reset variables - fclose(file_); - file_ = NULL; - isOpen=false; - } -} - -int LAMEFile::fileSize() { - if (!isOpen) //of course - return 0; - else - return size_; -} - -std::string LAMEFile::readAll() { - std::string s; - size_t size = fileSize(); - s.resize(size); - read(&s[0], size); - return s; -} - -int LAMEFile::write(const void *data, size_t size) { - if (isOpen) { - return (int)fwrite(data, 1, size, file_); //we return the number of bytes that actually got written - } else { - return 0; - } -} - -int LAMEFile::read(void *data, size_t size) { - if (isOpen) { - return (int)fread(data, 1, size, file_); - } else { - return 0; - } -} - -int LAMEFile::readInt() { - int temp; - if (read(&temp, sizeof(int))) - return temp; - else - return 0; -} - -void LAMEFile::writeInt(int i) { - write(&i, sizeof(int)); -} - -char LAMEFile::readChar() { - char temp; - if (read(&temp, sizeof(char))) - return temp; - else - return 0; -} - -void LAMEFile::writeChar(char i) { - write(&i,sizeof(char)); -} diff --git a/ext/native/file/easy_file.h b/ext/native/file/easy_file.h deleted file mode 100644 index fbc439adf9..0000000000 --- a/ext/native/file/easy_file.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -// A dumb wrapper around stdio, for convenience. Very old. - -#include -#include - -#include "base/basictypes.h" - - -// Raw file paths, does not go through VFS. - -enum eFileMode { - FILE_READ=5, - FILE_WRITE=6 -}; - -// TODO: Rename. -class LAMEFile { -public: - LAMEFile(); - virtual ~LAMEFile(); - - bool open(const char *filename, eFileMode mode); - bool open(std::string filename, eFileMode mode) { - return open(filename.c_str(), mode); - } - void close(); - - void writeInt(int i); - void writeChar(char i); - int write(const void *data, size_t size); - void write(const std::string &str) { - write((void *)str.data(), str.size()); - } - - int readInt(); - char readChar(); - int read(void *data, size_t size); - - std::string readAll(); - - int fileSize(); - - void seekBeg(int pos) { - if (isOpen) fseek(file_,pos,SEEK_SET); - } - void seekEnd(int pos) { - if (isOpen) fseek(file_,pos,SEEK_END); - } - void seekCurrent(int pos) { - if (isOpen) fseek(file_,pos,SEEK_CUR); - } -private: - FILE *file_; - bool isOpen; - int size_; -}; diff --git a/ext/native/file/file_util.h b/ext/native/file/file_util.h index 6b659bea9b..37a1ef6073 100644 --- a/ext/native/file/file_util.h +++ b/ext/native/file/file_util.h @@ -29,6 +29,7 @@ std::string getFileExtension(const std::string &fn); std::string getDir(const std::string &path); std::string getFilename(std::string path); bool getFileInfo(const char *path, FileInfo *fileInfo); +FILE *openCFile(const std::string &filename, const char *mode); enum { GETFILES_GETHIDDEN = 1 diff --git a/ext/native/native.vcxproj b/ext/native/native.vcxproj index afa7591ac4..ee844615a8 100644 --- a/ext/native/native.vcxproj +++ b/ext/native/native.vcxproj @@ -220,7 +220,6 @@ - @@ -676,7 +675,6 @@ - diff --git a/ext/native/native.vcxproj.filters b/ext/native/native.vcxproj.filters index 3a2995ac5f..4b855232c5 100644 --- a/ext/native/native.vcxproj.filters +++ b/ext/native/native.vcxproj.filters @@ -63,9 +63,6 @@ file - - file - file @@ -341,9 +338,6 @@ file - - file - file