private void ProcessRemovedFiles(CancellationToken cancellationToken) { DebugLogger.Log("Processing removed files."); var files = _versionDiffSummary.RemovedFiles.Where(s => !s.EndsWith("/")); var directories = _versionDiffSummary.RemovedFiles.Where(s => s.EndsWith("/")); int counter = 0; _removeFilesStatusReporter.OnProgressChanged(0.0, "Installing package..."); foreach (var fileName in files) { cancellationToken.ThrowIfCancellationRequested(); string filePath = _localData.Path.PathCombine(fileName); if (File.Exists(filePath)) { FileOperations.Delete(filePath); } _localMetaData.UnregisterEntry(fileName); counter++; _removeFilesStatusReporter.OnProgressChanged(counter / (double)_versionDiffSummary.RemovedFiles.Length, "Installing package..."); } foreach (var dirName in directories) { cancellationToken.ThrowIfCancellationRequested(); string dirPath = _localData.Path.PathCombine(dirName); if (Directory.Exists(dirPath) && DirectoryOperations.IsDirectoryEmpty(dirPath)) { DirectoryOperations.Delete(dirPath, false); } // TODO: Uncomment this after fixing directory registration in install content command //_localMetaData.UnregisterEntry(dirName); counter++; _removeFilesStatusReporter.OnProgressChanged(counter / (double)_versionDiffSummary.RemovedFiles.Length, "Installing package..."); } _removeFilesStatusReporter.OnProgressChanged(1.0, string.Empty); }
public override void Execute(CancellationToken cancellationToken) { base.Execute(cancellationToken); DebugLogger.Log("Uninstalling."); var entries = _localMetaData.GetRegisteredEntries(); var files = entries.Where(s => !s.EndsWith("/")).ToArray(); // TODO: Uncomment this after fixing directory registration in install content command //var directories = entries.Where(s => s.EndsWith("/")); int counter = 0; foreach (var fileName in files) { cancellationToken.ThrowIfCancellationRequested(); var filePath = _localData.Path.PathCombine(fileName); if (File.Exists(filePath)) { FileOperations.Delete(filePath); } _localMetaData.UnregisterEntry(fileName); counter++; _statusReporter.OnProgressChanged(counter / (double)entries.Length); } // TODO: Delete this after fixing directory registration in install content command // Temporary solution for deleting directories during uninstallation. foreach (var fileName in files) { cancellationToken.ThrowIfCancellationRequested(); string parentDirName = fileName; do { parentDirName = Path.GetDirectoryName(parentDirName); var parentDirPath = _localData.Path.PathCombine(parentDirName); if (Directory.Exists(parentDirPath)) { if (DirectoryOperations.IsDirectoryEmpty(parentDirPath)) { DirectoryOperations.Delete(parentDirPath, false); } else { break; } } } while (parentDirName != null); } // TODO: Uncomment this after fixing directory registration in install content command /* * foreach (var dirName in directories) * { * cancellationToken.ThrowIfCancellationRequested(); * * var dirPath = _localData.Path.PathCombine(dirName); * * if (Directory.Exists(dirPath) && DirectoryOperations.IsDirectoryEmpty(dirPath)) * { * DirectoryOperations.Delete(dirPath, false); * } * * _localMetaData.UnregisterEntry(dirName); * * counter++; * _statusReporter.OnProgressChanged(counter / (double)entries.Length); * }*/ }