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

Return-To-The-Roots / s25client / 14284082480

05 Apr 2025 05:14PM UTC coverage: 50.296% (+0.008%) from 50.288%
14284082480

Pull #1750

github

web-flow
Merge 739414d33 into c8cf430f2
Pull Request #1750: Fix size of Settings window

8 of 26 new or added lines in 15 files covered. (30.77%)

2 existing lines in 1 file now uncovered.

22363 of 44463 relevant lines covered (50.3%)

36104.46 hits per line

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

21.97
/libs/s25main/Settings.cpp
1
// Copyright (C) 2005 - 2021 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/const_gui_ids.h"
15
#include "libsiedler2/ArchivItem_Ini.h"
16
#include "libsiedler2/ArchivItem_Text.h"
17
#include "libsiedler2/libsiedler2.h"
18
#include "s25util/StringConversion.h"
19
#include "s25util/System.h"
20
#include "s25util/error.h"
21
#include <boost/filesystem/operations.hpp>
22

23
const int Settings::VERSION = 13;
24
const std::array<std::string, 10> Settings::SECTION_NAMES = {
25
  {"global", "video", "language", "driver", "sound", "lobby", "server", "proxy", "interface", "addons"}};
26

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

30
const std::map<GUI_ID, std::string> persistentWindows = {{CGI_CHAT, "wnd_chat"},
31
                                                         {CGI_POSTOFFICE, "wnd_postoffice"},
32
                                                         {CGI_DISTRIBUTION, "wnd_distribution"},
33
                                                         {CGI_BUILDORDER, "wnd_buildorder"},
34
                                                         {CGI_TRANSPORT, "wnd_transport"},
35
                                                         {CGI_MILITARY, "wnd_military"},
36
                                                         {CGI_TOOLS, "wnd_tools"},
37
                                                         {CGI_INVENTORY, "wnd_inventory"},
38
                                                         {CGI_MINIMAP, "wnd_minimap"},
39
                                                         {CGI_BUILDINGS, "wnd_buildings"},
40
                                                         {CGI_BUILDINGSPRODUCTIVITY, "wnd_buildingsproductivity"},
41
                                                         {CGI_MUSICPLAYER, "wnd_musicplayer"},
42
                                                         {CGI_STATISTICS, "wnd_statistics"},
43
                                                         {CGI_ECONOMICPROGRESS, "wnd_economicprogress"},
44
                                                         {CGI_DIPLOMACY, "wnd_diplomacy"},
45
                                                         {CGI_SHIP, "wnd_ship"},
46
                                                         {CGI_MERCHANDISE_STATISTICS, "wnd_merchandise_statistics"}};
47

48
namespace validate {
49
boost::optional<uint16_t> checkPort(const std::string& port)
9✔
50
{
51
    int32_t iPort;
52
    if((helpers::tryFromString(port, iPort) || s25util::tryFromStringClassic(port, iPort)) && checkPort(iPort))
9✔
53
        return static_cast<uint16_t>(iPort);
3✔
54
    else
55
        return boost::none;
6✔
56
}
57
bool checkPort(int port)
7✔
58
{
59
    // Disallow port 0 as it may cause problems
60
    return port > 0 && port <= 65535;
7✔
61
}
62
} // namespace validate
63

64
Settings::Settings() //-V730
5✔
65
{
66
    LoadDefaults();
5✔
67
}
5✔
68

