Update:Allow custom path of release

This commit is contained in:
daleclack 2021-12-31 22:49:10 +08:00
parent 117ecf438b
commit feb85700c9
8 changed files with 281 additions and 87 deletions

View File

@ -24,6 +24,27 @@
} }
] ]
}, },
{
"name": "(gdb) 启动win32)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/builddir_win32/XeRelease.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "Meson: Build target",
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "D:/msys64/mingw64/bin/gdb.exe"
},
{ {
"name": "(lldb) 启动", "name": "(lldb) 启动",
"type": "cppdbg", "type": "cppdbg",

View File

@ -2,7 +2,7 @@
"tasks": [ "tasks": [
{ {
"type": "meson", "type": "meson",
"target": "XeRelease", //"target": "XeRelease",
"mode": "build", "mode": "build",
"group": "build", "group": "build",
"problemMatcher": [], "problemMatcher": [],

View File

@ -15,6 +15,19 @@
<object class="GtkButtonBox"> <object class="GtkButtonBox">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="layout-style">end</property> <property name="layout-style">end</property>
<child>
<object class="GtkButton" id="btnpath">
<property name="label" translatable="yes">Custom Path</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child> <child>
<object class="GtkButton" id="btn_ok"> <object class="GtkButton" id="btn_ok">
<property name="label" translatable="yes">OK</property> <property name="label" translatable="yes">OK</property>
@ -25,7 +38,7 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -38,7 +51,7 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>
@ -72,7 +85,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<!-- n-columns=2 n-rows=3 --> <!-- n-columns=2 n-rows=4 -->
<object class="GtkGrid"> <object class="GtkGrid">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
@ -157,6 +170,29 @@
<property name="top-attach">2</property> <property name="top-attach">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Path:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_path">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="text" translatable="yes">./</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>

View File

@ -11,6 +11,9 @@ ref_Glade(ref_builder)
ref_builder->get_widget("entry_lts",entry_lts); ref_builder->get_widget("entry_lts",entry_lts);
ref_builder->get_widget("entry_stable",entry_stable); ref_builder->get_widget("entry_stable",entry_stable);
ref_builder->get_widget("entry_dev",entry_dev); ref_builder->get_widget("entry_dev",entry_dev);
ref_builder->get_widget("entry_path",entry_path);
ref_builder->get_widget("btnpath",btnpath);
//Read Configs //Read Configs
std::string config; std::string config;
if(readCfgFile("xe_config","Longterm",config)){ if(readCfgFile("xe_config","Longterm",config)){
@ -22,6 +25,18 @@ ref_Glade(ref_builder)
if(readCfgFile("xe_config","Develop",config)){ if(readCfgFile("xe_config","Develop",config)){
entry_dev->set_text(config); entry_dev->set_text(config);
} }
readCfgFile("xe_config","Release_Path_Unix",config_unix);
readCfgFile("xe_config","Release_Path_Win32",config_win32);
//Use different path for Linux filesystem and Windows
if(unix_file_system_detected()){
entry_path->set_text(config_unix);
}else{
entry_path->set_text(config_win32);
}
//Connect Signal
btnpath->signal_clicked().connect(sigc::mem_fun(*this,&MyDialog::btnpath_clicked));
} }
void MyDialog::on_response(int response_id){ void MyDialog::on_response(int response_id){
@ -29,7 +44,22 @@ void MyDialog::on_response(int response_id){
if(response_id == Gtk::RESPONSE_OK){ if(response_id == Gtk::RESPONSE_OK){
Glib::ustring config; Glib::ustring config;
std::fstream outfile; std::fstream outfile;
//Initalize Config for path
if(unix_file_system_detected()){
config_unix = entry_path->get_text();
}else{
config_win32 = entry_path->get_text();
}
//Open the config file
outfile.open("xe_config",std::ios_base::out); outfile.open("xe_config",std::ios_base::out);
/*OutPut contents to the file
Simple Contents of xe_config:
Longterm=x.x
Stable=x.x
Develop=x.x
Release_Path_Unix=/xxx/xxx
Release_Path_Win32=X:\xxx\xxx
*/
if(outfile.is_open()){ if(outfile.is_open()){
outfile<<"This is the config file of Xe Release"<<std::endl; outfile<<"This is the config file of Xe Release"<<std::endl;
outfile<<"See more on github.com/daleclack/Xe-Release"<<std::endl; outfile<<"See more on github.com/daleclack/Xe-Release"<<std::endl;
@ -40,6 +70,8 @@ void MyDialog::on_response(int response_id){
outfile<<"Stable="<<config<<std::endl; outfile<<"Stable="<<config<<std::endl;
config=entry_dev->get_text(); config=entry_dev->get_text();
outfile<<"Develop="<<config<<std::endl; outfile<<"Develop="<<config<<std::endl;
outfile<<"Release_Path_Unix="<<config_unix<<std::endl;
outfile<<"Release_Path_Win32="<<config_win32<<std::endl;
} }
outfile.close(); outfile.close();
} }
@ -57,6 +89,24 @@ MyDialog * MyDialog::create(Gtk::Window& parent){
return dialog; return dialog;
} }
void MyDialog::btnpath_clicked(){
//Create a Dialog
dialog = Gtk::FileChooserNative::create("Select a folder",*this,
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER,"OK","Cancel");
dialog->signal_response().connect(sigc::mem_fun(*this,&MyDialog::dialog_response));
dialog->show();
}
void MyDialog::dialog_response(int response_id){
if(response_id == Gtk::RESPONSE_ACCEPT){
Glib::ustring path = dialog->get_filename();
entry_path->set_text(path);
}
dialog.reset();
}
MsgBox::MsgBox(Gtk::Window &parent) MsgBox::MsgBox(Gtk::Window &parent)
:hbox(Gtk::ORIENTATION_HORIZONTAL,5) :hbox(Gtk::ORIENTATION_HORIZONTAL,5)
{ {

View File

@ -12,7 +12,17 @@ protected:
void on_response(int response_id) override; void on_response(int response_id) override;
private: private:
Glib::RefPtr<Gtk::Builder> ref_Glade; Glib::RefPtr<Gtk::Builder> ref_Glade;
Gtk::Entry * entry_lts,* entry_stable,* entry_dev; //Child widgets
Gtk::Entry * entry_lts,* entry_stable,* entry_dev,* entry_path;
Gtk::Button * btnpath;
//Strings to store path on Windows and Unix-Like systems
std::string config_win32,config_unix;
//Signal Handlers
Glib::RefPtr<Gtk::FileChooserNative> dialog;
void btnpath_clicked();
void dialog_response(int response_id);
}; };
class MsgBox : public Gtk::Dialog{ class MsgBox : public Gtk::Dialog{
@ -28,3 +38,11 @@ private:
Gtk::Label msg_label; Gtk::Label msg_label;
Gtk::Box *vbox,hbox; Gtk::Box *vbox,hbox;
}; };
static inline bool unix_file_system_detected(){
#ifdef _WIN32
return false;
#else
return true;
#endif
}

View File

@ -62,7 +62,7 @@ msg_dialog(*this)
void MyWin::titlebar_init(){ void MyWin::titlebar_init(){
//Add HeaderBar //Add HeaderBar
header.set_title("Xe Release 13"); header.set_title("Xe Release 14");
header.set_show_close_button(); header.set_show_close_button();
header.set_decoration_layout("close,minimize:menu"); header.set_decoration_layout("close,minimize:menu");
set_titlebar(header); set_titlebar(header);
@ -162,7 +162,7 @@ void MyWin::main_releases(){
void MyWin::about_dialog(){ void MyWin::about_dialog(){
char *version; char *version;
version=g_strdup_printf("13.0\nRunning Against Gtkmm %d.%d.%d", version=g_strdup_printf("14.0\nRunning Against Gtkmm %d.%d.%d",
GTKMM_MAJOR_VERSION, GTKMM_MAJOR_VERSION,
GTKMM_MINOR_VERSION, GTKMM_MINOR_VERSION,
GTKMM_MICRO_VERSION); GTKMM_MICRO_VERSION);

View File

@ -1,103 +1,164 @@
#include<cstdio> #include <cstdio>
#include<ctime> #include <ctime>
#include<cstring> #include <cstring>
#include<cstdlib> #include <cstdlib>
#include"xeapi.hh" #include "xerelease.hh"
#include "xeapi.hh"
#include "cfgfile2/cfgfile.hh"
//typedef void(*LP)(struct tm *local);//define a pointer function // typedef void(*LP)(struct tm *local);//define a pointer function
int total_day(int year,int month,int day) int total_day(int year, int month, int day)
{ {
//Calculate day of 1 year // Calculate day of 1 year
int sum=0; int sum = 0;
switch(month){ switch (month)
case 1: {
sum=day;break; case 1:
case 2: sum = day;
sum=day+31;break; break;
case 3: case 2:
sum=day+59;break; sum = day + 31;
case 4: break;
sum=day+90;break; case 3:
case 5: sum = day + 59;
sum=day+120;break; break;
case 6: case 4:
sum=day+151;break; sum = day + 90;
case 7: break;
sum=day+181;break; case 5:
case 8: sum = day + 120;
sum=day+212;break; break;
case 9: case 6:
sum=day+243;break; sum = day + 151;
case 10: break;
sum=day+273;break; case 7:
case 11: sum = day + 181;
sum=day+304;break; break;
case 12: case 8:
sum=day+334;break; sum = day + 212;
default: break;
printf("Date Wrong!"); case 9:
} sum = day + 243;
if(year%4==0&&year%100!=0) sum=sum+1; break;
return sum; case 10:
sum = day + 273;
break;
case 11:
sum = day + 304;
break;
case 12:
sum = day + 334;
break;
default:
printf("Date Wrong!");
}
if (year % 4 == 0 && year % 100 != 0)
sum = sum + 1;
return sum;
} }
int total_year_day(int year1,int year2){//Calculate day of years int total_year_day(int year1, int year2)
int sum=0; {
sum=(year2-year1)*365; // Calculate day of years
for(int i=year1;i<year2;i++){ int sum = 0;
if(i%4==0&&i%100!=0){ sum = (year2 - year1) * 365;
sum=sum+1; for (int i = year1; i < year2; i++)
} {
} if (i % 4 == 0 && i % 100 != 0)
return sum; {
sum = sum + 1;
}
}
return sum;
}
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())
{
if(readCfgFile("xe_config","Release_Path_Unix",path)){
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]);
}
}
} }
void dale(struct tm *local) void dale(struct tm *local)
{ {
printf("xeinit release maker by dale\n"); printf("xeinit release maker by dale\n");
} }
void longterm(struct tm *local,const char * lts,char *str) void longterm(struct tm *local, const char *lts, char *str)
{ {
// Print Version of longterm release in the file
char filename[57]; char filename[57];
sprintf(filename,"xe-%c.x",lts[0]); path_translate(filename,lts);
int lts_ver=0;//release version //sprintf(filename, "xe-%c.x", lts[0]);
int year1=2019,month1=1,day1=11,year2=local->tm_year+1900,month2=local->tm_mon+1,day2=local->tm_mday; int lts_ver = 0; // default release version
lts_ver=total_year_day(year1,year2)-total_day(year1,month1,day1)+total_day(year2,month2,day2);//get release version int year1 = 2019, month1 = 1, day1 = 11, year2 = local->tm_year + 1900,
sprintf(str,"Xeinit LTS version:%s.%d\n",lts,lts_ver); month2 = local->tm_mon + 1, day2 = local->tm_mday;
freopen(filename,"a",stdout);//put all output in xe-release file // get release version
printf("%4d-%02d-%02d ",local->tm_year+1900,local->tm_mon+1,local->tm_mday);//output:release branch time in xe-release lts_ver = total_year_day(year1, year2) - total_day(year1, month1, day1) +
printf("%s.%d Api:%d\n",lts,lts_ver,xeapi1(local)); total_day(year2, month2, day2);
// For show in dialog or console
sprintf(str, "Xeinit LTS version:%s.%d\n", lts, lts_ver);
freopen(filename, "a", stdout);
// put all output in the release file
// output:release branch time in xe-release
printf("%4d-%02d-%02d ", local->tm_year + 1900, local->tm_mon + 1, local->tm_mday);
printf("%s.%d Api:%d\n", lts, lts_ver, xeapi1(local));
fclose(stdout); fclose(stdout);
return ; return;
} }
void stable(struct tm *local,const char * rel,char *str) void stable(struct tm *local, const char *rel, char *str)
{ {
// Print Version of stable release in the file
char filename[57]; char filename[57];
sprintf(filename,"xe-%c.x",rel[0]); path_translate(filename,rel);
int devel1;//stable release version //sprintf(filename, "xe-%c.x", rel[0]);
int year1=2017,month1=5,day1=19,year2=local->tm_year+1900,month2=local->tm_mon+1,day2=local->tm_mday; int devel1; // stable release version
devel1=total_year_day(year1,year2)-total_day(year1,month1,day1)+total_day(year2,month2,day2);//get release version int year1 = 2017, month1 = 5, day1 = 19, year2 = local->tm_year + 1900,
sprintf(str,"Xeinit stable Version:%s.%d\n",rel,devel1); month2 = local->tm_mon + 1, day2 = local->tm_mday;
freopen(filename,"a",stdout); // get release version
printf("%4d-%02d-%02d ",local->tm_year+1900,local->tm_mon+1,local->tm_mday);//output:development branch time in xe-release devel1 = total_year_day(year1, year2) - total_day(year1, month1, day1) +
printf("%s.%d build:%d\n",rel,devel1,xeapi1(local)); total_day(year2, month2, day2);
sprintf(str, "Xeinit stable Version:%s.%d\n", rel, devel1);
freopen(filename, "a", stdout);
// put all output in the release file
// output:development branch time in xe-release
printf("%4d-%02d-%02d ", local->tm_year + 1900, local->tm_mon + 1, local->tm_mday);
printf("%s.%d build:%d\n", rel, devel1, xeapi1(local));
fclose(stdout); fclose(stdout);
return ; return;
} }
void develop(struct tm *local,const char * devel,char *str){ void develop(struct tm *local, const char *devel, char *str)
{
// Print Version of develop release in the file
char filename[57]; char filename[57];
sprintf(filename,"xe-%c.x",devel[0]); path_translate(filename,devel);
int devel1;//development version //sprintf(filename, "xe-%c.x", devel[0]);
int year1=2017,month1=5,day1=19,year2=local->tm_year+1900,month2=local->tm_mon+1,day2=local->tm_mday; int devel1; // development version
devel1=total_year_day(year1,year2)-total_day(year1,month1,day1)+total_day(year2,month2,day2);//get release version int year1 = 2017, month1 = 5, day1 = 19, year2 = local->tm_year + 1900,
sprintf(str,"Xeinit devel Version:%s.%d\n",devel,devel1); month2 = local->tm_mon + 1, day2 = local->tm_mday;
freopen(filename,"a",stdout); // get release version
printf("%4d-%02d-%02d ",local->tm_year+1900,local->tm_mon+1,local->tm_mday);//output:development branch time in xe-release devel1 = total_year_day(year1, year2) - total_day(year1, month1, day1) +
printf("%s.%d build:%d\n",devel,devel1,xeapi1(local)); total_day(year2, month2, day2);
sprintf(str, "Xeinit devel Version:%s.%d\n", devel, devel1);
freopen(filename, "a", stdout);
// put all output in the release file
// output:development branch time in xe-release
printf("%4d-%02d-%02d ", local->tm_year + 1900, local->tm_mon + 1, local->tm_mday);
printf("%s.%d build:%d\n", devel, devel1, xeapi1(local));
fclose(stdout); fclose(stdout);
return ; return;
} }

View File

@ -13,4 +13,12 @@ void stable(struct tm *local,const char * rel,char *str);
void develop(struct tm *local,const char * devel,char *str); void develop(struct tm *local,const char * devel,char *str);
static inline bool rel_unix_file_system_detected(){
#ifdef _WIN32
return false;
#else
return true;
#endif
}
#endif #endif