summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/DiscUtils.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2021-12-09 22:20:26 +0100
committerGitHub <noreply@github.com>2021-12-09 22:20:26 +0100
commitd5d21c6533ff2709b9cdf357b0569f3418264812 (patch)
tree22ddd7bcb52644ad5e9b206e4036d9ea9441d085 /Source/Core/DiscIO/DiscUtils.cpp
parent85e5070215f1d39331ef7d67dbcb15e067b45173 (diff)
parent1aa8a4d46ffbf019f6bb4bccb81cc89bec07bb38 (diff)
Merge pull request #10252 from ssdsnake/feature_dolphintool
DolphinTool: Add CLI tool subsystem + commands for verifying and converting RVZ/ISO/WIA/GCZ
Diffstat (limited to 'Source/Core/DiscIO/DiscUtils.cpp')
-rw-r--r--Source/Core/DiscIO/DiscUtils.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/DiscUtils.cpp b/Source/Core/DiscIO/DiscUtils.cpp
index 84cf7ed7c4..002ce066db 100644
--- a/Source/Core/DiscIO/DiscUtils.cpp
+++ b/Source/Core/DiscIO/DiscUtils.cpp
@@ -12,6 +12,8 @@
#include <fmt/format.h>
#include "Common/CommonTypes.h"
+#include "Common/MathUtil.h"
+#include "DiscIO/Blob.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
@@ -198,4 +200,49 @@ u64 GetBiggestReferencedOffset(const Volume& volume, const std::vector<Partition
return biggest_offset;
}
+bool IsGCZBlockSizeLegacyCompatible(int block_size, u64 file_size)
+{
+ // In order for versions of Dolphin prior to 5.0-11893 to be able to convert a GCZ file
+ // to ISO without messing up the final part of the file in some way, the file size
+ // must be an integer multiple of the block size (fixed in 3aa463c) and must not be
+ // an integer multiple of the block size multiplied by 32 (fixed in 26b21e3).
+ return file_size % block_size == 0 && file_size % (block_size * 32) != 0;
+}
+
+bool IsDiscImageBlockSizeValid(int block_size, DiscIO::BlobType format)
+{
+ switch (format)
+ {
+ case DiscIO::BlobType::GCZ:
+ // Block size "must" be a power of 2
+ if (!MathUtil::IsPow2(block_size))
+ return false;
+
+ break;
+ case DiscIO::BlobType::WIA:
+ // Block size must not be less than the minimum, and must be a multiple of it
+ if (block_size < WIA_MIN_BLOCK_SIZE || block_size % WIA_MIN_BLOCK_SIZE != 0)
+ return false;
+
+ break;
+ case DiscIO::BlobType::RVZ:
+ // Block size must not be smaller than the minimum
+ // Block sizes smaller than the large block size threshold must be a power of 2
+ // Block sizes larger than that threshold must be a multiple of the threshold
+ if (block_size < RVZ_MIN_BLOCK_SIZE ||
+ (block_size < RVZ_BIG_BLOCK_SIZE_LCM && !MathUtil::IsPow2(block_size)) ||
+ (block_size > RVZ_BIG_BLOCK_SIZE_LCM && block_size % RVZ_BIG_BLOCK_SIZE_LCM != 0))
+ {
+ return false;
+ }
+
+ break;
+ default:
+ ASSERT(false);
+ break;
+ }
+
+ return true;
+}
+
} // namespace DiscIO