DolphinTool: Ditch OOP design
This commit is contained in:
parent
98b5d72ef1
commit
25c020cbe2
|
@ -1,6 +1,5 @@
|
||||||
add_executable(dolphin-tool
|
add_executable(dolphin-tool
|
||||||
ToolHeadlessPlatform.cpp
|
ToolHeadlessPlatform.cpp
|
||||||
Command.h
|
|
||||||
ConvertCommand.cpp
|
ConvertCommand.cpp
|
||||||
ConvertCommand.h
|
ConvertCommand.h
|
||||||
VerifyCommand.cpp
|
VerifyCommand.cpp
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
// Copyright 2021 Dolphin Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace DolphinTool
|
|
||||||
{
|
|
||||||
class Command
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Command() {}
|
|
||||||
virtual ~Command() {}
|
|
||||||
virtual int Main(const std::vector<std::string>& args) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace DolphinTool
|
|
|
@ -18,12 +18,42 @@
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
#include "DiscIO/VolumeDisc.h"
|
#include "DiscIO/VolumeDisc.h"
|
||||||
#include "DiscIO/WIABlob.h"
|
#include "DiscIO/WIABlob.h"
|
||||||
#include "DolphinTool/Command.h"
|
|
||||||
#include "UICommon/UICommon.h"
|
#include "UICommon/UICommon.h"
|
||||||
|
|
||||||
namespace DolphinTool
|
namespace DolphinTool
|
||||||
{
|
{
|
||||||
int ConvertCommand::Main(const std::vector<std::string>& args)
|
static std::optional<DiscIO::WIARVZCompressionType>
|
||||||
|
ParseCompressionTypeString(const std::string& compression_str)
|
||||||
|
{
|
||||||
|
if (compression_str == "none")
|
||||||
|
return DiscIO::WIARVZCompressionType::None;
|
||||||
|
else if (compression_str == "purge")
|
||||||
|
return DiscIO::WIARVZCompressionType::Purge;
|
||||||
|
else if (compression_str == "bzip2")
|
||||||
|
return DiscIO::WIARVZCompressionType::Bzip2;
|
||||||
|
else if (compression_str == "lzma")
|
||||||
|
return DiscIO::WIARVZCompressionType::LZMA;
|
||||||
|
else if (compression_str == "lzma2")
|
||||||
|
return DiscIO::WIARVZCompressionType::LZMA2;
|
||||||
|
else if (compression_str == "zstd")
|
||||||
|
return DiscIO::WIARVZCompressionType::Zstd;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::optional<DiscIO::BlobType> ParseFormatString(const std::string& format_str)
|
||||||
|
{
|
||||||
|
if (format_str == "iso")
|
||||||
|
return DiscIO::BlobType::PLAIN;
|
||||||
|
else if (format_str == "gcz")
|
||||||
|
return DiscIO::BlobType::GCZ;
|
||||||
|
else if (format_str == "wia")
|
||||||
|
return DiscIO::BlobType::WIA;
|
||||||
|
else if (format_str == "rvz")
|
||||||
|
return DiscIO::BlobType::RVZ;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConvertCommand(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
optparse::OptionParser parser;
|
optparse::OptionParser parser;
|
||||||
|
|
||||||
|
@ -324,35 +354,4 @@ int ConvertCommand::Main(const std::vector<std::string>& args)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<DiscIO::WIARVZCompressionType>
|
|
||||||
ConvertCommand::ParseCompressionTypeString(const std::string& compression_str)
|
|
||||||
{
|
|
||||||
if (compression_str == "none")
|
|
||||||
return DiscIO::WIARVZCompressionType::None;
|
|
||||||
else if (compression_str == "purge")
|
|
||||||
return DiscIO::WIARVZCompressionType::Purge;
|
|
||||||
else if (compression_str == "bzip2")
|
|
||||||
return DiscIO::WIARVZCompressionType::Bzip2;
|
|
||||||
else if (compression_str == "lzma")
|
|
||||||
return DiscIO::WIARVZCompressionType::LZMA;
|
|
||||||
else if (compression_str == "lzma2")
|
|
||||||
return DiscIO::WIARVZCompressionType::LZMA2;
|
|
||||||
else if (compression_str == "zstd")
|
|
||||||
return DiscIO::WIARVZCompressionType::Zstd;
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<DiscIO::BlobType> ConvertCommand::ParseFormatString(const std::string& format_str)
|
|
||||||
{
|
|
||||||
if (format_str == "iso")
|
|
||||||
return DiscIO::BlobType::PLAIN;
|
|
||||||
else if (format_str == "gcz")
|
|
||||||
return DiscIO::BlobType::GCZ;
|
|
||||||
else if (format_str == "wia")
|
|
||||||
return DiscIO::BlobType::WIA;
|
|
||||||
else if (format_str == "rvz")
|
|
||||||
return DiscIO::BlobType::RVZ;
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
} // namespace DolphinTool
|
} // namespace DolphinTool
|
||||||
|
|
|
@ -3,25 +3,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "DiscIO/Blob.h"
|
|
||||||
#include "DiscIO/WIABlob.h"
|
|
||||||
#include "DolphinTool/Command.h"
|
|
||||||
|
|
||||||
namespace DolphinTool
|
namespace DolphinTool
|
||||||
{
|
{
|
||||||
class ConvertCommand final : public Command
|
int ConvertCommand(const std::vector<std::string>& args);
|
||||||
{
|
|
||||||
public:
|
|
||||||
int Main(const std::vector<std::string>& args) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::optional<DiscIO::WIARVZCompressionType>
|
|
||||||
ParseCompressionTypeString(const std::string& compression_str);
|
|
||||||
std::optional<DiscIO::BlobType> ParseFormatString(const std::string& format_str);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace DolphinTool
|
} // namespace DolphinTool
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="ConvertCommand.cpp" />
|
<ClCompile Include="ConvertCommand.cpp" />
|
||||||
<ClCompile Include="VerifyCommand.cpp" />
|
<ClCompile Include="VerifyCommand.cpp" />
|
||||||
|
<ClCompile Include="HeaderCommand.cpp" />
|
||||||
<ClCompile Include="ToolHeadlessPlatform.cpp" />
|
<ClCompile Include="ToolHeadlessPlatform.cpp" />
|
||||||
<ClCompile Include="ToolMain.cpp" />
|
<ClCompile Include="ToolMain.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Command.h" />
|
|
||||||
<ClInclude Include="ConvertCommand.h" />
|
<ClInclude Include="ConvertCommand.h" />
|
||||||
<ClInclude Include="VerifyCommand.h" />
|
<ClInclude Include="VerifyCommand.h" />
|
||||||
|
<ClInclude Include="HeaderCommand.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Manifest Include="DolphinTool.exe.manifest" />
|
<Manifest Include="DolphinTool.exe.manifest" />
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
<SourceFiles Include="$(TargetPath)" />
|
<SourceFiles Include="$(TargetPath)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Command.h" />
|
|
||||||
<ClInclude Include="ConvertCommand.h" />
|
<ClInclude Include="ConvertCommand.h" />
|
||||||
<ClInclude Include="VerifyCommand.h" />
|
<ClInclude Include="VerifyCommand.h" />
|
||||||
<ClInclude Include="HeaderCommand.h" />
|
<ClInclude Include="HeaderCommand.h" />
|
||||||
|
|
|
@ -2,16 +2,20 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "DolphinTool/HeaderCommand.h"
|
#include "DolphinTool/HeaderCommand.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <OptionParser.h>
|
||||||
|
|
||||||
#include "DiscIO/Blob.h"
|
#include "DiscIO/Blob.h"
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
#include "DiscIO/VolumeDisc.h"
|
#include "DiscIO/VolumeDisc.h"
|
||||||
|
|
||||||
#include <OptionParser.h>
|
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace DolphinTool
|
namespace DolphinTool
|
||||||
{
|
{
|
||||||
int HeaderCommand::Main(const std::vector<std::string>& args)
|
int HeaderCommand(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
optparse::OptionParser parser;
|
optparse::OptionParser parser;
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "DolphinTool/Command.h"
|
|
||||||
|
|
||||||
namespace DolphinTool
|
namespace DolphinTool
|
||||||
{
|
{
|
||||||
class HeaderCommand final : public Command
|
int HeaderCommand(const std::vector<std::string>& args);
|
||||||
{
|
|
||||||
public:
|
|
||||||
int Main(const std::vector<std::string>& args) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace DolphinTool
|
} // namespace DolphinTool
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "Common/StringUtil.h"
|
||||||
#include "Common/Version.h"
|
#include "Common/Version.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "DolphinTool/Command.h"
|
|
||||||
#include "DolphinTool/ConvertCommand.h"
|
#include "DolphinTool/ConvertCommand.h"
|
||||||
#include "DolphinTool/HeaderCommand.h"
|
#include "DolphinTool/HeaderCommand.h"
|
||||||
#include "DolphinTool/VerifyCommand.h"
|
#include "DolphinTool/VerifyCommand.h"
|
||||||
|
@ -38,18 +39,13 @@ int main(int argc, char* argv[])
|
||||||
// Take off the program name and command selector before passing arguments down
|
// Take off the program name and command selector before passing arguments down
|
||||||
const std::vector<std::string> args(argv + 2, argv + argc);
|
const std::vector<std::string> args(argv + 2, argv + argc);
|
||||||
|
|
||||||
std::unique_ptr<DolphinTool::Command> command;
|
|
||||||
|
|
||||||
if (command_str == "convert")
|
if (command_str == "convert")
|
||||||
command = std::make_unique<DolphinTool::ConvertCommand>();
|
return DolphinTool::ConvertCommand(args);
|
||||||
else if (command_str == "verify")
|
else if (command_str == "verify")
|
||||||
command = std::make_unique<DolphinTool::VerifyCommand>();
|
return DolphinTool::VerifyCommand(args);
|
||||||
else if (command_str == "header")
|
else if (command_str == "header")
|
||||||
command = std::make_unique<DolphinTool::HeaderCommand>();
|
return DolphinTool::HeaderCommand(args);
|
||||||
else
|
return PrintUsage(1);
|
||||||
return PrintUsage(1);
|
|
||||||
|
|
||||||
return command->Main(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
@ -2,13 +2,77 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "DolphinTool/VerifyCommand.h"
|
#include "DolphinTool/VerifyCommand.h"
|
||||||
#include "UICommon/UICommon.h"
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <OptionParser.h>
|
#include <OptionParser.h>
|
||||||
|
|
||||||
|
#include "Common/StringUtil.h"
|
||||||
|
#include "DiscIO/VolumeDisc.h"
|
||||||
|
#include "DiscIO/VolumeVerifier.h"
|
||||||
|
#include "UICommon/UICommon.h"
|
||||||
|
|
||||||
namespace DolphinTool
|
namespace DolphinTool
|
||||||
{
|
{
|
||||||
int VerifyCommand::Main(const std::vector<std::string>& args)
|
static std::string HashToHexString(const std::vector<u8>& hash)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::hex;
|
||||||
|
for (int i = 0; i < static_cast<int>(hash.size()); ++i)
|
||||||
|
{
|
||||||
|
ss << std::setw(2) << std::setfill('0') << static_cast<int>(hash[i]);
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PrintFullReport(const DiscIO::VolumeVerifier::Result& result)
|
||||||
|
{
|
||||||
|
if (!result.hashes.crc32.empty())
|
||||||
|
std::cout << "CRC32: " << HashToHexString(result.hashes.crc32) << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "CRC32 not computed" << std::endl;
|
||||||
|
|
||||||
|
if (!result.hashes.md5.empty())
|
||||||
|
std::cout << "MD5: " << HashToHexString(result.hashes.md5) << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "MD5 not computed" << std::endl;
|
||||||
|
|
||||||
|
if (!result.hashes.sha1.empty())
|
||||||
|
std::cout << "SHA1: " << HashToHexString(result.hashes.sha1) << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "SHA1 not computed" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Problems Found: " << (result.problems.empty() ? "No" : "Yes") << std::endl;
|
||||||
|
|
||||||
|
for (const auto& problem : result.problems)
|
||||||
|
{
|
||||||
|
std::cout << std::endl << "Severity: ";
|
||||||
|
switch (problem.severity)
|
||||||
|
{
|
||||||
|
case DiscIO::VolumeVerifier::Severity::Low:
|
||||||
|
std::cout << "Low";
|
||||||
|
break;
|
||||||
|
case DiscIO::VolumeVerifier::Severity::Medium:
|
||||||
|
std::cout << "Medium";
|
||||||
|
break;
|
||||||
|
case DiscIO::VolumeVerifier::Severity::High:
|
||||||
|
std::cout << "High";
|
||||||
|
break;
|
||||||
|
case DiscIO::VolumeVerifier::Severity::None:
|
||||||
|
std::cout << "None";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Summary: " << problem.text << std::endl << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int VerifyCommand(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
optparse::OptionParser parser;
|
optparse::OptionParser parser;
|
||||||
|
|
||||||
|
@ -115,61 +179,4 @@ int VerifyCommand::Main(const std::vector<std::string>& args)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VerifyCommand::PrintFullReport(const DiscIO::VolumeVerifier::Result& result)
|
|
||||||
{
|
|
||||||
if (!result.hashes.crc32.empty())
|
|
||||||
std::cout << "CRC32: " << HashToHexString(result.hashes.crc32) << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << "CRC32 not computed" << std::endl;
|
|
||||||
|
|
||||||
if (!result.hashes.md5.empty())
|
|
||||||
std::cout << "MD5: " << HashToHexString(result.hashes.md5) << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << "MD5 not computed" << std::endl;
|
|
||||||
|
|
||||||
if (!result.hashes.sha1.empty())
|
|
||||||
std::cout << "SHA1: " << HashToHexString(result.hashes.sha1) << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << "SHA1 not computed" << std::endl;
|
|
||||||
|
|
||||||
std::cout << "Problems Found: " << (result.problems.empty() ? "No" : "Yes") << std::endl;
|
|
||||||
|
|
||||||
for (const auto& problem : result.problems)
|
|
||||||
{
|
|
||||||
std::cout << std::endl << "Severity: ";
|
|
||||||
switch (problem.severity)
|
|
||||||
{
|
|
||||||
case DiscIO::VolumeVerifier::Severity::Low:
|
|
||||||
std::cout << "Low";
|
|
||||||
break;
|
|
||||||
case DiscIO::VolumeVerifier::Severity::Medium:
|
|
||||||
std::cout << "Medium";
|
|
||||||
break;
|
|
||||||
case DiscIO::VolumeVerifier::Severity::High:
|
|
||||||
std::cout << "High";
|
|
||||||
break;
|
|
||||||
case DiscIO::VolumeVerifier::Severity::None:
|
|
||||||
std::cout << "None";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ASSERT(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
std::cout << "Summary: " << problem.text << std::endl << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string VerifyCommand::HashToHexString(const std::vector<u8>& hash)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << std::hex;
|
|
||||||
for (int i = 0; i < static_cast<int>(hash.size()); ++i)
|
|
||||||
{
|
|
||||||
ss << std::setw(2) << std::setfill('0') << static_cast<int>(hash[i]);
|
|
||||||
}
|
|
||||||
return ss.str();
|
|
||||||
}
|
|
||||||
} // namespace DolphinTool
|
} // namespace DolphinTool
|
||||||
|
|
|
@ -3,26 +3,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "DiscIO/Volume.h"
|
|
||||||
#include "DiscIO/VolumeDisc.h"
|
|
||||||
#include "DiscIO/VolumeVerifier.h"
|
|
||||||
#include "DolphinTool/Command.h"
|
|
||||||
|
|
||||||
namespace DolphinTool
|
namespace DolphinTool
|
||||||
{
|
{
|
||||||
class VerifyCommand final : public Command
|
int VerifyCommand(const std::vector<std::string>& args);
|
||||||
{
|
|
||||||
public:
|
|
||||||
int Main(const std::vector<std::string>& args) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void PrintFullReport(const DiscIO::VolumeVerifier::Result& result);
|
|
||||||
|
|
||||||
std::string HashToHexString(const std::vector<u8>& hash);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace DolphinTool
|
} // namespace DolphinTool
|
||||||
|
|
Loading…
Reference in New Issue