• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 20641422872

01 Jan 2026 03:57PM UTC coverage: 50.532% (-0.05%) from 50.58%
20641422872

Pull #1804

github

web-flow
Merge 04b41dbf7 into d98c92f3b
Pull Request #1804: Android build

65 of 226 new or added lines in 13 files covered. (28.76%)

15 existing lines in 5 files now uncovered.

22599 of 44722 relevant lines covered (50.53%)

35465.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.74
/libs/s25main/Settings.cpp
1
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "Settings.h"
6
#include "DrawPoint.h"
7
#include "RTTR_Version.h"
8
#include "RttrConfig.h"
9
#include "drivers/AudioDriverWrapper.h"
10
#include "drivers/VideoDriverWrapper.h"
11
#include "files.h"
12
#include "helpers/strUtils.h"
13
#include "languages.h"
14
#include "gameData/PortraitConsts.h"
15
#include "gameData/const_gui_ids.h"
16
#include "libsiedler2/ArchivItem_Ini.h"
17
#include "libsiedler2/ArchivItem_Text.h"
18
#include "libsiedler2/libsiedler2.h"
19
#include "s25util/StringConversion.h"
20
#include "s25util/System.h"
21
#include "s25util/error.h"
22
#include <boost/filesystem/operations.hpp>
23

24
namespace {
25
#ifdef __ANDROID__
26
constexpr bool SHARED_TEXTURES_DEFAULT = false;
27
constexpr MapScrollMode MAP_SCROLL_MODE_DEFAULT = MapScrollMode::GrabAndDrag;
28
#else
29
constexpr bool SHARED_TEXTURES_DEFAULT = true;
30
constexpr MapScrollMode MAP_SCROLL_MODE_DEFAULT = MapScrollMode::ScrollOpposite;
31
#endif
32
} // namespace
33

34
const int Settings::VERSION = 13;
35
const std::array<std::string, 10> Settings::SECTION_NAMES = {
36
  {"global", "video", "language", "driver", "sound", "lobby", "server", "proxy", "interface", "addons"}};
37

38
const std::array<short, 13> Settings::SCREEN_REFRESH_RATES = {
39
  {-1, 25, 30, 50, 60, 75, 80, 100, 120, 150, 180, 200, 240}};
40

41
const std::map<GUI_ID, std::string> persistentWindows = {{CGI_CHAT, "wnd_chat"},
42
                                                         {CGI_POSTOFFICE, "wnd_postoffice"},
43
                                                         {CGI_DISTRIBUTION, "wnd_distribution"},
44
                                                         {CGI_BUILDORDER, "wnd_buildorder"},
45
                                                         {CGI_TRANSPORT, "wnd_transport"},
46
                                                         {CGI_MILITARY, "wnd_military"},
47
                                                         {CGI_TOOLS, "wnd_tools"},
48
                                                         {CGI_INVENTORY, "wnd_inventory"},
49
                                                         {CGI_MINIMAP, "wnd_minimap"},
50
                                                         {CGI_BUILDINGS, "wnd_buildings"},
51
                                                         {CGI_BUILDINGSPRODUCTIVITY, "wnd_buildingsproductivity"},
52
                                                         {CGI_MUSICPLAYER, "wnd_musicplayer"},
53
                                                         {CGI_STATISTICS, "wnd_statistics"},
54
                                                         {CGI_ECONOMICPROGRESS, "wnd_economicprogress"},
55
                                                         {CGI_DIPLOMACY, "wnd_diplomacy"},
56
                                                         {CGI_SHIP, "wnd_ship"},
57
                                                         {CGI_MERCHANDISE_STATISTICS, "wnd_merchandise_statistics"}};
58

59
namespace validate {
60
boost::optional<uint16_t> checkPort(const std::string& port)
9✔
61
{
62
    int32_t iPort;
63
    if((helpers::tryFromString(port, iPort) || s25util::tryFromStringClassic(port, iPort)) && checkPort(iPort))
9✔
64
        return static_cast<uint16_t>(iPort);
3✔
65
    else
66
        return boost::none;
6✔
67
}
68
bool checkPort(int port)
7✔
69
{
70
    // Disallow port 0 as it may cause problems
71
    return port > 0 && port <= 65535;
7✔
72
}
73
} // namespace validate
74

75
Settings::Settings() //-V730
5✔
76
{
77
    LoadDefaults();
5✔
78
}
5✔
79

