mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-30 22:51:01 +00:00
Handle Extra Args
This commit is contained in:
parent
75c9b584ee
commit
c3ac4c9c38
11 changed files with 136 additions and 16 deletions
|
@ -38,7 +38,7 @@ void I_PrintStr (const char *str);
|
|||
void I_SetIWADInfo ();
|
||||
|
||||
// Pick from multiple IWADs to use
|
||||
int I_PickIWad (WadStuff *wads, int numwads, bool queryiwad, int defaultiwad, int&);
|
||||
int I_PickIWad (WadStuff *wads, int numwads, bool queryiwad, int defaultiwad, int&, FString &);
|
||||
|
||||
// [RH] Checks the registry for Steam's install path, so we can scan its
|
||||
// directories for IWADs if the user purchased any through Steam.
|
||||
|
|
|
@ -298,7 +298,7 @@ void I_PrintStr(const char *cp)
|
|||
if (StartWindow) RedrawProgressBar(ProgressBarCurPos,ProgressBarMaxPos);
|
||||
}
|
||||
|
||||
int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags)
|
||||
int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags, FString &extraArgs)
|
||||
{
|
||||
if (!showwin)
|
||||
{
|
||||
|
@ -308,7 +308,7 @@ int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int&
|
|||
#ifdef __APPLE__
|
||||
return I_PickIWad_Cocoa (wads, numwads, showwin, defaultiwad);
|
||||
#else
|
||||
return LauncherWindow::ExecModal(wads, numwads, defaultiwad, &autoloadflags);
|
||||
return LauncherWindow::ExecModal(wads, numwads, defaultiwad, &autoloadflags, &extraArgs);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -353,7 +353,7 @@ static void SetQueryIWad(HWND dialog)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
int I_PickIWad(WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags)
|
||||
int I_PickIWad(WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags, FString &extraArgs)
|
||||
{
|
||||
int vkey;
|
||||
if (stricmp(queryiwad_key, "shift") == 0)
|
||||
|
@ -370,7 +370,7 @@ int I_PickIWad(WadStuff *wads, int numwads, bool showwin, int defaultiwad, int&
|
|||
}
|
||||
if (showwin || (vkey != 0 && GetAsyncKeyState(vkey)))
|
||||
{
|
||||
return LauncherWindow::ExecModal(wads, numwads, defaultiwad, &autoloadflags);
|
||||
return LauncherWindow::ExecModal(wads, numwads, defaultiwad, &autoloadflags, &extraArgs);
|
||||
}
|
||||
return defaultiwad;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ void I_PrintStr (const char *cp);
|
|||
void I_SetIWADInfo ();
|
||||
|
||||
// Pick from multiple IWADs to use
|
||||
int I_PickIWad(WadStuff* wads, int numwads, bool queryiwad, int defaultiwad, int& autoloadflags);
|
||||
int I_PickIWad(WadStuff* wads, int numwads, bool queryiwad, int defaultiwad, int& autoloadflags, FString &extraArgs);
|
||||
|
||||
// The ini could not be saved at exit
|
||||
bool I_WriteIniFailed (const char* filename);
|
||||
|
|
|
@ -345,6 +345,114 @@ void FArgs::AppendArgs(int argc, const FString *argv)
|
|||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// FArgs :: AppendArgsString
|
||||
//
|
||||
// Adds extra args as a space-separated string, supporting simple quoting, and inserting -file args into the right place
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
|
||||
void FArgs::AppendArgsString(FString argv)
|
||||
{
|
||||
auto file_index = Argv.Find("-file");
|
||||
auto files_end = file_index + 1;
|
||||
|
||||
for (; files_end < Argv.Size() && Argv[files_end][0] != '-' && Argv[files_end][0] != '+'; ++files_end);
|
||||
|
||||
if(file_index == Argv.Size())
|
||||
{
|
||||
Argv.Push("-file");
|
||||
}
|
||||
|
||||
bool inserting_file = true;
|
||||
|
||||
argv.StripLeftRight();
|
||||
|
||||
size_t i = 0;
|
||||
size_t lastSection = 0;
|
||||
size_t lastStart = 0;
|
||||
char lastQuoteType = 0;
|
||||
|
||||
FString tmp;
|
||||
bool has_tmp = false;
|
||||
|
||||
for(i = 0; i < argv.Len(); i++)
|
||||
{
|
||||
if(argv[i] == ' ')
|
||||
{
|
||||
FString arg = tmp + argv.Mid(lastSection, i - lastSection);
|
||||
|
||||
if(arg[0] == '-' || arg[0] == '+') inserting_file = false;
|
||||
|
||||
if(inserting_file)
|
||||
{
|
||||
Argv.Insert(files_end++, arg);
|
||||
}
|
||||
else if(arg.Compare("-file") == 0)
|
||||
{
|
||||
inserting_file = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
files_end++;
|
||||
Argv.Insert(file_index++, arg);
|
||||
}
|
||||
|
||||
lastSection = i + 1;
|
||||
tmp = "";
|
||||
has_tmp = false;
|
||||
for(;(i + 1) < argv.Len() && argv[i + 1] == ' '; i++, lastSection++);
|
||||
lastStart = i + 1;
|
||||
}
|
||||
else if(argv[i] == '\'' || argv[i] == '"')
|
||||
{
|
||||
lastQuoteType = argv[i];
|
||||
tmp += argv.Mid(lastSection, i - lastSection);
|
||||
has_tmp = true;
|
||||
bool wasSlash = false;
|
||||
|
||||
for(i++; (argv[i] != lastQuoteType || wasSlash) && i < argv.Len(); i++)
|
||||
{
|
||||
if(i == '\\' && !wasSlash)
|
||||
{
|
||||
wasSlash = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp += argv[i];
|
||||
wasSlash = false;
|
||||
}
|
||||
}
|
||||
lastSection = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(lastSection != i)
|
||||
{ // ended on an unquoted section
|
||||
FString arg = tmp + argv.Mid(lastSection);
|
||||
if(inserting_file)
|
||||
{
|
||||
Argv.Insert(files_end, arg);
|
||||
}
|
||||
else if(arg.Compare("-file") != 0)
|
||||
{
|
||||
Argv.Insert(file_index, arg);
|
||||
}
|
||||
}
|
||||
else if(has_tmp)
|
||||
{ // ended on a quote
|
||||
if(inserting_file)
|
||||
{
|
||||
Argv.Insert(files_end, tmp);
|
||||
}
|
||||
else if(tmp.Compare("-file") != 0)
|
||||
{
|
||||
Argv.Insert(file_index, tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
//===========================================================================
|
||||
//
|
||||
// FArgs :: RemoveArg
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
|
||||
void AppendArg(FString arg);
|
||||
void AppendArgs(int argc, const FString *argv);
|
||||
void AppendArgsString(FString argv);
|
||||
void RemoveArg(int argindex);
|
||||
void RemoveArgs(const char *check);
|
||||
void SetArgs(int argc, char **argv);
|
||||
|
|
|
@ -128,6 +128,7 @@ public:
|
|||
FString (FString &&other) noexcept : Chars(other.Chars) { other.ResetToNull(); }
|
||||
FString (const char *copyStr);
|
||||
FString (const char *copyStr, size_t copyLen);
|
||||
FString (const std::string &s) : FString(s.c_str(), s.length()) {}
|
||||
FString (char oneChar);
|
||||
FString(const TArray<char> & source) : FString(source.Data(), source.Size()) {}
|
||||
FString(const TArray<uint8_t> & source) : FString((char*)source.Data(), source.Size()) {}
|
||||
|
|
|
@ -764,9 +764,18 @@ int FIWadManager::IdentifyVersion (std::vector<std::string>&wadfiles, const char
|
|||
if (autoloadbrightmaps) flags |= 4;
|
||||
if (autoloadwidescreen) flags |= 8;
|
||||
|
||||
pick = I_PickIWad(&wads[0], (int)wads.Size(), queryiwad, pick, flags);
|
||||
FString extraArgs;
|
||||
|
||||
pick = I_PickIWad(&wads[0], (int)wads.Size(), queryiwad, pick, flags, extraArgs);
|
||||
if (pick >= 0)
|
||||
{
|
||||
extraArgs.StripLeftRight();
|
||||
|
||||
if(extraArgs.Len() > 0)
|
||||
{
|
||||
Args->AppendArgsString(extraArgs);
|
||||
}
|
||||
|
||||
disableautoload = !!(flags & 1);
|
||||
autoloadlights = !!(flags & 2);
|
||||
autoloadbrightmaps = !!(flags & 4);
|
||||
|
|
|
@ -1809,7 +1809,9 @@ static void GetCmdLineFiles(std::vector<std::string>& wadfiles)
|
|||
int i, argc;
|
||||
|
||||
argc = Args->CheckParmList("-file", &args);
|
||||
for (i = 0; i < argc; ++i)
|
||||
|
||||
// [RL0] Check for array size to only add new wads
|
||||
for (i = wadfiles.size(); i < argc; ++i)
|
||||
{
|
||||
D_AddWildFile(wadfiles, args[i].GetChars(), ".wad", GameConfig);
|
||||
}
|
||||
|
@ -3764,6 +3766,9 @@ static int D_DoomMain_Internal (void)
|
|||
std::vector<std::string> allwads;
|
||||
|
||||
const FIWADInfo *iwad_info = iwad_man->FindIWAD(allwads, iwad.GetChars(), basewad.GetChars(), optionalwad.GetChars());
|
||||
|
||||
GetCmdLineFiles(pwads); // [RL0] Update with files passed on the launcher extra args
|
||||
|
||||
if (!iwad_info) return 0; // user exited the selection popup via cancel button.
|
||||
if ((iwad_info->flags & GI_SHAREWARE) && pwads.size() > 0)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <zwidget/window/window.h>
|
||||
#include <zwidget/widgets/tabwidget/tabwidget.h>
|
||||
|
||||
int LauncherWindow::ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags)
|
||||
int LauncherWindow::ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags, FString * extraArgs)
|
||||
{
|
||||
Size screenSize = GetScreenSize();
|
||||
double windowWidth = 615.0;
|
||||
|
@ -23,6 +23,8 @@ int LauncherWindow::ExecModal(WadStuff* wads, int numwads, int defaultiwad, int*
|
|||
|
||||
DisplayWindow::RunLoop();
|
||||
|
||||
if(extraArgs) *extraArgs = launcher->PlayGame->GetExtraArgs();
|
||||
|
||||
return launcher->ExecResult;
|
||||
}
|
||||
|
||||
|
@ -54,12 +56,6 @@ void LauncherWindow::Start()
|
|||
{
|
||||
Settings->Save();
|
||||
|
||||
std::string extraargs = PlayGame->GetExtraArgs();
|
||||
if (!extraargs.empty())
|
||||
{
|
||||
// To do: restart the process like the cocoa backend is doing?
|
||||
}
|
||||
|
||||
ExecResult = PlayGame->GetSelectedGame();
|
||||
DisplayWindow::ExitLoop();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ struct WadStuff;
|
|||
class LauncherWindow : public Widget
|
||||
{
|
||||
public:
|
||||
static int ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags);
|
||||
static int ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags, FString * extraArgs = nullptr);
|
||||
|
||||
LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags);
|
||||
void UpdateLanguage();
|
||||
|
|
Loading…
Reference in a new issue