Skip to content

Commit

Permalink
Print update cleanup just once
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Apr 4, 2024
1 parent 64c2265 commit 3a141cd
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions ArchiSteamFarm/Core/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,38 +329,50 @@ internal static (bool IsWeak, string? Reason) TestPasswordStrength(string passwo
internal static async Task<bool> UpdateCleanup(string targetDirectory) {
ArgumentException.ThrowIfNullOrEmpty(targetDirectory);

bool updateCleanup = false;

try {
foreach (string directory in Directory.EnumerateDirectories(targetDirectory, $"{SharedInfo.UpdateDirectoryNewPrefix}*")) {
ASF.ArchiLogger.LogGenericInfo(Strings.UpdateCleanup);
if (!updateCleanup) {
updateCleanup = true;

Directory.Delete(directory, true);
ASF.ArchiLogger.LogGenericInfo(Strings.UpdateCleanup);
}

ASF.ArchiLogger.LogGenericInfo(Strings.Done);
Directory.Delete(directory, true);
}

foreach (string directory in Directory.EnumerateDirectories(targetDirectory, $"{SharedInfo.UpdateDirectoryOldPrefix}*")) {
ASF.ArchiLogger.LogGenericInfo(Strings.UpdateCleanup);
if (!updateCleanup) {
updateCleanup = true;

await DeletePotentiallyUsedDirectory(directory).ConfigureAwait(false);
ASF.ArchiLogger.LogGenericInfo(Strings.UpdateCleanup);
}

ASF.ArchiLogger.LogGenericInfo(Strings.Done);
await DeletePotentiallyUsedDirectory(directory).ConfigureAwait(false);
}

string oldBackupDirectory = Path.Combine(targetDirectory, SharedInfo.UpdateDirectoryOld);

if (Directory.Exists(oldBackupDirectory)) {
ASF.ArchiLogger.LogGenericInfo(Strings.UpdateCleanup);
if (!updateCleanup) {
updateCleanup = true;

await DeletePotentiallyUsedDirectory(oldBackupDirectory).ConfigureAwait(false);
ASF.ArchiLogger.LogGenericInfo(Strings.UpdateCleanup);
}

ASF.ArchiLogger.LogGenericInfo(Strings.Done);
await DeletePotentiallyUsedDirectory(oldBackupDirectory).ConfigureAwait(false);
}
} catch (Exception e) {

Check notice on line 366 in ArchiSteamFarm/Core/Utilities.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Do not catch general exception types

Modify 'UpdateCleanup' to catch a more specific allowed exception type, or rethrow the exception
ASF.ArchiLogger.LogGenericException(e);

return false;
}

if (updateCleanup) {
ASF.ArchiLogger.LogGenericInfo(Strings.Done);
}

return true;
}

Expand Down

0 comments on commit 3a141cd

Please sign in to comment.