Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-379: Change clear-cache to clear-temp #382

Merged
merged 4 commits into from
Sep 17, 2024
Merged
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
212 changes: 110 additions & 102 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,102 +1,110 @@
#TODO move this to lancache common
root = true

[*]
end_of_line = lf

[*.js]
indent_style = tab
tab_size = 4
curly_bracket_next_line = true

[*.py]
indent_style = tab
tab_size = 4

[*.csproj]
indent_style = space
indent_size = 2

# .NET formatting rules. See https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules
# Resharper Rules. See https://www.jetbrains.com/help/resharper/EditorConfig_Index.html
[*.cs]
# TODO change this to tab in all projects.
indent_style = space
indent_size = 4

# ----- Resharper Rules -----
# https://www.jetbrains.com/help/resharper/EditorConfig_CSHARP_CSharpIndentStylePageSchema.html#resharper_csharp_align_linq_query
align_linq_query = true
align_multiline_calls_chain = true
# Won't force add blank lines after block statements
blank_lines_after_block_statements = 0
csharp_prefer_braces = true
csharp_space_after_cast = false
indent_preprocessor_region = do_not_change
space_between_attribute_sections = false


# CA1002: Do not expose generic lists
dotnet_diagnostic.CA1002.severity = none
# CA1008: Enums should have zero value
# - The enums in this case are modeling Steam enums, so I have to match them exactly.
dotnet_diagnostic.CA1008.severity = none
# CA1014: Mark assemblies with CLSCompliant
dotnet_diagnostic.CA1014.severity = none
# CA1031: Modify (method) to catch a more specific allowed exception type, or rethrow the exception
dotnet_diagnostic.CA1031.severity = none
# CA1034: Nested types should not be visible
dotnet_diagnostic.CA1034.severity = none

# CA1051: Do not declare visible instance fields
dotnet_diagnostic.CA1051.severity = none
# CA1054: URI parameters should not be strings
dotnet_diagnostic.CA1054.severity = none
# CA1056: URI properties should not be strings
dotnet_diagnostic.CA1056.severity = none
# CA1062: Validate arguments of public methods
dotnet_diagnostic.CA1062.severity = none
# CA1305: The behavior of 'int.Parse(string)' could vary based on the current user's locale settings.
dotnet_diagnostic.CA1305.severity = none
# CA1307: Specify StringComparison for clarity
dotnet_diagnostic.CA1307.severity = none
dotnet_diagnostic.CA1310.severity = none
# CA1815: Override equals and operator equals on value types
dotnet_diagnostic.CA1815.severity = none
# CA1822: Member does not access instance data and can be marked as static
dotnet_diagnostic.CA1822.severity = none

# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
# - I'm not worried about performance in this application where ContainsKey() is being used, and I like the current syntax as far as readability
dotnet_diagnostic.CA1854.severity = none

# CA1860: Avoid using 'Enumerable.Any()' extension method, both for clarity and performance
# - I don't agree with this analyzer, using Any() is far more readable than comparing Count == 0, and has been a pattern in dotnet for more than a decade
dotnet_diagnostic.CA1860.severity = none

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = none
# CA2201: Do not raise reserved exception types
dotnet_diagnostic.CA2201.severity = none

# CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.cs1998.severity = error
# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed
dotnet_diagnostic.cs4014.severity = error

# IDE0028: Simplify collection initialization
# - Not a fan of the syntax, feels a little bit too terse
dotnet_style_prefer_collection_expression = false

# IDE0090 : 'new' expression can be simplified
csharp_style_implicit_object_creation_when_type_is_apparent = false

# IDE0290: Use primary constructor
# - I'm a fan of this syntax in Typescript, but it still feels a bit too jarring seeing it C# now
csharp_style_prefer_primary_constructors = false

# Banned APIs will be bumped up to an error instead of warning
dotnet_diagnostic.rs0030.severity = error

# The method does not need to use async/await - Introduces annoying 'return' statements for async methods, that hurt code readability.
dotnet_diagnostic.AsyncFixer01.severity = none
#TODO move this to lancache common
root = true

[*]
end_of_line = lf

