Пример #1
0
        public void ToStream_Should_Archive_Directories()
        {
            // Arrange
            var archiver = new ZipArchiver();
            var files    = new[]
            {
                new FileEntry {
                    Path = "d1/d2"
                },
            };

            // Act
            var buf = archiver.ToBytes(files);

            // Assert
            var zip = new ZipArchive(new MemoryStream(buf));

            using var entries = zip.Entries.GetEnumerator();
            entries.MoveNext().Should().BeTrue();
            var entry = entries.Current;

            Assert.NotNull(entry);
            entry.Name.Should().Be("d2");
            entry.FullName.Should().Be("d1/d2");
            using var reader = new StreamReader(entry.Open());
            reader.ReadToEnd().Should().BeEmpty();
            entries.MoveNext().Should().BeFalse();
        }
        public override bool SaveToBase()
        {
            this.ds.Tables.Remove(this.table_workdata);
            this.table_setting.Clear();
            DataRow[] dataRowArray = this.table_workdata.Select();
            int       count        = this.table_workdata.Columns.Count;

            for (int index1 = 0; index1 < dataRowArray.Length; ++index1)
            {
                for (int index2 = 1; index2 < count; ++index2)
                {
                    DataRow row = this.table_setting.NewRow();
                    this.table_setting.Rows.Add(row);
                    row["width"]  = (object)Useful.GetDouble((object)this.table_workdata.Columns[index2].ColumnName);
                    row["height"] = dataRowArray[index1][0];
                    row["value"]  = dataRowArray[index1][index2];
                }
            }
            MemoryStream memoryStream = new MemoryStream();

            this.ds.WriteXml((Stream)memoryStream, XmlWriteMode.WriteSchema);
            this.drSetting["blbvalue"] = (object)ZipArchiver.Zip(memoryStream.ToArray());
            this.ds.Tables.Add(this.table_workdata);
            this.table_workdata.AcceptChanges();
            this.ds.AcceptChanges();
            return(true);
        }
        public override void LoadFromBase()
        {
            try
            {
                if (this.drSetting["blbvalue"] != DBNull.Value)
                {
                    int num = (int)this.ds.ReadXml((Stream) new MemoryStream(ZipArchiver.UnZip((byte[])this.drSetting["blbvalue"])));
                }
            }
            catch
            {
            }
            this.gridControlTable.DataMember = "";
            this.gridControlTable.DataSource = (object)null;
            this.gridViewTable.Columns.Clear();
            if (this.table_workdata != null)
            {
                this.table_workdata.Clear();
                this.table_workdata.Columns.Clear();
            }
            else
            {
                this.table_workdata = new DataTable("workdata");
                this.ds.Tables.Add(this.table_workdata);
            }
            this.table_workdata.Columns.Add(new DataColumn("Высота\\Ширина"));
            double double1;

            for (DataRow[] dataRowArray = this.table_setting.Select("", "width"); dataRowArray.Length > 0; dataRowArray = this.table_setting.Select("width > " + double1.ToString().Replace(',', '.'), "width"))
            {
                double1 = Useful.GetDouble(dataRowArray[0]["width"]);
                this.table_workdata.Columns.Add(new DataColumn(double1.ToString(), typeof(double)));
            }
            double double2;

            for (DataRow[] dataRowArray = this.table_setting.Select("", "height,width"); dataRowArray.Length > 0; dataRowArray = this.table_setting.Select("height > " + double2.ToString().Replace(',', '.'), "height,width"))
            {
                double2 = Useful.GetDouble(dataRowArray[0]["height"]);
                DataRow row = this.table_workdata.NewRow();
                this.table_workdata.Rows.Add(row);
                row["Высота\\Ширина"] = (object)double2.ToString();
                foreach (DataRow dataRow in dataRowArray)
                {
                    if (Useful.GetDouble(dataRow["height"]) == double2)
                    {
                        row[dataRow["width"].ToString()] = dataRow["value"];
                    }
                    else
                    {
                        break;
                    }
                }
            }
            this.gridControlTable.DataSource = (object)this.ds;
            this.gridControlTable.DataMember = "workdata";
            this.SetParamFirstColumn();
            this.ds.AcceptChanges();
        }
 public CryptoArchiver(string fullFileName, IFileArchiver archiver = null)
 {
     if (archiver == null)
     {
         archiver = new ZipArchiver(fullFileName);
     }
     _archiver = archiver;
     _archiver.FullFileName = fullFileName;
 }
        public void Test()
        {
            ZipArchiver archiver = new ZipArchiver();

            var listFiles = GetPackageTestFilesList(TestFolder, Path.Combine(TestFolder, "archives", "test1.zip"));

            listFiles.AddRange(GetPackageTestFilesList(TestFolder, Path.Combine(TestFolder, "archives", "test2.zip")));

            WholeTest(archiver, listFiles);
        }
