summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/archive.cpp
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2014-09-12 00:48:04 +0200
committerGravatar Emmanuel Gil Peyrot2014-09-17 14:35:46 +0000
commitc197ce2180c5627567865a93a9d97190c3a8fdc9 (patch)
tree9ef81596a7d1fa4ce720d9bae8de4c38e9b1563b /src/core/hle/kernel/archive.cpp
parentCore: Add a method to obtain a Directory from an Archive. (diff)
downloadyuzu-c197ce2180c5627567865a93a9d97190c3a8fdc9.tar.gz
yuzu-c197ce2180c5627567865a93a9d97190c3a8fdc9.tar.xz
yuzu-c197ce2180c5627567865a93a9d97190c3a8fdc9.zip
Kernel: Add a Directory object and a getter for it from an Archive object.
Diffstat (limited to 'src/core/hle/kernel/archive.cpp')
-rw-r--r--src/core/hle/kernel/archive.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 24b2262bc..6161f4d00 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -8,6 +8,7 @@
8 8
9#include "core/file_sys/archive.h" 9#include "core/file_sys/archive.h"
10#include "core/file_sys/archive_sdmc.h" 10#include "core/file_sys/archive_sdmc.h"
11#include "core/file_sys/directory.h"
11#include "core/hle/service/service.h" 12#include "core/hle/service/service.h"
12#include "core/hle/kernel/archive.h" 13#include "core/hle/kernel/archive.h"
13 14
@@ -31,6 +32,14 @@ enum class FileCommand : u32 {
31 Flush = 0x08090000, 32 Flush = 0x08090000,
32}; 33};
33 34
35// Command to access directory
36enum class DirectoryCommand : u32 {
37 Dummy1 = 0x000100C6,
38 Control = 0x040100C4,
39 Read = 0x08010042,
40 Close = 0x08020000,
41};
42
34class Archive : public Object { 43class Archive : public Object {
35public: 44public:
36 std::string GetTypeName() const { return "Archive"; } 45 std::string GetTypeName() const { return "Archive"; }
@@ -187,6 +196,62 @@ public:
187 } 196 }
188}; 197};
189 198
199class Directory : public Object {
200public:
201 std::string GetTypeName() const { return "Directory"; }
202 std::string GetName() const { return path; }
203
204 static Kernel::HandleType GetStaticHandleType() { return HandleType::Directory; }
205 Kernel::HandleType GetHandleType() const { return HandleType::Directory; }
206
207 std::string path; ///< Path of the directory
208 std::unique_ptr<FileSys::Directory> backend; ///< File backend interface
209
210 /**
211 * Synchronize kernel object
212 * @param wait Boolean wait set if current thread should wait as a result of sync operation
213 * @return Result of operation, 0 on success, otherwise error code
214 */
215 Result SyncRequest(bool* wait) {
216 u32* cmd_buff = Service::GetCommandBuffer();
217 DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
218 switch (cmd) {
219
220 // Read from directory...
221 case DirectoryCommand::Read:
222 {
223 u32 count = cmd_buff[1];
224 u32 address = cmd_buff[3];
225 FileSys::Entry* entries = reinterpret_cast<FileSys::Entry*>(Memory::GetPointer(address));
226 DEBUG_LOG(KERNEL, "Read %s %s: count=%d", GetTypeName().c_str(), GetName().c_str(), count);
227
228 // Number of entries actually read
229 cmd_buff[2] = backend->Read(count, entries);
230 break;
231 }
232
233 // Unknown command...
234 default:
235 ERROR_LOG(KERNEL, "Unknown command=0x%08X!", cmd);
236 cmd_buff[1] = -1; // TODO(Link Mauve): use the correct error code for that.
237 return -1;
238 }
239 cmd_buff[1] = 0; // No error
240 return 0;
241 }
242
243 /**
244 * Wait for kernel object to synchronize
245 * @param wait Boolean wait set if current thread should wait as a result of sync operation
246 * @return Result of operation, 0 on success, otherwise error code
247 */
248 Result WaitSynchronization(bool* wait) {
249 // TODO(bunnei): ImplementMe
250 ERROR_LOG(OSHLE, "(UNIMPLEMENTED)");
251 return 0;
252 }
253};
254
190//////////////////////////////////////////////////////////////////////////////////////////////////// 255////////////////////////////////////////////////////////////////////////////////////////////////////
191 256
192std::map<FileSys::Archive::IdCode, Handle> g_archive_map; ///< Map of file archives by IdCode 257std::map<FileSys::Archive::IdCode, Handle> g_archive_map; ///< Map of file archives by IdCode
@@ -268,6 +333,23 @@ Handle OpenFileFromArchive(Handle archive_handle, const std::string& path, const
268 return handle; 333 return handle;
269} 334}
270 335
336/**
337 * Open a Directory from an Archive
338 * @param archive_handle Handle to an open Archive object
339 * @param path Path to the Directory inside of the Archive
340 * @return Opened Directory object
341 */
342Handle OpenDirectoryFromArchive(Handle archive_handle, const std::string& path) {
343 Directory* directory = new Directory;
344 Handle handle = Kernel::g_object_pool.Create(directory);
345
346 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
347 directory->path = path;
348 directory->backend = archive->backend->OpenDirectory(path);
349
350 return handle;
351}
352
271/// Initialize archives 353/// Initialize archives
272void ArchiveInit() { 354void ArchiveInit() {
273 g_archive_map.clear(); 355 g_archive_map.clear();