Skip to content
Closed
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
45 changes: 44 additions & 1 deletion Wauncher/Services/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@
[ObservableProperty]
private bool _updateIndeterminate;

private CancellationTokenSource? _updateCts;

Check warning on line 46 in Wauncher/Services/UpdateService.cs

View workflow job for this annotation

GitHub Actions / build

The field 'UpdateService._updateCts' is never used

Check warning on line 46 in Wauncher/Services/UpdateService.cs

View workflow job for this annotation

GitHub Actions / build

The field 'UpdateService._updateCts' is never used
private Patches? _cachedPatches;
private bool _forceValidateAllOnce;

public async Task<bool> CheckForUpdatesAsync()
{
if (IsCheckingUpdates || IsUpdating || IsInstalling)
{
string errorMsg = "Update check already in progress";
Terminal.Warning(errorMsg);
ErrorLogger.LogError("UpdateService.CheckForUpdatesAsync", errorMsg, "Multiple update check attempts");
return false;
}

IsCheckingUpdates = true;

Expand All @@ -60,21 +65,41 @@

if (!File.Exists(csgoExe))
{
string errorMsg = "Game executable not found - installation needed";
Terminal.Print(errorMsg);
ErrorLogger.LogError("UpdateService.CheckForUpdatesAsync", errorMsg, $"Expected path: {csgoExe}");
IsNeedingInstall = true;
return true;
}

Terminal.Print("Checking for updates...");
var patches = await GetPatchesAsync();
if (patches == null)
{
string errorMsg = "Failed to retrieve patch information";
Terminal.Warning(errorMsg);
ErrorLogger.LogError("UpdateService.CheckForUpdatesAsync", errorMsg, "GetPatchesAsync returned null");
return false;
}

var needsUpdate = await ValidateFilesAsync(patches);
IsUpdateAvailable = needsUpdate;

if (needsUpdate)
{
Terminal.Print("Updates are available");
}
else
{
Terminal.Print("Game is up to date");
}

return needsUpdate;
}
catch (Exception ex)
{
string errorMsg = $"Update check failed: {ex.Message}";
Terminal.Error(errorMsg);
ErrorLogger.LogError("UpdateService.CheckForUpdatesAsync", ex, "Failed to check for updates");
return false;
}
Expand Down Expand Up @@ -248,16 +273,34 @@
private async Task<Patches?> GetPatchesAsync()
{
if (_cachedPatches != null)
{
Terminal.Print("Using cached patch information");
return _cachedPatches;
}

try
{
Terminal.Print("Fetching patch information from API...");
var patches = await PatchManager.ValidatePatches();
_cachedPatches = patches;

if (patches.Success)
{
_cachedPatches = patches;
Terminal.Print($"Patch validation complete: {patches.Missing.Count} missing, {patches.Outdated.Count} outdated");
}
else
{
string errorMsg = "Patch validation failed";
Terminal.Warning(errorMsg);
ErrorLogger.LogError("UpdateService.GetPatchesAsync", errorMsg, "PatchManager.ValidatePatches returned Success=false");
}

return patches;
}
catch (Exception ex)
{
string errorMsg = $"Failed to get patches: {ex.Message}";
Terminal.Error(errorMsg);
ErrorLogger.LogError("UpdateService.GetPatchesAsync", ex, "Failed to get patches");
return null;
}
Expand Down
64 changes: 57 additions & 7 deletions Wauncher/Utils/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
public static async Task<bool> Launch()
{
List<string> arguments = Argument.GenerateGameArguments();
if (arguments.Count > 0) Terminal.Print($"Arguments: {string.Join(" ", arguments)}");
if (arguments.Count > 0)
Terminal.Print($"Arguments: {string.Join(" ", arguments)}");

var settings = ViewModels.SettingsWindowViewModel.LoadGlobal();
string directory = Path.GetDirectoryName(Services.GetExePath()) ?? Directory.GetCurrentDirectory();
Expand All @@ -58,6 +59,14 @@

try
{
// Ensure the cfg directory exists
string cfgDirectory = Path.GetDirectoryName(gameStatePath) ?? "";
if (!Directory.Exists(cfgDirectory))
{
Directory.CreateDirectory(cfgDirectory);
Terminal.Print($"Created config directory: {cfgDirectory}");
}

string gameStateContents = $$"""
"ClassicCounter"
{
Expand All @@ -83,22 +92,36 @@
}
""";
await File.WriteAllTextAsync(gameStatePath, gameStateContents);
Terminal.Print("Game state integration config written successfully");
}
catch (Exception ex)
{
string errorMsg = "Failed to create game state integration config";
ErrorLogger.LogError("Game.Launch", ex, "Failed to write gamestate integration config");
Terminal.Error("(!) \"/csgo/cfg/gamestate_integration_cc.cfg\" not found in the current directory!");
Terminal.Error($"(!) \"/csgo/cfg/gamestate_integration_cc.cfg\" could not be created!");
ConsoleManager.ShowError($"{errorMsg}:\n{ex.Message}\n\nDiscord RPC and auto-connect features may not work properly.");
}
}
else if (File.Exists(gameStatePath))
{
File.Delete(gameStatePath);
try
{
File.Delete(gameStatePath);
Terminal.Print("Removed game state integration config (disabled)");
}
catch (Exception ex)
{
string errorMsg = "Failed to delete game state integration config";

Check warning on line 114 in Wauncher/Utils/Game.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'errorMsg' is assigned but its value is never used

Check warning on line 114 in Wauncher/Utils/Game.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'errorMsg' is assigned but its value is never used
ErrorLogger.LogError("Game.Launch", ex, "Failed to delete gamestate integration config");
Terminal.Warning("Could not delete game state integration config file");
}
}

_process = new Process();

string gameExe = "csgo.exe";
_process.StartInfo.FileName = Path.Combine(directory, gameExe);
string gameExePath = Path.Combine(directory, gameExe);
_process.StartInfo.FileName = gameExePath;
_process.StartInfo.Arguments = string.Join(" ", arguments);
_process.StartInfo.WorkingDirectory = directory;

Expand All @@ -111,12 +134,39 @@

if (!File.Exists(_process.StartInfo.FileName))
{
Terminal.Error($"(!) {gameExe} not found in the current directory!");
ConsoleManager.ShowError($"{gameExe} not found in the current directory!\n\nPlease make sure the launcher and game files are in the same folder.");
string errorMsg = $"{gameExe} not found in current directory!\n\nExpected path: {_process.StartInfo.FileName}";
Terminal.Error($"(!) {errorMsg}");
ConsoleManager.ShowError(errorMsg);
ErrorLogger.LogError("Game.Launch", "Game executable not found", $"Path: {_process.StartInfo.FileName}");
return false;
}

return _process.Start();
try
{
Terminal.Print($"Starting process: {_process.StartInfo.FileName} {_process.StartInfo.Arguments}");
bool started = _process.Start();

if (started)
{
Terminal.Print("Game process started successfully");
}
else
{
string errorMsg = "Failed to start game process (Process.Start returned false)";
Terminal.Error(errorMsg);
ErrorLogger.LogError("Game.Launch", errorMsg, $"Executable: {_process.StartInfo.FileName}, Arguments: {_process.StartInfo.Arguments}");
}

return started;
}
catch (Exception ex)
{
string errorMsg = $"Failed to start game process:\n{ex.Message}";
Terminal.Error($"(!) {errorMsg}");
ConsoleManager.ShowError(errorMsg);
ErrorLogger.LogError("Game.Launch", ex, $"Executable: {_process.StartInfo.FileName}, Arguments: {_process.StartInfo.Arguments}");
return false;
}
}

public static async Task Monitor()
Expand Down
Loading
Loading