diff options
author | Subv <subv2112@gmail.com> | 2015-12-28 16:17:06 +0100 |
---|---|---|
committer | Subv <subv2112@gmail.com> | 2016-03-20 20:28:22 +0100 |
commit | 95b34f8081e26cfe75d63a853d1626fdd5b636e6 (patch) | |
tree | a25b91d70bf84ad71922f63f2f92e37320d2bbfa /src/core/file_sys/disk_archive.cpp | |
parent | HLE/FS: Fixed the OpenDirectory error code (diff) | |
download | yuzu-95b34f8081e26cfe75d63a853d1626fdd5b636e6.tar yuzu-95b34f8081e26cfe75d63a853d1626fdd5b636e6.tar.gz yuzu-95b34f8081e26cfe75d63a853d1626fdd5b636e6.tar.bz2 yuzu-95b34f8081e26cfe75d63a853d1626fdd5b636e6.tar.lz yuzu-95b34f8081e26cfe75d63a853d1626fdd5b636e6.tar.xz yuzu-95b34f8081e26cfe75d63a853d1626fdd5b636e6.tar.zst yuzu-95b34f8081e26cfe75d63a853d1626fdd5b636e6.zip |
Diffstat (limited to 'src/core/file_sys/disk_archive.cpp')
-rw-r--r-- | src/core/file_sys/disk_archive.cpp | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index 2dca895fd..8e4ea01c5 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -17,12 +17,13 @@ namespace FileSys { -std::unique_ptr<FileBackend> DiskArchive::OpenFile(const Path& path, const Mode mode) const { +ResultVal<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); auto file = Common::make_unique<DiskFile>(*this, path, mode); - if (!file->Open()) - return nullptr; - return std::move(file); + ResultCode result = file->Open(); + if (result.IsError()) + return result; + return MakeResult<std::unique_ptr<FileBackend>>(std::move(file)); } ResultCode DiskArchive::DeleteFile(const Path& path) const { @@ -103,25 +104,38 @@ DiskFile::DiskFile(const DiskArchive& archive, const Path& path, const Mode mode this->mode.hex = mode.hex; } -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; +ResultCode DiskFile::Open() { + if (FileUtil::IsDirectory(path)) + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + + // Specifying only the Create flag is invalid + if (mode.create_flag && !mode.read_flag && !mode.write_flag) { + return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); } - 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 + if (!FileUtil::Exists(path)) { + if (!mode.create_flag) { + LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str()); + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); + } else { + // Create the file + FileUtil::CreateEmptyFile(path); + } + } + + std::string mode_string = ""; + if (mode.write_flag) + mode_string += "r+"; // Files opened with Write access can be read from else if (mode.read_flag) - mode_string = "r"; + mode_string += "r"; // Open the file in binary mode, to avoid problems with CR/LF on Windows systems mode_string += "b"; file = Common::make_unique<FileUtil::IOFile>(path, mode_string.c_str()); - return file->IsOpen(); + if (file->IsOpen()) + return RESULT_SUCCESS; + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); } ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { |