Change config file to json

This commit is contained in:
daleclack 2022-07-26 10:36:50 +08:00
parent 241211c4e9
commit 07aa1278a5
5 changed files with 134 additions and 53 deletions

View File

@ -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"
}
}

View File

@ -33,6 +33,7 @@ MyDialog::MyDialog(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &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)){

View File

@ -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);
longterm(local, config_longterm.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();
}
break;
case Releases::Stable:
if (readCfgFile("xe_config", "Stable", ver))
{
stable(local, ver.c_str(), str);
stable(local, config_stable.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();
}
break;
case Releases::Dev:
if (readCfgFile("xe_config", "Develop", ver))
{
develop(local, ver.c_str(), str);
develop(local, config_devel.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();
}
break;
}
}

View File

@ -2,7 +2,6 @@
#include <gtkmm.h>
#include "MyDialog.hh"
#include "../cfgfile2/cfgfile.hh"
class MyWin : public Gtk::ApplicationWindow
{

View File

@ -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)
{
// Get Config from json file
std::ifstream json_file("xe_config.json");
if (json_file.is_open())
{
// 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())
{
if(readCfgFile("xe_config","Release_Path_Unix",path)){
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)