Example #1
0
//FIXME: merge with basicly duplicate in slpaths.cpp
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 (%swritable)\n",
			 SlPaths::GetConfigPath().c_str(),
			 BtS(configwriteable, "", "not ").c_str());
	Paths paths;
	getWritePaths(paths);
	for (size_t i = 0; i < paths.size(); ++i) {
		std::string path = paths[i].m_path;
#if defined(__WIN32__) || defined(_MSC_VER)
		path = Utf8ToLocalEncoding(path.c_str());
#endif
		res += stdprintf("%s (%s)\n", paths[i].m_desc.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;
			wxString dummy_fn = paths[i].m_path;
			if (!wxEndsWithPathSeparator(dummy_fn)) {
				dummy_fn += wxFileName::GetPathSeparator();
			}
			dummy_fn += _T("dummy.txt");

			std::string dummyFileString = dummy_fn.ToStdString();
#if defined(__WIN32__) || defined(_MSC_VER)
			dummyFileString = Utf8ToLocalEncoding(dummyFileString.c_str());
#endif
			of.open(dummyFileString);

			if (of.is_open()) {
				of << "fhreuohgeiuhguie";
				of.flush();
				of.close();
				tried = wxRemoveFile(dummyFileString);
			}
		} catch (...) {
		}
		if (paths[i].m_requireswrite && (!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;
}
Example #2
0
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(" ");
	m_main_sizer->Add(out, 1, wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 0);
	SetSizer(m_main_sizer);
	Layout();
}