69
void Settings::LoadDefaults()
5✔
70
{
71
    // global
72
    // {
73
    // 0 = ask user at start, 1 = enabled, 2 = always ask
74
    global.submit_debug_data = 0;
5✔
75
    global.use_upnp = false;
5✔
76
    global.smartCursor = true;
5✔
77
    global.debugMode = false;
5✔
78
    global.showGFInfo = false;
5✔
79
    // }
80

81
    // video
82
    // {
83
    if(VIDEODRIVER.IsLoaded())
5✔
84
    {
85
        video.fullscreenSize = VIDEODRIVER.GetWindowSize();
3✔
86
        video.windowedSize = VIDEODRIVER.IsFullscreen() ? VideoMode(800, 600) : video.fullscreenSize;
3✔
87
        video.fullscreen = VIDEODRIVER.IsFullscreen();
3✔
88
    } else
89
    {
90
        video.windowedSize = video.fullscreenSize = VideoMode(800, 600);
2✔
91
        video.fullscreen = false;
2✔
92
    }
93
    video.framerate = 0; // Special value for HW vsync
5✔
94
    video.vbo = true;
5✔
95
    video.shared_textures = true;
5✔
96
    video.guiScale = 0; // special value indicating automatic selection
5✔
97
    // }
98

99
    // language
100
    // {
101
    language.language.clear();
5✔
102
    // }
103

104
    LANGUAGES.setLanguage(language.language);
5✔
105

106
    // driver
107
    // {
108
    driver.audio = AUDIODRIVER.GetName();
5✔
109
    driver.video = VIDEODRIVER.GetName();
5✔
110
    // }
111

112
    // sound
113
    // {
114
    sound.musicEnabled = false;
5✔
115
    sound.musicVolume = 30;
5✔
116
    sound.effectsEnabled = true;
5✔
117
    sound.effectsVolume = 75;
5✔
118
    sound.playlist = s25::files::defaultPlaylist;
5✔
119
    // }
120

121
    // lobby
122
    // {
123

124
    lobby.name = System::getUserName();
5✔
125
    lobby.password.clear();
5✔
126
    lobby.save_password = false;
5✔
127
    // }
128

129
    // server
130
    // {
131
    server.last_ip.clear();
5✔
132
    server.localPort = 3665;
5✔
133
    server.ipv6 = false;
5✔
134
    // }
135

136
    proxy = ProxySettings();
5✔
137
    proxy.port = 1080;
5✔
138

139
    // interface
140
    // {
141
    interface.autosave_interval = 0;
5✔
142
    interface.invertMouse = false;
5✔
143
    interface.enableWindowPinning = false;
5✔
144
    interface.windowSnapDistance = 8;
5✔
145
    // }
146

147
    // addons
148
    // {
149
    addons.configuration.clear();
5✔
150
    // }
151

152
    LoadIngameDefaults();
5✔
153
}
5✔
154

155
void Settings::LoadIngameDefaults()
5✔
156
{
157
    // ingame
158
    // {
159
    ingame.scale_statistics = false;
5✔
160
    ingame.showBQ = false;
5✔
161
    ingame.showNames = false;
5✔
162
    ingame.showProductivity = false;
5✔
163
    ingame.minimapExtended = false;
5✔
164
    // }
165

166
    // windows
167
    // {
168
    for(const auto& window : persistentWindows)
90✔
169
        windows.persistentSettings[window.first] = PersistentWindowSettings();
85✔
170
    // }
171
}
5✔
172

173
///////////////////////////////////////////////////////////////////////////////
174
// Routine zum Laden der Konfiguration
175
void Settings::Load()
×
176
{
177
    libsiedler2::Archiv settings;
×
178
    const auto settingsPath = RTTRCONFIG.ExpandPath(s25::resources::config);
×
179
    try
180
    {
181
        if(libsiedler2::Load(settingsPath, settings) != 0 || settings.size() < SECTION_NAMES.size())
×
182
            throw std::runtime_error("File missing or invalid");
×
183

184
        const libsiedler2::ArchivItem_Ini* iniGlobal =
185
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("global"));
×
186
        const libsiedler2::ArchivItem_Ini* iniVideo = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("video"));
×
187
        const libsiedler2::ArchivItem_Ini* iniLanguage =
188
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("language"));
×
189
        const libsiedler2::ArchivItem_Ini* iniDriver =
190
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("driver"));
×
191
        const libsiedler2::ArchivItem_Ini* iniSound = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("sound"));
×
192
        const libsiedler2::ArchivItem_Ini* iniLobby = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("lobby"));
×
193
        const libsiedler2::ArchivItem_Ini* iniServer =
194
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("server"));
×
195
        const libsiedler2::ArchivItem_Ini* iniProxy = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("proxy"));
