Skip to content

Commit

Permalink
Merge branch 'feature/win32-stdio-redir'
Browse files Browse the repository at this point in the history
  • Loading branch information
irydacea committed Nov 23, 2015
2 parents a7bb6b1 + 758f929 commit 71009d9
Show file tree
Hide file tree
Showing 14 changed files with 682 additions and 141 deletions.
6 changes: 6 additions & 0 deletions RELEASE_NOTES
Expand Up @@ -57,6 +57,12 @@ See also bug [bug]23753[/bug].
[/list]
[/rasection]

[rasection="New log files location on Windows"]
From this release onwards, Wesnoth no longer writes its stdout/stderr logs to [tt]stdout.txt[/tt]/[tt]stderr.txt[/tt] in the installation path. Instead, a single combined log file is written to [tt]<user data dir>\logs\wesnoth-<TIMESTAMP>-<PID>.log[/tt] containing all stdout [b]and[/b] stderr output. Up to 8 older log files are kept around, the rest being automatically deleted at game startup. Note that if an early startup failure occurs, the log file will be found at [tt]%TEMP%\wesnoth-<TIMESTAMP>-<PID>.log[/tt] instead.

Since this replaces SDL 1.2's buggy built-in stdout/stderr redirection code with a Unicode-aware alternative, this also fixes bug [bug]22897[/bug].
[/rasection]

