23 #include "gameexecutablepicker.h"
25 #include "configuration/doomseekerconfig.h"
26 #include "datapaths.h"
27 #include "filefilter.h"
28 #include "gui/commongui.h"
30 #include "plugins/engineplugin.h"
31 #include "serverapi/exefile.h"
32 #include "serverapi/gameexefactory.h"
33 #include "serverapi/gamefile.h"
34 #include "templatedpathresolver.h"
35 #include "ui_gameexecutablepicker.h"
36 #include <QFileDialog>
39 DClass<GameExecutablePicker> :
public Ui::GameExecutablePicker
54 d->btnBrowse->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon));
59 GameExecutablePicker::~GameExecutablePicker()
63 void GameExecutablePicker::add(
const QString &path)
65 if (!path.trimmed().isEmpty() && d->executableInput->findText(path) < 0)
66 d->executableInput->addItem(path);
69 void GameExecutablePicker::browse()
72 QString dialogDir = gConfig.doomseeker.previousCreateServerExecDir;
73 QString path = QFileDialog::getOpenFileName(
this, tr(
"Doomseeker - Browse executable"),
74 dialogDir, FileFilter::executableFilesFilter());
78 path = gDefaultDataPaths->portablizePath(path);
79 gConfig.doomseeker.previousCreateServerExecDir = path;
80 d->executableInput->setCurrentText(path);
86 GameFileList GameExecutablePicker::gameExecutables()
const
89 GameFileList candidates = GameFiles::allFlagMatchExecutables(files, d->allowedExecs);
90 if (d->allowedExecs & GameFile::Client)
91 candidates.prepend(GameFiles::defaultClientExecutable(files));
92 else if (d->allowedExecs & GameFile::Server)
93 candidates.prepend(GameFiles::defaultServerExecutable(files));
94 else if (d->allowedExecs & GameFile::Offline)
95 candidates.prepend(GameFiles::defaultOfflineExecutable(files));
99 QString GameExecutablePicker::path()
const
101 return d->executableInput->currentText();
104 void GameExecutablePicker::setPath(
const QString &path)
106 d->executableInput->setCurrentText(path);
109 void GameExecutablePicker::setExecutableToDefault()
115 showWarning(tr(
"Plugin doesn't support configuration."));
122 showWarning(tr(
"Game doesn't define any executables for this game setup."));
126 for (
const GameFile &candidate : execs.asQList())
128 const QString path = cfg->
value(candidate.configName()).toString();
131 d->executableInput->setCurrentText(path);
135 showWarning(tr(
"Default executable for this game isn't configured."));
140 d->allowedExecs = execs;
144 void GameExecutablePicker::setPlugin(
EnginePlugin *plugin)
150 void GameExecutablePicker::showWarning(
const QString &msg)
152 d->lblWarning->setVisible(!msg.trimmed().isEmpty());
153 d->lblWarning->setToolTip(msg);
156 void GameExecutablePicker::reloadExecutables()
159 if (d->plugin ==
nullptr)
161 showWarning(tr(
"Game plugin not set."));
164 QString currentExec = d->executableInput->currentText();
165 d->executableInput->clear();
169 d->executableInput->setCurrentText(currentExec);
174 for (
const GameFile &file : files.asQList())
178 for (
const ExeFilePath &exe : d->plugin->gameExe()->additionalExecutables(d->allowedExecs))
181 if (fileInfo.isFile())
182 add(gDefaultDataPaths->portablizePath(exe.path()));
185 if (d->executableInput->findText(currentExec) >= 0)
186 d->executableInput->setCurrentText(currentExec);
188 setExecutableToDefault();