From 952cba862763847053ed06dff0935ff1e118b8df Mon Sep 17 00:00:00 2001 From: NicknineTheEagle Date: Sun, 1 Nov 2020 01:27:42 +0300 Subject: [PATCH] Implemented deleting files when updating (#113) Implemented deleting files when updating --- DepotDownloader/ContentDownloader.cs | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 66b829e0..49345ff8 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -599,6 +599,7 @@ namespace DepotDownloader { ulong TotalBytesCompressed = 0; ulong TotalBytesUncompressed = 0; + var previousFiles = new List(); foreach ( var depot in depots ) { @@ -1007,6 +1008,34 @@ 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 ); + if ( newManifestFile == null ) + continue; + + var previousFile = previousFiles.SingleOrDefault( f => f.FileName == file.FileName ); + if ( previousFile == null ) + continue; + + string fileFinalPath = Path.Combine( depot.installDir, file.FileName ); + if ( !File.Exists( fileFinalPath ) ) + continue; + + 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();