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

Return-To-The-Roots / s25client / 23849259886

01 Apr 2026 12:45PM UTC coverage: 50.177% (-0.2%) from 50.337%
23849259886

Pull #1890

github

web-flow
Merge d31e037e7 into e4146df45
Pull Request #1890: Add support for borderless Windows

155 of 626 new or added lines in 44 files covered. (24.76%)

24 existing lines in 7 files now uncovered.

23064 of 45965 relevant lines covered (50.18%)

43357.7 hits per line

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

21.48
/libs/s25main/Settings.cpp
1
// Copyright (C) 2005 - 2026 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 "driver/VideoInterface.h"
10
#include "drivers/AudioDriverWrapper.h"
11
#include "drivers/VideoDriverWrapper.h"
12
#include "enum_cast.hpp"
13
#include "files.h"
14
#include "helpers/MaxEnumValue.h"
15
#include "helpers/strUtils.h"
16
#include "languages.h"
17
#include "gameData/PortraitConsts.h"
18
#include "gameData/const_gui_ids.h"
19
#include "libsiedler2/ArchivItem_Ini.h"
20
#include "libsiedler2/ArchivItem_Text.h"
21
#include "libsiedler2/libsiedler2.h"
22
#include "s25util/StringConversion.h"
23
#include "s25util/System.h"
24
#include "s25util/error.h"
25
#include <boost/filesystem/operations.hpp>
26

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

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

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

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

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

78
Settings::Settings() //-V730
5✔
79
{
80
    LoadDefaults();
5✔
81
}
5✔
82

83
void Settings::LoadDefaults()
5✔
84
{
85
    // global
86
    // {
87
    // 0 = ask user at start, 1 = enabled, 2 = always ask
88
    global.submitDebugData = 0;
5✔
89
    global.useUPNP = false;
5✔
90
    global.smartCursor = true;
5✔
91
    global.debugMode = false;
5✔
92
    global.showGFInfo = false;
5✔
93
    // }
94

95
    // video
96
    // {
97
    if(VIDEODRIVER.IsLoaded())
5✔
98
    {
99
        video.fullscreenSize = (VIDEODRIVER.GetDisplayMode() == DisplayMode::Fullscreen) ? VIDEODRIVER.GetWindowSize() :
3✔
100
                                                                                           VIDEODRIVER.MinWindowSize;
3✔
101
        video.windowedSize = (VIDEODRIVER.GetDisplayMode() == DisplayMode::Windowed) ? VIDEODRIVER.GetWindowSize() :
3✔
NEW
102
                                                                                       VIDEODRIVER.MinWindowSize;
×
103
        video.displayMode = VIDEODRIVER.GetDisplayMode();
3✔
104
    } else
105
    {
106
        video.windowedSize = video.fullscreenSize = VIDEODRIVER.MinWindowSize;
2✔
107
        video.displayMode = DisplayMode::Windowed;
2✔
108
    }
109
    video.framerate = 0; // Special value for HW vsync
5✔
110
    video.vbo = true;
5✔
111
    video.sharedTextures = SHARED_TEXTURES_DEFAULT;
5✔
112
    video.guiScale = 0; // special value indicating automatic selection
5✔
113
    // }
114

115
    // language
116
    // {
117
    language.language.clear();
5✔
118
    // }
119

120
    LANGUAGES.setLanguage(language.language);
5✔
121

122
    // driver
123
    // {
124
    driver.audio = AUDIODRIVER.GetName();
5✔
125
    driver.video = VIDEODRIVER.GetName();
5✔
126
    // }
127

128
    // sound
129
    // {
130
    sound.musicEnabled = false;
5✔
131
    sound.musicVolume = 30;
5✔
132
    sound.effectsEnabled = true;
5✔
133
    sound.effectsVolume = 75;
5✔
134
    sound.birdsEnabled = true;
5✔
135
    sound.playlist = s25::files::defaultPlaylist;
5✔
136
    // }
137

138
    // lobby
139
    // {
140

141
    lobby.name = System::getUserName();
5✔
142
    lobby.portraitIndex = 0;
5✔
143
    lobby.password.clear();
5✔
144
    lobby.savePassword = false;
5✔
145
    // }
146

147
    // server
148
    // {
149
    server.lastIP.clear();
5✔
150
    server.localPort = 3665;
5✔
151
    server.ipv6 = false;
5✔
152
    // }
153

154
    proxy = ProxySettings();
5✔
155
    proxy.port = 1080;
5✔
156

157
    // interface
158
    // {
159
    interface.autosaveInterval = 0;
5✔
160
    interface.mapScrollMode = MAP_SCROLL_MODE_DEFAULT;
5✔
161
    interface.enableWindowPinning = false;
5✔
162
    interface.windowSnapDistance = 8;
5✔
163
    // }
164

165
    // addons
166
    // {
167
    addons.configuration.clear();
5✔
168
    // }
169

170
    LoadIngameDefaults();
5✔
171
}
5✔
172

