コード例 #1
0
        public DistributionResultCode PreparePackage(DistributionPackage package, DirectoryInfo targetDirectory)
        {
            if (package.PackageSize > targetDirectory.GetAvailableFreeSpace())
            {
                _logger.LogWarning($"Not enough space for update package in target path: {targetDirectory.FullName}");
                return(DistributionResultCode.NotEnoughSpace);
            }

            if (targetDirectory.Exists)
            {
                _logger.LogDebug("Cleaning target directory");
                targetDirectory.Delete(true);
            }

            targetDirectory.Create();

            var  totalFilesCount  = package.DistributionFiles.Count();
            long failedFilesCount = 0;
            long progress         = 0;

            Parallel.ForEach(package.DistributionFiles, PrepareDistributionFiles);

            if (failedFilesCount > 0)
            {
                return(DistributionResultCode.HasFailedFiles);
            }

            package.SaveToFile(targetDirectory.FullName);

            return(DistributionResultCode.Finished);

            // local method
            void PrepareDistributionFiles(DistributionFile distFile)
            {
                var ok = false;

                for (var i = 0; i < DEFAULT_RETRY_COUNT; i++)
                {
                    ok = PrepareFile(distFile, targetDirectory);
                    if (ok)
                    {
                        break;
                    }
                }

                if (!ok)
                {
                    Interlocked.Increment(ref failedFilesCount);
                }

                Interlocked.Increment(ref progress);
                ProgressChanged?.Invoke(Interlocked.Read(ref progress), totalFilesCount);
            }
        }
コード例 #2
0
        public void Start()
        {
            var store        = runtimeConfig.ArtifactStore;
            var distribution = config.Distribution;

            DistributionPackage = store.GetDistributionPackage(distribution);
            if (DistributionPackage?.BinTools != null)
            {
                ExecuteCommands();
            }
        }
コード例 #3
0
ファイル: Package.cs プロジェクト: amelkor/IcyLight
        public DistributionPackage Build()
        {
            var packageinfo = new DistributionPackage
            {
                ApplicationId      = _options.ApplicationId,
                ApplicationVersion = _options.Version,
                OnePiece           = _options.CompressSingleZip
            };
            var files = Directory.EnumerateFiles(_inputPath.FullName, _options.FilesPattern, SearchOption.AllDirectories).ToList();

            if (!files.Any())
            {
                _log.Error("Source directory contains no files");
                Environment.Exit(Codes.ERROR_SRC_DIR_NO_FILES);
            }

            Directory.CreateDirectory(_options.TargetPath);

            Parallel.ForEach(files, filePath =>
            {
                var distFile = ProcessFile(new FileInfo(filePath));
                Debug.Assert(distFile != null);
                lock (packageinfo)
                {
                    packageinfo.DistributionFiles.Add(distFile);
                    packageinfo.PackageSize += _options.CompressSingleZip ? distFile.Size : distFile.CompressedSize;
                }
            });

            if (_options.CompressSingleZip)
            {
                var(size, hash, name)            = CompressOnePieceFile(_inputPath);
                packageinfo.OnePieceArchieveName = name;
                packageinfo.OnePiece             = true;
                packageinfo.OnePieceArchieveSize = size;
                packageinfo.OnePieceArchieveHash = hash;
            }

            return(packageinfo);
        }
コード例 #4
0
        public DistributionResultCode InstallPackage(DirectoryInfo packageDirectory, DirectoryInfo targetDirectory)
        {
            var package = DistributionPackage.FindInDirectory(packageDirectory);

            if (package == null)
            {
                _logger.LogError($"Package directory {packageDirectory.Name} contains no package info file");
                return(DistributionResultCode.PackageInfoNotFound);
            }

            var  totalFilesCount  = package.DistributionFiles.Count();
            long failedFilesCount = 0;
            long progress         = 0;

            Parallel.ForEach(package.DistributionFiles, ProcessDistributionFile);

            if (failedFilesCount > 0)
            {
                return(DistributionResultCode.HasFailedFiles);
            }

            return(DistributionResultCode.Finished);

            // local method
            void ProcessDistributionFile(DistributionFile distFile)
            {
                Interlocked.Increment(ref progress);
                ProgressChanged?.Invoke(Interlocked.Read(ref progress), totalFilesCount);

                var target = new FileInfo(Path.Combine(targetDirectory.FullName, distFile.InternalPath, distFile.Name));

                if (distFile.Action == FileProcessingAction.Delete)
                {
                    _logger.LogTrace($"Deleting file: {distFile.InternalPath}\\{target.Name}");
                    target.DeleteIfExists();
                    return;
                }

                var temp = new FileInfo(Path.Combine(packageDirectory.FullName, distFile.InternalPath, distFile.Name));

                switch (distFile.Action)
                {
                case FileProcessingAction.Install:
                    _logger.LogTrace($"Installing file: {distFile.InternalPath}\\{target.Name}");
                    target.DeleteIfExists();
                    File.Move(temp.FullName, target.FullName);
                    return;

                case FileProcessingAction.Patch:
                {
                    _logger.LogTrace($"Patching file: {distFile.InternalPath}\\{target.Name}");

                    if (!_patcher.TryApplyPatch(distFile, target, temp))
                    {
                        Interlocked.Increment(ref failedFilesCount);
                        _logger.LogError($"Can not patch file: {distFile.InternalPath}\\{target.Name}");
                    }
                    return;
                }
                }
            }
        }