summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-09-19 21:55:47 -0400
committerGravatar Zach Hilman2018-09-21 19:53:05 -0400
commitf68e324672ba93cf932e64a05cbdad871cb6e235 (patch)
treee7944cc071d4655c8dfd48050b262620812a90f3 /src
parentvfs: Add GetEntries method (diff)
downloadyuzu-f68e324672ba93cf932e64a05cbdad871cb6e235.tar.gz
yuzu-f68e324672ba93cf932e64a05cbdad871cb6e235.tar.xz
yuzu-f68e324672ba93cf932e64a05cbdad871cb6e235.zip
vfs: Add and rewite VfsRawCopy functions
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/vfs.cpp36
-rw-r--r--src/core/file_sys/vfs.h6
2 files changed, 36 insertions, 6 deletions
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp
index 1ddfb7600..218cfde66 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs.cpp
@@ -463,13 +463,41 @@ bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, std::size_t
463 return true; 463 return true;
464} 464}
465 465
466bool VfsRawCopy(VirtualFile src, VirtualFile dest) { 466bool VfsRawCopy(const VirtualFile& src, const VirtualFile& dest, size_t block_size) {
467 if (src == nullptr || dest == nullptr) 467 if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
468 return false; 468 return false;
469 if (!dest->Resize(src->GetSize())) 469 if (!dest->Resize(src->GetSize()))
470 return false; 470 return false;
471 std::vector<u8> data = src->ReadAllBytes(); 471
472 return dest->WriteBytes(data, 0) == data.size(); 472 std::vector<u8> temp(std::min(block_size, src->GetSize()));
473 for (size_t i = 0; i < src->GetSize(); i += block_size) {
474 const auto read = std::min(block_size, src->GetSize() - i);
475 const auto block = src->Read(temp.data(), read, i);
476
477 if (dest->Write(temp.data(), read, i) != read)
478 return false;
479 }
480
481 return true;
482}
483
484bool VfsRawCopyD(const VirtualDir& src, const VirtualDir& dest, size_t block_size) {
485 if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
486 return false;
487
488 for (const auto& file : src->GetFiles()) {
489 const auto out = dest->CreateFile(file->GetName());
490 if (!VfsRawCopy(file, out, block_size))
491 return false;
492 }
493
494 for (const auto& dir : src->GetSubdirectories()) {
495 const auto out = dest->CreateSubdirectory(dir->GetName());
496 if (!VfsRawCopyD(dir, out, block_size))
497 return false;
498 }
499
500 return true;
473} 501}
474 502
475VirtualDir GetOrCreateDirectoryRelative(const VirtualDir& rel, std::string_view path) { 503VirtualDir GetOrCreateDirectoryRelative(const VirtualDir& rel, std::string_view path) {
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h
index 828e87f38..6aec4c164 100644
--- a/src/core/file_sys/vfs.h
+++ b/src/core/file_sys/vfs.h
@@ -316,12 +316,14 @@ public:
316}; 316};
317 317
318// Compare the two files, byte-for-byte, in increments specificed by block_size 318// Compare the two files, byte-for-byte, in increments specificed by block_size
319bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, std::size_t block_size = 0x200); 319bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, size_t block_size = 0x1000);
320 320
321// A method that copies the raw data between two different implementations of VirtualFile. If you 321// A method that copies the raw data between two different implementations of VirtualFile. If you
322// are using the same implementation, it is probably better to use the Copy method in the parent 322// are using the same implementation, it is probably better to use the Copy method in the parent
323// directory of src/dest. 323// directory of src/dest.
324bool VfsRawCopy(VirtualFile src, VirtualFile dest); 324bool VfsRawCopy(const VirtualFile& src, const VirtualFile& dest, size_t block_size = 0x1000);
325
326bool VfsRawCopyD(const VirtualDir& src, const VirtualDir& dest, size_t block_size = 0x1000);
325 327
326// Checks if the directory at path relative to rel exists. If it does, returns that. If it does not 328// Checks if the directory at path relative to rel exists. If it does, returns that. If it does not
327// it attempts to create it and returns the new dir or nullptr on failure. 329// it attempts to create it and returns the new dir or nullptr on failure.