[springlobby] 01/03: Imported Upstream version 0.252+dfsg

Markus Koschany apo at moszumanska.debian.org
Sat Jul 23 20:16:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

apo pushed a commit to branch master
in repository springlobby.

commit cf92e7dc5898f0748df5858df0a655e71358adba
Author: Markus Koschany <apo at debian.org>
Date:   Sat Jul 23 21:42:26 2016 +0200

    Imported Upstream version 0.252+dfsg
---
 ChangeLog              |  10 ++++
 VERSION                |   2 +-
 springlobby_config.h   |   2 +-
 src/CMakeLists.txt     |   1 +
 src/chatlog.cpp        |  11 ++---
 src/chatlog.h          |   2 +-
 src/gui/chatpanel.cpp  | 128 ++++++++++++++++++++++++++++---------------------
 src/gui/infodialog.cpp |  68 +-------------------------
 src/springlobbyapp.cpp |   4 +-
 src/sysinfo.cpp        |  86 +++++++++++++++++++++++++++++++++
 src/sysinfo.h          |   4 ++
 src/tests/chatlog.cpp  |   9 ++--
 src/utils/slpaths.cpp  |   5 --
 src/utils/slpaths.h    |   1 -
 14 files changed, 192 insertions(+), 141 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c64c1dd..04bbceb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 ChangeLog of Springlobby
 
+## 0.252
+ - log help->system info into springlobby.log
+ - some cleanup
+
+## 0.251
+ - slightly refactor irc colors handling
+
+## 0.250
+ - heavily increase performance of chat output (fixes a DoS)
+
 ## 0.249
  - fix crash when parsing .sdfz (compressed spring demo file)
  - fix crash with broken SpringData dirs
diff --git a/VERSION b/VERSION
index 96be840..f850828 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.249
+0.252
diff --git a/springlobby_config.h b/springlobby_config.h
index 807fe9a..931ae62 100644
--- a/springlobby_config.h
+++ b/springlobby_config.h
@@ -6,6 +6,6 @@
 #undef VERSION
 
 /* the git tag / commit we build from */
-#define VERSION "0.249"
+#define VERSION "0.252"
 
 #endif	/* SPRINGLOBBY_HEADERGUARD_CONFIG_H */
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a754643..502e354 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -162,6 +162,7 @@ set(springlobbySrc
 	spring.cpp
 	springlobbyapp.cpp
 	springprocess.cpp
+	sysinfo.cpp
 	tasserver.cpp
 	user.cpp
 	useractions.cpp
diff --git a/src/chatlog.cpp b/src/chatlog.cpp
index 7f5c5a1..ca5a0fb 100644
--- a/src/chatlog.cpp
+++ b/src/chatlog.cpp
@@ -7,7 +7,6 @@
 #include <wx/file.h>
 #include <wx/filefn.h>
 #include <wx/dir.h>
-#include <wx/datetime.h>
 #include <wx/intl.h>
 #include <wx/filename.h>
 #include <wx/log.h>
@@ -72,13 +71,13 @@ void ChatLog::CloseSession()
 		return;
 	}
 
-	AddMessage(wxEmptyString, _("### Session Closed at [%Y-%m-%d %H:%M]"));
+	AddMessage(wxDateTime::Now().Format(_("### Session Closed at [%Y-%m-%d %H:%M]")));
 	m_logfile.Flush();
 	m_active = false;
 	m_logfile.Close();
 }
 
