DolphinTool: Less string copies

This commit is contained in:
get 2023-06-16 19:33:38 -05:00
parent 5029924ba1
commit e67c196d2a
3 changed files with 18 additions and 23 deletions

View file

@ -61,9 +61,11 @@ int ConvertCommand(const std::vector<std::string>& args)
parser.usage("usage: convert [options]... [FILE]..."); parser.usage("usage: convert [options]... [FILE]...");
parser.add_option("-u", "--user") parser.add_option("-u", "--user")
.type("string")
.action("store") .action("store")
.help("User folder path, required for temporary processing files. " .help("User folder path, required for temporary processing files. "
"Will be automatically created if this option is not set."); "Will be automatically created if this option is not set.")
.set_default("");
parser.add_option("-i", "--input") parser.add_option("-i", "--input")
.type("string") .type("string")
@ -110,34 +112,29 @@ int ConvertCommand(const std::vector<std::string>& args)
// Initialize the dolphin user directory, required for temporary processing files // Initialize the dolphin user directory, required for temporary processing files
// If this is not set, destructive file operations could occur due to path confusion // If this is not set, destructive file operations could occur due to path confusion
std::string user_directory; UICommon::SetUserDirectory(options["user"]);
if (options.is_set("user"))
user_directory = static_cast<const char*>(options.get("user"));
UICommon::SetUserDirectory(user_directory);
UICommon::Init(); UICommon::Init();
// Validate options // Validate options
// --input // --input
const std::string input_file_path = static_cast<const char*>(options.get("input")); if (!options.is_set("input"))
if (input_file_path.empty())
{ {
std::cerr << "Error: No input set" << std::endl; std::cerr << "Error: No input set" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
const std::string& input_file_path = options["input"];
// --output // --output
const std::string output_file_path = static_cast<const char*>(options.get("output")); if (!options.is_set("output"))
if (output_file_path.empty())
{ {
std::cerr << "Error: No output set" << std::endl; std::cerr << "Error: No output set" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
const std::string& output_file_path = options["output"];
// --format // --format
const std::optional<DiscIO::BlobType> format_o = const std::optional<DiscIO::BlobType> format_o = ParseFormatString(options["format"]);
ParseFormatString(static_cast<const char*>(options.get("format")));
if (!format_o.has_value()) if (!format_o.has_value())
{ {
std::cerr << "Error: No output format set" << std::endl; std::cerr << "Error: No output format set" << std::endl;
@ -255,7 +252,7 @@ int ConvertCommand(const std::vector<std::string>& args)
// --compress, --compress_level // --compress, --compress_level
std::optional<DiscIO::WIARVZCompressionType> compression_o = std::optional<DiscIO::WIARVZCompressionType> compression_o =
ParseCompressionTypeString(static_cast<const char*>(options.get("compression"))); ParseCompressionTypeString(options["compression"]);
std::optional<int> compression_level_o; std::optional<int> compression_level_o;
if (options.is_set("compression_level")) if (options.is_set("compression_level"))

View file

@ -43,7 +43,7 @@ int HeaderCommand(const std::vector<std::string>& args)
const optparse::Values& options = parser.parse_args(args); const optparse::Values& options = parser.parse_args(args);
// Validate options // Validate options
const std::string input_file_path = static_cast<const char*>(options.get("input")); const std::string& input_file_path = options["input"];
if (input_file_path.empty()) if (input_file_path.empty())
{ {
std::cerr << "Error: No input set" << std::endl; std::cerr << "Error: No input set" << std::endl;

View file

@ -80,9 +80,11 @@ int VerifyCommand(const std::vector<std::string>& args)
parser.usage("usage: verify [options]..."); parser.usage("usage: verify [options]...");
parser.add_option("-u", "--user") parser.add_option("-u", "--user")
.type("string")
.action("store") .action("store")
.help("User folder path, required for temporary processing files. " .help("User folder path, required for temporary processing files. "
"Will be automatically created if this option is not set."); "Will be automatically created if this option is not set.")
.set_default("");
parser.add_option("-i", "--input") parser.add_option("-i", "--input")
.type("string") .type("string")
@ -101,20 +103,16 @@ int VerifyCommand(const std::vector<std::string>& args)
// Initialize the dolphin user directory, required for temporary processing files // Initialize the dolphin user directory, required for temporary processing files
// If this is not set, destructive file operations could occur due to path confusion // If this is not set, destructive file operations could occur due to path confusion
std::string user_directory; UICommon::SetUserDirectory(options["user"]);
if (options.is_set("user"))
user_directory = static_cast<const char*>(options.get("user"));
UICommon::SetUserDirectory(user_directory);
UICommon::Init(); UICommon::Init();
// Validate options // Validate options
const std::string input_file_path = static_cast<const char*>(options.get("input")); if (!options.is_set("input"))
if (input_file_path.empty())
{ {
std::cerr << "Error: No input set" << std::endl; std::cerr << "Error: No input set" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
const std::string& input_file_path = options["input"];
DiscIO::Hashes<bool> hashes_to_calculate{}; DiscIO::Hashes<bool> hashes_to_calculate{};
const bool algorithm_is_set = options.is_set("algorithm"); const bool algorithm_is_set = options.is_set("algorithm");
@ -124,7 +122,7 @@ int VerifyCommand(const std::vector<std::string>& args)
} }
else else
{ {
const std::string algorithm = static_cast<const char*>(options.get("algorithm")); const std::string& algorithm = options["algorithm"];
if (algorithm == "crc32") if (algorithm == "crc32")
hashes_to_calculate.crc32 = true; hashes_to_calculate.crc32 = true;
else if (algorithm == "md5") else if (algorithm == "md5")