173
void Settings::LoadIngameDefaults()
5✔
174
{
175
    // ingame
176
    // {
177
    ingame.scaleStatistics = false;
5✔
178
    ingame.showBQ = false;
5✔
179
    ingame.showNames = false;
5✔
180
    ingame.showProductivity = false;
5✔
181
    ingame.minimapExtended = false;
5✔
182
    // }
183

184
    // windows
185
    // {
186
    for(const auto& window : persistentWindows)
90✔
187
        windows.persistentSettings[window.first] = PersistentWindowSettings();
85✔
188
    // }
189
}
5✔
190

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

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

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

229
        // global
230
        // {
231
        if(iniGlobal->getValue("gameversion") != rttr::version::GetRevision())
×
232
            s25util::warning("Your application version has changed - please recheck your settings!");
×
233

NEW
234
        global.submitDebugData = iniGlobal->getIntValue("submit_debug_data");
×
NEW
235
        global.useUPNP = iniGlobal->getBoolValue("use_upnp");
×
236
        global.smartCursor = iniGlobal->getValue("smartCursor", true);
×
237
        global.debugMode = iniGlobal->getValue("debugMode", false);
×
238
        global.showGFInfo = iniGlobal->getValue("showGFInfo", false);
×
239
        // };
240

241
        // video
242
        // {
243
        video.windowedSize.width = iniVideo->getIntValue("windowed_width");
×
244
        video.windowedSize.height = iniVideo->getIntValue("windowed_height");
×
245
        video.fullscreenSize.width = iniVideo->getIntValue("fullscreen_width");
×
246
        video.fullscreenSize.height = iniVideo->getIntValue("fullscreen_height");
×
NEW
247
        const auto displayMode = iniVideo->getValue("displayMode", -1);
×
NEW
248
        if(displayMode >= 0 && static_cast<unsigned>(displayMode) <= helpers::MaxEnumValue_v<DisplayMode::Type>)
×
NEW
249
            video.displayMode = DisplayMode(displayMode);
×
250
        else
251
        {
NEW
252
            video.displayMode =
×
NEW
253
              iniVideo->getValue("fullscreen", false) ? DisplayMode::Fullscreen : DisplayMode::Windowed;
×
254
        }
NEW
255
        video.displayMode.resizeable = !iniVideo->getValue("lock_window_size", false);
×
256
        video.framerate = iniVideo->getValue("framerate", 0);
×
257
        video.vbo = iniVideo->getBoolValue("vbo");
×
NEW
258
        video.sharedTextures = iniVideo->getBoolValue("shared_textures");
×
259
        video.guiScale = iniVideo->getValue("gui_scale", 0);
×
260
        // };
261

262
        if(video.fullscreenSize.width == 0 || video.fullscreenSize.height == 0 || video.windowedSize.width == 0
×
263
           || video.windowedSize.height == 0)
×
264
            throw std::runtime_error("Invalid video settings");
×
265

266
        // language
267
        // {
268
        language.language = iniLanguage->getValue("language");
×
269
        // }
270

271
        LANGUAGES.setLanguage(language.language);
×
272

273
        // driver
274
        // {
275
        driver.video = iniDriver->getValue("video");
×
276
        driver.audio = iniDriver->getValue("audio");
×
277
        // }
278

279
        // sound
280
        // {
281
        sound.musicEnabled = iniSound->getBoolValue("musik");
