void HStorage_WriteDataToFile(varStorage_t* vobj, const char* filename){ fileHandle_t file; char infostring[8192], buf[128]; int i; char name[MAX_VARNAME]; char *string; int count; vsMemObj_t* obj; vsValue_t value; varType_t type; mvabuf; obj = vobj->memObj; file = FS_SV_FOpenFileWrite(va("%s.tmp", filename)); if(!file){ Com_PrintError("HStorage_WriteDataToFile: Can not open %s for writing\n", filename); return; } HStorage_IterInit( obj ); while(HStorage_IterHasNext( obj )) { count = HStorage_IterGetNextInfo( obj, name, &type ); if(count == 0) { continue; } *infostring = 0; BigInfo_SetValueForKey(infostring, "name", name); BigInfo_SetValueForKey(infostring, "type", HStorage_EnumToVarType(type)); BigInfo_SetValueForKey(infostring, "count", va("%d", count)); for(i = 0; i < count; i++) { if(HStorage_GetDataInternal(obj, &value) == 0) { break; } if(type == VSVAR_STRING) { string = HStorage_ValueToString(type, &value, buf, sizeof(buf)); BigInfo_SetEncodedValueForKey(infostring, va("v%d", i), string, strlen(string)); }else{ BigInfo_SetValueForKey(infostring, va("v%d", i), HStorage_ValueToString(type, &value, buf, sizeof(buf))); } } Q_strcat(infostring, sizeof(infostring), "\\\n"); FS_Write(infostring, strlen(infostring), file); } FS_FCloseFile(file); FS_SV_HomeCopyFile(va("%s.tmp", filename) , (char*)filename); }
void SV_WriteBanlist(){ banList_t *this; time_t aclock; time(&aclock); fileHandle_t file; char infostring[1024]; int i; file = FS_SV_FOpenFileWrite(va("%s.tmp", banlistfile->string)); if(!file){ Com_PrintError("SV_WriteBanlist: Can not open %s for writing\n",banlistfile->string); return; } this = banlist; if(!this) return; for(i = 0 ; i < current_banindex; this++, i++){ if(this->expire == (time_t)-1 || this->expire > aclock){ *infostring = 0; if(this->playeruid > 0){ Info_SetValueForKey(infostring, "uid", va("%i", this->playeruid)); }else if(this->pbguid[7]){ Info_SetValueForKey(infostring, "guid", this->pbguid); }else{ continue; } Info_SetValueForKey(infostring, "nick", this->playername); Info_SetValueForKey(infostring, "rsn", this->reason); Info_SetValueForKey(infostring, "exp", va("%i", this->expire)); Info_SetValueForKey(infostring, "auid", va("%i", this->adminuid)); Q_strcat(infostring, sizeof(infostring), "\\\n"); FS_Write(infostring,strlen(infostring),file); } } FS_FCloseFile(file); FS_SV_HomeCopyFile(va("%s.tmp", banlistfile->string) ,banlistfile->string); // FS_SV_Rename(va("%s.tmp", banlist->string),banlist->string); }