예제 #1
0
        private void InnerInstall(ManifestModuleInfo module, IProgress <ProgressMessage> progress)
        {
            var dstModuleDir  = Path.Combine(_options.DiscoveryPath, module.Id);
            var moduleZipPath = Path.Combine(dstModuleDir, GetModuleZipFileName(module.Id, module.Version.ToString()));

            _fileManager.CreateDirectory(dstModuleDir);

            //download  module archive from web
            if (Uri.IsWellFormedUriString(module.Ref, UriKind.Absolute))
            {
                var moduleUrl = new Uri(module.Ref);

                using (var fileStream = _fileSystem.File.OpenWrite(moduleZipPath))
                    using (var webStream = _externalClient.OpenRead(moduleUrl))
                    {
                        Report(progress, ProgressMessageLevel.Info, "Downloading '{0}' ", module.Ref);
                        webStream.CopyTo(fileStream);
                    }
            }
            else if (_fileSystem.File.Exists(module.Ref))
            {
                moduleZipPath = module.Ref;
            }

            _zipFileWrapper.Extract(moduleZipPath, dstModuleDir);

            Report(progress, ProgressMessageLevel.Info, "Successfully installed '{0}'.", module);
        }
예제 #2
0
        private void InnerInstall(ManifestModuleInfo module, IProgress <ProgressMessage> progress)
        {
            var dstModuleDir  = Path.Combine(_options.DiscoveryPath, module.Id);
            var moduleZipPath = Path.Combine(dstModuleDir, GetModuleZipFileName(module.Id, module.Version.ToString()));

            _fileManager.CreateDirectory(dstModuleDir);

            //download  module archive from web
            if (Uri.IsWellFormedUriString(module.Ref, UriKind.Absolute))
            {
                var moduleUrl = new Uri(module.Ref);

                using (var fileStream = File.OpenWrite(moduleZipPath))
                    using (var webStream = _externalClient.OpenRead(moduleUrl))
                    {
                        Report(progress, ProgressMessageLevel.Info, "Downloading '{0}' ", module.Ref);
                        webStream.CopyTo(fileStream);
                    }
            }
            else if (File.Exists(module.Ref))
            {
                moduleZipPath = module.Ref;
            }

            using (var zipStream = File.Open(moduleZipPath, FileMode.Open))
                using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Read))
                {
                    foreach (var entry in archive.Entries.Where(e => !string.IsNullOrEmpty(e.Name)))
                    {
                        //Report(progress, ProgressMessageLevel.Info, "Extracting '{0}' ", entry.FullName);
                        var filePath = Path.Combine(dstModuleDir, entry.FullName);
                        //Create directory if not exist
                        var directoryPath = Path.GetDirectoryName(filePath);
                        _fileManager.CreateDirectory(directoryPath);

                        using (var entryStream = entry.Open())
                            using (var fileStream = File.Create(filePath))
                            {
                                entryStream.CopyTo(fileStream);
                            }
                        File.SetLastWriteTime(filePath, entry.LastWriteTime.LocalDateTime);
                    }
                }

            Report(progress, ProgressMessageLevel.Info, "Successfully installed '{0}'.", module);
        }
예제 #3
0
        public void Extract(string zipFile, string destinationDir)
        {
            using (var archive = OpenRead(zipFile))
            {
                foreach (var entry in archive.Entries.Where(e => !string.IsNullOrEmpty(e.Name)))
                {
                    var filePath = Path.Combine(destinationDir, entry.FullName);
                    //Create directory if not exist
                    var directoryPath = Path.GetDirectoryName(filePath);
                    _fileManager.CreateDirectory(directoryPath);

                    using (var entryStream = entry.Open())
                        using (var fileStream = _fileSystem.File.Create(filePath))
                        {
                            entryStream.CopyTo(fileStream);
                        }
                    _fileSystem.File.SetLastWriteTime(filePath, entry.LastWriteTime.LocalDateTime);
                }
            }
        }