×
282
        sound.musicVolume = iniSound->getIntValue("musik_volume");
×
283
        sound.effectsEnabled = iniSound->getBoolValue("effekte");
×
284
        sound.effectsVolume = iniSound->getIntValue("effekte_volume");
×
285
        sound.birdsEnabled = iniSound->getValue("bird_sounds", true);
×
286
        sound.playlist = iniSound->getValue("playlist");
×
287
        // }
288

289
        // lobby
290
        // {
291
        lobby.name = iniLobby->getValue("name");
×
292
        lobby.portraitIndex = iniLobby->getIntValue("portrait_index");
×
293
        lobby.password = iniLobby->getValue("password");
×
NEW
294
        lobby.savePassword = iniLobby->getBoolValue("save_password");
×
295
        // }
296

297
        if(lobby.name.empty())
×
298
            lobby.name = System::getUserName();
×
299

300
        if(lobby.portraitIndex >= Portraits.size())
×
301
        {
302
            lobby.portraitIndex = 0;
×
303
        }
304

305
        // server
306
        // {
NEW
307
        server.lastIP = iniServer->getValue("last_ip");
×
308
        boost::optional<uint16_t> port = validate::checkPort(iniServer->getValue("local_port"));
×
309
        server.localPort = port.value_or(3665);
×
310
        server.ipv6 = iniServer->getBoolValue("ipv6");
×
311
        // }
312

313
        // proxy
314
        // {
315
        proxy.hostname = iniProxy->getValue("proxy");
×
316
        port = validate::checkPort(iniProxy->getValue("port"));
×
317
        proxy.port = port.value_or(1080);
×
318
        proxy.type = ProxyType(iniProxy->getIntValue("typ"));
×
319
        // }
320

321
        // Empty proxy address completely disables proxy.
322
        // Disabled proxy removes proxy address.
323
        if(proxy.hostname.empty() || (proxy.type != ProxyType::Socks4 && proxy.type != ProxyType::Socks5))
×
324
        {
325
            proxy.type = ProxyType::None;
×
326
            proxy.hostname.clear();
×
327
        }
328
        // Enabled Socks v4 disables IPv6
329
        else if(proxy.type == ProxyType::Socks4 && server.ipv6)
×
330
            server.ipv6 = false;
×
331

332
        // interface
333
        // {
NEW
334
        interface.autosaveInterval = iniInterface->getIntValue("autosave_interval");
×
335
        try
336
        {
337
            interface.mapScrollMode = static_cast<MapScrollMode>(iniInterface->getIntValue("map_scroll_mode"));
×
338
        } catch(const std::runtime_error&)
×
339
        {
340
            interface.mapScrollMode =
×
341
              iniInterface->getBoolValue("invert_mouse") ? MapScrollMode::ScrollSame : MapScrollMode::ScrollOpposite;
×
342
            s25util::warning(
×
343
              "Value 'map_scroll_mode' not found! Using 'invert_mouse' instead - please recheck your settings!");
344
        }
345
        interface.enableWindowPinning = iniInterface->getValue("enable_window_pinning", false);
×
346
        interface.windowSnapDistance = iniInterface->getValue("window_snap_distance", 8);
×
347
        // }
348

349
        // addons
350
        // {
351
        for(unsigned addon = 0; addon < iniAddons->size(); ++addon)
×
352
        {
353
            const auto* item = dynamic_cast<const libsiedler2::ArchivItem_Text*>(iniAddons->get(addon));
×
354

355
            if(item)
×
356
                addons.configuration.insert(std::make_pair(s25util::fromStringClassic<unsigned>(item->getName()),
×
357
                                                           s25util::fromStringClassic<unsigned>(item->getText())));
×
358
        }
359

360
        LoadIngame();
×
361
        // }
362
    } catch(const std::runtime_error& e)
×
363
    {
364
        s25util::warning(std::string("Could not use settings from \"") + settingsPath.string()
×
365
                         + "\", using default values. Reason: " + e.what());
×
366
        LoadDefaults();
×
367
        Save();
×
368
    }
369
}
×
370

