diff options
| author | a1xd <[email protected]> | 2021-09-22 00:22:27 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-09-22 00:22:27 -0400 |
| commit | 993900cbe46c4ec5cffff54e33cbfe5c162dbad1 (patch) | |
| tree | 340dc29e927a8d7bbc19baa4f7099c29e09dd322 /converter/converter.cpp | |
| parent | remove converter questions, add notes instead (diff) | |
| download | rawaccel-993900cbe46c4ec5cffff54e33cbfe5c162dbad1.tar.xz rawaccel-993900cbe46c4ec5cffff54e33cbfe5c162dbad1.zip | |
converter - use argv for IA settings path
Diffstat (limited to 'converter/converter.cpp')
| -rw-r--r-- | converter/converter.cpp | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/converter/converter.cpp b/converter/converter.cpp index bb76bce..46adc02 100644 --- a/converter/converter.cpp +++ b/converter/converter.cpp @@ -214,7 +214,7 @@ bool try_convert(const ia_settings_t& ia_settings) { return true; } -int main() +int main(int argc, char** argv) { auto close_prompt = [] { std::cout << "Press any key to close this window . . ." << std::endl; @@ -222,6 +222,19 @@ int main() std::exit(0); }; + auto convert_or_print_error = [](auto&& path) { + try { + if (!try_convert(parse_ia_settings(path))) + std::cout << "Unable to convert settings.\n"; + } + catch (Exception^ e) { + Console::WriteLine("\nError: {0}", e); + } + catch (const std::exception& e) { + std::cout << "Error: " << e.what() << '\n'; + } + }; + try { VersionHelper::ValidOrThrow(); } @@ -230,42 +243,38 @@ int main() close_prompt(); } - std::optional<fs::path> opt_path; - - if (fs::exists(IA_SETTINGS_NAME)) { - opt_path = IA_SETTINGS_NAME; + if (argc == 2 && fs::exists(argv[1])) { + convert_or_print_error(argv[1]); } else { - for (auto&& entry : fs::directory_iterator(".")) { - if (fs::is_regular_file(entry) && - entry.path().extension() == IA_PROFILE_EXT) { - opt_path = entry; - break; - } + std::optional<fs::path> opt_path; + + if (fs::exists(IA_SETTINGS_NAME)) { + opt_path = IA_SETTINGS_NAME; } - } - - if (opt_path) { - std::string path = opt_path->filename().generic_string(); - std::stringstream ss; - ss << "Found " << path << - "\n\nConvert and send settings generated from " << path << '?'; - if (ask(ss.str())) { - try { - if (!try_convert(parse_ia_settings(opt_path.value()))) - std::cout << "Unable to convert settings.\n"; + else { + for (auto&& entry : fs::directory_iterator(".")) { + if (fs::is_regular_file(entry) && + entry.path().extension() == IA_PROFILE_EXT) { + opt_path = entry; + break; + } } - catch (Exception^ e) { - Console::WriteLine("\nError: {0}", e); - } - catch (const std::exception& e) { - std::cout << "Error: " << e.what() << '\n'; + } + + if (opt_path) { + std::string path = opt_path->filename().generic_string(); + std::stringstream ss; + ss << "Found " << path << + "\n\nConvert and send settings generated from " << path << '?'; + if (ask(ss.str())) { + convert_or_print_error(opt_path.value()); } } - } - else { - std::cout << "Drop your InterAccel settings/profile into this directory.\n" - "Then run this program to generate the equivalent Raw Accel settings.\n"; + else { + std::cout << "Drop your InterAccel settings/profile into this directory.\n" + "Then run this program to generate the equivalent Raw Accel settings.\n"; + } } close_prompt(); |