Skip to content

Commit

Permalink
BugFix - Run at startup finally fixed V. 5.1.5.3 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
tsgsOFFICIAL committed Nov 6, 2024
1 parent c654ef3 commit 67c311c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
20 changes: 14 additions & 6 deletions CS2-AutoAccept/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
Directory.SetCurrentDirectory(AppContext.BaseDirectory);

// Check if another instance of the app is already running
Mutex mutex = new Mutex(true, "CS2-AutoAccept by tsgsOFFICIAL", out bool createdNew);
string[] args = Environment.GetCommandLineArgs();
bool updated = false;
bool ignoreMutexRule = false; // This is true if the application is started as a replacement, for example when updating or when an error occurs.

foreach (string arg in args)
{
// Application was updated
if (arg.ToLower().Equals("--updated"))
// Application was ignoreMutexRule
if (arg.ToLower().Equals("--updated") || arg.ToLower().Equals("--restart"))
{
updated = true;
ignoreMutexRule = true;
break;
}
}

// If another instance exists, trigger the event and exit
if (!createdNew && !updated)
if (!createdNew && !ignoreMutexRule)
{
// Create a MemoryMappedFile to notify the other instance
using (MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen("CS2_AutoAccept_MMF", 1024))
Expand All @@ -40,7 +42,13 @@ protected override void OnStartup(StartupEventArgs e)

// Shutdown the second instance
Current.Shutdown();
mutex.ReleaseMutex();

// Ensure mutex is released only if it was created successfully
if (createdNew)
{
mutex.ReleaseMutex();
}

return;
}

Expand Down
2 changes: 1 addition & 1 deletion CS2-AutoAccept/CS2-AutoAccept.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Description>A program to automatically find and press "ACCEPT" for you, when entering a competitive match in CS2.</Description>
<Copyright>©️ tsgsOFFICIAL - 2024</Copyright>
<FileVersion>5.1.5.2</FileVersion>
<FileVersion>5.1.5.3</FileVersion>
<AssemblyName>CS2-AutoAccept</AssemblyName>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions CS2-AutoAccept/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ private void ControlLocation()
}

// Start the updated program, in the new default path
Process.Start(Path.Combine(_basePath, "CS2-AutoAccept"));
Process.Start(Path.Combine(_basePath, "CS2-AutoAccept"), "--restarted");
Environment.Exit(0);
}
}
Expand Down Expand Up @@ -1242,8 +1242,8 @@ private Bitmap OptimiseImage(Bitmap bitmap)
// PrintToLog("{OCR} " + ex.Message);
if (ex.Message.ToLower().Contains("failed to initialise tesseract engine"))
{
Process.Start(Path.Combine(_basePath, "CS2-AutoAccept"));
ShowNotification("Error", ex.Message);
Process.Start(Path.Combine(_basePath, "CS2-AutoAccept"), "--restart");
ShowNotification("CS2 AutoAccept", "Tesseract failed to initialise, restarting the application.. " + ex.Message);
Environment.Exit(0);
return ("", 100);
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 8 additions & 3 deletions CS2-AutoAccept/updateInfo.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"version": "5.1.5.2",
"type": "Feature",
"changelog": "Improved the automatic update flow.",
"version": "5.1.5.3",
"type": "Bug",
"changelog": "Fixed AppContext bug, where Tesseract wouldn't launch after rebooting'.",
"historic_versions": [
{
"version": "5.1.5.2",
"type": "Feature",
"changelog": "Improved the automatic update flow."
},
{
"version": "5.1.5.1",
"type": "Bugfix",
Expand Down

0 comments on commit 67c311c

Please sign in to comment.