-bool ChatLog::AddMessage(const wxString& text, const wxString& timeformat)
+bool ChatLog::AddMessage(const wxString& text)
 {
 	if (!LogEnabled()) {
 		return true;
@@ -86,8 +85,7 @@ bool ChatLog::AddMessage(const wxString& text, const wxString& timeformat)
 	if (!m_active) { //logging is enabled, logfile should be writeable
 		return false;
 	}
-	wxString logtime = wxDateTime::Now().Format(timeformat);
-	const bool res = m_logfile.Write(logtime + text + wxTextBuffer::GetEOL(), wxConvUTF8);
+	const bool res = m_logfile.Write(text + wxTextBuffer::GetEOL(), wxConvUTF8);
 	if (!res) {
 		wxLogWarning(_T("Couldn't write to %s"), m_logname.c_str());
 		m_logfile.Close();
@@ -135,7 +133,7 @@ bool ChatLog::OpenLogFile()
 	FillLastLineArray();
 	m_active = true;
 
-	return AddMessage(wxEmptyString, _T( "### Session Start at [%Y-%m-%d %H:%M]" ));
+	return AddMessage(wxDateTime::Now().Format(_( "### Session Start at [%Y-%m-%d %H:%M]" )));
 }
 
 const wxArrayString& ChatLog::GetLastLines() const
@@ -299,4 +297,5 @@ void ChatLog::FillLastLineArray()
 #ifdef WIN32
 	delete[] eol;
 #endif
+	m_logfile.SeekEnd();
 }
diff --git a/src/chatlog.h b/src/chatlog.h
index 1a37b1f..59f4ea9 100644
--- a/src/chatlog.h
+++ b/src/chatlog.h
@@ -40,7 +40,7 @@ public:
 	 *
 	 * @see LogEnabled LogTime
 	 */
-	bool AddMessage(const wxString& text, const wxString& timeformat = _T("[%H:%M:%S] "));
+	bool AddMessage(const wxString& text);
 
 	/** Check if chat logging is enabled.
 	 *
diff --git a/src/gui/chatpanel.cpp b/src/gui/chatpanel.cpp
index 8fc2d10..d22341f 100644
--- a/src/gui/chatpanel.cpp
+++ b/src/gui/chatpanel.cpp
@@ -379,17 +379,14 @@ void ChatPanel::OutputLine(const wxString& message, const wxColour& col, bool sh
 	if (!m_chatlog_text)
 		return;
 
-	wxDateTime now = wxDateTime::Now();
-	wxTextAttr timestyle(sett().GetChatColorTime(), sett().GetChatColorBackground());
-	wxTextAttr chatstyle(col, sett().GetChatColorBackground());
-
 	ChatLine newline;
-	newline.chat = wxString(message.c_str());
-	newline.chatstyle = chatstyle;
+	newline.chat = message;
+	newline.chatstyle = wxTextAttr(col, sett().GetChatColorBackground());
 	if (showtime) {
+		wxDateTime now = wxDateTime::Now();
 		newline.time = _T( "[" ) + now.Format(_T( "%H:%M:%S" )) + _T( "]" );
-		newline.timestyle = timestyle;
-		m_chat_log.AddMessage(message);
+		newline.timestyle = wxTextAttr(sett().GetChatColorTime(), sett().GetChatColorBackground());
+		m_chat_log.AddMessage(newline.time + _T(" ") + message);
 	} else {
 		newline.time.clear();
 	}
@@ -401,7 +398,6 @@ void ChatPanel::OutputLine(const wxString& message, const wxColour& col, bool sh
 	}
 }
 
-
 void ChatPanel::OutputLine(const ChatLine& line)
 {
 	const int numOfLines = m_chatlog_text->GetNumberOfLines();
@@ -420,7 +416,9 @@ void ChatPanel::OutputLine(const ChatLine& line)
 
 	if (!line.time.empty()) {
 		m_chatlog_text->SetDefaultStyle(line.timestyle);
-		m_chatlog_text->AppendText(line.time);
+		m_chatlog_text->AppendText(line.time + _T(" "));
+	} else {
+		m_chatlog_text->SetDefaultStyle(line.chatstyle);
 	}
 
 #ifndef __WXOSX_COCOA__
@@ -436,30 +434,15 @@ void ChatPanel::OutputLine(const ChatLine& line)
 		const wxColor oldcolor(line.chatstyle.GetTextColour());
 
 		while (m1.Len() > 0) {
-			const wxUniChar c = m1.GetChar(0);
-			if (c == 3 && m1.Len() > 1 && (m1.GetChar(1) >= 48 && m1.GetChar(1) <= 58)) { // Color
-				if (m1.Len() > 2 && (m1.GetChar(2) >= 48 && m1.GetChar(2) <= 58)) {
-					color = (int(m1.GetChar(1)) - 48) * 10 + (int(m1.GetChar(2)) - 48);
-					m1 = m1.Mid(3);
-				} else {
-					color = int(m1.GetChar(1)) - 48;
-					m1 = m1.Mid(2);
-				}
-
-				wxColor dummy(0, 0, 0);
-				if ((color > -1) && (color < long((sizeof(m_irc_colors) / sizeof(dummy))))) {
-					curcolor = m_irc_colors[color];
-				}
-
-			} else if (c == 2) { //Bold
-				bold = !bold;
-				m1 = m1.Mid(1);
-			} else if (c == 0x0F) { //Reset formatting
-				bold = false;
-				curcolor = oldcolor;
-				m1 = m1.Mid(1);
-			} else {
-
+			wxUniChar c = m1.GetChar(0);
+			wxUniChar tmp = c;
+			size_t len = 0;
+			unsigned char uc = c;
+			while(uc!=0x1f && uc!=0x1d && uc!=0x03 && uc!=0x02 && uc!=0x016 && uc!=0x0F && len < m1.Len()) { //get all text until first irc color is found
+				c = tmp;
+				tmp = m1.GetChar(len++);
+			}
+			if (len > 0) { //unformated text found, add as whole
 				wxFont font = oldfont; //isn't needed any more in wx3.0
 				at = line.chatstyle;
 				if (bold)
@@ -467,9 +450,44 @@ void ChatPanel::OutputLine(const ChatLine& line)
 				at.SetFont(font);
 				at.SetTextColour(curcolor);
 				m_chatlog_text->SetDefaultStyle(at);
-				m_chatlog_text->AppendText(m1.Mid(0, 1));
-				m1 = m1.Mid(1);
+				m_chatlog_text->AppendText(m1.Mid(0, len));
+				m1 = m1.Mid(len);
+				if (m1.Len() <= 0) { //no chars left, abort
+					break;
+				}
+			}
+			uc = c;
+			switch(uc) { //  http://en.wikichip.org/wiki/irc/colors
+				case 0x1f: //underline
+					break;
+				case 0x1d: //italics
+					break;
+				case 0x03: {
+					if (m1.Len() > 2 && (m1.GetChar(2) >= 48 && m1.GetChar(2) <= 58)) {
+						color = (int(m1.GetChar(1)) - 48) * 10 + (int(m1.GetChar(2)) - 48);
+						m1 = m1.Mid(2); //next chars
+					} else {
+						color = int(m1.GetChar(1)) - 48;
+						m1 = m1.Mid(1); //next char
+					}
+
+					wxColor dummy(0, 0, 0);
+					if ((color > -1) && (color < long((sizeof(m_irc_colors) / sizeof(dummy))))) {
+						curcolor = m_irc_colors[color];
+					}
+					break;
+				}
+				case 0x02: //bold
+					bold = !bold;
+					break;
+				case 0x16: //reverse;
+					break;
+				case 0x0F: //reset formating
+					bold = false;
+					curcolor = oldcolor;
+					break;
 			}
+			m1 = m1.Mid(1); //next char!
 		}
 		m_chatlog_text->AppendText(_T("\n"));
 	} else
@@ -566,9 +584,9 @@ void ChatPanel::Said(const wxString& who, const wxString& message)
 		wxString message2;
 		who2 = message.BeforeFirst('>').AfterFirst('<');
 		message2 = message.AfterFirst('>');
-		OutputLine(_T( " <" ) + who2 + _T( "> " ) + message2, col);
+		OutputLine(_T( "<" ) + who2 + _T( "> " ) + message2, col);
 	} else {
-		OutputLine(_T( " <" ) + who + _T( "> " ) + message, col);
+		OutputLine(_T( "<" ) + who + _T( "> " ) + message, col);
 	}
 
 
@@ -630,7 +648,7 @@ void ChatPanel::DidAction(const wxString& who, const wxString& action)
 
 	// change the image of the tab to show new events
 	SetIconHighlight(highlight_say);
-	OutputLine(_T( " * " ) + who + _T( " " ) + action, sett().GetChatColorAction());
+	OutputLine(_T( "* " ) + who + _T( " " ) + action, sett().GetChatColorAction());
 	if (m_type == CPT_User && (ui().GetActiveChatPanel() != this || !wxTheApp->IsActive())) {
 		const wxString msg = wxString::Format(_T("%s \n%s"), who.c_str(), action.Left(50).c_str());
 		UiEvents::GetNotificationEventSender().SendEvent(
@@ -645,7 +663,7 @@ void ChatPanel::Motd(const wxString& message)
 {
 	// change the image of the tab to show new events
 	SetIconHighlight(highlight_say);
-	OutputLine(_T( " ** motd ** " ) + message, sett().GetChatColorServer());
+	OutputLine(_T( "** motd ** " ) + message, sett().GetChatColorServer());
 }
 
 void ChatPanel::StatusMessage(const wxString& message)
@@ -655,25 +673,25 @@ void ChatPanel::StatusMessage(const wxString& message)
 	} else {
 		if (CPT_Server == m_type)
 			SetIconHighlight(highlight_important);
-		OutputLine(_T( " ** Server ** " ) + message, sett().GetChatColorServer());
+		OutputLine(_T( "** Server ** " ) + message, sett().GetChatColorServer());
 	}
 }
 
 void ChatPanel::ClientMessage(const wxString& message)
 {
-	OutputLine(_T( " ** " ) + message, sett().GetChatColorClient());
+	OutputLine(_T( "** " ) + message, sett().GetChatColorClient());
 }
 
 void ChatPanel::UnknownCommand(const wxString& command, const wxString& params)
 {
 	// change the image of the tab to show new events
 	SetIconHighlight(highlight_important);
-	OutputLine(_(" !! Command: \"") + command + _("\" params: \"") + params + _T( "\"." ), sett().GetChatColorError());
+	OutputLine(_("!! Command: \"") + command + _("\" params: \"") + params + _T( "\"." ), sett().GetChatColorError());
 }
 
 void ChatPanel::OutputError(const wxString& message)
 {
-	OutputLine(wxString::Format(_(" Error: %s"), message.c_str()), sett().GetChatColorError());
+	OutputLine(wxString::Format(_("Error: %s"), message.c_str()), sett().GetChatColorError());
 }
 
 
@@ -696,7 +714,7 @@ void ChatPanel::Joined(User& who)
 		if (m_type == CPT_Channel) {
 			SetIconHighlight(highlight_join_leave);
 		}
-		OutputLine(_T( " ** " ) + wxString::Format(_("%s joined %s."), TowxString(who.GetNick()).c_str(), GetChatTypeStr().c_str()), sett().GetChatColorJoinPart());
+		OutputLine(_T( "** " ) + wxString::Format(_("%s joined %s."), TowxString(who.GetNick()).c_str(), GetChatTypeStr().c_str()), sett().GetChatColorJoinPart());
 	}
 
 	if (m_show_nick_list && (m_nicklist != nullptr)) {
@@ -715,7 +733,7 @@ void ChatPanel::OnChannelJoin(User& who)
 		UpdateUserCountLabel();
 	}
 	if (m_display_joinitem) {
-		OutputLine(_T( " ** " ) + wxString::Format(_("%s joined %s."), TowxString(who.GetNick()).c_str(), GetChatTypeStr().c_str()), sett().GetChatColorJoinPart());
+		OutputLine(_T( "** " ) + wxString::Format(_("%s joined %s."), TowxString(who.GetNick()).c_str(), GetChatTypeStr().c_str()), sett().GetChatColorJoinPart());
 	}
 	// Also add the User to the TextCompletionDatabase
 	textcompletiondatabase.Insert_Mapping(TowxString(who.GetNick()), TowxString(who.GetNick()));
@@ -728,7 +746,7 @@ void ChatPanel::Parted(User& who, const wxString& message)
 	const wxString nick = TowxString(who.GetNick());
 	const bool wasactive = m_active_users.erase(nick) > 0;
 	if (m_display_joinitem || (wasactive && !who.IsBot())) {
-		OutputLine(_T( " ** " ) + wxString::Format(_("%s left %s (%s)."), nick.c_str(), GetChatTypeStr().c_str(), message.c_str()), sett().GetChatColorJoinPart());
+		OutputLine(_T( "** " ) + wxString::Format(_("%s left %s (%s)."), nick.c_str(), GetChatTypeStr().c_str(), message.c_str()), sett().GetChatColorJoinPart());
 	}
 	if (m_type == CPT_Channel) {
 		if (m_channel == 0)
@@ -767,13 +785,13 @@ void ChatPanel::SetTopic(const wxString& who, const wxString& message)
 	// change the image of the tab to show new events
 	if (m_topic_set)
 		SetIconHighlight(highlight_say);
-	OutputLine(_(" ** Channel topic:"), col);
+	OutputLine(_("** Channel topic:"), col);
 	wxStringTokenizer tkz(message, _T("\n"));
 	while (tkz.HasMoreTokens()) {
 		wxString msg = tkz.GetNextToken();
 		OutputLine(_T(" ") + msg, col);
 	}
-	OutputLine(_(" ** Set by ") + who, col);
+	OutputLine(_("** Set by ") + who, col);
 	m_topic_set = true;
 }
 
@@ -917,7 +935,7 @@ bool ChatPanel::Say(const wxString& message) //FIXME: remove all parsing / token
 
 		if (line == _T( "/ver" )) {
 			//!this instance is not replaced with GetAppname for sake of help/debug online
-			OutputLine(_(" You have SpringLobby v") + TowxString(getSpringlobbyVersion()), sett().GetChatColorNormal());
+			OutputLine(_("You have SpringLobby v") + TowxString(getSpringlobbyVersion()), sett().GetChatColorNormal());
 			return true;
 		}
 
@@ -999,7 +1017,7 @@ bool ChatPanel::Say(const wxString& message) //FIXME: remove all parsing / token
 			}
 
 			m_server->SendCmd(STD_STRING(line), "");
-			OutputLine(_(" Sent: \"") + line + _("\""), sett().GetChatColorNormal());
+			OutputLine(_("Sent: \"") + line + _("\""), sett().GetChatColorNormal());
 		}
 	}
 	return true;
@@ -1033,14 +1051,14 @@ void ChatPanel::OnUserDisconnected()
 {
 	// change the image of the tab to show new events
 	SetIconHighlight(highlight_join_leave);
-	OutputLine(_(" ** User is now offline."), sett().GetChatColorJoinPart());
+	OutputLine(_("** User is now offline."), sett().GetChatColorJoinPart());
 }
 
 void ChatPanel::OnUserConnected()
 {
 	// change the image of the tab to show new events
 	SetIconHighlight(highlight_join_leave);
-	OutputLine(_(" ** User just got online."), sett().GetChatColorJoinPart());
+	OutputLine(_("** User just got online."), sett().GetChatColorJoinPart());
 }
 
 
@@ -1166,7 +1184,7 @@ void ChatPanel::SetBattle(IBattle* battle)
 	}
 
 	if (m_battle != NULL) {
-		OutputLine(_(" ** Left Battle."), sett().GetChatColorNotification());
+		OutputLine(_("** Left Battle."), sett().GetChatColorNotification());
 	}
 
 	if (battle == NULL) {
@@ -1174,7 +1192,7 @@ void ChatPanel::SetBattle(IBattle* battle)
 		return;
 	}
 
-	OutputLine(_(" ** Joined Battle."), sett().GetChatColorNotification());
+	OutputLine(_("** Joined Battle."), sett().GetChatColorNotification());
 
 	for (unsigned int i = 0; i < battle->GetNumUsers(); ++i) {
 		const wxString nick = TowxString(battle->GetUser(i).GetNick());
diff --git a/src/gui/infodialog.cpp b/src/gui/infodialog.cpp
index 910be16..33ecfb2 100644
--- a/src/gui/infodialog.cpp
+++ b/src/gui/infodialog.cpp
@@ -4,89 +4,25 @@
 
 #include <wx/sizer.h>
 #include <wx/textctrl.h>
-#include <wx/app.h>
 #include <wx/version.h>
-#include <vector>
-#include <fstream>
 #include <utility>
-#include <wx/filename.h>
 
 #include <lslutils/misc.h>
 
 #include "settings.h"
+#include "sysinfo.h"
 #include "utils/conversion.h"
-#include "utils/version.h"
 #include "utils/platform.h"
-#include "utils/slpaths.h"
-
-#if defined(__unix__) || defined(__APPLE__)
-#include <unistd.h>
-#define WRITABLE W_OK
-#elif defined(__WIN32__) || defined(_MSC_VER)
-#include <io.h>
-#define WRITABLE 02
-#else
-#error "os not supported"
-#endif
-
-inline wxString BtS(bool q, std::string y = "yes", std::string n = "no")
-{
-	return q ? TowxString(y) : TowxString(n);
-}
 
 InfoDialog::InfoDialog(wxWindow* parent)
     : wxDialog(parent, wxID_ANY, _("Paths"), wxDefaultPosition, wxSize(620, 400), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxCLOSE_BOX)
 {
 	m_main_sizer = new wxBoxSizer(wxVERTICAL);
 
-	typedef std::vector<std::pair<std::string, wxString> > Paths;
-	Paths paths;
-	paths.push_back(std::make_pair(SlPaths::GetLobbyWriteDir(), _T("LobbyWriteDir")));
-	paths.push_back(std::make_pair(SlPaths::GetCachePath(), _T("CachePath")));
-	paths.push_back(std::make_pair(SlPaths::GetExecutableFolder(), _T("ExecutableFolder")));
-	paths.push_back(std::make_pair(SlPaths::GetDownloadDir(), _T("DownloadDir")));
-	paths.push_back(std::make_pair(SlPaths::GetDataDir(), _T("Current SpringData:")));
 
 	wxTextCtrl* out = new wxTextCtrl(this, wxNewId(), wxEmptyString, wxDefaultPosition, wxDefaultSize,
 					 wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH | wxTE_AUTO_URL);
-
-	*out << TowxString(getSpringlobbyAgent()) + _T("\n");
-	*out << wxString::Format(_T("SpringLobby config file: %s (%s writable)\n"),
-				 TowxString(SlPaths::GetConfigPath()).c_str(),
-				 BtS(wxFileName::IsFileWritable(TowxString(SlPaths::GetConfigPath())), "", "not").c_str());
-
-	for (size_t i = 0; i < paths.size(); ++i) {
-		const wxString path = TowxString(paths[i].first);
-		*out << wxString::Format(_T("%s (%s)\n"), paths[i].second.c_str(), path.c_str());
-		const bool wx = wxFileName::IsDirWritable(path);
-		const bool posix = access(STD_STRING(path).c_str(), WRITABLE) == 0;
-		bool tried = false;
-		try {
-			std::ofstream of;
-			const wxString dummy_fn = path + wxFileName::GetPathSeparator() + _T("dummy.txt");
-			of.open(STD_STRING(dummy_fn).c_str());
-
-			if (of.is_open()) {
-				of << "fhreuohgeiuhguie";
-				of.flush();
-				of.close();
-				tried = wxRemoveFile(dummy_fn);
-			}
-		} catch (...) {
-		}
-		*out << wxString::Format(_T("\tWX: %s POSIX: %s TRY: %s\n"), BtS(wx).c_str(), BtS(posix).c_str(), BtS(tried).c_str());
-	}
-
-	*out << wxString::Format(_T("Current unitsync: %s\n"), TowxString(SlPaths::GetUnitSync()).c_str());
-	*out << wxString::Format(_T("Current spring executable: %s\n"), TowxString(SlPaths::GetSpringBinary()).c_str());
-	*out << wxString::Format(_T("Current uikeys.txt: %s\n"), TowxString(SlPaths::GetUikeys()).c_str());
-
-	*out << wxString::Format(_T("Portable mode: %s\n"), BtS(SlPaths::IsPortableMode()).c_str());
-
-	*out << wxString::Format(_T("Compiled with wxWidgets %d.%d.%d.%d"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, wxSUBRELEASE_NUMBER) + _T("\n");
-	*out << _T("Started with: \n");
-	for (int i = 0; i < wxTheApp->argc; ++i)
-		*out << wxTheApp->argv[i] << _T(" ");
+	out->SetValue(TowxString(GetSpringlobbyInfo()));
 	m_main_sizer->Add(out, 1, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 0);
 	SetSizer(m_main_sizer);
 	Layout();
diff --git a/src/springlobbyapp.cpp b/src/springlobbyapp.cpp
index d34038f..ebabacc 100644
--- a/src/springlobbyapp.cpp
+++ b/src/springlobbyapp.cpp
@@ -55,6 +55,7 @@
 #include "gui/ui.h"
 #include "servermanager.h"
 #include "gui/iconscollection.h"
+#include "sysinfo.h"
 
 #include <wx/debugrpt.h>
 #include <wx/intl.h>
@@ -160,7 +161,6 @@ bool SpringLobbyApp::OnInit()
 	// configure unitsync paths before trying to load
 	SlPaths::ReconfigureUnitsync();
 
-
 	sett().Setup(m_translationhelper);
 
 	notificationManager(); //needs to be initialized too
@@ -176,6 +176,8 @@ bool SpringLobbyApp::OnInit()
 		wxLogWarning("Couldn't load unitsync");
 	}
 
+	wxLogWarning("%s", TowxString(GetSpringlobbyInfo()).c_str());
+
 	ui().OnInit();
 	return true;
 }
diff --git a/src/sysinfo.cpp b/src/sysinfo.cpp
new file mode 100644
index 0000000..f9bd7f5
--- /dev/null
+++ b/src/sysinfo.cpp
@@ -0,0 +1,86 @@
+/* This file is part of the Springlobby (GPL v2 or later), see COPYING */
+
+#include <string>
+#include <vector>
+#include <fstream>
+#include <wx/app.h>
+#include <wx/log.h>
+#include <wx/filename.h>
+#include <wx/string.h>
+#include "utils/conversion.h"
+#include "utils/slpaths.h"
+#include "utils/version.h"
+
+#if defined(__unix__) || defined(__APPLE__)
+#include <unistd.h>
+#define WRITABLE W_OK
+#elif defined(__WIN32__) || defined(_MSC_VER)
+#include <io.h>
+#define WRITABLE 02
+#else
+#error "os not supported"
+#endif
+
+
+inline std::string BtS(bool q, const std::string& yes = "yes", const std::string& no = "no")
+{
+	return q ? yes : no;
+}
+typedef std::vector<std::pair<std::string, std::string> > Paths;
+
+static void getWritePaths(Paths& paths)
+{
+	paths.push_back(std::make_pair(SlPaths::GetLobbyWriteDir(), "LobbyWriteDir"));
+	paths.push_back(std::make_pair(SlPaths::GetCachePath(), "CachePath"));
+	paths.push_back(std::make_pair(SlPaths::GetExecutableFolder(), "ExecutableFolder"));
+	paths.push_back(std::make_pair(SlPaths::GetDownloadDir(), "DownloadDir"));
+	paths.push_back(std::make_pair(SlPaths::GetDataDir(), "Current SpringData:"));
+}
+
+std::string GetSpringlobbyInfo()
+{
+	static const std::string nl = std::string("\n");
+	std::string res;
+	res  = getSpringlobbyAgent() + nl;
+	const bool configwriteable = wxFileName::IsFileWritable(TowxString(SlPaths::GetConfigPath()));
+	res += stdprintf("SpringLobby config file: %s (%s writable)\n",
+				 SlPaths::GetConfigPath().c_str(),
+				 BtS(configwriteable, "", "not").c_str());
+	Paths paths;
+	getWritePaths(paths);
+	for (size_t i = 0; i < paths.size(); ++i) {
+		const std::string path = paths[i].first;
+		res += stdprintf("%s (%s)\n", paths[i].second.c_str(), path.c_str());
+		const bool wx = wxFileName::IsDirWritable(path);
+		const bool posix = access(path.c_str(), WRITABLE) == 0;
+		bool tried = false;
+		try {
+			std::ofstream of;
+			const wxString dummy_fn = path + wxFileName::GetPathSeparator() + _T("dummy.txt");
+			of.open(STD_STRING(dummy_fn).c_str());
+
+			if (of.is_open()) {
+				of << "fhreuohgeiuhguie";
+				of.flush();
+				of.close();
+				tried = wxRemoveFile(dummy_fn);
+			}
+		} catch (...) {
+		}
+		if (!wx || !posix | !tried){
+			wxLogError("%s is not writeable!", path.c_str());
+		}
+		res += stdprintf(("\tWX: %s POSIX: %s TRY: %s\n"), BtS(wx).c_str(), BtS(posix).c_str(), BtS(tried).c_str());
+	}
+
+	res += stdprintf("Current unitsync: %s\n", SlPaths::GetUnitSync().c_str());
+	res += stdprintf("Current spring executable: %s\n", SlPaths::GetSpringBinary().c_str());
+	res += stdprintf("Portable mode: %s\n", BtS(SlPaths::IsPortableMode()).c_str());
+
+	res += stdprintf(("Compiled with wxWidgets %d.%d.%d.%d"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER, wxSUBRELEASE_NUMBER) + nl;
+	res += "Started with: \n";
+	for (int i = 0; i < wxTheApp->argc; ++i)
+		res += STD_STRING(wxTheApp->argv[i]) + std::string(" ");
+	return res;
+}
+
diff --git a/src/sysinfo.h b/src/sysinfo.h
new file mode 100644
index 0000000..538722a
--- /dev/null
+++ b/src/sysinfo.h
@@ -0,0 +1,4 @@
+/* This file is part of the Springlobby (GPL v2 or later), see COPYING */
+
+std::string GetSpringlobbyInfo();
+
diff --git a/src/tests/chatlog.cpp b/src/tests/chatlog.cpp
index abd0de1..73235fb 100644
--- a/src/tests/chatlog.cpp
+++ b/src/tests/chatlog.cpp
@@ -33,6 +33,8 @@ void customMessageBox(int, wxString const&, wxString const&, long, int, int)
 
 BOOST_AUTO_TEST_CASE(slconfig)
 {
+	//delete wxLog::SetActiveTarget(new wxLogStderr(NULL));
+
 	const wxString line1 = _T("this is line 1");
 	const wxString line2 = _T("this is line 2");
 	const wxString line3 = _T("this is line 3");
@@ -55,10 +57,9 @@ BOOST_AUTO_TEST_CASE(slconfig)
 		wxLogMessage(_T("line: '%s'"), line.c_str());
 	}
 
-	const int skip = 11; //ignore date
-	BOOST_CHECK(lines[lines.GetCount() - 4].Mid(skip) == line1);
-	BOOST_CHECK(lines[lines.GetCount() - 3].Mid(skip) == line2);
-	BOOST_CHECK(lines[lines.GetCount() - 2].Mid(skip) == line3);
+	BOOST_CHECK(lines[lines.GetCount() - 4] == line1);
+	BOOST_CHECK(lines[lines.GetCount() - 3] == line2);
+	BOOST_CHECK(lines[lines.GetCount() - 2] == line3);
 
 	delete logfile;
 }
diff --git a/src/utils/slpaths.cpp b/src/utils/slpaths.cpp
index a437782..e165e05 100644
--- a/src/utils/slpaths.cpp
+++ b/src/utils/slpaths.cpp
@@ -347,11 +347,6 @@ std::string SlPaths::GetLobbyWriteDir()
 	return LSL::Util::EnsureDelimiter(GetConfigfileDir());
 }
 
-std::string SlPaths::GetUikeys(const std::string& index)
-{
-	return GetDataDir(index) + "uikeys.txt";
-}
-
 bool SlPaths::CreateSpringDataDir(const std::string& dir)
 {
 	if (dir.empty()) {
diff --git a/src/utils/slpaths.h b/src/utils/slpaths.h
index 359a61e..b06d30a 100644
--- a/src/utils/slpaths.h
+++ b/src/utils/slpaths.h
@@ -51,7 +51,6 @@ public:
 	static std::string GetSpringBinary(const std::string& index = GetCurrentUsedSpringIndex());
 	static void SetSpringBinary(const std::string& path, const std::string& index = GetCurrentUsedSpringIndex());
 
-	static std::string GetUikeys(const std::string& index = GetCurrentUsedSpringIndex());
 	static std::string GetDataDir(const std::string& index = GetCurrentUsedSpringIndex());
 	static std::string GetSpringConfigFilePath(const std::string& index = GetCurrentUsedSpringIndex());
 	static std::string GetDownloadDir();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/springlobby.git



More information about the Pkg-games-commits mailing list