Пример #1
0
        public void TestTextEncryption2()
        {
            var testEncryptions = EncryptionTest.TestEncryptions();


            foreach (var testEncryption in testEncryptions)
            {
                Console.WriteLine("Using crypto: {0}", testEncryption);
                var str = "long";
                var ms  = new MemoryStream();
                var aw  = new ArchiveWriter(ms);
                aw.Encryption = testEncryption;
                aw.Write(str, 0x1B, 0x73);

                var tmp = ms.ToArray();
                debugArray(tmp);

                tmp = aw.EncodeString(str, out _);
                debugArray(tmp);

                ms.Position = 0;

                var ar = new ArchiveReader(ms);
                ar.SetEncryption(testEncryption);

                Assert.AreEqual(str, ar.ReadString(0x1B, 0x73));
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            if (args == null || args.Length != 2)
            {
                Console.WriteLine("Usage: <source folder> <destinaion file>");
            }

            var source = new DirectoryInfo(args[0]);

            if (!source.Exists)
            {
                throw new ApplicationException("Source folder does not exist");
            }


            var destination = new FileInfo(args[1]);

            if (destination.Exists)
            {
                throw new ApplicationException("Destination already exists");
            }

            // mem-stream needs to be here for this to work?
            using (var destinationStream = destination.OpenWrite())
                using (var memStream = new MemoryStream())
                    using (var lz4Stream = new LZ4Stream(destinationStream, CompressionMode.Compress, true, true))
                    {
                        using (var archiveWriter = new ArchiveWriter(memStream, true))
                            archiveWriter.AddFiles(source);

                        memStream.Position = 0;
                        memStream.CopyTo(lz4Stream);
                    }
        }
        /* ----------------------------------------------------------------- */
        ///
        /// Archive
        ///
        /// <summary>
        /// 圧縮処理を実行します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Archive()
        {
            var fmt   = GetFormat();
            var dest  = GetTmp();
            var query = RtSettings.Password.HasValue() || Request.Password ?
                        new Query <string>(e => RaisePasswordRequested(e)) :
                        null;

            System.Diagnostics.Debug.Assert(RtSettings != null);
            this.LogDebug(string.Format("Format:{0}\tMethod:{1}", fmt, RtSettings.CompressionMethod));

            using (var writer = new ArchiveWriter(fmt, IO))
            {
                writer.Option = RtSettings.ToOption(Settings);
                if (Settings.Value.Archive.Filtering)
                {
                    writer.Filters = Settings.Value.GetFilters();
                }
                foreach (var item in Request.Sources)
                {
                    writer.Add(item);
                }
                ProgressStart();
                writer.Save(dest, query, CreateInnerProgress(x => Report = x));
            }

            // Move
            if (!IO.Exists(Tmp))
            {
                return;
            }
            IO.Move(Tmp, Destination, true);
        }
Пример #4
0
 private void ZipToOutputFile(string folderToZip)
 {
     using (ArchiveWriter zip = ArchiveFactory.Writer(ArchiveFactory.Type.Zip, File.OpenWrite(_destFile)))
     {
         zip.CreateArchive(folderToZip);
     }
 }
Пример #5
0
    public void Save(string basePath, string currentSaveDir)
    {
        if (GameState == null)
        {
            throw new CorruptSaveException("Missing GameState.");
        }

        if (UiState == null)
        {
            throw new CorruptSaveException("Missing UiState.");
        }

        var serializedGameState = SavedGameState.Save(GameState, Co8State != null);

        var serializedUiState = SavedUiState.Save(UiState, Co8State != null);

        // Write the files to the current save directory so they are added to the save archive afterwards
        WriteStateToDirectory(serializedGameState, serializedUiState, currentSaveDir);

        try
        {
            ArchiveWriter.Compress(basePath + ".tfai", basePath + ".tfaf", currentSaveDir);
        }
        finally
        {
            DeleteStateFromDirectory(currentSaveDir);
        }
    }
        public void Can_read_write_nested_named_stream()
        {
            ////Arrange
            using (var stream = new MemoryStream())
            {
                using (var archiveWriter = new ArchiveWriter(stream, true))
                    archiveWriter
                    .AddStream("test.txt", new MemoryStream(Encoding.UTF8.GetBytes("hello world")))
                    .AddStream("this/is/nested/test.txt", new MemoryStream(Encoding.UTF8.GetBytes("hello world")));

                stream.Position = 0;

                using (var archiveReader = new ArchiveReader(stream))
                    using (var destinationStream = new MemoryStream())
                    {
                        // move to second file
                        archiveReader.ReadFileName();
                        archiveReader.ExtractToStream(Stream.Null);

                        ////Act
                        var file = archiveReader.ReadFileName();
                        archiveReader.ExtractToStream(destinationStream);


                        ////Assert
                        Assert.That(file, Is.EqualTo("this/is/nested/test.txt"));
                        Assert.That(Encoding.UTF8.GetString(destinationStream.ToArray()), Is.EqualTo("hello world"));
                    }
            }
        }
Пример #7
0
        public void Archive_Skip()
        {
            var dir    = GetResultsWith("Ignore");
            var ignore = IO.Combine(dir, "Sample.txt");

            var io = new IO();

            io.Failed += (s, e) => e.Cancel = true;
            io.Copy(GetExamplesWith("Sample.txt"), ignore);

            var dest = io.Combine(dir, "Sample.zip");

            using (var _ = OpenExclude(ignore))
                using (var writer = new ArchiveWriter(Format.Zip, io))
                {
                    writer.Add(ignore);
                    writer.Add(GetExamplesWith("Sample 00..01"));
                    writer.Save(dest);
                }

            using (var reader = new ArchiveReader(dest))
            {
                Assert.That(reader.Items.Count, Is.EqualTo(8));
                Assert.That(reader.Items.Any(x => x.FullName == "Sample.txt"), Is.False);
            }
        }
Пример #8
0
 public void Add_NotFound() => Assert.That(() =>
 {
     using (var writer = new ArchiveWriter(Format.Zip))
     {
         writer.Add(GetExamplesWith("NotFound.txt"));
     }
 }, Throws.TypeOf <System.IO.FileNotFoundException>());
Пример #9
0
        public static void SaveAs(bool worksheet, EditableView pnlView)
        {
            var strFilename = FileDialog.ShowSave(FileDialog.Context.Document, "SAW 7|*" + Document.StandardExtension + "|SAW 6|*.sss", Path.GetFileName(CurrentDocument.FilenameWithExtension(Document.StandardExtension)));

            if (string.IsNullOrEmpty(strFilename))
            {
                return;
            }
            CurrentDocument.SAWHeader.SetWindowBounds(pnlView.GetDocumentScreenCoords());
            if (strFilename.ToLower().EndsWith(".sss"))
            {
                using (var op = new Globals.Operation("[Save_SAW6]"))
                {
                    var oldDoc = new SAW6Doc(CurrentDocument);

                    using (var writer = new ArchiveWriter(strFilename, oldDoc.m_Header.Version))
                    {
                        oldDoc.Write(writer);
                    }
                    op.ConfirmSuccess(true);
                }
            }
            else
            {
                if (!CurrentDocument.IsPaletteWithin)
                {
                    CurrentDocument.Filename = strFilename;
                }
                CurrentDocument.DisplayName = "";                 // otherwise the original worksheet name remains in the title bar, rather than the filename
                SaveFile(pnlView);
            }
        }
Пример #10
0
        public void TestTextEncryption()
        {
            var testEncryptions = EncryptionTest.TestEncryptions();


            foreach (var testEncryption in testEncryptions)
            {
                var ms = new MemoryStream();
                var aw = new ArchiveWriter(ms);
                aw.Encryption = testEncryption;
                aw.Write("long", 0x1B, 0x73);

                Console.Write("> ");
                var tmp = ms.ToArray();
                foreach (var b in tmp)
                {
                    Console.Write(b.ToString("X2"));
                }

                Console.WriteLine();

                ms.Position = 0;

                var ar = new ArchiveReader(ms);
                ar.SetEncryption(aw.Encryption);

                Assert.AreEqual("long", ar.ReadString(0x1B, 0x73));
            }
        }
Пример #11
0
        public void ShouldBuildArchiveFromExistingFile()
        {
            var fieldMetaDataBuilder = FieldsMetaDataBuilder.Fields()
                                       .AutomaticallyIndex()
                                       .AddField(_ => _.Term(Terms.taxonID))
                                       .AddField(_ => _.Term(Terms.vernacularName))
                                       .AddField(_ => _.Term(Terms.language));
            var fileMetaData = CoreFileMetaDataBuilder.File("taxon.txt")
                               .FieldsEnclosedBy("\"")
                               .FieldsTerminatedBy(",")
                               .LinesTerminatedBy("\\n")
                               .IgnoreHeaderLines(1)
                               .Encoding(Encoding.UTF8)
                               .Index(0)
                               .RowType(RowTypes.Taxon)
                               .AddFields(fieldMetaDataBuilder);
            var fileBuider = FileBuilder.MetaData(fileMetaData)
                             .UseExistingFile("./resources/whales/whales.txt");

            ArchiveWriter.CoreFile(fileBuider, fileMetaData)
            .Build("whales.zip");

            Assert.True(File.Exists("whales.zip"));

            using (var archive = new ArchiveReader("whales.zip"))
            {
                var whales = archive.CoreFile
                             .DataRows
                             .Select(n => n[Terms.vernacularName]);
                Assert.Equal(new[] { "sperm whale", "cachalot", "gray whale" }, whales);
            }
        }
Пример #12
0
 public void Write(ArchiveWriter ar)
 {
     ar.WriteStringL(FontName);
     ar.Write(lfHeight);
     ar.Write(lfWeight);
     ar.Write(lfUnderline);
     ar.Write(lfItalic);
     ar.Write(lfStrikeout);
 }
Пример #13
0
        /// <summary>
        /// Configures the logging of error messages.
        /// </summary>
        private static void CreateErrorLogger()
        {
            string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            ArchiveWriter archiveWriter = new ArchiveWriter(directory + @"\logs", "error");
            LevelWriter levelWriter = new LevelWriter(archiveWriter, new[] {Logger.eLEVEL.ERROR});
            FormatWriter formatWriter = new FormatWriter(levelWriter, new DetailFormat());

            Logger.Add(formatWriter);
        }
Пример #14
0
        /// <summary>
        /// Configures the logging of messages by thread.
        /// </summary>
        private static void CreateThreadLogger(string pName, int pThreadID)
        {
            string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            ArchiveWriter archiveWriter = new ArchiveWriter(directory + @"\logs", pName.ToLower().Replace(' ','-'));
            ThreadWriter threadWriter = new ThreadWriter(archiveWriter, pThreadID);
            FormatWriter formatWriter = new FormatWriter(threadWriter, new DetailFormat());

            Logger.Add(formatWriter);
        }
Пример #15
0
        public override void Write(ArchiveWriter writer)
        {
            writer.WriteCompressedInt(ChildCount);
            var data = (PcomObject[])_obj;

            for (var i = 0; i < ChildCount; i++)
            {
                WriteToBlob(writer, data[i]);
            }
        }
Пример #16
0
 public void Archive_PasswordCancel() => Assert.That(() =>
 {
     using (var writer = new ArchiveWriter(Format.Zip))
     {
         var dest  = GetResultsWith("PasswordCancel.zip");
         var query = new Query <string>(e => e.Cancel = true);
         writer.Add(GetExamplesWith("Sample.txt"));
         writer.Save(dest, query, null);
     }
 }, Throws.TypeOf <OperationCanceledException>());
Пример #17
0
        public override void Write(ArchiveWriter writer)
        {
            writer.Write((byte)0);
            writer.Write((byte)(IsArray ? 1 : 0));
            writer.WriteCompressedInt(ChildCount);

            foreach (var o in this)
            {
                WriteToBlob(writer, o);
            }
        }
Пример #18
0
 public override void Write(ArchiveWriter ar)
 {
     if (Value)
     {
         ar.Write(Convert.ToInt16(1));
     }
     else
     {
         ar.Write(Convert.ToInt16(0));
     }
 }
Пример #19
0
        public ArchiveFileManager(string leaguePath)
        {
            _leaguePath = leaguePath;
            _reader     = new ArchiveReader();
            _writer     = new ArchiveWriter();
            _writing    = false;

            LoadManifestPaths();
            LoadArchiveStates();
            LoadArchives();
        }
Пример #20
0
 public void Archive_SfxNotFound() => Assert.That(() =>
 {
     using (var writer = new ArchiveWriter(Format.Sfx))
     {
         var dest      = GetResultsWith("SfxNotFound.exe");
         writer.Option = new SfxOption {
             Module = "dummy.sfx"
         };
         writer.Add(GetExamplesWith("Sample.txt"));
         writer.Save(dest);
     }
 }, Throws.TypeOf <System.IO.FileNotFoundException>());
Пример #21
0
 public override void Write(ArchiveWriter ar)
 {
     base.BaseWrite(ar);
     if (m_WindowsCommand == Windows.SW_MAXIMIZE)
     {
         ar.Write((short)Windows.SW_RESTORE);
         Globals.NonFatalOperationalError(Strings.Item("SAW_FILE_SAW6_Unsupported", "Maximize Window command"));
     }
     else
     {
         ar.Write(m_WindowsCommand);
     }
 }
Пример #22
0
        public void Archive_PermissionError() => Assert.That(() =>
        {
            var dir = GetResultsWith("PermissionError");
            var src = IO.Combine(dir, "Sample.txt");

            IO.Copy(GetExamplesWith("Sample.txt"), src);

            using (var _ = OpenExclude(src))
                using (var writer = new ArchiveWriter(Format.Zip))
                {
                    writer.Add(src);
                    writer.Save(IO.Combine(dir, "Sample.zip"));
                }
        }, Throws.TypeOf <System.IO.IOException>());
Пример #23
0
Файл: Puyo.cs Проект: X-Hax/SA3D
        public override byte[] GetBytes()
        {
            MemoryStream  pvmStream         = new MemoryStream();
            ArchiveBase   pvmbase           = new PvmArchive();
            ArchiveWriter puyoArchiveWriter = pvmbase.Create(pvmStream);

            foreach (PVMEntry tex in Entries)
            {
                MemoryStream ms = new MemoryStream(tex.Data);
                puyoArchiveWriter.CreateEntry(ms, tex.Name);
            }
            puyoArchiveWriter.Flush();
            return(pvmStream.ToArray());
        }
Пример #24
0
        public override void Write(ArchiveWriter writer)
        {
            writer.Write((byte)0);
            if (_objects.Count > 0)
            {
                writer.Write((byte)1);
                base.Write(writer);
            }
            else
            {
                writer.Write((byte)0);
            }

            writer.WriteCompressedInt(Width);
            writer.WriteCompressedInt(Height);
            writer.WriteCompressedInt((int)PixFormat);
            writer.WriteCompressedInt(MagLevel);

            for (var i = 0; i < 4; i++)
            {
                writer.WriteCompressedInt((int)0);
            }

            int dataSize = 0;

            // Data Size
            writer.Write(dataSize);
            if (dataSize > 0)
            {
                // CWzCanvas::SerializeData
                writer.Write((byte)0);

                for (int y = 0; y < Height; y += TileHeight)
                {
                    RCINFO[] rcs = new RCINFO[WidthCount];
                    int      i   = 0;
                    for (int x = 0; x < Width; x += TileWidth)
                    {
                        var canvas = GetCanvas(x, y);
                        var rcinfo = new RCINFO
                        {
                            currentOffset = 0,
                            rc            = canvas,
                        };

                        canvas.LockAddress(out rcinfo.pitch, out rcinfo.data);
                    }
                }
            }
        }
Пример #25
0
        public void TestValidWriterGeneration()
        {
            Dictionary <ArchiveFactory.Type, Type> validIterators = new Dictionary <ArchiveFactory.Type, Type>()
            {
                { ArchiveFactory.Type.Tar, typeof(SharpZipTarArchiveWriter) },
                { ArchiveFactory.Type.Zip, typeof(DotNetZipZipWriter) }
            };

            foreach (KeyValuePair <ArchiveFactory.Type, Type> pair in validIterators)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    ArchiveWriter providedStream = ArchiveFactory.Writer(pair.Key, ms);
                    Assert.AreEqual(providedStream.GetType(), pair.Value);
                }
            }
        }
Пример #26
0
        public int Run()
        {
            using (var writer = new ArchiveWriter("test_archive.pak", false))
            {
                writer.Compress(Assembly.GetExecutingAssembly(), "examples.Resources.lorem_ipsum.txt", "lorem_ipsum.txt");
            }

            using (var reader = new ArchiveReader("test_archive.pak"))
            {
                var file = reader.GetFile("lorem_ipsum.txt");
                var data = reader.Decompress(file);

                string content = Encoding.ASCII.GetString(data);
                Console.WriteLine(content);
            }

            return(0);
        }
        /* ----------------------------------------------------------------- */
        ///
        /// Invoke
        ///
        /// <summary>
        /// Invokes the compression and saves the archive.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void Invoke(CompressRuntimeSetting src)
        {
            GetType().LogDebug($"Format:{src.Format}", $"Method:{src.CompressionMethod}");

            using (var writer = new ArchiveWriter(src.Format, src.ToOption(Settings)))
            {
                foreach (var e in Request.Sources)
                {
                    writer.Add(e);
                }
                writer.Save(Temp, GetProgress());
            }

            if (Io.Exists(Temp))
            {
                Io.Move(Temp, Destination, true);
            }
        }
        public Format Archive(Format format, string filename, string password,
                              string[] items, ArchiveOption option)
        {
            var dest = GetResultsWith(filename);

            using (var writer = new ArchiveWriter(format))
            {
                writer.Option = option;
                foreach (var item in items)
                {
                    writer.Add(GetExamplesWith(item));
                }
                writer.Save(dest, password);
                writer.Clear();
            }

            using (var ss = IO.OpenRead(dest)) return(Formats.FromStream(ss));
        }
Пример #29
0
        public int Archive_Filter(bool filter)
        {
            var names = new[] { "Filter.txt", "FilterDirectory" };
            var s     = filter ? "True" : "False";
            var dest  = GetResultsWith($"Filter{s}.zip");

            using (var writer = new ArchiveWriter(Format.Zip))
            {
                if (filter)
                {
                    writer.Filters = names;
                }
                writer.Add(GetExamplesWith("Sample.txt"));
                writer.Add(GetExamplesWith("Sample 00..01"));
                writer.Save(dest);
            }

            using (var reader = new ArchiveReader(dest)) return(reader.Items.Count);
        }
Пример #30
0
        public async Task ShouldBuildArchive()
        {
            var context = BuilderContext.Default;

            var occurrences = await fixture.GetOccurrencesAsync();

            var occurrenceMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder;
            var coreFileMetaDataBuilder   = CoreFileMetaDataBuilder.File("occurrence.txt")
                                            .IgnoreHeaderLines(1)
                                            .Encoding(Encoding.UTF8)
                                            .Index(0)
                                            .RowType(RowTypes.Occurrence)
                                            .AddFields(occurrenceMetaDataBuilder);
            var coreFileBuilder = FileBuilder.MetaData(coreFileMetaDataBuilder)
                                  .Context(context)
                                  .BuildRows(rowBuilder => BuildCoreRows(rowBuilder));

            var multimedia = await fixture.GetMultimediaAsync();

            var multimediaMetaDataBuilder    = fixture.MultimediaMetaDataBuilder;
            var extensionFileMetaDataBuilder = ExtensionFileMetaDataBuilder.File("multimedia.txt")
                                               .IgnoreHeaderLines(1)
                                               .Encoding(Encoding.UTF8)
                                               .CoreIndex(0)
                                               .RowType(RowTypes.Occurrence)
                                               .AddFields(multimediaMetaDataBuilder);
            var extensionFileBuilder = FileBuilder.MetaData(extensionFileMetaDataBuilder)
                                       .Context(context)
                                       .BuildRows(rowBuilder => BuildExtensionRows(rowBuilder));

            var archiveName = "archivexxx.zip";

            ArchiveWriter.CoreFile(coreFileBuilder, coreFileMetaDataBuilder)
            .Context(context)
            .AddExtensionFile(extensionFileBuilder, extensionFileMetaDataBuilder)
            .AddExtraFile("resources/ExtraData.txt")
            .Build(archiveName);

            Assert.True(File.Exists(archiveName));
            context.Cleanup();
        }
Пример #31
0
        public void TestSubPropSerializingAndDeserializing()
        {
            var parentProp = new WzProperty();
            var subProp    = new WzProperty();

            parentProp.Set("sub", subProp);


            var ms = new MemoryStream();
            var aw = new ArchiveWriter(ms);

            parentProp.Write(aw);


            ms.Position = 0;

            var outProp = new WzProperty();

            outProp.Read(new ArchiveReader(ms));

            Assert.IsTrue(outProp.HasChild("sub"));
            Assert.IsInstanceOfType(outProp["sub"], typeof(WzProperty));
        }
Пример #32
0
        public override void Write(ArchiveWriter writer)
        {
            writer.Write((byte)0);
            if (_objects.Count > 0)
            {
                writer.Write((byte)1);
                base.Write(writer);
            }
            else
            {
                writer.Write((byte)0);
            }

            writer.WriteCompressedInt(Width);
            writer.WriteCompressedInt(Height);
            writer.WriteCompressedInt((int)PixFormat);
            writer.WriteCompressedInt(MagLevel);

            for (var i = 0; i < 4; i++)
            {
                writer.WriteCompressedInt((int)0);
            }
        }