DolphinTool: Use EXIT_SUCCESS and EXIT_FAILURE

This commit is contained in:
get 2023-06-14 23:27:14 -05:00
parent 523f8c5776
commit 969eeb4b52
4 changed files with 34 additions and 28 deletions

View File

@ -3,6 +3,7 @@
#include "DolphinTool/ConvertCommand.h"
#include <cstdlib>
#include <iostream>
#include <limits>
#include <optional>
@ -123,7 +124,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (input_file_path.empty())
{
std::cerr << "Error: No input set" << std::endl;
return 1;
return EXIT_FAILURE;
}
// --output
@ -131,7 +132,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (output_file_path.empty())
{
std::cerr << "Error: No output set" << std::endl;
return 1;
return EXIT_FAILURE;
}
// --format
@ -140,7 +141,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (!format_o.has_value())
{
std::cerr << "Error: No output format set" << std::endl;
return 1;
return EXIT_FAILURE;
}
const DiscIO::BlobType format = format_o.value();
@ -149,7 +150,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (!blob_reader)
{
std::cerr << "Error: The input file could not be opened." << std::endl;
return 1;
return EXIT_FAILURE;
}
// --scrub
@ -162,7 +163,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (scrub)
{
std::cerr << "Error: Scrubbing is only supported for GC/Wii disc images." << std::endl;
return 1;
return EXIT_FAILURE;
}
std::cerr << "Warning: The input file is not a GC/Wii disc image. Continuing anyway."
@ -174,7 +175,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (volume->IsDatelDisc())
{
std::cerr << "Error: Scrubbing a Datel disc is not supported." << std::endl;
return 1;
return EXIT_FAILURE;
}
blob_reader = DiscIO::ScrubbedBlob::Create(input_file_path);
@ -182,7 +183,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (!blob_reader)
{
std::cerr << "Error: Unable to process disc image. Try again without --scrub." << std::endl;
return 1;
return EXIT_FAILURE;
}
}
@ -225,13 +226,13 @@ int ConvertCommand(const std::vector<std::string>& args)
if (!block_size_o.has_value())
{
std::cerr << "Error: Block size must be set for GCZ/RVZ/WIA" << std::endl;
return 1;
return EXIT_FAILURE;
}
if (!DiscIO::IsDiscImageBlockSizeValid(block_size_o.value(), format))
{
std::cerr << "Error: Block size is not valid for this format" << std::endl;
return 1;
return EXIT_FAILURE;
}
if (block_size_o.value() < DiscIO::PREFERRED_MIN_BLOCK_SIZE ||
@ -265,7 +266,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (!compression_o.has_value())
{
std::cerr << "Error: Compression format must be set for WIA or RVZ" << std::endl;
return 1;
return EXIT_FAILURE;
}
if ((format == DiscIO::BlobType::WIA &&
@ -274,7 +275,7 @@ int ConvertCommand(const std::vector<std::string>& args)
compression_o.value() == DiscIO::WIARVZCompressionType::Purge))
{
std::cerr << "Error: Compression type is not supported for the container format" << std::endl;
return 1;
return EXIT_FAILURE;
}
if (compression_o.value() == DiscIO::WIARVZCompressionType::None)
@ -287,7 +288,7 @@ int ConvertCommand(const std::vector<std::string>& args)
{
std::cerr << "Error: Compression level must be set when compression type is not 'none'"
<< std::endl;
return 1;
return EXIT_FAILURE;
}
const std::pair<int, int> range =
@ -295,7 +296,7 @@ int ConvertCommand(const std::vector<std::string>& args)
if (compression_level_o.value() < range.first || compression_level_o.value() > range.second)
{
std::cerr << "Error: Compression level not in acceptable range" << std::endl;
return 1;
return EXIT_FAILURE;
}
}
}
@ -349,9 +350,9 @@ int ConvertCommand(const std::vector<std::string>& args)
if (!success)
{
std::cerr << "Error: Conversion failed" << std::endl;
return 1;
return EXIT_FAILURE;
}
return 0;
return EXIT_SUCCESS;
}
} // namespace DolphinTool

View File

@ -3,6 +3,7 @@
#include "DolphinTool/HeaderCommand.h"
#include <cstdlib>
#include <optional>
#include <string>
#include <vector>
@ -46,7 +47,7 @@ int HeaderCommand(const std::vector<std::string>& args)
if (input_file_path.empty())
{
std::cerr << "Error: No input set" << std::endl;
return 1;
return EXIT_FAILURE;
}
const bool enable_block_size = options.is_set_by_user("block_size");
@ -58,7 +59,7 @@ int HeaderCommand(const std::vector<std::string>& args)
if (!blob_reader)
{
std::cerr << "Error: Unable to open disc image" << std::endl;
return 1;
return EXIT_FAILURE;
}
if (enable_block_size || enable_compression_method || enable_compression_level)
@ -104,6 +105,6 @@ int HeaderCommand(const std::vector<std::string>& args)
}
}
return 0;
return EXIT_SUCCESS;
}
} // namespace DolphinTool

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
@ -16,12 +17,10 @@
#include "DolphinTool/HeaderCommand.h"
#include "DolphinTool/VerifyCommand.h"
static int PrintUsage(int code)
static void PrintUsage()
{
std::cerr << "usage: dolphin-tool COMMAND -h" << std::endl << std::endl;
std::cerr << "commands supported: [convert, verify, header]" << std::endl;
return code;
}
#ifdef _WIN32
@ -33,7 +32,10 @@ int main(int argc, char* argv[])
Core::DeclareAsHostThread();
if (argc < 2)
return PrintUsage(1);
{
PrintUsage();
return EXIT_FAILURE;
}
const std::string_view command_str = argv[1];
// Take off the program name and command selector before passing arguments down
@ -45,7 +47,8 @@ int main(int argc, char* argv[])
return DolphinTool::VerifyCommand(args);
else if (command_str == "header")
return DolphinTool::HeaderCommand(args);
return PrintUsage(1);
PrintUsage();
return EXIT_FAILURE;
}
#ifdef _WIN32

View File

@ -3,6 +3,7 @@
#include "DolphinTool/VerifyCommand.h"
#include <cstdlib>
#include <string>
#include <vector>
@ -112,7 +113,7 @@ int VerifyCommand(const std::vector<std::string>& args)
if (input_file_path.empty())
{
std::cerr << "Error: No input set" << std::endl;
return 1;
return EXIT_FAILURE;
}
DiscIO::Hashes<bool> hashes_to_calculate{};
@ -136,7 +137,7 @@ int VerifyCommand(const std::vector<std::string>& args)
{
// optparse should protect from this
std::cerr << "Error: No algorithms selected for the operation" << std::endl;
return 1;
return EXIT_FAILURE;
}
// Open the volume
@ -144,7 +145,7 @@ int VerifyCommand(const std::vector<std::string>& args)
if (!volume)
{
std::cerr << "Error: Unable to open disc image" << std::endl;
return 1;
return EXIT_FAILURE;
}
// Verify the volume
@ -173,10 +174,10 @@ int VerifyCommand(const std::vector<std::string>& args)
else
{
std::cerr << "Error: No hash computed" << std::endl;
return 1;
return EXIT_FAILURE;
}
}
return 0;
return EXIT_SUCCESS;
}
} // namespace DolphinTool