From 5aac03a39b96dcfff4a7fd294e1e4d5bcbe1201f Mon Sep 17 00:00:00 2001 From: Thomas Emil Jensen Date: Fri, 29 Jul 2022 18:05:24 +0200 Subject: [PATCH] Setting to control update checking --- config/settings.conf | 1 + include/Definitions.hpp | 4 ++-- include/Settings.cpp | 44 +++++++++++++++++++++++++++++++---------- include/Settings.hpp | 24 ++++++++++++++++++++++ main.cpp | 33 +++++++++++++++++++++---------- userguide.md | 27 +++++++++++++++++++++---- 6 files changed, 107 insertions(+), 26 deletions(-) diff --git a/config/settings.conf b/config/settings.conf index 74077c5..3c83a97 100644 --- a/config/settings.conf +++ b/config/settings.conf @@ -1,3 +1,4 @@ +check enabled d . m keys i mathcad diff --git a/include/Definitions.hpp b/include/Definitions.hpp index 27fc42f..828bd59 100644 --- a/include/Definitions.hpp +++ b/include/Definitions.hpp @@ -23,8 +23,8 @@ namespace mcon #define STR(s) s #endif - #define MCON_VERSION "1.5.3" - #define MCON_VERSION_WRAPPED STR( "1.5.3" ) + #define MCON_VERSION "1.5.4" + #define MCON_VERSION_WRAPPED STR( "1.5.4" ) } #endif // __DEFINITIONS_H__ \ No newline at end of file diff --git a/include/Settings.cpp b/include/Settings.cpp index 729c020..6cfe774 100644 --- a/include/Settings.cpp +++ b/include/Settings.cpp @@ -8,9 +8,6 @@ namespace mcon lexer(std::move(character_stream), character_set) { character_set->LoadFromFolder("./resources/character-sets"); - STRING_OUTPUT - << STR("For usage information, enter \"help\" (without quote marks) or read the associated user guide.") - << std::endl; LoadSettings(); } @@ -109,6 +106,16 @@ namespace mcon Download(); break; } + case Setting::CheckUpdate: + { + check_update.first = check_update_settings.at(current_token.content); + check_update.second = a_console_input; + if (a_user_triggered) + { + STRING_OUTPUT << STR("\nUpdate checking behavior updated.\n") << std::endl; + } + break; + } case Setting::DecimalSeparator: { decimal_separator.first = decimal_separator_settings.at(current_token.content); @@ -198,19 +205,22 @@ namespace mcon << STR("\n") << STR("2. Show current settings s show settings [no arguments] s\n") << STR("\n") - << STR("3. Show user guide g guide userguide [no arguments] g\n") + << STR("3. Open user guide g guide userguide [no arguments] g\n") << STR("\n") << STR("4. Open download page download [no arguments] download\n") << STR("\n") - << STR("5. Set decimal separator d dec ds sep period . d ,\n") + << STR("5. Set update checking check enabled true check false\n") + << STR(" disabled false\n") + << STR("\n") + << STR("6. Set decimal separator d dec ds sep period . d ,\n") << STR(" comma ,\n") << STR("\n") - << STR("6. Set output mode m mode keys keystrokes m clip\n") + << STR("7. Set output mode m mode keys keystrokes m clip\n") << STR(" clip clipboard\n") << STR("\n") - << STR("7. Set input format i in input Mathcad mathcad i mathcad\n") + << STR("8. Set input format i in input Mathcad mathcad i mathcad\n") << STR("\n") - << STR("8. Set output format o out output Mathcad mathcad o latex\n") + << STR("9. Set output format o out output Mathcad mathcad o latex\n") << STR(" LaTeX Latex latex\n") << STR(" MathML mathml\n") << STR(" UnicodeMath unicodemath Unicode unicode\n") @@ -222,6 +232,7 @@ namespace mcon void Settings::ShowSettings() { + String current_update_checking; String current_decimal_separator; String current_input_language; String current_output_language; @@ -229,6 +240,7 @@ namespace mcon try { + current_update_checking = check_update_names.at(check_update.first); current_decimal_separator = decimal_separator_names.at(decimal_separator.first); current_output_mode = output_mode_names.at(output_mode.first); current_input_language = input_language_names.at(input_language.first); @@ -246,16 +258,19 @@ namespace mcon << STR("\n") << STR("Displaying current settings\n") << STR("----------------------------------------------------------------------------------------------------\n") + << STR("Update checking: ") + << current_update_checking + << STR("\n") << STR("Decimal separator: ") << current_decimal_separator << STR("\n") << STR("Output mode: ") << current_output_mode << STR("\n") - << STR("Input language: ") + << STR("Input format: ") << current_input_language << STR("\n") - << STR("Output language: ") + << STR("Output format: ") << current_output_language << STR("\n") << std::endl; @@ -278,6 +293,7 @@ namespace mcon void Settings::SaveSettings() { String commands = + check_update.second + STR("\n") + decimal_separator.second + STR("\n") + output_mode.second + STR("\n") + input_language.second + STR("\n") + @@ -289,6 +305,14 @@ namespace mcon return; } + void Settings::PrintTip() + { + STRING_OUTPUT + << STR("For usage information, enter \"help\" (without quote marks) or read the associated user guide.") + << std::endl; + return; + } + void Settings::Download() { STRING_OUTPUT << STR("\nOpening download page in browser...\n") << std::endl; diff --git a/include/Settings.hpp b/include/Settings.hpp index 1853271..f2bc81b 100644 --- a/include/Settings.hpp +++ b/include/Settings.hpp @@ -22,12 +22,19 @@ namespace mcon ShowSettings, ShowGuide, Download, + CheckUpdate, DecimalSeparator, InputLanguage, OutputLanguage, OutputMode }; + enum class UpdateChecking + { + Enabled, + Disabled + }; + enum class DecimalSeparator { Period, @@ -78,7 +85,9 @@ namespace mcon void ShowSettings(); void LoadSettings(); void SaveSettings(); + void PrintTip(); + std::pair check_update = {UpdateChecking::Enabled, STR("check enabled")}; std::pair decimal_separator = {DecimalSeparator::Period, STR("decimal period")}; std::pair output_mode = {OutputMode::Keystrokes, STR("mode keystrokes")}; std::pair input_language = {InputLanguage::Mathcad, STR("input mathcad")}; @@ -100,6 +109,7 @@ namespace mcon {STR("help"), Setting::Help}, {STR("?"), Setting::Help}, {STR("download"), Setting::Download}, + {STR("check"), Setting::CheckUpdate}, {STR("s"), Setting::ShowSettings}, {STR("show"), Setting::ShowSettings}, {STR("settings"), Setting::ShowSettings}, @@ -120,6 +130,20 @@ namespace mcon {STR("m"), Setting::OutputMode}, }; + const std::unordered_map check_update_names = + { + {UpdateChecking::Enabled, STR("Enabled")}, + {UpdateChecking::Disabled, STR("Disabled")}, + }; + + const std::unordered_map check_update_settings = + { + {STR("enabled"), UpdateChecking::Enabled}, + {STR("true"), UpdateChecking::Enabled}, + {STR("disabled"), UpdateChecking::Disabled}, + {STR("false"), UpdateChecking::Disabled}, + }; + const std::unordered_map decimal_separator_names = { {DecimalSeparator::Period, STR("Period (.)")}, diff --git a/main.cpp b/main.cpp index 08aa83f..695026a 100644 --- a/main.cpp +++ b/main.cpp @@ -58,24 +58,37 @@ int main() std::wcout.imbue(utf8); #endif - // Version output and check + // Version output STRING_OUTPUT << STR("math-converter-") << MCON_VERSION_WRAPPED << std::endl; - try + // Settings initialisation + auto settings_mutex = std::make_shared(); + auto settings = std::make_shared(); + + // Check for new releases + if (settings->check_update.first == mcon::UpdateChecking::Enabled) { - auto version = mcon::Version(MCON_VERSION); - version.Check(); + try + { + auto version = mcon::Version(MCON_VERSION); + version.Check(); + } + catch(const std::exception& e) + { + ERROR_OUTPUT + << STR("An error occured while checking for new releases.\n") + << std::endl; + } } - catch(const std::exception& e) + else { - ERROR_OUTPUT - << "An error occured while checking for an updated version.\n" + STRING_OUTPUT + << STR("Currently not checking for new releases upon launch.\n") << std::endl; } - // Settings initialisation - auto settings_mutex = std::make_shared(); - auto settings = std::make_shared(); + // Print usage tip + settings->PrintTip(); // hotkey_thread to catch hotkey triggers and convert math expressions // config_thread to handle input from the console diff --git a/userguide.md b/userguide.md index a00241f..4a2ecb5 100644 --- a/userguide.md +++ b/userguide.md @@ -1,4 +1,4 @@ -# User guide for math-converter-1.5.3 +# User guide for math-converter-1.5.4 ## Supported platforms @@ -62,14 +62,17 @@ While not all math syntax is supported, a variety of commonly-used features are The supported input character set can be extended with additional, user-made `.json` files under `/resources/character-sets/`, which are loaded at program launch. Characters not in the character sets will be discarded. Additionally, configuration can be achieved at runtime via the terminal window the program runs in. Settings are saved to `/config/settings.conf`. The currently supported configuration commands include: -- Display help +- Show help +- Show current settings +- Open user guide - Open download page +- Set update checking behavior - Set decimal separator - Set output mode - Set input format - Set output format -### Display help +### Show help This command displays help about the configuration commands. @@ -77,7 +80,15 @@ Command aliases: `h help ?`
Available arguments: none
Example: `h` -### Show user guide +### Show current settings + +This command displays the current settings for decimal separator, output mode, input format and output format. + +Command aliases: `s show settings`
+Available arguments: none
+Example: `s` + +### Open user guide This command opens the user guide on math-converter's Github. @@ -93,6 +104,14 @@ Command aliases: `download`
Available arguments: none
Example: `download` +### Set update checking behavior + +This command controls whether or not math-converter checks for new releases upon launch. + +Command aliases: `check`
+Available arguments: `enabled true disabled false`
+Example: `check false` + ### Set decimal separator This command sets the decimal separator to either a period or a comma. The default is a period.