Skip to content

Commit

Permalink
Look for Steam App leftovers in some of Steam's temp folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Klocman committed Mar 3, 2023
1 parent 0d21e69 commit 61d5def
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion source/UninstallTools/Factory/SteamFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security;
using Klocman.IO;
using Klocman.Tools;
using UninstallTools.Junk;
using UninstallTools.Junk.Confidence;
using UninstallTools.Junk.Containers;
using UninstallTools.Properties;

namespace UninstallTools.Factory
{
public class SteamFactory : IIndependantUninstallerFactory
public class SteamFactory : IIndependantUninstallerFactory, IJunkCreator
{
private static bool? _steamHelperIsAvailable;
private static string _steamLocation;
Expand Down Expand Up @@ -61,6 +67,8 @@ private static void GetSteamInfo()
internal static string SteamHelperPath
=> Path.Combine(UninstallToolsGlobalConfig.AssemblyLocation, @"SteamHelper.exe");

#region IIndependantUninstallerFactory

public IList<ApplicationUninstallerEntry> GetUninstallerEntries(
ListGenerationProgress.ListGenerationCallback progressCallback)
{
Expand Down Expand Up @@ -96,5 +104,59 @@ internal static string SteamHelperPath

public bool IsEnabled() => UninstallToolsGlobalConfig.ScanSteam;
public string DisplayName => Localisation.Progress_AppStores_Steam;

#endregion

#region IJunkCreator

private static readonly string[] TempFolderNames = { "downloading", "shadercache", "temp" };
public void Setup(ICollection<ApplicationUninstallerEntry> allUninstallers) { }
public IEnumerable<IJunkResult> FindJunk(ApplicationUninstallerEntry target)
{
if (target.UninstallerKind != UninstallerType.Steam)
return Enumerable.Empty<IJunkResult>();

var results = new List<IJunkResult>();
try
{
// Look for this appID in steam library's temporary folders (game is inside "common" folder, temp folders are next to that)
var d = new DirectoryInfo(target.InstallLocation);
if (d.Parent?.Name == "common" && d.Parent.Parent != null)
{
var libraryDir = d.Parent.Parent.FullName;
Debug.Assert(target.RatingId.StartsWith("Steam App "));
var appIdStr = target.RatingId.Substring("Steam App ".Length);
foreach (var cacheFolderName in TempFolderNames)
{
var subpath = Path.Combine(libraryDir, cacheFolderName, appIdStr);
if (Directory.Exists(subpath))
{
var junk = new FileSystemJunk(new DirectoryInfo(subpath), target, this);
junk.Confidence.Add(ConfidenceRecords.ExplicitConnection);
junk.Confidence.Add(4);
results.Add(junk);
}
}
}
else
{
Debug.Fail(target.InstallLocation + " does not point inside of a steam library's common folder");
}

}
catch (SecurityException e)
{
Console.WriteLine(e);
}
catch (IOException e)
{
Console.WriteLine(e);
}
return results;
}

public string CategoryName { get; } = Localisation.UninstallerType_Steam;

#endregion
}
}

0 comments on commit 61d5def

Please sign in to comment.