Ejemplo n.º 1
0
 public void Extract(VSAS fileArchive)
 {
     Console.WriteLine("EXTRACTED FILES:");
     foreach (InnerFile file in fileArchive.files)
     {
         string filepath = outputDir;
         foreach (byte b in file.header.fileName.Take(file.header.fileNameLength).ToArray())
         {
             filepath += (char)b;
         }
         Console.WriteLine(filepath);
         File.WriteAllBytes(filepath, file.data);
     }
 }
Ejemplo n.º 2
0
        public void Archive(VSAS fileArchive, string name, bool encrypt, int compress)
        {
            if (encrypt)
            {
                fileArchive.header.algNumEncryption = 1;
            }
            else
            {
                fileArchive.header.algNumEncryption = 0;
            }

            if (compress == 1)
            {
                fileArchive.header.algNumContextCompression = 1;
            }
            else
            if (compress == 0)
            {
                fileArchive.header.algNumContextCompression = 0;
            }
            else
            if (compress == 2)
            {
                fileArchive.header.algNumContextCompression = 2;
            }

            if (compress != 0)
            {
                Console.WriteLine("INPUT FILES COMPRESSION");
            }
            if (encrypt)
            {
                Console.WriteLine("INPUT FILES ENCRYPTION");
            }
            Console.WriteLine("TO:");

            // ЗАШИФРОВКА И УПАКОВКА
            List <byte> arr = new List <byte>();

            arr.AddRange(fileArchive.header.ToBytes());
            foreach (InnerFile file in fileArchive.files)
            {
                if (encrypt)
                {
                    Encrypt(file);
                }
                if (compress == 1)
                {
                    CompressWithFano(file);
                }
                if (compress == 2)
                {
                    CompressWithArythmetic(file);
                }

                arr.AddRange(file.header.ToBytes());
                if (encrypt)
                {
                    arr.AddRange(file.encryptionHeader);
                }
                if (compress == 1)
                {
                    arr.AddRange(file.symCodeTable);
                }


                arr.AddRange(file.data);
            }

            string archivePath = outputDir + name;

            Console.WriteLine(archivePath);
            File.WriteAllBytes(archivePath, arr.ToArray());
        }