[*.js]
indent_style = tab
tab_size = 4
curly_bracket_next_line = true

[*.py]
indent_style = tab
tab_size = 4

[*.csproj]
indent_style = space
indent_size = 2

# .NET formatting rules. See https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/formatting-rules
# Resharper Rules. See https://www.jetbrains.com/help/resharper/EditorConfig_Index.html
[*.cs]
# TODO change this to tab in all projects.
indent_style = space
indent_size = 4

# ----- Resharper Rules -----
# https://www.jetbrains.com/help/resharper/EditorConfig_CSHARP_CSharpIndentStylePageSchema.html#resharper_csharp_align_linq_query
align_linq_query = true
align_multiline_calls_chain = true
# Won't force add blank lines after block statements
blank_lines_after_block_statements = 0
csharp_prefer_braces = true
csharp_space_after_cast = false
indent_preprocessor_region = do_not_change
space_between_attribute_sections = false


# CA1002: Do not expose generic lists
dotnet_diagnostic.CA1002.severity = none
# CA1008: Enums should have zero value
# - The enums in this case are modeling Steam enums, so I have to match them exactly.
dotnet_diagnostic.CA1008.severity = none
# CA1014: Mark assemblies with CLSCompliant
dotnet_diagnostic.CA1014.severity = none
# CA1031: Modify (method) to catch a more specific allowed exception type, or rethrow the exception
dotnet_diagnostic.CA1031.severity = none
# CA1034: Nested types should not be visible
dotnet_diagnostic.CA1034.severity = none

# CA1051: Do not declare visible instance fields
dotnet_diagnostic.CA1051.severity = none
# CA1054: URI parameters should not be strings
dotnet_diagnostic.CA1054.severity = none
# CA1056: URI properties should not be strings
dotnet_diagnostic.CA1056.severity = none
# CA1062: Validate arguments of public methods
dotnet_diagnostic.CA1062.severity = none
# CA1305: The behavior of 'int.Parse(string)' could vary based on the current user's locale settings.
dotnet_diagnostic.CA1305.severity = none
# CA1307: Specify StringComparison for clarity
dotnet_diagnostic.CA1307.severity = none
dotnet_diagnostic.CA1310.severity = none
# CA1815: Override equals and operator equals on value types
dotnet_diagnostic.CA1815.severity = none
# CA1822: Member does not access instance data and can be marked as static
dotnet_diagnostic.CA1822.severity = none

# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
# - I'm not worried about performance in this application where ContainsKey() is being used, and I like the current syntax as far as readability
dotnet_diagnostic.CA1854.severity = none

# CA1860: Avoid using 'Enumerable.Any()' extension method, both for clarity and performance
# - I don't agree with this analyzer, using Any() is far more readable than comparing Count == 0, and has been a pattern in dotnet for more than a decade
dotnet_diagnostic.CA1860.severity = none

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = none
# CA2201: Do not raise reserved exception types
dotnet_diagnostic.CA2201.severity = none

# CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.cs1998.severity = error
# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed
dotnet_diagnostic.cs4014.severity = error

# IDE0028: Simplify collection initialization
# - Not a fan of the syntax, feels a little bit too terse
dotnet_style_prefer_collection_expression = false

# IDE0074: Use compound assignment
# - I'm not a big fan of this syntax, I find it a bit difficult to read similarly how I find ternary operators difficult to read.
dotnet_diagnostic.IDE0074.severity = none

# IDE0090 : 'new' expression can be simplified
csharp_style_implicit_object_creation_when_type_is_apparent = false

# IDE0270: Null check can be simplified
dotnet_style_coalesce_expression = false
dotnet_diagnostic.IDE0270.severity = none

# IDE0290: Use primary constructor
# - I'm a fan of this syntax in Typescript, but it still feels a bit too jarring seeing it C# now
csharp_style_prefer_primary_constructors = false

# Banned APIs will be bumped up to an error instead of warning
dotnet_diagnostic.rs0030.severity = error

