private static void Setup() { if (Settings.Default.checkForUpdates) { Task.Run(Program.UpdateChecker); ToggleUpdateTimer(); } if (Settings.Default.autoScanOnStartup) { FileWatcher.ToggleCacheScanner(true); } if (Settings.Default.runSteamOnStartup && Process.GetProcessesByName("Steam").FirstOrDefault() == null) { Process.Start(Program.steamDir + "\\Steam.exe", Settings.Default.steamLaunchArgs); } if (Settings.Default.forceScanOnStartup) { Program.FindCacheFile(); } }
public static void ClearSteamCache() { var LibraryCSSDir = Path.Combine(LibraryUIDir, "css"); if (!Directory.Exists(SteamCacheDir) && !Directory.Exists(LibraryCSSDir)) { Print("Cache folder does not exist.", LogLevel.Warning); return; } var preScannerStatus = FileWatcher.scannerExists; var preSteamStatus = Process.GetProcessesByName("Steam").FirstOrDefault() != null; if (preSteamStatus) { 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; })); } while (preSteamStatus && hackyThreadingFix == 2) { Task.Delay(TimeSpan.FromMilliseconds(100)); } if (hackyThreadingFix == 1) { Main.ToggleButtons(true); return; } if (!ShutdownSteam()) { Main.ToggleButtons(true); return; } FileWatcher.ToggleCacheScanner(false); if (!Directory.Exists(SteamCacheDir)) { goto librarycss; } Print("Deleting cache files..."); try { Directory.Delete(SteamCacheDir, true); } catch (IOException ioe) { Print("Some cache files in use, cannot delete.", LogLevel.Error); Print(ioe.ToString(), LogLevel.Error); } finally { Print("Cache files deleted."); } librarycss: if (Directory.Exists(LibraryCSSDir)) { Print("Deleting patched library file..."); Directory.Delete(LibraryCSSDir, true); } FileWatcher.ToggleCacheScanner(preScannerStatus); if (preSteamStatus) { StartSteam(); } Main.ToggleButtons(true); }
public static void FindCacheFile(bool forceUpdate = false) { Settings.Default.Reload(); var preScannerStatus = FileWatcher.scannerExists; FileWatcher.ToggleCacheScanner(false); Main.ToggleButtons(false); Print("Force scan started."); GetLatestFriendsCss(forceUpdate); while (updatePending) { Task.Delay(TimeSpan.FromMilliseconds(20)).Wait(); } if (friendsCssCrcs[0] == null && friendsCssCrcs[1] == null) { Print("Friends.css could not be obtained, ending force check..."); goto ResetButtons; } Print("Finding list of possible cache files..."); if (!Directory.Exists(SteamCacheDir)) { Print("Cache folder does not exist.", LogLevel.Error); Print("Please confirm that Steam is running and that the friends list is open and try again.", LogLevel.Error); goto ResetButtons; } var validFiles = new DirectoryInfo(SteamCacheDir).EnumerateFiles("f_*", SearchOption.TopDirectoryOnly) .Where(f => f.Length >= friendsCssesPatched[0].Length / 2 || f.Length <= friendsCssesPatched[0].Length * 2) .OrderByDescending(f => f.LastWriteTime) .Select(f => f.FullName) .ToList(); var count = validFiles.Count; if (count == 0) { Print("No matching cache files found.", LogLevel.Error); Print("Please confirm that Steam is running and that the friends list is open and try again.", LogLevel.Error); goto ResetButtons; } Print($"Found {count} possible cache files."); string friendscachefile = null; var patchedFileFound = false; Print("Checking cache files for match..."); Parallel.ForEach(validFiles, (s, state) => { for (int i = 0; i < friendsCssUrls.Count; i++) { if (CompareCRC(s, friendsCssCrcs[i])) { byte[] cachefile; try { using (var f = new FileStream(s, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { cachefile = new byte[f.Length]; f.Read(cachefile, 0, cachefile.Length); } } catch { Print($"Error, {s} could not be opened.", LogLevel.Debug); return; } friendscachefile = s; PatchCacheFile(s, Decompress(cachefile), i); return; } else { patchedFileFound = CompareCRC(s, friendsCssesPatched[i]) || patchedFileFound; } } }); if (string.IsNullOrEmpty(friendscachefile)) { if (!patchedFileFound) { Print("Cache file does not exist, is outdated, or is different from expected.", LogLevel.Warning); } else { Print("Cache file is already patched."); } } ResetButtons: PatchLibrary(); Main.ToggleButtons(true); if (preScannerStatus) { FileWatcher.ToggleCacheScanner(true); } }