80
void Settings::LoadDefaults()
5✔
81
{
82
    // global
83
    // {
84
    // 0 = ask user at start, 1 = enabled, 2 = always ask
85
    global.submit_debug_data = 0;
5✔
86
    global.use_upnp = false;
5✔
87
    global.smartCursor = true;
5✔
88
    global.debugMode = false;
5✔
89
    global.showGFInfo = false;
5✔
90
    // }
91

92
    // video
93
    // {
94
    if(VIDEODRIVER.IsLoaded())
5✔
95
    {
96
        video.fullscreenSize = VIDEODRIVER.GetWindowSize();
3✔
97
        video.windowedSize = VIDEODRIVER.IsFullscreen() ? VideoMode(800, 600) : video.fullscreenSize;
3✔
98
        video.fullscreen = VIDEODRIVER.IsFullscreen();
3✔
99
    } else
100
    {
101
        video.windowedSize = video.fullscreenSize = VideoMode(800, 600);
2✔
102
        video.fullscreen = false;
2✔
103
    }
104
    video.framerate = 0; // Special value for HW vsync
5✔
105
    video.vbo = true;
5✔
106
    video.shared_textures = SHARED_TEXTURES_DEFAULT;
5✔
107
    video.guiScale = 0; // special value indicating automatic selection
5✔
108
    // }
109

110
    // language
111
    // {
112
    language.language.clear();
5✔
113
    // }
114

115
    LANGUAGES.setLanguage(language.language);
5✔
116

117
    // driver
118
    // {
119
    driver.audio = AUDIODRIVER.GetName();
5✔
120
    driver.video = VIDEODRIVER.GetName();
5✔
121
    // }
122

123
    // sound
124
    // {
125
    sound.musicEnabled = false;
5✔
126
    sound.musicVolume = 30;
5✔
127
    sound.effectsEnabled = true;
5✔
128
    sound.effectsVolume = 75;
5✔
129
    sound.birdsEnabled = true;
5✔
130
    sound.playlist = s25::files::defaultPlaylist;
5✔
131
    // }
132

133
    // lobby
134
    // {
135

136
    lobby.name = System::getUserName();
5✔
137
    lobby.portraitIndex = 0;
5✔
138
    lobby.password.clear();
5✔
139
    lobby.save_password = false;
5✔
140
    // }
141

142
    // server
143
    // {
144
    server.last_ip.clear();
5✔
145
    server.localPort = 3665;
5✔
146
    server.ipv6 = false;
5✔
147
    // }
148

149
    proxy = ProxySettings();
5✔
150
    proxy.port = 1080;
5✔
151

152
    // interface
153
    // {
154
    interface.autosave_interval = 0;
5✔
155
    interface.mapScrollMode = MAP_SCROLL_MODE_DEFAULT;
5✔
156
    interface.enableWindowPinning = false;
5✔
157
    interface.windowSnapDistance = 8;
5✔
158
    // }
159

160
    // addons
161
    // {
162
    addons.configuration.clear();
5✔
163
    // }
164

165
    LoadIngameDefaults();
5✔
166
}
5✔
167

168
void Settings::LoadIngameDefaults()
5✔
169
{
170
    // ingame
171
    // {
172
    ingame.scale_statistics = false;
5✔
173
    ingame.showBQ = false;
5✔
174
    ingame.showNames = false;
5✔
175
    ingame.showProductivity = false;
5✔
176
    ingame.minimapExtended = false;
5✔
177
    // }
178

179
    // windows
180
    // {
181
    for(const auto& window : persistentWindows)
90✔
182
        windows.persistentSettings[window.first] = PersistentWindowSettings();
85✔
183
    // }
184
}
5✔
185

186
///////////////////////////////////////////////////////////////////////////////
187
// Routine for loading the configuration
188
void Settings::Load()
×
189
{
190
    libsiedler2::Archiv settings;
×
191
    const auto settingsPath = RTTRCONFIG.ExpandPath(s25::resources::config);
×
192
    try
193
    {
194
        if(libsiedler2::Load(settingsPath, settings) != 0 || settings.size() < SECTION_NAMES.size())
×
195
            throw std::runtime_error("File missing or invalid");
×
196

197
        const libsiedler2::ArchivItem_Ini* iniGlobal =
198
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("global"));
×
199
        const libsiedler2::ArchivItem_Ini* iniVideo = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("video"));
×
200
        const libsiedler2::ArchivItem_Ini* iniLanguage =
