Exemplo n.º 1
0
void EXPORT_CALL cfgLoadStr(const wchar * Section, const wchar * Key, wchar * Return,const wchar* Default)
{
	verify(Section!=0 && wcslen(Section)!=0);
	verify(Key!=0 && wcslen(Key)!=0);
	verify(Return!=0);
	if (Default==0)
		Default=L"";
	ConfigSection* cs= cfgdb.GetEntry(Section);
	ConfigEntry* ce=cs->FindEntry(Key);
	if (!ce)
	{
		cs->SetEntry(Key,Default,CEM_SAVE);
		wcscpy(Return,Default);
	}
	else
	{
		wcscpy(Return,ce->GetValue().c_str());
	}
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
void EXPORT_CALL cfgSaveStr(const wchar * Section, const wchar * Key, const wchar * String)
{
	cfgdb.GetEntry(Section)->SetEntry(Key,String,CEM_SAVE);
	savecfgf();
	//WritePrivateProfileString(Section,Key,String,cfgPath);
}