Beispiel #1
0
void SpringOptionsTab::OnAddBundle(wxCommandEvent& /*event*/)
{
	wxFileDialog pick(this, _("Choose UnitSync library"),
			  wxPathOnly(TowxString(SlPaths::GetUnitSync())),
			  wxFileName::FileName(TowxString(SlPaths::GetUnitSync())).GetFullName(),
			  GetUnitsyncFilter());
	if (pick.ShowModal() == wxID_OK) {
		//get unitsync version & add to list
		bool failed = false;
		wxString failMessage;
		LSL::SpringBundle bundle;
#ifdef __APPLE__
		wxString path = pick.GetPath();
		bundle.unitsync = STD_STRING(path + (path.EndsWith("libunitsync.dylib") ? "" : "/Contents/MacOS/libunitsync.dylib"));
#else
		bundle.unitsync = STD_STRING(pick.GetPath());
#endif
		wxString version;
		try {
			bundle.AutoComplete();
			version = TowxString(bundle.version);
			if (!bundle.IsValid() || version.IsEmpty()) { // couldn't detect paths automaticly, allow user to select spring executable
				wxFileDialog pick(this, _("Choose a Spring executable"),
						  wxPathOnly(TowxString(bundle.unitsync)),
						  wxFileName::FileName(TowxString(SlPaths::GetSpringBinary())).GetFullName(),
						  GetSpringFilter());
				if (pick.ShowModal() == wxID_OK) {
					bundle.spring = STD_STRING(pick.GetPath());
				}
			}

			if (!bundle.IsValid() || version.IsEmpty()) {
				failed = true;
				failMessage = wxString::Format(_T("%s did not find engine and unitsync executables at %s\n\nPlease ensure that both exist and that you have appropriate access privileges."), getSpringlobbyName().c_str(), bundle.path.c_str());
			}
		} catch (const LSL::Exceptions::unitsync& e) {
			failed = true;
			failMessage = wxString::Format(_T("%s could not obtain the version string from the shared library file %s\n\nPlease provide a valid unitsync file."), getSpringlobbyName().c_str(), bundle.unitsync.c_str());
		}
		if (failed) {
			customMessageBox(SL_MAIN_ICON, failMessage, _("Configuration error"), wxOK);
			return;
		}

		m_spring_list->Append(version);
		m_spring_list->SetStringSelection(version);
		m_sync_edit->SetValue(TowxString(bundle.unitsync));
		m_exec_edit->SetValue(TowxString(bundle.spring));
		SlPaths::RefreshSpringVersionList(false, &bundle);
		DoRestore();
	}
}
// searches in OS standard paths for a system installed spring
bool SpringBundle::LocateSystemInstalledSpring(LSL::SpringBundle& bundle)
{
	LSL::StringVector paths;

	GetEnv("SPRING_BUNDLE_DIR", paths);
	GetEnv("PATH", paths);
	GetEnv("ProgramFiles", paths);
	GetEnv("ProgramFiles(x86)", paths);
	//GetEnv("ProgramFiles(x64)", paths); //32 bit springlobby can't use 64 bit
	GetEnv("LD_LIBRARY_PATH", paths);
	GetEnv("LDPATH", paths);

	AddPath("/usr/local/lib/spring", paths);
	AddPath("/usr/local/lib64", paths);
	AddPath("/usr/local/games", paths);
	AddPath("/usr/local/games/lib", paths);
	AddPath("/usr/local/lib", paths);
	AddPath("/usr/lib64", paths);
	AddPath("/usr/lib", paths);
	AddPath("/usr/lib/spring", paths);
	AddPath("/usr/games", paths);
	AddPath("/usr/games/lib64", paths);
	AddPath("/usr/games/lib", paths);
	AddPath("/lib", paths);
	AddPath("/bin", paths);

	for (const std::string path : paths) {
		if (bundle.AutoComplete(path)) {
			return true;
		}
	}
	return false;
}