Skip to content

Commit

Permalink
add override method of CreateProcess: CreateProcess(MVersion version,…
Browse files Browse the repository at this point in the history
… MLaunchOption option)
  • Loading branch information
AlphaBs committed Jun 14, 2021
1 parent 0efdd8d commit cad6b02
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions CmlLib/Core/CMLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,30 @@ public Process CreateProcess(string mcversion, string forgeversion, MLaunchOptio

return CreateProcess(versionName, option);
}

public Process CreateProcess(string versionName, MLaunchOption option)
=> CreateProcess(GetVersion(versionName), option);

[MethodTimer.Time]
public Process CreateProcess(string versionname, MLaunchOption option)
public Process CreateProcess(MVersion version, MLaunchOption option)
{
option.StartVersion = GetVersion(versionname);
option.StartVersion = version;

if (this.FileDownloader != null)
CheckAndDownload(option.StartVersion);

return CreateProcess(option);
}

[MethodTimer.Time]
public async Task<Process> CreateProcessAsync(string versionname, MLaunchOption option)
public async Task<Process> CreateProcessAsync(string versionName, MLaunchOption option)
{
var version = await GetVersionAsync(versionName).ConfigureAwait(false);
return await CreateProcessAsync(version, option).ConfigureAwait(false);
}

public async Task<Process> CreateProcessAsync(MVersion version, MLaunchOption option)
{
option.StartVersion = await GetVersionAsync(versionname).ConfigureAwait(false);
option.StartVersion = version;

if (this.FileDownloader != null)
await CheckAndDownloadAsync(option.StartVersion).ConfigureAwait(false);
Expand All @@ -196,34 +204,39 @@ public async Task<Process> CreateProcessAsync(string versionname, MLaunchOption

public Process CreateProcess(MLaunchOption option)
{
if (option.Path == null)
option.Path = MinecraftPath;
checkLaunchOption(option);
var launch = new MLaunch(option);
return launch.GetProcess();
}

public async Task<Process> CreateProcessAsync(MLaunchOption option)
{
if (option.Path == null)
option.Path = MinecraftPath;

checkLaunchOption(option);
var launch = new MLaunch(option);
return await Task.Run(launch.GetProcess).ConfigureAwait(false);
}

public Process Launch(string versionname, MLaunchOption option)
public Process Launch(string versionName, MLaunchOption option)
{
Process process = CreateProcess(versionname, option);
Process process = CreateProcess(versionName, option);
process.Start();
return process;
}

public async Task<Process> LaunchAsync(string versionname, MLaunchOption option)
public async Task<Process> LaunchAsync(string versionName, MLaunchOption option)
{
Process process = await CreateProcessAsync(versionname, option)
Process process = await CreateProcessAsync(versionName, option)
.ConfigureAwait(false);
process.Start();
return process;
}

private void checkLaunchOption(MLaunchOption option)
{
if (option.Path == null)
option.Path = MinecraftPath;
if (!string.IsNullOrEmpty(option.JavaPath) && option.StartVersion != null)
option.StartVersion.JavaBinaryPath = option.JavaPath;
}
}
}

0 comments on commit cad6b02

Please sign in to comment.