201
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("language"));
×
202
        const libsiedler2::ArchivItem_Ini* iniDriver =
203
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("driver"));
×
204
        const libsiedler2::ArchivItem_Ini* iniSound = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("sound"));
×
205
        const libsiedler2::ArchivItem_Ini* iniLobby = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("lobby"));
×
206
        const libsiedler2::ArchivItem_Ini* iniServer =
207
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("server"));
×
208
        const libsiedler2::ArchivItem_Ini* iniProxy = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("proxy"));
×
209
        const libsiedler2::ArchivItem_Ini* iniInterface =
210
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("interface"));
×
211
        const libsiedler2::ArchivItem_Ini* iniAddons =
212
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("addons"));
×
213

214
        // Is one of the categories missing?
215
        if(!iniGlobal || !iniVideo || !iniLanguage || !iniDriver || !iniSound || !iniLobby || !iniServer || !iniProxy
×
216
           || !iniInterface || !iniAddons)
×
217
        {
218
            throw std::runtime_error("Missing section");
×
219
        }
220
        // Is the settings version correct?
221
        if(iniGlobal->getValue("version", 0) != VERSION)
×
222
            throw std::runtime_error("Wrong version");
×
223

224
        // global
225
        // {
226
        if(iniGlobal->getValue("gameversion") != rttr::version::GetRevision())
×
227
            s25util::warning("Your application version has changed - please recheck your settings!");
×
228

229
        global.submit_debug_data = iniGlobal->getIntValue("submit_debug_data");
×
230
        global.use_upnp = iniGlobal->getBoolValue("use_upnp");
×
231
        global.smartCursor = iniGlobal->getValue("smartCursor", true);
×
232
        global.debugMode = iniGlobal->getValue("debugMode", false);
×
233
        global.showGFInfo = iniGlobal->getValue("showGFInfo", false);
×
234
        // };
235

236
        // video
237
        // {
238
        video.windowedSize.width = iniVideo->getIntValue("windowed_width");
×
239
        video.windowedSize.height = iniVideo->getIntValue("windowed_height");
×
240
        video.fullscreenSize.width = iniVideo->getIntValue("fullscreen_width");
×
241
        video.fullscreenSize.height = iniVideo->getIntValue("fullscreen_height");
×
242
        video.fullscreen = iniVideo->getBoolValue("fullscreen");
×
243
        video.framerate = iniVideo->getValue("framerate", 0);
×
244
        video.vbo = iniVideo->getBoolValue("vbo");
×
245
        video.shared_textures = iniVideo->getBoolValue("shared_textures");
×
246
        video.guiScale = iniVideo->getValue("gui_scale", 0);
×
247
        // };
248

249
        if(video.fullscreenSize.width == 0 || video.fullscreenSize.height == 0 || video.windowedSize.width == 0
×
250
           || video.windowedSize.height == 0)
×
251
            throw std::runtime_error("Invalid video settings");
×
252

253
        // language
254
        // {
255
        language.language = iniLanguage->getValue("language");
×
256
        // }
257

258
        LANGUAGES.setLanguage(language.language);
×
259

260
        // driver
261
        // {
262
        driver.video = iniDriver->getValue("video");
×
263
        driver.audio = iniDriver->getValue("audio");
×
264
        // }
265

266
        // sound
267
        // {
268
        sound.musicEnabled = iniSound->getBoolValue("musik");
×
269
        sound.musicVolume = iniSound->getIntValue("musik_volume");
×
270
        sound.effectsEnabled = iniSound->getBoolValue("effekte");
×
271
        sound.effectsVolume = iniSound->getIntValue("effekte_volume");
×
272
        sound.birdsEnabled = iniSound->getValue("bird_sounds", true);
×
273
        sound.playlist = iniSound->getValue("playlist");
×
274
        // }
275

276
        // lobby
277
        // {
278
        lobby.name = iniLobby->getValue("name");
×
279
        lobby.portraitIndex = iniLobby->getIntValue("portrait_index");
×
280
        lobby.password = iniLobby->getValue("password");
×
281
        lobby.save_password = iniLobby->getBoolValue("save_password");
×
282
        // }
283

284
        if(lobby.name.empty())
×
285
            lobby.name = System::getUserName();
×
286

287
        if(lobby.portraitIndex >= Portraits.size())
×
288
        {
289
            lobby.portraitIndex = 0;
×
290
        }
291

292
        // server
293
        // {
