diff --git a/CMakeLists.txt b/CMakeLists.txt index ebd1b151c0..91f08e233b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -588,8 +588,10 @@ add_library(Common STATIC Common/Data/Random/Rng.h Common/File/VFS/VFS.h Common/File/VFS/VFS.cpp - Common/File/VFS/AssetReader.cpp - Common/File/VFS/AssetReader.h + Common/File/VFS/ZipFileReader.cpp + Common/File/VFS/ZipFileReader.h + Common/File/VFS/DirectoryReader.cpp + Common/File/VFS/DirectoryReader.h Common/File/AndroidStorage.h Common/File/AndroidStorage.cpp Common/File/DiskFree.h @@ -1150,7 +1152,7 @@ elseif(IOS AND NOT LIBRETRO) UI/DarwinFileSystemServices.h Common/Battery/AppleBatteryClient.m ) - + set(nativeExtraLibs ${nativeExtraLibs} "-framework Foundation -framework MediaPlayer -framework AudioToolbox -framework CoreGraphics -framework QuartzCore -framework UIKit -framework GLKit -framework OpenAL -framework AVFoundation -framework CoreLocation -framework CoreVideo -framework CoreMedia -framework CoreServices" ) if(EXISTS "${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks/GameController.framework") set(nativeExtraLibs ${nativeExtraLibs} "-weak_framework GameController") diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 451e8dd426..8557f133d3 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -425,8 +425,9 @@ + - + @@ -861,8 +862,9 @@ + - + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 3c0a310aff..0f40093153 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -176,9 +176,6 @@ File\VFS - - File\VFS - Data\Format @@ -467,6 +464,12 @@ GPU\OpenGL + + File\VFS + + + File\VFS + @@ -628,9 +631,6 @@ File\VFS - - File\VFS - Data\Format @@ -884,6 +884,12 @@ GPU\OpenGL + + File\VFS + + + File\VFS + diff --git a/Common/File/VFS/DirectoryReader.cpp b/Common/File/VFS/DirectoryReader.cpp new file mode 100644 index 0000000000..d979dd4d7c --- /dev/null +++ b/Common/File/VFS/DirectoryReader.cpp @@ -0,0 +1,31 @@ +#include "Common/Common.h" +#include "Common/Log.h" +#include "Common/File/VFS/DirectoryReader.h" + +DirectoryReader::DirectoryReader(const Path &path) { + path_ = path; +} + +uint8_t *DirectoryReader::ReadFile(const char *path, size_t *size) { + Path new_path = Path(path).StartsWith(path_) ? Path(path) : path_ / path; + return File::ReadLocalFile(new_path, size); +} + +bool DirectoryReader::GetFileListing(const char *path, std::vector *listing, const char *filter = nullptr) { + Path new_path = Path(path).StartsWith(path_) ? Path(path) : path_ / path; + + File::FileInfo info; + if (!File::GetFileInfo(new_path, &info)) + return false; + + if (info.isDirectory) { + File::GetFilesInDir(new_path, listing, filter); + return true; + } + return false; +} + +bool DirectoryReader::GetFileInfo(const char *path, File::FileInfo *info) { + Path new_path = Path(path).StartsWith(path_) ? Path(path) : path_ / path; + return File::GetFileInfo(new_path, info); +} diff --git a/Common/File/VFS/DirectoryReader.h b/Common/File/VFS/DirectoryReader.h new file mode 100644 index 0000000000..facd3efe72 --- /dev/null +++ b/Common/File/VFS/DirectoryReader.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Common/File/VFS/VFS.h" +#include "Common/File/FileUtil.h" +#include "Common/File/Path.h" + +class DirectoryReader : public VFSBackend { +public: + explicit DirectoryReader(const Path &path); + // use delete[] on the returned value. + uint8_t *ReadFile(const char *path, size_t *size) override; + bool GetFileListing(const char *path, std::vector *listing, const char *filter) override; + bool GetFileInfo(const char *path, File::FileInfo *info) override; + std::string toString() const override { + return path_.ToString(); + } + +private: + Path path_; +}; + diff --git a/Common/File/VFS/VFS.cpp b/Common/File/VFS/VFS.cpp index e765c9ca78..634f53baa1 100644 --- a/Common/File/VFS/VFS.cpp +++ b/Common/File/VFS/VFS.cpp @@ -1,11 +1,13 @@ +#include + #include "Common/Log.h" #include "Common/File/VFS/VFS.h" -#include "Common/File/VFS/AssetReader.h" +#include "Common/File/FileUtil.h" #include "Common/File/AndroidStorage.h" VFS g_VFS; -void VFS::Register(const char *prefix, AssetReader *reader) { +void VFS::Register(const char *prefix, VFSBackend *reader) { entries_.push_back(VFSEntry{ prefix, reader }); DEBUG_LOG(IO, "Registered VFS for prefix %s: %s", prefix, reader->toString().c_str()); } @@ -45,7 +47,7 @@ uint8_t *VFS::ReadFile(const char *filename, size_t *size) { if (0 == memcmp(filename, entry.prefix, prefix_len)) { fileSystemFound = true; // INFO_LOG(IO, "Prefix match: %s (%s) -> %s", entries[i].prefix, filename, filename + prefix_len); - uint8_t *data = entry.reader->ReadAsset(filename + prefix_len, size); + uint8_t *data = entry.reader->ReadFile(filename + prefix_len, size); if (data) return data; else diff --git a/Common/File/VFS/VFS.h b/Common/File/VFS/VFS.h index 41ac6ae3f9..bd6cc6f3fb 100644 --- a/Common/File/VFS/VFS.h +++ b/Common/File/VFS/VFS.h @@ -14,11 +14,11 @@ // on the system level, like loading assets, and maybe texture packs. Also, as mentioned, // this one is read-only, so a bit smaller and simpler. -class AssetReader { +class VFSBackend { public: - virtual ~AssetReader() {} + virtual ~VFSBackend() {} // use delete[] to release the returned memory. - virtual uint8_t *ReadAsset(const char *path, size_t *size) = 0; + virtual uint8_t *ReadFile(const char *path, size_t *size) = 0; // Filter support is optional but nice to have virtual bool GetFileListing(const char *path, std::vector *listing, const char *filter = 0) = 0; @@ -29,7 +29,7 @@ public: class VFS { public: ~VFS() { Clear(); } - void Register(const char *prefix, AssetReader *reader); + void Register(const char *prefix, VFSBackend *reader); void Clear(); // Use delete [] to release the returned memory. @@ -42,7 +42,7 @@ public: private: struct VFSEntry { const char *prefix; - AssetReader *reader; + VFSBackend *reader; }; std::vector entries_; }; diff --git a/Common/File/VFS/AssetReader.cpp b/Common/File/VFS/ZipFileReader.cpp similarity index 70% rename from Common/File/VFS/AssetReader.cpp rename to Common/File/VFS/ZipFileReader.cpp index 64116703b9..f058deb486 100644 --- a/Common/File/VFS/AssetReader.cpp +++ b/Common/File/VFS/ZipFileReader.cpp @@ -1,7 +1,8 @@ #include #include #include -#include +#include +#include #ifdef SHARED_LIBZIP #include @@ -11,9 +12,9 @@ #include "Common/Common.h" #include "Common/Log.h" -#include "Common/File/VFS/AssetReader.h" +#include "Common/File/VFS/ZipFileReader.h" -uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size) { +static uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size) { // Figure out the file size first. struct zip_stat zstat; zip_file *file = zip_fopen(archive, filename, ZIP_FL_NOCASE|ZIP_FL_UNCHANGED); @@ -32,7 +33,7 @@ uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size) { return contents; } -ZipAssetReader::ZipAssetReader(const char *zip_file, const char *in_zip_path) { +ZipFileReader::ZipFileReader(const char *zip_file, const char *in_zip_path) { zip_file_ = zip_open(zip_file, 0, NULL); strcpy(in_zip_path_, in_zip_path); if (!zip_file_) { @@ -50,24 +51,22 @@ ZipAssetReader::ZipAssetReader(const char *zip_file, const char *in_zip_path) { } } -ZipAssetReader::~ZipAssetReader() { +ZipFileReader::~ZipFileReader() { std::lock_guard guard(lock_); zip_close(zip_file_); } -uint8_t *ZipAssetReader::ReadAsset(const char *path, size_t *size) { - char temp_path[1024]; - strcpy(temp_path, in_zip_path_); - strcat(temp_path, path); +uint8_t *ZipFileReader::ReadFile(const char *path, size_t *size) { + char temp_path[2048]; + snprintf(temp_path, sizeof(temp_path), "%s%s", in_zip_path_, path); std::lock_guard guard(lock_); return ReadFromZip(zip_file_, temp_path, size); } -bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector *listing, const char *filter = 0) { - char path[1024]; - strcpy(path, in_zip_path_); - strcat(path, orig_path); +bool ZipFileReader::GetFileListing(const char *orig_path, std::vector *listing, const char *filter = 0) { + char path[2048]; + snprintf(path, sizeof(path), "%s%s", in_zip_path_, orig_path); std::set filters; std::string tmp; @@ -123,7 +122,7 @@ bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector &files, std::set &directories) { +void ZipFileReader::GetZipListings(const char *path, std::set &files, std::set &directories) { size_t pathlen = strlen(path); if (path[pathlen - 1] == '/') pathlen--; @@ -149,7 +148,7 @@ void ZipAssetReader::GetZipListings(const char *path, std::set &fil } } -bool ZipAssetReader::GetFileInfo(const char *path, File::FileInfo *info) { +bool ZipFileReader::GetFileInfo(const char *path, File::FileInfo *info) { struct zip_stat zstat; char temp_path[1024]; snprintf(temp_path, sizeof(temp_path), "%s%s", in_zip_path_, path); @@ -168,31 +167,3 @@ bool ZipAssetReader::GetFileInfo(const char *path, File::FileInfo *info) { info->size = zstat.size; return true; } - -DirectoryAssetReader::DirectoryAssetReader(const Path &path) { - path_ = path; -} - -uint8_t *DirectoryAssetReader::ReadAsset(const char *path, size_t *size) { - Path new_path = Path(path).StartsWith(path_) ? Path(path) : path_ / path; - return File::ReadLocalFile(new_path, size); -} - -bool DirectoryAssetReader::GetFileListing(const char *path, std::vector *listing, const char *filter = nullptr) { - Path new_path = Path(path).StartsWith(path_) ? Path(path) : path_ / path; - - File::FileInfo info; - if (!File::GetFileInfo(new_path, &info)) - return false; - - if (info.isDirectory) { - File::GetFilesInDir(new_path, listing, filter); - return true; - } - return false; -} - -bool DirectoryAssetReader::GetFileInfo(const char *path, File::FileInfo *info) { - Path new_path = Path(path).StartsWith(path_) ? Path(path) : path_ / path; - return File::GetFileInfo(new_path, info); -} diff --git a/Common/File/VFS/AssetReader.h b/Common/File/VFS/ZipFileReader.h similarity index 51% rename from Common/File/VFS/AssetReader.h rename to Common/File/VFS/ZipFileReader.h index b1ec629725..0480d9673d 100644 --- a/Common/File/VFS/AssetReader.h +++ b/Common/File/VFS/ZipFileReader.h @@ -8,19 +8,18 @@ #include #include -#include #include #include "Common/File/VFS/VFS.h" #include "Common/File/FileUtil.h" #include "Common/File/Path.h" -class ZipAssetReader : public AssetReader { +class ZipFileReader : public VFSBackend { public: - ZipAssetReader(const char *zip_file, const char *in_zip_path); - ~ZipAssetReader(); + ZipFileReader(const char *zip_file, const char *in_zip_path); + ~ZipFileReader(); // use delete[] on the returned value. - uint8_t *ReadAsset(const char *path, size_t *size) override; + uint8_t *ReadFile(const char *path, size_t *size) override; bool GetFileListing(const char *path, std::vector *listing, const char *filter) override; bool GetFileInfo(const char *path, File::FileInfo *info) override; std::string toString() const override { @@ -34,19 +33,3 @@ private: std::mutex lock_; char in_zip_path_[256]; }; - -class DirectoryAssetReader : public AssetReader { -public: - explicit DirectoryAssetReader(const Path &path); - // use delete[] - uint8_t *ReadAsset(const char *path, size_t *size) override; - bool GetFileListing(const char *path, std::vector *listing, const char *filter) override; - bool GetFileInfo(const char *path, File::FileInfo *info) override; - std::string toString() const override { - return path_.ToString(); - } - -private: - Path path_; -}; - diff --git a/Qt/QtMain.h b/Qt/QtMain.h index 0177ca9292..639806bcf5 100644 --- a/Qt/QtMain.h +++ b/Qt/QtMain.h @@ -25,7 +25,7 @@ QTM_USE_NAMESPACE #include "Common/System/Display.h" #include "Common/TimeUtil.h" #include "Common/File/VFS/VFS.h" -#include "Common/File/VFS/AssetReader.h" +#include "Common/File/VFS/DirectoryReader.h" #include "Common/GPU/OpenGL/GLCommon.h" #include "Common/GPU/OpenGL/GLFeatures.h" #include "Common/Input/InputState.h" @@ -191,4 +191,3 @@ private: #endif //SDL #endif - diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 833f8fdd75..e482eca117 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -67,7 +67,8 @@ #include "Common/Profiler/Profiler.h" #include "Common/Data/Encoding/Utf8.h" #include "Common/File/VFS/VFS.h" -#include "Common/File/VFS/AssetReader.h" +#include "Common/File/VFS/ZipFileReader.h" +#include "Common/File/VFS/DirectoryReader.h" #include "Common/CPUDetect.h" #include "Common/File/FileUtil.h" #include "Common/TimeUtil.h" @@ -467,27 +468,27 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch // We want this to be FIRST. #if PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC) // Packed assets are included in app - g_VFS.Register("", new DirectoryAssetReader(Path(external_dir))); + g_VFS.Register("", new DirectoryReader(Path(external_dir))); #endif #if defined(ASSETS_DIR) - g_VFS.Register("", new DirectoryAssetReader(Path(ASSETS_DIR))); + g_VFS.Register("", new DirectoryReader(Path(ASSETS_DIR))); #endif #if !defined(MOBILE_DEVICE) && !defined(_WIN32) && !PPSSPP_PLATFORM(SWITCH) - g_VFS.Register("", new DirectoryAssetReader(File::GetExeDirectory() / "assets")); - g_VFS.Register("", new DirectoryAssetReader(File::GetExeDirectory())); - g_VFS.Register("", new DirectoryAssetReader(Path("/usr/local/share/ppsspp/assets"))); - g_VFS.Register("", new DirectoryAssetReader(Path("/usr/local/share/games/ppsspp/assets"))); - g_VFS.Register("", new DirectoryAssetReader(Path("/usr/share/ppsspp/assets"))); - g_VFS.Register("", new DirectoryAssetReader(Path("/usr/share/games/ppsspp/assets"))); + g_VFS.Register("", new DirectoryReader(File::GetExeDirectory() / "assets")); + g_VFS.Register("", new DirectoryReader(File::GetExeDirectory())); + g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/ppsspp/assets"))); + g_VFS.Register("", new DirectoryReader(Path("/usr/local/share/games/ppsspp/assets"))); + g_VFS.Register("", new DirectoryReader(Path("/usr/share/ppsspp/assets"))); + g_VFS.Register("", new DirectoryReader(Path("/usr/share/games/ppsspp/assets"))); #endif #if PPSSPP_PLATFORM(SWITCH) Path assetPath = Path(user_data_path) / "assets"; - g_VFS.Register("", new DirectoryAssetReader(assetPath)); + g_VFS.Register("", new DirectoryReader(assetPath)); #else - g_VFS.Register("", new DirectoryAssetReader(Path("assets"))); + g_VFS.Register("", new DirectoryReader(Path("assets"))); #endif - g_VFS.Register("", new DirectoryAssetReader(Path(savegame_dir))); + g_VFS.Register("", new DirectoryReader(Path(savegame_dir))); #if (defined(MOBILE_DEVICE) || !defined(USING_QT_UI)) && !PPSSPP_PLATFORM(UWP) if (host == nullptr) { diff --git a/UWP/CommonUWP/CommonUWP.vcxproj b/UWP/CommonUWP/CommonUWP.vcxproj index a0747fc3e9..6160d923d6 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj +++ b/UWP/CommonUWP/CommonUWP.vcxproj @@ -306,7 +306,8 @@ - + + @@ -443,7 +444,8 @@ - + + diff --git a/UWP/CommonUWP/CommonUWP.vcxproj.filters b/UWP/CommonUWP/CommonUWP.vcxproj.filters index f8e8679432..40b8f80da4 100644 --- a/UWP/CommonUWP/CommonUWP.vcxproj.filters +++ b/UWP/CommonUWP/CommonUWP.vcxproj.filters @@ -252,7 +252,10 @@ Data\Format - + + File\VFS + + File\VFS @@ -589,7 +592,10 @@ Data\Format - + + File\VFS + + File\VFS diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index c2995c8711..5fabe3a4e1 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -11,7 +11,7 @@ #include "Common/Common.h" #include "Common/Input/InputState.h" #include "Common/File/VFS/VFS.h" -#include "Common/File/VFS/AssetReader.h" +#include "Common/File/VFS/DirectoryReader.h" #include "Common/Thread/ThreadUtil.h" #include "Common/Data/Encoding/Utf8.h" #include "Common/DirectXHelper.h" @@ -76,8 +76,8 @@ PPSSPP_UWPMain::PPSSPP_UWPMain(App ^app, const std::shared_ptr