Commit graph

52 commits

Author SHA1 Message Date
Celtic Minstrel
3ac7f8d970 NULL -> nullptr
A few cases of NULL were missed, since changing them led to errors
(Mainly instances where it was passed to a boost::function)
2016-03-31 00:42:38 -04:00
gfgtdf
f1a42c87cf automatically create parent directories when writing to a file. 2016-01-29 22:48:02 +01:00
gfgtdf
3448e35c2b fixup a boost version check 2016-01-29 22:48:00 +01:00
gfgtdf
c39569c693 remove file_exists check in get_user_data_path()
this check really did more harm than good because:
1) It possible that the directory is removed just after the function was
called but before the returned string was used.
2) It's slow.

Instead of checking the existence here the game now tries to create
directories in ofstream when they don't exist yet. (commit will follow)
2016-01-29 22:47:58 +01:00
Jyrki Vesterinen
702be57481 Fixed: filesystem::get_exe_dir() returned a wrong directory on Windows
It returned the current directory, not the EXE directory.
2016-01-20 19:54:45 +02:00
gfgtdf
0f8998d121 PREFERENCES_DIR macro now works on windows too. 2016-01-18 18:21:20 +01:00
Elvish_Hunter
9b7b1751fd Removed trailing tabs and whitespaces from C++ source
I used this command line: find <source directory> -name \*.\[ch\]pp -print0 | xargs -0 sed -i 's/[[:blank:]]*$//'
2015-12-21 20:39:46 +01:00
Ignacio R. Morelle
aae8e70c7a log/windows: Add our own stdout/stderr redirection on Windows
This replaces SDL 1.2's built-in stdout/stderr redirection, which writes
the log file to the process working directory (usually an
admin-restricted location) instead of a more accessible user-writable
location.

My approach combines stdout and stderr into a single log file which
includes the process id and timestamp in its filename in order to
accomodate multiple instances and (coming later) log rotation. The log
file is created in the user's temporary directory defined by Windows,
and then relocated to the game user data dir as soon as it is set-up the
first time, placed in the Windows-specific logs/ subdir.