Пример #6
0
        public void GetPackaging_Should_Be_application_zip()
        {
            // Arrange
            var archiver = new ZipArchiver();

            // Act
            var packaging = archiver.GetPackaging();

            // Assert
            packaging.Should().Be("zip");
        }
Пример #7
0
        public void GetFileExtension_Should_Be_zip()
        {
            // Arrange
            var archiver = new ZipArchiver();

            // Act
            var ext = archiver.GetFileExtension();

            // Assert
            ext.Should().Be(".zip");
        }
Пример #8
0
        public void ToStream_Should_Create_Zip_Archive()
        {
            // Arrange
            var archiver = new ZipArchiver();
            var files    = new FileEntry[0];

            // Act
            var buf = archiver.ToBytes(files);

            // Assert
            new ZipArchive(new MemoryStream(buf)).Should().BeOfType <ZipArchive>();
        }
        public void ExtractTest()
        {
            Stream target = new FileStream(@"D:\Users\Eisuke\Desktop\分散処理しないdll.zip", FileMode.Open);

            string destinationFolder = @"D:\ZipTest";

            string password = string.Empty;

            ZipArchiver.Extract(target, destinationFolder, password);

            Assert.IsTrue(System.IO.File.Exists(@"D:\ZipTest\分散処理しない版\TtlSVC.Core.dll"));
        }
        private void ReadFile(string filename)
        {
            try
            {
                if (!VerifyImportArchive(filename))
                {
                    System.Windows.MessageBox.Show("Archive does not contain button data file " + StreamDeckConstants.BUTTON_EXPORT_FILENAME + ". Choose an other file.", "Invalid export file", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                /*
                 * Copy zip to temp folder and work on it there
                 */
                StreamDeckCommon.CleanDCSFPTemporaryFolder();
                var tempFolder = StreamDeckCommon.GetDCSFPTemporaryFolder();
                _extractedFilesFolder = tempFolder + "\\extracted_files";

                if (!Directory.Exists(_extractedFilesFolder))
                {
                    Directory.CreateDirectory(_extractedFilesFolder);
                }

                File.Copy(filename, tempFolder + "\\" + Path.GetFileName(filename));
                filename = tempFolder + "\\" + Path.GetFileName(filename);

                /*
                 * Extract files to folder extracted_files
                 */
                ZipArchiver.ExtractZipFile(filename, _extractedFilesFolder);

                Clear();

                var fileContents = File.ReadAllText(_extractedFilesFolder + "\\" + StreamDeckConstants.BUTTON_EXPORT_FILENAME);

                TranslateJSON(fileContents);

                ShowButtons();
            }
            finally
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
            }
        }
Пример #11
0
        private void CreateZipArchive(CommandPipelineContext context)
        {
            var archiver = new ZipArchiver();

            if (!context.Options.PackageFileName.EndsWith(".zip"))
            {
                context.Options.PackageFileName = string.Format("{0}.zip", context.Options.PackageFileName);
            }

            var zip = Path.Combine(context.Options.PackageDirectory, context.Options.PackageFileName);

            Logger.InfoFormat("Creating package '{0}' as zip archive for path '{1}'...",
                              Path.GetFileName(zip),
                              context.Options.ScriptsPath);

            // create a working directory as a copy of the scripts path
            // due to zip archiver not being able to access directory
            // while it is zipping the contents:
            var workingDirectory = string.Format(@"{0}-working-{1}",
                                                 context.Options.ScriptsPath, Guid.NewGuid().ToString("N"));

            _fileSystem.CopyFolderContents(context.Options.ScriptsPath, workingDirectory, true);

            var files = new HashSet <string>();

            _fileSystem.GetFilesInPath(files, workingDirectory);

            var zipItems = files
                           .Where(file => Path.GetExtension(file) == ".sql")
                           .Select(file => new ZipItem(file, Path.GetDirectoryName(file)))
                           .ToList();

            archiver.Zip(zip, zipItems);

            _fileSystem.DeleteFolder(workingDirectory);

            Logger.InfoFormat("Package '{0}' created for path '{1}'.",
                              Path.GetFileName(zip),
                              context.Options.ScriptsPath);
        }
Пример #12
0
        private void CreateZipArchiveForDelta(CommandPipelineContext context)
        {
            var archiver = new ZipArchiver();
            var delta    = context.Deltas.First();

            var commits = delta.CommitScripts
                          .Select(script => new ZipItem(script.GetFullPath(),
                                                        Path.GetDirectoryName(script.GetFullPath())))
                          .ToList();

            var rollbacks = delta.RollbackScripts
                            .Select(script => new ZipItem(script.GetFullPath(),
                                                          Path.GetDirectoryName(script.GetFullPath())))
                            .ToList();

            var zipitems = new List <ZipItem>(commits);

            zipitems.AddRange(rollbacks);

            if (!context.Options.PackageName.EndsWith(".zip"))
            {
                context.Options.PackageName = string.Format("{0}.zip", context.Options.PackageName);
            }

            var zip = Path.Combine(Environment.CurrentDirectory, context.Options.PackageName);

            Logger.InfoFormat("Creating package '{0}' as zip archive at '{1}'...",
                              Path.GetFileName(zip),
                              Path.GetDirectoryName(zip));

            archiver.Zip(zip, zipitems);

            Logger.InfoFormat("Package '{0}'  created at '{1}'.",
                              Path.GetFileName(zip),
                              Path.GetDirectoryName(zip));
        }
Пример #13
0
        private void ExpandPackageIntoPackageFolderInDeploymentsDirectory(
            CommandPipelineContext context,
            string packageDeployDirectory)
        {
            var zipArchiver = new ZipArchiver();
            var zipFile     = GetZipFileLocation(context);

            Logger.InfoFormat("Unpacking '{0}' into directory '{1}'...",
                              GetZipFileName(context), packageDeployDirectory);

            zipArchiver.Unzip(zipFile, packageDeployDirectory);

            // gather all of the directories in the archive
            // path and look for a folder that matches the
            // standard folder name, when we have this
            // we can move those contents under the root
            // deploy path:
            var foldersInDeployDirectory = new HashSet <string>();

            _fileSystem.GetFoldersInPath(foldersInDeployDirectory, packageDeployDirectory);

            // the first file in the zip archive should be the root of the scripts
            // directory as defined by the caller, move all of the content under
            // this root folder to the root of the folder named after the package (i.e. *.zip file)
            // for the current deployment:
            var zipFileRootFolder = foldersInDeployDirectory.FirstOrDefault();

            _fileSystem.CopyFolderContents(zipFileRootFolder, packageDeployDirectory, true);

            //var installPath =
            //    foldersInDeployDirectory
            //        .Where(folder => FolderStructure.Folders.Values.Any(v => folder.Contains(v)))
            //        .Select(folder => ScrubInstallDirectoryFromFolderStructureNames(folder))
            //        .FirstOrDefault();

            // move the archive to the root of the deploy folder:
            _fileSystem.CopyFile(zipFile,
                                 Path.Combine(packageDeployDirectory, Path.GetFileName(zipFile)));

            // remove the extracted root folder of the *.zip file while
            // after moving its underlying content to the root of the
            // folder with the package name (it will have a "temp" prefix
            // attached to the specified directory where the scripts are located):
            var tempDirectoryCreatedOnExtraction = Directory
                                                   .EnumerateDirectories(packageDeployDirectory)
                                                   .FirstOrDefault(d => d.EndsWith("temp"));

            if (!string.IsNullOrEmpty(tempDirectoryCreatedOnExtraction))
            {
                _fileSystem.DeleteFolder(tempDirectoryCreatedOnExtraction);
            }

            //var foldersToClean = foldersInDeployDirectory
            //    .Select(directory => Path.GetDirectoryName(directory))
            //    .Where(directory => !FolderStructure.Folders.Values.Contains(directory))
            //    .Select(directory => Path.Combine(packageDeployDirectory, directory))
            //    .Distinct()
            //    .ToList();

            //foreach (var folder in foldersToClean)
            //{
            //    try
            //    {
            //        _fileSystem.DeleteFolder(folder);
            //    }
            //    catch
            //    {
            //    }
            //}

            Logger.InfoFormat("'{0}' unpacked into directory '{1}'",
                              GetZipFileName(context), packageDeployDirectory);

            Logger.InfoFormat("Redirecting scripts path to deployed package directory '{0}'...", packageDeployDirectory);
            context.Options.ScriptsPath = packageDeployDirectory;
        }
 private bool VerifyImportArchive(string filename)
 {
     return(ZipArchiver.ZipFileContainsFile(filename, StreamDeckConstants.BUTTON_EXPORT_FILENAME));
 }