void ini_updateFile(int compress) { gzFile zf = NULL; FILE *f = NULL; iniElem *aux; if (ini.comment == NULL) return ; if (compress) { zf = gzopen(get_ini_path(), "wb"); gzprintf(zf, "%s", ini.comment); } else { f = fopen(get_ini_path(), "wb"); fprintf(f, "%s", ini.comment); } aux = ini.list; while (aux != NULL) { if (compress) { gzprintf(zf, "[%s]\n", aux->entry.MD5); gzprintf(zf, "Good Name=%s\n", aux->entry.goodname); gzprintf(zf, "Header Code=%s\n", aux->entry.CRC); if (strcmp(aux->entry.refMD5, "")) gzprintf(zf, "Reference=%s\n", aux->entry.refMD5); if (aux->entry.eeprom16kb == 1) gzprintf(zf, "Eeprom=16k\n"); if (strcmp(aux->entry.comments, "")) gzprintf(zf, "Comments=%s\n", aux->entry.comments); gzprintf(zf, "\n"); } else { fprintf(f, "[%s]\n", aux->entry.MD5); fprintf(f, "Good Name=%s\n", aux->entry.goodname); fprintf(f, "Header Code=%s\n", aux->entry.CRC); if (strcmp(aux->entry.refMD5, "")) fprintf(f, "Reference=%s\n", aux->entry.refMD5); if (aux->entry.eeprom16kb == 1) fprintf(f, "Eeprom=16k\n"); if (strcmp(aux->entry.comments, "")) fprintf(f, "Comments=%s\n", aux->entry.comments); fprintf(f, "\n"); } aux = aux->next_entry; } if (compress) gzclose(zf); else fclose(f); }
int open_ini(HWND hwnd,int explore) { WIN32_FIND_DATA fd; HANDLE h; char str[MAX_PATH+80]; if(h=FindFirstFile(ini_file,&fd)!=INVALID_HANDLE_VALUE){ FindClose(h); if(explore){ if(get_ini_path(str,sizeof(str))) ShellExecute(hwnd,"explore",str,NULL,NULL,SW_SHOWNORMAL); } else{ if(ini_file[0]!=0) if(ShellExecute(hwnd,"open","notepad.exe",ini_file,NULL,SW_SHOWNORMAL)<=32) ShellExecute(hwnd,"open",ini_file,NULL,NULL,SW_SHOWNORMAL); } } else if(hwnd!=0){ memset(str,0,sizeof(str)); _snprintf(str,sizeof(str)-1,"cant locate ini file:\r\n%s",ini_file); MessageBox(hwnd,str,"Error",MB_OK); } return TRUE; }
int get_lua_script_fname(char *fname,int len) { if(fname!=0 && len>0){ fname[0]=0; get_ini_path(fname,len); _snprintf(fname,len,"%s%s",fname,LUA_SCRIPT_NAME); } return 0; }
void ini_openFile() { gzFile f; char buf[256]; int i=0; iniElem *cur = NULL; if (ini.comment != NULL) return; memset( &emptyEntry,0,sizeof(emptyEntry)); f = gzopen(get_ini_path(), "rb"); if (f==NULL) return; do { gzgets(f, buf, 255); if (buf[0] != '[') { i+= strlen(buf); if (ini.comment == NULL) { ini.comment = (char*)malloc(i+1); strcpy(ini.comment, buf); } else { ini.comment = (char*)realloc(ini.comment, i+1); strcat(ini.comment, buf); } } } while (buf[0] != '[' && !gzeof(f)); for (i=0; i<255; i++) { ini.CRC_lists[i] = NULL; } ini.list = NULL; do { if (buf[0] == '[') { if (ini.list == NULL) { ini.list = (iniElem*)malloc(sizeof(iniElem)); ini.list->next_entry = NULL; ini.list->next_crc = NULL; ini.list->next_MD5 = NULL; cur = ini.list; } else { cur->next_entry = (iniElem*)malloc(sizeof(iniElem)); cur = cur->next_entry; cur->next_crc = NULL; cur->next_MD5 = NULL; } i = strlen(buf); while(buf[i] != ']') i--; buf[i] = 0; strncpy(cur->entry.MD5, buf+1, 32); cur->entry.MD5[32] = '\0'; buf[3] = 0; sscanf(buf+1, "%X", &i); if (ini.MD5_lists[i] == NULL) ini.MD5_lists[i] = cur; else { iniElem *aux = ini.MD5_lists[i]; cur->next_MD5 = aux; ini.MD5_lists[i] = cur; } cur->entry.eeprom16kb = 0; strcpy(cur->entry.refMD5, ""); strcpy(cur->entry.comments, ""); } else { i = split_property(buf); if (i != -1) { if (!strcmp(buf, "Good Name")) { if (buf[i+1+strlen(buf+i+1)-1] == '\n') buf[i+1+strlen(buf+i+1)-1] = '\0'; if (buf[i+1+strlen(buf+i+1)-1] == '\r') buf[i+1+strlen(buf+i+1)-1] = '\0'; strncpy(cur->entry.goodname, buf+i+1, 99); } else if (!strcmp(buf, "Header Code")) { strncpy(cur->entry.CRC, buf+i+1, 21); cur->entry.CRC[21] = '\0'; buf[i+3] = 0; sscanf(buf+i+1, "%X", &i); if (ini.CRC_lists[i] == NULL) ini.CRC_lists[i] = cur; else { iniElem *aux = ini.CRC_lists[i]; cur->next_crc = aux; ini.CRC_lists[i] = cur; } } else if (!strcmp(buf, "Reference")) { strncpy(cur->entry.refMD5, buf+i+1, 32); cur->entry.refMD5[32] = '\0'; } else if (!strcmp(buf, "Eeprom")) { if (!strncmp(buf+i+1, "16k", 3)) cur->entry.eeprom16kb = 1; } else if (!strcmp(buf, "Comments")) { if (buf[i+1+strlen(buf+i+1)-1] == '\n') buf[i+1+strlen(buf+i+1)-1] = '\0'; if (buf[i+1+strlen(buf+i+1)-1] == '\r') buf[i+1+strlen(buf+i+1)-1] = '\0'; strcpy(cur->entry.comments, buf+i+1); } } } gzgets(f, buf, 255); } while (!gzeof(f)); gzclose(f); }
void lua_script_init(lua_State **L,HANDLE **lua_filenotify,__int64 *ft) { char fscript[MAX_PATH]={0}; int script_changed=FALSE; get_lua_script_fname(fscript,sizeof(fscript)); if(lua_script_enable){ __int64 tt=0; get_last_write_time(fscript,&tt); if(tt!=(*ft)){ script_changed=TRUE; hide_tooltip(); } } if(lua_script_enable){ if((*L)==0 || script_changed){ lua_State *lua; lua=luaL_newstate(); if(lua!=0){ luaL_openlibs(lua); if(luaL_loadfile(lua,fscript)!=LUA_OK){ printf("luaL_loadfile error:%s\n",lua_tostring(lua, -1)); show_tooltip(lua_tostring(lua, -1),0,0); lua_close(lua); } else{ lua_register_c_functions(lua); if(lua_pcall(lua,0,0,0)!=LUA_OK){ printf("lua_pcall error:%s\n",lua_tostring(lua, -1)); show_tooltip(lua_tostring(lua, -1),0,0); lua_close(lua); } else{ if((*L)!=0) lua_close(*L); *L=lua; get_last_write_time(fscript,ft); lua_error_msg=0; hide_tooltip(); } } } } } if(*lua_filenotify!=0){ if(FindNextChangeNotification(*lua_filenotify)==0){ FindCloseChangeNotification(*lua_filenotify); *lua_filenotify=0; } } if(*lua_filenotify==0){ HANDLE fn; char path[MAX_PATH]={0}; get_ini_path(path,sizeof(path)); fn=FindFirstChangeNotification(path,FALSE,FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_LAST_WRITE); if(fn!=INVALID_HANDLE_VALUE) *lua_filenotify=fn; } }