Skip to content

Commit

Permalink
Merge pull request #4 from tsgsOFFICIAL/Bug/run-at-startup
Browse files Browse the repository at this point in the history
BugFix - Run at startup fixed V. 5.1.5.1 🦟
  • Loading branch information
tsgsOFFICIAL authored Nov 4, 2024
2 parents c50696e + c07e4e9 commit b16d5ed
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
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.0</FileVersion>
<FileVersion>5.1.5.1</FileVersion>
<AssemblyName>CS2-AutoAccept</AssemblyName>
</PropertyGroup>

Expand Down
55 changes: 36 additions & 19 deletions CS2-AutoAccept/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public partial class MainWindow : Window
private string _basePath;
private string _updatePath;
private readonly bool debugMode = false;
public ICommand ToggleWindowCommand { get; }
public ICommand ToggleWindowCommand { get; }
public ICommand CloseCommand { get; }
private bool _isTrayIconVisible;

Expand All @@ -78,28 +78,16 @@ public bool IsTrayIconVisible
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
IsTrayIconVisible = true;
DataContext = this;

ToggleWindowCommand = new RelayCommand(o => ToggleWindowState());
ToggleWindowCommand = new RelayCommand(o => ToggleWindowState());
CloseCommand = new RelayCommand(o => CloseApplication());

// Event handler for double-click on TaskbarIcon
MyNotifyIcon.TrayMouseDoubleClick += OnTrayIconDoubleClick;

// Access command line arguments
string[] args = Environment.GetCommandLineArgs();

foreach (string arg in args)
{
if (arg.ToLower().Equals("start cs2"))
{
LaunchWeb("steam://rungameid/730");
Button_LaunchCS.Content = "Launching CS2";
_gameRunExtraDelay = 15;
}
}

_basePath = Path.Combine(Environment.ExpandEnvironmentVariables("%APPDATA%"), "CS2 AutoAccept");
_updatePath = Path.Combine(_basePath, "UPDATE");

Expand Down Expand Up @@ -218,7 +206,6 @@ public MainWindow()
}
}
#endregion

}
private void ToggleWindowState()
{
Expand All @@ -244,6 +231,26 @@ private void UpdateTrayIconVisibility()
MyNotifyIcon.Visibility = IsTrayIconVisible ? Visibility.Visible : Visibility.Collapsed;
}
#region EventHandlers
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// Access command line arguments
string[] args = Environment.GetCommandLineArgs();

foreach (string arg in args)
{
if (arg.ToLower().Equals("start cs2"))
{
LaunchWeb("steam://rungameid/730");
Button_LaunchCS.Content = "Launching CS2";
_gameRunExtraDelay = 15;
}

if (arg.ToLower().Equals("--minimize"))
{
WindowState = WindowState.Minimized;
}
}
}
protected override void OnStateChanged(EventArgs e)
{
base.OnStateChanged(e);
Expand Down Expand Up @@ -425,7 +432,7 @@ private void Program_state_Unchecked(object sender, RoutedEventArgs e)
// PrintToLog("{Program_state_Unchecked}");
cts!.Cancel();
Program_state_continuously.IsChecked = false;
_scannerIsActive = false;
_scannerIsActive = false;

// Change to a darker color
Program_state.Foreground = new SolidColorBrush(Colors.Red);
Expand Down Expand Up @@ -468,14 +475,15 @@ private void Program_state_continuously_Unchecked(object sender, RoutedEventArgs
private void Run_at_startup_state_Checked(object sender, RoutedEventArgs e)
{
// PrintToLog("{Run_at_startup_state_Checked}");
string exeLocation = $"{AppContext.BaseDirectory}CS2-AutoAccept";
string exePath = GetExePath();

try
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

if (key.GetValue("CS2-AutoAccept") == null)
{
key.SetValue("CS2-AutoAccept", exeLocation);
key.SetValue("CS2-AutoAccept", $"{exePath} --minimize");
}

key.Close();
Expand Down Expand Up @@ -537,6 +545,15 @@ private void WindowSizeChangedEventHandler(object sender, SizeChangedEventArgs e
File.WriteAllText(Path.Combine(_basePath, "settings.cs2_auto"), jsonString);
}
#endregion
private string GetExePath()
{
string? exeLocation5 = Process.GetCurrentProcess().MainModule?.FileName;

string executingDir = AppDomain.CurrentDomain.BaseDirectory;
string executingName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);

return exeLocation5 ?? $"{Path.Combine(executingDir, executingName)}.exe";
}
/// <summary>
/// Restore the window size, if it was previously opened & changed
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions CS2-AutoAccept/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"CS2-AutoAccept": {
"commandName": "Project"
}
}
}
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.0",
"type": "major",
"changelog": "Removed keybinds temporarily & added system tray icon as requested.",
"version": "5.1.5.1",
"type": "Bugfix",
"changelog": "Fixed a bug where the application would not start with windows.",
"historic_versions": [
{
"version": "5.1.5.0",
"type": "major",
"changelog": "Removed keybinds temporarily & added system tray icon as requested."
},
{
"version": "5.1.4.5",
"type": "minor",
Expand Down

0 comments on commit b16d5ed

Please sign in to comment.