Beispiel #1
0
        private void ProcessModifiedFiles(string packageDirPath,
                                          CancellationToken cancellationToken)
        {
            DebugLogger.Log("Processing modified files.");

            for (int i = 0; i < _versionDiffSummary.ModifiedFiles.Length; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var entryName = _versionDiffSummary.ModifiedFiles[i];

                if (!entryName.EndsWith("/"))
                {
                    PatchFile(entryName, packageDirPath);

                    _localMetaData.RegisterEntry(entryName, _versionId);
                }
                else
                {
                    // TODO: Uncomment this after fixing directory registration in install content command
                    //_localMetaData.RegisterEntry(entryName, _versionId);
                }

                _modifiedFilesStatusReporter.OnProgressChanged((i + 1) / (double)_versionDiffSummary.ModifiedFiles.Length);
            }

            _modifiedFilesStatusReporter.OnProgressChanged(1.0);
        }
        public override void Execute(CancellationToken cancellationToken)
        {
            base.Execute(cancellationToken);

            Checks.FileExists(_packagePath);

            if (_versionDiffSummary.CompressionMethod == "pack1")
            {
                Assert.IsTrue(File.Exists(_packageMetaPath),
                              "Compression method is pack1, but meta file does not exist");

                DebugLogger.Log("Parsing package meta file");
                _pack1Meta = Pack1Meta.ParseFromFile(_packageMetaPath);
                DebugLogger.Log("Package meta file parsed succesfully");
            }

            DebugLogger.Log("Installing diff.");

            var packageDirPath = _temporaryData.GetUniquePath();

            DebugLogger.LogVariable(packageDirPath, "packageDirPath");

            DebugLogger.Log("Creating package directory.");
            DirectoryOperations.CreateDirectory(packageDirPath);
            try
            {
                DebugLogger.Log("Unarchiving files.");
                string      usedSuffix;
                IUnarchiver unarchiver = CreateUnrachiver(packageDirPath, out usedSuffix);

                _unarchivePackageStatusReporter.OnProgressChanged(0.0, "Unarchiving package...");

                unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) =>
                {
                    var entryMinProgress = Mathf.Max(0, entry - 1) / (double)amount;  // entry could be zero
                    var entryMaxProgress = entry / (double)amount;

                    var progress = entryMinProgress + (entryMaxProgress - entryMinProgress) * entryProgress;

                    _unarchivePackageStatusReporter.OnProgressChanged(progress, "Unarchiving package...");
                };

                unarchiver.Unarchive(cancellationToken);

                _unarchivePackageStatusReporter.OnProgressChanged(1.0, string.Empty);

                ProcessAddedFiles(packageDirPath, usedSuffix, cancellationToken);
                ProcessRemovedFiles(cancellationToken);
                ProcessModifiedFiles(packageDirPath, usedSuffix, cancellationToken);
                DeleteEmptyMacAppDirectories();
            }
            finally
            {
                DebugLogger.Log("Deleting package directory.");
                if (Directory.Exists(packageDirPath))
                {
                    DirectoryOperations.Delete(packageDirPath, true);
                }
            }
        }
