Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private void RemoveFile(string fileName, CancellationToken cancellationToken)
        {
            _logger.LogDebug(string.Format("Processing remove file entry {0}", fileName));

            string filePath = _localData.Path.PathCombine(fileName);

            _logger.LogTrace("filePath = " + filePath);

            _logger.LogDebug("Deleting file in local data. Checking whether it actually exists...");
            if (File.Exists(filePath))
            {
                _logger.LogDebug("File exists. Deleting it...");
                FileOperations.Delete(filePath, cancellationToken);
                _logger.LogDebug("File deleted.");
            }
            else
            {
                _logger.LogDebug("File already doesn't exist.");
            }

            _localMetaData.UnregisterEntry(fileName);

            _logger.LogDebug("Remove file entry processed.");
        }
        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);
             * }*/
        }