Added a way to check Block Size, Compression Method, and Compression Level flags to dolphin-tool

New dolphin-tool command: "header"
-b / --block_size
-c / --compression
-l / --compression_level

Informative RVZ/WIA header2 value "compression_level" is now a s32 instead of a u32, because negative compression is a thing.

Speaking of, it is now possible to use negative compression levels in dolphin-tool's convert command (not the GUI, though).
This commit is contained in:
Minty-Meeo
2022-02-24 04:51:52 -06:00
parent 75ad057b08
commit deba9ce256
20 changed files with 167 additions and 8 deletions

View File

@ -5,6 +5,8 @@ add_executable(dolphin-tool
ConvertCommand.h
VerifyCommand.cpp
VerifyCommand.h
HeaderCommand.cpp
HeaderCommand.h
ToolMain.cpp
)

View File

@ -220,7 +220,8 @@ int ConvertCommand::Main(const std::vector<std::string>& args)
return 1;
}
const std::pair<int, int> range = DiscIO::GetAllowedCompressionLevels(compression_o.value());
const std::pair<int, int> range =
DiscIO::GetAllowedCompressionLevels(compression_o.value(), false);
if (compression_level_o.value() < range.first || compression_level_o.value() > range.second)
{
std::cerr << "Error: Compression level not in acceptable range" << std::endl;

View File

@ -38,6 +38,7 @@
<ItemGroup>
<ClCompile Include="ConvertCommand.cpp" />
<ClCompile Include="VerifyCommand.cpp" />
<ClCompile Include="HeaderCommand.cpp" />
<ClCompile Include="ToolHeadlessPlatform.cpp" />
<ClCompile Include="ToolMain.cpp" />
</ItemGroup>
@ -52,6 +53,7 @@
<ClInclude Include="Command.h" />
<ClInclude Include="ConvertCommand.h" />
<ClInclude Include="VerifyCommand.h" />
<ClInclude Include="HeaderCommand.h" />
</ItemGroup>
<ItemGroup>
<Manifest Include="DolphinTool.exe.manifest" />

View File

@ -0,0 +1,106 @@
// Copyright 2022 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinTool/HeaderCommand.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeDisc.h"
#include <OptionParser.h>
#include <optional>
namespace DolphinTool
{
int HeaderCommand::Main(const std::vector<std::string>& args)
{
auto parser = std::make_unique<optparse::OptionParser>();
parser->usage("usage: header [options]...");
parser->add_option("-i", "--input")
.type("string")
.action("store")
.help("Path to disc image FILE.")
.metavar("FILE");
parser->add_option("-b", "--block_size")
.action("store_true")
.help("Optional. Print the block size of GCZ/WIA/RVZ formats, then exit.");
parser->add_option("-c", "--compression")
.action("store_true")
.help("Optional. Print the compression method of GCZ/WIA/RVZ formats, then exit.");
parser->add_option("-l", "--compression_level")
.action("store_true")
.help("Optional. Print the level of compression for WIA/RVZ formats, then exit.");
const optparse::Values& options = parser->parse_args(args);
// Validate options
const std::string input_file_path = static_cast<const char*>(options.get("input"));
if (input_file_path.empty())
{
std::cerr << "Error: No input set" << std::endl;
return 1;
}
bool enable_block_size = options.is_set_by_user("block_size");
bool enable_compression_method = options.is_set_by_user("compression");
bool enable_compression_level = options.is_set_by_user("compression_level");
// Open the blob reader, plus get blob type
std::shared_ptr<DiscIO::BlobReader> blob_reader = DiscIO::CreateBlobReader(input_file_path);
if (!blob_reader)
{
std::cerr << "Error: Unable to open disc image" << std::endl;
return 1;
}
const DiscIO::BlobType blob_type = blob_reader->GetBlobType();
if (enable_block_size || enable_compression_method || enable_compression_level)
{
if (enable_block_size)
{
const auto block_size = blob_reader->GetBlockSize();
if (block_size == 0)
std::cout << "N/A" << std::endl;
else
std::cout << block_size << std::endl;
}
if (enable_compression_method)
{
const auto compression_method = blob_reader->GetCompressionMethod();
if (compression_method == "")
std::cout << "N/A" << std::endl;
else
std::cout << compression_method << std::endl;
}
if (enable_compression_level)
{
const auto compression_level_o = blob_reader->GetCompressionLevel();
if (compression_level_o == std::nullopt)
std::cout << "N/A" << std::endl;
else
std::cout << compression_level_o.value() << std::endl;
}
}
else
{
if (blob_type == DiscIO::BlobType::GCZ)
{
std::cout << "Block Size: " << blob_reader->GetBlockSize() << std::endl;
std::cout << "Compression Method: " << blob_reader->GetCompressionMethod() << std::endl;
}
if (blob_type == DiscIO::BlobType::WIA || blob_type == DiscIO::BlobType::RVZ)
{
std::cout << "Block Size: " << blob_reader->GetBlockSize() << std::endl;
std::cout << "Compression Method: " << blob_reader->GetCompressionMethod() << std::endl;
std::cout << "Compression Level: " << blob_reader->GetCompressionLevel().value() << std::endl;
}
}
return 0;
}
} // namespace DolphinTool

View File

@ -0,0 +1,19 @@
// Copyright 2022 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <string>
#include <vector>
#include "DolphinTool/Command.h"
namespace DolphinTool
{
class HeaderCommand final : public Command
{
public:
int Main(const std::vector<std::string>& args) override;
};
} // namespace DolphinTool

View File

@ -10,12 +10,13 @@
#include "Common/Version.h"
#include "DolphinTool/Command.h"
#include "DolphinTool/ConvertCommand.h"
#include "DolphinTool/HeaderCommand.h"
#include "DolphinTool/VerifyCommand.h"
static int PrintUsage(int code)
{
std::cerr << "usage: dolphin-tool COMMAND -h" << std::endl << std::endl;
std::cerr << "commands supported: [convert, verify]" << std::endl;
std::cerr << "commands supported: [convert, verify, header]" << std::endl;
return code;
}
@ -38,6 +39,8 @@ int main(int argc, char* argv[])
command = std::make_unique<DolphinTool::ConvertCommand>();
else if (command_str == "verify")
command = std::make_unique<DolphinTool::VerifyCommand>();
else if (command_str == "header")
command = std::make_unique<DolphinTool::HeaderCommand>();
else
return PrintUsage(1);