# The method does not need to use async/await - Introduces annoying 'return' statements for async methods, that hurt code readability.
dotnet_diagnostic.AsyncFixer01.severity = none
2 changes: 1 addition & 1 deletion LancachePrefill.Common
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
namespace SteamPrefill.CliCommands
{
[UsedImplicitly]
[Command("clear-cache", Description = "Empties out temporary cached data, to free up disk space")]
public sealed class ClearCacheCommand : ICommand
[Command("clear-temp", Description = "Empties out temporary data, such as saved manifests, to free up disk space")]
public sealed class ClearTempCommand : ICommand
{
[CommandOption("yes", shortName: 'y', Description = "When specified, will clear the cache without prompting", Converter = typeof(NullableBoolConverter))]
[CommandOption("yes", shortName: 'y', Description = "When specified, will clear the temp files without prompting.", Converter = typeof(NullableBoolConverter))]
public bool? AcceptPrompt { get; init; }

public ValueTask ExecuteAsync(IConsole console)
Expand All @@ -14,28 +14,28 @@ public ValueTask ExecuteAsync(IConsole console)

var ansiConsole = console.CreateAnsiConsole();
// Remove the v1/v2/v3 sub-directories
var rootCacheDir = new DirectoryInfo(AppConfig.CacheDir).Parent;
var rootTempDir = new DirectoryInfo(AppConfig.TempDir).Parent;

// Scanning the cache directory to see how much space could be saved
List<FileInfo> cacheFolderContents = null;
ansiConsole.StatusSpinner().Start($"Scanning {Cyan("Cache")} directory...", ctx =>
// Scanning the temp directory to see how much space could be saved
List<FileInfo> tempFolderContents = null;
ansiConsole.StatusSpinner().Start($"Scanning {Cyan("temp")} directory...", ctx =>
{
cacheFolderContents = rootCacheDir.EnumerateFiles("*.*", SearchOption.AllDirectories).ToList();
tempFolderContents = rootTempDir.EnumerateFiles("*.*", SearchOption.AllDirectories).ToList();
});

var totalSizeOnDisk = ByteSize.FromBytes(cacheFolderContents.Sum(e => e.Length));
if (totalSizeOnDisk.Bytes == 0 && cacheFolderContents.Count == 0)
var totalSizeOnDisk = ByteSize.FromBytes(tempFolderContents.Sum(e => e.Length));
if (totalSizeOnDisk.Bytes == 0 && tempFolderContents.Count == 0)
{
ansiConsole.LogMarkupLine($"Nothing to cleanup! {Cyan("Cache")} directory is already empty!");
ansiConsole.LogMarkupLine($"Nothing to cleanup! {Cyan("temp")} directory is already empty!");
return default;
}
ansiConsole.LogMarkupLine($"Found {LightYellow(cacheFolderContents.Count)} cached files, totaling {Magenta(totalSizeOnDisk.ToDecimalString())}");
ansiConsole.LogMarkupLine($"Found {LightYellow(tempFolderContents.Count)} temp files, totaling {Magenta(totalSizeOnDisk.ToDecimalString())}");

// If user hasn't passed in the accept flag, then we should ask them if they want to delete the files
if (!(AcceptPrompt ?? false))
{
var userResponse = ansiConsole.Prompt(new SelectionPrompt<bool>()
.Title("Continue to empty cache?")
.Title("Continue to delete temp files?")
.AddChoices(true, false)
.UseConverter(e => e == false ? "No" : "Yes"));
filesShouldBeDeleted = filesShouldBeDeleted || userResponse;
Expand All @@ -46,9 +46,9 @@ public ValueTask ExecuteAsync(IConsole console)
return default;
}

ansiConsole.StatusSpinner().Start("Deleting cached files...", ctx =>
ansiConsole.StatusSpinner().Start("Deleting temp files...", ctx =>
{
Directory.Delete(rootCacheDir.FullName, true);
Directory.Delete(rootTempDir.FullName, true);
});
ansiConsole.LogMarkupLine("Done!");

Expand Down
2 changes: 1 addition & 1 deletion SteamPrefill/CliCommands/PrefillCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async ValueTask ExecuteAsync(IConsole console)
// Property must be set to false in order to disable ansi escape sequences
_ansiConsole.Profile.Capabilities.Ansi = !NoAnsiEscapeSequences ?? true;

await UpdateChecker.CheckForUpdatesAsync(typeof(Program), "tpill90/steam-lancache-prefill", AppConfig.CacheDir);
await UpdateChecker.CheckForUpdatesAsync(typeof(Program), "tpill90/steam-lancache-prefill", AppConfig.TempDir);

var downloadArgs = new DownloadArguments
{
Expand Down
2 changes: 1 addition & 1 deletion SteamPrefill/Models/DepotInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public sealed class DepotInfo

public ulong? ManifestId { get; set; }

public string ManifestFileName => $"{AppConfig.CacheDir}/{_originalAppId}_{ContainingAppId}_{DepotId}_{ManifestId}.bin";
public string ManifestFileName => $"{AppConfig.TempDir}/{_originalAppId}_{ContainingAppId}_{DepotId}_{ManifestId}.bin";

/// <summary>
/// Determines what app actually owns the depot, by default it is the current app.
Expand Down
10 changes: 5 additions & 5 deletions SteamPrefill/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
"commandName": "Project",
"commandLineArgs": "benchmark run"
},
"Clear cache": {
"commandName": "Project",
"commandLineArgs": "clear-cache"
},
"Stats": {
"commandName": "Project",
"commandLineArgs": "status --nocache"
},
"Clear Temp": {
"commandName": "Project",
"commandLineArgs": "clear-temp"
}
}
}
}
21 changes: 8 additions & 13 deletions SteamPrefill/Settings/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ static AppConfig()
{
// Create required folders
Directory.CreateDirectory(ConfigDir);
Directory.CreateDirectory(CacheDir);
Directory.CreateDirectory(TempDir);
}

/// <summary>
Expand All @@ -31,12 +31,7 @@ public static bool VerboseLogs
/// Downloaded manifests, as well as other metadata, are saved into this directory to speedup future prefill runs.
/// All data in here should be able to be deleted safely.
/// </summary>
public static readonly string CacheDir = CacheDirUtils.GetCacheDirBaseDirectories("SteamPrefill", CacheDirVersion);

/// <summary>
/// Increment when there is a breaking change made to the files in the cache directory
/// </summary>
private const string CacheDirVersion = "v1";
public static readonly string TempDir = TempDirUtils.GetTempDirBaseDirectories("SteamPrefill", "v1");

/// <summary>
/// Contains user configuration. Should not be deleted, doing so will reset the app back to defaults.
Expand All @@ -54,22 +49,22 @@ public static bool VerboseLogs
public static readonly string UserSelectedAppsPath = Path.Combine(ConfigDir, "selectedAppsToPrefill.json");

/// <summary>
/// Keeps track of which depots have been previously downloaded. Is used to determine whether or not a game is up to date,
/// based on whether all of the depots being downloaded are up to date.
/// Keeps track of which depots have been previously downloaded. Is used to determine whether a game is up-to-date,
/// based on whether all the depots being downloaded are up-to-date.
/// </summary>
public static readonly string SuccessfullyDownloadedDepotsPath = Path.Combine(ConfigDir, "successfullyDownloadedDepots.json");

/// <summary>
/// Stores the user's current CellId, which corresponds to their region.
/// Stores the user's current CellId, which corresponds to their region.
/// </summary>
/// <see cref="Steam3Session.CellId">See for additional documentation</see>
public static readonly string CachedCellIdPath = Path.Combine(CacheDir, "cellId.txt");
public static readonly string CachedCellIdPath = Path.Combine(TempDir, "cellId.txt");

#endregion

#region Debugging
#region Debugging

public static readonly string DebugOutputDir = Path.Combine(CacheDir, "Debugging");
public static readonly string DebugOutputDir = Path.Combine(TempDir, "Debugging");

/// <summary>
/// Skips using locally cached manifests. Saves disk space, at the expense of slower subsequent runs. Intended for debugging.
Expand Down
19 changes: 0 additions & 19 deletions docs/mkdocs/detailed-command-usage/Clear-Cache.md

This file was deleted.

Loading
Loading