×
196
        const libsiedler2::ArchivItem_Ini* iniInterface =
197
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("interface"));
×
198
        const libsiedler2::ArchivItem_Ini* iniAddons =
199
          static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("addons"));
×
200

201
        // ist eine der Kategorien nicht vorhanden?
202
        if(!iniGlobal || !iniVideo || !iniLanguage || !iniDriver || !iniSound || !iniLobby || !iniServer || !iniProxy
×
203
           || !iniInterface || !iniAddons)
×
204
        {
205
            throw std::runtime_error("Missing section");
×
206
        }
207
        // stimmt die Settingsversion?
208
        if(iniGlobal->getValue("version", 0) != VERSION)
×
209
            throw std::runtime_error("Wrong version");
×
210

211
        // global
212
        // {
213
        if(iniGlobal->getValue("gameversion") != rttr::version::GetRevision())
×
214
            s25util::warning("Your application version has changed - please recheck your settings!");
×
215

216
        global.submit_debug_data = iniGlobal->getIntValue("submit_debug_data");
×
217
        global.use_upnp = iniGlobal->getBoolValue("use_upnp");
×
218
        global.smartCursor = iniGlobal->getValue("smartCursor", true);
×
219
        global.debugMode = iniGlobal->getValue("debugMode", false);
×
220
        global.showGFInfo = iniGlobal->getValue("showGFInfo", false);
×
221
        // };
222

223
        // video
224
        // {
225
        video.windowedSize.width = iniVideo->getIntValue("windowed_width");
×
226
        video.windowedSize.height = iniVideo->getIntValue("windowed_height");
×
227
        video.fullscreenSize.width = iniVideo->getIntValue("fullscreen_width");
×
228
        video.fullscreenSize.height = iniVideo->getIntValue("fullscreen_height");
×
229
        video.fullscreen = iniVideo->getBoolValue("fullscreen");
×
230
        video.framerate = iniVideo->getValue("framerate", 0);
×
231
        video.vbo = iniVideo->getBoolValue("vbo");
×
232
        video.shared_textures = iniVideo->getBoolValue("shared_textures");
×
233
        video.guiScale = iniVideo->getValue("gui_scale", 0);
×
234
        // };
235

236
        if(video.fullscreenSize.width == 0 || video.fullscreenSize.height == 0 || video.windowedSize.width == 0
×
237
           || video.windowedSize.height == 0)
×
238
            throw std::runtime_error("Invalid video settings");
×
239

240
        // language
241
        // {
242
        language.language = iniLanguage->getValue("language");
×
243
        // }
244

245
        LANGUAGES.setLanguage(language.language);
×
246

247
        // driver
248
        // {
249
        driver.video = iniDriver->getValue("video");
×
250
        driver.audio = iniDriver->getValue("audio");
×
251
        // }
252

253
        // sound
254
        // {
255
        sound.musicEnabled = iniSound->getBoolValue("musik");
×
256
        sound.musicVolume = iniSound->getIntValue("musik_volume");
×
257
        sound.effectsEnabled = iniSound->getBoolValue("effekte");
×
258
        sound.effectsVolume = iniSound->getIntValue("effekte_volume");
×
259
        sound.playlist = iniSound->getValue("playlist");
×
260
        // }
261

262
        // lobby
263
        // {
264
        lobby.name = iniLobby->getValue("name");
×
265
        lobby.password = iniLobby->getValue("password");
×
266
        lobby.save_password = iniLobby->getBoolValue("save_password");
×
267
        // }
268

269
        if(lobby.name.empty())
×
270
            lobby.name = System::getUserName();
×
271

272
        // server
273
        // {
274
        server.last_ip = iniServer->getValue("last_ip");
×
275
        boost::optional<uint16_t> port = validate::checkPort(iniServer->getValue("local_port"));
×
276
        server.localPort = port.value_or(3665);
×
277
        server.ipv6 = iniServer->getBoolValue("ipv6");
×
278
        // }
279

280
        // proxy
281
        // {
