summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2014-09-27 19:21:48 +0000
committerGravatar Emmanuel Gil Peyrot2014-10-06 19:58:42 +0200
commit0be5c03176236fe602d49c32717a6f3af0a55465 (patch)
tree61573d4ed66ac5e7f46968ef871b3acf9f0c5b99 /src/core
parentFileSys/Kernel: Implement SetSize service call for File objects. (diff)
downloadyuzu-0be5c03176236fe602d49c32717a6f3af0a55465.tar.gz
yuzu-0be5c03176236fe602d49c32717a6f3af0a55465.tar.xz
yuzu-0be5c03176236fe602d49c32717a6f3af0a55465.zip
FileSys: split the constructor into an Open method, in order to notify the opener something went wrong.
Kernel: Return an invalid handle to OpenFile when it failed to open.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/file_sys/archive_sdmc.cpp2
-rw-r--r--src/core/file_sys/file.h6
-rw-r--r--src/core/file_sys/file_romfs.cpp8
-rw-r--r--src/core/file_sys/file_romfs.h6
-rw-r--r--src/core/file_sys/file_sdmc.cpp38
-rw-r--r--src/core/file_sys/file_sdmc.h8
-rw-r--r--src/core/hle/kernel/archive.cpp3
7 files changed, 57 insertions, 14 deletions
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 8d0827380..213923c02 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -46,6 +46,8 @@ bool Archive_SDMC::Initialize() {
46std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const { 46std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const {
47 DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode); 47 DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode);
48 File_SDMC* file = new File_SDMC(this, path, mode); 48 File_SDMC* file = new File_SDMC(this, path, mode);
49 if (!file->Open())
50 return nullptr;
49 return std::unique_ptr<File>(file); 51 return std::unique_ptr<File>(file);
50} 52}
51 53
diff --git a/src/core/file_sys/file.h b/src/core/file_sys/file.h
index 443e65319..4013b6c3e 100644
--- a/src/core/file_sys/file.h
+++ b/src/core/file_sys/file.h
@@ -19,6 +19,12 @@ public:
19 virtual ~File() { } 19 virtual ~File() { }
20 20
21 /** 21 /**
22 * Open the file
23 * @return true if the file opened correctly
24 */
25 virtual bool Open() = 0;
26
27 /**
22 * Read data from the file 28 * Read data from the file
23 * @param offset Offset in bytes to start reading data from 29 * @param offset Offset in bytes to start reading data from
24 * @param length Length in bytes of data to read from file 30 * @param length Length in bytes of data to read from file
diff --git a/src/core/file_sys/file_romfs.cpp b/src/core/file_sys/file_romfs.cpp
index 3ef616e08..b55708df4 100644
--- a/src/core/file_sys/file_romfs.cpp
+++ b/src/core/file_sys/file_romfs.cpp
@@ -18,6 +18,14 @@ File_RomFS::~File_RomFS() {
18} 18}
19 19
20/** 20/**
21 * Open the file
22 * @return true if the file opened correctly
23 */
24bool File_RomFS::Open() {
25 return false;
26}
27
28/**
21 * Read data from the file 29 * Read data from the file
22 * @param offset Offset in bytes to start reading data from 30 * @param offset Offset in bytes to start reading data from
23 * @param length Length in bytes of data to read from file 31 * @param length Length in bytes of data to read from file
diff --git a/src/core/file_sys/file_romfs.h b/src/core/file_sys/file_romfs.h
index 06973eb93..5196701d3 100644
--- a/src/core/file_sys/file_romfs.h
+++ b/src/core/file_sys/file_romfs.h
@@ -20,6 +20,12 @@ public:
20 ~File_RomFS() override; 20 ~File_RomFS() override;
21 21
22 /** 22 /**
23 * Open the file
24 * @return true if the file opened correctly
25 */
26 bool Open() override;
27
28 /**
23 * Read data from the file 29 * Read data from the file
24 * @param offset Offset in bytes to start reading data from 30 * @param offset Offset in bytes to start reading data from
25 * @param length Length in bytes of data to read from file 31 * @param length Length in bytes of data to read from file
diff --git a/src/core/file_sys/file_sdmc.cpp b/src/core/file_sys/file_sdmc.cpp
index 3ef2b0c0e..26204392c 100644
--- a/src/core/file_sys/file_sdmc.cpp
+++ b/src/core/file_sys/file_sdmc.cpp
@@ -19,20 +19,8 @@ File_SDMC::File_SDMC(const Archive_SDMC* archive, const std::string& path, const
19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass 19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
20 // the root directory we set while opening the archive. 20 // the root directory we set while opening the archive.
21 // For example, opening /../../etc/passwd can give the emulated program your users list. 21 // For example, opening /../../etc/passwd can give the emulated program your users list.
22 std::string real_path = archive->GetMountPoint() + path; 22 this->path = archive->GetMountPoint() + path;
23 23 this->mode.hex = mode.hex;
24 if (!mode.create_flag && !FileUtil::Exists(real_path)) {
25 file = nullptr;
26 return;
27 }
28
29 std::string mode_string;
30 if (mode.read_flag)
31 mode_string += "r";
32 if (mode.write_flag)
33 mode_string += "w";
34
35 file = new FileUtil::IOFile(real_path, mode_string.c_str());
36} 24}
37 25
38File_SDMC::~File_SDMC() { 26File_SDMC::~File_SDMC() {
@@ -40,6 +28,28 @@ File_SDMC::~File_SDMC() {
40} 28}
41 29
42/** 30/**
31 * Open the file
32 * @return true if the file opened correctly
33 */
34bool File_SDMC::Open() {
35 if (!mode.create_flag && !FileUtil::Exists(path)) {
36 ERROR_LOG(FILESYS, "Non-existing file %s can’t be open without mode create.", path.c_str());
37 return false;
38 }
39
40 std::string mode_string;
41 if (mode.read_flag && mode.write_flag)
42 mode_string = "w+";
43 else if (mode.read_flag)
44 mode_string = "r";
45 else if (mode.write_flag)
46 mode_string = "w";
47
48 file = new FileUtil::IOFile(path, mode_string.c_str());
49 return true;
50}
51
52/**
43 * Read data from the file 53 * Read data from the file
44 * @param offset Offset in bytes to start reading data from 54 * @param offset Offset in bytes to start reading data from
45 * @param length Length in bytes of data to read from file 55 * @param length Length in bytes of data to read from file
diff --git a/src/core/file_sys/file_sdmc.h b/src/core/file_sys/file_sdmc.h
index 6b3a1f3a5..df032f7c0 100644
--- a/src/core/file_sys/file_sdmc.h
+++ b/src/core/file_sys/file_sdmc.h
@@ -23,6 +23,12 @@ public:
23 ~File_SDMC() override; 23 ~File_SDMC() override;
24 24
25 /** 25 /**
26 * Open the file
27 * @return true if the file opened correctly
28 */
29 bool Open() override;
30
31 /**
26 * Read data from the file 32 * Read data from the file
27 * @param offset Offset in bytes to start reading data from 33 * @param offset Offset in bytes to start reading data from
28 * @param length Length in bytes of data to read from file 34 * @param length Length in bytes of data to read from file
@@ -61,6 +67,8 @@ public:
61 bool Close() const override; 67 bool Close() const override;
62 68
63private: 69private:
70 std::string path;
71 Mode mode;
64 FileUtil::IOFile* file; 72 FileUtil::IOFile* file;
65}; 73};
66 74
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 0a66ab29b..86aba7489 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -374,6 +374,9 @@ Handle OpenFileFromArchive(Handle archive_handle, const std::string& path, const
374 file->path = path; 374 file->path = path;
375 file->backend = archive->backend->OpenFile(path, mode); 375 file->backend = archive->backend->OpenFile(path, mode);
376 376
377 if (!file->backend)
378 return 0;
379
377 return handle; 380 return handle;
378} 381}
379 382