diff --git a/XeRelease_Gtkmm3/CMakeLists.txt b/XeRelease_Gtkmm3/CMakeLists.txt index b4c176e..02dea14 100644 --- a/XeRelease_Gtkmm3/CMakeLists.txt +++ b/XeRelease_Gtkmm3/CMakeLists.txt @@ -16,7 +16,8 @@ pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0) include_directories (${GTKMM3_INCLUDE_DIRS}) link_directories (${GTKMM3_LIBRARY_DIRS}) -add_executable(XeRelease src/main.cc src/MyWin.cc src/MyDialog.cc src/resources.cpp) +add_executable(XeRelease src/main.cc src/MyWin.cc src/MyDialog.cc +src/xerelease.cc src/xeapi.cc src/resources.cpp) IF(WIN32) SET(CMAKE_EXE_LINKER_FLAGS -mwindows) diff --git a/XeRelease_Gtkmm3/src/MyWin.cc b/XeRelease_Gtkmm3/src/MyWin.cc index c8e9840..98358a1 100644 --- a/XeRelease_Gtkmm3/src/MyWin.cc +++ b/XeRelease_Gtkmm3/src/MyWin.cc @@ -1,6 +1,9 @@ #include "MyWin.hh" #include "img7.xpm" #include "winpe.xpm" +#include "xeapi.hh" +#include "xerelease.hh" +#include enum Releases{ LongTerm, @@ -25,6 +28,15 @@ input_dialog(*this) gtk_image_set_from_pixbuf(background.gobj(),sized->gobj()); overlay.add(background); + //Get Local time + time_t t; + t=time(NULL); + local=localtime(&t); + + //Initalize Api Label + sprintf(api_version,"Xe Api Version:%d",xeapi1(local)); + api_label.set_label(api_version); + //Initalize combobox combo.append("Longterm"); combo.append("Stable"); @@ -34,6 +46,7 @@ input_dialog(*this) //Add Main Controls btn_box.set_halign(Gtk::ALIGN_CENTER); btn_box.set_valign(Gtk::ALIGN_CENTER); + btn_box.pack_start(api_label,Gtk::PACK_SHRINK); btn_box.pack_start(combo,Gtk::PACK_SHRINK); btn_box.pack_start(btn_ver,Gtk::PACK_SHRINK); overlay.add_overlay(btn_box); @@ -98,6 +111,16 @@ void MyWin::background2(){ sized.reset(); } +bool MyWin::get_config(const char *filename){ + fp=fopen(filename,"rt+"); + if(fp==NULL){ + msg_dialog.Init("The config file not exist!\nUse Change config menu for a config"); + msg_dialog.show_all(); + return false; + } + return true; +} + void MyWin::config_lts(){ input_dialog.set_msg("Input Xe LTS Config"); input_dialog.set_filename("config_lts"); @@ -117,20 +140,40 @@ void MyWin::config_devel(){ } void MyWin::main_releases(){ + //Get Selection int version=combo.get_active_row_number(); - switch (version) + char str[57],ver[15];//Version and Full Version + switch (version)//Use Selection to Perform { case Releases::LongTerm: - msg_dialog.Init("Xe LongTerm Version:"); + if(get_config("config_lts")){ + fscanf(fp,"%s",ver); + longterm(local,ver,str); + msg_dialog.Init(str); + msg_dialog.show_all(); + fclose(fp); + } break; case Releases::Stable: - msg_dialog.Init("Xe Stable Version:"); + if(get_config("config_stable")){ + fscanf(fp,"%s",ver); + stable(local,ver,str); + msg_dialog.Init(str); + msg_dialog.show_all(); + fclose(fp); + } break; case Releases::Develop: - msg_dialog.Init("Xe Develop Version"); + if(get_config("config_devel")){ + fscanf(fp,"%s",ver); + develop(local,ver,str); + msg_dialog.Init(str); + msg_dialog.show_all(); + fclose(fp); + } break; } - msg_dialog.show_all(); + } void MyWin::about_dialog(){ diff --git a/XeRelease_Gtkmm3/src/MyWin.hh b/XeRelease_Gtkmm3/src/MyWin.hh index 0d2b391..d270f69 100644 --- a/XeRelease_Gtkmm3/src/MyWin.hh +++ b/XeRelease_Gtkmm3/src/MyWin.hh @@ -14,6 +14,7 @@ private: Gtk::Image background; Gtk::Overlay overlay; Gtk::Box btn_box; + Gtk::Label api_label; Gtk::ComboBoxText combo; Gtk::Button btn_ver; @@ -32,9 +33,13 @@ private: void background2(); //Version Configs + FILE *fp;//file pointer to read file + struct tm *local; + char api_version[57]; void config_lts(); void config_stable(); void config_devel(); + bool get_config(const char *filename); //Signal Handlers void about_dialog(); diff --git a/XeRelease_Gtkmm3/src/xeapi.cc b/XeRelease_Gtkmm3/src/xeapi.cc new file mode 100644 index 0000000..cd9c6a6 --- /dev/null +++ b/XeRelease_Gtkmm3/src/xeapi.cc @@ -0,0 +1,9 @@ +#include"xeapi.hh" +int xeapi1(struct tm *local){ + int year1=2019,month1=6,apiver=0; + int year2=local->tm_year+1900,month2=local->tm_mon+1; + //printf("%d %d",year1,year2); + apiver=(year2-year1)*12-month1+month2+22; + if(local->tm_mday<7) apiver--; + return apiver; +} diff --git a/XeRelease_Gtkmm3/src/xeapi.hh b/XeRelease_Gtkmm3/src/xeapi.hh new file mode 100644 index 0000000..8a825a3 --- /dev/null +++ b/XeRelease_Gtkmm3/src/xeapi.hh @@ -0,0 +1,9 @@ +#ifndef __XE_API_ +#define __XE_API_ + +#include +extern int xeapi1(struct tm *local); +//This header defines a function to calculate the month from 2019.6 to now +//The beginning is 2019.6,and the api version generated by this function >=20 + +#endif diff --git a/XeRelease_Gtkmm3/src/xerelease.cc b/XeRelease_Gtkmm3/src/xerelease.cc new file mode 100644 index 0000000..d3dff92 --- /dev/null +++ b/XeRelease_Gtkmm3/src/xerelease.cc @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include"xeapi.hh" + +//typedef void(*LP)(struct tm *local);//define a pointer function + +int total_day(int year,int month,int day) +{ + //Calculate day of 1 year + int sum=0; + switch(month){ + case 1: + sum=day;break; + case 2: + sum=day+31;break; + case 3: + sum=day+59;break; + case 4: + sum=day+90;break; + case 5: + sum=day+120;break; + case 6: + sum=day+151;break; + case 7: + sum=day+181;break; + case 8: + sum=day+212;break; + case 9: + sum=day+243;break; + 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 sum=0; + sum=(year2-year1)*365; + for(int i=year1;itm_year+1900,month2=local->tm_mon+1,day2=local->tm_mday; + lts_ver=total_year_day(year1,year2)-total_day(year1,month1,day1)+total_day(year2,month2,day2);//get release version + sprintf(str,"Xeinit LTS version:%s.%d\n",lts,lts_ver); + freopen(filename,"a",stdout);//put all output in xe-release file + printf("%4d-%02d-%02d ",local->tm_year+1900,local->tm_mon+1,local->tm_mday);//output:release branch time in xe-release + printf("%s.%d Api:%d\n",lts,lts_ver,xeapi1(local)); + fclose(stdout); + return ; +} + +void stable(struct tm *local,char rel[],char *str) +{ + char filename[57]; + 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; + devel1=total_year_day(year1,year2)-total_day(year1,month1,day1)+total_day(year2,month2,day2);//get release version + sprintf(str,"Xeinit stable Version:%s.%d\n",rel,devel1); + freopen(filename,"a",stdout); + printf("%4d-%02d-%02d ",local->tm_year+1900,local->tm_mon+1,local->tm_mday);//output:development branch time in xe-release + printf("%s.%d Api:%d\n",rel,devel1,xeapi1(local)); + fclose(stdout); + return ; +} + +void develop(struct tm *local,char devel[],char *str){ + char filename[57]; + 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; + devel1=total_year_day(year1,year2)-total_day(year1,month1,day1)+total_day(year2,month2,day2);//get release version + sprintf(str,"Xeinit devel Version:%s.%d\n",devel,devel1); + freopen(filename,"a",stdout); + printf("%4d-%02d-%02d ",local->tm_year+1900,local->tm_mon+1,local->tm_mday);//output:development branch time in xe-release + printf("%s.%d Api:%d\n",devel,devel1,xeapi1(local)); + fclose(stdout); + return ; +} diff --git a/XeRelease_Gtkmm3/src/xerelease.hh b/XeRelease_Gtkmm3/src/xerelease.hh new file mode 100644 index 0000000..68bb53a --- /dev/null +++ b/XeRelease_Gtkmm3/src/xerelease.hh @@ -0,0 +1,16 @@ +#ifndef __XE_RELEASE_ +#define __XE_RELEASE_ + +int total_day(int year,int month,int day); + +int total_year_day(int year1,int year2); + +void dale(struct tm *local); + +void longterm(struct tm *local,char lts[],char *str); + +void stable(struct tm *local,char rel[],char *str); + +void develop(struct tm *local,char devel[],char *str); + +#endif \ No newline at end of file