#include "os.h" // keep it low for CP/TP running OS 3.9... #define BUFFER_SIZE (2*1024*1024) #define NUMBUF_SIZE 8 #define OS_PATH "/phoenix/install/TI-Nspire.tnc" #define NLAUNCH_PATH "/phoenix/install/phoenix.tns" #define TMP_PATH "/documents/TI-Nspire.light.tnc.tns" #define DHEADER_SIZE 30 #define EHEADER_SIZE 46 #define MIN(a,b) ((a)<(b)?(a):(b)) char buffer[BUFFER_SIZE]; char bufnum[NUMBUF_SIZE]; char* ospath[]={OS_PATH,NLAUNCH_PATH}; #define NPATH sizeof(ospath)/sizeof(char*) int error = 0; unsigned int size = 0; char* zipfooter = 0; char* ziptoc = 0; char* zipheader = 0; int ifooter = -1; int itoc = -1; int idata = -1; int headersize = 0; int tocsize = 0; int datasize = 0; int onumfiles = 0; int numfiles = 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(end0) { fseek(hi,start,SEEK_SET); while(size) { tsize=MIN(BUFFER_SIZE,size); if(tsize==fread(buffer,1,tsize,hi)); size-=fwrite(buffer,1,tsize,ho); } } return size<=0; } char* prettySize(int n) { if(n<1000) sprintf(bufnum,"%dB",n); else if(n<1000000) sprintf(bufnum,"%d.%02dKB",n/1000,(n%1000)/10); else sprintf(bufnum,"%d.%02dMB",n/1000000,((n/1000)%1000)/10); return bufnum; } int main() { char* tmp; int i, esize, nsize, newsize, ios=0, ok=0; FILE* h=0; while(ios0) remove(TMP_PATH); if(!nl_isstartup() && error>=0) { if(!error) { char bufnum1[NUMBUF_SIZE]; prettySize(size); strcpy(bufnum1,bufnum); char bufnum2[NUMBUF_SIZE]; prettySize(newsize); strcpy(bufnum2,bufnum); sprintf(buffer,"%s[%s]\n%s[%s]\nYour OS image has been optimized.\nYou've gained %s.",ospath[ios],bufnum1,ospath[ios],bufnum2,prettySize(size-newsize)); } else strcpy(buffer,"Error : Your OS image couldn't be optimized..."); show_msgbox("Info",buffer); } return 0; }