Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
XKaguya authored Jan 19, 2025
1 parent 756dd9c commit 289b81c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 37 deletions.
114 changes: 78 additions & 36 deletions StoPasswordBook/StoPasswordBook/Generic/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Http;
using System.Net.Sockets;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Media;
using System.Xml;
using log4net;
Expand Down Expand Up @@ -255,6 +256,39 @@ private static async Task<bool> Locate()
SemaphoreLocate.Release();
}
}

public static int GetDebugPort()
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = "cmd.exe";
processStartInfo.Arguments = "/C wmic process where \"caption='Star Trek Online.exe'\" get caption,commandline /value";
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;

Process? process = Process.Start(processStartInfo);

if (process == null)
{
return 0;
}

string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

if (output.Contains("remote-debugging-port"))
{
string pattern = @"--remote-debugging-port=(\d+)";
Match match = Regex.Match(output, pattern);

if (match.Success)
{
string portValue = match.Groups[1].Value;
return int.Parse(portValue);
}
}

return 0;
}

public static async Task InitApi()
{
Expand All @@ -263,55 +297,63 @@ public static async Task InitApi()
await SemaphoreInitApi.WaitAsync();
Log.Debug("Called InitApi");

if (GlobalVariables.LauncherPath == "null" || !File.Exists(GlobalVariables.LauncherPath))
int port = GetDebugPort();
if (port == 0)
{
OpenFileDialog openFileDialog = new OpenFileDialog
if (GlobalVariables.LauncherPath == "null" || !File.Exists(GlobalVariables.LauncherPath))
{
Filter = "Star Trek Online.exe|Star Trek Online.exe",
Title = "Select the game launcher",
FileName = "Star Trek Online.exe"
};
OpenFileDialog openFileDialog = new OpenFileDialog
{
Filter = "Star Trek Online.exe|Star Trek Online.exe",
Title = "Select the game launcher",
FileName = "Star Trek Online.exe"
};

bool? result = openFileDialog.ShowDialog();
bool? result = openFileDialog.ShowDialog();

if (result == true)
{
GlobalVariables.LauncherPath = openFileDialog.FileName;
if (result == true)
{
GlobalVariables.LauncherPath = openFileDialog.FileName;
}
}
}

SaveSettings();
SaveSettings();

int availablePort = GetAvailablePort();
GlobalVariables.DebugPort = availablePort;
int availablePort = GetAvailablePort();
GlobalVariables.DebugPort = availablePort;

if (!File.Exists(GlobalVariables.LauncherPath))
{
MainWindow.UpdateText("Launcher not found. Please reset the game launcher settings.");
return;
}
if (!File.Exists(GlobalVariables.LauncherPath))
{
MainWindow.UpdateText("Launcher not found. Please reset the game launcher settings.");
return;
}

var processStartInfo = new ProcessStartInfo
{
FileName = GlobalVariables.LauncherPath,
Arguments = $"--remote-debugging-port={GlobalVariables.DebugPort}",
};
var processStartInfo = new ProcessStartInfo
{
FileName = GlobalVariables.LauncherPath,
Arguments = $"--remote-debugging-port={GlobalVariables.DebugPort}",
};

Process? process = null;
Process? process = null;

try
{
process = Process.Start(processStartInfo);
}
catch (Exception ex)
{
Log.Error(ex.Message + ex.StackTrace);
}
try
{
process = Process.Start(processStartInfo);
}
catch (Exception ex)
{
Log.Error(ex.Message + ex.StackTrace);
}

if (process == null)
if (process == null)
{
MainWindow.UpdateText("Failed to start the launcher. Please try again or check the log.");
return;
}
}
else
{
MainWindow.UpdateText("Failed to start the launcher. Please try again or check the log.");
return;
GlobalVariables.DebugPort = port;
}
}
finally
Expand Down
2 changes: 1 addition & 1 deletion StoPasswordBook/StoPasswordBook/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace StoPasswordBook;
/// </summary>
public partial class MainWindow : FluentWindow
{
public static readonly string Version = "1.0.5";
public static readonly string Version = "1.0.6";

private static readonly ILog Log = LogManager.GetLogger(typeof(MainWindow));

Expand Down

0 comments on commit 289b81c

Please sign in to comment.