#include #define BUFFER_SIZE 512 #define OS_PATH "/phoenix/install/TI-Nspire.tnc" #define NLAUNCH_PATH "/phoenix/install/phoenix.tns" char buffer[BUFFER_SIZE]; char* ospath[]={OS_PATH,NLAUNCH_PATH}; #define NPATH sizeof(ospath)/sizeof(char*) #define TYPE_SIZE 8 #define BASE_SIZE 10 #define VERSION_SIZE 10 #define EXT_SIZE 4 #define DHEADER_SIZE 30 #define EHEADER_SIZE 46 typedef struct { char base[BASE_SIZE]; char ext[EXT_SIZE]; char version[VERSION_SIZE]; } osheader_s; int isFile(char* path) { struct stat s; s.st_mode=0; return !stat(path, &s); } void (*reset)(); void (*reset)()= (void*)0; char* getTypeExt(char* typestr, char* ext) { *typestr=0; switch(ext[1]) { case 'c': strcat(typestr," CX"); break; case 'm': strcat(typestr," CM"); } if(ext[2]=='c') strcat(typestr," CAS"); return typestr; } void getOSInfos(char* file, osheader_s* osheader) { memset(osheader,0,sizeof(osheader_s)); FILE* h=fopen(file,"rb"); if(h) { fscanf(h,"%s %s ",osheader->base, osheader->version); osheader->base[BASE_SIZE-1]=0; fclose(h); } } unsigned int size = 0; char* zipfooter = 0; int ifooter = -1; int itoc = -1; int datasize = 0; int onumfiles = 0; int footersize = 0; int sizeoffset = -1; int getInt(char* buf, int n) { unsigned int r = 0; int i; for(i=n-1;i>=0;i--) { r = r<<8; r += buf[i]; } return r; } int searchFile(FILE* h, char* str, int size, int start, int end) { int l = strlen(str); char* tmp = malloc(l+1); int i = start; int f=-1; if(tmp) { f=0; tmp[l]=0; if(start>size-l) start = size-l; if(end>size-l) end = size-l; if(start<0) start = 0; if(end<0) end = 0; fseek(h,start,SEEK_SET); while(((i>=start && i<=end) || (i<=start && i>=end)) && !f) { fread(tmp,1,l,h); if(!strcmp(tmp,str)) f=1; else if(end=0 && !progname;i--) if(argv[0][i]=='/') progname=argv[0]+i+1; if(progname) { for(i=strlen(progname)-1;i>=0;i--) if(progname[i]=='.') { progname[i]=0; i=0; } cfg_register_fileext("tcc",progname); cfg_register_fileext("tco",progname); cfg_register_fileext("tmc",progname); cfg_register_fileext("tmo",progname); cfg_register_fileext("tnc",progname); cfg_register_fileext("tno",progname); cfg_register_fileext("tlo",progname); sprintf(buffer,"%s installed !",progname); show_msgbox("Info", buffer); } } else { while(ios%s, you may also need to reset minOS.\nIf I am not a %s%s, or if this is a 3.6+ altered OS image, you'll also need an appropriate boot helper.",osheader_new.base,getTypeExt(typestr,osheader_new.ext),osheader_new.version,osheader_new.version,osheader_new.base,typestr); result=show_msgbox_2b("Install OS ?", buffer, "Yes", "No"); if(result==1) { sprintf(buffer,"Do you want to backup your current %s%s %s OS ?",osheader_old.base,getTypeExt(typestrold,osheader_old.ext),osheader_old.version); result=show_msgbox_3b("Save OS ?", buffer, "Yes", "No", "Cancel"); if(result!=3) { h=fopen(argv[1],"rb"); if(h) { zipoffset = searchFile(h,"PK\x03\x04",size,0,size-4); if(zipoffset) zipoffset=getZipFileDataOffset(argv[1],zipoffset,"TI-Nspire.img"); if(zipoffset) zipoffset = searchFile(h,"PK\x03\x04",size,zipoffset,size-4); fclose(h); } if(zipoffset) { extract_zip(argv[1],"/",0,zipoffset); if(result==1) { sprintf(buffer,"/documents/%s.%s.tns",osheader_old.version,osheader_old.ext); remove(buffer); rename(ospath[ios],buffer); sprintf(buffer,"Your current %s%s %s OS image has been backuped to /documents/%s.%s.\n",osheader_old.base,typestrold,osheader_old.version,osheader_old.version,osheader_old.ext); } else { remove(ospath[ios]); *buffer=0; } rename(argv[1],ospath[ios]); strcat(buffer,"New OS image injected and extracted.\nReset the calculator to use it.\nDo you want to reset now ?"); result=show_msgbox_2b("Reset ?", buffer, "Yes", "No"); if(result==1) reset(); } } } } } }