294
        server.last_ip = iniServer->getValue("last_ip");
×
295
        boost::optional<uint16_t> port = validate::checkPort(iniServer->getValue("local_port"));
×
296
        server.localPort = port.value_or(3665);
×
297
        server.ipv6 = iniServer->getBoolValue("ipv6");
×
298
        // }
299

300
        // proxy
301
        // {
302
        proxy.hostname = iniProxy->getValue("proxy");
×
303
        port = validate::checkPort(iniProxy->getValue("port"));
×
304
        proxy.port = port.value_or(1080);
×
305
        proxy.type = ProxyType(iniProxy->getIntValue("typ"));
×
306
        // }
307

308
        // Empty proxy address completely disables proxy.
309
        // Disabled proxy removes proxy address.
310
        if(proxy.hostname.empty() || (proxy.type != ProxyType::Socks4 && proxy.type != ProxyType::Socks5))
×
311
        {
312
            proxy.type = ProxyType::None;
×
313
            proxy.hostname.clear();
×
314
        }
315
        // Enabled Socks v4 disables IPv6
316
        else if(proxy.type == ProxyType::Socks4 && server.ipv6)
×
317
            server.ipv6 = false;
×
318

319
        // interface
320
        // {
321
        interface.autosave_interval = iniInterface->getIntValue("autosave_interval");
×
322
        try
323
        {
NEW
324
            interface.mapScrollMode = static_cast<MapScrollMode>(iniInterface->getIntValue("map_scroll_mode"));
×
NEW
325
        } catch(const std::runtime_error&)
×
326
        {
NEW
327
            interface.mapScrollMode =
×
NEW
328
              iniInterface->getBoolValue("invert_mouse") ? MapScrollMode::ScrollSame : MapScrollMode::ScrollOpposite;
×
NEW
329
            s25util::warning(
×
330
              "Value 'map_scroll_mode' not found! Using 'invert_mouse' instead - please recheck your settings!");
331
        }
332
        interface.enableWindowPinning = iniInterface->getValue("enable_window_pinning", false);
×
333
        interface.windowSnapDistance = iniInterface->getValue("window_snap_distance", 8);
×
334
        // }
335

336
        // addons
337
        // {
338
        for(unsigned addon = 0; addon < iniAddons->size(); ++addon)
×
339
        {
340
            const auto* item = dynamic_cast<const libsiedler2::ArchivItem_Text*>(iniAddons->get(addon));
×
341

342
            if(item)
×
343
                addons.configuration.insert(std::make_pair(s25util::fromStringClassic<unsigned>(item->getName()),
×
344
                                                           s25util::fromStringClassic<unsigned>(item->getText())));
×
345
        }
346

347
        LoadIngame();
×
348
        // }
349
    } catch(const std::runtime_error& e)
×
350
    {
351
        s25util::warning(std::string("Could not use settings from \"") + settingsPath.string()
×
352
                         + "\", using default values. Reason: " + e.what());
×
353
        LoadDefaults();
×
354
        Save();
×
355
    }
356
}
×
357

358
void Settings::LoadIngame()
×
359
{
360
    libsiedler2::Archiv settingsIngame;
×
361
    const auto settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);
×
362
    try
363
    {
364
        if(libsiedler2::Load(settingsPathIngame, settingsIngame) != 0)
×
365
            throw std::runtime_error("File missing");
×
366

367
        const libsiedler2::ArchivItem_Ini* iniIngame =
368
          static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find("ingame"));
×
369
        if(!iniIngame)
×
370
            throw std::runtime_error("Missing section");
×
371
        // ingame
372
        // {
373
        ingame.scale_statistics = iniIngame->getBoolValue("scale_statistics");
×
374
        ingame.showBQ = iniIngame->getBoolValue("show_building_quality");
×
375
        ingame.showNames = iniIngame->getBoolValue("show_names");
×
376
        ingame.showProductivity = iniIngame->getBoolValue("show_productivity");
×
377
        ingame.minimapExtended = iniIngame->getBoolValue("minimap_extended");
×
378
        // }
379
        // ingame windows
380
        for(const auto& window : persistentWindows)
