Merge lp:~widelands-dev/widelands/add-xdg-support into lp:widelands
- add-xdg-support
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 9187 | ||||
Proposed branch: | lp:~widelands-dev/widelands/add-xdg-support | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
2598 lines (+670/-270) 73 files modified
CMakeLists.txt (+6/-0) compile.sh (+27/-2) src/CMakeLists.txt (+3/-2) src/editor/CMakeLists.txt (+1/-1) src/editor/editorinteractive.cc (+3/-2) src/editor/ui_menus/main_menu_map_options.cc (+2/-1) src/editor/ui_menus/main_menu_new_map.cc (+2/-1) src/editor/ui_menus/main_menu_random_map.cc (+2/-1) src/editor/ui_menus/main_menu_save_map.cc (+2/-1) src/editor/ui_menus/player_menu.cc (+3/-5) src/game_io/CMakeLists.txt (+1/-1) src/game_io/game_preload_packet.cc (+1/-1) src/io/CMakeLists.txt (+15/-0) src/io/filesystem/filesystem.cc (+99/-0) src/io/filesystem/filesystem.h (+8/-0) src/io/profile.cc (+1/-3) src/io/profile.h (+4/-4) src/logic/CMakeLists.txt (+3/-2) src/logic/ai_dna_handler.cc (+1/-1) src/logic/game.cc (+3/-2) src/logic/save_handler.cc (+5/-6) src/logic/single_player_game_controller.cc (+2/-2) src/map_io/CMakeLists.txt (+1/-1) src/map_io/coords_profile.cc (+1/-1) src/map_io/map_allowed_building_types_packet.cc (+1/-1) src/map_io/map_allowed_worker_types_packet.cc (+1/-1) src/map_io/map_elemental_packet.cc (+1/-1) src/map_io/map_objective_packet.cc (+1/-1) src/map_io/map_player_names_and_tribes_packet.cc (+1/-1) src/map_io/map_player_position_packet.cc (+1/-1) src/map_io/map_players_messages_packet.cc (+1/-1) src/map_io/map_port_spaces_packet.cc (+1/-1) src/map_io/map_version_packet.cc (+1/-1) src/network/CMakeLists.txt (+0/-1) src/network/gameclient.cc (+4/-4) src/network/gamehost.cc (+6/-6) src/profile/CMakeLists.txt (+0/-14) src/scripting/CMakeLists.txt (+2/-1) src/scripting/lua_bases.cc (+1/-1) src/scripting/lua_game.cc (+2/-1) src/sound/CMakeLists.txt (+1/-1) src/sound/sound_handler.cc (+15/-19) src/ui_basic/CMakeLists.txt (+0/-1) src/ui_basic/panel.cc (+2/-2) src/ui_fsmenu/CMakeLists.txt (+5/-5) src/ui_fsmenu/campaign_select.cc (+0/-1) src/ui_fsmenu/campaigns.cc (+1/-1) src/ui_fsmenu/internet_lobby.cc (+6/-9) src/ui_fsmenu/launch_mpg.cc (+1/-1) src/ui_fsmenu/loadgame.cc (+3/-4) src/ui_fsmenu/multiplayer.cc (+8/-10) src/ui_fsmenu/netsetup_lan.cc (+5/-7) src/ui_fsmenu/options.cc (+3/-2) src/ui_fsmenu/scenario_select.cc (+1/-1) src/wlapplication.cc (+89/-90) src/wlapplication.h (+10/-0) src/wlapplication_options.cc (+151/-0) src/wlapplication_options.h (+118/-0) src/wui/CMakeLists.txt (+4/-4) src/wui/chat_overlay.cc (+2/-3) src/wui/economy_options_window.cc (+1/-1) src/wui/game_main_menu_save_game.cc (+2/-1) src/wui/interactive_base.cc (+0/-1) src/wui/interactive_base.h (+1/-1) src/wui/interactive_gamebase.cc (+0/-1) src/wui/interactive_gamebase.h (+1/-1) src/wui/interactive_player.cc (+0/-1) src/wui/interactive_player.h (+1/-1) src/wui/interactive_spectator.cc (+0/-1) src/wui/interactive_spectator.h (+1/-1) src/wui/login_box.cc (+14/-18) src/wui/mapview.cc (+2/-2) src/wui/watchwindow.cc (+2/-2) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/add-xdg-support | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
kaputtnik (community) | Needs Fixing | ||
Toni Förster | Approve | ||
Klaus Halfmann | code review | Approve | |
GunChleoc | Needs Fixing | ||
Review via email: mp+347652@code.launchpad.net |
Commit message
Add basic XDG support.
Use 'XDG_DATA_
'~/.widelands' will be used as a fallback if the folder already exists.
Description of the change
bunnybot (widelandsofficial) wrote : | # |
Klaus Halfmann (klaus-halfmann) wrote : | # |
Hello Luki, thanks for your support!
I was no ware about that spec. But on OSX such Files should e.g. be found
at ~/Library/
OK just found "NOT APPLE". Sound Like I have to do this on a seperate branch,
and it can be tested on *nix only.
Gun: I am not sure if this should make it into R20 it may break some tescases
and documentation. So I would suggets to put this in at the begin of R21,
once R20 is on the road to be relased.
I will try to check how this beaves on OSX perhaps on Sunday.
Not sure If I will be able to unpack that Linux Box in my corner soon.
One nit inline, code looks so far so good.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 3600. State: failed. Details: https:/
Appveyor build 3403. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
There are still some trailing whitespaces that need fixing.
Maybe we can have this for Build 20 already; I'll need to take a look and to some testing when I get back home.
/home/travis/
/home/travis/
/home/travis/
/home/travis/
+echo 'You have codecheck warnings (see above) Please fix.'
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 3612. State: passed. Details: https:/
Appveyor build 3414. State: success. Details: https:/
Klaus Halfmann (klaus-halfmann) wrote : | # |
Lucki: On a normal build this will never be enabled.
e.g. I use compile.sh which does not know about that flag, yet.
I will compile this on OSX now.
Once with default and once with -DUSE_XDG=ON
It shoud not make any difference though.
As of the code this will only come into effect for completely new installations,
as long as there is a ~/.widelands directory this still will be used.
Klaus Halfmann (klaus-halfmann) wrote : | # |
I added cmake .. -DUSE_XDG=ON to compile.sh, but still that code is not executed?
please help me with that cmake stuff ...
Klaus Halfmann (klaus-halfmann) wrote : | # |
OK must remove that "AND NOT APPLE" stuff, too
Klaus Halfmann (klaus-halfmann) wrote : | # |
The Code works as expected.
Please check my inline comment. (I cannot commit to your branch)
Gun: I think this could become a default.
Lucki: Do you intend to enable this in some Ubuntu repository?
Lucki (lucki1) wrote : | # |
I'm sorry I confused you.
I wasn't aware that there was a 'compile.sh'. I have now adjusted them additionally.
A little more explanation:
Because the general acceptance of this change in the linked bug report was rather low, this setting must be explicitly activated. This can now be done with './compile.sh --with-xdg' or 'cmake .. -DUSE_XDG=ON'.
These changes only affect Linux, so Apple and Windows should be excluded in the 'CMakeLists.txt'. I cannot test this part due to a lack of operating systems. If the option is activated on Apple or Windows against expectation, the filter in the 'CMakeLists.txt' should still prevent the option from being activated on the wrong operating systems. These changes should have no effect on Apple and Windows. Hopefully.
You are right that these changes only affect complete new installations or require a manual move of the relevant folder. In addition, this option must be activated separately. This was chosen because, as I said, acceptance of these changes was rather low.
If the option is enabled and no folder '$HOME/.widelands' exists, the folder is created or used in '$XDG_DATA_
Hopefully this option will be used by the package maintainers in the future. :)
Klaus Halfmann (klaus-halfmann) wrote : | # |
Thanks Lucki for your changes, this is 100% OK for me now:
> ./compile.sh --help
--with-xdg Enable support for the XDG Base Directory Specification.
> ./compile.sh --with-xdg
Basic XDG Base Directory Specification will be used on Linux
if no existing $HOME/.widelands folder is found.
The widelands user data can be found in $XDG_DATA_
and defaults to $HOME/.
See https:/
for more information.
I dont have a Linux PC around for testing by now.
Lets have another automated tests, can go in in once those have passed.
Klaus Halfmann (klaus-halfmann) wrote : | # |
Gun: any idea why bunnybot did not pick up this one?
GunChleoc (gunchleoc) wrote : | # |
I have added some comments for more code improvements. Thanks for taking this on :)
To comply with the standard, we still need another directory defined, which is $XDG_CONFIG_HOME and where "config" should sit.
At the moment, we have const std::string kConfigFile = "config"; defined in src/logic/
The file is read/written in src/ui_
GunChleoc (gunchleoc) wrote : | # |
It's been a while since you have merged trunk - please use bzr merge after implementing the in-line comments.
Klaus Halfmann (klaus-halfmann) wrote : | # |
Lucki, will you care for the XDG_CONFIG_HOME?
I revived that Ubuntu Machine, but currently cannot
acces it (mut reduce sons screen time ...)
Not sure If I will have time to activly care for this one.
Lucki (lucki1) wrote : | # |
I'm afraid I can't.
I've played a bit around and nothing worked out.
This should be done by a person more capable than me in a different pull request.
GunChleoc (gunchleoc) wrote : | # |
I have added you to widelands-dev. Can you change the branch owner? Then anybody can pick this up - I don't think we should merge this without having the config file fixed.
In theory, it should work just like the other directory. Search the codebase for "g_options" to see how the file is loaded and saved.
Lucki (lucki1) wrote : | # |
Done
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 3656. State: failed. Details: https:/
Appveyor build 3455. State: failed. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Thanks!
I'm concentrating on Build 20 targeted bugs at the moment, so it will be a while before I get around to it.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4711. State: failed. Details: https:/
Appveyor build 4497. State: success. Details: https:/
Lucki (lucki1) wrote : | # |
This works now in my little testing.
There are two little warnings (not errors) I'm not sure why they're present:
* Compiling without USE_XDG gives me an -Wundef warning in wlapplication.
* In debug mode, compiled with USE_XDG I get "could not open file for reading:" instead of the nice "There's no configuration file, using default values." message. This should be catched in profile.cc.
Klaus Halfmann (klaus-halfmann) wrote : | # |
Sorry I currently have no Linux/Ubuntu around for easy testing
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4718. State: passed. Details: https:/
Appveyor build 4504. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Hi Lucki,
I apologize for taking so long to get back to you.
I have pushed a commit with a code review - please have a look. I have also moved the profile.h to a different directory, because it has bothered me for a long time and it sort of fits thematically.
I am getting this crash when starting a game:
Reading Player Message Data ... There's no configuration file, using default values.
WidelandsMapLoa
Fatal exception: messages for player 1: [../src/
I think the way to go here is to move everything related to g_options into a new file wlapplication_
Klaus Halfmann (klaus-halfmann) wrote : | # |
I managed to boot my Mac from some stick into Xubuntu,
so I will pick up on this one.
Can you suggest some graphic frontend for GDB for me?
Lucki (lucki1) wrote : | # |
I'm not sure how I could miss that error on map loading… The filename the game is searching for is somehow empty but I couldn't get the reason yet.
Reading and writing the config file itself works fine in the menu.
I think the error should be located before we're moving stuff around.
GunChleoc (gunchleoc) wrote : | # |
Agreed, we'll need to find the error first.
I have only ever used GDB on the command line. Looks like there are some graphical frontends available though https:/
Klaus Halfmann (klaus-halfmann) wrote : | # |
Hmm, I found those XDG variables on this Xubuntu:
declare -x XDG_CONFIG_
declare -x XDG_CURRENT_
declare -x XDG_DATA_
declare -x XDG_GREETER_
declare -x XDG_MENU_
declare -x XDG_RUNTIME_
declare -x XDG_SEAT="seat0"
declare -x XDG_SEAT_
declare -x XDG_SESSION_
declare -x XDG_SESSION_
declare -x XDG_SESSION_ID="c2"
declare -x XDG_SESSION_
declare -x XDG_SESSION_
declare -x XDG_VTNR="7"
But no:
$XDG_DATA_HOME or $XDG_CONFIG_HOME/
Shall we extend this to use $XDG_CONFIG_DIRS / $XDG_DATA_DIRS ?
Lucki (lucki1) wrote : | # |
That added FileError catch was the cause of the error. Removed it but now there's the uncatched error message again if no config file is at the expected location.
For XDG_DATA_DIRS: Right now there's WL_INSTALL_DATADIR which gets hardcoded into the binary.
Lucki (lucki1) wrote : | # |
I'm not sure if it's necessary to care for XDG_CONFIG_DIRS as the configuration file always gets written and needs write access.
XDG_DATA_DIRS looks doable, I'm testing a bit around.
GunChleoc (gunchleoc) wrote : | # |
I could start a game now, both with and without ~/.widelands present :)
It would be good to have some log output that will describe where the directories are when Widelands starts. Otherwise, it will be hard to help with support queries from players in the future.
Lucki (lucki1) wrote : | # |
Added a log entry for the configuration file if it's outside the home directory.
The homedir already gets logged and if a folder gets added through XDG_DATA_DIRS it's mentioned as "Adding directory: /usr/share/
The argument --homedir overrides the configuration directory and sets it to the given homedir.
The argument --datadir takes precedence over XDG_DATA_DIRS while the environment variable itself takes precedence over the INSTALL_DATADIR path given at compile time.
Klaus Halfmann (klaus-halfmann) wrote : | # |
I now got:
Set home directory: /home/klaus/
Set configuration: /home/klaus/
[] config:0: RealFSImpl::load: could not open file for reading: /home/klaus/
Widelands executable directory: /home/klaus/
Adding directory: /home/klaus/
Looks ok for me.
Will do a code-review on the OS-X side of this hardware
Klaus Halfmann (klaus-halfmann) wrote : | # |
OK for me.
Now:
* how can make this a default for *nix builds?
* Who could check if this really matches the specs?
GunChleoc (gunchleoc) wrote : | # |
I have done more testing and it all works as expected.
Since it falls back to the old scheme when a .widelands directory is present (which is more convenient for me when developing), I think we could make this the default now.
I'd also still like to see the refactoring done to get rid of the code duplication.
GunChleoc (gunchleoc) wrote : | # |
I had a look at the spec - we have a "temp" dir now for map backups that are used to make saveloading of games stable. If we want to be strict, those files should go to:
"There is a single base directory relative to which user-specific runtime files and other file objects should be placed. This directory is defined by the environment variable $XDG_RUNTIME_DIR."
Lucki (lucki1) wrote : | # |
XDG_RUNTIME_DIR is meant for sockets, named pipes, ... as later described. I don't think that's the right place for temporary files. The specification isn't clear about temporary files.
A quick search point up this blog, I don't know anything about them but it looks logical what they're describing: http://
1. You need a place to put your socket (or other communication primitive) and your code runs privileged: use a subdirectory beneath /run. (Or beneath /var/run for extra compatibility.)
2. You need a place to put your socket (or other communication primitive) and your code runs unprivileged: use a subdirectory beneath $XDG_RUNTIME_DIR.
3. You need a place to put your larger downloads and downloads in progress and run unprivileged: use $XDG_DOWNLOAD_DIR.
4. You need a place to put cache files which should be persistent and run unprivileged: use $XDG_CACHE_HOME.
5. Nothing of the above applies and you need to place a small file that needs no persistency: use $TMPDIR with a fallback on /tmp. And use mkstemp(), and mkdtemp() and nothing homegrown.
6. Otherwise use $TMPDIR with a fallback on /var/tmp. Also use mkstemp(
This would probably go into 6. because the temporary files don't have to be persistence so they don't fit in 4.?
They're also pointing this out: "One thing we'd like to stress is that /tmp and /var/tmp more often than not are actually not the right choice for your usecase. There are valid uses of these directories, but quite often another directory might actually be the better place. So, be careful, consider the other options, but if you do go for /tmp or /var/tmp then at least make sure to use mkstemp(
About the refactoring: I think klaus-halfmann wanted to pick that up and that's probably a good idea because you know every related bit in the code.
GunChleoc (gunchleoc) wrote : | # |
6. Sounds good.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 5269. State: failed. Details: https:/
Appveyor build 5045. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Thanks for sticking with this!
I have added 2 comments to the diff.
Lucki (lucki1) : | # |
Toni Förster (stonerl) wrote : | # |
Is there any particular reason why this hasn't been merged already?
kaputtnik (franku) wrote : | # |
There are some text conflicts in this branch:
Text conflict in src/wui/
Text conflict in src/wui/
Text conflict in src/wui/
They must be fixed before merging.
kaputtnik (franku) wrote : | # |
I get a crash with these steps:
1. Open Editor
2. Click 'Save Map'
3. In this view click 'Map Options'
4. Change the mapname
5. Click 'OK'
Although i used a debug build i get no debug information.
kaputtnik (franku) wrote : | # |
Just found that the crash happens also if just open the Map Options menu and clicking OK, without opening the save map menu prior
Lucki (lucki1) wrote : | # |
Well, that was dumb…
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 5344. State: errored. Details: https:/
Appveyor build 5114. State: success. Details: https:/
kaputtnik (franku) wrote : | # |
The crash is gone, thanks :-)
But the behavior is different from trunk, don't know if this is intended:
In Trunk:
1. Open Save map view
2. In that view click Map options
3. Change map name and click on ok
Result: The filename in 'Save Map' view get overwritten to fit with the name given in 'Map Options'.
In this branch the filename stays at it is.
Can you also take a look at the codecheck warnings reported by travis?
kaputtnik (franku) wrote : | # |
The use of the XDG specifications looks good so far. Tested with and without an existing ~/.widelands directory. Also the option --without-xdg in the compile script. All fine here on archlinux!
:-)
Lucki (lucki1) wrote : | # |
> In this branch the filename stays at it is.
I can't verify this behavior on my end. It behaves exactly as you described: "The filename in 'Save Map' view get overwritten to fit with the name given in 'Map Options'."
Travis errors I can't solve:
* apt-get install failed
* E: Unable to locate package clang-7
Not sure why I didn't got the codecheck warnings locally…
kaputtnik (franku) wrote : | # |
You just grabbed the travis report which i didn't watched :D
The reports i mean complains about such codecheck warnings:
/home/travis/
...
See e.g.: https:/
I have to test again the thing with the filename...
kaputtnik (franku) wrote : | # |
Hm, ok, i can't reproduce the filename behavior again. Maybe i am messed up due to the hot day :-D
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 5349. State: passed. Details: https:/
Appveyor build 5119. State: success. Details: https:/
kaputtnik (franku) wrote : | # |
Great!
@bunnybot merge
GunChleoc (gunchleoc) wrote : | # |
The codecheck warnings about the CMakeLists stopped working on my machine too.
Sorry for dragging my feet on the final review.
@Lucki: How do you want to be credited, nickname only, or nick + real name?
Lucki (lucki1) wrote : | # |
Nickname, if possible also give a hug to Holarse.de
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2019-07-18 17:30:34 +0000 |
3 | +++ CMakeLists.txt 2019-08-27 19:00:46 +0000 |
4 | @@ -50,6 +50,12 @@ |
5 | option(OPTION_BUILD_TRANSLATIONS "Build translations" ON) |
6 | option(OPTION_BUILD_TESTS "Build tests" ON) |
7 | |
8 | +option(USE_XDG "Follow XDG-Basedir specification" ON) # Enabled by default |
9 | +IF(USE_XDG AND NOT APPLE AND NOT WIN32) |
10 | + ADD_DEFINITIONS(-DUSE_XDG) |
11 | + message(STATUS "Building with XDG support") |
12 | +ENDIF(USE_XDG AND NOT APPLE AND NOT WIN32) |
13 | + |
14 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
15 | message(FATAL_ERROR "Build directory and source directory must not be the same.") |
16 | endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
17 | |
18 | === modified file 'compile.sh' |
19 | --- compile.sh 2019-06-15 09:13:13 +0000 |
20 | +++ compile.sh 2019-08-27 19:00:46 +0000 |
21 | @@ -45,6 +45,8 @@ |
22 | echo " Release builds are created without AddressSanitizer" |
23 | echo " by default." |
24 | echo " " |
25 | + echo "--without-xdg Disable support for the XDG Base Directory Specification." |
26 | + echo " " |
27 | echo "Compiler options:" |
28 | echo " " |
29 | echo "-j <number> or --cores <number>" |
30 | @@ -88,6 +90,7 @@ |
31 | BUILD_TYPE="Debug" |
32 | USE_ASAN="ON" |
33 | COMPILER="default" |
34 | +USE_XDG="ON" |
35 | |
36 | if [ "$(uname)" = "Darwin" ]; then |
37 | CORES="$(expr $(sysctl -n hw.ncpu) - 1)" |
38 | @@ -154,6 +157,10 @@ |
39 | fi |
40 | shift |
41 | ;; |
42 | + --without-xdg) |
43 | + USE_XDG="OFF" |
44 | + shift |
45 | + ;; |
46 | *) |
47 | # unknown option |
48 | ;; |
49 | @@ -202,6 +209,18 @@ |
50 | else |
51 | echo "Will build without AddressSanitizer." |
52 | fi |
53 | +if [ $USE_XDG = "ON" ]; then |
54 | + echo " " |
55 | + echo "Basic XDG Base Directory Specification will be used on Linux" |
56 | + echo "if no existing \$HOME/.widelands folder is found." |
57 | + echo "The widelands user data can be found in \$XDG_DATA_HOME/widelands" |
58 | + echo "and defaults to \$HOME/.local/share/widelands." |
59 | + echo "The widelands user configuration can be found in \$XDG_CONFIG_HOME/widelands" |
60 | + echo "and defaults to \$HOME/.config/widelands." |
61 | + echo "See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html" |
62 | + echo "for more information." |
63 | + echo " " |
64 | +fi |
65 | echo " " |
66 | echo "###########################################################" |
67 | echo " " |
68 | @@ -260,9 +279,9 @@ |
69 | # Compile Widelands |
70 | compile_widelands () { |
71 | if [ $buildtool = "ninja" ] || [ $buildtool = "ninja-build" ] ; then |
72 | - cmake -G Ninja .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_BUILD_TESTS=$BUILD_TESTS -DOPTION_ASAN=$USE_ASAN |
73 | + cmake -G Ninja .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_BUILD_TESTS=$BUILD_TESTS -DOPTION_ASAN=$USE_ASAN -DUSE_XDG=$USE_XDG |
74 | else |
75 | - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_BUILD_TESTS=$BUILD_TESTS -DOPTION_ASAN=$USE_ASAN |
76 | + cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOPTION_BUILD_WEBSITE_TOOLS=$BUILD_WEBSITE -DOPTION_BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS -DOPTION_BUILD_TESTS=$BUILD_TESTS -DOPTION_ASAN=$USE_ASAN -DUSE_XDG=$USE_XDG |
77 | fi |
78 | |
79 | $buildtool -j $CORES |
80 | @@ -360,6 +379,12 @@ |
81 | echo "# - No tests #" |
82 | fi |
83 | |
84 | +if [ $USE_XDG = "ON" ]; then |
85 | + echo "# - With support for the XDG Base Directory Specification #" |
86 | +else |
87 | + echo "# - Without support for the XDG Base Directory #" |
88 | + echo "# Specification #" |
89 | +fi |
90 | if [ $BUILD_WEBSITE = "ON" ]; then |
91 | echo "# - Website-related executables #" |
92 | else |
93 | |
94 | === modified file 'src/CMakeLists.txt' |
95 | --- src/CMakeLists.txt 2019-05-27 14:28:34 +0000 |
96 | +++ src/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
97 | @@ -73,7 +73,6 @@ |
98 | add_subdirectory(map_io) |
99 | add_subdirectory(network) |
100 | add_subdirectory(notifications) |
101 | -add_subdirectory(profile) |
102 | add_subdirectory(random) |
103 | add_subdirectory(scripting) |
104 | add_subdirectory(sound) |
105 | @@ -93,6 +92,8 @@ |
106 | wlapplication.h |
107 | wlapplication_messages.cc |
108 | wlapplication_messages.h |
109 | + wlapplication_options.cc |
110 | + wlapplication_options.h |
111 | USES_SDL2 |
112 | USES_SDL2_IMAGE |
113 | USES_SDL2_TTF |
114 | @@ -108,6 +109,7 @@ |
115 | graphic_fonthandler |
116 | graphic_text |
117 | io_filesystem |
118 | + io_profile |
119 | logic |
120 | logic_exceptions |
121 | logic_filesystem_constants |
122 | @@ -117,7 +119,6 @@ |
123 | logic_single_player_game_settings |
124 | map_io_map_loader |
125 | network |
126 | - profile |
127 | random |
128 | sound |
129 | ui_basic |
130 | |
131 | === modified file 'src/editor/CMakeLists.txt' |
132 | --- src/editor/CMakeLists.txt 2019-06-01 14:16:25 +0000 |
133 | +++ src/editor/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
134 | @@ -110,12 +110,12 @@ |
135 | map_io |
136 | map_io_map_loader |
137 | notifications |
138 | - profile |
139 | random |
140 | scripting_coroutine |
141 | scripting_lua_interface |
142 | scripting_lua_table |
143 | ui_basic |
144 | + widelands_ball_of_mud |
145 | wui |
146 | wui_common_mapdetails |
147 | wui_mapview_pixelfunctions |
148 | |
149 | === modified file 'src/editor/editorinteractive.cc' |
150 | --- src/editor/editorinteractive.cc 2019-08-10 16:38:15 +0000 |
151 | +++ src/editor/editorinteractive.cc 2019-08-27 19:00:46 +0000 |
152 | @@ -67,6 +67,7 @@ |
153 | #include "scripting/lua_table.h" |
154 | #include "ui_basic/messagebox.h" |
155 | #include "ui_basic/progresswindow.h" |
156 | +#include "wlapplication_options.h" |
157 | #include "wui/game_tips.h" |
158 | #include "wui/interactive_base.h" |
159 | |
160 | @@ -82,7 +83,7 @@ |
161 | } // namespace |
162 | |
163 | EditorInteractive::EditorInteractive(Widelands::EditorGameBase& e) |
164 | - : InteractiveBase(e, g_options.pull_section("global")), |
165 | + : InteractiveBase(e, get_config_section()), |
166 | need_save_(false), |
167 | realtime_(SDL_GetTicks()), |
168 | is_painting_(false), |
169 | @@ -908,7 +909,7 @@ |
170 | egbase.world(), 64, 64, 0, |
171 | /** TRANSLATORS: Default name for new map */ |
172 | _("No Name"), |
173 | - g_options.pull_section("global").get_string( |
174 | + get_config_string( |
175 | "realname", |
176 | /** TRANSLATORS: Map author name when it hasn't been set yet */ |
177 | pgettext("author_name", "Unknown"))); |
178 | |
179 | === modified file 'src/editor/ui_menus/main_menu_map_options.cc' |
180 | --- src/editor/ui_menus/main_menu_map_options.cc 2019-08-10 16:38:15 +0000 |
181 | +++ src/editor/ui_menus/main_menu_map_options.cc 2019-08-27 19:00:46 +0000 |
182 | @@ -33,6 +33,7 @@ |
183 | #include "ui_basic/editbox.h" |
184 | #include "ui_basic/multilineeditbox.h" |
185 | #include "ui_basic/textarea.h" |
186 | +#include "wlapplication_options.h" |
187 | #include "wui/map_tags.h" |
188 | |
189 | inline EditorInteractive& MainMenuMapOptions::eia() { |
190 | @@ -194,7 +195,7 @@ |
191 | void MainMenuMapOptions::clicked_ok() { |
192 | eia().egbase().mutable_map()->set_name(name_.text()); |
193 | eia().egbase().mutable_map()->set_author(author_.text()); |
194 | - g_options.pull_section("global").set_string("realname", author_.text()); |
195 | + set_config_string("realname", author_.text()); |
196 | eia().egbase().mutable_map()->set_description(descr_->get_text()); |
197 | eia().egbase().mutable_map()->set_hint(hint_->get_text()); |
198 | |
199 | |
200 | === modified file 'src/editor/ui_menus/main_menu_new_map.cc' |
201 | --- src/editor/ui_menus/main_menu_new_map.cc 2019-06-25 08:03:30 +0000 |
202 | +++ src/editor/ui_menus/main_menu_new_map.cc 2019-08-27 19:00:46 +0000 |
203 | @@ -36,6 +36,7 @@ |
204 | #include "logic/map_objects/world/terrain_description.h" |
205 | #include "logic/map_objects/world/world.h" |
206 | #include "ui_basic/progresswindow.h" |
207 | +#include "wlapplication_options.h" |
208 | |
209 | inline EditorInteractive& MainMenuNewMap::eia() { |
210 | return dynamic_cast<EditorInteractive&>(*get_parent()); |
211 | @@ -108,7 +109,7 @@ |
212 | map->create_empty_map( |
213 | egbase.world(), map_size_box_.selected_width(), map_size_box_.selected_height(), |
214 | list_.get_selected(), _("No Name"), |
215 | - g_options.pull_section("global").get_string("realname", pgettext("author_name", "Unknown"))); |
216 | + get_config_string("realname", pgettext("author_name", "Unknown"))); |
217 | |
218 | egbase.postload(); |
219 | egbase.load_graphics(loader_ui); |
220 | |
221 | === modified file 'src/editor/ui_menus/main_menu_random_map.cc' |
222 | --- src/editor/ui_menus/main_menu_random_map.cc 2019-08-10 16:38:15 +0000 |
223 | +++ src/editor/ui_menus/main_menu_random_map.cc 2019-08-27 19:00:46 +0000 |
224 | @@ -39,6 +39,7 @@ |
225 | #include "random/random.h" |
226 | #include "ui_basic/messagebox.h" |
227 | #include "ui_basic/progresswindow.h" |
228 | +#include "wlapplication_options.h" |
229 | |
230 | namespace { |
231 | // The map generator can't find starting positions for too many players |
232 | @@ -486,7 +487,7 @@ |
233 | MapGenerator gen(*map, map_info, egbase); |
234 | map->create_empty_map( |
235 | egbase.world(), map_info.w, map_info.h, 0, _("No Name"), |
236 | - g_options.pull_section("global").get_string("realname", pgettext("author_name", "Unknown")), |
237 | + get_config_string("realname", pgettext("author_name", "Unknown")), |
238 | sstrm.str().c_str()); |
239 | loader_ui.step(_("Generating random map…")); |
240 | |
241 | |
242 | === modified file 'src/editor/ui_menus/main_menu_save_map.cc' |
243 | --- src/editor/ui_menus/main_menu_save_map.cc 2019-08-10 16:38:15 +0000 |
244 | +++ src/editor/ui_menus/main_menu_save_map.cc 2019-08-27 19:00:46 +0000 |
245 | @@ -40,6 +40,7 @@ |
246 | #include "map_io/map_saver.h" |
247 | #include "map_io/widelands_map_loader.h" |
248 | #include "ui_basic/messagebox.h" |
249 | +#include "wlapplication_options.h" |
250 | #include "wui/mapdetails.h" |
251 | #include "wui/maptable.h" |
252 | |
253 | @@ -148,7 +149,7 @@ |
254 | filename.substr(0, filename_size - 4) : |
255 | filename); |
256 | } |
257 | - if (save_map(filename, !g_options.pull_section("global").get_bool("nozip", false))) { |
258 | + if (save_map(filename, !get_config_bool("nozip", false))) { |
259 | die(); |
260 | } else { |
261 | table_.focus(); |
262 | |
263 | === modified file 'src/editor/ui_menus/player_menu.cc' |
264 | --- src/editor/ui_menus/player_menu.cc 2019-08-10 16:38:15 +0000 |
265 | +++ src/editor/ui_menus/player_menu.cc 2019-08-27 19:00:46 +0000 |
266 | @@ -32,9 +32,9 @@ |
267 | #include "logic/map.h" |
268 | #include "logic/map_objects/tribes/tribe_basic_info.h" |
269 | #include "logic/widelands.h" |
270 | -#include "profile/profile.h" |
271 | #include "ui_basic/checkbox.h" |
272 | #include "ui_basic/multilinetextarea.h" |
273 | +#include "wlapplication_options.h" |
274 | |
275 | namespace { |
276 | constexpr int kMargin = 4; |
277 | @@ -101,8 +101,7 @@ |
278 | |
279 | void write_option() { |
280 | if (reminder_choice_.get_state()) { |
281 | - g_options.pull_section("global").set_bool( |
282 | - "editor_player_menu_warn_too_many_players", false); |
283 | + set_config_bool("editor_player_menu_warn_too_many_players", false); |
284 | } |
285 | } |
286 | |
287 | @@ -255,8 +254,7 @@ |
288 | |
289 | // Display a warning if there are too many players |
290 | if (nr_players > kMaxRecommendedPlayers) { |
291 | - if (g_options.pull_section("global").get_bool( |
292 | - "editor_player_menu_warn_too_many_players", true)) { |
293 | + if (get_config_bool("editor_player_menu_warn_too_many_players", true)) { |
294 | EditorPlayerMenuWarningBox warning(get_parent()); |
295 | if (warning.run<UI::Panel::Returncodes>() == UI::Panel::Returncodes::kBack) { |
296 | // Abort setting of players |
297 | |
298 | === modified file 'src/game_io/CMakeLists.txt' |
299 | --- src/game_io/CMakeLists.txt 2019-05-05 18:53:14 +0000 |
300 | +++ src/game_io/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
301 | @@ -33,6 +33,7 @@ |
302 | graphic_minimap_renderer |
303 | io_fileread |
304 | io_filesystem |
305 | + io_profile |
306 | logic |
307 | logic_commands |
308 | logic_exceptions |
309 | @@ -42,7 +43,6 @@ |
310 | logic_widelands_geometry_io |
311 | map_io |
312 | map_io_map_loader |
313 | - profile |
314 | scripting_lua_interface |
315 | scripting_lua_table |
316 | wui |
317 | |
318 | === modified file 'src/game_io/game_preload_packet.cc' |
319 | --- src/game_io/game_preload_packet.cc 2019-02-23 11:00:49 +0000 |
320 | +++ src/game_io/game_preload_packet.cc 2019-08-27 19:00:46 +0000 |
321 | @@ -28,11 +28,11 @@ |
322 | #include "build_info.h" |
323 | #include "graphic/image_io.h" |
324 | #include "graphic/minimap_renderer.h" |
325 | +#include "io/profile.h" |
326 | #include "logic/game.h" |
327 | #include "logic/game_data_error.h" |
328 | #include "logic/map.h" |
329 | #include "logic/playersmanager.h" |
330 | -#include "profile/profile.h" |
331 | #include "scripting/lua_interface.h" |
332 | #include "scripting/lua_table.h" |
333 | #include "wui/interactive_player.h" |
334 | |
335 | === modified file 'src/io/CMakeLists.txt' |
336 | --- src/io/CMakeLists.txt 2018-05-16 13:51:48 +0000 |
337 | +++ src/io/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
338 | @@ -23,3 +23,18 @@ |
339 | io_filesystem |
340 | io_stream |
341 | ) |
342 | + |
343 | +wl_library(io_profile |
344 | + SRCS |
345 | + profile.h |
346 | + profile.cc |
347 | + DEPENDS |
348 | + base_exceptions |
349 | + base_geometry |
350 | + base_i18n |
351 | + base_log |
352 | + base_macros |
353 | + build_info |
354 | + io_fileread |
355 | + io_filesystem |
356 | + ) |
357 | |
358 | === modified file 'src/io/filesystem/filesystem.cc' |
359 | --- src/io/filesystem/filesystem.cc 2019-05-27 21:04:13 +0000 |
360 | +++ src/io/filesystem/filesystem.cc 2019-08-27 19:00:46 +0000 |
361 | @@ -312,6 +312,105 @@ |
362 | return homedir; |
363 | } |
364 | |
365 | +#ifdef USE_XDG |
366 | +/** |
367 | + * Return $XDG_DATA_HOME/widelands. Falls back to $HOME/.local/share/widelands |
368 | + * https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
369 | + * Prioritises $HOME/.widelands if it exists. |
370 | + */ |
371 | +std::string FileSystem::get_userdatadir() { |
372 | + std::string userdatadir = get_homedir(); |
373 | + |
374 | + // Use dotfolder for backwards compatibility if it exists. |
375 | + RealFSImpl dot(userdatadir); |
376 | + if (dot.is_directory(".widelands")) { |
377 | + userdatadir = userdatadir + "/.widelands"; |
378 | + } |
379 | +#ifdef HAS_GETENV |
380 | + else { |
381 | + if (char const* const datahome = getenv("XDG_DATA_HOME")) { |
382 | + userdatadir = std::string(datahome) + "/widelands"; |
383 | + } |
384 | + else { |
385 | + // If XDG_DATA_HOME is not set, the default path is used. |
386 | + userdatadir = userdatadir + "/.local/share/widelands"; |
387 | + } |
388 | + } |
389 | +#else |
390 | + else { |
391 | + // Fallback to not dump all files into the current working dir. |
392 | + userdatadir = userdatadir + "/.widelands"; |
393 | + } |
394 | +#endif |
395 | + |
396 | + // Unlike the homedir function, this function includes the program name. |
397 | + // This is handled in 'src/wlapplication.cc'. |
398 | + return userdatadir; |
399 | +} |
400 | + |
401 | +/** |
402 | + * Return $XDG_CONFIG_HOME/widelands. Falls back to $HOME/.config/widelands |
403 | + * https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
404 | + * Prioritises $HOME/.widelands if it exists. |
405 | + */ |
406 | +std::string FileSystem::get_userconfigdir() { |
407 | + std::string userconfigdir = get_homedir(); |
408 | + |
409 | + // Use dotfolder for backwards compatibility if it exists. |
410 | + RealFSImpl dot(userconfigdir); |
411 | + if (dot.is_directory(".widelands")) { |
412 | + userconfigdir = userconfigdir + "/.widelands"; |
413 | + } |
414 | +#ifdef HAS_GETENV |
415 | + else { |
416 | + if (char const* const confighome = getenv("XDG_CONFIG_HOME")) { |
417 | + userconfigdir = std::string(confighome) + "/widelands"; |
418 | + } |
419 | + else { |
420 | + // If XDG_CONFIG_HOME is not set, the default path is used. |
421 | + userconfigdir = userconfigdir + "/.config/widelands"; |
422 | + } |
423 | + } |
424 | +#else |
425 | + else { |
426 | + // Fallback to not dump all files into the current working dir. |
427 | + userconfigdir = userconfigdir + "/.widelands"; |
428 | + } |
429 | +#endif |
430 | + |
431 | + // Unlike the homedir function, this function includes the program name. |
432 | + // This is handled in 'src/wlapplication.cc'. |
433 | + return userconfigdir; |
434 | +} |
435 | + |
436 | +/** |
437 | + * Return $XDG_DATA_DIRS. Falls back to /usr/local/share:/usr/share |
438 | + * https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
439 | + */ |
440 | +std::vector<std::string> FileSystem::get_xdgdatadirs() { |
441 | + std::vector<std::string> xdgdatadirs; |
442 | + std::string environment; |
443 | +#ifdef HAS_GETENV |
444 | + environment = getenv("XDG_DATA_DIRS"); |
445 | +#endif |
446 | + if (environment.empty()) { |
447 | + environment = "/usr/local/share:/usr/share"; |
448 | + } |
449 | + |
450 | + // https://stackoverflow.com/a/14266139 |
451 | + std::string token; |
452 | + std::string delimiter = ":"; |
453 | + size_t pos = 0; |
454 | + while ((pos = environment.find(delimiter)) != std::string::npos) { |
455 | + token = environment.substr(0, pos); |
456 | + xdgdatadirs.push_back(token); |
457 | + environment.erase(0, pos + delimiter.length()); |
458 | + } |
459 | + xdgdatadirs.push_back(environment); |
460 | + return xdgdatadirs; |
461 | +} |
462 | +#endif |
463 | + |
464 | // Returning a vector rather than a set because animations need the indices |
465 | std::vector<std::string> FileSystem::get_sequential_files(const std::string& directory, |
466 | const std::string& basename, |
467 | |
468 | === modified file 'src/io/filesystem/filesystem.h' |
469 | --- src/io/filesystem/filesystem.h 2019-05-27 21:04:13 +0000 |
470 | +++ src/io/filesystem/filesystem.h 2019-08-27 19:00:46 +0000 |
471 | @@ -132,6 +132,14 @@ |
472 | static std::string filename_without_ext(const char* n); |
473 | static std::string get_homedir(); |
474 | |
475 | +#ifdef USE_XDG |
476 | + // Get XDG dirs for Linux |
477 | + // https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
478 | + static std::string get_userdatadir(); |
479 | + static std::string get_userconfigdir(); |
480 | + static std::vector<std::string> get_xdgdatadirs(); |
481 | +#endif |
482 | + |
483 | /// Return the files in the given 'directory' that match the condition in 'test', i.e. 'test' |
484 | /// returned 'true' for their filenames. |
485 | template <class UnaryPredicate> |
486 | |
487 | === renamed file 'src/profile/profile.cc' => 'src/io/profile.cc' |
488 | --- src/profile/profile.cc 2019-02-23 11:00:49 +0000 |
489 | +++ src/io/profile.cc 2019-08-27 19:00:46 +0000 |
490 | @@ -17,7 +17,7 @@ |
491 | * |
492 | */ |
493 | |
494 | -#include "profile/profile.h" |
495 | +#include "io/profile.h" |
496 | |
497 | #include <algorithm> |
498 | #include <cctype> |
499 | @@ -63,8 +63,6 @@ |
500 | /** TRANSLATORS: Needs to be consistent with the translations in widelands-console */ |
501 | _("off"), "0"}; |
502 | |
503 | -Profile g_options(Profile::err_log); |
504 | - |
505 | Section::Value::Value(const std::string& nname, const char* const nval) |
506 | : used_(false), name_(nname) { |
507 | set_string(nval); |
508 | |
509 | === renamed file 'src/profile/profile.h' => 'src/io/profile.h' |
510 | --- src/profile/profile.h 2019-02-23 11:00:49 +0000 |
511 | +++ src/io/profile.h 2019-08-27 19:00:46 +0000 |
512 | @@ -17,8 +17,8 @@ |
513 | * |
514 | */ |
515 | |
516 | -#ifndef WL_PROFILE_PROFILE_H |
517 | -#define WL_PROFILE_PROFILE_H |
518 | +#ifndef WL_IO_PROFILE_H |
519 | +#define WL_IO_PROFILE_H |
520 | |
521 | #include <cstring> |
522 | #include <memory> |
523 | @@ -31,7 +31,7 @@ |
524 | // TODO(unknown): as soon as g_fs is not needed anymore, |
525 | // include "filesystem.h" instead of layered_filesystem.h. |
526 | |
527 | -extern class Profile g_options; |
528 | +class Profile; |
529 | class FileSystem; |
530 | |
531 | /** |
532 | @@ -224,4 +224,4 @@ |
533 | DISALLOW_COPY_AND_ASSIGN(Profile); |
534 | }; |
535 | |
536 | -#endif // end of include guard: WL_PROFILE_PROFILE_H |
537 | +#endif // end of include guard: WL_IO_PROFILE_H |
538 | |
539 | === modified file 'src/logic/CMakeLists.txt' |
540 | --- src/logic/CMakeLists.txt 2019-08-09 17:29:40 +0000 |
541 | +++ src/logic/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
542 | @@ -62,8 +62,8 @@ |
543 | logic |
544 | logic_commands |
545 | logic_game_settings |
546 | - profile |
547 | ui_basic |
548 | + widelands_ball_of_mud |
549 | wui |
550 | ) |
551 | |
552 | @@ -234,6 +234,7 @@ |
553 | graphic_playercolor |
554 | io_fileread |
555 | io_filesystem |
556 | + io_profile |
557 | io_stream |
558 | logic_commands |
559 | logic_constants |
560 | @@ -250,7 +251,6 @@ |
561 | map_io_map_loader |
562 | note_sound |
563 | notifications |
564 | - profile |
565 | random |
566 | scripting_logic # TODO(GunChleoc): Circular dependency |
567 | scripting_lua_interface |
568 | @@ -258,6 +258,7 @@ |
569 | sound |
570 | sound_constants |
571 | ui_basic |
572 | + widelands_ball_of_mud |
573 | wui # TODO(GunChleoc): Circular dependency |
574 | ) |
575 | |
576 | |
577 | === modified file 'src/logic/ai_dna_handler.cc' |
578 | --- src/logic/ai_dna_handler.cc 2019-02-23 11:00:49 +0000 |
579 | +++ src/logic/ai_dna_handler.cc 2019-08-27 19:00:46 +0000 |
580 | @@ -24,8 +24,8 @@ |
581 | #include "base/time_string.h" |
582 | #include "base/wexception.h" |
583 | #include "io/filesystem/layered_filesystem.h" |
584 | +#include "io/profile.h" |
585 | #include "logic/filesystem_constants.h" |
586 | -#include "profile/profile.h" |
587 | |
588 | namespace Widelands { |
589 | |
590 | |
591 | === modified file 'src/logic/game.cc' |
592 | --- src/logic/game.cc 2019-06-28 15:05:22 +0000 |
593 | +++ src/logic/game.cc 2019-08-27 19:00:46 +0000 |
594 | @@ -66,6 +66,7 @@ |
595 | #include "scripting/lua_table.h" |
596 | #include "sound/sound_handler.h" |
597 | #include "ui_basic/progresswindow.h" |
598 | +#include "wlapplication_options.h" |
599 | #include "wui/game_tips.h" |
600 | #include "wui/interactive_player.h" |
601 | |
602 | @@ -245,7 +246,7 @@ |
603 | } |
604 | win_condition_displayname_ = "Scenario"; |
605 | |
606 | - set_ibase(new InteractivePlayer(*this, g_options.pull_section("global"), 1, false)); |
607 | + set_ibase(new InteractivePlayer(*this, get_config_section(), 1, false)); |
608 | |
609 | loader_ui.step(_("Loading map…")); |
610 | maploader->load_map_complete(*this, Widelands::MapLoader::LoadType::kScenario); |
611 | @@ -409,7 +410,7 @@ |
612 | } |
613 | loader_ui.set_background(background); |
614 | player_nr = gpdp.get_player_nr(); |
615 | - set_ibase(new InteractivePlayer(*this, g_options.pull_section("global"), player_nr, false)); |
616 | + set_ibase(new InteractivePlayer(*this, get_config_section(), player_nr, false)); |
617 | |
618 | loader_ui.step(_("Loading…")); |
619 | gl.load_game(); |
620 | |
621 | === modified file 'src/logic/save_handler.cc' |
622 | --- src/logic/save_handler.cc 2019-02-23 11:00:49 +0000 |
623 | +++ src/logic/save_handler.cc 2019-08-27 19:00:46 +0000 |
624 | @@ -37,6 +37,7 @@ |
625 | #include "logic/game.h" |
626 | #include "logic/game_controller.h" |
627 | #include "logic/generic_save_handler.h" |
628 | +#include "wlapplication_options.h" |
629 | #include "wui/interactive_base.h" |
630 | |
631 | SaveHandler::SaveHandler() |
632 | @@ -198,15 +199,13 @@ |
633 | if (initialized_) |
634 | return; |
635 | |
636 | - Section& global = g_options.pull_section("global"); |
637 | - |
638 | - fs_type_ = global.get_bool("nozip", false) ? FileSystem::DIR : FileSystem::ZIP; |
639 | - |
640 | - autosave_interval_in_ms_ = global.get_int("autosave", kDefaultAutosaveInterval * 60) * 1000; |
641 | + fs_type_ = get_config_bool("nozip", false) ? FileSystem::DIR : FileSystem::ZIP; |
642 | + |
643 | + autosave_interval_in_ms_ = get_config_int("autosave", kDefaultAutosaveInterval * 60) * 1000; |
644 | |
645 | next_save_realtime_ = realtime + autosave_interval_in_ms_; |
646 | |
647 | - number_of_rolls_ = global.get_int("rolling_autosave", 5); |
648 | + number_of_rolls_ = get_config_int("rolling_autosave", 5); |
649 | |
650 | initialized_ = true; |
651 | } |
652 | |
653 | === modified file 'src/logic/single_player_game_controller.cc' |
654 | --- src/logic/single_player_game_controller.cc 2019-05-01 07:20:25 +0000 |
655 | +++ src/logic/single_player_game_controller.cc 2019-08-27 19:00:46 +0000 |
656 | @@ -24,7 +24,7 @@ |
657 | #include "logic/player.h" |
658 | #include "logic/playercommand.h" |
659 | #include "logic/playersmanager.h" |
660 | -#include "profile/profile.h" |
661 | +#include "wlapplication_options.h" |
662 | |
663 | SinglePlayerGameController::SinglePlayerGameController(Widelands::Game& game, |
664 | bool const useai, |
665 | @@ -33,7 +33,7 @@ |
666 | use_ai_(useai), |
667 | lastframe_(SDL_GetTicks()), |
668 | time_(game_.get_gametime()), |
669 | - speed_(g_options.pull_section("global").get_natural("speed_of_new_game", 1000)), |
670 | + speed_(get_config_natural("speed_of_new_game", 1000)), |
671 | paused_(false), |
672 | player_cmdserial_(0), |
673 | local_(local) { |
674 | |
675 | === modified file 'src/map_io/CMakeLists.txt' |
676 | --- src/map_io/CMakeLists.txt 2019-05-26 01:45:17 +0000 |
677 | +++ src/map_io/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
678 | @@ -105,6 +105,7 @@ |
679 | graphic_surface |
680 | io_fileread |
681 | io_filesystem |
682 | + io_profile |
683 | logic |
684 | logic_constants |
685 | logic_exceptions |
686 | @@ -113,6 +114,5 @@ |
687 | logic_objectives |
688 | logic_widelands_geometry |
689 | logic_widelands_geometry_io |
690 | - profile |
691 | scripting_logic |
692 | ) |
693 | |
694 | === modified file 'src/map_io/coords_profile.cc' |
695 | --- src/map_io/coords_profile.cc 2019-02-23 11:00:49 +0000 |
696 | +++ src/map_io/coords_profile.cc 2019-08-27 19:00:46 +0000 |
697 | @@ -25,8 +25,8 @@ |
698 | #include <string> |
699 | |
700 | #include "base/wexception.h" |
701 | +#include "io/profile.h" |
702 | #include "logic/widelands_geometry.h" |
703 | -#include "profile/profile.h" |
704 | |
705 | namespace Widelands { |
706 | |
707 | |
708 | === modified file 'src/map_io/map_allowed_building_types_packet.cc' |
709 | --- src/map_io/map_allowed_building_types_packet.cc 2019-02-23 11:00:49 +0000 |
710 | +++ src/map_io/map_allowed_building_types_packet.cc 2019-08-27 19:00:46 +0000 |
711 | @@ -22,11 +22,11 @@ |
712 | #include <boost/format.hpp> |
713 | |
714 | #include "base/macros.h" |
715 | +#include "io/profile.h" |
716 | #include "logic/game.h" |
717 | #include "logic/game_data_error.h" |
718 | #include "logic/map_objects/tribes/tribe_descr.h" |
719 | #include "logic/player.h" |
720 | -#include "profile/profile.h" |
721 | |
722 | namespace Widelands { |
723 | |
724 | |
725 | === modified file 'src/map_io/map_allowed_worker_types_packet.cc' |
726 | --- src/map_io/map_allowed_worker_types_packet.cc 2019-02-23 11:00:49 +0000 |
727 | +++ src/map_io/map_allowed_worker_types_packet.cc 2019-08-27 19:00:46 +0000 |
728 | @@ -22,11 +22,11 @@ |
729 | #include <boost/format.hpp> |
730 | |
731 | #include "base/macros.h" |
732 | +#include "io/profile.h" |
733 | #include "logic/game.h" |
734 | #include "logic/game_data_error.h" |
735 | #include "logic/map_objects/tribes/tribe_descr.h" |
736 | #include "logic/player.h" |
737 | -#include "profile/profile.h" |
738 | |
739 | namespace Widelands { |
740 | |
741 | |
742 | === modified file 'src/map_io/map_elemental_packet.cc' |
743 | --- src/map_io/map_elemental_packet.cc 2019-02-27 19:00:36 +0000 |
744 | +++ src/map_io/map_elemental_packet.cc 2019-08-27 19:00:46 +0000 |
745 | @@ -22,10 +22,10 @@ |
746 | #include <boost/algorithm/string.hpp> |
747 | #include <boost/format.hpp> |
748 | |
749 | +#include "io/profile.h" |
750 | #include "logic/editor_game_base.h" |
751 | #include "logic/game_data_error.h" |
752 | #include "logic/map.h" |
753 | -#include "profile/profile.h" |
754 | |
755 | namespace Widelands { |
756 | |
757 | |
758 | === modified file 'src/map_io/map_objective_packet.cc' |
759 | --- src/map_io/map_objective_packet.cc 2019-02-23 11:00:49 +0000 |
760 | +++ src/map_io/map_objective_packet.cc 2019-08-27 19:00:46 +0000 |
761 | @@ -21,11 +21,11 @@ |
762 | |
763 | #include <memory> |
764 | |
765 | +#include "io/profile.h" |
766 | #include "logic/editor_game_base.h" |
767 | #include "logic/game_data_error.h" |
768 | #include "logic/map.h" |
769 | #include "logic/objective.h" |
770 | -#include "profile/profile.h" |
771 | |
772 | namespace Widelands { |
773 | |
774 | |
775 | === modified file 'src/map_io/map_player_names_and_tribes_packet.cc' |
776 | --- src/map_io/map_player_names_and_tribes_packet.cc 2019-02-27 19:00:36 +0000 |
777 | +++ src/map_io/map_player_names_and_tribes_packet.cc 2019-08-27 19:00:46 +0000 |
778 | @@ -22,11 +22,11 @@ |
779 | #include <boost/algorithm/string/trim.hpp> |
780 | #include <boost/format.hpp> |
781 | |
782 | +#include "io/profile.h" |
783 | #include "logic/editor_game_base.h" |
784 | #include "logic/game_data_error.h" |
785 | #include "logic/map.h" |
786 | #include "logic/map_objects/world/world.h" |
787 | -#include "profile/profile.h" |
788 | |
789 | namespace Widelands { |
790 | |
791 | |
792 | === modified file 'src/map_io/map_player_position_packet.cc' |
793 | --- src/map_io/map_player_position_packet.cc 2019-02-27 19:00:36 +0000 |
794 | +++ src/map_io/map_player_position_packet.cc 2019-08-27 19:00:46 +0000 |
795 | @@ -21,11 +21,11 @@ |
796 | |
797 | #include <boost/format.hpp> |
798 | |
799 | +#include "io/profile.h" |
800 | #include "logic/editor_game_base.h" |
801 | #include "logic/game_data_error.h" |
802 | #include "logic/map.h" |
803 | #include "map_io/coords_profile.h" |
804 | -#include "profile/profile.h" |
805 | |
806 | namespace Widelands { |
807 | |
808 | |
809 | === modified file 'src/map_io/map_players_messages_packet.cc' |
810 | --- src/map_io/map_players_messages_packet.cc 2019-02-23 11:00:49 +0000 |
811 | +++ src/map_io/map_players_messages_packet.cc 2019-08-27 19:00:46 +0000 |
812 | @@ -23,13 +23,13 @@ |
813 | |
814 | #include <boost/format.hpp> |
815 | |
816 | +#include "io/profile.h" |
817 | #include "logic/game_data_error.h" |
818 | #include "logic/message.h" |
819 | #include "logic/player.h" |
820 | #include "map_io/coords_profile.h" |
821 | #include "map_io/map_object_loader.h" |
822 | #include "map_io/map_object_saver.h" |
823 | -#include "profile/profile.h" |
824 | |
825 | namespace Widelands { |
826 | |
827 | |
828 | === modified file 'src/map_io/map_port_spaces_packet.cc' |
829 | --- src/map_io/map_port_spaces_packet.cc 2019-03-24 13:13:34 +0000 |
830 | +++ src/map_io/map_port_spaces_packet.cc 2019-08-27 19:00:46 +0000 |
831 | @@ -24,11 +24,11 @@ |
832 | #include <boost/algorithm/string.hpp> |
833 | |
834 | #include "base/log.h" |
835 | +#include "io/profile.h" |
836 | #include "logic/editor_game_base.h" |
837 | #include "logic/game_data_error.h" |
838 | #include "logic/map.h" |
839 | #include "map_io/coords_profile.h" |
840 | -#include "profile/profile.h" |
841 | |
842 | namespace Widelands { |
843 | |
844 | |
845 | === modified file 'src/map_io/map_version_packet.cc' |
846 | --- src/map_io/map_version_packet.cc 2019-06-23 10:30:26 +0000 |
847 | +++ src/map_io/map_version_packet.cc 2019-08-27 19:00:46 +0000 |
848 | @@ -22,10 +22,10 @@ |
849 | #include "build_info.h" |
850 | #include "io/fileread.h" |
851 | #include "io/filewrite.h" |
852 | +#include "io/profile.h" |
853 | #include "logic/editor_game_base.h" |
854 | #include "logic/game_data_error.h" |
855 | #include "logic/map.h" |
856 | -#include "profile/profile.h" |
857 | |
858 | namespace Widelands { |
859 | |
860 | |
861 | === modified file 'src/network/CMakeLists.txt' |
862 | --- src/network/CMakeLists.txt 2019-05-04 15:37:33 +0000 |
863 | +++ src/network/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
864 | @@ -55,7 +55,6 @@ |
865 | logic_game_settings |
866 | logic_tribe_basic_info |
867 | map_io_map_loader |
868 | - profile |
869 | random |
870 | scripting_lua_interface |
871 | scripting_lua_table |
872 | |
873 | === modified file 'src/network/gameclient.cc' |
874 | --- src/network/gameclient.cc 2019-06-24 21:59:24 +0000 |
875 | +++ src/network/gameclient.cc 2019-08-27 19:00:46 +0000 |
876 | @@ -53,6 +53,7 @@ |
877 | #include "ui_basic/progresswindow.h" |
878 | #include "ui_fsmenu/launch_mpg.h" |
879 | #include "wlapplication.h" |
880 | +#include "wlapplication_options.h" |
881 | #include "wui/game_tips.h" |
882 | #include "wui/interactive_player.h" |
883 | #include "wui/interactive_spectator.h" |
884 | @@ -163,9 +164,9 @@ |
885 | (boost::format("%s_netclient%u") % kAutosavePrefix % static_cast<unsigned int>(pn)).str()); |
886 | InteractiveGameBase* igb; |
887 | if (pn > 0) { |
888 | - igb = new InteractivePlayer(*game, g_options.pull_section("global"), pn, true); |
889 | + igb = new InteractivePlayer(*game, get_config_section(), pn, true); |
890 | } else { |
891 | - igb = new InteractiveSpectator(*game, g_options.pull_section("global"), true); |
892 | + igb = new InteractiveSpectator(*game, get_config_section(), true); |
893 | } |
894 | game->set_ibase(igb); |
895 | igb->set_chat_provider(*parent); |
896 | @@ -264,9 +265,8 @@ |
897 | |
898 | d->server_is_waiting = true; |
899 | |
900 | - bool write_sync_streams = g_options.pull_section("global").get_bool("write_syncstreams", true); |
901 | Widelands::Game game; |
902 | - game.set_write_syncstream(write_sync_streams); |
903 | + game.set_write_syncstream(get_config_bool("write_syncstreams", true)); |
904 | |
905 | try { |
906 | std::unique_ptr<UI::ProgressWindow> loader_ui(new UI::ProgressWindow()); |
907 | |
908 | === modified file 'src/network/gamehost.cc' |
909 | --- src/network/gamehost.cc 2019-06-24 21:59:24 +0000 |
910 | +++ src/network/gamehost.cc 2019-08-27 19:00:46 +0000 |
911 | @@ -58,11 +58,11 @@ |
912 | #include "network/network_lan_promotion.h" |
913 | #include "network/network_player_settings_backend.h" |
914 | #include "network/network_protocol.h" |
915 | -#include "profile/profile.h" |
916 | #include "scripting/lua_interface.h" |
917 | #include "ui_basic/progresswindow.h" |
918 | #include "ui_fsmenu/launch_mpg.h" |
919 | #include "wlapplication.h" |
920 | +#include "wlapplication_options.h" |
921 | #include "wui/game_tips.h" |
922 | #include "wui/interactive_player.h" |
923 | #include "wui/interactive_spectator.h" |
924 | @@ -632,9 +632,9 @@ |
925 | broadcast(packet); |
926 | |
927 | Widelands::Game game; |
928 | - game.set_ai_training_mode(g_options.pull_section("global").get_bool("ai_training", false)); |
929 | - game.set_auto_speed(g_options.pull_section("global").get_bool("auto_speed", false)); |
930 | - game.set_write_syncstream(g_options.pull_section("global").get_bool("write_syncstreams", true)); |
931 | + game.set_ai_training_mode(get_config_bool("ai_training", false)); |
932 | + game.set_auto_speed(get_config_bool("auto_speed", false)); |
933 | + game.set_write_syncstream(get_config_bool("write_syncstreams", true)); |
934 | |
935 | try { |
936 | std::unique_ptr<UI::ProgressWindow> loader_ui; |
937 | @@ -668,9 +668,9 @@ |
938 | } |
939 | |
940 | if ((pn > 0) && (pn <= UserSettings::highest_playernum())) { |
941 | - igb = new InteractivePlayer(game, g_options.pull_section("global"), pn, true); |
942 | + igb = new InteractivePlayer(game, get_config_section(), pn, true); |
943 | } else { |
944 | - igb = new InteractiveSpectator(game, g_options.pull_section("global"), true); |
945 | + igb = new InteractiveSpectator(game, get_config_section(), true); |
946 | } |
947 | igb->set_chat_provider(d->chat); |
948 | game.set_ibase(igb); |
949 | |
950 | === removed directory 'src/profile' |
951 | === removed file 'src/profile/CMakeLists.txt' |
952 | --- src/profile/CMakeLists.txt 2015-11-28 22:29:26 +0000 |
953 | +++ src/profile/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
954 | @@ -1,14 +0,0 @@ |
955 | -wl_library(profile |
956 | - SRCS |
957 | - profile.h |
958 | - profile.cc |
959 | - DEPENDS |
960 | - base_exceptions |
961 | - base_geometry |
962 | - base_i18n |
963 | - base_log |
964 | - base_macros |
965 | - build_info |
966 | - io_fileread |
967 | - io_filesystem |
968 | - ) |
969 | |
970 | === modified file 'src/scripting/CMakeLists.txt' |
971 | --- src/scripting/CMakeLists.txt 2019-05-05 18:53:14 +0000 |
972 | +++ src/scripting/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
973 | @@ -108,6 +108,7 @@ |
974 | economy |
975 | io_fileread |
976 | io_filesystem |
977 | + io_profile |
978 | logic |
979 | logic_commands |
980 | logic_constants |
981 | @@ -120,7 +121,6 @@ |
982 | logic_tribe_basic_info |
983 | logic_widelands_geometry |
984 | map_io |
985 | - profile |
986 | scripting_base |
987 | scripting_coroutine |
988 | scripting_errors |
989 | @@ -129,6 +129,7 @@ |
990 | scripting_luna |
991 | third_party_eris |
992 | ui_basic |
993 | + widelands_ball_of_mud |
994 | wui |
995 | wui_mapview_pixelfunctions |
996 | ) |
997 | |
998 | === modified file 'src/scripting/lua_bases.cc' |
999 | --- src/scripting/lua_bases.cc 2019-04-09 16:43:49 +0000 |
1000 | +++ src/scripting/lua_bases.cc 2019-08-27 19:00:46 +0000 |
1001 | @@ -24,6 +24,7 @@ |
1002 | |
1003 | #include "economy/economy.h" |
1004 | #include "io/filesystem/layered_filesystem.h" |
1005 | +#include "io/profile.h" |
1006 | #include "logic/filesystem_constants.h" |
1007 | #include "logic/map_objects/checkstep.h" |
1008 | #include "logic/map_objects/tribes/tribe_descr.h" |
1009 | @@ -31,7 +32,6 @@ |
1010 | #include "logic/map_objects/tribes/ware_descr.h" |
1011 | #include "logic/map_objects/world/world.h" |
1012 | #include "logic/player.h" |
1013 | -#include "profile/profile.h" |
1014 | #include "scripting/factory.h" |
1015 | #include "scripting/globals.h" |
1016 | #include "scripting/lua_map.h" |
1017 | |
1018 | === modified file 'src/scripting/lua_game.cc' |
1019 | --- src/scripting/lua_game.cc 2019-08-10 16:38:15 +0000 |
1020 | +++ src/scripting/lua_game.cc 2019-08-27 19:00:46 +0000 |
1021 | @@ -37,6 +37,7 @@ |
1022 | #include "scripting/globals.h" |
1023 | #include "scripting/lua_interface.h" |
1024 | #include "scripting/lua_map.h" |
1025 | +#include "wlapplication_options.h" |
1026 | #include "wui/interactive_player.h" |
1027 | #include "wui/story_message_box.h" |
1028 | |
1029 | @@ -1069,7 +1070,7 @@ |
1030 | Objective& o = get(L, get_game(L)); |
1031 | o.set_done(luaL_checkboolean(L, -1)); |
1032 | |
1033 | - const int32_t autosave = g_options.pull_section("global").get_int("autosave", 0); |
1034 | + const int32_t autosave = get_config_int("autosave", 0); |
1035 | if (autosave <= 0) { |
1036 | return 0; |
1037 | } |
1038 | |
1039 | === modified file 'src/sound/CMakeLists.txt' |
1040 | --- src/sound/CMakeLists.txt 2019-04-08 13:32:28 +0000 |
1041 | +++ src/sound/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
1042 | @@ -32,7 +32,7 @@ |
1043 | io_fileread |
1044 | io_filesystem |
1045 | logic_exceptions |
1046 | - profile |
1047 | random |
1048 | sound_constants |
1049 | + widelands_ball_of_mud |
1050 | ) |
1051 | |
1052 | === modified file 'src/sound/sound_handler.cc' |
1053 | --- src/sound/sound_handler.cc 2019-05-12 12:08:33 +0000 |
1054 | +++ src/sound/sound_handler.cc 2019-08-27 19:00:46 +0000 |
1055 | @@ -30,7 +30,7 @@ |
1056 | |
1057 | #include "base/i18n.h" |
1058 | #include "base/log.h" |
1059 | -#include "profile/profile.h" |
1060 | +#include "wlapplication_options.h" |
1061 | |
1062 | namespace { |
1063 | constexpr int kDefaultMusicVolume = 64; |
1064 | @@ -190,28 +190,26 @@ |
1065 | } |
1066 | |
1067 | /** |
1068 | - * Load the sound options from g_options. If an option is not available, use the defaults set by the |
1069 | + * Load the sound options from cached config. If an option is not available, use the defaults set by the |
1070 | * constructor. |
1071 | */ |
1072 | void SoundHandler::read_config() { |
1073 | // TODO(GunChleoc): Compatibility code to avoid getting bug reports about unread sections. Remove |
1074 | // after Build 21. |
1075 | - if (g_options.get_section("sound") == nullptr) { |
1076 | - Section& global = g_options.pull_section("global"); |
1077 | - |
1078 | + if (get_config_section_ptr("sound") == nullptr) { |
1079 | for (auto& option : sound_options_) { |
1080 | switch (option.first) { |
1081 | case SoundType::kMusic: |
1082 | - option.second.volume = global.get_int("music_volume", option.second.volume); |
1083 | - option.second.enabled = !global.get_bool("disable_music", !option.second.enabled); |
1084 | + option.second.volume = get_config_int("music_volume", option.second.volume); |
1085 | + option.second.enabled = !get_config_bool("disable_music", !option.second.enabled); |
1086 | break; |
1087 | case SoundType::kChat: |
1088 | - option.second.volume = global.get_int("fx_volume", option.second.volume); |
1089 | - option.second.enabled = global.get_bool("sound_at_message", option.second.enabled); |
1090 | + option.second.volume = get_config_int("fx_volume", option.second.volume); |
1091 | + option.second.enabled = get_config_bool("sound_at_message", option.second.enabled); |
1092 | break; |
1093 | default: |
1094 | - option.second.volume = global.get_int("fx_volume", option.second.volume); |
1095 | - option.second.enabled = !global.get_bool("disable_fx", !option.second.enabled); |
1096 | + option.second.volume = get_config_int("fx_volume", option.second.volume); |
1097 | + option.second.enabled = !get_config_bool("disable_fx", !option.second.enabled); |
1098 | break; |
1099 | } |
1100 | } |
1101 | @@ -219,32 +217,30 @@ |
1102 | } |
1103 | |
1104 | // This is the code that we want to keep |
1105 | - Section& sound = g_options.pull_section("sound"); |
1106 | for (auto& option : sound_options_) { |
1107 | option.second.volume = |
1108 | - sound.get_int(("volume_" + option.second.name).c_str(), option.second.volume); |
1109 | + get_config_int("sound", ("volume_" + option.second.name).c_str(), option.second.volume); |
1110 | option.second.enabled = |
1111 | - sound.get_bool(("enable_" + option.second.name).c_str(), option.second.enabled); |
1112 | + get_config_bool("sound", ("enable_" + option.second.name).c_str(), option.second.enabled); |
1113 | } |
1114 | } |
1115 | |
1116 | -/// Save the current sound options to g_options |
1117 | +/// Save the current sound options to config cache |
1118 | void SoundHandler::save_config() { |
1119 | - Section& sound = g_options.pull_section("sound"); |
1120 | for (auto& option : sound_options_) { |
1121 | const int volume = option.second.volume; |
1122 | const std::string& name = option.second.name; |
1123 | const bool enabled = option.second.enabled; |
1124 | |
1125 | const std::string enable_name = "enable_" + name; |
1126 | - sound.set_bool(enable_name.c_str(), enabled); |
1127 | + set_config_bool("sound", enable_name.c_str(), enabled); |
1128 | |
1129 | const std::string volume_name = "volume_" + name; |
1130 | - sound.set_int(volume_name.c_str(), volume); |
1131 | + set_config_int("sound", volume_name.c_str(), volume); |
1132 | } |
1133 | } |
1134 | |
1135 | -/// Read the sound options from g_options and apply them |
1136 | +/// Read the sound options from the cache and apply them |
1137 | void SoundHandler::load_config() { |
1138 | read_config(); |
1139 | for (auto& option : sound_options_) { |
1140 | |
1141 | === modified file 'src/ui_basic/CMakeLists.txt' |
1142 | --- src/ui_basic/CMakeLists.txt 2019-05-03 19:24:19 +0000 |
1143 | +++ src/ui_basic/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
1144 | @@ -71,7 +71,6 @@ |
1145 | graphic_wordwrap |
1146 | io_filesystem |
1147 | notifications |
1148 | - profile |
1149 | scripting_lua_interface |
1150 | scripting_lua_table |
1151 | sound |
1152 | |
1153 | === modified file 'src/ui_basic/panel.cc' |
1154 | --- src/ui_basic/panel.cc 2019-07-28 08:46:47 +0000 |
1155 | +++ src/ui_basic/panel.cc 2019-08-27 19:00:46 +0000 |
1156 | @@ -25,9 +25,9 @@ |
1157 | #include "graphic/rendertarget.h" |
1158 | #include "graphic/text/font_set.h" |
1159 | #include "graphic/text_layout.h" |
1160 | -#include "profile/profile.h" |
1161 | #include "sound/sound_handler.h" |
1162 | #include "wlapplication.h" |
1163 | +#include "wlapplication_options.h" |
1164 | |
1165 | namespace UI { |
1166 | |
1167 | @@ -165,7 +165,7 @@ |
1168 | |
1169 | // With the default of 30FPS, the game will be drawn every 33ms. |
1170 | const uint32_t draw_delay = |
1171 | - 1000 / std::max(5, g_options.pull_section("global").get_int("maxfps", 30)); |
1172 | + 1000 / std::max(5, get_config_int("maxfps", 30)); |
1173 | |
1174 | static InputCallback input_callback = {Panel::ui_mousepress, Panel::ui_mouserelease, |
1175 | Panel::ui_mousemove, Panel::ui_key, |
1176 | |
1177 | === modified file 'src/ui_fsmenu/CMakeLists.txt' |
1178 | --- src/ui_fsmenu/CMakeLists.txt 2019-05-26 01:58:59 +0000 |
1179 | +++ src/ui_fsmenu/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
1180 | @@ -17,7 +17,6 @@ |
1181 | scripting_lua_table |
1182 | ui_basic |
1183 | ui_fsmenu_base |
1184 | - profile |
1185 | sound |
1186 | widelands_ball_of_mud |
1187 | wui_sound_options |
1188 | @@ -77,12 +76,12 @@ |
1189 | base_i18n |
1190 | graphic |
1191 | io_filesystem |
1192 | - profile |
1193 | network |
1194 | random |
1195 | ui_basic |
1196 | ui_fsmenu_base |
1197 | ui_fsmenu_main_menu |
1198 | + widelands_ball_of_mud |
1199 | wui_common_mapdetails |
1200 | wui |
1201 | ) |
1202 | @@ -104,6 +103,7 @@ |
1203 | graphic_playercolor |
1204 | helper |
1205 | io_filesystem |
1206 | + io_profile |
1207 | logic |
1208 | logic_game_controller |
1209 | logic_game_settings |
1210 | @@ -111,7 +111,6 @@ |
1211 | logic_map_objects |
1212 | logic_tribe_basic_info |
1213 | map_io_map_loader |
1214 | - profile |
1215 | scripting_lua_interface |
1216 | scripting_lua_table |
1217 | ui_basic |
1218 | @@ -119,6 +118,7 @@ |
1219 | ui_fsmenu_helpwindow |
1220 | ui_fsmenu_loading_common |
1221 | ui_fsmenu_maploading |
1222 | + widelands_ball_of_mud |
1223 | wui |
1224 | wui_chat_ui |
1225 | wui_common_gamedetails |
1226 | @@ -147,12 +147,12 @@ |
1227 | graphic_fonthandler |
1228 | graphic_surface |
1229 | io_filesystem |
1230 | + io_profile |
1231 | logic_filesystem_constants |
1232 | logic_game_controller |
1233 | logic_game_settings |
1234 | logic_tribe_basic_info |
1235 | map_io_map_loader |
1236 | - profile |
1237 | scripting_lua_interface |
1238 | scripting_lua_table |
1239 | ui_basic |
1240 | @@ -173,11 +173,11 @@ |
1241 | base_macros |
1242 | graphic |
1243 | network |
1244 | - profile |
1245 | random |
1246 | sound |
1247 | ui_basic |
1248 | ui_fsmenu_base |
1249 | + widelands_ball_of_mud |
1250 | wui_chat_ui |
1251 | ) |
1252 | |
1253 | |
1254 | === modified file 'src/ui_fsmenu/campaign_select.cc' |
1255 | --- src/ui_fsmenu/campaign_select.cc 2019-05-26 17:21:15 +0000 |
1256 | +++ src/ui_fsmenu/campaign_select.cc 2019-08-27 19:00:46 +0000 |
1257 | @@ -27,7 +27,6 @@ |
1258 | #include "base/wexception.h" |
1259 | #include "graphic/graphic.h" |
1260 | #include "logic/filesystem_constants.h" |
1261 | -#include "profile/profile.h" |
1262 | #include "scripting/lua_interface.h" |
1263 | #include "scripting/lua_table.h" |
1264 | |
1265 | |
1266 | === modified file 'src/ui_fsmenu/campaigns.cc' |
1267 | --- src/ui_fsmenu/campaigns.cc 2019-07-31 16:33:35 +0000 |
1268 | +++ src/ui_fsmenu/campaigns.cc 2019-08-27 19:00:46 +0000 |
1269 | @@ -25,9 +25,9 @@ |
1270 | #include "base/log.h" |
1271 | #include "graphic/graphic.h" |
1272 | #include "io/filesystem/filesystem.h" |
1273 | +#include "io/profile.h" |
1274 | #include "logic/filesystem_constants.h" |
1275 | #include "logic/map_objects/tribes/tribe_basic_info.h" |
1276 | -#include "profile/profile.h" |
1277 | #include "scripting/lua_interface.h" |
1278 | |
1279 | namespace { |
1280 | |
1281 | === modified file 'src/ui_fsmenu/internet_lobby.cc' |
1282 | --- src/ui_fsmenu/internet_lobby.cc 2019-08-10 16:38:15 +0000 |
1283 | +++ src/ui_fsmenu/internet_lobby.cc 2019-08-27 19:00:46 +0000 |
1284 | @@ -30,10 +30,10 @@ |
1285 | #include "network/gameclient.h" |
1286 | #include "network/gamehost.h" |
1287 | #include "network/internet_gaming.h" |
1288 | -#include "profile/profile.h" |
1289 | #include "random/random.h" |
1290 | #include "sound/sound_handler.h" |
1291 | #include "ui_basic/messagebox.h" |
1292 | +#include "wlapplication_options.h" |
1293 | |
1294 | namespace { |
1295 | |
1296 | @@ -128,15 +128,13 @@ |
1297 | boost::bind(&FullscreenMenuInternetLobby::clicked_back, boost::ref(*this))); |
1298 | |
1299 | // Set the texts and style of UI elements |
1300 | - Section& s = g_options.pull_section("global"); // for playername |
1301 | - |
1302 | title.set_font_scale(scale_factor()); |
1303 | |
1304 | opengames_.set_font_scale(scale_factor()); |
1305 | clients_.set_font_scale(scale_factor()); |
1306 | servername_.set_font_scale(scale_factor()); |
1307 | |
1308 | - std::string server = s.get_string("servername", ""); |
1309 | + std::string server = get_config_string("servername", ""); |
1310 | edit_servername_.set_font_scale(scale_factor()); |
1311 | edit_servername_.set_text(server); |
1312 | edit_servername_.changed.connect( |
1313 | @@ -222,10 +220,9 @@ |
1314 | |
1315 | /// connects Widelands with the metaserver |
1316 | void FullscreenMenuInternetLobby::connect_to_metaserver() { |
1317 | - Section& s = g_options.pull_section("global"); |
1318 | - const std::string& metaserver = s.get_string("metaserver", INTERNET_GAMING_METASERVER.c_str()); |
1319 | - uint32_t port = s.get_natural("metaserverport", kInternetGamingPort); |
1320 | - std::string auth = is_registered_ ? password_ : s.get_string("uuid"); |
1321 | + const std::string& metaserver = get_config_string("metaserver", INTERNET_GAMING_METASERVER.c_str()); |
1322 | + uint32_t port = get_config_natural("metaserverport", kInternetGamingPort); |
1323 | + std::string auth = is_registered_ ? password_ : get_config_string("uuid", nullptr); |
1324 | assert(!auth.empty()); |
1325 | InternetGaming::ref().login(nickname_, auth, is_registered_, metaserver, port); |
1326 | } |
1327 | @@ -451,7 +448,7 @@ |
1328 | } |
1329 | } |
1330 | |
1331 | - g_options.pull_section("global").set_string("servername", servername_ui); |
1332 | + set_config_string("servername", servername_ui); |
1333 | |
1334 | // Set up the game |
1335 | InternetGaming::ref().set_local_servername(servername_ui); |
1336 | |
1337 | === modified file 'src/ui_fsmenu/launch_mpg.cc' |
1338 | --- src/ui_fsmenu/launch_mpg.cc 2019-05-28 17:01:30 +0000 |
1339 | +++ src/ui_fsmenu/launch_mpg.cc 2019-08-27 19:00:46 +0000 |
1340 | @@ -28,6 +28,7 @@ |
1341 | #include "graphic/graphic.h" |
1342 | #include "graphic/playercolor.h" |
1343 | #include "io/filesystem/layered_filesystem.h" |
1344 | +#include "io/profile.h" |
1345 | #include "logic/game.h" |
1346 | #include "logic/game_controller.h" |
1347 | #include "logic/game_settings.h" |
1348 | @@ -36,7 +37,6 @@ |
1349 | #include "logic/map_objects/tribes/tribe_basic_info.h" |
1350 | #include "logic/player.h" |
1351 | #include "map_io/map_loader.h" |
1352 | -#include "profile/profile.h" |
1353 | #include "scripting/lua_interface.h" |
1354 | #include "scripting/lua_table.h" |
1355 | #include "ui_basic/messagebox.h" |
1356 | |
1357 | === modified file 'src/ui_fsmenu/loadgame.cc' |
1358 | --- src/ui_fsmenu/loadgame.cc 2019-05-26 17:21:15 +0000 |
1359 | +++ src/ui_fsmenu/loadgame.cc 2019-08-27 19:00:46 +0000 |
1360 | @@ -22,7 +22,7 @@ |
1361 | #include <memory> |
1362 | |
1363 | #include "base/i18n.h" |
1364 | -#include "profile/profile.h" |
1365 | +#include "wlapplication_options.h" |
1366 | #include "wui/gamedetails.h" |
1367 | |
1368 | FullscreenMenuLoadGame::FullscreenMenuLoadGame(Widelands::Game& g, |
1369 | @@ -101,8 +101,7 @@ |
1370 | if (is_replay_) { |
1371 | show_filenames_->changed.connect( |
1372 | boost::bind(&FullscreenMenuLoadGame::toggle_filenames, boost::ref(*this))); |
1373 | - show_filenames_->set_state( |
1374 | - g_options.pull_section("global").get_bool("display_replay_filenames", true)); |
1375 | + show_filenames_->set_state(get_config_bool("display_replay_filenames", true)); |
1376 | } |
1377 | |
1378 | fill_table(); |
1379 | @@ -125,7 +124,7 @@ |
1380 | |
1381 | void FullscreenMenuLoadGame::toggle_filenames() { |
1382 | showing_filenames_ = show_filenames_->get_state(); |
1383 | - g_options.pull_section("global").set_bool("display_replay_filenames", showing_filenames_); |
1384 | + set_config_bool("display_replay_filenames", showing_filenames_); |
1385 | |
1386 | // Remember selection |
1387 | const std::set<uint32_t> selected = load_or_save_.table().selections(); |
1388 | |
1389 | === modified file 'src/ui_fsmenu/multiplayer.cc' |
1390 | --- src/ui_fsmenu/multiplayer.cc 2019-05-26 17:21:15 +0000 |
1391 | +++ src/ui_fsmenu/multiplayer.cc 2019-08-27 19:00:46 +0000 |
1392 | @@ -22,9 +22,9 @@ |
1393 | #include "base/i18n.h" |
1394 | #include "graphic/graphic.h" |
1395 | #include "network/internet_gaming.h" |
1396 | -#include "profile/profile.h" |
1397 | #include "random/random.h" |
1398 | #include "ui_basic/messagebox.h" |
1399 | +#include "wlapplication_options.h" |
1400 | #include "wui/login_box.h" |
1401 | |
1402 | FullscreenMenuMultiPlayer::FullscreenMenuMultiPlayer() |
1403 | @@ -96,11 +96,9 @@ |
1404 | * This fullscreen menu ends it's modality. |
1405 | */ |
1406 | void FullscreenMenuMultiPlayer::internet_login() { |
1407 | - Section& s = g_options.pull_section("global"); |
1408 | - |
1409 | - nickname_ = s.get_string("nickname", ""); |
1410 | - password_ = s.get_string("password_sha1", "no_password_set"); |
1411 | - register_ = s.get_bool("registered", false); |
1412 | + nickname_ = get_config_string("nickname", ""); |
1413 | + password_ = get_config_string("password_sha1", "no_password_set"); |
1414 | + register_ = get_config_bool("registered", false); |
1415 | |
1416 | // Checks can be done directly in editbox' by using valid_username(). |
1417 | // This is just to be on the safe side, in case the user changed the password in the config file. |
1418 | @@ -111,9 +109,9 @@ |
1419 | } |
1420 | |
1421 | // Try to connect to the metaserver |
1422 | - const std::string& meta = s.get_string("metaserver", INTERNET_GAMING_METASERVER.c_str()); |
1423 | - uint32_t port = s.get_natural("metaserverport", kInternetGamingPort); |
1424 | - std::string auth = register_ ? password_ : s.get_string("uuid"); |
1425 | + const std::string& meta = get_config_string("metaserver", INTERNET_GAMING_METASERVER.c_str()); |
1426 | + uint32_t port = get_config_natural("metaserverport", kInternetGamingPort); |
1427 | + std::string auth = register_ ? password_ : get_config_string("uuid", nullptr); |
1428 | assert(!auth.empty()); |
1429 | InternetGaming::ref().login(nickname_, auth, register_, meta, port); |
1430 | |
1431 | @@ -128,7 +126,7 @@ |
1432 | |
1433 | // Reset InternetGaming and passwort and show internet login again |
1434 | InternetGaming::ref().reset(); |
1435 | - s.set_string("password_sha1", "no_password_set"); |
1436 | + set_config_string("password_sha1", "no_password_set"); |
1437 | auto_log_ = true; |
1438 | show_internet_login(); |
1439 | } |
1440 | |
1441 | === modified file 'src/ui_fsmenu/netsetup_lan.cc' |
1442 | --- src/ui_fsmenu/netsetup_lan.cc 2019-05-26 17:21:15 +0000 |
1443 | +++ src/ui_fsmenu/netsetup_lan.cc 2019-08-27 19:00:46 +0000 |
1444 | @@ -25,7 +25,7 @@ |
1445 | #include "network/constants.h" |
1446 | #include "network/internet_gaming.h" |
1447 | #include "network/network.h" |
1448 | -#include "profile/profile.h" |
1449 | +#include "wlapplication_options.h" |
1450 | |
1451 | FullscreenMenuNetSetupLAN::FullscreenMenuNetSetupLAN() |
1452 | : FullscreenMenuBase(), |
1453 | @@ -110,13 +110,11 @@ |
1454 | loadlasthost.sigclicked.connect( |
1455 | boost::bind(&FullscreenMenuNetSetupLAN::clicked_lasthost, boost::ref(*this))); |
1456 | |
1457 | - Section& s = g_options.pull_section("global"); // for playername |
1458 | - |
1459 | playername.set_font_scale(scale_factor()); |
1460 | hostname.set_font_scale(scale_factor()); |
1461 | |
1462 | hostname.changed.connect(boost::bind(&FullscreenMenuNetSetupLAN::change_hostname, this)); |
1463 | - playername.set_text(s.get_string("nickname", (_("nobody")))); |
1464 | + playername.set_text(get_config_string("nickname", (_("nobody")))); |
1465 | playername.changed.connect(boost::bind(&FullscreenMenuNetSetupLAN::change_playername, this)); |
1466 | opengames.add_column(listw_ * 2 / 5, _("Host")); |
1467 | opengames.add_column(listw_ * 2 / 5, _("Map")); |
1468 | @@ -264,12 +262,12 @@ |
1469 | joingame.set_enabled(true); |
1470 | } |
1471 | |
1472 | - g_options.pull_section("global").set_string("nickname", playername.text()); |
1473 | + set_config_string("nickname", playername.text()); |
1474 | } |
1475 | |
1476 | void FullscreenMenuNetSetupLAN::clicked_joingame() { |
1477 | // Save selected host so users can reload it for reconnection. |
1478 | - g_options.pull_section("global").set_string("lasthost", hostname.text()); |
1479 | + set_config_string("lasthost", hostname.text()); |
1480 | |
1481 | end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kJoingame); |
1482 | } |
1483 | @@ -279,7 +277,7 @@ |
1484 | } |
1485 | |
1486 | void FullscreenMenuNetSetupLAN::clicked_lasthost() { |
1487 | - Section& s = g_options.get_safe_section("global"); |
1488 | + Section& s = get_config_safe_section(); |
1489 | std::string const host = s.get_string("lasthost", ""); |
1490 | hostname.set_text(host); |
1491 | if (host.size()) |
1492 | |
1493 | === modified file 'src/ui_fsmenu/options.cc' |
1494 | --- src/ui_fsmenu/options.cc 2019-06-25 08:03:30 +0000 |
1495 | +++ src/ui_fsmenu/options.cc 2019-08-27 19:00:46 +0000 |
1496 | @@ -37,13 +37,14 @@ |
1497 | #include "graphic/text/font_set.h" |
1498 | #include "graphic/text_layout.h" |
1499 | #include "helper.h" |
1500 | +#include "io/filesystem/disk_filesystem.h" |
1501 | #include "io/filesystem/layered_filesystem.h" |
1502 | #include "logic/filesystem_constants.h" |
1503 | -#include "profile/profile.h" |
1504 | #include "scripting/lua_interface.h" |
1505 | #include "scripting/lua_table.h" |
1506 | #include "sound/sound_handler.h" |
1507 | #include "wlapplication.h" |
1508 | +#include "wlapplication_options.h" |
1509 | |
1510 | namespace { |
1511 | |
1512 | @@ -679,5 +680,5 @@ |
1513 | g_sh->save_config(); |
1514 | |
1515 | // Now write to file |
1516 | - g_options.write(kConfigFile.c_str(), true); |
1517 | + write_config(WLApplication::get()); |
1518 | } |
1519 | |
1520 | === modified file 'src/ui_fsmenu/scenario_select.cc' |
1521 | --- src/ui_fsmenu/scenario_select.cc 2019-05-26 17:21:15 +0000 |
1522 | +++ src/ui_fsmenu/scenario_select.cc 2019-08-27 19:00:46 +0000 |
1523 | @@ -26,9 +26,9 @@ |
1524 | #include "base/i18n.h" |
1525 | #include "base/wexception.h" |
1526 | #include "graphic/graphic.h" |
1527 | +#include "io/profile.h" |
1528 | #include "logic/filesystem_constants.h" |
1529 | #include "map_io/widelands_map_loader.h" |
1530 | -#include "profile/profile.h" |
1531 | #include "scripting/lua_interface.h" |
1532 | #include "scripting/lua_table.h" |
1533 | #include "ui_basic/scrollbar.h" |
1534 | |
1535 | === modified file 'src/wlapplication.cc' |
1536 | --- src/wlapplication.cc 2019-05-27 21:04:13 +0000 |
1537 | +++ src/wlapplication.cc 2019-08-27 19:00:46 +0000 |
1538 | @@ -73,7 +73,6 @@ |
1539 | #include "network/gameclient.h" |
1540 | #include "network/gamehost.h" |
1541 | #include "network/internet_gaming.h" |
1542 | -#include "profile/profile.h" |
1543 | #include "random/random.h" |
1544 | #include "sound/sound_handler.h" |
1545 | #include "ui_basic/messagebox.h" |
1546 | @@ -93,6 +92,7 @@ |
1547 | #include "ui_fsmenu/scenario_select.h" |
1548 | #include "ui_fsmenu/singleplayer.h" |
1549 | #include "wlapplication_messages.h" |
1550 | +#include "wlapplication_options.h" |
1551 | #include "wui/game_tips.h" |
1552 | #include "wui/interactive_player.h" |
1553 | #include "wui/interactive_spectator.h" |
1554 | @@ -234,6 +234,11 @@ |
1555 | // We don't have a destination dir for the logger yet |
1556 | std::cout << "Adding home directory: " << commandline_["homedir"].c_str() << std::endl; |
1557 | homedir_ = commandline_["homedir"]; |
1558 | +#ifdef USE_XDG |
1559 | + // This commandline option should probably also affect the |
1560 | + // configuration file. |
1561 | + userconfigdir_ = commandline_["homedir"]; |
1562 | +#endif |
1563 | commandline_.erase("homedir"); |
1564 | } |
1565 | |
1566 | @@ -318,6 +323,11 @@ |
1567 | should_die_(false), |
1568 | #ifdef _WIN32 |
1569 | homedir_(FileSystem::get_homedir() + "\\.widelands"), |
1570 | +#elif defined USE_XDG |
1571 | + // To enable backwards compatibility, the program name is passed with the |
1572 | + // path. |
1573 | + homedir_(FileSystem::get_userdatadir()), |
1574 | + userconfigdir_(FileSystem::get_userconfigdir()), |
1575 | #else |
1576 | homedir_(FileSystem::get_homedir() + "/.widelands"), |
1577 | #endif |
1578 | @@ -347,8 +357,6 @@ |
1579 | cleanup_temp_files(); |
1580 | cleanup_temp_backups(); |
1581 | |
1582 | - Section& config = g_options.pull_section("global"); |
1583 | - |
1584 | // Start the SDL core |
1585 | if (SDL_Init(SDL_INIT_VIDEO) == -1) |
1586 | throw wexception("Failed to initialize SDL, no valid video driver: %s", SDL_GetError()); |
1587 | @@ -363,9 +371,9 @@ |
1588 | &g_gr->images(), i18n::get_locale()); // This will create the fontset, so loading it first. |
1589 | |
1590 | g_gr->initialize( |
1591 | - config.get_bool("debug_gl_trace", false) ? Graphic::TraceGl::kYes : Graphic::TraceGl::kNo, |
1592 | - config.get_int("xres", DEFAULT_RESOLUTION_W), config.get_int("yres", DEFAULT_RESOLUTION_H), |
1593 | - config.get_bool("fullscreen", false)); |
1594 | + get_config_bool("debug_gl_trace", false) ? Graphic::TraceGl::kYes : Graphic::TraceGl::kNo, |
1595 | + get_config_int("xres", DEFAULT_RESOLUTION_W), get_config_int("yres", DEFAULT_RESOLUTION_H), |
1596 | + get_config_bool("fullscreen", false)); |
1597 | |
1598 | g_sh = new SoundHandler(); |
1599 | |
1600 | @@ -385,7 +393,7 @@ |
1601 | std::srand(time(nullptr)); |
1602 | |
1603 | // Make sure we didn't forget to read any global option |
1604 | - g_options.check_used(); |
1605 | + check_config_used(); |
1606 | } |
1607 | |
1608 | /** |
1609 | @@ -435,7 +443,7 @@ |
1610 | replay(); |
1611 | } else if (game_type_ == LOADGAME) { |
1612 | Widelands::Game game; |
1613 | - game.set_ai_training_mode(g_options.pull_section("global").get_bool("ai_training", false)); |
1614 | + game.set_ai_training_mode(get_config_bool("ai_training", false)); |
1615 | try { |
1616 | game.run_load_game(filename_, script_to_run_); |
1617 | } catch (const Widelands::GameDataError& e) { |
1618 | @@ -569,7 +577,7 @@ |
1619 | last_resolution_change_ = time; |
1620 | bool value = !g_gr->fullscreen(); |
1621 | g_gr->set_fullscreen(value); |
1622 | - g_options.pull_section("global").set_bool("fullscreen", value); |
1623 | + set_config_bool("fullscreen", value); |
1624 | } |
1625 | return true; |
1626 | } |
1627 | @@ -743,14 +751,12 @@ |
1628 | } |
1629 | |
1630 | void WLApplication::refresh_graphics() { |
1631 | - Section& s = g_options.pull_section("global"); |
1632 | - |
1633 | g_gr->change_resolution( |
1634 | - s.get_int("xres", DEFAULT_RESOLUTION_W), s.get_int("yres", DEFAULT_RESOLUTION_H)); |
1635 | - g_gr->set_fullscreen(s.get_bool("fullscreen", false)); |
1636 | + get_config_int("xres", DEFAULT_RESOLUTION_W), get_config_int("yres", DEFAULT_RESOLUTION_H)); |
1637 | + g_gr->set_fullscreen(get_config_bool("fullscreen", false)); |
1638 | |
1639 | // does only work with a window |
1640 | - set_input_grab(s.get_bool("inputgrab", false)); |
1641 | + set_input_grab(get_config_bool("inputgrab", false)); |
1642 | } |
1643 | |
1644 | /** |
1645 | @@ -760,13 +766,12 @@ |
1646 | bool WLApplication::init_settings() { |
1647 | |
1648 | // Read in the configuration file |
1649 | - g_options.read(kConfigFile.c_str(), "global"); |
1650 | - Section& s = g_options.pull_section("global"); |
1651 | + read_config(this); |
1652 | |
1653 | // Then parse the commandline - overwrites conffile settings |
1654 | handle_commandline_parameters(); |
1655 | |
1656 | - set_mouse_swap(s.get_bool("swapmouse", false)); |
1657 | + set_mouse_swap(get_config_bool("swapmouse", false)); |
1658 | |
1659 | // TODO(unknown): KLUDGE! |
1660 | // Without this the following config options get dropped by check_used(). |
1661 | @@ -774,79 +779,73 @@ |
1662 | // sensible way |
1663 | |
1664 | // Some of the options listed here are documented in wlapplication_messages.cc |
1665 | - s.get_bool("ai_training"); |
1666 | - s.get_bool("auto_speed"); |
1667 | - s.get_bool("fullscreen"); |
1668 | - s.get_bool("animate_map_panning"); |
1669 | - s.get_int("xres"); |
1670 | - s.get_int("yres"); |
1671 | - s.get_int("border_snap_distance"); |
1672 | - s.get_int("maxfps"); |
1673 | - s.get_int("panel_snap_distance"); |
1674 | - s.get_int("autosave"); |
1675 | - s.get_int("rolling_autosave"); |
1676 | - // Undocumented on command line, appears in game options |
1677 | - s.get_bool("single_watchwin"); |
1678 | - s.get_bool("auto_roadbuild_mode"); |
1679 | - // Undocumented on command line, appears in game options |
1680 | - s.get_bool("nozip"); |
1681 | - s.get_bool("snap_windows_only_when_overlapping"); |
1682 | - s.get_bool("dock_windows_to_edges"); |
1683 | - s.get_bool("write_syncstreams"); |
1684 | - // Undocumented on command line, appears in game options |
1685 | - s.get_bool("transparent_chat"); |
1686 | + get_config_bool("ai_training", false); |
1687 | + get_config_bool("auto_speed", false); |
1688 | + get_config_bool("fullscreen", false); |
1689 | + get_config_bool("animate_map_panning", false); |
1690 | + get_config_int("xres", 0); |
1691 | + get_config_int("yres", 0); |
1692 | + get_config_int("border_snap_distance", 0); |
1693 | + get_config_int("maxfps", 0); |
1694 | + get_config_int("panel_snap_distance", 0); |
1695 | + get_config_int("autosave", 0); |
1696 | + get_config_int("rolling_autosave", 0); |
1697 | + // Undocumented on command line, appears in game options |
1698 | + get_config_bool("single_watchwin", false); |
1699 | + get_config_bool("auto_roadbuild_mode", false); |
1700 | + // Undocumented on command line, appears in game options |
1701 | + get_config_bool("nozip", false); |
1702 | + get_config_bool("snap_windows_only_when_overlapping", false); |
1703 | + get_config_bool("dock_windows_to_edges", false); |
1704 | + get_config_bool("write_syncstreams", false); |
1705 | + // Undocumented on command line, appears in game options |
1706 | + get_config_bool("transparent_chat", false); |
1707 | // Undocumented. Unique ID used to allow the metaserver to recognize players |
1708 | - s.get_string("uuid"); |
1709 | + get_config_string("uuid", ""); |
1710 | // Undocumented, appears in online login box |
1711 | // Whether the used metaserver login is for a registered user |
1712 | - s.get_string("registered"); |
1713 | + get_config_string("registered", ""); |
1714 | // Undocumented, appears in online login box and LAN lobby |
1715 | // The nickname used for LAN and online games |
1716 | - s.get_string("nickname"); |
1717 | + get_config_string("nickname", ""); |
1718 | // Undocumented. The plaintext password for online logins |
1719 | // TODO(Notabilis): Remove next line after build 20. |
1720 | // Currently left in to avoid removing stored passwords for users of both build 19 and trunk |
1721 | - s.get_string("password"); |
1722 | + get_config_string("password", ""); |
1723 | // Undocumented, appears in online login box. The hashed password for online logins |
1724 | - s.get_string("password_sha1"); |
1725 | + get_config_string("password_sha1", ""); |
1726 | // Undocumented, appears in online login box. Whether to automatically use the stored login |
1727 | - s.get_string("auto_log"); |
1728 | + get_config_string("auto_log", ""); |
1729 | // Undocumented, appears in LAN lobby. The last host connected to |
1730 | - s.get_string("lasthost"); |
1731 | + get_config_string("lasthost", ""); |
1732 | // Undocumented, appears in online lobby. The name of the last hosted game |
1733 | - s.get_string("servername"); |
1734 | + get_config_string("servername", ""); |
1735 | // Undocumented, appears in editor. Name of map author |
1736 | - s.get_string("realname"); |
1737 | - s.get_string("metaserver"); |
1738 | - s.get_natural("metaserverport"); |
1739 | + get_config_string("realname", ""); |
1740 | + get_config_string("metaserver", ""); |
1741 | + get_config_natural("metaserverport", 0); |
1742 | // Undocumented, checkbox appears on "Watch Replay" screen |
1743 | - s.get_bool("display_replay_filenames"); |
1744 | - s.get_bool("editor_player_menu_warn_too_many_players"); |
1745 | + get_config_bool("display_replay_filenames", false); |
1746 | + get_config_bool("editor_player_menu_warn_too_many_players", false); |
1747 | // KLUDGE! |
1748 | |
1749 | - long int last_start = s.get_int("last_start", 0); |
1750 | - if (last_start + 12 * 60 * 60 < time(nullptr) || !s.get_string("uuid")) { |
1751 | + long int last_start = get_config_int("last_start", 0); |
1752 | + if (last_start + 12 * 60 * 60 < time(nullptr) || !get_config_string("uuid", "").empty()) { |
1753 | // First start of the game or not started for 12 hours. Create a (new) UUID. |
1754 | // For the use of the UUID, see network/internet_gaming_protocol.h |
1755 | - s.set_string("uuid", generate_random_uuid()); |
1756 | + get_config_string("uuid", generate_random_uuid().c_str()); |
1757 | } |
1758 | - s.set_int("last_start", time(nullptr)); |
1759 | + get_config_int("last_start", time(nullptr)); |
1760 | |
1761 | // Replace the stored plaintext password with its SHA-1 hashed version |
1762 | // Used to upgrade the stored password when upgrading widelands |
1763 | - if (strlen(s.get_string("password", "")) > 0 && strlen(s.get_string("password_sha1", "")) == 0) { |
1764 | - s.set_string("password_sha1", crypto::sha1(s.get_string("password"))); |
1765 | + if (get_config_string("password", "").length() > 0 && get_config_string("password_sha1", "").length() == 0) { |
1766 | + get_config_string("password_sha1", crypto::sha1(get_config_string("password", "")).c_str()); |
1767 | } |
1768 | |
1769 | // Save configuration now. Otherwise, the UUID is not saved |
1770 | - // when the game crashes, loosing part of its advantage |
1771 | - try { |
1772 | - g_options.write("config", false); |
1773 | - } catch (const std::exception& e) { |
1774 | - log("WARNING: could not save configuration: %s\n", e.what()); |
1775 | - } catch (...) { |
1776 | - log("WARNING: could not save configuration"); |
1777 | - } |
1778 | + // when the game crashes, losing part of its advantage |
1779 | + write_config(this); |
1780 | |
1781 | return true; |
1782 | } |
1783 | @@ -855,9 +854,6 @@ |
1784 | * Initialize language settings |
1785 | */ |
1786 | void WLApplication::init_language() { |
1787 | - // retrieve configuration settings |
1788 | - Section& s = g_options.pull_section("global"); |
1789 | - |
1790 | // Initialize locale and grab "widelands" textdomain |
1791 | i18n::init_locale(); |
1792 | |
1793 | @@ -865,7 +861,7 @@ |
1794 | i18n::grab_textdomain("widelands"); |
1795 | |
1796 | // Set locale corresponding to selected language |
1797 | - std::string language = s.get_string("language", ""); |
1798 | + std::string language = get_config_string("language", ""); |
1799 | i18n::set_locale(language); |
1800 | } |
1801 | |
1802 | @@ -876,13 +872,7 @@ |
1803 | // To be proper, release our textdomain |
1804 | i18n::release_textdomain(); |
1805 | |
1806 | - try { // overwrite the old config file |
1807 | - g_options.write(kConfigFile.c_str(), true); |
1808 | - } catch (const std::exception& e) { |
1809 | - log("WARNING: could not save configuration: %s\n", e.what()); |
1810 | - } catch (...) { |
1811 | - log("WARNING: could not save configuration"); |
1812 | - } |
1813 | + write_config(this); |
1814 | } |
1815 | |
1816 | void WLApplication::shutdown_hardware() { |
1817 | @@ -962,7 +952,7 @@ |
1818 | commandline_.erase("nosound"); |
1819 | } |
1820 | if (commandline_.count("nozip")) { |
1821 | - g_options.pull_section("global").create_val("nozip", "true"); |
1822 | + set_config_bool("nozip", true); |
1823 | commandline_.erase("nozip"); |
1824 | } |
1825 | |
1826 | @@ -973,6 +963,16 @@ |
1827 | datadir_ = is_absolute_path(INSTALL_DATADIR) ? |
1828 | INSTALL_DATADIR : |
1829 | get_executable_directory() + FileSystem::file_separator() + INSTALL_DATADIR; |
1830 | +#ifdef USE_XDG |
1831 | + // Overwrite with first folder found in XDG_DATA_DIRS |
1832 | + for (const auto& datadir: FileSystem::get_xdgdatadirs()) { |
1833 | + RealFSImpl dir(datadir); |
1834 | + if (dir.is_directory(datadir + "/widelands")) { |
1835 | + datadir_ = datadir + "/widelands"; |
1836 | + break; |
1837 | + } |
1838 | + } |
1839 | +#endif |
1840 | } |
1841 | if (!is_absolute_path(datadir_)) { |
1842 | try { |
1843 | @@ -1046,17 +1046,17 @@ |
1844 | |
1845 | // Following is used for training of AI |
1846 | if (commandline_.count("ai_training")) { |
1847 | - g_options.pull_section("global").create_val("ai_training", "true"); |
1848 | + set_config_bool("ai_training", true); |
1849 | commandline_.erase("ai_training"); |
1850 | } else { |
1851 | - g_options.pull_section("global").create_val("ai_training", "false"); |
1852 | + set_config_bool("ai_training", false); |
1853 | } |
1854 | |
1855 | if (commandline_.count("auto_speed")) { |
1856 | - g_options.pull_section("global").create_val("auto_speed", "true"); |
1857 | + set_config_bool("auto_speed", true); |
1858 | commandline_.erase("auto_speed"); |
1859 | } else { |
1860 | - g_options.pull_section("global").create_val("auto_speed", "false"); |
1861 | + set_config_bool("auto_speed", false); |
1862 | } |
1863 | |
1864 | // If it hasn't been handled yet it's probably an attempt to |
1865 | @@ -1070,7 +1070,7 @@ |
1866 | // TODO(unknown): barf here on unknown option; the list of known options |
1867 | // needs to be centralized |
1868 | |
1869 | - g_options.pull_section("global").create_val(it->first.c_str(), it->second.c_str()); |
1870 | + set_config_string(it->first.c_str(), it->second.c_str()); |
1871 | } |
1872 | |
1873 | if (commandline_.count("help") || commandline_.count("version")) { |
1874 | @@ -1118,7 +1118,7 @@ |
1875 | replay(); |
1876 | break; |
1877 | case FullscreenMenuBase::MenuTarget::kOptions: { |
1878 | - Section& s = g_options.pull_section("global"); |
1879 | + Section& s = get_config_section(); |
1880 | OptionsCtrl om(s); |
1881 | break; |
1882 | } |
1883 | @@ -1248,11 +1248,10 @@ |
1884 | std::string password(mp.get_password()); |
1885 | bool registered = mp.registered(); |
1886 | |
1887 | - Section& s = g_options.pull_section("global"); |
1888 | - s.set_string("nickname", playername); |
1889 | + get_config_string("nickname", playername); |
1890 | // Only change the password if we use a registered account |
1891 | if (registered) { |
1892 | - s.set_string("password_sha1", password); |
1893 | + get_config_string("password_sha1", password); |
1894 | } |
1895 | |
1896 | // reinitalise in every run, else graphics look strange |
1897 | @@ -1318,7 +1317,7 @@ |
1898 | |
1899 | Widelands::Game game; |
1900 | |
1901 | - game.set_ai_training_mode(g_options.pull_section("global").get_bool("ai_training", false)); |
1902 | + game.set_ai_training_mode(get_config_bool("ai_training", false)); |
1903 | |
1904 | if (code == FullscreenMenuBase::MenuTarget::kScenarioGame) { // scenario |
1905 | try { |
1906 | @@ -1333,7 +1332,7 @@ |
1907 | try { |
1908 | // Game controller needs the ibase pointer to init |
1909 | // the chat |
1910 | - game.set_ibase(new InteractivePlayer(game, g_options.pull_section("global"), pn, false)); |
1911 | + game.set_ibase(new InteractivePlayer(game, get_config_section(), pn, false)); |
1912 | std::unique_ptr<GameController> ctrl(new SinglePlayerGameController(game, true, pn)); |
1913 | UI::ProgressWindow loader_ui; |
1914 | std::vector<std::string> tipstext; |
1915 | @@ -1370,7 +1369,7 @@ |
1916 | Widelands::Game game; |
1917 | std::string filename; |
1918 | |
1919 | - game.set_ai_training_mode(g_options.pull_section("global").get_bool("ai_training", false)); |
1920 | + game.set_ai_training_mode(get_config_bool("ai_training", false)); |
1921 | SinglePlayerGameSettingsProvider sp; |
1922 | FullscreenMenuLoadGame ssg(game, &sp); |
1923 | |
1924 | @@ -1457,7 +1456,7 @@ |
1925 | |
1926 | loader_ui.step(_("Loading…")); |
1927 | |
1928 | - game.set_ibase(new InteractiveSpectator(game, g_options.pull_section("global"))); |
1929 | + game.set_ibase(new InteractiveSpectator(game, get_config_section())); |
1930 | game.set_write_replay(false); |
1931 | ReplayGameController rgc(game, filename_); |
1932 | |
1933 | |
1934 | === modified file 'src/wlapplication.h' |
1935 | --- src/wlapplication.h 2019-02-23 11:00:49 +0000 |
1936 | +++ src/wlapplication.h 2019-08-27 19:00:46 +0000 |
1937 | @@ -196,6 +196,13 @@ |
1938 | void replay(); |
1939 | static void emergency_save(Widelands::Game&); |
1940 | |
1941 | +#ifdef USE_XDG |
1942 | + // this is only for src/wlapplication_options.cc |
1943 | + std::string get_userconfigdir() { |
1944 | + return userconfigdir_; |
1945 | + } |
1946 | +#endif |
1947 | + |
1948 | private: |
1949 | WLApplication(int argc, char const* const* argv); |
1950 | |
1951 | @@ -259,6 +266,9 @@ |
1952 | bool should_die_; |
1953 | |
1954 | std::string homedir_; |
1955 | +#ifdef USE_XDG |
1956 | + std::string userconfigdir_; |
1957 | +#endif |
1958 | |
1959 | /// flag indicating if stdout and stderr have been redirected |
1960 | bool redirected_stdio_; |
1961 | |
1962 | === added file 'src/wlapplication_options.cc' |
1963 | --- src/wlapplication_options.cc 1970-01-01 00:00:00 +0000 |
1964 | +++ src/wlapplication_options.cc 2019-08-27 19:00:46 +0000 |
1965 | @@ -0,0 +1,151 @@ |
1966 | +/* |
1967 | + * Copyright (C) 2012-2019 by the Widelands Development Team |
1968 | + * |
1969 | + * This program is free software; you can redistribute it and/or |
1970 | + * modify it under the terms of the GNU General Public License |
1971 | + * as published by the Free Software Foundation; either version 2 |
1972 | + * of the License, or (at your option) any later version. |
1973 | + * |
1974 | + * This program is distributed in the hope that it will be useful, |
1975 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1976 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1977 | + * GNU General Public License for more details. |
1978 | + * |
1979 | + * You should have received a copy of the GNU General Public License |
1980 | + * along with this program; if not, write to the Free Software |
1981 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
1982 | + * |
1983 | + */ |
1984 | + |
1985 | +#include "wlapplication_options.h" |
1986 | + |
1987 | +#include "base/log.h" |
1988 | +#include "io/filesystem/disk_filesystem.h" |
1989 | +#include "io/profile.h" |
1990 | +#include "logic/filesystem_constants.h" |
1991 | +#include "wlapplication.h" |
1992 | + |
1993 | +Profile g_options(Profile::err_log); |
1994 | + |
1995 | +void check_config_used() { |
1996 | + g_options.check_used(); |
1997 | +} |
1998 | + |
1999 | +Section& get_config_section() { |
2000 | + return g_options.pull_section("global"); |
2001 | +} |
2002 | + |
2003 | +Section& get_config_section(const std::string& section) { |
2004 | + return g_options.pull_section(section.c_str()); |
2005 | +} |
2006 | + |
2007 | +Section* get_config_section_ptr(const std::string& section) { |
2008 | + return g_options.get_section(section.c_str()); |
2009 | +} |
2010 | + |
2011 | +bool get_config_bool(const std::string& name, const bool dflt) { |
2012 | + return g_options.pull_section("global").get_bool(name.c_str(), dflt); |
2013 | +} |
2014 | + |
2015 | +bool get_config_bool(const std::string& section, |
2016 | + const std::string& name, |
2017 | + const bool dflt) { |
2018 | + return g_options.pull_section(section.c_str()).get_bool(name.c_str(), dflt); |
2019 | +} |
2020 | + |
2021 | +int32_t get_config_int(const std::string& name, const int32_t dflt) { |
2022 | + return g_options.pull_section("global").get_int(name.c_str(), dflt); |
2023 | +} |
2024 | + |
2025 | +int32_t get_config_int(const std::string& section, |
2026 | + const std::string& name, |
2027 | + const int32_t dflt) { |
2028 | + return g_options.pull_section(section.c_str()).get_int(name.c_str(), dflt); |
2029 | +} |
2030 | + |
2031 | +uint32_t get_config_natural(const std::string& name, const uint32_t dflt) { |
2032 | + return g_options.pull_section("global").get_natural(name.c_str(), dflt); |
2033 | +} |
2034 | + |
2035 | +uint32_t get_config_natural(const std::string& section, |
2036 | + const std::string& name, |
2037 | + uint32_t dflt) { |
2038 | + return g_options.pull_section(section.c_str()).get_natural(name.c_str(), dflt); |
2039 | +} |
2040 | + |
2041 | +std::string get_config_string(const std::string& name, |
2042 | + const std::string& dflt) { |
2043 | + return g_options.pull_section("global").get_string(name.c_str(), dflt.c_str()); |
2044 | +} |
2045 | + |
2046 | +std::string get_config_string(const std::string& section, |
2047 | + const std::string& name, |
2048 | + const std::string& dflt) { |
2049 | + return g_options.pull_section(section.c_str()).get_string(name.c_str(), dflt.c_str()); |
2050 | +} |
2051 | + |
2052 | +Section& get_config_safe_section() { |
2053 | + return g_options.get_safe_section("global"); |
2054 | +} |
2055 | + |
2056 | +Section& get_config_safe_section(const std::string& section) { |
2057 | + return g_options.get_safe_section(section.c_str()); |
2058 | +} |
2059 | + |
2060 | +void set_config_bool(const std::string& name, const bool value) { |
2061 | + g_options.pull_section("global").set_bool(name.c_str(), value); |
2062 | +} |
2063 | + |
2064 | +void set_config_bool(const std::string& section, |
2065 | + const std::string& name, |
2066 | + const bool value) { |
2067 | + g_options.pull_section(section.c_str()).set_bool(name.c_str(), value); |
2068 | +} |
2069 | + |
2070 | +void set_config_int(const std::string& name, int32_t value) { |
2071 | + g_options.pull_section("global").set_int(name.c_str(), value); |
2072 | +} |
2073 | + |
2074 | +void set_config_int(const std::string& section, |
2075 | + const std::string& name, |
2076 | + const int32_t value) { |
2077 | + g_options.pull_section(section.c_str()).set_int(name.c_str(), value); |
2078 | +} |
2079 | + |
2080 | +void set_config_string(const std::string& name, const std::string& value) { |
2081 | + g_options.pull_section("global").set_string(name.c_str(), value.c_str()); |
2082 | +} |
2083 | + |
2084 | +void set_config_string(const std::string& section, |
2085 | + const std::string& name, |
2086 | + const std::string& value) { |
2087 | + g_options.pull_section(section.c_str()).set_string(name.c_str(), value.c_str()); |
2088 | +} |
2089 | + |
2090 | +void read_config(WLApplication* wlapplication) { |
2091 | +#ifdef USE_XDG |
2092 | + RealFSImpl dir(wlapplication->get_userconfigdir()); |
2093 | + dir.ensure_directory_exists("."); |
2094 | + log("Set configuration file: %s/%s\n", |
2095 | + wlapplication->get_userconfigdir().c_str(), |
2096 | + kConfigFile.c_str()); |
2097 | + g_options.read(kConfigFile.c_str(), "global", dir); |
2098 | +#else |
2099 | + g_options.read(kConfigFile.c_str(), "global"); |
2100 | +#endif |
2101 | +} |
2102 | + |
2103 | +void write_config(WLApplication* wlapplication) { |
2104 | + try { // overwrite the old config file |
2105 | +#ifdef USE_XDG |
2106 | + RealFSImpl dir(wlapplication->get_userconfigdir()); |
2107 | + g_options.write(kConfigFile.c_str(), true, dir); |
2108 | +#else |
2109 | + g_options.write(kConfigFile.c_str(), true); |
2110 | +#endif |
2111 | + } catch (const std::exception& e) { |
2112 | + log("WARNING: could not save configuration: %s\n", e.what()); |
2113 | + } catch (...) { |
2114 | + log("WARNING: could not save configuration"); |
2115 | + } |
2116 | +} |
2117 | |
2118 | === added file 'src/wlapplication_options.h' |
2119 | --- src/wlapplication_options.h 1970-01-01 00:00:00 +0000 |
2120 | +++ src/wlapplication_options.h 2019-08-27 19:00:46 +0000 |
2121 | @@ -0,0 +1,118 @@ |
2122 | +/* |
2123 | + * Copyright (C) 2012-2019 by the Widelands Development Team |
2124 | + * |
2125 | + * This program is free software; you can redistribute it and/or |
2126 | + * modify it under the terms of the GNU General Public License |
2127 | + * as published by the Free Software Foundation; either version 2 |
2128 | + * of the License, or (at your option) any later version. |
2129 | + * |
2130 | + * This program is distributed in the hope that it will be useful, |
2131 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2132 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2133 | + * GNU General Public License for more details. |
2134 | + * |
2135 | + * You should have received a copy of the GNU General Public License |
2136 | + * along with this program; if not, write to the Free Software |
2137 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
2138 | + * |
2139 | + */ |
2140 | + |
2141 | +#ifndef WL_WLAPPLICATION_OPTIONS_H |
2142 | +#define WL_WLAPPLICATION_OPTIONS_H |
2143 | + |
2144 | +#include "io/profile.h" |
2145 | +#include "wlapplication.h" |
2146 | + |
2147 | +/* |
2148 | + * Further explanations for all functions and its return values |
2149 | + * can be found in io/profile.cc |
2150 | + */ |
2151 | +class Section; |
2152 | + |
2153 | +/* |
2154 | + * Check if all options has been read. |
2155 | + */ |
2156 | +void check_config_used(); |
2157 | + |
2158 | +/* |
2159 | + * Get config values from the config settings cache. |
2160 | + * If the section parameter is omitted the global section will be used. |
2161 | + * Values are available after read_config() is called. |
2162 | + */ |
2163 | +Section& get_config_section(); |
2164 | +Section& get_config_section(const std::string&); |
2165 | +Section* get_config_section_ptr(const std::string&); |
2166 | +bool get_config_bool(const std::string& name, bool dflt); |
2167 | +bool get_config_bool(const std::string& section, |
2168 | + const std::string& name, |
2169 | + const bool dflt); |
2170 | +int32_t get_config_int(const std::string& name, const int32_t dflt = 0); |
2171 | +int32_t get_config_int(const std::string& section, |
2172 | + const std::string& name, |
2173 | + const int32_t dflt); |
2174 | +uint32_t get_config_natural(const std::string& name, uint32_t dflt); |
2175 | +uint32_t get_config_natural(const std::string& section, |
2176 | + const std::string& name, |
2177 | + const uint32_t dflt); |
2178 | +std::string get_config_string(const std::string& name, |
2179 | + const std::string& dflt); |
2180 | +std::string get_config_string(const std::string& section, |
2181 | + const std::string& name, |
2182 | + const std::string& dflt); |
2183 | + |
2184 | +/* |
2185 | + * Get config values from the config settings cache. |
2186 | + * Throws an exception if the value doesn't exist. |
2187 | + * If the section parameter is omitted the global section will be used. |
2188 | + * Values are available after read_config() is called. |
2189 | + */ |
2190 | +Section& get_config_safe_section(); |
2191 | +Section& get_config_safe_section(const std::string&); |
2192 | + |
2193 | +/* |
2194 | + * Set config values to the config settings cache. |
2195 | + * If the section parameter is omitted the global section will be used. |
2196 | + * Values will be written to the config file once write_config() is called. |
2197 | + */ |
2198 | +void set_config_bool(const std::string& name, bool value); |
2199 | +void set_config_bool(const std::string& section, |
2200 | + const std::string& name, |
2201 | + bool value); |
2202 | +void set_config_int(const std::string& name, int32_t value); |
2203 | +void set_config_int(const std::string& section, |
2204 | + const std::string& name, |
2205 | + const int32_t value); |
2206 | +void set_config_string(const std::string& name, const std::string& value); |
2207 | +void set_config_string(const std::string& section, |
2208 | + const std::string& name, |
2209 | + const std::string& value); |
2210 | + |
2211 | +/* |
2212 | + * Reads the configuration from kConfigFile. |
2213 | + * Defaults to $XDG_CONFIG_HOME/widelands/config on Unix. |
2214 | + * Defaults to homedir/config everywhere else, if homedir is set manually or if |
2215 | + * built without XDG-support. |
2216 | + * |
2217 | + * This function needs access to the WLApplication object to distinguish |
2218 | + * between multiple possible states. |
2219 | + * While we could use WLApplication::get() this would get us in an infinite loop |
2220 | + * because this function will be called in the constructor of said object and |
2221 | + * WLApplication::get() spawns another object if there isn't one yet. |
2222 | + */ |
2223 | +void read_config(WLApplication*); |
2224 | + |
2225 | +/* |
2226 | + * Writes the configuration to kConfigFile. |
2227 | + * Defaults to $XDG_CONFIG_HOME/widelands/config on Unix. |
2228 | + * Defaults to homedir/config everywhere else, if homedir is set manually or if |
2229 | + * built without XDG-support. |
2230 | + * |
2231 | + * This function needs access to the WLApplication object to distinguish |
2232 | + * between multiple possible states. |
2233 | + * While we could use WLApplication::get() this would get us in an infinite loop |
2234 | + * because this function will be called in the constructor of said object and |
2235 | + * WLApplication::get() spawns another object if there isn't one yet. |
2236 | + */ |
2237 | +void write_config(WLApplication*); |
2238 | + |
2239 | +#endif // end of include guard: WL_WLAPPLICATION_OPTIONS_H |
2240 | |
2241 | === modified file 'src/wui/CMakeLists.txt' |
2242 | --- src/wui/CMakeLists.txt 2019-07-11 08:38:29 +0000 |
2243 | +++ src/wui/CMakeLists.txt 2019-08-27 19:00:46 +0000 |
2244 | @@ -31,9 +31,9 @@ |
2245 | graphic_text |
2246 | graphic_text_layout |
2247 | logic |
2248 | - profile |
2249 | sound |
2250 | ui_basic |
2251 | + widelands_ball_of_mud |
2252 | wui |
2253 | ) |
2254 | |
2255 | @@ -49,7 +49,7 @@ |
2256 | logic_filesystem_constants |
2257 | logic_map_objects |
2258 | notifications |
2259 | - profile |
2260 | + io_profile |
2261 | ui_basic |
2262 | wui_waresdisplay |
2263 | ) |
2264 | @@ -152,7 +152,6 @@ |
2265 | graphic_game_renderer |
2266 | logic_map |
2267 | logic_widelands_geometry |
2268 | - profile |
2269 | ui_basic |
2270 | widelands_ball_of_mud |
2271 | wui_mapview_pixelfunctions |
2272 | @@ -294,6 +293,7 @@ |
2273 | graphic_toolbar_imageset |
2274 | io_fileread |
2275 | io_filesystem |
2276 | + io_profile |
2277 | logic |
2278 | logic_constants |
2279 | logic_commands |
2280 | @@ -309,12 +309,12 @@ |
2281 | network |
2282 | note_sound |
2283 | notifications |
2284 | - profile |
2285 | scripting_coroutine |
2286 | scripting_lua_interface |
2287 | scripting_lua_table |
2288 | sound |
2289 | ui_basic |
2290 | + widelands_ball_of_mud |
2291 | wui_chat_ui |
2292 | wui_common_gamedetails |
2293 | wui_economy_options |
2294 | |
2295 | === modified file 'src/wui/chat_overlay.cc' |
2296 | --- src/wui/chat_overlay.cc 2019-05-26 17:21:15 +0000 |
2297 | +++ src/wui/chat_overlay.cc 2019-08-27 19:00:46 +0000 |
2298 | @@ -31,7 +31,7 @@ |
2299 | #include "graphic/rendertarget.h" |
2300 | #include "graphic/style_manager.h" |
2301 | #include "graphic/text/rt_errors.h" |
2302 | -#include "profile/profile.h" |
2303 | +#include "wlapplication_options.h" |
2304 | #include "wui/chat_msg_layout.h" |
2305 | #include "wui/logmessage.h" |
2306 | |
2307 | @@ -85,8 +85,7 @@ |
2308 | ChatOverlay::ChatOverlay( |
2309 | UI::Panel* const parent, int32_t const x, int32_t const y, int32_t const w, int32_t const h) |
2310 | : UI::Panel(parent, x, y, w, h), m(new Impl()) { |
2311 | - Section& s = g_options.pull_section("global"); |
2312 | - m->transparent_ = s.get_bool("transparent_chat", true); |
2313 | + m->transparent_ = get_config_bool("transparent_chat", true); |
2314 | |
2315 | set_thinks(true); |
2316 | } |
2317 | |
2318 | === modified file 'src/wui/economy_options_window.cc' |
2319 | --- src/wui/economy_options_window.cc 2019-08-13 11:22:26 +0000 |
2320 | +++ src/wui/economy_options_window.cc 2019-08-27 19:00:46 +0000 |
2321 | @@ -24,13 +24,13 @@ |
2322 | #include <boost/lexical_cast.hpp> |
2323 | |
2324 | #include "graphic/graphic.h" |
2325 | +#include "io/profile.h" |
2326 | #include "logic/editor_game_base.h" |
2327 | #include "logic/filesystem_constants.h" |
2328 | #include "logic/map_objects/tribes/ware_descr.h" |
2329 | #include "logic/map_objects/tribes/worker_descr.h" |
2330 | #include "logic/player.h" |
2331 | #include "logic/playercommand.h" |
2332 | -#include "profile/profile.h" |
2333 | #include "ui_basic/messagebox.h" |
2334 | |
2335 | static const char pic_tab_wares[] = "images/wui/buildings/menu_tab_wares.png"; |
2336 | |
2337 | === modified file 'src/wui/game_main_menu_save_game.cc' |
2338 | --- src/wui/game_main_menu_save_game.cc 2019-04-18 08:32:25 +0000 |
2339 | +++ src/wui/game_main_menu_save_game.cc 2019-08-27 19:00:46 +0000 |
2340 | @@ -36,6 +36,7 @@ |
2341 | #include "logic/generic_save_handler.h" |
2342 | #include "logic/playersmanager.h" |
2343 | #include "ui_basic/messagebox.h" |
2344 | +#include "wlapplication_options.h" |
2345 | #include "wui/interactive_gamebase.h" |
2346 | |
2347 | InteractiveGameBase& GameMainMenuSaveGame::igbase() { |
2348 | @@ -162,7 +163,7 @@ |
2349 | } |
2350 | |
2351 | std::string filename = filename_editbox_.text(); |
2352 | - if (save_game(filename, !g_options.pull_section("global").get_bool("nozip", false))) { |
2353 | + if (save_game(filename, !get_config_bool("nozip", false))) { |
2354 | die(); |
2355 | } else { |
2356 | load_or_save_.table_.focus(); |
2357 | |
2358 | === modified file 'src/wui/interactive_base.cc' |
2359 | --- src/wui/interactive_base.cc 2019-08-10 16:38:15 +0000 |
2360 | +++ src/wui/interactive_base.cc 2019-08-27 19:00:46 +0000 |
2361 | @@ -45,7 +45,6 @@ |
2362 | #include "logic/maptriangleregion.h" |
2363 | #include "logic/player.h" |
2364 | #include "logic/widelands_geometry.h" |
2365 | -#include "profile/profile.h" |
2366 | #include "scripting/lua_interface.h" |
2367 | #include "sound/sound_handler.h" |
2368 | #include "wui/game_chat_menu.h" |
2369 | |
2370 | === modified file 'src/wui/interactive_base.h' |
2371 | --- src/wui/interactive_base.h 2019-08-10 16:38:15 +0000 |
2372 | +++ src/wui/interactive_base.h 2019-08-27 19:00:46 +0000 |
2373 | @@ -26,10 +26,10 @@ |
2374 | #include <SDL_keycode.h> |
2375 | |
2376 | #include "graphic/toolbar_imageset.h" |
2377 | +#include "io/profile.h" |
2378 | #include "logic/editor_game_base.h" |
2379 | #include "logic/map.h" |
2380 | #include "notifications/notifications.h" |
2381 | -#include "profile/profile.h" |
2382 | #include "sound/note_sound.h" |
2383 | #include "ui_basic/box.h" |
2384 | #include "ui_basic/dropdown.h" |
2385 | |
2386 | === modified file 'src/wui/interactive_gamebase.cc' |
2387 | --- src/wui/interactive_gamebase.cc 2019-08-13 11:12:56 +0000 |
2388 | +++ src/wui/interactive_gamebase.cc 2019-08-27 19:00:46 +0000 |
2389 | @@ -34,7 +34,6 @@ |
2390 | #include "logic/map_objects/tribes/ship.h" |
2391 | #include "logic/player.h" |
2392 | #include "network/gamehost.h" |
2393 | -#include "profile/profile.h" |
2394 | #include "wui/constructionsitewindow.h" |
2395 | #include "wui/dismantlesitewindow.h" |
2396 | #include "wui/game_chat_menu.h" |
2397 | |
2398 | === modified file 'src/wui/interactive_gamebase.h' |
2399 | --- src/wui/interactive_gamebase.h 2019-08-10 16:38:15 +0000 |
2400 | +++ src/wui/interactive_gamebase.h 2019-08-27 19:00:46 +0000 |
2401 | @@ -23,8 +23,8 @@ |
2402 | #include <map> |
2403 | #include <memory> |
2404 | |
2405 | +#include "io/profile.h" |
2406 | #include "logic/game.h" |
2407 | -#include "profile/profile.h" |
2408 | #include "ui_basic/dropdown.h" |
2409 | #include "ui_basic/unique_window.h" |
2410 | #include "wui/general_statistics_menu.h" |
2411 | |
2412 | === modified file 'src/wui/interactive_player.cc' |
2413 | --- src/wui/interactive_player.cc 2019-08-13 11:12:56 +0000 |
2414 | +++ src/wui/interactive_player.cc 2019-08-27 19:00:46 +0000 |
2415 | @@ -39,7 +39,6 @@ |
2416 | #include "logic/map_objects/tribes/tribe_descr.h" |
2417 | #include "logic/message_queue.h" |
2418 | #include "logic/player.h" |
2419 | -#include "profile/profile.h" |
2420 | #include "ui_basic/unique_window.h" |
2421 | #include "wui/building_statistics_menu.h" |
2422 | #include "wui/debugconsole.h" |
2423 | |
2424 | === modified file 'src/wui/interactive_player.h' |
2425 | --- src/wui/interactive_player.h 2019-08-10 16:38:15 +0000 |
2426 | +++ src/wui/interactive_player.h 2019-08-27 19:00:46 +0000 |
2427 | @@ -25,9 +25,9 @@ |
2428 | |
2429 | #include <SDL_keyboard.h> |
2430 | |
2431 | +#include "io/profile.h" |
2432 | #include "logic/message_id.h" |
2433 | #include "logic/note_map_options.h" |
2434 | -#include "profile/profile.h" |
2435 | #include "ui_basic/button.h" |
2436 | #include "wui/interactive_gamebase.h" |
2437 | |
2438 | |
2439 | === modified file 'src/wui/interactive_spectator.cc' |
2440 | --- src/wui/interactive_spectator.cc 2019-04-26 06:35:15 +0000 |
2441 | +++ src/wui/interactive_spectator.cc 2019-08-27 19:00:46 +0000 |
2442 | @@ -24,7 +24,6 @@ |
2443 | #include "chat/chat.h" |
2444 | #include "logic/game_controller.h" |
2445 | #include "logic/player.h" |
2446 | -#include "profile/profile.h" |
2447 | #include "ui_basic/textarea.h" |
2448 | #include "ui_basic/unique_window.h" |
2449 | #include "wui/fieldaction.h" |
2450 | |
2451 | === modified file 'src/wui/interactive_spectator.h' |
2452 | --- src/wui/interactive_spectator.h 2019-04-26 06:35:15 +0000 |
2453 | +++ src/wui/interactive_spectator.h 2019-08-27 19:00:46 +0000 |
2454 | @@ -22,7 +22,7 @@ |
2455 | |
2456 | #include <SDL_keyboard.h> |
2457 | |
2458 | -#include "profile/profile.h" |
2459 | +#include "io/profile.h" |
2460 | #include "ui_basic/button.h" |
2461 | #include "wui/interactive_gamebase.h" |
2462 | |
2463 | |
2464 | === modified file 'src/wui/login_box.cc' |
2465 | --- src/wui/login_box.cc 2019-06-01 11:29:24 +0000 |
2466 | +++ src/wui/login_box.cc 2019-08-27 19:00:46 +0000 |
2467 | @@ -23,9 +23,9 @@ |
2468 | #include "graphic/font_handler.h" |
2469 | #include "network/crypto.h" |
2470 | #include "network/internet_gaming.h" |
2471 | -#include "profile/profile.h" |
2472 | #include "ui_basic/button.h" |
2473 | #include "ui_basic/messagebox.h" |
2474 | +#include "wlapplication_options.h" |
2475 | |
2476 | LoginBox::LoginBox(Panel& parent) |
2477 | : Window(&parent, "login_box", 0, 0, 500, 280, _("Online Game Settings")) { |
2478 | @@ -67,13 +67,12 @@ |
2479 | eb_nickname->changed.connect(boost::bind(&LoginBox::change_playername, this)); |
2480 | cb_register->clickedto.connect(boost::bind(&LoginBox::clicked_register, this)); |
2481 | |
2482 | - Section& s = g_options.pull_section("global"); |
2483 | - eb_nickname->set_text(s.get_string("nickname", _("nobody"))); |
2484 | - cb_register->set_state(s.get_bool("registered", false)); |
2485 | + eb_nickname->set_text(get_config_string("nickname", _("nobody"))); |
2486 | + cb_register->set_state(get_config_bool("registered", false)); |
2487 | eb_password->set_password(true); |
2488 | |
2489 | if (registered()) { |
2490 | - eb_password->set_text(s.get_string("password_sha1", "")); |
2491 | + eb_password->set_text(get_config_string("password_sha1", "")); |
2492 | loginbtn->set_enabled(false); |
2493 | } else { |
2494 | eb_password->set_can_focus(false); |
2495 | @@ -92,17 +91,16 @@ |
2496 | * called, if "login" is pressed. |
2497 | */ |
2498 | void LoginBox::clicked_ok() { |
2499 | - Section& s = g_options.pull_section("global"); |
2500 | if (cb_register->get_state()) { |
2501 | if (check_password()) { |
2502 | - s.set_string("nickname", eb_nickname->text()); |
2503 | - s.set_bool("registered", true); |
2504 | + set_config_string("nickname", eb_nickname->text()); |
2505 | + set_config_bool("registered", true); |
2506 | end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kOk); |
2507 | } |
2508 | } else { |
2509 | - s.set_string("nickname", eb_nickname->text()); |
2510 | - s.set_bool("registered", false); |
2511 | - s.set_string("password_sha1", ""); |
2512 | + set_config_string("nickname", eb_nickname->text()); |
2513 | + set_config_bool("registered", false); |
2514 | + set_config_string("password_sha1", ""); |
2515 | end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kOk); |
2516 | } |
2517 | } |
2518 | @@ -171,12 +169,11 @@ |
2519 | loginbtn->set_enabled(false); |
2520 | } |
2521 | |
2522 | - Section& s = g_options.pull_section("global"); |
2523 | - if (eb_password->has_focus() && eb_password->text() == s.get_string("password_sha1", "")) { |
2524 | + if (eb_password->has_focus() && eb_password->text() == get_config_string("password_sha1", "")) { |
2525 | eb_password->set_text(""); |
2526 | } |
2527 | |
2528 | - if (cb_register->get_state() && eb_password->text() == s.get_string("password_sha1", "")) { |
2529 | + if (cb_register->get_state() && eb_password->text() == get_config_string("password_sha1", "")) { |
2530 | loginbtn->set_enabled(false); |
2531 | } |
2532 | } |
2533 | @@ -184,9 +181,8 @@ |
2534 | /// Check password against metaserver |
2535 | bool LoginBox::check_password() { |
2536 | // Try to connect to the metaserver |
2537 | - Section& s = g_options.pull_section("global"); |
2538 | - const std::string& meta = s.get_string("metaserver", INTERNET_GAMING_METASERVER.c_str()); |
2539 | - uint32_t port = s.get_natural("metaserverport", kInternetGamingPort); |
2540 | + const std::string& meta = get_config_string("metaserver", INTERNET_GAMING_METASERVER.c_str()); |
2541 | + uint32_t port = get_config_natural("metaserverport", kInternetGamingPort); |
2542 | std::string password = crypto::sha1(eb_password->text()); |
2543 | |
2544 | if (!InternetGaming::ref().check_password(get_nickname(), password, meta, port)) { |
2545 | @@ -208,7 +204,7 @@ |
2546 | // be copied to another system and used to log in as the user on the metaserver. Further note: |
2547 | // SHA-1 is considered broken and shouldn't be used anymore. But since the passwords on the |
2548 | // server are protected by SHA-1 we have to use it here, too |
2549 | - s.set_string("password_sha1", password); |
2550 | + set_config_string("password_sha1", password); |
2551 | InternetGaming::ref().logout(); |
2552 | return true; |
2553 | } |
2554 | |
2555 | === modified file 'src/wui/mapview.cc' |
2556 | --- src/wui/mapview.cc 2019-08-10 16:38:15 +0000 |
2557 | +++ src/wui/mapview.cc 2019-08-27 19:00:46 +0000 |
2558 | @@ -24,8 +24,8 @@ |
2559 | #include "base/macros.h" |
2560 | #include "base/math.h" |
2561 | #include "graphic/rendertarget.h" |
2562 | -#include "profile/profile.h" |
2563 | #include "wlapplication.h" |
2564 | +#include "wlapplication_options.h" |
2565 | #include "wui/mapviewpixelfunctions.h" |
2566 | |
2567 | namespace { |
2568 | @@ -296,7 +296,7 @@ |
2569 | MapView::MapView( |
2570 | UI::Panel* parent, const Widelands::Map& map, int32_t x, int32_t y, uint32_t w, uint32_t h) |
2571 | : UI::Panel(parent, x, y, w, h), |
2572 | - animate_map_panning_(g_options.pull_section("global").get_bool("animate_map_panning", true)), |
2573 | + animate_map_panning_(get_config_bool("animate_map_panning", true)), |
2574 | map_(map), |
2575 | view_(), |
2576 | last_mouse_pos_(Vector2i::zero()), |
2577 | |
2578 | === modified file 'src/wui/watchwindow.cc' |
2579 | --- src/wui/watchwindow.cc 2019-04-26 06:35:15 +0000 |
2580 | +++ src/wui/watchwindow.cc 2019-08-27 19:00:46 +0000 |
2581 | @@ -30,7 +30,7 @@ |
2582 | #include "logic/map.h" |
2583 | #include "logic/map_objects/bob.h" |
2584 | #include "logic/player.h" |
2585 | -#include "profile/profile.h" |
2586 | +#include "wlapplication_options.h" |
2587 | #include "wui/interactive_gamebase.h" |
2588 | #include "wui/interactive_player.h" |
2589 | #include "wui/mapviewpixelconstants.h" |
2590 | @@ -305,7 +305,7 @@ |
2591 | =============== |
2592 | */ |
2593 | WatchWindow* show_watch_window(InteractiveGameBase& parent, const Widelands::Coords& coords) { |
2594 | - if (g_options.pull_section("global").get_bool("single_watchwin", false)) { |
2595 | + if (get_config_bool("single_watchwin", false)) { |
2596 | if (!g_watch_window) { |
2597 | g_watch_window = new WatchWindow(parent, 250, 150, 200, 200, true); |
2598 | } |
Continuous integration builds have changed state:
Travis build 3597. State: errored. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 389472179. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ lucki1_ widelands_ add_xdg_ support- 3400.
Appveyor build 3400. State: success. Details: https:/