371
void Settings::LoadIngame()
×
372
{
373
    libsiedler2::Archiv settingsIngame;
×
374
    const auto settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);
×
375
    try
376
    {
377
        if(libsiedler2::Load(settingsPathIngame, settingsIngame) != 0)
×
378
            throw std::runtime_error("File missing");
×
379

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

416
///////////////////////////////////////////////////////////////////////////////
417
// Routine for saving the configuration
418
void Settings::Save()
×
419
{
420
    libsiedler2::Archiv settings;
×
421
    settings.alloc(SECTION_NAMES.size());
×
422
    for(unsigned i = 0; i < SECTION_NAMES.size(); ++i)
×
423
        settings.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(SECTION_NAMES[i]));
×
424

425
    libsiedler2::ArchivItem_Ini* iniGlobal = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("global"));
×
426
    libsiedler2::ArchivItem_Ini* iniVideo = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("video"));
×
427
    libsiedler2::ArchivItem_Ini* iniLanguage = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("language"));
×
428
    libsiedler2::ArchivItem_Ini* iniDriver = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("driver"));
×
429
    libsiedler2::ArchivItem_Ini* iniSound = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("sound"));
×
430
    libsiedler2::ArchivItem_Ini* iniLobby = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("lobby"));
×
431
    libsiedler2::ArchivItem_Ini* iniServer = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("server"));
×
432
    libsiedler2::ArchivItem_Ini* iniProxy = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("proxy"));
×
433
    libsiedler2::ArchivItem_Ini* iniInterface = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("interface"));
×
434
    libsiedler2::ArchivItem_Ini* iniAddons = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("addons"));
×
435

436
    // Is one of the categories missing?
437
    RTTR_Assert(iniGlobal && iniVideo && iniLanguage && iniDriver && iniSound && iniLobby && iniServer && iniProxy
×
438
                && iniInterface && iniAddons);
439

440
    // global
441
    // {
442
    iniGlobal->setValue("version", VERSION);
×
443
    iniGlobal->setValue("gameversion", rttr::version::GetRevision());
×
NEW
444
    iniGlobal->setValue("submit_debug_data", global.submitDebugData);
×
NEW
445
    iniGlobal->setValue("use_upnp", global.useUPNP);
×
446
    iniGlobal->setValue("smartCursor", global.smartCursor);
×
447
    iniGlobal->setValue("debugMode", global.debugMode);
×
448
    iniGlobal->setValue("showGFInfo", global.showGFInfo);
×
449
    // };
450

451
    // video
452
    // {
453
    iniVideo->setValue("fullscreen_width", video.fullscreenSize.width);
×
454
    iniVideo->setValue("fullscreen_height", video.fullscreenSize.height);
×
455
    iniVideo->setValue("windowed_width", video.windowedSize.width);
×
456
    iniVideo->setValue("windowed_height", video.windowedSize.height);
×
NEW
457
    iniVideo->setValue("displayMode", rttr::enum_cast(video.displayMode.type));
×
NEW
458
    iniVideo->setValue("lock_window_size", !video.displayMode.resizeable);
×
459
    iniVideo->setValue("framerate", video.framerate);
×
460
    iniVideo->setValue("vbo", video.vbo);
×
NEW
461
    iniVideo->setValue("shared_textures", video.sharedTextures);
×
462
    iniVideo->setValue("gui_scale", video.guiScale);
×
463
    // };
464

465
    // language
466
    // {
467
    iniLanguage->setValue("language", language.language);
×
468
    // }
469

470
    // driver
471
    // {
472
    iniDriver->setValue("video", driver.video);
×
473
    iniDriver->setValue("audio", driver.audio);
×
474
    // }
475

476
    // sound
477
    // {
478
    iniSound->setValue("musik", sound.musicEnabled);
×
479
    iniSound->setValue("musik_volume", sound.musicVolume);
×
480
    iniSound->setValue("effekte", sound.effectsEnabled);
×
481
    iniSound->setValue("effekte_volume", sound.effectsVolume);
×
482
    iniSound->setValue("bird_sounds", sound.birdsEnabled);
×
483
    iniSound->setValue("playlist", sound.playlist);
×
484
    // }
485

486
    // lobby
487
    // {