282
        proxy.hostname = iniProxy->getValue("proxy");
×
283
        port = validate::checkPort(iniProxy->getValue("port"));
×
284
        proxy.port = port.value_or(1080);
×
285
        proxy.type = ProxyType(iniProxy->getIntValue("typ"));
×
286
        // }
287

288
        // leere proxyadresse deaktiviert proxy komplett
289
        // deaktivierter proxy entfernt proxyadresse
290
        if(proxy.hostname.empty() || (proxy.type != ProxyType::Socks4 && proxy.type != ProxyType::Socks5))
×
291
        {
292
            proxy.type = ProxyType::None;
×
293
            proxy.hostname.clear();
×
294
        }
295
        // aktivierter Socks v4 deaktiviert ipv6
296
        else if(proxy.type == ProxyType::Socks4 && server.ipv6)
×
297
            server.ipv6 = false;
×
298

299
        // interface
300
        // {
301
        interface.autosave_interval = iniInterface->getIntValue("autosave_interval");
×
302
        interface.invertMouse = iniInterface->getValue("invert_mouse", false);
×
303
        interface.enableWindowPinning = iniInterface->getValue("enable_window_pinning", false);
×
304
        interface.windowSnapDistance = iniInterface->getValue("window_snap_distance", 8);
×
305
        // }
306

307
        // addons
308
        // {
309
        for(unsigned addon = 0; addon < iniAddons->size(); ++addon)
×
310
        {
311
            const auto* item = dynamic_cast<const libsiedler2::ArchivItem_Text*>(iniAddons->get(addon));
×
312

313
            if(item)
×
314
                addons.configuration.insert(std::make_pair(s25util::fromStringClassic<unsigned>(item->getName()),
×
315
                                                           s25util::fromStringClassic<unsigned>(item->getText())));
×
316
        }
317

318
        LoadIngame();
×
319
        // }
NEW
320
    } catch(const std::runtime_error& e)
×
321
    {
322
        s25util::warning(std::string("Could not use settings from \"") + settingsPath.string()
×
323
                         + "\", using default values. Reason: " + e.what());
×
324
        LoadDefaults();
×
325
        Save();
×
326
    }
327
}
×
328

329
void Settings::LoadIngame()
×
330
{
331
    libsiedler2::Archiv settingsIngame;
×
332
    const auto settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);
×
333
    try
334
    {
335
        if(libsiedler2::Load(settingsPathIngame, settingsIngame) != 0)
×
336
            throw std::runtime_error("File missing");
×
337

338
        const libsiedler2::ArchivItem_Ini* iniIngame =
339
          static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find("ingame"));
×
340
        if(!iniIngame)
×
341
            throw std::runtime_error("Missing section");
×
342
        // ingame
343
        // {
344
        ingame.scale_statistics = iniIngame->getBoolValue("scale_statistics");
×
345
        ingame.showBQ = iniIngame->getBoolValue("show_building_quality");
×
346
        ingame.showNames = iniIngame->getBoolValue("show_names");
×
347
        ingame.showProductivity = iniIngame->getBoolValue("show_productivity");
×
348
        ingame.minimapExtended = iniIngame->getBoolValue("minimap_extended");
×
349
        // }
350
        // ingame windows
351
        for(const auto& window : persistentWindows)
×
352
        {
353
            const auto* iniWindow = static_cast<const libsiedler2::ArchivItem_Ini*>(settingsIngame.find(window.second));
×
354
            if(!iniWindow)
×
355
                continue;
×
356
            auto& settings = windows.persistentSettings[window.first];
×
357
            const auto lastPos = settings.lastPos =
×
358
              DrawPoint(iniWindow->getIntValue("pos_x"), iniWindow->getIntValue("pos_y"));
×
359
            settings.restorePos = DrawPoint(iniWindow->getValue("restore_pos_x", lastPos.x),
×
360
                                            iniWindow->getValue("restore_pos_y", lastPos.y));
×
361
            settings.isOpen = iniWindow->getIntValue("is_open");
×
362
            settings.isPinned = iniWindow->getValue("is_pinned", false);
×
363
            settings.isMinimized = iniWindow->getValue("is_minimized", false);
×
364
        }