The most pressing issues this solves are the lack of built-in
stdout/stderr redirection in SDL 2's SDL2main.lib entry point, and
Unicode path issues with SDL 1.2 (bug #22897). Additionally, it allows
us to not have to rely on UAC virtualization anymore; this is arguably
far more important because it has been known to break on occasion (e.g.
<http://r.wesnoth.org/t42970>), and starting with version 1.13.2 we want
to declare Windows Vista - 10 compatibility in our side-by-side manifest
(see commit e119f4071f).

Currently missing features coming later:

 * Log rotation (otherwise the logs/ dir may grow forever)
 * wesnothd support (although the code is already required to be linked
   into wesnothd due to it being required by the FS API)
 * Integration with the version info dialog
2015-11-23 03:21:42 -03:00
Ignacio R. Morelle
8f8fde43ba fs: Use SHGetFolderPath() instead of SHGetSpecialFolderPath()
The former has been "unsupported" since Windows XP, while the latter is
still supported in Vista and later as a wrapper around a newer API.

Most importantly, used this as an excuse to rewrite the code to take
advantage of the fact that we already link to SHELL32.DLL at runtime
(it implements ShellExecute() and Shell_NotifyIcon(), used elsewhere in
our code), only run on versions of Windows guarantee to provide the
SHGetFolderPath symbol, and thus don't need all the LoadLibrary mumbo
jumbo that made the code considerably uglier and denser.
2015-10-20 22:52:31 -03:00
Ignacio R. Morelle
bc22ec9176 fs: Treat . and .. in userdata/config paths relative to cwd on Windows
This allows asking Wesnoth to store user files in a directory relative
to the install dir if wanted on Windows (e.g. for portable installs to
removable media where the absolute path to the install dir is not
constant or under the user's control).
2015-10-20 22:02:56 -03:00
Ignacio R. Morelle
795dd8c420 fs: Default to Documents for user config/data on Windows
Use Documents\My Games\WesnothX.Y for user config data on Windows like
we currently do when using --config-dir there with a relative path. The
behavior of --config-dir when passed a relative path remains unchanged
with this commit, making the new out-of-the-box default equivalent to
passing --config-dir WesnothX.Y, except this is now enforced by Wesnoth
rather than a finicky installer option.

See bug #23753 for the rationale behind this change.

People who really can't live without the old CWD\userdata layout should
either use --config-dir with an absolute path to their existing userdata
dir, or wait for the next commit (which will help with "portable"
installs to removable devices, for example).
2015-10-20 20:53:41 -03:00
Ignacio R. Morelle
1fe5134e73 fs: Clean up Windows-specific code in set_user_data_dir()
No functional changes. Probably. More about this in the next commit.
2015-10-20 20:53:41 -03:00
Quentin Pradet
f71784a05b Fix get_exe_dir on OS X
Except on Windows, this detects procfs before using it instead of trying
to detect the OS.
2015-08-30 10:05:28 +04:00
Ignacio R. Morelle
b2738ffb2f Use looks_like_pbl() to disallow .pbl file inclusion (bug #23504)
This function is implemented using case-insensitive pattern matching,
unlike filesystem::ends_with(). I missed this when writing my original
fix, so the vulnerability still applied to .pbl files on a
case-insensitive filesystem (e.g. NTFS and FAT* on Windows) by using
different case to bypass the check.
2015-06-16 23:24:30 -03:00
Ignacio R. Morelle
f891446818 Disallow inclusion of .pbl files from WML (bug #23504)
Note that this will also cause Lua wesnoth.have_file() to return false
on .pbl files.
2015-06-09 06:19:17 -03:00
Ignacio R. Morelle
542b3a2904 fs: Demote a few BFS-specific error log statements to info level
Some of these don't even exist in the legacy non-BFS implementation, but
it's possible they might prove useful for debugging later.

Fixes some spurious errors printed when browsing directories outside the
user's home dir on Linux/*BSD/etc., as well as a few recently introduced
in the GUI2 test suite by commit
db28dca52c.
2015-04-12 02:16:52 -03:00
gfgtdf
5a55d7ee01 fixup 20e9706c11
that commit changed uintmax_t to be 4 bytes long instead of 8 bytes long in windows which makes us uncapable to read files >4GB.

boost::filesystem::file_size retrun type is boost::uintmax_t so we don't need to include files for this line.
2015-04-10 00:29:09 +02:00
Ignacio R. Morelle
1c927c8407 fs: Prevent the BFS version of get_wml_location() from escaping the data dir
This is essentially a port to the BFS implementation of the fs API of
commits 314425ab0e and
9f458d1bb2, which were authored separately
from the BFS branch.

Note that this introduces another disparity in behavior between the BFS
and legacy implementations of this API, in that the BFS
get_wml_location() function will now always start at <data dir>/data/
instead of starting at <data dir> in obscure border cases. This is
expected to have no impact on anything at all for reasons discussed on
IRC.
2015-04-04 23:40:41 -03:00
gfgtdf
d12c594d90 fix crash when failing to save file.
https://gna.org/bugs/index.php?23301
2015-02-25 17:05:59 +01:00
Ignacio R. Morelle
9d1ecacbb1 fs: Quietly ignore non-dir targets in get_files_in_dir() (BFS only)
The non-BFS implementation already ignored this case without making
noise in stderr, and this function is used by delete_directory(), which
also accepts both regular files and directories. The add-ons management
code has always relied on this behavior.
2014-12-23 22:46:36 -03:00
Chris Beck
6dfb9d156d fixup HEAD^ 2014-12-10 14:29:06 -05:00
Chris Beck
20e9706c11 refactor commit 3f3687388f 2014-12-10 14:08:02 -05:00
anonymissimus
69394df46b add and use constructor (instead of assignment)
This fixes a MSVC warning about "cannot instantiate
customcodecvt_do_conversion_writer".
2014-11-30 18:32:37 +01:00
anonymissimus
3f3687388f replace typedef'ed type uintmax_t by its long form unsigned long long
It seems this type is not yet available in MSVC9, only in later versions.
2014-11-30 18:32:36 +01:00
gfgtdf
b4d49a3675 fix windows document folder name with unicode usernames
http://gna.org/bugs/?22983
2014-11-26 04:21:59 +01:00
Ignacio R. Morelle
8e3428e6a3 fs: Don't complain about failing to read /proc/self/exe with Boost.filesystem
This is intended to silently fail on Unix-like platforms where no procfs
is available, and indeed that's how it works in the non-BFS
implementation of get_exe_dir(). The caller (currently a single function
in game.cpp/wesnoth.cpp) must be able to deal with this situation
in a graceful fashion.
2014-11-20 00:35:03 -03:00
gfgtdf
115c2a7985 use generic_string()
this fixes a bug which caused that _final.cfg wasn't included last
becasue we compared a string with "/_final.cfg". By using
generic_string() we make sure that the seperators are '/'.

http://gna.org/bugs/?22967
2014-11-18 04:38:10 +01:00
Ignacio R. Morelle
c293e20d25 fs: Fix relative directory creation incongruity with Boost.filesystem
The non-BFS version of create_directory_if_missing_recursive() handles
relative path names (e.g. "foo") correctly and doesn't attempt to create
a parent that is left unspecified in the path (i.e. empty), but the BFS
version does, predictably failing the whole operation.

This fixes an issue where `./wesnoth -p data foo` from the source tree
would fail with `error filesystem: Could not create parents to foo` if
`foo` did not already exist, when using the Boost.filesystem-based
implementation. `./wesnoth -p data ./foo` would succeed because there is
a visible parent directory '.' that already exists and needs not be
created again.
2014-11-09 19:01:13 -03:00
Ignacio R. Morelle
10f9187150 fs: Fix normalize_path("") incongruity with Boost.filesystem
The non-BFS version of normalize_path() returns an empty string when
passed an empty string, but the BFS version returns the normalized
version of the current working dir for the Wesnoth process.

Due to the way editor::start()'s arguments are built from the process
command line, the result of normalize_path("") gets passed to it when
starting with the --editor switch and no map path argument. If the
result describes a directory, the editor brings up the filechooser
dialog on that path; otherwise, it attempts to open it as a map file.

Making the BFS version of normalize_path() follow the non-BFS behavior
fixes the editor unexpectedly bringing up the filechooser when started
from the command line.
2014-11-08 02:31:21 -03:00
gfgtdf
0586becbfa add custom codecvt for better error mesages.
this codecvt gibes errormessages in LOG_FS if it meets an invalid utf8 char.
also the boost codecvt seems inconsistetn becasue it seems on msvc it acepts utf8 AND ansi while it only accpets ansi on mingw.
2014-10-23 14:49:17 +02:00
gfgtdf
66712590d0 add boost 1.44 comability
it seems like iostream from boost 1.44 is incompatible to filesystem
from boost  1.44.
Actualy i didnt veryfy this becasue i don't have boost < 1.50. I added
an adapter for boost filesystem that made it looks liek filesystem 1.43
which we can pass to boost iostreams 1.44.
2014-10-21 18:12:37 +02:00
gfgtdf
c27fb4d00e fix filesystem_boost.cpp on mingw
this raises our dependency for boost iostream to 1.44 or above
2014-10-21 18:12:36 +02:00
gfgtdf
e3818c2843 reenable ".." in get_binary_file_location
this was also how ".." behaved in the old code.
2014-10-18 04:17:01 +02:00
gfgtdf
0ba4e1488f use utf8 in boost filesystem on windows
code from 0e6a10a8c5ce8a48eb18c025547e3d30b5509349 and
e37f34b5cd.
I put it into #ifdefs becasue idk whether i chould/can raise the boost
dependency on linux to 1.48
2014-10-17 17:26:37 +02:00
gfgtdf
b247d86910 ignore files that begin with '.'
this is also the behaviour in the non boost filesystem code
2014-10-17 16:41:25 +02:00
gfgtdf
e038938a73 Merge branch 'boost_filesystem' of https://github.com/AI0867/wesnoth into AI-boost_filesystem_3
Conflicts:
	.travis.yml
	SConstruct
	src/campaign_server/campaign_server.cpp
	src/create_engine.cpp
	src/editor/map/map_context.cpp
	src/game_config_manager.cpp
	src/gui/dialogs/screenshot_notification.cpp
	src/gui/dialogs/wml_error.cpp
	src/savegame.cpp
2014-10-17 16:40:45 +02:00
Alexander van Gessel
a27b2ff4a7 Create userdata/editor/scenarios 2014-04-09 17:21:33 +02:00
Alexander van Gessel
1d19bb949a Get rid of some #ifdef'd usage of a variable that no longer exists 2014-04-09 15:28:42 +02:00
Alexander van Gessel
a5d5266197 Remove unused variable 2014-04-09 12:24:18 +02:00
Alexander van Gessel
5df2e0c727 Factor out a common expression 2014-04-09 12:21:57 +02:00
Alexander van Gessel
a6633c81df Don't fail on file_not_found if that's what you're checking for 2014-04-09 12:17:36 +02:00
Alexander van Gessel
d2590b096f Remove a redundant function call 2014-04-09 11:47:16 +02:00
Alexander van Gessel
ed8feb3d89 Fix some error messages 2014-04-09 11:47:01 +02:00
Alexander van Gessel
67d462e21b Merge branch 'master' into boost_filesystem
Conflicts:
	.travis.yml
	SConstruct
	src/addon/manager.cpp
	src/campaign_server/campaign_server.cpp
	src/editor/map/context_manager.cpp
	src/editor/map/map_context.cpp
	src/filesystem.cpp
	src/filesystem.hpp
	src/game.cpp
	src/game_config_manager.cpp
	src/gui/dialogs/editor/custom_tod.cpp
	src/gui/dialogs/lobby/lobby_data.cpp
	src/gui/dialogs/mp_create_game.cpp
	src/gui/widgets/settings.cpp
	src/hotkeys.cpp
	src/multiplayer_create_engine.cpp
	src/multiplayer_lobby.cpp
	src/network.cpp
	src/savegame.cpp
	src/serialization/preprocessor.cpp
	src/widgets/button.cpp
	src/windows_tray_notification.hpp
2014-04-08 17:42:32 +02:00
Alexander van Gessel
ce5d5d5774 Win32 API fixes 2014-04-07 01:06:48 +02:00
Alexander van Gessel (AI0867)
bbb83d3f93 We don't need filesystem_win32.ii, just windows.h 2013-11-27 13:30:11 +01:00
Alexander van Gessel (AI0867)
037e1c1299 Windows uses a different error when a directory in a path doesn't exist 2013-11-27 13:30:10 +01:00
Alexander van Gessel (AI0867)
12e02a9ccb Get rid of some const-reference-to-temporary warnings 2013-11-27 13:22:45 +01:00
Alexander van Gessel (AI0867)
fa95dafd63 Log the error message when complaining about there being an error 2013-11-27 13:22:45 +01:00
Alexander van Gessel (AI0867)
e4f7d7093b Some windows-related fixes 2013-11-27 13:22:44 +01:00