diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 0bcce7d16..997e82cc9 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -152,7 +152,7 @@ void GMainWindow::BootGame(const char* filename)
void GMainWindow::OnMenuLoadFile()
{
- QString filename = QFileDialog::getOpenFileName(this, tr("Load file"), QString(), tr("3DS homebrew (*.elf *.axf *.dat *.bin)"));
+ QString filename = QFileDialog::getOpenFileName(this, tr("Load file"), QString(), tr("3DS executable (*.elf *.axf *.cci *.cxi)"));
if (filename.size())
BootGame(filename.toLatin1().data());
}
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 634f4d572..9ee803fda 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -8,6 +8,7 @@ set(SRCS core.cpp
system.cpp
arm/disassembler/arm_disasm.cpp
arm/disassembler/load_symbol_map.cpp
+ file_sys/archive_romfs.cpp
arm/interpreter/arm_interpreter.cpp
arm/interpreter/armcopro.cpp
arm/interpreter/armemu.cpp
@@ -29,17 +30,17 @@ set(SRCS core.cpp
arm/interpreter/mmu/tlb.cpp
arm/interpreter/mmu/wb.cpp
arm/interpreter/mmu/xscale_copro.cpp
- file_sys/directory_file_system.cpp
- file_sys/meta_file_system.cpp
hle/hle.cpp
hle/config_mem.cpp
hle/coprocessor.cpp
hle/svc.cpp
+ hle/kernel/archive.cpp
hle/kernel/event.cpp
hle/kernel/kernel.cpp
hle/kernel/mutex.cpp
hle/kernel/thread.cpp
hle/service/apt.cpp
+ hle/service/fs.cpp
hle/service/gsp.cpp
hle/service/hid.cpp
hle/service/ndm.cpp
@@ -75,18 +76,19 @@ set(HEADERS core.h
arm/interpreter/vfp/asm_vfp.h
arm/interpreter/vfp/vfp.h
arm/interpreter/vfp/vfp_helper.h
- file_sys/directory_file_system.h
- file_sys/file_sys.h
- file_sys/meta_file_system.h
+ file_sys/archive.h
+ file_sys/archive_romfs.h
hle/config_mem.h
hle/coprocessor.h
hle/hle.h
hle/svc.h
+ hle/kernel/archive.h
hle/kernel/kernel.h
hle/kernel/mutex.h
hle/kernel/thread.h
hle/function_wrappers.h
hle/service/apt.h
+ hle/service/fs.h
hle/service/gsp.h
hle/service/hid.h
hle/service/service.h
diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj
index e2216760a..4e521903c 100644
--- a/src/core/core.vcxproj
+++ b/src/core/core.vcxproj
@@ -162,16 +162,17 @@
-
-
+
+
+
@@ -211,18 +212,19 @@
-
-
-
+
+
+
+
diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters
index 91d3292da..17829b8b1 100644
--- a/src/core/core.vcxproj.filters
+++ b/src/core/core.vcxproj.filters
@@ -63,12 +63,6 @@
arm\interpreter
-
- file_sys
-
-
- file_sys
-
hw
@@ -176,6 +170,15 @@
loader
+
+ hle\kernel
+
+
+ hle\service
+
+
+ file_sys
+
@@ -205,15 +208,6 @@
arm\interpreter
-
- file_sys
-
-
- file_sys
-
-
- file_sys
-
hw
@@ -314,6 +308,18 @@
loader
+
+ hle\kernel
+
+
+ hle\service
+
+
+ file_sys
+
+
+ file_sys
+
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
new file mode 100644
index 000000000..ed2d83640
--- /dev/null
+++ b/src/core/file_sys/archive.h
@@ -0,0 +1,54 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "common/common_types.h"
+
+#include "core/hle/kernel/kernel.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// FileSys namespace
+
+namespace FileSys {
+
+class Archive : NonCopyable {
+public:
+ /// Supported archive types
+ enum class IdCode : u32 {
+ RomFS = 0x00000003,
+ SaveData = 0x00000004,
+ ExtSaveData = 0x00000006,
+ SharedExtSaveData = 0x00000007,
+ SystemSaveData = 0x00000008,
+ SDMC = 0x00000009,
+ SDMCWriteOnly = 0x0000000A,
+ };
+
+ Archive() { }
+ virtual ~Archive() { }
+
+ /**
+ * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
+ * @return IdCode of the archive
+ */
+ virtual IdCode GetIdCode() const = 0;
+
+ /**
+ * Read data from the archive
+ * @param offset Offset in bytes to start reading archive from
+ * @param length Length in bytes to read data from archive
+ * @param buffer Buffer to read data into
+ * @return Number of bytes read
+ */
+ virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0;
+
+ /**
+ * Get the size of the archive in bytes
+ * @return Size of the archive in bytes
+ */
+ virtual size_t GetSize() const = 0;
+};
+
+} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
new file mode 100644
index 000000000..fd84b9c8c
--- /dev/null
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -0,0 +1,46 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "common/common_types.h"
+
+#include "core/file_sys/archive_romfs.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// FileSys namespace
+
+namespace FileSys {
+
+Archive_RomFS::Archive_RomFS(const Loader::AppLoader& app_loader) {
+ // Load the RomFS from the app
+ if (Loader::ResultStatus::Success != app_loader.ReadRomFS(raw_data)) {
+ WARN_LOG(FILESYS, "Unable to read RomFS!");
+ }
+}
+
+Archive_RomFS::~Archive_RomFS() {
+}
+
+/**
+ * Read data from the archive
+ * @param offset Offset in bytes to start reading archive from
+ * @param length Length in bytes to read data from archive
+ * @param buffer Buffer to read data into
+ * @return Number of bytes read
+ */
+size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
+ DEBUG_LOG(FILESYS, "called offset=%d, length=%d", offset, length);
+ memcpy(buffer, &raw_data[(u32)offset], length);
+ return length;
+}
+
+/**
+ * Get the size of the archive in bytes
+ * @return Size of the archive in bytes
+ */
+size_t Archive_RomFS::GetSize() const {
+ ERROR_LOG(FILESYS, "(UNIMPLEMENTED)");
+ return 0;
+}
+
+} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
new file mode 100644
index 000000000..8a31190a9
--- /dev/null
+++ b/src/core/file_sys/archive_romfs.h
@@ -0,0 +1,50 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include
+
+#include "common/common_types.h"
+
+#include "core/file_sys/archive.h"
+#include "core/loader/loader.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// FileSys namespace
+
+namespace FileSys {
+
+/// File system interface to the RomFS archive
+class Archive_RomFS final : public Archive {
+public:
+ Archive_RomFS(const Loader::AppLoader& app_loader);
+ ~Archive_RomFS() override;
+
+ /**
+ * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
+ * @return IdCode of the archive
+ */
+ IdCode GetIdCode() const override { return IdCode::RomFS; };
+
+ /**
+ * Read data from the archive
+ * @param offset Offset in bytes to start reading archive from
+ * @param length Length in bytes to read data from archive
+ * @param buffer Buffer to read data into
+ * @return Number of bytes read
+ */
+ size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
+
+ /**
+ * Get the size of the archive in bytes
+ * @return Size of the archive in bytes
+ */
+ size_t GetSize() const override;
+
+private:
+ std::vector raw_data;
+};
+
+} // namespace FileSys
diff --git a/src/core/file_sys/directory_file_system.cpp b/src/core/file_sys/directory_file_system.cpp
deleted file mode 100644
index 6c6f33c2b..000000000
--- a/src/core/file_sys/directory_file_system.cpp
+++ /dev/null
@@ -1,669 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "common/chunk_file.h"
-#include "common/file_util.h"
-#include "common/utf8.h"
-
-#include "core/file_sys/directory_file_system.h"
-
-#if EMU_PLATFORM == PLATFORM_WINDOWS
-#include
-#include
-#else
-#include
-#include
-#include
-#include
-#endif
-
-#if HOST_IS_CASE_SENSITIVE
-static bool FixFilenameCase(const std::string &path, std::string &filename)
-{
- // Are we lucky?
- if (File::Exists(path + filename))
- return true;
-
- size_t filenameSize = filename.size(); // size in bytes, not characters
- for (size_t i = 0; i < filenameSize; i++)
- {
- filename[i] = tolower(filename[i]);
- }
-
- //TODO: lookup filename in cache for "path"
-
- struct dirent_large { struct dirent entry; char padding[FILENAME_MAX+1]; } diren;
- struct dirent_large;
- struct dirent *result = NULL;
-
- DIR *dirp = opendir(path.c_str());
- if (!dirp)
- return false;
-
- bool retValue = false;
-
- while (!readdir_r(dirp, (dirent*) &diren, &result) && result)
- {
- if (strlen(result->d_name) != filenameSize)
- continue;
-
- size_t i;
- for (i = 0; i < filenameSize; i++)
- {
- if (filename[i] != tolower(result->d_name[i]))
- break;
- }
-
- if (i < filenameSize)
- continue;
-
- filename = result->d_name;
- retValue = true;
- }
-
- closedir(dirp);
-
- return retValue;
-}
-
-bool FixPathCase(std::string& basePath, std::string &path, FixPathCaseBehavior behavior)
-{
- size_t len = path.size();
-
- if (len == 0)
- return true;
-
- if (path[len - 1] == '/')
- {
- len--;
-
- if (len == 0)
- return true;
- }
-
- std::string fullPath;
- fullPath.reserve(basePath.size() + len + 1);
- fullPath.append(basePath);
-
- size_t start = 0;
- while (start < len)
- {
- size_t i = path.find('/', start);
- if (i == std::string::npos)
- i = len;
-
- if (i > start)
- {
- std::string component = path.substr(start, i - start);
-
- // Fix case and stop on nonexistant path component
- if (FixFilenameCase(fullPath, component) == false) {
- // Still counts as success if partial matches allowed or if this
- // is the last component and only the ones before it are required
- return (behavior == FPC_PARTIAL_ALLOWED || (behavior == FPC_PATH_MUST_EXIST && i >= len));
- }
-
- path.replace(start, i - start, component);
-
- fullPath.append(component);
- fullPath.append(1, '/');
- }
-
- start = i + 1;
- }
-
- return true;
-}
-
-#endif
-
-std::string DirectoryFileHandle::GetLocalPath(std::string& basePath, std::string localpath)
-{
- if (localpath.empty())
- return basePath;
-
- if (localpath[0] == '/')
- localpath.erase(0,1);
- //Convert slashes
-#ifdef _WIN32
- for (size_t i = 0; i < localpath.size(); i++) {
- if (localpath[i] == '/')
- localpath[i] = '\\';
- }
-#endif
- return basePath + localpath;
-}
-
-bool DirectoryFileHandle::Open(std::string& basePath, std::string& fileName, FileAccess access)
-{
-#if HOST_IS_CASE_SENSITIVE
- if (access & (FILEACCESS_APPEND|FILEACCESS_CREATE|FILEACCESS_WRITE))
- {
- DEBUG_LOG(FILESYS, "Checking case for path %s", fileName.c_str());
- if ( ! FixPathCase(basePath, fileName, FPC_PATH_MUST_EXIST) )
- return false; // or go on and attempt (for a better error code than just 0?)
- }
- // else we try fopen first (in case we're lucky) before simulating case insensitivity
-#endif
-
- std::string fullName = GetLocalPath(basePath,fileName);
- INFO_LOG(FILESYS,"Actually opening %s", fullName.c_str());
-
- //TODO: tests, should append seek to end of file? seeking in a file opened for append?
-#ifdef _WIN32
- // Convert parameters to Windows permissions and access
- DWORD desired = 0;
- DWORD sharemode = 0;
- DWORD openmode = 0;
- if (access & FILEACCESS_READ) {
- desired |= GENERIC_READ;
- sharemode |= FILE_SHARE_READ;
- }
- if (access & FILEACCESS_WRITE) {
- desired |= GENERIC_WRITE;
- sharemode |= FILE_SHARE_WRITE;
- }
- if (access & FILEACCESS_CREATE) {
- openmode = OPEN_ALWAYS;
- } else {
- openmode = OPEN_EXISTING;
- }
- //Let's do it!
- hFile = CreateFile(ConvertUTF8ToWString(fullName).c_str(), desired, sharemode, 0, openmode, 0, 0);
- bool success = hFile != INVALID_HANDLE_VALUE;
-#else
- // Convert flags in access parameter to fopen access mode
- const char *mode = NULL;
- if (access & FILEACCESS_APPEND) {
- if (access & FILEACCESS_READ)
- mode = "ab+"; // append+read, create if needed
- else
- mode = "ab"; // append only, create if needed
- } else if (access & FILEACCESS_WRITE) {
- if (access & FILEACCESS_READ) {
- // FILEACCESS_CREATE is ignored for read only, write only, and append
- // because C++ standard fopen's nonexistant file creation can only be
- // customized for files opened read+write
- if (access & FILEACCESS_CREATE)
- mode = "wb+"; // read+write, create if needed
- else
- mode = "rb+"; // read+write, but don't create
- } else {
- mode = "wb"; // write only, create if needed
- }
- } else { // neither write nor append, so default to read only
- mode = "rb"; // read only, don't create
- }
-
- hFile = fopen(fullName.c_str(), mode);
- bool success = hFile != 0;
-#endif
-
-#if HOST_IS_CASE_SENSITIVE
- if (!success &&
- !(access & FILEACCESS_APPEND) &&
- !(access & FILEACCESS_CREATE) &&
- !(access & FILEACCESS_WRITE))
- {
- if ( ! FixPathCase(basePath,fileName, FPC_PATH_MUST_EXIST) )
- return 0; // or go on and attempt (for a better error code than just 0?)
- fullName = GetLocalPath(basePath,fileName);
- const char* fullNameC = fullName.c_str();
-
- DEBUG_LOG(FILESYS, "Case may have been incorrect, second try opening %s (%s)", fullNameC, fileName.c_str());
-
- // And try again with the correct case this time
-#ifdef _WIN32
- hFile = CreateFile(fullNameC, desired, sharemode, 0, openmode, 0, 0);
- success = hFile != INVALID_HANDLE_VALUE;
-#else
- hFile = fopen(fullNameC, mode);
- success = hFile != 0;
-#endif
- }
-#endif
-
- return success;
-}
-
-size_t DirectoryFileHandle::Read(u8* pointer, s64 size)
-{
- size_t bytesRead = 0;
-#ifdef _WIN32
- ::ReadFile(hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesRead, 0);
-#else
- bytesRead = fread(pointer, 1, size, hFile);
-#endif
- return bytesRead;
-}
-
-size_t DirectoryFileHandle::Write(const u8* pointer, s64 size)
-{
- size_t bytesWritten = 0;
-#ifdef _WIN32
- ::WriteFile(hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesWritten, 0);
-#else
- bytesWritten = fwrite(pointer, 1, size, hFile);
-#endif
- return bytesWritten;
-}
-
-size_t DirectoryFileHandle::Seek(s32 position, FileMove type)
-{
-#ifdef _WIN32
- DWORD moveMethod = 0;
- switch (type) {
- case FILEMOVE_BEGIN: moveMethod = FILE_BEGIN; break;
- case FILEMOVE_CURRENT: moveMethod = FILE_CURRENT; break;
- case FILEMOVE_END: moveMethod = FILE_END; break;
- }
- DWORD newPos = SetFilePointer(hFile, (LONG)position, 0, moveMethod);
- return newPos;
-#else
- int moveMethod = 0;
- switch (type) {
- case FILEMOVE_BEGIN: moveMethod = SEEK_SET; break;
- case FILEMOVE_CURRENT: moveMethod = SEEK_CUR; break;
- case FILEMOVE_END: moveMethod = SEEK_END; break;
- }
- fseek(hFile, position, moveMethod);
- return ftell(hFile);
-#endif
-}
-
-void DirectoryFileHandle::Close()
-{
-#ifdef _WIN32
- if (hFile != (HANDLE)-1)
- CloseHandle(hFile);
-#else
- if (hFile != 0)
- fclose(hFile);
-#endif
-}
-
-DirectoryFileSystem::DirectoryFileSystem(IHandleAllocator *_hAlloc, std::string _basePath) : basePath(_basePath) {
- File::CreateFullPath(basePath);
- hAlloc = _hAlloc;
-}
-
-DirectoryFileSystem::~DirectoryFileSystem() {
- for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
- iter->second.hFile.Close();
- }
-}
-
-std::string DirectoryFileSystem::GetLocalPath(std::string localpath) {
- if (localpath.empty())
- return basePath;
-
- if (localpath[0] == '/')
- localpath.erase(0,1);
- //Convert slashes
-#ifdef _WIN32
- for (size_t i = 0; i < localpath.size(); i++) {
- if (localpath[i] == '/')
- localpath[i] = '\\';
- }
-#endif
- return basePath + localpath;
-}
-
-bool DirectoryFileSystem::MkDir(const std::string &dirname) {
-#if HOST_IS_CASE_SENSITIVE
- // Must fix case BEFORE attempting, because MkDir would create
- // duplicate (different case) directories
-
- std::string fixedCase = dirname;
- if ( ! FixPathCase(basePath,fixedCase, FPC_PARTIAL_ALLOWED) )
- return false;
-
- return File::CreateFullPath(GetLocalPath(fixedCase));
-#else
- return File::CreateFullPath(GetLocalPath(dirname));
-#endif
-}
-
-bool DirectoryFileSystem::RmDir(const std::string &dirname) {
- std::string fullName = GetLocalPath(dirname);
-
-#if HOST_IS_CASE_SENSITIVE
- // Maybe we're lucky?
- if (File::DeleteDirRecursively(fullName))
- return true;
-
- // Nope, fix case and try again
- fullName = dirname;
- if ( ! FixPathCase(basePath,fullName, FPC_FILE_MUST_EXIST) )
- return false; // or go on and attempt (for a better error code than just false?)
-
- fullName = GetLocalPath(fullName);
-#endif
-
-/*#ifdef _WIN32
- return RemoveDirectory(fullName.c_str()) == TRUE;
-#else
- return 0 == rmdir(fullName.c_str());
-#endif*/
- return File::DeleteDirRecursively(fullName);
-}
-
-int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &to) {
- std::string fullTo = to;
-
- // Rename ignores the path (even if specified) on to.
- size_t chop_at = to.find_last_of('/');
- if (chop_at != to.npos)
- fullTo = to.substr(chop_at + 1);
-
- // Now put it in the same directory as from.
- size_t dirname_end = from.find_last_of('/');
- if (dirname_end != from.npos)
- fullTo = from.substr(0, dirname_end + 1) + fullTo;
-
- // At this point, we should check if the paths match and give an already exists error.
- if (from == fullTo)
- return -1;//SCE_KERNEL_ERROR_ERRNO_FILE_ALREADY_EXISTS;
-
- std::string fullFrom = GetLocalPath(from);
-
-#if HOST_IS_CASE_SENSITIVE
- // In case TO should overwrite a file with different case
- if ( ! FixPathCase(basePath,fullTo, FPC_PATH_MUST_EXIST) )
- return -1; // or go on and attempt (for a better error code than just false?)
-#endif
-
- fullTo = GetLocalPath(fullTo);
- const char * fullToC = fullTo.c_str();
-
-#ifdef _WIN32
- bool retValue = (MoveFile(ConvertUTF8ToWString(fullFrom).c_str(), ConvertUTF8ToWString(fullToC).c_str()) == TRUE);
-#else
- bool retValue = (0 == rename(fullFrom.c_str(), fullToC));
-#endif
-
-#if HOST_IS_CASE_SENSITIVE
- if (! retValue)
- {
- // May have failed due to case sensitivity on FROM, so try again
- fullFrom = from;
- if ( ! FixPathCase(basePath,fullFrom, FPC_FILE_MUST_EXIST) )
- return -1; // or go on and attempt (for a better error code than just false?)
- fullFrom = GetLocalPath(fullFrom);
-
-#ifdef _WIN32
- retValue = (MoveFile(fullFrom.c_str(), fullToC) == TRUE);
-#else
- retValue = (0 == rename(fullFrom.c_str(), fullToC));
-#endif
- }
-#endif
-
- // TODO: Better error codes.
- return retValue ? 0 : -1;//SCE_KERNEL_ERROR_ERRNO_FILE_ALREADY_EXISTS;
-}
-
-bool DirectoryFileSystem::RemoveFile(const std::string &filename) {
- std::string fullName = GetLocalPath(filename);
-#ifdef _WIN32
- bool retValue = (::DeleteFileA(fullName.c_str()) == TRUE);
-#else
- bool retValue = (0 == unlink(fullName.c_str()));
-#endif
-
-#if HOST_IS_CASE_SENSITIVE
- if (! retValue)
- {
- // May have failed due to case sensitivity, so try again
- fullName = filename;
- if ( ! FixPathCase(basePath,fullName, FPC_FILE_MUST_EXIST) )
- return false; // or go on and attempt (for a better error code than just false?)
- fullName = GetLocalPath(fullName);
-
-#ifdef _WIN32
- retValue = (::DeleteFileA(fullName.c_str()) == TRUE);
-#else
- retValue = (0 == unlink(fullName.c_str()));
-#endif
- }
-#endif
-
- return retValue;
-}
-
-u32 DirectoryFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) {
- OpenFileEntry entry;
- bool success = entry.hFile.Open(basePath,filename,access);
-
- if (!success) {
-#ifdef _WIN32
- ERROR_LOG(FILESYS, "DirectoryFileSystem::OpenFile: FAILED, %i - access = %i", GetLastError(), (int)access);
-#else
- ERROR_LOG(FILESYS, "DirectoryFileSystem::OpenFile: FAILED, access = %i", (int)access);
-#endif
- //wwwwaaaaahh!!
- return 0;
- } else {
-#ifdef _WIN32
- if (access & FILEACCESS_APPEND)
- entry.hFile.Seek(0,FILEMOVE_END);
-#endif
-
- u32 newHandle = hAlloc->GetNewHandle();
- entries[newHandle] = entry;
-
- return newHandle;
- }
-}
-
-void DirectoryFileSystem::CloseFile(u32 handle) {
- EntryMap::iterator iter = entries.find(handle);
- if (iter != entries.end()) {
- hAlloc->FreeHandle(handle);
- iter->second.hFile.Close();
- entries.erase(iter);
- } else {
- //This shouldn't happen...
- ERROR_LOG(FILESYS,"Cannot close file that hasn't been opened: %08x", handle);
- }
-}
-
-bool DirectoryFileSystem::OwnsHandle(u32 handle) {
- EntryMap::iterator iter = entries.find(handle);
- return (iter != entries.end());
-}
-
-size_t DirectoryFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
- EntryMap::iterator iter = entries.find(handle);
- if (iter != entries.end())
- {
- size_t bytesRead = iter->second.hFile.Read(pointer,size);
- return bytesRead;
- } else {
- //This shouldn't happen...
- ERROR_LOG(FILESYS,"Cannot read file that hasn't been opened: %08x", handle);
- return 0;
- }
-}
-
-size_t DirectoryFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {
- EntryMap::iterator iter = entries.find(handle);
- if (iter != entries.end())
- {
- size_t bytesWritten = iter->second.hFile.Write(pointer,size);
- return bytesWritten;
- } else {
- //This shouldn't happen...
- ERROR_LOG(FILESYS,"Cannot write to file that hasn't been opened: %08x", handle);
- return 0;
- }
-}
-
-size_t DirectoryFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {
- EntryMap::iterator iter = entries.find(handle);
- if (iter != entries.end()) {
- return iter->second.hFile.Seek(position,type);
- } else {
- //This shouldn't happen...
- ERROR_LOG(FILESYS,"Cannot seek in file that hasn't been opened: %08x", handle);
- return 0;
- }
-}
-
-FileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
- FileInfo x;
- x.name = filename;
-
- std::string fullName = GetLocalPath(filename);
- if (! File::Exists(fullName)) {
-#if HOST_IS_CASE_SENSITIVE
- if (! FixPathCase(basePath,filename, FPC_FILE_MUST_EXIST))
- return x;
- fullName = GetLocalPath(filename);
-
- if (! File::Exists(fullName))
- return x;
-#else
- return x;
-#endif
- }
- x.type = File::IsDirectory(fullName) ? FILETYPE_DIRECTORY : FILETYPE_NORMAL;
- x.exists = true;
-
- if (x.type != FILETYPE_DIRECTORY)
- {
-#ifdef _WIN32
- struct _stat64i32 s;
- _wstat64i32(ConvertUTF8ToWString(fullName).c_str(), &s);
-#else
- struct stat s;
- stat(fullName.c_str(), &s);
-#endif
-
- x.size = File::GetSize(fullName);
- x.access = s.st_mode & 0x1FF;
- localtime_r((time_t*)&s.st_atime,&x.atime);
- localtime_r((time_t*)&s.st_ctime,&x.ctime);
- localtime_r((time_t*)&s.st_mtime,&x.mtime);
- }
-
- return x;
-}
-
-bool DirectoryFileSystem::GetHostPath(const std::string &inpath, std::string &outpath) {
- outpath = GetLocalPath(inpath);
- return true;
-}
-
-#ifdef _WIN32
-#define FILETIME_FROM_UNIX_EPOCH_US 11644473600000000ULL
-
-static void tmFromFiletime(tm &dest, FILETIME &src)
-{
- u64 from_1601_us = (((u64) src.dwHighDateTime << 32ULL) + (u64) src.dwLowDateTime) / 10ULL;
- u64 from_1970_us = from_1601_us - FILETIME_FROM_UNIX_EPOCH_US;
-
- time_t t = (time_t) (from_1970_us / 1000000UL);
- localtime_r(&t, &dest);
-}
-#endif
-
-std::vector DirectoryFileSystem::GetDirListing(std::string path) {
- std::vector myVector;
-#ifdef _WIN32
- WIN32_FIND_DATA findData;
- HANDLE hFind;
-
- std::string w32path = GetLocalPath(path) + "\\*.*";
-
- hFind = FindFirstFile(ConvertUTF8ToWString(w32path).c_str(), &findData);
-
- if (hFind == INVALID_HANDLE_VALUE) {
- return myVector; //the empty list
- }
-
- while (true) {
- FileInfo entry;
- if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- entry.type = FILETYPE_DIRECTORY;
- else
- entry.type = FILETYPE_NORMAL;
-
- // TODO: Make this more correct?
- entry.access = entry.type == FILETYPE_NORMAL ? 0666 : 0777;
- // TODO: is this just for .. or all subdirectories? Need to add a directory to the test
- // to find out. Also why so different than the old test results?
- if (!wcscmp(findData.cFileName, L"..") )
- entry.size = 4096;
- else
- entry.size = findData.nFileSizeLow | ((u64)findData.nFileSizeHigh<<32);
- entry.name = ConvertWStringToUTF8(findData.cFileName);
- tmFromFiletime(entry.atime, findData.ftLastAccessTime);
- tmFromFiletime(entry.ctime, findData.ftCreationTime);
- tmFromFiletime(entry.mtime, findData.ftLastWriteTime);
- myVector.push_back(entry);
-
- int retval = FindNextFile(hFind, &findData);
- if (!retval)
- break;
- }
-#else
- dirent *dirp;
- std::string localPath = GetLocalPath(path);
- DIR *dp = opendir(localPath.c_str());
-
-#if HOST_IS_CASE_SENSITIVE
- if(dp == NULL && FixPathCase(basePath,path, FPC_FILE_MUST_EXIST)) {
- // May have failed due to case sensitivity, try again
- localPath = GetLocalPath(path);
- dp = opendir(localPath.c_str());
- }
-#endif
-
- if (dp == NULL) {
- ERROR_LOG(FILESYS,"Error opening directory %s\n",path.c_str());
- return myVector;
- }
-
- while ((dirp = readdir(dp)) != NULL) {
- FileInfo entry;
- struct stat s;
- std::string fullName = GetLocalPath(path) + "/"+dirp->d_name;
- stat(fullName.c_str(), &s);
- if (S_ISDIR(s.st_mode))
- entry.type = FILETYPE_DIRECTORY;
- else
- entry.type = FILETYPE_NORMAL;
- entry.access = s.st_mode & 0x1FF;
- entry.name = dirp->d_name;
- entry.size = s.st_size;
- localtime_r((time_t*)&s.st_atime,&entry.atime);
- localtime_r((time_t*)&s.st_ctime,&entry.ctime);
- localtime_r((time_t*)&s.st_mtime,&entry.mtime);
- myVector.push_back(entry);
- }
- closedir(dp);
-#endif
- return myVector;
-}
-
-void DirectoryFileSystem::DoState(PointerWrap &p) {
- if (!entries.empty()) {
- p.SetError(p.ERROR_WARNING);
- ERROR_LOG(FILESYS, "FIXME: Open files during savestate, could go badly.");
- }
-}
diff --git a/src/core/file_sys/directory_file_system.h b/src/core/file_sys/directory_file_system.h
deleted file mode 100644
index 9af2854a2..000000000
--- a/src/core/file_sys/directory_file_system.h
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#pragma once
-
-// TODO: Remove the Windows-specific code, FILE is fine there too.
-
-#include