Beispiel #3
0
        public override void Execute(CancellationToken cancellationToken)
        {
            base.Execute(cancellationToken);

            Checks.FileExists(_packagePath);

            if (_versionDiffSummary.CompressionMethod == "pack1")
            {
                Assert.IsTrue(File.Exists(_packageMetaPath),
                              "Compression method is pack1, but meta file does not exist");

                DebugLogger.Log("Parsing package meta file");
                _pack1Meta = Pack1Meta.ParseFromFile(_packageMetaPath);
                DebugLogger.Log("Package meta file parsed succesfully");
            }

            DebugLogger.Log("Installing diff.");

            var packageDirPath = _temporaryData.GetUniquePath();

            DebugLogger.LogVariable(packageDirPath, "packageDirPath");

            DebugLogger.Log("Creating package directory.");
            DirectoryOperations.CreateDirectory(packageDirPath);
            try
            {
                DebugLogger.Log("Unarchiving files.");
                IUnarchiver unarchiver = CreateUnrachiver(packageDirPath);

                unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount) =>
                {
                    _unarchivePackageStatusReporter.OnProgressChanged(entry / (double)amount);
                };

                unarchiver.Unarchive(cancellationToken);

                _unarchivePackageStatusReporter.OnProgressChanged(1.0);

                ProcessAddedFiles(packageDirPath, cancellationToken);
                ProcessRemovedFiles(cancellationToken);
                ProcessModifiedFiles(packageDirPath, cancellationToken);
            }
            finally
            {
                DebugLogger.Log("Deleting package directory.");
                if (Directory.Exists(packageDirPath))
                {
                    DirectoryOperations.Delete(packageDirPath, true);
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        private void ProcessAddedFiles(string packageDirPath, string suffix,
                                       CancellationToken cancellationToken)
        {
            DebugLogger.Log("Processing added files.");

            _addFilesStatusReporter.OnProgressChanged(0.0, "Installing package...");

            for (int i = 0; i < _versionDiffSummary.AddedFiles.Length; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var entryName = _versionDiffSummary.AddedFiles[i];

                string entryPath = _localData.Path.PathCombine(entryName);

                if (entryName.EndsWith("/"))
                {
                    DirectoryOperations.CreateDirectory(entryPath);

                    // TODO: Uncomment this after fixing directory registration in install content command
                    //_localMetaData.RegisterEntry(entryName, _versionId);
                }
                else
                {
                    string sourceFilePath = Path.Combine(packageDirPath, entryName + suffix);

                    if (!File.Exists(sourceFilePath))
                    {
                        throw new InstallerException(string.Format("Cannot find file <{0}> in content package.", entryName));
                    }

                    DebugLogger.LogFormat("Copying {0} -> {1}", sourceFilePath, entryName);
                    DirectoryOperations.CreateParentDirectory(entryPath);
                    FileOperations.Copy(sourceFilePath, entryPath, true);

                    _localMetaData.RegisterEntry(entryName, _versionId);
                }

                _addFilesStatusReporter.OnProgressChanged((i + 1) / (double)_versionDiffSummary.AddedFiles.Length, "Installing package...");
            }

            _addFilesStatusReporter.OnProgressChanged(1.0, "Installing package...");
        }
        public override void Execute(CancellationToken cancellationToken)
        {
            base.Execute(cancellationToken);

            DebugLogger.Log("Checking version integrity.");

            var files = new FileIntegrity[_versionSummary.Files.Length];

            for (int i = 0; i < _versionSummary.Files.Length; i++)
            {
                files[i] = CheckFile(_versionSummary.Files[i]);

                _statusReporter.OnProgressChanged((i + 1) / (double)_versionSummary.Files.Length);
            }

            Results = new VersionIntegrity(files);
        }
        public override void Execute(CancellationToken cancellationToken)
        {
            base.Execute(cancellationToken);

            Checks.FileExists(_packagePath);
            Assert.IsTrue(_localMetaData.GetRegisteredEntries().Length == 0,
                          "Cannot install content if previous version is still present.");

            if (_versionContentSummary.CompressionMethod == "pack1")
            {
                Assert.IsTrue(File.Exists(_packageMetaPath),
                              "Compression method is pack1, but meta file does not exist");

                DebugLogger.Log("Parsing package meta file");
                _pack1Meta = Pack1Meta.ParseFromFile(_packageMetaPath);
                DebugLogger.Log("Package meta file parsed succesfully");
            }

            DebugLogger.Log("Installing content.");

            var packageDirPath = _temporaryData.GetUniquePath();

            DebugLogger.LogVariable(packageDirPath, "destinationDir");

            DebugLogger.Log("Creating package directory.");
            DirectoryOperations.CreateDirectory(packageDirPath);
            try
            {
                DebugLogger.Log("Unarchiving package.");

                IUnarchiver unarchiver = CreateUnrachiver(packageDirPath);

                unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount) =>
                {
                    _unarchivePackageStatusReporter.OnProgressChanged(entry / (double)amount);
                };

                unarchiver.Unarchive(cancellationToken);

                _unarchivePackageStatusReporter.OnProgressChanged(1.0);

                DebugLogger.Log("Copying files.");

                for (int i = 0; i < _versionContentSummary.Files.Length; i++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    InstallFile(_versionContentSummary.Files[i].Path, packageDirPath);

                    _copyFilesStatusReporter.OnProgressChanged((i + 1) / (double)_versionContentSummary.Files.Length);
                }

                _copyFilesStatusReporter.OnProgressChanged(1.0);
            }
            finally
            {
                DebugLogger.Log("Deleting package directory.");
                if (Directory.Exists(packageDirPath))
                {
                    DirectoryOperations.Delete(packageDirPath, true);
                }
            }
        }
        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);
             * }*/
        }