Add Api Show

This commit is contained in:
daleclack 2021-06-24 20:36:12 +08:00
parent 229c7569ad
commit 3d3888a3a9
7 changed files with 192 additions and 6 deletions

View File

@ -16,7 +16,8 @@ pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
include_directories (${GTKMM3_INCLUDE_DIRS}) include_directories (${GTKMM3_INCLUDE_DIRS})
link_directories (${GTKMM3_LIBRARY_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) IF(WIN32)
SET(CMAKE_EXE_LINKER_FLAGS -mwindows) SET(CMAKE_EXE_LINKER_FLAGS -mwindows)

View File

@ -1,6 +1,9 @@
#include "MyWin.hh" #include "MyWin.hh"
#include "img7.xpm" #include "img7.xpm"
#include "winpe.xpm" #include "winpe.xpm"
#include "xeapi.hh"
#include "xerelease.hh"
#include <cstdio>
enum Releases{ enum Releases{
LongTerm, LongTerm,
@ -25,6 +28,15 @@ input_dialog(*this)
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj()); gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
overlay.add(background); 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 //Initalize combobox
combo.append("Longterm"); combo.append("Longterm");
combo.append("Stable"); combo.append("Stable");
@ -34,6 +46,7 @@ input_dialog(*this)
//Add Main Controls //Add Main Controls
btn_box.set_halign(Gtk::ALIGN_CENTER); btn_box.set_halign(Gtk::ALIGN_CENTER);
btn_box.set_valign(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(combo,Gtk::PACK_SHRINK);
btn_box.pack_start(btn_ver,Gtk::PACK_SHRINK); btn_box.pack_start(btn_ver,Gtk::PACK_SHRINK);
overlay.add_overlay(btn_box); overlay.add_overlay(btn_box);
@ -98,6 +111,16 @@ void MyWin::background2(){
sized.reset(); 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(){ void MyWin::config_lts(){
input_dialog.set_msg("Input Xe LTS Config"); input_dialog.set_msg("Input Xe LTS Config");
input_dialog.set_filename("config_lts"); input_dialog.set_filename("config_lts");
@ -117,20 +140,40 @@ void MyWin::config_devel(){
} }
void MyWin::main_releases(){ void MyWin::main_releases(){
//Get Selection
int version=combo.get_active_row_number(); 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: 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; break;
case Releases::Stable: 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; break;
case Releases::Develop: 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; break;
} }
msg_dialog.show_all();
} }
void MyWin::about_dialog(){ void MyWin::about_dialog(){

View File

@ -14,6 +14,7 @@ private:
Gtk::Image background; Gtk::Image background;
Gtk::Overlay overlay; Gtk::Overlay overlay;
Gtk::Box btn_box; Gtk::Box btn_box;
Gtk::Label api_label;
Gtk::ComboBoxText combo; Gtk::ComboBoxText combo;
Gtk::Button btn_ver; Gtk::Button btn_ver;
@ -32,9 +33,13 @@ private:
void background2(); void background2();
//Version Configs //Version Configs
FILE *fp;//file pointer to read file
struct tm *local;
char api_version[57];
void config_lts(); void config_lts();
void config_stable(); void config_stable();
void config_devel(); void config_devel();
bool get_config(const char *filename);
//Signal Handlers //Signal Handlers
void about_dialog(); void about_dialog();

View File

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

View File

@ -0,0 +1,9 @@
#ifndef __XE_API_
#define __XE_API_
#include<ctime>
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

View File

@ -0,0 +1,103 @@
#include<cstdio>
#include<ctime>
#include<cstring>
#include<cstdlib>
#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;i<year2;i++){
if(i%4==0&&i%100!=0){
sum=sum+1;
}
}
return sum;
}
void dale(struct tm *local)
{
printf("xeinit release maker by dale\n");
}
void longterm(struct tm *local,char lts[],char *str)
{
char filename[57];
sprintf(filename,"xe-%c.x",lts[0]);
int lts_ver=0;//release version
int year1=2019,month1=1,day1=11,year2=local->tm_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 ;
}

View File

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