From 1afec7199e8fca586179d1585d213cf7533ad338 Mon Sep 17 00:00:00 2001 From: NicknineTheEagle Date: Fri, 19 Jun 2020 21:40:55 +0300 Subject: [PATCH] Implemented deleting files when updating --- DepotDownloader/ContentDownloader.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 7f1dc839..5d4217f4 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -596,6 +596,7 @@ namespace DepotDownloader { ulong TotalBytesCompressed = 0; ulong TotalBytesUncompressed = 0; + var previousFiles = new List(); foreach ( var depot in depots ) { @@ -1004,6 +1005,28 @@ namespace DepotDownloader await Task.WhenAll( tasks ).ConfigureAwait( false ); + // Check for deleted files if updating the depot. + if ( oldProtoManifest != null ) + { + var oldfilesAfterExclusions = oldProtoManifest.Files.AsParallel().Where( f => TestIsFileIncluded( f.FileName ) ).ToList(); + + foreach ( var file in oldfilesAfterExclusions ) + { + // Delete it if it's in the old manifest AND not in the new manifest AND not in any of the previous depots. + var newManifestFile = filesAfterExclusions.SingleOrDefault( f => f.FileName == file.FileName ); + var previousFile = previousFiles.SingleOrDefault( f => f.FileName == file.FileName ); + if ( newManifestFile == null && previousFile == null ) + { + string fileFinalPath = Path.Combine( depot.installDir, file.FileName ); + File.Delete( fileFinalPath ); + Console.WriteLine( "Deleted {0}", fileFinalPath ); + } + } + } + + // Remember files we processed for later. + previousFiles.AddRange( filesAfterExclusions ); + DepotConfigStore.Instance.InstalledManifestIDs[ depot.id ] = depot.manifestId; DepotConfigStore.Save();