/** * 连接游戏服务器 */ void CMole2dGameFrameDlg::ConnectLoginServer(std::string name,std::string pw) { if(name.empty() || pw.empty()) return; m_totalOnlinePlayers=0; m_loginName = name; m_loginPW = pw; Ini_SetFile(IDD_CLIENT_CONFIG_FILE); std::string serverip = Ini_GetString("SystemSet","ServerIp","127.0.0.1"); int serverport = Ini_GetInt("SystemSet","ServerPort",1234); if(!serverip.empty() && serverport > 0) Connect(serverip,serverport); AfxGetMainWnd()->SendMessage(IDD_SHOW_CONN_TIP,5,0); }
AR_NAMESPACE_BEGIN #define _CHECK_AND_JMP(__stmt) do{ if(__stmt == AR_E_NOMEM){ goto END_POINT; }}while( 0 ) static void ini_test1() { arString_t *str; iniObject_t *obj; str = AR_CreateString(); obj = NULL; if(AR_LoadBomTextFile(L"D:\\1.ini", NULL, str) != AR_S_YES) { goto END_POINT; } obj = Ini_CreateObject(); if(obj == NULL) { goto END_POINT; } if(Ini_LoadObjectFromString(obj, AR_GetStringCString(str)) != AR_S_YES) { goto END_POINT; } printf("Ini_GetInt == %d\r\n", Ini_GetInt(obj, INI_EMPTY_SECTION_NAME, L"a", 0)); printf("Ini_GetUInt == %u\r\n", Ini_GetUInt(obj, INI_EMPTY_SECTION_NAME, L"b", 0)); printf("Ini_GetFloat == %g\r\n", Ini_GetFloat(obj, INI_EMPTY_SECTION_NAME, L"c", 0.0f)); _CHECK_AND_JMP(Ini_SetComment(obj, INI_EMPTY_SECTION_NAME, L"optimize3", L";²âÊÔIni_SetComment")); _CHECK_AND_JMP(Ini_RemoveKey(obj, INI_EMPTY_SECTION_NAME, L"optimize")); _CHECK_AND_JMP(Ini_RemoveKey(obj, INI_EMPTY_SECTION_NAME, L"optimize2")); //Ini_RemoveKey(obj, INI_EMPTY_SECTION_NAME, L"optimize3"); _CHECK_AND_JMP(Ini_RemoveKey(obj, INI_EMPTY_SECTION_NAME, L"optimize4")); _CHECK_AND_JMP(Ini_RemoveSection(obj, L"OPTIMIZE")); _CHECK_AND_JMP(Ini_RemoveSection(obj, L"OPTIMIZATION1")); _CHECK_AND_JMP(Ini_InsertSection(obj, L"Test", L";test")); _CHECK_AND_JMP(Ini_SetString(obj, L"Test", L" a ", L"3", L"comment1")); _CHECK_AND_JMP(Ini_SetString(obj, L"Test", L" b ", NULL, L"comment2")); _CHECK_AND_JMP(Ini_SetInt(obj, L"Test", L"c", -33, NULL)); _CHECK_AND_JMP(Ini_SetUInt(obj, L"Test", L"d", 44, L"comment4")); _CHECK_AND_JMP(Ini_SetFloat(obj, L"Test", L"e", 0.123456789, L"comment5")); /*bad section name*/ _CHECK_AND_JMP(Ini_InsertSection(obj, L"[ ]", L"")); _CHECK_AND_JMP(Ini_InsertSection(obj, L" ", L"")); _CHECK_AND_JMP(Ini_InsertSection(obj, L" p ", L"")); _CHECK_AND_JMP(Ini_SaveObjectToString(obj, str)); ::MessageBoxW(NULL, AR_GetStringCString(str), 0,0); END_POINT: if(obj) { Ini_DestroyObject(obj); obj = NULL; } if(str) { AR_DestroyString(str); str = NULL; } }
static int Initial(int item, int flag) { char pathName[MAX_PATHNAME_LEN]; char dirName[MAX_PATHNAME_LEN]; char *buffer=""; int value=0; int status=0; GetProjectDir (dirName); MakePathname (dirName, "config.ini", pathName); inihandle = Ini_New (0); status = Ini_ReadFromFile (inihandle, pathName); buffer=(char*)malloc(300); memset(buffer,0,300); if ((status)<0) { return status; } if (0 == item) // system operation { if(1 == flag) //write { GetCtrlVal (customizingHandle, CUSTOM_UPDATENAME, buffer); Ini_PutString (inihandle, "system", "update_vendor_name", buffer); Ini_WriteToFile (inihandle, pathName); } if(0 == flag) // read { Ini_GetStringIntoBuffer (inihandle, "system", "update_vendor_name", buffer, 100); SetCtrlVal (customizingHandle, CUSTOM_UPDATENAME, buffer); } } if (1 == item) // item operation { if(1 == flag) // write { status = GetCtrlVal (itemHandle, FILE_ITEM_VENDOR, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "item", "vendor", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_SCFC, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "item", "scfc", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_CONFIG, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "item", "config", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_SWCONFIG, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "item", "swconfig", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_HWF, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "item", "hwf", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_SYSINFO, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "item", "sysinfo", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_SELFDEFI, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "item", "selfdefi", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_SELFDEFIPATH, buffer); if ((status)<0) { return status; } status = Ini_PutString (inihandle, "item", "selfpath", buffer); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_SELFDEFIFILE, buffer); if ((status)<0) { return status; } status = Ini_PutString (inihandle, "item", "selffile", buffer); if ((status)<0) { return status; } status = Ini_WriteToFile (inihandle, pathName); if ((status)<0) { return status; } } if(0 == flag) // read { status = Ini_GetInt (inihandle, "item", "vendor", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_VENDOR, value); if ((status)<0) { return status; } status = Ini_GetInt (inihandle, "item", "scfc", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_SCFC, value); if ((status)<0) { return status; } status = Ini_GetInt (inihandle, "item", "config", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_CONFIG, value); if ((status)<0) { return status; } status = Ini_GetInt (inihandle, "item", "swconfig", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_SWCONFIG, value); if ((status)<0) { return status; } status = Ini_GetInt (inihandle, "item", "hwf", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_HWF, value); if ((status)<0) { return status; } status = Ini_GetInt (inihandle, "item", "sysinfo", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_SYSINFO, value); if ((status)<0) { return status; } status = Ini_GetInt (inihandle, "item", "selfdefi", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_SELFDEFI, value); if ((status)<0) { return status; } status = Ini_GetStringIntoBuffer (inihandle, "item", "selfpath", buffer, 300); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_SELFDEFIPATH, buffer); if ((status)<0) { return status; } status = Ini_GetStringIntoBuffer (inihandle, "item", "selffile", buffer, 300); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_SELFDEFIFILE, buffer); if ((status)<0) { return status; } } } if (2 == item) // filter operation { if(1==flag) { status = GetCtrlVal (itemHandle, FILE_ITEM_TECHLOGS, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "filter", "techlogs", value); if ((status)<0) { return status; } status = GetCtrlVal (itemHandle, FILE_ITEM_FILTER, buffer); if ((status)<0) { return status; } status = Ini_PutString (inihandle, "filter", "filter", buffer); if ((status)<0) { return status; } status = Ini_WriteToFile (inihandle, pathName); if ((status)<0) { return status; } } if(0==flag) { status = Ini_GetInt (inihandle, "filter", "techlogs", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_TECHLOGS, value); if ((status)<0) { return status; } status = Ini_GetStringIntoBuffer (inihandle, "filter", "filter", buffer, 300); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_FILTER, buffer); if ((status)<0) { return status; } } } if (3 == item) // search operation { if(1==flag) { status = GetCtrlVal (itemHandle, FILE_ITEM_SEARCH, &value); if ((status)<0) { return status; } status = Ini_PutInt (inihandle, "search", "search", value); if ((status)<0) { return status; } memset(buffer,0,100); status = GetCtrlVal (itemHandle, FILE_ITEM_S_FILENAME, buffer); if ((status)<0) { return status; } status = Ini_PutString (inihandle, "search", "file_name", buffer); if ((status)<0) { return status; } memset(buffer,0,100); status = GetCtrlVal (itemHandle, FILE_ITEM_S_FILEPATH, buffer); if ((status)<0) { return status; } status = Ini_PutString (inihandle, "search", "file_path", buffer); if ((status)<0) { return status; } status = Ini_WriteToFile (inihandle, pathName); if ((status)<0) { return status; } } if(0==flag) { status = Ini_GetInt (inihandle, "search", "search", &value); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_SEARCH, value); if ((status)<0) { return status; } memset(buffer,0,100); status = Ini_GetStringIntoBuffer (inihandle, "search", "file_name", buffer, 300); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_S_FILENAME, buffer); if ((status)<0) { return status; } memset(buffer,0,100); status = Ini_GetStringIntoBuffer (inihandle, "search", "file_path", buffer, 300); if ((status)<0) { return status; } status = SetCtrlVal (itemHandle, FILE_ITEM_S_FILEPATH, buffer); if ((status)<0) { return status; } } } free(buffer); Ini_Dispose (inihandle); return 1; }