Browse Source
Merge pull request #288 from Subv/savedata_stuff
Merge pull request #288 from Subv/savedata_stuff
FS_U: Implemented the SaveData archivepull/15/merge
25 changed files with 458 additions and 490 deletions
-
1src/common/common_paths.h
-
2src/common/file_util.cpp
-
1src/common/file_util.h
-
8src/core/CMakeLists.txt
-
33src/core/file_sys/archive_savedata.cpp
-
32src/core/file_sys/archive_savedata.h
-
83src/core/file_sys/archive_sdmc.cpp
-
66src/core/file_sys/archive_sdmc.h
-
88src/core/file_sys/directory_sdmc.cpp
-
55src/core/file_sys/directory_sdmc.h
-
167src/core/file_sys/disk_archive.cpp
-
101src/core/file_sys/disk_archive.h
-
5src/core/file_sys/file_backend.h
-
2src/core/file_sys/file_romfs.h
-
110src/core/file_sys/file_sdmc.cpp
-
75src/core/file_sys/file_sdmc.h
-
1src/core/hle/kernel/kernel.cpp
-
6src/core/hle/kernel/kernel.h
-
2src/core/hle/result.h
-
51src/core/hle/service/fs/archive.cpp
-
6src/core/hle/service/fs/archive.h
-
42src/core/hle/service/fs/fs_user.cpp
-
1src/core/loader/loader.cpp
-
4src/core/loader/ncch.cpp
-
6src/core/loader/ncch.h
@ -0,0 +1,33 @@ |
|||||
|
// Copyright 2014 Citra Emulator Project
|
||||
|
// Licensed under GPLv2+
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include <sys/stat.h>
|
||||
|
|
||||
|
#include "common/common_types.h"
|
||||
|
#include "common/file_util.h"
|
||||
|
|
||||
|
#include "core/file_sys/archive_savedata.h"
|
||||
|
#include "core/file_sys/disk_archive.h"
|
||||
|
#include "core/settings.h"
|
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
// FileSys namespace
|
||||
|
|
||||
|
namespace FileSys { |
||||
|
|
||||
|
Archive_SaveData::Archive_SaveData(const std::string& mount_point, u64 program_id) |
||||
|
: DiskArchive(mount_point + Common::StringFromFormat("%016X", program_id) + DIR_SEP) { |
||||
|
LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str()); |
||||
|
} |
||||
|
|
||||
|
bool Archive_SaveData::Initialize() { |
||||
|
if (!FileUtil::CreateFullPath(mount_point)) { |
||||
|
LOG_ERROR(Service_FS, "Unable to create SaveData path."); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} // namespace FileSys
|
||||
@ -0,0 +1,32 @@ |
|||||
|
// Copyright 2014 Citra Emulator Project |
||||
|
// Licensed under GPLv2+ |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "common/common_types.h" |
||||
|
|
||||
|
#include "core/file_sys/disk_archive.h" |
||||
|
#include "core/loader/loader.h" |
||||
|
|
||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////// |
||||
|
// FileSys namespace |
||||
|
|
||||
|
namespace FileSys { |
||||
|
|
||||
|
/// File system interface to the SaveData archive |
||||
|
class Archive_SaveData final : public DiskArchive { |
||||
|
public: |
||||
|
Archive_SaveData(const std::string& mount_point, u64 program_id); |
||||
|
|
||||
|
/** |
||||
|
* Initialize the archive. |
||||
|
* @return CreateSaveDataResult AlreadyExists if the SaveData folder already exists, |
||||
|
* Success if it was created properly and Failure if there was any error |
||||
|
*/ |
||||
|
bool Initialize(); |
||||
|
|
||||
|
std::string GetName() const override { return "SaveData"; } |
||||
|
}; |
||||
|
|
||||
|
} // namespace FileSys |
||||
@ -1,88 +0,0 @@ |
|||||
// Copyright 2014 Citra Emulator Project
|
|
||||
// Licensed under GPLv2
|
|
||||
// Refer to the license.txt file included.
|
|
||||
|
|
||||
#include <sys/stat.h>
|
|
||||
|
|
||||
#include "common/common_types.h"
|
|
||||
#include "common/file_util.h"
|
|
||||
|
|
||||
#include "core/file_sys/directory_sdmc.h"
|
|
||||
#include "core/file_sys/archive_sdmc.h"
|
|
||||
|
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||
// FileSys namespace
|
|
||||
|
|
||||
namespace FileSys { |
|
||||
|
|
||||
Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const Path& path) { |
|
||||
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
|
||||
// the root directory we set while opening the archive.
|
|
||||
// For example, opening /../../usr/bin can give the emulated program your installed programs.
|
|
||||
this->path = archive->GetMountPoint() + path.AsString(); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
Directory_SDMC::~Directory_SDMC() { |
|
||||
Close(); |
|
||||
} |
|
||||
|
|
||||
bool Directory_SDMC::Open() { |
|
||||
if (!FileUtil::IsDirectory(path)) |
|
||||
return false; |
|
||||
FileUtil::ScanDirectoryTree(path, directory); |
|
||||
children_iterator = directory.children.begin(); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* List files contained in the directory |
|
||||
* @param count Number of entries to return at once in entries |
|
||||
* @param entries Buffer to read data into |
|
||||
* @return Number of entries listed |
|
||||
*/ |
|
||||
u32 Directory_SDMC::Read(const u32 count, Entry* entries) { |
|
||||
u32 entries_read = 0; |
|
||||
|
|
||||
while (entries_read < count && children_iterator != directory.children.cend()) { |
|
||||
const FileUtil::FSTEntry& file = *children_iterator; |
|
||||
const std::string& filename = file.virtualName; |
|
||||
Entry& entry = entries[entries_read]; |
|
||||
|
|
||||
LOG_TRACE(Service_FS, "File %s: size=%llu dir=%d", filename.c_str(), file.size, file.isDirectory); |
|
||||
|
|
||||
// TODO(Link Mauve): use a proper conversion to UTF-16.
|
|
||||
for (size_t j = 0; j < FILENAME_LENGTH; ++j) { |
|
||||
entry.filename[j] = filename[j]; |
|
||||
if (!filename[j]) |
|
||||
break; |
|
||||
} |
|
||||
|
|
||||
FileUtil::SplitFilename83(filename, entry.short_name, entry.extension); |
|
||||
|
|
||||
entry.is_directory = file.isDirectory; |
|
||||
entry.is_hidden = (filename[0] == '.'); |
|
||||
entry.is_read_only = 0; |
|
||||
entry.file_size = file.size; |
|
||||
|
|
||||
// We emulate a SD card where the archive bit has never been cleared, as it would be on
|
|
||||
// most user SD cards.
|
|
||||
// Some homebrews (blargSNES for instance) are known to mistakenly use the archive bit as a
|
|
||||
// file bit.
|
|
||||
entry.is_archive = !file.isDirectory; |
|
||||
|
|
||||
++entries_read; |
|
||||
++children_iterator; |
|
||||
} |
|
||||
return entries_read; |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* Close the directory |
|
||||
* @return true if the directory closed correctly |
|
||||
*/ |
|
||||
bool Directory_SDMC::Close() const { |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
} // namespace FileSys
|
|
||||
@ -1,55 +0,0 @@ |
|||||
// Copyright 2014 Citra Emulator Project |
|
||||
// Licensed under GPLv2 |
|
||||
// Refer to the license.txt file included. |
|
||||
|
|
||||
#pragma once |
|
||||
|
|
||||
#include "common/common_types.h" |
|
||||
#include "common/file_util.h" |
|
||||
|
|
||||
#include "core/file_sys/directory_backend.h" |
|
||||
#include "core/file_sys/archive_sdmc.h" |
|
||||
#include "core/loader/loader.h" |
|
||||
|
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////// |
|
||||
// FileSys namespace |
|
||||
|
|
||||
namespace FileSys { |
|
||||
|
|
||||
class Directory_SDMC final : public DirectoryBackend { |
|
||||
public: |
|
||||
Directory_SDMC(); |
|
||||
Directory_SDMC(const Archive_SDMC* archive, const Path& path); |
|
||||
~Directory_SDMC() override; |
|
||||
|
|
||||
/** |
|
||||
* Open the directory |
|
||||
* @return true if the directory opened correctly |
|
||||
*/ |
|
||||
bool Open() override; |
|
||||
|
|
||||
/** |
|
||||
* List files contained in the directory |
|
||||
* @param count Number of entries to return at once in entries |
|
||||
* @param entries Buffer to read data into |
|
||||
* @return Number of entries listed |
|
||||
*/ |
|
||||
u32 Read(const u32 count, Entry* entries) override; |
|
||||
|
|
||||
/** |
|
||||
* Close the directory |
|
||||
* @return true if the directory closed correctly |
|
||||
*/ |
|
||||
bool Close() const override; |
|
||||
|
|
||||
private: |
|
||||
std::string path; |
|
||||
u32 total_entries_in_directory; |
|
||||
FileUtil::FSTEntry directory; |
|
||||
|
|
||||
// We need to remember the last entry we returned, so a subsequent call to Read will continue |
|
||||
// from the next one. This iterator will always point to the next unread entry. |
|
||||
std::vector<FileUtil::FSTEntry>::iterator children_iterator; |
|
||||
}; |
|
||||
|
|
||||
} // namespace FileSys |
|
||||
@ -0,0 +1,167 @@ |
|||||
|
// Copyright 2014 Citra Emulator Project
|
||||
|
// Licensed under GPLv2
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include <sys/stat.h>
|
||||
|
|
||||
|
#include "common/common_types.h"
|
||||
|
#include "common/file_util.h"
|
||||
|
|
||||
|
#include "core/file_sys/disk_archive.h"
|
||||
|
#include "core/settings.h"
|
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
// FileSys namespace
|
||||
|
|
||||
|
namespace FileSys { |
||||
|
|
||||
|
std::unique_ptr<FileBackend> DiskArchive::OpenFile(const Path& path, const Mode mode) const { |
||||
|
LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex); |
||||
|
DiskFile* file = new DiskFile(this, path, mode); |
||||
|
if (!file->Open()) |
||||
|
return nullptr; |
||||
|
return std::unique_ptr<FileBackend>(file); |
||||
|
} |
||||
|
|
||||
|
bool DiskArchive::DeleteFile(const FileSys::Path& path) const { |
||||
|
return FileUtil::Delete(GetMountPoint() + path.AsString()); |
||||
|
} |
||||
|
|
||||
|
bool DiskArchive::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { |
||||
|
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString()); |
||||
|
} |
||||
|
|
||||
|
bool DiskArchive::DeleteDirectory(const FileSys::Path& path) const { |
||||
|
return FileUtil::DeleteDir(GetMountPoint() + path.AsString()); |
||||
|
} |
||||
|
|
||||
|
bool DiskArchive::CreateDirectory(const Path& path) const { |
||||
|
return FileUtil::CreateDir(GetMountPoint() + path.AsString()); |
||||
|
} |
||||
|
|
||||
|
bool DiskArchive::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { |
||||
|
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString()); |
||||
|
} |
||||
|
|
||||
|
std::unique_ptr<DirectoryBackend> DiskArchive::OpenDirectory(const Path& path) const { |
||||
|
LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str()); |
||||
|
DiskDirectory* directory = new DiskDirectory(this, path); |
||||
|
if (!directory->Open()) |
||||
|
return nullptr; |
||||
|
return std::unique_ptr<DirectoryBackend>(directory); |
||||
|
} |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
||||
|
DiskFile::DiskFile(const DiskArchive* archive, const Path& path, const Mode mode) { |
||||
|
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
||||
|
// the root directory we set while opening the archive.
|
||||
|
// For example, opening /../../etc/passwd can give the emulated program your users list.
|
||||
|
this->path = archive->GetMountPoint() + path.AsString(); |
||||
|
this->mode.hex = mode.hex; |
||||
|
this->archive = archive; |
||||
|
} |
||||
|
|
||||
|
bool DiskFile::Open() { |
||||
|
if (!mode.create_flag && !FileUtil::Exists(path)) { |
||||
|
LOG_ERROR(Service_FS, "Non-existing file %s can’t be open without mode create.", path.c_str()); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
std::string mode_string; |
||||
|
if (mode.create_flag) |
||||
|
mode_string = "w+"; |
||||
|
else if (mode.write_flag) |
||||
|
mode_string = "r+"; // Files opened with Write access can be read from
|
||||
|
else if (mode.read_flag) |
||||
|
mode_string = "r"; |
||||
|
|
||||
|
// Open the file in binary mode, to avoid problems with CR/LF on Windows systems
|
||||
|
mode_string += "b"; |
||||
|
|
||||
|
file = new FileUtil::IOFile(path, mode_string.c_str()); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
size_t DiskFile::Read(const u64 offset, const u32 length, u8* buffer) const { |
||||
|
file->Seek(offset, SEEK_SET); |
||||
|
return file->ReadBytes(buffer, length); |
||||
|
} |
||||
|
|
||||
|
size_t DiskFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { |
||||
|
file->Seek(offset, SEEK_SET); |
||||
|
size_t written = file->WriteBytes(buffer, length); |
||||
|
if (flush) |
||||
|
file->Flush(); |
||||
|
return written; |
||||
|
} |
||||
|
|
||||
|
size_t DiskFile::GetSize() const { |
||||
|
return static_cast<size_t>(file->GetSize()); |
||||
|
} |
||||
|
|
||||
|
bool DiskFile::SetSize(const u64 size) const { |
||||
|
file->Resize(size); |
||||
|
file->Flush(); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool DiskFile::Close() const { |
||||
|
return file->Close(); |
||||
|
} |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
||||
|
DiskDirectory::DiskDirectory(const DiskArchive* archive, const Path& path) { |
||||
|
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
||||
|
// the root directory we set while opening the archive.
|
||||
|
// For example, opening /../../usr/bin can give the emulated program your installed programs.
|
||||
|
this->path = archive->GetMountPoint() + path.AsString(); |
||||
|
this->archive = archive; |
||||
|
} |
||||
|
|
||||
|
bool DiskDirectory::Open() { |
||||
|
if (!FileUtil::IsDirectory(path)) |
||||
|
return false; |
||||
|
FileUtil::ScanDirectoryTree(path, directory); |
||||
|
children_iterator = directory.children.begin(); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
u32 DiskDirectory::Read(const u32 count, Entry* entries) { |
||||
|
u32 entries_read = 0; |
||||
|
|
||||
|
while (entries_read < count && children_iterator != directory.children.cend()) { |
||||
|
const FileUtil::FSTEntry& file = *children_iterator; |
||||
|
const std::string& filename = file.virtualName; |
||||
|
Entry& entry = entries[entries_read]; |
||||
|
|
||||
|
LOG_TRACE(Service_FS, "File %s: size=%llu dir=%d", filename.c_str(), file.size, file.isDirectory); |
||||
|
|
||||
|
// TODO(Link Mauve): use a proper conversion to UTF-16.
|
||||
|
for (size_t j = 0; j < FILENAME_LENGTH; ++j) { |
||||
|
entry.filename[j] = filename[j]; |
||||
|
if (!filename[j]) |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
FileUtil::SplitFilename83(filename, entry.short_name, entry.extension); |
||||
|
|
||||
|
entry.is_directory = file.isDirectory; |
||||
|
entry.is_hidden = (filename[0] == '.'); |
||||
|
entry.is_read_only = 0; |
||||
|
entry.file_size = file.size; |
||||
|
|
||||
|
// We emulate a SD card where the archive bit has never been cleared, as it would be on
|
||||
|
// most user SD cards.
|
||||
|
// Some homebrews (blargSNES for instance) are known to mistakenly use the archive bit as a
|
||||
|
// file bit.
|
||||
|
entry.is_archive = !file.isDirectory; |
||||
|
|
||||
|
++entries_read; |
||||
|
++children_iterator; |
||||
|
} |
||||
|
return entries_read; |
||||
|
} |
||||
|
|
||||
|
} // namespace FileSys
|
||||
@ -0,0 +1,101 @@ |
|||||
|
// Copyright 2014 Citra Emulator Project |
||||
|
// Licensed under GPLv2 |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "common/common_types.h" |
||||
|
|
||||
|
#include "core/file_sys/archive_backend.h" |
||||
|
#include "core/loader/loader.h" |
||||
|
|
||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////// |
||||
|
// FileSys namespace |
||||
|
|
||||
|
namespace FileSys { |
||||
|
|
||||
|
/** |
||||
|
* Helper which implements a backend accessing the host machine's filesystem. |
||||
|
* This should be subclassed by concrete archive types, which will provide the |
||||
|
* base directory on the host filesystem and override any required functionality. |
||||
|
*/ |
||||
|
class DiskArchive : public ArchiveBackend { |
||||
|
public: |
||||
|
DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {} |
||||
|
|
||||
|
virtual std::string GetName() const = 0; |
||||
|
std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; |
||||
|
bool DeleteFile(const FileSys::Path& path) const override; |
||||
|
bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; |
||||
|
bool DeleteDirectory(const FileSys::Path& path) const override; |
||||
|
bool CreateDirectory(const Path& path) const override; |
||||
|
bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; |
||||
|
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; |
||||
|
|
||||
|
/** |
||||
|
* Getter for the path used for this Archive |
||||
|
* @return Mount point of that passthrough archive |
||||
|
*/ |
||||
|
const std::string& GetMountPoint() const { |
||||
|
return mount_point; |
||||
|
} |
||||
|
|
||||
|
protected: |
||||
|
std::string mount_point; |
||||
|
}; |
||||
|
|
||||
|
class DiskFile : public FileBackend { |
||||
|
public: |
||||
|
DiskFile(); |
||||
|
DiskFile(const DiskArchive* archive, const Path& path, const Mode mode); |
||||
|
|
||||
|
~DiskFile() override { |
||||
|
Close(); |
||||
|
} |
||||
|
|
||||
|
bool Open() override; |
||||
|
size_t Read(const u64 offset, const u32 length, u8* buffer) const override; |
||||
|
size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override; |
||||
|
size_t GetSize() const override; |
||||
|
bool SetSize(const u64 size) const override; |
||||
|
bool Close() const override; |
||||
|
|
||||
|
void Flush() const override { |
||||
|
file->Flush(); |
||||
|
} |
||||
|
|
||||
|
protected: |
||||
|
const DiskArchive* archive; |
||||
|
std::string path; |
||||
|
Mode mode; |
||||
|
FileUtil::IOFile* file; |
||||
|
}; |
||||
|
|
||||
|
class DiskDirectory : public DirectoryBackend { |
||||
|
public: |
||||
|
DiskDirectory(); |
||||
|
DiskDirectory(const DiskArchive* archive, const Path& path); |
||||
|
|
||||
|
~DiskDirectory() override { |
||||
|
Close(); |
||||
|
} |
||||
|
|
||||
|
bool Open() override; |
||||
|
u32 Read(const u32 count, Entry* entries) override; |
||||
|
|
||||
|
bool Close() const override { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
protected: |
||||
|
const DiskArchive* archive; |
||||
|
std::string path; |
||||
|
u32 total_entries_in_directory; |
||||
|
FileUtil::FSTEntry directory; |
||||
|
|
||||
|
// We need to remember the last entry we returned, so a subsequent call to Read will continue |
||||
|
// from the next one. This iterator will always point to the next unread entry. |
||||
|
std::vector<FileUtil::FSTEntry>::iterator children_iterator; |
||||
|
}; |
||||
|
|
||||
|
} // namespace FileSys |
||||
@ -1,110 +0,0 @@ |
|||||
// Copyright 2014 Citra Emulator Project
|
|
||||
// Licensed under GPLv2
|
|
||||
// Refer to the license.txt file included.
|
|
||||
|
|
||||
#include <sys/stat.h>
|
|
||||
|
|
||||
#include "common/common_types.h"
|
|
||||
#include "common/file_util.h"
|
|
||||
|
|
||||
#include "core/file_sys/file_sdmc.h"
|
|
||||
#include "core/file_sys/archive_sdmc.h"
|
|
||||
|
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||
// FileSys namespace
|
|
||||
|
|
||||
namespace FileSys { |
|
||||
|
|
||||
File_SDMC::File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode) { |
|
||||
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
|
||||
// the root directory we set while opening the archive.
|
|
||||
// For example, opening /../../etc/passwd can give the emulated program your users list.
|
|
||||
this->path = archive->GetMountPoint() + path.AsString(); |
|
||||
this->mode.hex = mode.hex; |
|
||||
} |
|
||||
|
|
||||
File_SDMC::~File_SDMC() { |
|
||||
Close(); |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* Open the file |
|
||||
* @return true if the file opened correctly |
|
||||
*/ |
|
||||
bool File_SDMC::Open() { |
|
||||
if (!mode.create_flag && !FileUtil::Exists(path)) { |
|
||||
LOG_ERROR(Service_FS, "Non-existing file %s can’t be open without mode create.", path.c_str()); |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
std::string mode_string; |
|
||||
if (mode.create_flag) |
|
||||
mode_string = "w+"; |
|
||||
else if (mode.write_flag) |
|
||||
mode_string = "r+"; // Files opened with Write access can be read from
|
|
||||
else if (mode.read_flag) |
|
||||
mode_string = "r"; |
|
||||
|
|
||||
// Open the file in binary mode, to avoid problems with CR/LF on Windows systems
|
|
||||
mode_string += "b"; |
|
||||
|
|
||||
file = new FileUtil::IOFile(path, mode_string.c_str()); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* Read data from the file |
|
||||
* @param offset Offset in bytes to start reading data from |
|
||||
* @param length Length in bytes of data to read from file |
|
||||
* @param buffer Buffer to read data into |
|
||||
* @return Number of bytes read |
|
||||
*/ |
|
||||
size_t File_SDMC::Read(const u64 offset, const u32 length, u8* buffer) const { |
|
||||
file->Seek(offset, SEEK_SET); |
|
||||
return file->ReadBytes(buffer, length); |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* Write data to the file |
|
||||
* @param offset Offset in bytes to start writing data to |
|
||||
* @param length Length in bytes of data to write to file |
|
||||
* @param flush The flush parameters (0 == do not flush) |
|
||||
* @param buffer Buffer to read data from |
|
||||
* @return Number of bytes written |
|
||||
*/ |
|
||||
size_t File_SDMC::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { |
|
||||
file->Seek(offset, SEEK_SET); |
|
||||
size_t written = file->WriteBytes(buffer, length); |
|
||||
if (flush) |
|
||||
file->Flush(); |
|
||||
return written; |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* Get the size of the file in bytes |
|
||||
* @return Size of the file in bytes |
|
||||
*/ |
|
||||
size_t File_SDMC::GetSize() const { |
|
||||
return static_cast<size_t>(file->GetSize()); |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* Set the size of the file in bytes |
|
||||
* @param size New size of the file |
|
||||
* @return true if successful |
|
||||
*/ |
|
||||
bool File_SDMC::SetSize(const u64 size) const { |
|
||||
file->Resize(size); |
|
||||
file->Flush(); |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
/**
|
|
||||
* Close the file |
|
||||
* @return true if the file closed correctly |
|
||||
*/ |
|
||||
bool File_SDMC::Close() const { |
|
||||
return file->Close(); |
|
||||
} |
|
||||
|
|
||||
} // namespace FileSys
|
|
||||
@ -1,75 +0,0 @@ |
|||||
// Copyright 2014 Citra Emulator Project |
|
||||
// Licensed under GPLv2 |
|
||||
// Refer to the license.txt file included. |
|
||||
|
|
||||
#pragma once |
|
||||
|
|
||||
#include "common/common_types.h" |
|
||||
#include "common/file_util.h" |
|
||||
|
|
||||
#include "core/file_sys/file_backend.h" |
|
||||
#include "core/file_sys/archive_sdmc.h" |
|
||||
#include "core/loader/loader.h" |
|
||||
|
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////// |
|
||||
// FileSys namespace |
|
||||
|
|
||||
namespace FileSys { |
|
||||
|
|
||||
class File_SDMC final : public FileBackend { |
|
||||
public: |
|
||||
File_SDMC(); |
|
||||
File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode); |
|
||||
~File_SDMC() override; |
|
||||
|
|
||||
/** |
|
||||
* Open the file |
|
||||
* @return true if the file opened correctly |
|
||||
*/ |
|
||||
bool Open() override; |
|
||||
|
|
||||
/** |
|
||||
* Read data from the file |
|
||||
* @param offset Offset in bytes to start reading data from |
|
||||
* @param length Length in bytes of data to read from file |
|
||||
* @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; |
|
||||
|
|
||||
/** |
|
||||
* Write data to the file |
|
||||
* @param offset Offset in bytes to start writing data to |
|
||||
* @param length Length in bytes of data to write to file |
|
||||
* @param flush The flush parameters (0 == do not flush) |
|
||||
* @param buffer Buffer to read data from |
|
||||
* @return Number of bytes written |
|
||||
*/ |
|
||||
size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override; |
|
||||
|
|
||||
/** |
|
||||
* Get the size of the file in bytes |
|
||||
* @return Size of the file in bytes |
|
||||
*/ |
|
||||
size_t GetSize() const override; |
|
||||
|
|
||||
/** |
|
||||
* Set the size of the file in bytes |
|
||||
* @param size New size of the file |
|
||||
* @return true if successful |
|
||||
*/ |
|
||||
bool SetSize(const u64 size) const override; |
|
||||
|
|
||||
/** |
|
||||
* Close the file |
|
||||
* @return true if the file closed correctly |
|
||||
*/ |
|
||||
bool Close() const override; |
|
||||
|
|
||||
private: |
|
||||
std::string path; |
|
||||
Mode mode; |
|
||||
FileUtil::IOFile* file; |
|
||||
}; |
|
||||
|
|
||||
} // namespace FileSys |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue