diff --git a/SteamCleaner/ActionCommand.cs b/SteamCleaner/ActionCommand.cs index 202fc1d..6b1af4c 100644 --- a/SteamCleaner/ActionCommand.cs +++ b/SteamCleaner/ActionCommand.cs @@ -1,16 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +#region + +using System; using System.Windows.Input; +#endregion + namespace SteamCleaner { public class ActionCommand : ICommand { - private readonly Action _execute; private readonly Func _canExecute; + private readonly Action _execute; public ActionCommand(Action execute) : this(_ => execute(), null) { @@ -40,14 +40,8 @@ public void Execute(object parameter) public event EventHandler CanExecuteChanged { - add - { - CommandManager.RequerySuggested += value; - } - remove - { - CommandManager.RequerySuggested -= value; - } + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } } public void Refresh() @@ -55,4 +49,4 @@ public void Refresh() CommandManager.InvalidateRequerySuggested(); } } -} +} \ No newline at end of file diff --git a/SteamCleaner/App.xaml.cs b/SteamCleaner/App.xaml.cs index e335130..9bd6c79 100644 --- a/SteamCleaner/App.xaml.cs +++ b/SteamCleaner/App.xaml.cs @@ -1,23 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +#region + using System.Windows; using SteamCleaner.Utilities; +#endregion + namespace SteamCleaner { /// - /// Interaction logic for App.xaml + /// Interaction logic for App.xaml /// public partial class App : Application { - - void AppStartup(object sender, StartupEventArgs args) + private void AppStartup(object sender, StartupEventArgs args) { - - var mainWindow = new MainWindow { DataContext = new MainWindowViewModel() @@ -26,4 +22,4 @@ void AppStartup(object sender, StartupEventArgs args) Tools.CheckForUpdates(); } } -} +} \ No newline at end of file diff --git a/SteamCleaner/ConfirmationDialog.xaml.cs b/SteamCleaner/ConfirmationDialog.xaml.cs index 4a18767..963e549 100644 --- a/SteamCleaner/ConfirmationDialog.xaml.cs +++ b/SteamCleaner/ConfirmationDialog.xaml.cs @@ -1,22 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +#region + using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; + +#endregion namespace SteamCleaner { /// - /// Interaction logic for ConfirmationDialog.xaml + /// Interaction logic for ConfirmationDialog.xaml /// public partial class ConfirmationDialog : UserControl { @@ -25,4 +16,4 @@ public ConfirmationDialog() InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/SteamCleaner/FailuresDialog.xaml.cs b/SteamCleaner/FailuresDialog.xaml.cs index 92ba199..96ea31b 100644 --- a/SteamCleaner/FailuresDialog.xaml.cs +++ b/SteamCleaner/FailuresDialog.xaml.cs @@ -1,22 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +#region + using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; + +#endregion namespace SteamCleaner { /// - /// Interaction logic for FailuresDialog.xaml + /// Interaction logic for FailuresDialog.xaml /// public partial class FailuresDialog : UserControl { @@ -25,4 +16,4 @@ public FailuresDialog() InitializeComponent(); } } -} +} \ No newline at end of file diff --git a/SteamCleaner/FileViewModel.cs b/SteamCleaner/FileViewModel.cs index 137725d..7274f9b 100644 --- a/SteamCleaner/FileViewModel.cs +++ b/SteamCleaner/FileViewModel.cs @@ -1,4 +1,8 @@ -using System; +#region + +using System; + +#endregion namespace SteamCleaner { diff --git a/SteamCleaner/MainWindow.xaml.cs b/SteamCleaner/MainWindow.xaml.cs index 0853ae5..8049ce0 100644 --- a/SteamCleaner/MainWindow.xaml.cs +++ b/SteamCleaner/MainWindow.xaml.cs @@ -1,22 +1,14 @@ -using System; -using System.Collections.Generic; +#region + using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; + +#endregion namespace SteamCleaner { /// - /// Interaction logic for MainWindow.xaml + /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { @@ -45,6 +37,4 @@ private void ReportABugMenuItem_OnClick(object sender, RoutedEventArgs e) Process.Start("https://github.com/Codeusa/SteamCleaner/issues"); } } - - -} +} \ No newline at end of file diff --git a/SteamCleaner/MainWindowViewModel.cs b/SteamCleaner/MainWindowViewModel.cs index 42f9978..89a2726 100644 --- a/SteamCleaner/MainWindowViewModel.cs +++ b/SteamCleaner/MainWindowViewModel.cs @@ -1,20 +1,20 @@ -using System.Collections.Generic; +#region + using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.Windows.Input; using SteamCleaner.Utilities; +#endregion + namespace SteamCleaner { public class MainWindowViewModel : INotifyPropertyChanged { - private readonly ObservableCollection _pathsInternal = new ObservableCollection(); private readonly ObservableCollection _filesInternal = new ObservableCollection(); + private readonly ObservableCollection _pathsInternal = new ObservableCollection(); private string _statistics; public MainWindowViewModel() @@ -27,7 +27,6 @@ public MainWindowViewModel() //TODO run on a background thread, add spinner etc RunRefresh(); - } @@ -50,6 +49,8 @@ public string Statistics } } + public event PropertyChangedEventHandler PropertyChanged; + private void RunRefresh() { //needs to be called to ensure we aren't loading a previously stored object. @@ -57,12 +58,20 @@ private void RunRefresh() _pathsInternal.Clear(); foreach (var steamPath in SteamUtilities.SteamPaths()) _pathsInternal.Add(steamPath); + if (GoGUtilities.GoGExisit()) + { + _pathsInternal.Add("GoG Games Detected"); + } _filesInternal.Clear(); - foreach (var fileViewModel in CleanerUtilities.FindRedistributables().Select(r => new FileViewModel(r.Path, StringUtilities.GetBytesReadable(r.Size)))) - _filesInternal.Add(fileViewModel); - - Statistics = CleanerUtilities.TotalFiles() + " files have been found (" + CleanerUtilities.TotalTakenSpace() + ") "; + foreach ( + var fileViewModel in + CleanerUtilities.FindRedistributables() + .Select(r => new FileViewModel(r.Path, StringUtilities.GetBytesReadable(r.Size)))) + _filesInternal.Add(fileViewModel); + + Statistics = CleanerUtilities.TotalFiles() + " files have been found (" + CleanerUtilities.TotalTakenSpace() + + ") "; } private async void RunClean() @@ -70,7 +79,6 @@ private async void RunClean() await CleanerUtilities.CleanData(); RunRefresh(); - } private async void CheckForUpdate() @@ -78,11 +86,9 @@ private async void CheckForUpdate() Tools.CheckForUpdates(); } - public event PropertyChangedEventHandler PropertyChanged; - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } -} +} \ No newline at end of file diff --git a/SteamCleaner/Properties/AssemblyInfo.cs b/SteamCleaner/Properties/AssemblyInfo.cs index 28450d1..a961400 100644 --- a/SteamCleaner/Properties/AssemblyInfo.cs +++ b/SteamCleaner/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] \ No newline at end of file diff --git a/SteamCleaner/SteamCleaner.csproj b/SteamCleaner/SteamCleaner.csproj index cae7aa7..663f1cd 100644 --- a/SteamCleaner/SteamCleaner.csproj +++ b/SteamCleaner/SteamCleaner.csproj @@ -90,6 +90,7 @@ + diff --git a/SteamCleaner/Utilities/CleanerUtilities.cs b/SteamCleaner/Utilities/CleanerUtilities.cs index 9bbb0f3..82f064e 100644 --- a/SteamCleaner/Utilities/CleanerUtilities.cs +++ b/SteamCleaner/Utilities/CleanerUtilities.cs @@ -2,11 +2,9 @@ using System; using System.Collections.Generic; -using System.Drawing.Text; using System.IO; using System.Linq; using System.Text.RegularExpressions; -using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -24,11 +22,10 @@ internal class CleanerUtilities private static List DetectRedistributablesWalk(string sDir) { - var files = new List(); - + foreach (var d in from d in Directory.GetDirectories(sDir) - let regex = new Regex("(.*)(directx|redist|miles|support)(.*)", RegexOptions.IgnoreCase) + let regex = new Regex("(.*)(directx|redist|miles|support|installer)(.*)", RegexOptions.IgnoreCase) let match = regex.Match(d) where match.Success select d) @@ -46,7 +43,7 @@ where fileMatch.Success private static List DetectRenPyRedistributables(string sDir) { var files = new List(); - var filters = new string[] { "darwin", "linux" }; + var filters = new[] {"darwin", "linux"}; foreach (var d in Directory.GetDirectories(sDir).Where(d => d.Contains("\\lib"))) { files.AddRange(DetectRenPyRedistributables(d)); @@ -66,12 +63,19 @@ public static List FindRedistributables() return cachedRedistributables; } var steamPaths = SteamUtilities.SteamPaths(); - var crawlableDirs = steamPaths.Select(path => SteamUtilities.FixPath(path)).Where(appPath => Directory.Exists(appPath)).ToList(); - + var crawlableDirs = steamPaths.Select(SteamUtilities.FixPath).Where(Directory.Exists).ToList(); + crawlableDirs.AddRange(GoGUtilities.GoGGamePaths()); + var gameDirs = crawlableDirs.Select(Directory.GetDirectories).SelectMany(directories => directories).ToList(); + gameDirs.AddRange(GoGUtilities.GoGGamePaths()); //Probably a better way to detect if some retarded publisher nested their package in a folder, but atm capcom is the only one i've seen do it. - foreach (var nestedGameFolder in gameDirs.ToList().Where(gameDir => gameDir.ToLower().Contains("capcom")).Select(gameDir => new DirectoryInfo(gameDir).GetDirectories()).SelectMany(nestedGameFolders => nestedGameFolders)) + foreach ( + var nestedGameFolder in + gameDirs.ToList() + .Where(gameDir => gameDir.ToLower().Contains("capcom")) + .Select(gameDir => new DirectoryInfo(gameDir).GetDirectories()) + .SelectMany(nestedGameFolders => nestedGameFolders)) { gameDirs.Add(nestedGameFolder.FullName); } @@ -80,8 +84,7 @@ public static List FindRedistributables() foreach (var dir in gameDirs) { redistFiles.AddRange(DetectRedistributablesWalk(dir)); - redistFiles.AddRange(DetectRenPyRedistributables(dir)); - + redistFiles.AddRange(DetectRenPyRedistributables(dir)); } var cleanAbleFiles = redistFiles.Select(file => new Redistributables { @@ -134,7 +137,8 @@ public static async Task CleanData() ((o, args) => DeleteFiles(redistributables, progressBar, args.Session))); } - private static void DeleteFiles(IEnumerable redistributables, ProgressBar progressBar, DialogSession dialogSession) + private static void DeleteFiles(IEnumerable redistributables, ProgressBar progressBar, + DialogSession dialogSession) { Task.Factory.StartNew(() => { @@ -144,13 +148,13 @@ private static void DeleteFiles(IEnumerable redistributables, { progressBar.Dispatcher.BeginInvoke(new Action(() => progressBar.Value = item.idx)); try - { + { if (File.Exists(item.red.Path)) File.Delete(item.red.Path); } catch { - failures.Add(item.red.Path); + failures.Add(item.red.Path); } } @@ -161,8 +165,8 @@ private static void DeleteFiles(IEnumerable redistributables, dialogSession.UpdateContent(failuresDialog); })); else - progressBar.Dispatcher.BeginInvoke(new Action(dialogSession.Close)); - }); + progressBar.Dispatcher.BeginInvoke(new Action(dialogSession.Close)); + }); } public class Redistributables diff --git a/SteamCleaner/Utilities/GoGUtilities.cs b/SteamCleaner/Utilities/GoGUtilities.cs new file mode 100644 index 0000000..4190cc1 --- /dev/null +++ b/SteamCleaner/Utilities/GoGUtilities.cs @@ -0,0 +1,61 @@ +#region + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Microsoft.Win32; + +#endregion + +namespace SteamCleaner.Utilities +{ + internal class GoGUtilities + { + public static bool GoGExisit() + { + var regPath = ""; + var is64Bit = Environment.Is64BitOperatingSystem; + if (is64Bit) + { + Console.WriteLine("64 Bit operating system detected"); + regPath = "SOFTWARE\\WOW6432Node\\GOG.com\\Games"; + } + else + { + Console.WriteLine("32 Bit operating system detected"); + regPath = "SOFTWARE\\GOG.com\\Games"; + } + var root = Registry.LocalMachine.OpenSubKey(regPath); + return root != null; + } + + public static List GoGGamePaths() + { + var regPath = ""; + var paths = new List(); + var is64Bit = Environment.Is64BitOperatingSystem; + if (is64Bit) + { + Console.WriteLine("64 Bit operating system detected"); + regPath = "SOFTWARE\\WOW6432Node\\GOG.com\\Games"; + } + else + { + Console.WriteLine("32 Bit operating system detected"); + regPath = "SOFTWARE\\GOG.com\\Games"; + } + + var root = Registry.LocalMachine.OpenSubKey(regPath); + if (root != null) + paths.AddRange( + root.GetSubKeyNames() + .Select(keyname => root.OpenSubKey(keyname)) + .Where(key => key != null) + .Select(key => key.GetValue("PATH")) + .Select(o => o.ToString()) + .Where(Directory.Exists)); + return paths; + } + } +} \ No newline at end of file diff --git a/SteamCleaner/Utilities/SteamUtilities.cs b/SteamCleaner/Utilities/SteamUtilities.cs index de9210a..2c07bb1 100644 --- a/SteamCleaner/Utilities/SteamUtilities.cs +++ b/SteamCleaner/Utilities/SteamUtilities.cs @@ -56,20 +56,28 @@ public static List SteamPaths() public static int CountOccurences(string needle, string haystack) { - return (haystack.Length - haystack.Replace(needle, "").Length) / needle.Length; + return (haystack.Length - haystack.Replace(needle, "").Length)/needle.Length; } public static List GetSecondarySteamInstallPaths() { var configPath = GetSteamPath() + "\\config\\config.vdf"; var data = File.ReadAllText(configPath); - int numberOfInstallPaths = CountOccurences("BaseInstallFolder", data); + var numberOfInstallPaths = CountOccurences("BaseInstallFolder", data); var dataArray = File.ReadAllLines(configPath); var paths = new List(); for (var i = 0; i < numberOfInstallPaths; i++) { var slot = i + 1; - paths.AddRange(from t in dataArray where t.Contains("BaseInstallFolder_" + slot) select t.Trim() into dataString let regex = new Regex("\\\"(.*)\\\"(.*)\\\"", RegexOptions.IgnoreCase) select regex.Match(dataString) into match where match.Success select FixPath(match.Groups[2].Value).Replace("\\\\", "\\")); + paths.AddRange(from t in dataArray + where t.Contains("BaseInstallFolder_" + slot) + select t.Trim() + into dataString + let regex = new Regex("\\\"(.*)\\\"(.*)\\\"", RegexOptions.IgnoreCase) + select regex.Match(dataString) + into match + where match.Success + select FixPath(match.Groups[2].Value).Replace("\\\\", "\\")); } return paths; } diff --git a/SteamCleaner/Utilities/Tools.cs b/SteamCleaner/Utilities/Tools.cs index 8adbac0..9aea44a 100644 --- a/SteamCleaner/Utilities/Tools.cs +++ b/SteamCleaner/Utilities/Tools.cs @@ -154,9 +154,7 @@ public static async void CheckForUpdates() MessageTextBlock = { Text = "A new Steam Cleaner update is available, update now?" - } - }; var result = await DialogHost.Show(dialog); diff --git a/version.xml b/version.xml index eddc553..6c6c4a2 100644 --- a/version.xml +++ b/version.xml @@ -1,5 +1,5 @@ - 1.3 + 1.4 https://github.com/Codeusa/SteamCleaner/releases/latest