Skip to content

Commit

Permalink
Check for TheDarkMod.exe in the engine folder.
Browse files Browse the repository at this point in the history
Some UI fixup.
  • Loading branch information
codereader committed Dec 7, 2017
1 parent 4fff619 commit 68250d6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
13 changes: 13 additions & 0 deletions libs/os/file.h
Expand Up @@ -86,6 +86,19 @@ inline bool fileOrDirExists(const std::string& path)
}
}

/// \brief Returns true if the file or directory identified by \p path exists.
inline bool fileOrDirExists(const fs::path& path)
{
try
{
return fs::exists(path);
}
catch (fs::filesystem_error&)
{
return false;
}
}

// Returns the file size in bytes, or static_cast<uintmax_t>(-1)
inline std::size_t getFileSize(const std::string& path)
{
Expand Down
9 changes: 5 additions & 4 deletions radiant/ui/prefdialog/GameSetupPageIdTech.cpp
Expand Up @@ -27,24 +27,25 @@ GameSetupPageIdTech::GameSetupPageIdTech(wxWindow* parent, const game::IGamePtr&
_enginePathEntry(nullptr)
{
wxFlexGridSizer* table = new wxFlexGridSizer(3, 2, wxSize(6, 6));
table->AddGrowableCol(1);
this->SetSizer(table);

_enginePathEntry = new wxutil::PathEntry(this, true);
_enginePathEntry->getEntryWidget()->SetMinClientSize(
wxSize(_enginePathEntry->getEntryWidget()->GetCharWidth() * 30, -1));

table->Add(new wxStaticText(this, wxID_ANY, _("Engine Path")), 0, wxALIGN_CENTRE_VERTICAL);
table->Add(_enginePathEntry, 0);
table->Add(_enginePathEntry, 1, wxEXPAND);

_fsGameEntry = new wxTextCtrl(this, wxID_ANY);
_fsGameEntry->SetMinClientSize(wxSize(_fsGameEntry->GetCharWidth() * 30, -1));
table->Add(new wxStaticText(this, wxID_ANY, _("Mod (fs_game)")), 0, wxALIGN_CENTRE_VERTICAL);
table->Add(_fsGameEntry, 0);
table->Add(_fsGameEntry, 1, wxEXPAND);

_fsGameBaseEntry = new wxTextCtrl(this, wxID_ANY);
_fsGameBaseEntry->SetMinClientSize(wxSize(_fsGameEntry->GetCharWidth() * 30, -1));
table->Add(new wxStaticText(this, wxID_ANY, _("Mod Base (fs_game_base, optional)")), 0, wxALIGN_CENTRE_VERTICAL);
table->Add(_fsGameBaseEntry, 0);
table->Add(new wxStaticText(this, wxID_ANY, _("Mod Base (fs_game_base)")), 0, wxALIGN_CENTRE_VERTICAL);
table->Add(_fsGameBaseEntry, 1, wxEXPAND);
}

const char* GameSetupPageIdTech::TYPE()
Expand Down
31 changes: 30 additions & 1 deletion radiant/ui/prefdialog/GameSetupPageTdm.cpp
Expand Up @@ -27,22 +27,27 @@ GameSetupPageTdm::GameSetupPageTdm(wxWindow* parent, const game::IGamePtr& game)
_enginePathEntry(nullptr)
{
wxFlexGridSizer* table = new wxFlexGridSizer(2, 2, wxSize(6, 6));
table->AddGrowableCol(1);
this->SetSizer(table);

_enginePathEntry = new wxutil::PathEntry(this, true);
_enginePathEntry->getEntryWidget()->SetMinClientSize(
wxSize(_enginePathEntry->getEntryWidget()->GetCharWidth() * 30, -1));

table->Add(new wxStaticText(this, wxID_ANY, _("Darkmod Path")), 0, wxALIGN_CENTRE_VERTICAL);
table->Add(new wxStaticText(this, wxID_ANY, _("DarkMod Path")), 0, wxALIGN_CENTRE_VERTICAL);
table->Add(_enginePathEntry, 1, wxEXPAND);

_enginePathEntry->getEntryWidget()->Bind(wxEVT_TEXT, [&](wxCommandEvent& ev)
{
populateAvailableMissionPaths();
});

_enginePathEntry->SetToolTip(_("This is the path where your TheDarkMod.exe is located."));

_missionEntry = new wxComboBox(this, wxID_ANY);
_missionEntry->SetMinClientSize(wxSize(_missionEntry->GetCharWidth() * 30, -1));
_missionEntry->SetToolTip(_("The FM folder name of the mission you want to work on, e.g. 'saintlucia'."));

table->Add(new wxStaticText(this, wxID_ANY, _("Mission")), 0, wxALIGN_CENTRE_VERTICAL);
table->Add(_missionEntry, 1, wxEXPAND);

Expand Down Expand Up @@ -134,6 +139,30 @@ void GameSetupPageTdm::validateSettings()
errorMsg += fmt::format(_("Engine path \"{0}\" does not exist.\n"), _config.enginePath);
}

// Check if the TheDarkMod.exe file is in the right place
fs::path darkmodExePath = _config.enginePath;

// No engine path set so far, search the game file for default values
const std::string ENGINE_EXECUTABLE_ATTRIBUTE =
#if defined(WIN32)
"engine_win32"
#elif defined(__linux__) || defined (__FreeBSD__)
"engine_linux"
#elif defined(__APPLE__)
"engine_macos"
#else
#error "unknown platform"
#endif
;

std::string exeName = _game->getKeyValue(ENGINE_EXECUTABLE_ATTRIBUTE);

if (!os::fileOrDirExists(darkmodExePath / exeName))
{
// engine executable not present
errorMsg += fmt::format(_("The engine executable \"{0}\" could not be found in the specified folder.\n"), exeName);
}

// Check the mod path (=mission path), if not empty
if (!_config.modPath.empty() && !os::fileOrDirExists(_config.modPath))
{
Expand Down

0 comments on commit 68250d6

Please sign in to comment.