//--------------------------------------------------------------------------- void __fastcall WriteWindowBasicInformationToIniFile(const char * section, TForm * form) { // window position and size GetIniFile()->WriteInteger(section, "Width", form->Width); GetIniFile()->WriteInteger(section, "Height", form->Height); GetIniFile()->WriteInteger(section, "Left", form->Left); GetIniFile()->WriteInteger(section, "Top", form->Top); }
void wxXMergeDatabases (wxApp * theApp, Display * display) { XrmDatabase homeDB, serverDB, applicationDB; char filenamebuf[1024]; char *filename = &filenamebuf[0]; char *environment; wxString classname = theApp->GetClassName(); char name[256]; (void) strcpy (name, "/usr/lib/X11/app-defaults/"); (void) strcat (name, classname.c_str()); /* Get application defaults file, if any */ applicationDB = XrmGetFileDatabase (name); (void) XrmMergeDatabases (applicationDB, &wxResourceDatabase); /* Merge server defaults, created by xrdb, loaded as a property of the root * window when the server initializes and loaded into the display * structure on XOpenDisplay; * if not defined, use .Xdefaults */ if (XResourceManagerString (display) != NULL) { serverDB = XrmGetStringDatabase (XResourceManagerString (display)); } else { (void) GetIniFile (filename, NULL); serverDB = XrmGetFileDatabase (filename); } XrmMergeDatabases (serverDB, &wxResourceDatabase); /* Open XENVIRONMENT file, or if not defined, the .Xdefaults, * and merge into existing database */ if ((environment = getenv ("XENVIRONMENT")) == NULL) { size_t len; environment = GetIniFile (filename, NULL); len = strlen (environment); wxString hostname = wxGetHostName(); if ( !!hostname ) strncat(environment, hostname, 1024 - len); } homeDB = XrmGetFileDatabase (environment); XrmMergeDatabases (homeDB, &wxResourceDatabase); }
/** * * [devices] * portX = pad * * [pad X] * api = joydev * * [joydev X] * button0 = 1 * button1 = 2 * ... * * */ bool SaveSetting(int port, const std::string& key, CONFIGVARIANT& var) { OSDebugOut(L"USBqemu save \"%s\" to [%S %d]\n", var.name, key.c_str(), port); std::wstringstream section; std::wstring wkey; wkey.assign(key.begin(), key.end()); section << wkey << " " << port; std::wstring ini; GetIniFile(ini); switch (var.type) { case CONFIG_TYPE_BOOL: return SaveSettingValue(ini, section.str(), var.name, var.boolValue); case CONFIG_TYPE_INT: return SaveSettingValue(ini, section.str(), var.name, var.intValue); case CONFIG_TYPE_TCHAR: return SaveSettingValue(ini, section.str(), var.name, var.wstrValue); case CONFIG_TYPE_WCHAR: return SaveSettingValue(ini, section.str(), var.name, var.wstrValue); case CONFIG_TYPE_CHAR: return SaveSettingValue(ini, section.str(), var.name, var.strValue); default: OSDebugOut(L"Invalid config type %d for %s\n", var.type, var.name); break; }; return false; }
bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) { if (!wxResourceDatabase) { Display *display = wxGlobalDisplay(); wxXMergeDatabases (wxTheApp, display); } XrmDatabase database; if (file != "") { char buffer[500]; // Is this right? Trying to get it to look in the user's // home directory instead of current directory -- JACS (void) GetIniFile (buffer, file); wxNode *node = wxResourceCache.Find (buffer); if (node) database = (XrmDatabase) node->Data (); else { database = XrmGetFileDatabase (buffer); wxResourceCache.Append (buffer, (wxObject *) database); } } else database = wxResourceDatabase; XrmValue xvalue; char *str_type[20]; char buf[150]; strcpy (buf, section); strcat (buf, "."); strcat (buf, entry); Bool success = XrmGetResource (database, buf, "*", str_type, &xvalue); // Try different combinations of upper/lower case, just in case... if (!success) { buf[0] = (isupper (buf[0]) ? tolower (buf[0]) : toupper (buf[0])); success = XrmGetResource (database, buf, "*", str_type, &xvalue); } if (success) { if (*value) delete[] *value; *value = new char[xvalue.size + 1]; strncpy (*value, xvalue.addr, (int) xvalue.size); return true; } return false; }
//--------------------------------------------------------------------------- void __fastcall ReadWindowBasicInformationFromIniFile(const char * section, TForm * form) { // window position and size int w, h, l, t; w = GetIniFile()->ReadInteger(section, "Width", -1); if(w == -1) w = form->Width; h = GetIniFile()->ReadInteger(section, "Height", -1); if(h == -1) h = form->Height; l = GetIniFile()->ReadInteger(section, "Left", -1); if(l == -1) l = form->Left; t = GetIniFile()->ReadInteger(section, "Top", -1); if(t == -1) t = form->Top; if(l > Screen->DesktopWidth + Screen->DesktopLeft) l = 0; if(t > Screen->DesktopHeight + Screen->DesktopTop) t = 0; form->SetBounds(l, t, w, h); }
void SaveConfig() { Config *Conf1 = &conf; std::wstring szIniFile; TCHAR szValue[256]; GetIniFile(szIniFile); FILE *f = nullptr; auto err = _wfopen_s(&f, szIniFile.c_str(), L"a+"); if (!f) { MessageBoxW(NULL, L"Cannot save to ini!", L"USBqemu", MB_ICONERROR); } else fclose(f); swprintf_s(szValue,L"%u",Conf1->Log); WritePrivateProfileString(TEXT("Interface"), TEXT("Logging"),szValue,szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->DFPPass); WritePrivateProfileString(TEXT("Devices"), TEXT("DFP Passthrough"),szValue,szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->Port0); WritePrivateProfileString(TEXT("Devices"), TEXT("Port 0"),szValue,szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->Port1); WritePrivateProfileString(TEXT("Devices"), TEXT("Port 1"),szValue,szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->WheelType[0]); WritePrivateProfileString(TEXT("Devices"), TEXT("Wheel Type 1"),szValue,szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->WheelType[1]); WritePrivateProfileString(TEXT("Devices"), TEXT("Wheel Type 2"),szValue,szIniFile.c_str()); WritePrivateProfileString(TEXT("Devices"), TEXT("USB Image"),Conf1->usb_img,szIniFile.c_str()); WritePrivateProfileString(TEXT("Devices"), TEXT("Mic 1"), Conf1->mics[0].c_str(), szIniFile.c_str()); WritePrivateProfileString(TEXT("Devices"), TEXT("Mic 2"), Conf1->mics[1].c_str(), szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->MicBuffering); WritePrivateProfileString(TEXT("Devices"), TEXT("Mic Buffering"),szValue,szIniFile.c_str()); //WritePrivateProfileString("Joystick", "Player1", player_joys[0].c_str(), szIniFile); //WritePrivateProfileString("Joystick", "Player2", player_joys[1].c_str(), szIniFile); }
void LoadConfig() { Config *Conf1 = &conf; std::wstring szIniFile; wchar_t szValue[MAX_PATH+1]; char tmpA[MAX_PATH + 1] = { 0 }; size_t num = 0; GetIniFile(szIniFile); FILE *fp = nullptr; auto err = _wfopen_s(&fp, szIniFile.c_str(), L"rt");//check if ini really exists if (!fp) { memset(&conf, 0, sizeof(conf)); conf.Log = 0;//default value SaveConfig();//save and return return ; } fclose(fp); GetPrivateProfileStringW(L"Interface", L"Logging", NULL, szValue, 20, szIniFile.c_str()); Conf1->Log = wcstoul(szValue, NULL, 10); GetPrivateProfileStringW(N_DEVICES, TEXT("DFP Passthrough"), NULL, szValue, 20, szIniFile.c_str()); Conf1->DFPPass = wcstoul(szValue, NULL, 10); GetPrivateProfileStringW(N_DEVICES, N_DEVICE_PORT0, NULL, szValue, ARRAYSIZE(szValue), szIniFile.c_str()); wcstombs_s(&num, tmpA, szValue, sizeof(tmpA));//TODO error-check Conf1->Port0 = tmpA; GetPrivateProfileStringW(N_DEVICES, N_DEVICE_PORT1, NULL, szValue, ARRAYSIZE(szValue), szIniFile.c_str()); wcstombs_s(&num, tmpA, szValue, sizeof(tmpA));//TODO error-check Conf1->Port1 = tmpA; GetPrivateProfileStringW(N_DEVICES, N_WHEEL_TYPE0, NULL, szValue, 20, szIniFile.c_str()); Conf1->WheelType[0] = wcstoul(szValue, NULL, 10); GetPrivateProfileStringW(N_DEVICES, N_WHEEL_TYPE1, NULL, szValue, 20, szIniFile.c_str()); Conf1->WheelType[1] = wcstoul(szValue, NULL, 10); return ; }
static VectorMap<String, String>& sIniKeys() { static VectorMap<String, String> key; static int version; if(version != ini_version__) { version = ini_version__; key = LoadIniFile(GetIniFile()); #ifdef PLATFORM_WIN32 if(key.GetCount() == 0) key = LoadIniFile(~GetExeDirFile("q.ini")); if(key.GetCount() == 0) key = LoadIniFile("c:\\q.ini"); #endif #ifdef PLATFORM_POSIX if(key.GetCount() == 0) key = LoadIniFile(GetHomeDirFile("q.ini")); #endif } return key; }
void SaveConfig() { Config *Conf1 = &conf; std::wstring szIniFile; TCHAR szValue[256]; GetIniFile(szIniFile); FILE *f = nullptr; auto err = _wfopen_s(&f, szIniFile.c_str(), L"a+"); if (!f) { MessageBoxW(NULL, L"Cannot save to ini!", L"USBqemu", MB_ICONERROR); } else fclose(f); swprintf_s(szValue,L"%u",Conf1->Log); WritePrivateProfileStringW(L"Interface", L"Logging", szValue, szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->DFPPass); WritePrivateProfileStringW(N_DEVICES, L"DFP Passthrough", szValue, szIniFile.c_str()); swprintf_s(szValue,L"%S",Conf1->Port0.c_str()); WritePrivateProfileStringW(N_DEVICES, N_DEVICE_PORT0, szValue, szIniFile.c_str()); swprintf_s(szValue,L"%S",Conf1->Port1.c_str()); WritePrivateProfileStringW(N_DEVICES, N_DEVICE_PORT1, szValue, szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->WheelType[0]); WritePrivateProfileStringW(N_DEVICES, N_WHEEL_TYPE0, szValue, szIniFile.c_str()); swprintf_s(szValue,L"%u",Conf1->WheelType[1]); WritePrivateProfileStringW(N_DEVICES, N_WHEEL_TYPE1, szValue, szIniFile.c_str()); for (auto &kp : changedAPIs) { CONFIGVARIANT var(N_DEVICE_API, CONFIG_TYPE_CHAR); var.strValue = kp.second; SaveSetting(kp.first.first, kp.first.second, var); } changedAPIs.clear(); }
bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) { char buffer[500]; (void) GetIniFile (buffer, file); XrmDatabase database; wxNode *node = wxResourceCache.Find (buffer); if (node) database = (XrmDatabase) node->Data (); else { database = XrmGetFileDatabase (buffer); wxResourceCache.Append (buffer, (wxObject *) database); } char resName[300]; strcpy (resName, section.c_str()); strcat (resName, "."); strcat (resName, entry.c_str()); XrmPutStringResource (&database, resName, value); return true; }
BOOL CReadCardInfoApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif /************************************************************************/ /* 一个进程只有一个实例 */ /************************************************************************/ //创建互斥对象 /* hMutex = CreateMutex(NULL, TRUE, strAppName); if (GetLastError() == ERROR_ALREADY_EXISTS) { bFound = TRUE; } if (hMutex) { ReleaseMutex(hMutex); } if (bFound == TRUE) { ::AfxMessageBox("你已经运行了一个实例了"); return FALSE; } */ GetIniFile(iniSkinFilePathBuf, "\\Skin.ini"); GetPrivateProfileString("SKINLIBRARY", "SKIN_NAME1", "", bufSkin, sizeof(bufSkin), iniSkinFilePathBuf); GetIniFile(iniDllFilePathBuf, "\\CardDll.ini"); GetPrivateProfileString("LOADLIBRARY", "DLL1", "", bufDll, sizeof(bufDll), iniDllFilePathBuf); CReadCardInfoDlg dlg; m_pMainWnd = &dlg; if (LoadAppFace() != 0) { ::AfxMessageBox("加载皮肤功能库失败!"); return FALSE; } if(LoadCardManDLL() != 0) { ::AfxMessageBox("加载业务功能库失败!"); return FALSE; } USkinInit(NULL, NULL, bufSkin); int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. FreeCardManDLL(); return FALSE; }
void IniSpawn::InitSpawn(const ieResRef DefaultArea) { const char *s; Holder<DataFileMgr> inifile = GetIniFile(DefaultArea); if (!inifile) { strnuprcpy(NamelessSpawnArea, DefaultArea, 8); return; } s = inifile->GetKeyAsString("nameless","destare",DefaultArea); strnuprcpy(NamelessSpawnArea, s, 8); s = inifile->GetKeyAsString("nameless","point","[0.0]"); int x,y; if (sscanf(s,"[%d.%d]", &x, &y)!=2) { x=0; y=0; } NamelessSpawnPoint.x=x; NamelessSpawnPoint.y=y; s = inifile->GetKeyAsString("nameless", "partyarea", DefaultArea); strnuprcpy(PartySpawnArea, s, 8); s = inifile->GetKeyAsString("nameless", "partypoint", "[0.0]"); if (sscanf(s,"[%d.%d]", &x, &y) != 2) { x = NamelessSpawnPoint.x; y = NamelessSpawnPoint.y; } PartySpawnPoint.x = x; PartySpawnPoint.y = y; //35 - already standing //36 - getting up NamelessState = inifile->GetKeyAsInt("nameless","state",36); namelessvarcount = inifile->GetKeysCount("namelessvar"); if (namelessvarcount) { NamelessVar = new VariableSpec[namelessvarcount]; for (y=0;y<namelessvarcount;y++) { const char* Key = inifile->GetKeyNameByIndex("namelessvar",y); strnlwrcpy(NamelessVar[y].Name, Key, 32); NamelessVar[y].Value = inifile->GetKeyAsInt("namelessvar",Key,0); } } localscount = inifile->GetKeysCount("locals"); if (localscount) { Locals = new VariableSpec[localscount]; for (y=0;y<localscount;y++) { const char* Key = inifile->GetKeyNameByIndex("locals",y); strnlwrcpy(Locals[y].Name, Key, 32); Locals[y].Value = inifile->GetKeyAsInt("locals",Key,0); } } s = inifile->GetKeyAsString("spawn_main","enter",NULL); if (s) { ReadSpawnEntry(inifile.get(), s, enterspawn); } s = inifile->GetKeyAsString("spawn_main","exit",NULL); if (s) { ReadSpawnEntry(inifile.get(), s, exitspawn); } s = inifile->GetKeyAsString("spawn_main","events",NULL); if (s) { eventcount = CountElements(s,','); eventspawns = new SpawnEntry[eventcount]; ieVariable *events = new ieVariable[eventcount]; GetElements(s, events, eventcount); int ec = eventcount; while(ec--) { ReadSpawnEntry(inifile.get(), events[ec], eventspawns[ec]); } delete[] events; } //maybe not correct InitialSpawn(); }
void LoadConfig() { Config *Conf1 = &conf; std::wstring szIniFile; TCHAR szValue[MAX_PATH+1]; GetIniFile(szIniFile); FILE *fp = nullptr; auto err = _wfopen_s(&fp, szIniFile.c_str(), L"rt");//check if ini really exists if (!fp) { memset(&conf, 0, sizeof(conf)); conf.Log = 0;//default value SaveConfig();//save and return return ; } fclose(fp); GetPrivateProfileString(TEXT("Interface"), TEXT("Logging"), NULL, szValue, 20, szIniFile.c_str()); Conf1->Log = wcstoul(szValue, NULL, 10); GetPrivateProfileString(TEXT("Devices"), TEXT("DFP Passthrough"), NULL, szValue, 20, szIniFile.c_str()); Conf1->DFPPass = wcstoul(szValue, NULL, 10); GetPrivateProfileString(TEXT("Devices"), TEXT("Port 0"), NULL, szValue, 20, szIniFile.c_str()); Conf1->Port0 = wcstoul(szValue, NULL, 10); GetPrivateProfileString(TEXT("Devices"), TEXT("Port 1"), NULL, szValue, 20, szIniFile.c_str()); Conf1->Port1 = wcstoul(szValue, NULL, 10); GetPrivateProfileString(TEXT("Devices"), TEXT("Wheel Type 1"), NULL, szValue, 20, szIniFile.c_str()); Conf1->WheelType[0] = wcstoul(szValue, NULL, 10); GetPrivateProfileString(TEXT("Devices"), TEXT("Wheel Type 2"), NULL, szValue, 20, szIniFile.c_str()); Conf1->WheelType[1] = wcstoul(szValue, NULL, 10); GetPrivateProfileString(TEXT("Devices"), TEXT("USB Image"), NULL, Conf1->usb_img, sizeof(Conf1->usb_img), szIniFile.c_str()); // Get mics TCHAR tmp[1024]; GetPrivateProfileString(TEXT("Devices"), TEXT("Mic 1"), NULL, tmp, sizeof(tmp)/sizeof(*tmp), szIniFile.c_str()); Conf1->mics[0] = tmp; GetPrivateProfileString(TEXT("Devices"), TEXT("Mic 2"), NULL, tmp, sizeof(tmp)/sizeof(*tmp), szIniFile.c_str()); Conf1->mics[1] = tmp; GetPrivateProfileString(TEXT("Devices"), TEXT("Mic Buffering"), NULL, szValue, 20, szIniFile.c_str()); Conf1->MicBuffering = wcstoul(szValue, NULL, 10); if(Conf1->MicBuffering == 0) Conf1->MicBuffering = 50; //GetPrivateProfileString("Joystick", "Player1", NULL, szValue, MAX_PATH, szIniFile); //player_joys[0] = szValue; //GetPrivateProfileString("Joystick", "Player2", NULL, szValue, MAX_PATH, szIniFile); //player_joys[1] = szValue; return ; }
int main( int argc, char* argv[] ) { DisplayCopyrightNotice(); std::string configFile = "hh.cfg"; std::string batchBuildId = ""; CTimeSpan totalTimeSpan; enum RunOption { ApproveUnitTest, ExecuteUnitTests, ExecuteUnitTestsInBatchBuildMode, GenerateConfigFile, ViewUnitTestFailures, EditUnitTest }; RunOption runOption = ExecuteUnitTests; bool verbose = false; try { for ( ;; ) { int c = getopt( argc, argv, "ac:b:gefv?" ); if (c == -1) { break; } switch ( c ) { case 'a': runOption = ApproveUnitTest; break; case 'c': configFile = optarg; break; case 'b': runOption = ExecuteUnitTestsInBatchBuildMode; batchBuildId = optarg; break; case 'g': runOption = GenerateConfigFile; break; case 'e': runOption = EditUnitTest; break; case 'f': runOption = ViewUnitTestFailures; break; case 'v': verbose = true; break; case '?': DisplayUsage( argv[0] ); return RESULT_SUCCESS; } } } catch ( HH_CommandLineError& ex ) { std::cout << ex.AsString() << std::endl; std::cout << std::endl; DisplayUsage( argv[0] ); return RESULT_ERROR; } try { HH_CommandLineNotifier commandLineNotifier( verbose ); switch( runOption ) { case ExecuteUnitTests: { HH_Runtime runtime( GetIniFile( verbose ), configFile, commandLineNotifier ); DisplayParameters( runtime, verbose ); totalTimeSpan = runtime.ExecuteUnitTest( batchBuildId ); DisplayElapsedTime( totalTimeSpan, verbose ); } break; case ExecuteUnitTestsInBatchBuildMode: { HH_Runtime runtime( GetIniFile( verbose ), configFile, commandLineNotifier ); DisplayParameters( runtime, verbose ); totalTimeSpan = runtime.ExecuteUnitTest( batchBuildId ); DisplayElapsedTime( totalTimeSpan, verbose ); } break; case ApproveUnitTest: { HH_Runtime runtime( GetIniFile( verbose ), configFile, commandLineNotifier ); DisplayParameters( runtime, verbose ); runtime.ApproveUnitTest(); } break; case GenerateConfigFile: HH_Runtime::GenerateConfigFile( commandLineNotifier ); break; case ViewUnitTestFailures: { HH_Runtime runtime( GetIniFile( verbose ), configFile, commandLineNotifier ); DisplayParameters( runtime, verbose ); runtime.ViewUnitTestFailures(); } break; case EditUnitTest: { HH_Runtime runtime( GetIniFile( verbose ), configFile, commandLineNotifier ); DisplayParameters( runtime, verbose ); runtime.EditDotInFile(); } break; } } catch ( HH_Exception& ex ) { HH_UnitTest::LogException( ex ); DisplayElapsedTime( totalTimeSpan, verbose ); return RESULT_ERROR; } return RESULT_SUCCESS; }