void savecfgf() { FILE* cfgfile = _tfopen(cfgPath,L"wt"); if (!cfgfile) log("Error : Unable to open file for saving \n"); else { cfgdb.SaveFile(cfgfile); fclose(cfgfile); } }
bool cfgOpen() { wchar * tmpPath = GetEmuPath(L""); wcscpy(appPath, tmpPath); free(tmpPath); if (cfgPath[0]==0) swprintf(cfgPath,L"%snullDC.cfg", appPath); swprintf(dataPath,L"%sdata\\", appPath); swprintf(pluginPath,L"%splugins\\", appPath); ConfigSection* cs= cfgdb.GetEntry(L"emu"); cs->SetEntry(L"AppPath",appPath,CEM_VIRTUAL | CEM_READONLY); cs->SetEntry(L"PluginPath",pluginPath,CEM_VIRTUAL | CEM_READONLY); cs->SetEntry(L"DataPath",dataPath,CEM_VIRTUAL | CEM_READONLY); cs->SetEntry(L"FullName",VER_FULLNAME,CEM_VIRTUAL | CEM_READONLY); cs->SetEntry(L"ShortName",VER_SHORTNAME,CEM_VIRTUAL | CEM_READONLY); cs->SetEntry(L"Name",VER_EMUNAME,CEM_VIRTUAL | CEM_READONLY); FILE* cfgfile = _tfopen(cfgPath,L"r"); if(!cfgfile) { cfgfile = _tfopen(cfgPath,L"wt"); if(!cfgfile) log("Unable to open the config file for reading or writing\nfile : %s\n",cfgPath); else { fprintf(cfgfile,";; nullDC cfg file ;;\n\n"); fseek(cfgfile,0,SEEK_SET); fclose(cfgfile); cfgfile = _tfopen(cfgPath,L"r"); if(!cfgfile) log("Unable to open the config file for reading\nfile : %s\n",cfgPath); } } wchar line[512]; wchar cur_sect[512]={0}; int cline=0; while(cfgfile && !feof(cfgfile)) { cline++; fgetws(line,512,cfgfile); if (wcslen(line)<3) continue; if (line[wcslen(line)-1]=='\r' || line[wcslen(line)-1]=='\n') line[wcslen(line)-1]=0; wchar* tl=trim_ws(line); if (tl[0]=='[' && tl[wcslen(tl)-1]==']') { tl[wcslen(tl)-1]=0; wcscpy(cur_sect,tl+1); trim_ws(cur_sect); } else { if (cur_sect[0]==0) continue;//no open section wchar* str1=wcsstr(tl,L"="); if (!str1) { wprintf(L"Malformed entry on cfg, ignoring @ %d(%s)\n",cline,tl); continue; } *str1=0; str1++; wchar* v=trim_ws(str1); wchar* k=trim_ws(tl); if (v && k) { ConfigSection*cs=cfgdb.GetEntry(cur_sect); //if (!cs->FindEntry(k)) cs->SetEntry(k,v,CEM_SAVE|CEM_LOAD); } else { wprintf(L"Malformed entry on cfg, ignoring @ %d(%s)\n",cline,tl); } } } for (size_t i=0;i<vlist.size();i++) { cfgdb.GetEntry(vlist[i].s)->SetEntry(vlist[i].n,vlist[i].v,CEM_VIRTUAL); } if (cfgfile) { cfgdb.SaveFile(cfgfile); fclose(cfgfile); } return true; }