Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6 Directly launch the game #16

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions KsGameLauncher/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
<setting name="MenuIconSize_Default" serializeAs="String">
<value>16</value>
</setting>
<setting name="ErrorReporterPath" serializeAs="String">
<value>launcher\modules\errorreporter.exe</value>
</setting>
<setting name="ErrorReporterPath_2dx" serializeAs="String">
<value>launcher\modules\bm2dx_er.exe</value>
</setting>
<setting name="LauncherPath" serializeAs="String">
<value>launcher\modules\launcher.exe</value>
</setting>
<setting name="LauncherPath_2dx" serializeAs="String">
<value>launcher\modules\bm2dx_launcher.exe</value>
</setting>
<setting name="AppUriScheme" serializeAs="String">
<value>ksgamelauncher</value>
</setting>
Expand Down Expand Up @@ -137,6 +149,9 @@
<setting name="NewGameFormSize" serializeAs="String">
<value>400, 300</value>
</setting>
<setting name="RunGameDirect" serializeAs="String">
<value>False</value>
</setting>
<setting name="RegisterCustomURI" serializeAs="String">
<value>False</value>
</setting>
Expand Down
40 changes: 27 additions & 13 deletions KsGameLauncher/Forms/OptionsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions KsGameLauncher/Forms/OptionsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private void OptionsForm_Load(object sender, EventArgs e)
checkBox_Notification.Checked = Properties.Settings.Default.EnableNotification;
checkBox_ConfirmExit.Checked = Properties.Settings.Default.ShowConfirmExit;
checkBox_DisplayInstalledGamesOnly.Checked = Properties.Settings.Default.ShowOnlyInstalledGames;
checkBox_RunDirect.Checked = Properties.Settings.Default.RunGameDirect;
checkBox_RegisterCustomURI.Checked = Properties.Settings.Default.RegisterCustomURI;
comboBox_ContextMenuSize.SelectedIndex = Properties.Settings.Default.ContextMenuSize;
int intervalSelectedIndex = 0;
Expand Down Expand Up @@ -99,6 +100,7 @@ private void OptionsForm_Load(object sender, EventArgs e)
checkBox_Notification.Text = Properties.Strings.OptionsDisplayNotification;
checkBox_ConfirmExit.Text = Properties.Strings.ShowConfirmExit;
checkBox_DisplayInstalledGamesOnly.Text = Properties.Strings.ShowOnlyInstalledGames;
checkBox_RunDirect.Text = Properties.Strings.RunGameDirectly;
linkLabel_OpenProxySettings.Text = Properties.Strings.OptionsProxySettingsLink;
button_Save.Text = Properties.Strings.ButtonSave;
button_SyncAppInfo.Text = Properties.Strings.SynchWithServerButton;
Expand Down Expand Up @@ -162,6 +164,7 @@ private void Button_Save_Click(object sender, EventArgs e)
Properties.Settings.Default.EnableNotification = checkBox_Notification.Checked;
Properties.Settings.Default.ShowConfirmExit = checkBox_ConfirmExit.Checked;
Properties.Settings.Default.ShowOnlyInstalledGames = checkBox_DisplayInstalledGamesOnly.Checked;
Properties.Settings.Default.RunGameDirect = checkBox_RunDirect.Checked;
Properties.Settings.Default.ContextMenuSize = comboBox_ContextMenuSize.SelectedIndex;
Properties.Settings.Default.Language = selectedLang.ID;
Properties.Settings.Default.UpdateCheckInterval = selectedInterval.Interval;
Expand Down
68 changes: 63 additions & 5 deletions KsGameLauncher/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ internal static Launcher Create()
return instance;
}

/// <summary>
/// Constructor
/// </summary>
private Launcher()
{

Expand Down Expand Up @@ -552,6 +555,7 @@ await Task.Factory.StartNew(() =>
/// Start game launcher
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public async Task StartApp(AppInfo app)
{
NetworkCredential credential = GetCredential();
Expand Down Expand Up @@ -708,6 +712,12 @@ public async Task StartApp(AppInfo app)
return;
}

/// <summary>
/// Parse launcher launch page
/// </summary>
/// <param name="content"></param>
/// <param name="querySelector"></param>
/// <exception cref="LauncherException"></exception>
async Task<bool> LauncherLoginPage(string content, string querySelector)
{
if (content == null || content.Length < 0)
Expand Down Expand Up @@ -741,24 +751,72 @@ async Task<bool> LauncherLoginPage(string content, string querySelector)
Debug.WriteLine(String.Format("launcherUri: {0}", launcherCustomProtocol));
Debug.WriteLine(String.Format("custom scheme: {0}", customUri.Scheme));
#endif
string launcherPath = Utils.GameRegistry.GetLauncherPath(customUri.Scheme);
RunGame(customUri);
}
return true;
}

/// <summary>
/// Launch the launcher or game
/// </summary>
/// <param name="launcherUri"></param>
private void RunGame(Uri launcherUri)
{
string execPath = Utils.GameRegistry.GetLauncherPath(launcherUri.Scheme);
string args = launcherUri.ToString();
#if DEBUG
Debug.WriteLine(String.Format("Launcher exec path: {0}", launcherPath));
Debug.WriteLine(String.Format("Launcher exec path: {0}", execPath));
#endif
if (Properties.Settings.Default.RunGameDirect)
{
string launcherPath, errorReporterPath;
launcherPath = Properties.Settings.Default.LauncherPath;
errorReporterPath = Properties.Settings.Default.ErrorReporterPath;
if (launcherUri.Scheme.StartsWith("bm2dxinf"))
{
launcherPath = Properties.Settings.Default.LauncherPath_2dx;
errorReporterPath = Properties.Settings.Default.ErrorReporterPath_2dx;
}

string testPath = execPath.Replace(launcherPath, errorReporterPath);

Process.Start(launcherPath, launcherCustomProtocol);
if (File.Exists(testPath))
{
execPath = testPath;
string param = "tk=";
if (launcherUri.Query.Contains("&"))
args = string.Format("-t {0}", launcherUri.Query.Substring(1).Substring(launcherUri.Query.IndexOf(param)+param.Length, launcherUri.Query.IndexOf("&")));
else
args = string.Format("-t {0}", launcherUri.Query.Substring(1).Substring(launcherUri.Query.IndexOf(param) + param.Length));
}
else
{
MessageBox.Show(Properties.Strings.CannotFindErrorReporter, Properties.Strings.AppName,
MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}
}
return true;

Process.Start(execPath, launcherUri.ToString());
}

/// <summary>
/// Get credentials
/// </summary>
/// <returns></returns>
private NetworkCredential GetCredential()
{
return CredentialManager.GetCredentials(target: Properties.Resources.CredentialTarget);
}

/// <summary>
/// Find game exe
/// </summary>
/// <param name="launcherPath"></param>
/// <returns></returns>
private string GetGamePathFromLauncher(string launcherPath)
{
string gamePath = launcherPath.Replace(@"\launcher\modules\launcher.exe", @"game\modules\");
string gamePath = launcherPath.Replace(Properties.Settings.Default.LauncherPath, @"game\modules\");
string[] files = Directory.GetFiles(gamePath, "*.exe");
if (files.Length < 0)
return null;
Expand Down
Loading