×
381
        {
382
            const auto* iniWindow = static_cast<const libsiedler2::ArchivItem_Ini*>(settingsIngame.find(window.second));
×
383
            if(!iniWindow)
×
384
                continue;
×
385
            auto& settings = windows.persistentSettings[window.first];
×
386
            const auto lastPos = settings.lastPos =
×
387
              DrawPoint(iniWindow->getIntValue("pos_x"), iniWindow->getIntValue("pos_y"));
×
388
            settings.restorePos = DrawPoint(iniWindow->getValue("restore_pos_x", lastPos.x),
×
389
                                            iniWindow->getValue("restore_pos_y", lastPos.y));
×
390
            settings.isOpen = iniWindow->getIntValue("is_open");
×
391
            settings.isPinned = iniWindow->getValue("is_pinned", false);
×
392
            settings.isMinimized = iniWindow->getValue("is_minimized", false);
×
393
        }
394
    } catch(const std::runtime_error& e)
×
395
    {
396
        s25util::warning(std::string("Could not use ingame settings from \"") + settingsPathIngame.string()
×
397
                         + "\", using default values. Reason: " + e.what());
×
398
        LoadIngameDefaults();
×
399
        SaveIngame();
×
400
    }
401
}
×
402

403
///////////////////////////////////////////////////////////////////////////////
404
// Routine for saving the configuration
405
void Settings::Save()
×
406
{
407
    libsiedler2::Archiv settings;
×
408
    settings.alloc(SECTION_NAMES.size());
×
409
    for(unsigned i = 0; i < SECTION_NAMES.size(); ++i)
×
410
        settings.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(SECTION_NAMES[i]));
×
411

412
    libsiedler2::ArchivItem_Ini* iniGlobal = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("global"));
×
413
    libsiedler2::ArchivItem_Ini* iniVideo = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("video"));
×
414
    libsiedler2::ArchivItem_Ini* iniLanguage = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("language"));
×
415
    libsiedler2::ArchivItem_Ini* iniDriver = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("driver"));
×
416
    libsiedler2::ArchivItem_Ini* iniSound = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("sound"));
×
417
    libsiedler2::ArchivItem_Ini* iniLobby = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("lobby"));
×
418
    libsiedler2::ArchivItem_Ini* iniServer = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("server"));
×
419
    libsiedler2::ArchivItem_Ini* iniProxy = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("proxy"));
×
420
    libsiedler2::ArchivItem_Ini* iniInterface = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("interface"));
×
421
    libsiedler2::ArchivItem_Ini* iniAddons = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("addons"));
×
422

423
    // Is one of the categories missing?
424
    RTTR_Assert(iniGlobal && iniVideo && iniLanguage && iniDriver && iniSound && iniLobby && iniServer && iniProxy
×
425
                && iniInterface && iniAddons);
426

427
    // global
428
    // {
429
    iniGlobal->setValue("version", VERSION);
×
430
    iniGlobal->setValue("gameversion", rttr::version::GetRevision());
×
431
    iniGlobal->setValue("submit_debug_data", global.submit_debug_data);
×
432
    iniGlobal->setValue("use_upnp", global.use_upnp);
×
433
    iniGlobal->setValue("smartCursor", global.smartCursor);
×
434
    iniGlobal->setValue("debugMode", global.debugMode);
×
435
    iniGlobal->setValue("showGFInfo", global.showGFInfo);
×
436
    // };
437

438
    // video
439
    // {
440
    iniVideo->setValue("fullscreen_width", video.fullscreenSize.width);
×
441
    iniVideo->setValue("fullscreen_height", video.fullscreenSize.height);
×
442
    iniVideo->setValue("windowed_width", video.windowedSize.width);
×
443
    iniVideo->setValue("windowed_height", video.windowedSize.height);
×
444
    iniVideo->setValue("fullscreen", video.fullscreen);
×
445
    iniVideo->setValue("framerate", video.framerate);
×
446
    iniVideo->setValue("vbo", video.vbo);
×
447
    iniVideo->setValue("shared_textures", video.shared_textures);
×
448
    iniVideo->setValue("gui_scale", video.guiScale);
×
449
    // };
450

451
    // language
452
    // {
453
    iniLanguage->setValue("language", language.language);
×
454
    // }
455

456
    // driver
457
    // {
458
    iniDriver->setValue("video", driver.video);
×
459
    iniDriver->setValue("audio", driver.audio);
×
460
    // }
461

462
    // sound
463
    // {
464
    iniSound->setValue("musik", sound.musicEnabled);
×
465
    iniSound->setValue("musik_volume", sound.musicVolume);
×
466
    iniSound->setValue("effekte", sound.effectsEnabled);