NEW
365
    } catch(const std::runtime_error& e)
×
366
    {
367
        s25util::warning(std::string("Could not use ingame settings from \"") + settingsPathIngame.string()
×
368
                         + "\", using default values. Reason: " + e.what());
×
369
        LoadIngameDefaults();
×
370
        SaveIngame();
×
371
    }
372
}
×
373

374
///////////////////////////////////////////////////////////////////////////////
375
// Routine zum Speichern der Konfiguration
376
void Settings::Save()
×
377
{
378
    libsiedler2::Archiv settings;
×
379
    settings.alloc(SECTION_NAMES.size());
×
380
    for(unsigned i = 0; i < SECTION_NAMES.size(); ++i)
×
381
        settings.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(SECTION_NAMES[i]));
×
382

383
    libsiedler2::ArchivItem_Ini* iniGlobal = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("global"));
×
384
    libsiedler2::ArchivItem_Ini* iniVideo = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("video"));
×
385
    libsiedler2::ArchivItem_Ini* iniLanguage = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("language"));
×
386
    libsiedler2::ArchivItem_Ini* iniDriver = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("driver"));
×
387
    libsiedler2::ArchivItem_Ini* iniSound = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("sound"));
×
388
    libsiedler2::ArchivItem_Ini* iniLobby = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("lobby"));
×
389
    libsiedler2::ArchivItem_Ini* iniServer = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("server"));
×
390
    libsiedler2::ArchivItem_Ini* iniProxy = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("proxy"));
×
391
    libsiedler2::ArchivItem_Ini* iniInterface = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("interface"));
×
392
    libsiedler2::ArchivItem_Ini* iniAddons = static_cast<libsiedler2::ArchivItem_Ini*>(settings.find("addons"));
×
393

394
    // ist eine der Kategorien nicht vorhanden?
395
    RTTR_Assert(iniGlobal && iniVideo && iniLanguage && iniDriver && iniSound && iniLobby && iniServer && iniProxy
×
396
                && iniInterface && iniAddons);
397

398
    // global
399
    // {
400
    iniGlobal->setValue("version", VERSION);
×
401
    iniGlobal->setValue("gameversion", rttr::version::GetRevision());
×
402
    iniGlobal->setValue("submit_debug_data", global.submit_debug_data);
×
403
    iniGlobal->setValue("use_upnp", global.use_upnp);
×
404
    iniGlobal->setValue("smartCursor", global.smartCursor);
×
405
    iniGlobal->setValue("debugMode", global.debugMode);
×
406
    iniGlobal->setValue("showGFInfo", global.showGFInfo);
×
407
    // };
408

409
    // video
410
    // {
411
    iniVideo->setValue("fullscreen_width", video.fullscreenSize.width);
×
412
    iniVideo->setValue("fullscreen_height", video.fullscreenSize.height);
×
413
    iniVideo->setValue("windowed_width", video.windowedSize.width);
×
414
    iniVideo->setValue("windowed_height", video.windowedSize.height);
×
415
    iniVideo->setValue("fullscreen", video.fullscreen);
×
416
    iniVideo->setValue("framerate", video.framerate);
×
417
    iniVideo->setValue("vbo", video.vbo);
×
418
    iniVideo->setValue("shared_textures", video.shared_textures);
×
419
    iniVideo->setValue("gui_scale", video.guiScale);
×
420
    // };
421

422
    // language
423
    // {
424
    iniLanguage->setValue("language", language.language);
×
425
    // }
426

427
    // driver
428
    // {
429
    iniDriver->setValue("video", driver.video);
×
430
    iniDriver->setValue("audio", driver.audio);
×
431
    // }
432

433
    // sound
434
    // {
435
    iniSound->setValue("musik", sound.musicEnabled);
×
436
    iniSound->setValue("musik_volume", sound.musicVolume);
×
437
    iniSound->setValue("effekte", sound.effectsEnabled);