488
    iniLobby->setValue("name", lobby.name);
×
489
    iniLobby->setValue("portrait_index", lobby.portraitIndex);
×
490
    iniLobby->setValue("password", lobby.password);
×
NEW
491
    iniLobby->setValue("save_password", lobby.savePassword);
×
492
    // }
493

494
    // server
495
    // {
NEW
496
    iniServer->setValue("last_ip", server.lastIP);
×
497
    iniServer->setValue("local_port", server.localPort);
×
498
    iniServer->setValue("ipv6", server.ipv6);
×
499
    // }
500

501
    // proxy
502
    // {
503
    iniProxy->setValue("proxy", proxy.hostname);
×
504
    iniProxy->setValue("port", proxy.port);
×
505
    iniProxy->setValue("typ", static_cast<int>(proxy.type));
×
506
    // }
507

508
    // interface
509
    // {
NEW
510
    iniInterface->setValue("autosave_interval", interface.autosaveInterval);
×
511
    iniInterface->setValue("map_scroll_mode", static_cast<int>(interface.mapScrollMode));
×
512
    iniInterface->setValue("enable_window_pinning", interface.enableWindowPinning);
×
513
    iniInterface->setValue("window_snap_distance", interface.windowSnapDistance);
×
514
    // }
515

516
    // addons
517
    // {
518
    iniAddons->clear();
×
519
    for(const auto& it : addons.configuration)
×
520
        iniAddons->setValue(s25util::toStringClassic(it.first), s25util::toStringClassic(it.second));
×
521
    // }
522

523
    bfs::path settingsPath = RTTRCONFIG.ExpandPath(s25::resources::config);
×
524
    if(libsiedler2::Write(settingsPath, settings) == 0)
×
525
        bfs::permissions(settingsPath, bfs::owner_read | bfs::owner_write);
×
526

527
    SaveIngame();
×
528
}
×
529

530
void Settings::SaveIngame()
×
531
{
532
    libsiedler2::Archiv settingsIngame;
×
533
    settingsIngame.alloc(1 + persistentWindows.size());
×
534
    settingsIngame.set(0, std::make_unique<libsiedler2::ArchivItem_Ini>("ingame"));
×
535
    unsigned i = 1;
×
536
    for(const auto& window : persistentWindows)
×
537
    {
538
        settingsIngame.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(window.second));
×
539
        i++;
×
540
    }
541

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

544
    RTTR_Assert(iniIngame);
×
545

546
    // ingame
547
    // {
NEW
548
    iniIngame->setValue("scale_statistics", ingame.scaleStatistics);
×
549
    iniIngame->setValue("show_building_quality", ingame.showBQ);
×
550
    iniIngame->setValue("show_names", ingame.showNames);
×
551
    iniIngame->setValue("show_productivity", ingame.showProductivity);
×
552
    iniIngame->setValue("minimap_extended", ingame.minimapExtended);
×
553
    // }
554

555
    // ingame windows
556
    for(const auto& window : persistentWindows)
×
557
    {
558
        auto* iniWindow = static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find(window.second));
×
559
        if(!iniWindow)
×
560
            continue;
×
561
        const auto& settings = windows.persistentSettings[window.first];
×
562
        iniWindow->setValue("pos_x", settings.lastPos.x);
×
563
        iniWindow->setValue("pos_y", settings.lastPos.y);
×
564
        if(settings.restorePos != settings.lastPos)
×
565
        {
566
            // only save if different; defaults to lastPos on load
567
            iniWindow->setValue("restore_pos_x", settings.restorePos.x);
×
568
            iniWindow->setValue("restore_pos_y", settings.restorePos.y);
×
569
        }
570
        iniWindow->setValue("is_open", settings.isOpen);
×
571
        iniWindow->setValue("is_pinned", settings.isPinned);
×
572
        iniWindow->setValue("is_minimized", settings.isMinimized);
×
573
    }
574

575
    bfs::path settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);
×
576
    if(libsiedler2::Write(settingsPathIngame, settingsIngame) == 0)
×
577
        bfs::permissions(settingsPathIngame, bfs::owner_read | bfs::owner_write);
×
578
}
×
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