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 void ReadProfileIni(const char *filename) { char *source; char *key; char *keys; char buffer[120]; uint16 locsi; if (filename == NULL) return; if (!File_Exists(filename)) return; source = GFX_Screen_Get_ByIndex(SCREEN_1); memset(source, 0, 32000); File_ReadBlockFile(filename, source, GFX_Screen_GetSize_ByIndex(SCREEN_1)); keys = source + strlen(source) + 5000; *keys = '\0'; Ini_GetString("construct", NULL, keys, keys, 2000, source); for (key = keys; *key != '\0'; key += strlen(key) + 1) { ObjectInfo *oi = NULL; uint16 count; uint8 type; uint16 buildCredits; uint16 buildTime; uint16 fogUncoverRadius; uint16 availableCampaign; uint16 sortPriority; uint16 priorityBuild; uint16 priorityTarget; uint16 hitpoints; type = Unit_StringToType(key); if (type != UNIT_INVALID) { oi = &g_table_unitInfo[type].o; } else { type = Structure_StringToType(key); if (type != STRUCTURE_INVALID) oi = &g_table_structureInfo[type].o; } if (oi == NULL) continue; Ini_GetString("construct", key, buffer, buffer, 120, source); count = sscanf(buffer, "%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu", &buildCredits, &buildTime, &hitpoints, &fogUncoverRadius, &availableCampaign, &priorityBuild, &priorityTarget, &sortPriority); oi->buildCredits = buildCredits; oi->buildTime = buildTime; oi->hitpoints = hitpoints; oi->fogUncoverRadius = fogUncoverRadius; oi->availableCampaign = availableCampaign; oi->priorityBuild = priorityBuild; oi->priorityTarget = priorityTarget; if (count <= 7) continue; oi->sortPriority = (uint8)sortPriority; } if (g_debugGame) { for (locsi = 0; locsi < UNIT_MAX; locsi++) { ObjectInfo *oi = &g_table_unitInfo[locsi].o; sprintf(buffer, "%*s%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d", 15 - (int)strlen(oi->name), "", oi->buildCredits, oi->buildTime, oi->hitpoints, oi->fogUncoverRadius, oi->availableCampaign, oi->priorityBuild, oi->priorityTarget, oi->sortPriority); Ini_SetString("construct", oi->name, buffer, source); } for (locsi = 0; locsi < STRUCTURE_MAX; locsi++) { ObjectInfo *oi = &g_table_unitInfo[locsi].o; sprintf(buffer, "%*s%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d", 15 - (int)strlen(oi->name), "", oi->buildCredits, oi->buildTime, oi->hitpoints, oi->fogUncoverRadius, oi->availableCampaign, oi->priorityBuild, oi->priorityTarget, oi->sortPriority); Ini_SetString("construct", oi->name, buffer, source); } } *keys = '\0'; Ini_GetString("combat", NULL, keys, keys, 2000, source); for (key = keys; *key != '\0'; key += strlen(key) + 1) { uint16 damage; uint16 movingSpeedFactor; uint16 fireDelay; uint16 fireDistance; Ini_GetString("combat", key, buffer, buffer, 120, source); String_Trim(buffer); if (sscanf(buffer, "%hu,%hu,%hu,%hu", &fireDistance, &damage, &fireDelay, &movingSpeedFactor) < 4) continue; for (locsi = 0; locsi < UNIT_MAX; locsi++) { UnitInfo *ui = &g_table_unitInfo[locsi]; if (strcasecmp(ui->o.name, key) != 0) continue; ui->damage = damage; ui->movingSpeedFactor = movingSpeedFactor; ui->fireDelay = fireDelay; ui->fireDistance = fireDistance; break; } } if (!g_debugGame) return; for (locsi = 0; locsi < UNIT_MAX; locsi++) { const UnitInfo *ui = &g_table_unitInfo[locsi]; sprintf(buffer, "%*s%4d,%4d,%4d,%4d", 15 - (int)strlen(ui->o.name), "", ui->fireDistance, ui->damage, ui->fireDelay, ui->movingSpeedFactor); Ini_SetString("combat", ui->o.name, buffer, source); } }
void CMultiMoveClientDlg::save_config() { CString ip_str; CString port_str; m_up_ip.GetWindowText(ip_str); m_up_port.GetWindowText(port_str); if(inet_addr_wcs(ip_str) == INADDR_NONE) { ip_str = TEXT("0.0.0.0"); } Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_UP_IP, (const wchar_t*)ip_str, NULL); Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_UP_PORT, (const wchar_t*)port_str, NULL); m_down_ip.GetWindowText(ip_str); m_down_port.GetWindowText(port_str); if(inet_addr_wcs(ip_str) == INADDR_NONE) { ip_str = TEXT("0.0.0.0"); } Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_DOWN_IP, (const wchar_t*)ip_str, NULL); Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_DOWN_PORT, (const wchar_t*)port_str, NULL); m_left_ip.GetWindowText(ip_str); m_left_port.GetWindowText(port_str); if(inet_addr_wcs(ip_str) == INADDR_NONE) { ip_str = TEXT("0.0.0.0"); } Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_LEFT_IP, (const wchar_t*)ip_str, NULL); Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_LEFT_PORT, (const wchar_t*)port_str, NULL); m_right_ip.GetWindowText(ip_str); m_right_port.GetWindowText(port_str); if(inet_addr_wcs(ip_str) == INADDR_NONE) { ip_str = TEXT("0.0.0.0"); } Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_RIGHT_IP, (const wchar_t*)ip_str, NULL); Ini_SetString(m_cfg, MM_CLI_CONFIG_SEC, MM_CLI_CONFIG_RIGHT_PORT, (const wchar_t*)port_str, NULL); /*****************************************************************************/ cmString_t *out = Com_CreateString(); Ini_SaveObjectToString(m_cfg, out); CString path = UTIL_GetModulePath(); path += MM_CLI_CONFIG; Com_SaveBomTextFile((const wchar_t*)path, COM_TXT_BOM_UTF_8, Com_GetStrString(out)); if(out) { Com_DestroyString(out); out = NULL; } }