diff --git a/XeRelease_Gtkmm3/.vscode/settings.json b/XeRelease_Gtkmm3/.vscode/settings.json index a6b3266..28debd9 100644 --- a/XeRelease_Gtkmm3/.vscode/settings.json +++ b/XeRelease_Gtkmm3/.vscode/settings.json @@ -6,6 +6,79 @@ "array": "cpp", "string": "cpp", "string_view": "cpp", - "*.inc": "cpp" + "*.inc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "any": "cpp", + "atomic": "cpp", + "hash_map": "cpp", + "strstream": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cfenv": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "source_location": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "variant": "cpp" } } \ No newline at end of file diff --git a/XeRelease_Gtkmm3/src/MyDialog.cc b/XeRelease_Gtkmm3/src/MyDialog.cc index d6dca1d..248bed1 100644 --- a/XeRelease_Gtkmm3/src/MyDialog.cc +++ b/XeRelease_Gtkmm3/src/MyDialog.cc @@ -33,6 +33,7 @@ MyDialog::MyDialog(BaseObjectType *cobject, const Glib::RefPtr &re entry_stable->set_text(config_stable); entry_dev->set_text(config_devel); } + json_file.close(); // std::string config; // if(readCfgFile("xe_config","Longterm",config)){ diff --git a/XeRelease_Gtkmm3/src/MyWin.cc b/XeRelease_Gtkmm3/src/MyWin.cc index a5fdd78..e108fc8 100644 --- a/XeRelease_Gtkmm3/src/MyWin.cc +++ b/XeRelease_Gtkmm3/src/MyWin.cc @@ -56,7 +56,7 @@ MyWin::MyWin() // Show everything add(stack1); - stack1.add(overlay,"main_page","WelCome"); + stack1.add(overlay, "main_page", "WelCome"); switcher.set_stack(stack1); show_all_children(); @@ -68,7 +68,7 @@ MyWin::MyWin() void MyWin::titlebar_init() { // Add HeaderBar - //header.set_title("Xe Release 15"); + // header.set_title("Xe Release 15"); // Add stack widget header.set_custom_title(switcher); @@ -86,7 +86,7 @@ void MyWin::titlebar_init() add_action("configs", sigc::mem_fun(*this, &MyWin::config_dialog)); add_action("back1", sigc::mem_fun(*this, &MyWin::background1)); add_action("back2", sigc::mem_fun(*this, &MyWin::background2)); - add_action("back3",sigc::mem_fun(*this,&MyWin::background3)); + add_action("back3", sigc::mem_fun(*this, &MyWin::background3)); add_action("about", sigc::mem_fun(*this, &MyWin::about_dialog)); add_action("quit", sigc::mem_fun(*this, &MyWin::hide)); @@ -120,7 +120,8 @@ void MyWin::background2() sized.reset(); } -void MyWin::background3(){ +void MyWin::background3() +{ // Set Background Image auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(fly); auto sized = pixbuf->scale_simple(640, 360, Gdk::INTERP_BILINEAR); @@ -147,50 +148,44 @@ void MyWin::main_releases() { // Get Selection int version = combo.get_active_row_number(); - std::string ver; // Version and Full Version char str[57]; // Get Configs + std::string config_longterm, config_stable, config_devel; + // Open json file + std::ifstream json_file("xe_config.json"); + json data; + if (json_file.is_open()) + { + // Read data from json file + data = json::parse(json_file); + config_longterm = data["Longterm"]; + config_stable = data["Stable"]; + config_devel = data["Develop"]; + } + else + { + msg_dialog.Init("The config doesn't exist!\nPlease use \"Config\" menu to set releases"); + msg_dialog.show_all(); + return; + } + json_file.close(); switch (version) // Use Selection to Perform { case Releases::LTS: - if (readCfgFile("xe_config", "Longterm", ver)) - { - longterm(local, ver.c_str(), str); - msg_dialog.Init(str); - msg_dialog.show_all(); - } - else - { - msg_dialog.Init("The config doesn't exist!\nPlease use \"Config\" menu to set releases"); - msg_dialog.show_all(); - } + longterm(local, config_longterm.c_str(), str); + msg_dialog.Init(str); + msg_dialog.show_all(); break; case Releases::Stable: - if (readCfgFile("xe_config", "Stable", ver)) - { - stable(local, ver.c_str(), str); - msg_dialog.Init(str); - msg_dialog.show_all(); - } - else - { - msg_dialog.Init("The config doesn't exist!\nPlease use \"Config\" menu to set releases"); - msg_dialog.show_all(); - } + stable(local, config_stable.c_str(), str); + msg_dialog.Init(str); + msg_dialog.show_all(); break; case Releases::Dev: - if (readCfgFile("xe_config", "Develop", ver)) - { - develop(local, ver.c_str(), str); - msg_dialog.Init(str); - msg_dialog.show_all(); - } - else - { - msg_dialog.Init("The config doesn't exist!\nPlease use \"Config\" menu to set releases"); - msg_dialog.show_all(); - } + develop(local, config_devel.c_str(), str); + msg_dialog.Init(str); + msg_dialog.show_all(); break; } } diff --git a/XeRelease_Gtkmm3/src/MyWin.hh b/XeRelease_Gtkmm3/src/MyWin.hh index 2b15f32..6f2af85 100644 --- a/XeRelease_Gtkmm3/src/MyWin.hh +++ b/XeRelease_Gtkmm3/src/MyWin.hh @@ -2,7 +2,6 @@ #include #include "MyDialog.hh" -#include "../cfgfile2/cfgfile.hh" class MyWin : public Gtk::ApplicationWindow { diff --git a/XeRelease_Gtkmm3/src/xerelease.cc b/XeRelease_Gtkmm3/src/xerelease.cc index 7bb9127..baf610f 100644 --- a/XeRelease_Gtkmm3/src/xerelease.cc +++ b/XeRelease_Gtkmm3/src/xerelease.cc @@ -5,6 +5,9 @@ #include "xerelease.hh" #include "xeapi.hh" #include "cfgfile2/cfgfile.hh" +#include "../json_nlohmann/json.hpp" + +using json = nlohmann::json; // typedef void(*LP)(struct tm *local);//define a pointer function @@ -75,20 +78,30 @@ int total_year_day(int year1, int year2) static void path_translate(char *result, const char *version) { - // Just combine the release file path and filename - std::string path; - if (rel_unix_file_system_detected()) + // Get Config from json file + std::ifstream json_file("xe_config.json"); + if (json_file.is_open()) { - if(readCfgFile("xe_config","Release_Path_Unix",path)){ + // Read data from json file + json data = json::parse(json_file); + // Just combine the release file path and filename + std::string path; + if (rel_unix_file_system_detected()) + { + path = data["Release_Path_Unix"]; sprintf(result, "%s/xe-%c.x", path.c_str(), version[0]); } + else + { + path = data["Release_Path_Win32"]; + sprintf(result, "%s\\xe-%c.x", path.c_str(), version[0]); + } } else { - if(readCfgFile("xe_config","Release_Path_Win32",path)){ - sprintf(result, "%s\\xe-%c.x", path.c_str(), version[0]); - } + sprintf(result, "./xe-%c.x", version[0]); } + json_file.close(); } void dale(struct tm *local) @@ -100,8 +113,8 @@ void longterm(struct tm *local, const char *lts, char *str) { // Print Version of longterm release in the file char filename[57]; - path_translate(filename,lts); - //sprintf(filename, "xe-%c.x", lts[0]); + path_translate(filename, lts); + // sprintf(filename, "xe-%c.x", lts[0]); int lts_ver = 0; // default release version int year1 = 2019, month1 = 1, day1 = 11, year2 = local->tm_year + 1900, month2 = local->tm_mon + 1, day2 = local->tm_mday; @@ -123,8 +136,8 @@ void stable(struct tm *local, const char *rel, char *str) { // Print Version of stable release in the file char filename[57]; - path_translate(filename,rel); - //sprintf(filename, "xe-%c.x", rel[0]); + path_translate(filename, rel); + // sprintf(filename, "xe-%c.x", rel[0]); int devel1; // stable release version int year1 = 2017, month1 = 5, day1 = 19, year2 = local->tm_year + 1900, month2 = local->tm_mon + 1, day2 = local->tm_mday; @@ -145,8 +158,8 @@ void develop(struct tm *local, const char *devel, char *str) { // Print Version of develop release in the file char filename[57]; - path_translate(filename,devel); - //sprintf(filename, "xe-%c.x", devel[0]); + path_translate(filename, devel); + // sprintf(filename, "xe-%c.x", devel[0]); int devel1; // development version int year1 = 2017, month1 = 5, day1 = 19, year2 = local->tm_year + 1900, month2 = local->tm_mon + 1, day2 = local->tm_mday;