Skip to content
This repository has been archived by the owner on May 15, 2022. It is now read-only.

Commit

Permalink
Fix UX Issues
Browse files Browse the repository at this point in the history
* When steam is running when the user attempts to clear its cache, lock the patcher window until the messagebox is responded to.
(Hacky fix, I will try to improve when I have more time, but it works)

* Prevent buttons from being enabled when functions are running.
  • Loading branch information
PhantomGamers committed Sep 23, 2020
1 parent 01fe314 commit 1374bcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Forms/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,19 @@ private static void ExitButton_Click(object sender, EventArgs e)

private async void ToggleScanButton_Click(object sender, RoutedEventArgs e)
{
ToggleButtons(false);
await Task.Run(() => FileWatcher.ToggleCacheScanner(!FileWatcher.scannerExists)).ConfigureAwait(false);
}

private async void ForceCheckButton_Click(object sender, RoutedEventArgs e)
{
ToggleButtons(false);
await Task.Run(() => Program.FindCacheFile(true)).ConfigureAwait(false);
}

private async void ClearCacheButton_Click(object sender, RoutedEventArgs e)
{
ToggleButtons(false);
await Task.Run(Program.ClearSteamCache).ConfigureAwait(false);
}

Expand Down
25 changes: 17 additions & 8 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Threading;

using static SteamFriendsPatcher.Utilities;

Expand Down Expand Up @@ -76,6 +77,8 @@ public enum LogLevel

private static readonly MainWindow Main = App.MainWindowRef;

private static int hackyThreadingFix = 2;

public static bool UpdateChecker()
{
lock (UpdateScannerLock)
Expand Down Expand Up @@ -439,7 +442,7 @@ public static bool GetLatestFriendsCss(bool force = false)
}

private static string FindSteamDir() { return GetRegistryData(@"SOFTWARE\Valve\Steam", "SteamPath").ToString().Replace(@"/", @"\"); }
private static int GetRunningGameID() { return (int)GetRegistryData(@"SOFTWARE\Valve\Steam", "RunningAppID"); }
private static int GetRunningGameID() { return (int)GetRegistryData(@"SOFTWARE\Valve\Steam", "RunningAppID"); }
private static string GetRunningGameName() { return GetRegistryData(@"SOFTWARE\Valve\Steam\Apps\" + GetRunningGameID(), "Name").ToString(); }

private static object GetRegistryData(string aKey, string aValueName)
Expand All @@ -461,7 +464,7 @@ private static bool FindFriendsWindow()

private static bool GameRunningCheck()
{
if(GetRunningGameID() != 0)
if (GetRunningGameID() != 0)
{
Print($"{GetRunningGameName()} is running, aborting Steam shutdown.", LogLevel.Warning);
return true;
Expand All @@ -471,7 +474,7 @@ private static bool GameRunningCheck()

private static bool ShutdownSteam()
{
if(GameRunningCheck()) return false;
if (GameRunningCheck()) return false;
var steamp = Process.GetProcessesByName("Steam").FirstOrDefault();
Print("Shutting down Steam...");
Process.Start(steamDir + "\\Steam.exe", "-shutdown");
Expand Down Expand Up @@ -514,15 +517,21 @@ public static void ClearSteamCache()
var preSteamStatus = Process.GetProcessesByName("Steam").FirstOrDefault() != null;
if (preSteamStatus)
{
if (MessageBox.Show("Steam will need to be shutdown to clear cache. Restart automatically?",
"Steam Friends Patcher", MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;

hackyThreadingFix = 2;
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
{
hackyThreadingFix = MessageBox.Show("Steam will need to be shutdown to clear cache. Restart automatically?",
"Steam Friends Patcher", MessageBoxButton.YesNo) == MessageBoxResult.Yes ? 0 : 1;
}));
}

if(!ShutdownSteam()) return;
while (preSteamStatus && hackyThreadingFix == 2) Task.Delay(TimeSpan.FromMilliseconds(100));

if(hackyThreadingFix == 1) { Main.ToggleButtons(true); return; }

if (!ShutdownSteam()) return;

FileWatcher.ToggleCacheScanner(false);
Main.ToggleButtons(false);

Print("Deleting cache files...");
try
Expand Down

0 comments on commit 1374bcb

Please sign in to comment.