×
438
    iniSound->setValue("effekte_volume", sound.effectsVolume);
×
439
    iniSound->setValue("playlist", sound.playlist);
×
440
    // }
441

442
    // lobby
443
    // {
444
    iniLobby->setValue("name", lobby.name);
×
445
    iniLobby->setValue("password", lobby.password);
×
446
    iniLobby->setValue("save_password", lobby.save_password);
×
447
    // }
448

449
    // server
450
    // {
451
    iniServer->setValue("last_ip", server.last_ip);
×
452
    iniServer->setValue("local_port", server.localPort);
×
453
    iniServer->setValue("ipv6", server.ipv6);
×
454
    // }
455

456
    // proxy
457
    // {
458
    iniProxy->setValue("proxy", proxy.hostname);
×
459
    iniProxy->setValue("port", proxy.port);
×
460
    iniProxy->setValue("typ", static_cast<int>(proxy.type));
×
461
    // }
462

463
    // interface
464
    // {
465
    iniInterface->setValue("autosave_interval", interface.autosave_interval);
×
466
    iniInterface->setValue("invert_mouse", interface.invertMouse);
×
467
    iniInterface->setValue("enable_window_pinning", interface.enableWindowPinning);
×
468
    iniInterface->setValue("window_snap_distance", interface.windowSnapDistance);
×
469
    // }
470

471
    // addons
472
    // {
473
    iniAddons->clear();
×
474
    for(const auto& it : addons.configuration)
×
475
        iniAddons->setValue(s25util::toStringClassic(it.first), s25util::toStringClassic(it.second));
×
476
    // }
477

478
    bfs::path settingsPath = RTTRCONFIG.ExpandPath(s25::resources::config);
×
479
    if(libsiedler2::Write(settingsPath, settings) == 0)
×
480
        bfs::permissions(settingsPath, bfs::owner_read | bfs::owner_write);
×
481

482
    SaveIngame();
×
483
}
×
484

485
void Settings::SaveIngame()
×
486
{
487
    libsiedler2::Archiv settingsIngame;
×
488
    settingsIngame.alloc(1 + persistentWindows.size());
×
489
    settingsIngame.set(0, std::make_unique<libsiedler2::ArchivItem_Ini>("ingame"));
×
490
    unsigned i = 1;
×
491
    for(const auto& window : persistentWindows)
×
492
    {
493
        settingsIngame.set(i, std::make_unique<libsiedler2::ArchivItem_Ini>(window.second));
×
494
        i++;
×
495
    }
496

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

499
    RTTR_Assert(iniIngame);
×
500

501
    // ingame
502
    // {
503
    iniIngame->setValue("scale_statistics", ingame.scale_statistics);
×
504
    iniIngame->setValue("show_building_quality", ingame.showBQ);
×
505
    iniIngame->setValue("show_names", ingame.showNames);
×
506
    iniIngame->setValue("show_productivity", ingame.showProductivity);
×
507
    iniIngame->setValue("minimap_extended", ingame.minimapExtended);
×
508
    // }
509

510
    // ingame windows
511
    for(const auto& window : persistentWindows)
×
512
    {
513
        auto* iniWindow = static_cast<libsiedler2::ArchivItem_Ini*>(settingsIngame.find(window.second));
×
514
        if(!iniWindow)
×
515
            continue;
×
516
        const auto& settings = windows.persistentSettings[window.first];
×
517
        iniWindow->setValue("pos_x", settings.lastPos.x);
×
518
        iniWindow->setValue("pos_y", settings.lastPos.y);
×
519
        if(settings.restorePos != settings.lastPos)
×
520
        {
521
            // only save if different; defaults to lastPos on load
522
            iniWindow->setValue("restore_pos_x", settings.restorePos.x);
×
523
            iniWindow->setValue("restore_pos_y", settings.restorePos.y);
×
524
        }
525
        iniWindow->setValue("is_open", settings.isOpen);
×
526
        iniWindow->setValue("is_pinned", settings.isPinned);
×
527
        iniWindow->setValue("is_minimized", settings.isMinimized);
×
528
    }
529

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