[rasection="New game version dialog"]
Describe how awesome the new game version dialog is and how it replaces the old game paths dialog from 1.12.x
[/rasection]
Expand Down
6 changes: 6 additions & 0 deletions changelog
Expand Up @@ -162,6 +162,12 @@ Version 1.13.1+dev:
explicitly use . or .. (e.g. `--config-dir .\userdata`) to force the
user config+data dir path to be relative to the current working dir (see
also bug #23753).
* Wesnoth now uses combined stdout+stderr log files on Windows, moved to
<user data dir>\logs during initialization and first created in the user's
temporary files directory defined by Windows. Log files are named like
"wesnoth-<TIMESTAMP>-<PID>.log" and up to 8 log files are kept along with
the latest session's log file. This avoids issues caused by SDL 1.2's
built-in redirection code not being Unicode-aware (fixes bug #22897).
* Removed legacy filesystem API implementation.
* Fixed Generate Map dialog bug that caused last choice of map
generator to not be actually selected (bug #23711).
Expand Down
5 changes: 3 additions & 2 deletions projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -251,8 +251,6 @@
<Unit filename="../../src/desktop/open.hpp" />
<Unit filename="../../src/desktop/version.cpp" />
<Unit filename="../../src/desktop/version.hpp" />
<Unit filename="../../src/desktop/windows_console.cpp" />
<Unit filename="../../src/desktop/windows_console.hpp" />
<Unit filename="../../src/desktop/windows_tray_notification.cpp" />
<Unit filename="../../src/desktop/windows_tray_notification.hpp" />
<Unit filename="../../src/dialogs.cpp" />
Expand Down Expand Up @@ -868,12 +866,15 @@
<Unit filename="../../src/leader_scroll_dialog.cpp" />
<Unit filename="../../src/leader_scroll_dialog.hpp" />
<Unit filename="../../src/lexical_cast.hpp" />
<Unit filename="../../src/libc_error.hpp" />
<Unit filename="../../src/loadscreen.cpp" />
<Unit filename="../../src/loadscreen.hpp" />
<Unit filename="../../src/lobby_preferences.cpp" />
<Unit filename="../../src/lobby_preferences.hpp" />
<Unit filename="../../src/log.cpp" />
<Unit filename="../../src/log.hpp" />
<Unit filename="../../src/log_windows.cpp" />
<Unit filename="../../src/log_windows.hpp" />
<Unit filename="../../src/lua/lapi.h" />
<Unit filename="../../src/lua/lauxlib.h" />
<Unit filename="../../src/lua/lcode.h" />
Expand Down
3 changes: 3 additions & 0 deletions projectfiles/CodeBlocks/wesnothd.cbp
Expand Up @@ -70,10 +70,13 @@
<Unit filename="../../src/gettext.hpp" />
<Unit filename="../../src/gettext_boost.cpp" />
<Unit filename="../../src/global.hpp" />
<Unit filename="../../src/libc_error.hpp" />
<Unit filename="../../src/loadscreen.hpp" />
<Unit filename="../../src/loadscreen_empty.cpp" />
<Unit filename="../../src/log.cpp" />
<Unit filename="../../src/log.hpp" />
<Unit filename="../../src/log_windows.cpp" />
<Unit filename="../../src/log_windows.hpp" />
<Unit filename="../../src/map.hpp" />
<Unit filename="../../src/mt_rng.cpp" />
<Unit filename="../../src/mt_rng.hpp" />
Expand Down
7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -288,6 +288,12 @@ else()
)
endif()

if(WIN32)
set(libwesnoth-core_STAT_SRC
${libwesnoth-core_STAT_SRC}
log_windows.cpp
)

# a 'lib' is automatically set in front when creating the library (as in the filename)
# internal reference is the name given here
add_library(wesnoth-core ${LIBRARY_TYPE} EXCLUDE_FROM_ALL ${libwesnoth-core_STAT_SRC})
Expand Down Expand Up @@ -1142,7 +1148,6 @@ set(libwesnoth-game_STAT_SRC
if(WIN32)
set(libwesnoth-game_STAT_SRC
${libwesnoth-game_STAT_SRC}
desktop/windows_console.cpp
desktop/windows_tray_notification.cpp
)
endif(WIN32)
Expand Down
6 changes: 5 additions & 1 deletion src/SConscript
Expand Up @@ -69,6 +69,11 @@ libwesnoth_core_sources.extend([
filesystem_env.Object("filesystem_boost.cpp")
])

if env["PLATFORM"] == "win32":
libwesnoth_core_sources.extend([
filesystem_env.Object("log_windows.cpp")
])

if env["libintl"]:
libwesnoth_core_sources.extend([
filesystem_env.Object("gettext.cpp")
Expand Down Expand Up @@ -630,7 +635,6 @@ wesnoth_sources = Split("""

if env["PLATFORM"] == "win32":
wesnoth_sources.append("desktop/windows_tray_notification.cpp")
wesnoth_sources.append("desktop/windows_console.cpp")

if env["PLATFORM"] == 'darwin':
wesnoth_sources.append("desktop/apple_notification.mm")
Expand Down
101 changes: 0 additions & 101 deletions src/desktop/windows_console.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions src/desktop/windows_console.hpp

This file was deleted.

7 changes: 7 additions & 0 deletions src/filesystem_boost.cpp
Expand Up @@ -34,7 +34,10 @@
using boost::uintmax_t;

#ifdef _WIN32
#include "log_windows.hpp"

#include <boost/locale.hpp>

#include <windows.h>
#include <shlobj.h>
#endif /* !_WIN32 */
Expand Down Expand Up @@ -478,6 +481,10 @@ static void setup_user_data_dir()
create_directory_if_missing(user_data_dir / "data" / "add-ons");
create_directory_if_missing(user_data_dir / "saves");
create_directory_if_missing(user_data_dir / "persist");

#ifdef _WIN32
lg::finish_log_file_setup();
#endif
}

#ifdef _WIN32
Expand Down
10 changes: 5 additions & 5 deletions src/gui/dialogs/game_version.cpp
Expand Up @@ -20,9 +20,6 @@
#include "desktop/clipboard.hpp"
#include "desktop/open.hpp"
#include "desktop/version.hpp"
#ifdef _WIN32
#include "desktop/windows_console.hpp"
#endif
#include "filesystem.hpp"
#include "formula_string_utils.hpp"
#include "game_config.hpp"
Expand All @@ -41,6 +38,9 @@
#include "gui/widgets/stacked_widget.hpp"
#include "gui/widgets/text.hpp"
#include "gui/widgets/window.hpp"
#ifdef _WIN32
#include "log_windows.hpp"
#endif
#include "serialization/string_utils.hpp"

#include "gettext.hpp"
Expand Down Expand Up @@ -93,7 +93,7 @@ tgame_version::tgame_version()
, browse_wid_stem_("browse_")
, path_map_()
#ifdef _WIN32
, log_path_(game_config::wesnoth_program_dir + "\\stderr.txt")
, log_path_(lg::log_file_path())
#endif
, deps_()
, opts_(game_config::optional_features_table())
Expand Down Expand Up @@ -199,7 +199,7 @@ void tgame_version::pre_show(CVideo& /*video*/, twindow& window)
boost::bind(&tgame_version::browse_directory_callback,
this,
log_path_));
stderr_button.set_active(!desktop::is_win32_console_enabled());
stderr_button.set_active(!log_path_.empty());
#endif

//
Expand Down
42 changes: 42 additions & 0 deletions src/libc_error.hpp
@@ -0,0 +1,42 @@
/*
By Ignacio Riquelme Morelle <shadowm2006@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
The contents of this file are placed in the public domain.
*/

#include <cerrno>
#include <cstring>
#include <string>

#ifndef LIBC_ERROR_HPP_INCLUDED
#define LIBC_ERROR_HPP_INCLUDED

/**
* Exception type used to propagate C runtime errors across functions.
*/
class libc_error
{
public:
libc_error(): e_(errno), msg_(strerror(e_))
{
}

/** Returns the value of @a errno at the time the exception was thrown. */
int num() const
{
return e_;
}

/** Returns an explanatory string describing the runtime error. */
const std::string& desc() const
{
return msg_;
}

private:
int e_;
std::string msg_;
};

#endif

0 comments on commit 71009d9

Please sign in to comment.