Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ProjBobcat/ProjBobcat/Class/Model/LaunchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class LaunchSettings
public bool VersionInsulation { get; init; }
public string? LauncherName { get; init; }

public string? CommandProxy { get; init; }

public GameArguments? FallBackGameArguments { get; init; }
public required GameArguments GameArguments { get; init; }
public required string[] GameEnvironmentVariables { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,19 @@ public override async Task<LaunchResult> LaunchTaskAsync(LaunchSettings settings
? Path.Combine(this.RootPath, GamePathHelper.GetGamePath(settings.Version))
: this.RootPath;

ProcessStartInfo psi;
ProcessStartInfo processStartInfo;

var commandProxy = settings.CommandProxy;

if (!settings.UseShellExecute)
{
psi = new ProcessStartInfo(java!.JavaPath, string.Join(' ', arguments))
var (command, finalArguments) = string.IsNullOrWhiteSpace(commandProxy) switch
{
true => (java!.JavaPath, string.Join(' ', arguments)),
false => (commandProxy.Trim(), $"\"{java!.JavaPath}\" {string.Join(' ', arguments)}")
};

processStartInfo = new ProcessStartInfo(command, finalArguments)
{
UseShellExecute = false,
WorkingDirectory = rootPath,
Expand All @@ -394,9 +402,11 @@ public override async Task<LaunchResult> LaunchTaskAsync(LaunchSettings settings
else
{
var normalJavaPath = java!.JavaPath.Replace("javaw", "java", StringComparison.OrdinalIgnoreCase);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this pr but @laolarou726 what's this? what if the path is "myjavawow/javaw.exe"? as a launcher core i think we should exactly use the given path. the problem that users might accidently select javaw should be addressed by the user inferface part.

var javaCommand = $"\"{normalJavaPath}\" {string.Join(' ', arguments)}";
var javaCommand = string.IsNullOrWhiteSpace(commandProxy)
? $"\"{normalJavaPath}\" {string.Join(' ', arguments)}"
: $"\"{commandProxy}\" \"{normalJavaPath}\" {string.Join(' ', arguments)}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we shouldn't use " for commandProxy, as it might be something like dotnet run

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, what about to use a commandFormat instead of commandProxy? For example we could directly change the format to "prime-run {java} even to put something here {args} maybe something more".

Copy link
Member

@yueyinqiu yueyinqiu Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

阿巴阿巴()好像说太多了()木有为难的意思,现在这样也可以()我先approve了()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we shouldn't use " for commandProxy, as it might be something like dotnet run

我想的是,如果用的是/path to/file这样的格式,应该考虑双引号封一起,不然路径有问题。至于dotnet run这种就不太好处理,这个要用dotnet作为程序主体吧,然后run 其他参数。其实也可以是分成代理命令主体和代理命令参数两个部分。但是这样要是用ls | grep 之类的管道符就很复杂了吧。一般就用一个prime-run,问题应该不大

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, what about to use a commandFormat instead of commandProxy? For example we could directly change the format to "prime-run {java} even to put something here {args} maybe something more".

或许是可行的办法,在useShellExecute的时候通过,在不使用的情况下需要确定命令的主体


psi = javaCommand switch
processStartInfo = javaCommand switch
{
_ when RuntimeInformation.IsOSPlatform(OSPlatform.Windows) =>
await StartGameInShellInWindows(rootPath, javaCommand),
Expand All @@ -406,15 +416,15 @@ await StartGameInShellInUnix(rootPath, javaCommand),
_ => throw new PlatformNotSupportedException("Unsupported OS platform.")
};
}

if (!settings.UseShellExecute)
{
// Patch for third-party launcher
psi.EnvironmentVariables.Remove("JAVA_TOOL_OPTIONS");
processStartInfo.EnvironmentVariables.Remove("JAVA_TOOL_OPTIONS");

foreach (var (k, v) in ParseGameEnv(settings.GameEnvironmentVariables))
{
psi.EnvironmentVariables.Add(k, v);
processStartInfo.EnvironmentVariables.Add(k, v);
}
}

Expand Down Expand Up @@ -451,7 +461,7 @@ await Task.Run(() =>
var launchWrapper = new LaunchWrapper(authResult, settings)
{
GameCore = this,
Process = Process.Start(psi)
Process = Process.Start(processStartInfo)
};

launchWrapper.Do();
Expand Down