summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar wwylele2016-10-18 17:27:51 +0800
committerGravatar wwylele2016-11-19 18:55:34 +0200
commit098778369962f8ec5eba6ccc91b2846c72cb0005 (patch)
treea07c47167884f8837448efb9ff7de9fe3f5c0f61 /src/core/file_sys
parentFileSys: add SDMCArchive (diff)
downloadyuzu-098778369962f8ec5eba6ccc91b2846c72cb0005.tar.gz
yuzu-098778369962f8ec5eba6ccc91b2846c72cb0005.tar.xz
yuzu-098778369962f8ec5eba6ccc91b2846c72cb0005.zip
FileSys: add SDMCWriteOnlyArchive
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_sdmcwriteonly.cpp70
-rw-r--r--src/core/file_sys/archive_sdmcwriteonly.h57
-rw-r--r--src/core/file_sys/errors.h2
3 files changed, 129 insertions, 0 deletions
diff --git a/src/core/file_sys/archive_sdmcwriteonly.cpp b/src/core/file_sys/archive_sdmcwriteonly.cpp
new file mode 100644
index 000000000..64ae49b86
--- /dev/null
+++ b/src/core/file_sys/archive_sdmcwriteonly.cpp
@@ -0,0 +1,70 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <memory>
6#include "common/file_util.h"
7#include "core/file_sys/archive_sdmcwriteonly.h"
8#include "core/file_sys/directory_backend.h"
9#include "core/file_sys/errors.h"
10#include "core/file_sys/file_backend.h"
11#include "core/settings.h"
12
13////////////////////////////////////////////////////////////////////////////////////////////////////
14// FileSys namespace
15
16namespace FileSys {
17
18ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Path& path,
19 const Mode& mode) const {
20 if (mode.read_flag) {
21 LOG_ERROR(Service_FS, "Read flag is not supported");
22 return ERROR_INVALID_READ_FLAG;
23 }
24 return SDMCArchive::OpenFile(path, mode);
25}
26
27ResultVal<std::unique_ptr<DirectoryBackend>> SDMCWriteOnlyArchive::OpenDirectory(
28 const Path& path) const {
29 LOG_ERROR(Service_FS, "Not supported");
30 return ERROR_UNSUPPORTED_OPEN_FLAGS;
31}
32
33ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point)
34 : sdmc_directory(mount_point) {
35 LOG_INFO(Service_FS, "Directory %s set as SDMCWriteOnly.", sdmc_directory.c_str());
36}
37
38bool ArchiveFactory_SDMCWriteOnly::Initialize() {
39 if (!Settings::values.use_virtual_sd) {
40 LOG_WARNING(Service_FS, "SDMC disabled by config.");
41 return false;
42 }
43
44 if (!FileUtil::CreateFullPath(sdmc_directory)) {
45 LOG_ERROR(Service_FS, "Unable to create SDMC path.");
46 return false;
47 }
48
49 return true;
50}
51
52ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMCWriteOnly::Open(const Path& path) {
53 auto archive = std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory);
54 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
55}
56
57ResultCode ArchiveFactory_SDMCWriteOnly::Format(const Path& path,
58 const FileSys::ArchiveFormatInfo& format_info) {
59 // TODO(wwylele): hwtest this
60 LOG_ERROR(Service_FS, "Attempted to format a SDMC write-only archive.");
61 return ResultCode(-1);
62}
63
64ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const Path& path) const {
65 // TODO(Subv): Implement
66 LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str());
67 return ResultCode(-1);
68}
69
70} // namespace FileSys
diff --git a/src/core/file_sys/archive_sdmcwriteonly.h b/src/core/file_sys/archive_sdmcwriteonly.h
new file mode 100644
index 000000000..ed977485a
--- /dev/null
+++ b/src/core/file_sys/archive_sdmcwriteonly.h
@@ -0,0 +1,57 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/file_sys/archive_sdmc.h"
8
9////////////////////////////////////////////////////////////////////////////////////////////////////
10// FileSys namespace
11
12namespace FileSys {
13
14/**
15 * Archive backend for SDMC write-only archive.
16 * The behaviour of SDMCWriteOnlyArchive is almost the same as SDMCArchive, except for
17 * - OpenDirectory is unsupported;
18 * - OpenFile with read flag is unsupported.
19 */
20class SDMCWriteOnlyArchive : public SDMCArchive {
21public:
22 SDMCWriteOnlyArchive(const std::string& mount_point) : SDMCArchive(mount_point) {}
23
24 std::string GetName() const override {
25 return "SDMCWriteOnlyArchive: " + mount_point;
26 }
27
28 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
29 const Mode& mode) const override;
30
31 ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
32};
33
34/// File system interface to the SDMC write-only archive
35class ArchiveFactory_SDMCWriteOnly final : public ArchiveFactory {
36public:
37 ArchiveFactory_SDMCWriteOnly(const std::string& mount_point);
38
39 /**
40 * Initialize the archive.
41 * @return true if it initialized successfully
42 */
43 bool Initialize();
44
45 std::string GetName() const override {
46 return "SDMCWriteOnly";
47 }
48
49 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
50 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
51 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
52
53private:
54 std::string sdmc_directory;
55};
56
57} // namespace FileSys
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h
index f9299364c..fd1b07df0 100644
--- a/src/core/file_sys/errors.h
+++ b/src/core/file_sys/errors.h
@@ -13,6 +13,8 @@ const ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrorDescription::FS_UnsupportedOp
13 ErrorLevel::Usage); 13 ErrorLevel::Usage);
14const ResultCode ERROR_INVALID_OPEN_FLAGS(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, 14const ResultCode ERROR_INVALID_OPEN_FLAGS(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS,
15 ErrorSummary::Canceled, ErrorLevel::Status); 15 ErrorSummary::Canceled, ErrorLevel::Status);
16const ResultCode ERROR_INVALID_READ_FLAG(ErrorDescription::FS_InvalidReadFlag, ErrorModule::FS,
17 ErrorSummary::InvalidArgument, ErrorLevel::Usage);
16const ResultCode ERROR_FILE_NOT_FOUND(ErrorDescription::FS_FileNotFound, ErrorModule::FS, 18const ResultCode ERROR_FILE_NOT_FOUND(ErrorDescription::FS_FileNotFound, ErrorModule::FS,
17 ErrorSummary::NotFound, ErrorLevel::Status); 19 ErrorSummary::NotFound, ErrorLevel::Status);
18const ResultCode ERROR_PATH_NOT_FOUND(ErrorDescription::FS_PathNotFound, ErrorModule::FS, 20const ResultCode ERROR_PATH_NOT_FOUND(ErrorDescription::FS_PathNotFound, ErrorModule::FS,