×
467
    iniSound->setValue("effekte_volume", sound.effectsVolume);
×
468
    iniSound->setValue("bird_sounds", sound.birdsEnabled);
×
469
    iniSound->setValue("playlist", sound.playlist);
×
470
    // }
471

472
    // lobby
473
    // {
474
    iniLobby->setValue("name", lobby.name);
×
475
    iniLobby->setValue("portrait_index", lobby.portraitIndex);
×
476
    iniLobby->setValue("password", lobby.password);
×
477
    iniLobby->setValue("save_password", lobby.save_password);
×
478
    // }
479

480
    // server
481
    // {
482
    iniServer->setValue("last_ip", server.last_ip);
×
483
    iniServer->setValue("local_port", server.localPort);
×
484
    iniServer->setValue("ipv6", server.ipv6);
×
485
    // }
486

487
    // proxy
488
    // {
489
    iniProxy->setValue("proxy", proxy.hostname);
×
490
    iniProxy->setValue("port", proxy.port);
×
491
    iniProxy->setValue("typ", static_cast<int>(proxy.type));
×
492
    // }
493

494
    // interface
495
    // {
496
    iniInterface->setValue("autosave_interval", interface.autosave_interval);
×
NEW
497
    iniInterface->setValue("map_scroll_mode", static_cast<int>(interface.mapScrollMode));
×
498
    iniInterface->setValue("enable_window_pinning", interface.enableWindowPinning);
×
499
    iniInterface->setValue("window_snap_distance", interface.windowSnapDistance);
×
500
    // }
501

502
    // addons
503
    // {
504
    iniAddons->clear();
×
505
    for(const auto& it : addons.configuration)
×
506
        iniAddons->setValue(s25util::toStringClassic(it.first), s25util::toStringClassic(it.second));
×
507
    // }
508

509
    bfs::path settingsPath = RTTRCONFIG.ExpandPath(s25::resources::config);
×
510
    if(libsiedler2::Write(settingsPath, settings) == 0)
×
511
        bfs::permissions(settingsPath, bfs::owner_read | bfs::owner_write);
×
512

513
    SaveIngame();
×
514
}
×
515

516
void Settings::SaveIngame()
×
517
{
518
    libsiedler2::Archiv settingsIngame;
×
519
    settingsIngame.alloc(1 + persistentWindows.size());
×
520
    settingsIngame.set(0, std::make_unique<libsiedler2::ArchivItem_Ini>("ingame"));
×
521
    unsigned i = 1;
×
522
    for(const auto& window : persistentWindows)
×
523
    {
524
        settingsIngame.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(window.second));
×
525
        i++;
×
526
    }
527

528
    auto* iniIngame = static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find("ingame"));
×
529

530
    RTTR_Assert(iniIngame);
×
531

532
    // ingame
533
    // {
534
    iniIngame->setValue("scale_statistics", ingame.scale_statistics);
×
535
    iniIngame->setValue("show_building_quality", ingame.showBQ);
×
536
    iniIngame->setValue("show_names", ingame.showNames);
×
537
    iniIngame->setValue("show_productivity", ingame.showProductivity);
×
538
    iniIngame->setValue("minimap_extended", ingame.minimapExtended);
×
539
    // }
540

541
    // ingame windows
542
    for(const auto& window : persistentWindows)
×
543
    {
544
        auto* iniWindow = static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find(window.second));
×
545
        if(!iniWindow)
×
546
            continue;
×
547
        const auto& settings = windows.persistentSettings[window.first];
×
548
        iniWindow->setValue("pos_x", settings.lastPos.x);
×
549
        iniWindow->setValue("pos_y", settings.lastPos.y);
×
550
        if(settings.restorePos != settings.lastPos)
×
551
        {
552
            // only save if different; defaults to lastPos on load
553
            iniWindow->setValue("restore_pos_x", settings.restorePos.x);
×
554
            iniWindow->setValue("restore_pos_y", settings.restorePos.y);
×
555
        }
556
        iniWindow->setValue("is_open", settings.isOpen);
×
557
        iniWindow->setValue("is_pinned", settings.isPinned);
×
558
        iniWindow->setValue("is_minimized", settings.isMinimized);
×
559
    }
560

561
    bfs::path settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);
×
562
    if(libsiedler2::Write(settingsPathIngame, settingsIngame) == 0)
×
563
        bfs::permissions(settingsPathIngame, bfs::owner_read | bfs::owner_write);
×
564
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc