Beispiel #1
0
    private static Dictionary <string, ZipFile> bundles;//Zip散表


    /// <summary>
    /// 加载AB包
    /// </summary>
    public static void LoadBundle()
    {
        FileManager.bundles = new Dictionary <string, ZipFile>();
        if (!File.Exists(Application.dataPath + "\\StreamingAssets\\Blocks.bundle"))
        {
            return;
        }
        ReadOptions readOptions = new ReadOptions();

        readOptions.Encoding = Encoding.UTF8;
        ZipFile zipFile = ZipFile.Read(Application.dataPath + "\\StreamingAssets\\Blocks.bundle", readOptions);

        zipFile.Password = Global.PW;
        var v = ZipFile.CheckZipPassword(Application.dataPath + "\\StreamingAssets\\Blocks.bundle", Global.PW);

        Debug.Log(v);
        Debug.Log("ssss");

        if (zipFile == null)
        {
            return;
        }

        FileManager.bundles["\\blocks\\"] = zipFile;
        //zipFile.Save(Application.dataPath+"/1.zip");
    }
Beispiel #2
0
        public void Password_CheckZipPassword_wi13664()
        {
            string[] passwords = { null,
                                   "Password!",
                                   TestUtilities.GenerateRandomPassword(),
                                   "_" };

            string dirToZip = Path.Combine(TopLevelDir, "zipthis");
            int    subdirCount;
            int    entries = TestUtilities.GenerateFilesOneLevelDeep
                                 (TestContext, "wi13664", dirToZip, null, out subdirCount);

            string[] filesToZip = Directory.GetFiles("zipthis", "*.*", SearchOption.AllDirectories);

            Assert.AreEqual <int>(filesToZip.Length, entries,
                                  "Incorrect number of entries in the directory.");

            for (int j = 0; j < passwords.Length; j++)
            {
                string zipFileToCreate = Path.Combine(TopLevelDir, String.Format("Password_CheckZipPassword_wi13664-{0}.zip", j));

                // Create the zip archive
                using (ZipFile zip1 = new ZipFile())
                {
                    zip1.Password = passwords[j];
                    zip1.AddFiles(filesToZip, true, "");
                    zip1.Save(zipFileToCreate);
                }

                var r = ZipFile.CheckZipPassword(zipFileToCreate, passwords[j]);
                Assert.IsTrue(r, "Bad password in round {0}", j);
            }
        }
Beispiel #3
0
        static void ExtractToDirectory(string tmpfile, string password, string extractPath)
        {
            if (string.IsNullOrWhiteSpace(extractPath))
            {
                extractPath = Directory.GetCurrentDirectory();
            }
            log.info("decompressing file");

            if (ZipFile.IsZipFile(tmpfile))
            {
                if (ZipFile.CheckZipPassword(tmpfile, password))
                {
                    using (ZipFile zip = new ZipFile(tmpfile))
                    {
                        zip.Password = password;
                        zip.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently);
                    }
                    log.info("file decompressed");
                }
                else
                {
                    log.error("incorrect password for compressed file");
                }
            }
            else
            {
                log.info("the file not compressed file");
                copyFileAsIt(tmpfile, extractPath);
                log.info("file coped as it");
            }
        }
Beispiel #4
0
 public static bool CheckZip(string path, string password)
 {
     try
     {
         return(ZipFile.CheckZipPassword(path, password));
     }
     catch (ZipException)
     {
         return(false);
     }
 }
Beispiel #5
0
        private void LoadExistingCasePanel_Load(object sender, EventArgs e)
        {
            Dock = DockStyle.Fill;
            uiPasswordTextBox.Focus();
            ShowPasswordEntry(!ZipFile.CheckZipPassword(file.FullName, ""));
            InitialiseFileDetailFields();
            uiPasswordTextBox.UseSystemPasswordChar = true;
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork             += BackgroundWorker_DoWork;
            backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
            backgroundWorker.RunWorkerAsync();
        }
        // Try the specified password on zip file
        public bool TryPassword(string cPassword)
        {
            bool success = false;

            try
            {
                // Try if password works
                success = ZipFile.CheckZipPassword(mFileName, cPassword);
                if (success)
                {
                    mFoundPassword = cPassword;
                }
            }
            catch { }

            return(success);
        }
        public FREObject UnzipFile(FREContext ctx, uint argc, FREObject[] argv)
        {
            var zipFile         = Convert.ToString(new FreObjectSharp(argv[0]).Value);
            var outputDirectory = Convert.ToString(new FreObjectSharp(argv[1]).Value);
            var password        = Convert.ToString(new FreObjectSharp(argv[2]).Value);

            if (!ZipFile.CheckZipPassword(zipFile, password))
            {
                return(new FreObjectSharp(false).RawValue);
            }
            ZipFile zip = ZipFile.Read(zipFile);

            zip.Password = password;
            Directory.CreateDirectory(outputDirectory);
            zip.ExtractAll(outputDirectory, ExtractExistingFileAction.OverwriteSilently);
            zip.Dispose();

            return(new FreObjectSharp(true).RawValue);
        }
Beispiel #8
0
        public ZipLoader(string zipPath, string domain, string pwd = null)
        {
            if (File.Exists(zipPath) == false)
            {
                throw new FileNotFoundException(zipPath);
            }
            if (ZipFile.IsZipFile(zipPath) == false)
            {
                throw new NotSupportedException("无法识别的ZIP文件");
            }

            if (pwd != null && ZipFile.CheckZipPassword(zipPath, pwd) == false)
            {
                throw new BadPasswordException("密码不正确");
            }
            _zip          = ZipFile.Read(zipPath);
            _zip.Password = pwd;
            _pwd          = pwd;
            Domain        = domain;
        }
Beispiel #9
0
 private void cstmForce()
 {
     foreach (string x in custm)
     {
         Console.WriteLine(x);
         try
         {
             if (ZipFile.CheckZipPassword(zipFile, x))
             {
                 zip.Password = x;
                 zip.ExtractAll(targetDirectory, ExtractExistingFileAction.DoNotOverwrite);
                 MessageBox.Show("Extracted !", ":)");
                 Console.WriteLine("Password : "******"Press enter to exit ...");
                 Console.ReadLine();
                 Environment.Exit(0);
             }
         }
         catch
         {
         }
     }
 }
Beispiel #10
0
 private void bruteForce(int xx)
 {
     if (x == xx)
     {
         foreach (char chrx in area)
         {
             texttotal = text + chrx;
             Console.WriteLine(texttotal);
             try
             {
                 if (ZipFile.CheckZipPassword(zipFile, texttotal))
                 {
                     zip.Password = texttotal;
                     zip.ExtractAll(targetDirectory, ExtractExistingFileAction.DoNotOverwrite);
                     MessageBox.Show("Extracted !", ":)");
                     Console.WriteLine("Password : "******"Press enter to exit ...");
                     Console.ReadLine();
                     Environment.Exit(0);
                 }
             }
             catch
             {
             }
         }
     }
     else
     {
         xx--;
         foreach (char chrx in area)
         {
             text += chrx;
             bruteForce(xx);
             text = text.Substring(0, text.Length - 1);
         }
     }
 }
        // These two data types are supported in DotNetZip, but only if .NET Framework is targeted.
        //private SelfExtractorFlavor _selfExtractorFlavor;
        //private SelfExtractorSaveOptions _selfExtractorSaveOptions;

        public void CallAll()
        {
            // These two apis are supported in DotNetZip, but only if .NET Framework is targeted.
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorFlavor);
            //_zipFile.SaveSelfExtractor(_string, _selfExtractorSaveOptions);

            //Project: Ionic.Zip
            _bZip2InputStream.Close();
            _bZip2InputStream.Flush();
            _int  = _bZip2InputStream.Read(_bytes, _int, _int);
            _int  = _bZip2InputStream.ReadByte();
            _long = _bZip2InputStream.Seek(_long, _seekOrigin);
            _bZip2InputStream.SetLength(_long);
            _bZip2InputStream.Write(_bytes, _int, _int);
            _bZip2OutputStream.Close();
            _bZip2OutputStream.Flush();
            _int  = _bZip2OutputStream.Read(_bytes, _int, _int);
            _long = _bZip2OutputStream.Seek(_long, _seekOrigin);
            _bZip2OutputStream.SetLength(_long);
            _bZip2OutputStream.Write(_bytes, _int, _int);
            _parallelBZip2OutputStream.Close();
            _parallelBZip2OutputStream.Flush();
            _int  = _parallelBZip2OutputStream.Read(_bytes, _int, _int);
            _long = _parallelBZip2OutputStream.Seek(_long, _seekOrigin);
            _parallelBZip2OutputStream.SetLength(_long);
            _parallelBZip2OutputStream.Write(_bytes, _int, _int);
            _crc32.Combine(_int, _int);
            _int = _crc32.ComputeCrc32(_int, _byte);
            _int = _crc32.GetCrc32(_stream);
            _int = _crc32.GetCrc32AndCopy(_stream, _stream);
            _crc32.Reset();
            _crc32.SlurpBlock(_bytes, _int, _int);
            _crc32.UpdateCRC(_byte);
            _crc32.UpdateCRC(_byte, _int);
            _crcCalculatorStream.Close();
            _crcCalculatorStream.Flush();
            _int  = _crcCalculatorStream.Read(_bytes, _int, _int);
            _long = _crcCalculatorStream.Seek(_long, _seekOrigin);
            _crcCalculatorStream.SetLength(_long);
            _crcCalculatorStream.Write(_bytes, _int, _int);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile);
            _zipEntriesCollection = _fileSelector.SelectEntries(_zipFile, _string);
            _stringsCollection    = _fileSelector.SelectFiles(_string);
            _stringsReadOnly      = _fileSelector.SelectFiles(_string, _bool);
            _string = _fileSelector.ToString();
            _bool   = _comHelper.CheckZip(_string);
            _bool   = _comHelper.CheckZipPassword(_string, _string);
            _comHelper.FixZipDirectory(_string);
            _string = _comHelper.GetZipLibraryVersion();
            _bool   = _comHelper.IsZipFile(_string);
            _bool   = _comHelper.IsZipFileWithExtract(_string);
            _countingStream.Adjust(_long);
            _countingStream.Flush();
            _int  = _countingStream.Read(_bytes, _int, _int);
            _long = _countingStream.Seek(_long, _seekOrigin);
            _countingStream.SetLength(_long);
            _countingStream.Write(_bytes, _int, _int);
            _zipEntry.Extract();
            _zipEntry.Extract(_extractExistingFileAction);
            _zipEntry.Extract(_string);
            _zipEntry.Extract(_string, _extractExistingFileAction);
            _zipEntry.Extract(_stream);
            _zipEntry.ExtractWithPassword(_extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string);
            _zipEntry.ExtractWithPassword(_string, _extractExistingFileAction, _string);
            _zipEntry.ExtractWithPassword(_string, _string);
            _zipEntry.ExtractWithPassword(_stream, _string);
            _crcCalculatorStream = _zipEntry.OpenReader();
            _crcCalculatorStream = _zipEntry.OpenReader(_string);
            _zipEntry.SetEntryTimes(_datetime, _datetime, _datetime);
            _string   = _zipEntry.ToString();
            _zipEntry = _zipFile.AddDirectory(_string);
            _zipEntry = _zipFile.AddDirectory(_string, _string);
            _zipEntry = _zipFile.AddDirectoryByName(_string);
            _zipEntry = _zipFile.AddEntry(_string, _bytes);
            _zipEntry = _zipFile.AddEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.AddEntry(_string, _string);
            _zipEntry = _zipFile.AddEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.AddEntry(_string, _stream);
            _zipEntry = _zipFile.AddFile(_string);
            _zipEntry = _zipFile.AddFile(_string, _string);
            _zipFile.AddFiles(_strings);
            _zipFile.AddFiles(_strings, _bool, _string);
            _zipFile.AddFiles(_strings, _string);
            _zipEntry = _zipFile.AddItem(_string);
            _zipEntry = _zipFile.AddItem(_string, _string);
            _zipFile.AddSelectedFiles(_string);
            _zipFile.AddSelectedFiles(_string, _bool);
            _zipFile.AddSelectedFiles(_string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _bool);
            _zipFile.AddSelectedFiles(_string, _string, _string);
            _zipFile.AddSelectedFiles(_string, _string, _string, _bool);
            _bool = _zipFile.ContainsEntry(_string);
            _zipFile.Dispose();
            _zipFile.ExtractAll(_string);
            _zipFile.ExtractAll(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string);
            _zipFile.ExtractSelectedEntries(_string, _extractExistingFileAction);
            _zipFile.ExtractSelectedEntries(_string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string);
            _zipFile.ExtractSelectedEntries(_string, _string, _string, _extractExistingFileAction);
            _enumerator = _zipFile.GetNewEnum();
            _zipFile.Initialize(_string);
            _zipFile.RemoveEntries(_zipEntriesCollection);
            _zipFile.RemoveEntries(_stringsCollection);
            _zipFile.RemoveEntry(_zipEntry);
            _zipFile.RemoveEntry(_string);
            _int = _zipFile.RemoveSelectedEntries(_string);
            _int = _zipFile.RemoveSelectedEntries(_string, _string);
            _zipFile.Save();
            _zipFile.Save(_string);
            _zipFile.Save(_stream);
            _zipEntriesCollection = _zipFile.SelectEntries(_string);
            _zipEntriesCollection = _zipFile.SelectEntries(_string, _string);
            _string   = _zipFile.ToString();
            _zipEntry = _zipFile.UpdateDirectory(_string);
            _zipEntry = _zipFile.UpdateDirectory(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _bytes);
            _zipEntry = _zipFile.UpdateEntry(_string, _openDelegate, _closeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _writeDelegate);
            _zipEntry = _zipFile.UpdateEntry(_string, _string);
            _zipEntry = _zipFile.UpdateEntry(_string, _string, _encoding);
            _zipEntry = _zipFile.UpdateEntry(_string, _stream);
            _zipEntry = _zipFile.UpdateFile(_string);
            _zipFile.UpdateFile(_string, _string);
            _zipFile.UpdateFiles(_strings);
            _zipFile.UpdateFiles(_strings, _string);
            _zipFile.UpdateItem(_string);
            _zipFile.UpdateItem(_string, _string);
            _zipFile.UpdateSelectedFiles(_string, _string, _string, _bool);
            _zipInputStream.Flush();
            _zipEntry = _zipInputStream.GetNextEntry();
            _int      = _zipInputStream.Read(_bytes, _int, _int);
            _long     = _zipInputStream.Seek(_long, _seekOrigin);
            _zipInputStream.SetLength(_long);
            _string = _zipInputStream.ToString();
            _zipInputStream.Write(_bytes, _int, _int);
            _bool = _zipOutputStream.ContainsEntry(_string);
            _zipOutputStream.Flush();
            _zipEntry = _zipOutputStream.PutNextEntry(_string);
            _int      = _zipOutputStream.Read(_bytes, _int, _int);
            _long     = _zipOutputStream.Seek(_long, _seekOrigin);
            _zipOutputStream.SetLength(_long);
            _string = _zipOutputStream.ToString();
            _zipOutputStream.Write(_bytes, _int, _int);
            _deflateStream.Flush();
            _int  = _deflateStream.Read(_bytes, _int, _int);
            _long = _deflateStream.Seek(_long, _seekOrigin);
            _deflateStream.SetLength(_long);
            _deflateStream.Write(_bytes, _int, _int);
            _gZipStream.Flush();
            _int  = _gZipStream.Read(_bytes, _int, _int);
            _long = _gZipStream.Seek(_long, _seekOrigin);
            _gZipStream.SetLength(_long);
            _gZipStream.Write(_bytes, _int, _int);
            _parallelDeflateOutputStream.Close();
            _parallelDeflateOutputStream.Flush();
            _int = _parallelDeflateOutputStream.Read(_bytes, _int, _int);
            _parallelDeflateOutputStream.Reset(_stream);
            _long = _parallelDeflateOutputStream.Seek(_long, _seekOrigin);
            _parallelDeflateOutputStream.SetLength(_long);
            _parallelDeflateOutputStream.Write(_bytes, _int, _int);

            // Static
            _bool = ZipFile.CheckZip(_string);
            _bool = ZipFile.CheckZip(_string, _bool, _textWriter);
            _bool = ZipFile.CheckZipPassword(_string, _string);
            ZipFile.FixZipDirectory(_string);
            _bool    = ZipFile.IsZipFile(_string);
            _bool    = ZipFile.IsZipFile(_string, _bool);
            _bool    = ZipFile.IsZipFile(_stream, _bool);
            _zipFile = ZipFile.Read(_string);
            _zipFile = ZipFile.Read(_string, _readOptions);
            _zipFile = ZipFile.Read(_stream);
            _zipFile = ZipFile.Read(_stream, _readOptions);
            _uint    = Adler.Adler32(_uint, _bytes, _int, _int);
            _bytes   = DeflateStream.CompressBuffer(_bytes);
            _bytes   = DeflateStream.CompressString(_string);
            _bytes   = DeflateStream.UncompressBuffer(_bytes);
            _string  = DeflateStream.UncompressString(_bytes);
            _bytes   = GZipStream.CompressBuffer(_bytes);
            _bytes   = GZipStream.CompressString(_string);
            _bytes   = GZipStream.UncompressBuffer(_bytes);
            _string  = GZipStream.UncompressString(_bytes);
            _bytes   = ZlibStream.CompressBuffer(_bytes);
            _bytes   = ZlibStream.CompressString(_string);
            _bytes   = ZlibStream.UncompressBuffer(_bytes);
            _string  = ZlibStream.UncompressString(_bytes);
        }
Beispiel #12
0
        private void VerifyPassword(object sender, WaitWindowEventArgs e)
        {
            string password = e.Arguments[0].ToString();

            e.Result = ZipFile.CheckZipPassword(file.FullName, password);
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Console.WriteAscii("DIP Archiver", Color.Red);

            if (args.Length < 2)
            {
                Console.WriteLine("You must to insert at last 2 args:", Color.Red);
                printUsage();

                Close();
                return;
            }

            entryFormatter = new Formatter[]
            {
                new Formatter($"Name", Color.Orange),
                new Formatter($"Compressed size", Color.Orange),
                new Formatter($"Encrypted", Color.Orange),
                new Formatter($"Compression", Color.Orange),
                new Formatter($"CRC", Color.Orange)
            };

            importFormatter = new Formatter[]
            {
                new Formatter("Added", Color.Orange)
            };

            switch (args[0])
            {
            case "-p":
            {
                var dirPath = args[1];
                var pwdPath = args.Length > 2 ? args[2] : string.Empty;

                if (!Directory.Exists(dirPath))
                {
                    Console.WriteLine("Invalid path selected, try again..");
                    break;
                }

                Console.WriteLine("Creating new cgd.dip archive..", Color.White);
                using (ZipFile zip = new ZipFile
                    {
                        CompressionLevel = CompressionLevel.BestCompression,
                        Password = string.IsNullOrEmpty(pwdPath) ? Encoding.UTF8.GetString(key)
                                                       : Encoding.UTF8.GetString(File.ReadAllBytes(pwdPath))
                    })
                {
                    var files = Directory.GetFiles(dirPath, "*",
                                                   SearchOption.AllDirectories).
                                Where(f => Path.GetExtension(f).
                                      ToLowerInvariant() != ".dip").ToArray();

                    foreach (var f in files)
                    {
                        zip.AddFile(f,
                                    Path.GetDirectoryName(f).
                                    Replace(dirPath, string.Empty));

                        Console.WriteFormatted("{0}: " + f + "\n", Color.White, importFormatter);
                    }

                    zip.Save(Path.ChangeExtension(dirPath, ".dip"));
                    Console.WriteLine("Archive saved", Color.Green);
                }
                break;
            }

            case "-u":
            {
                var dipPath = args[1];
                var pwdPath = args.Length > 2 ? args[2] : string.Empty;
                var outPath = Path.Combine(Path.GetDirectoryName(dipPath), "dip_out");

                if (!Path.GetExtension(dipPath).Equals(".dip"))
                {
                    Console.WriteLine("Invalid file extension", Color.Red);
                    break;
                }

                if (!ZipFile.CheckZipPassword(dipPath, string.IsNullOrEmpty(pwdPath) ? Encoding.UTF8.GetString(key)
                                                                                 : Encoding.UTF8.GetString(File.ReadAllBytes(pwdPath))))
                {
                    Console.WriteLine("Invalid archive password", Color.Red);
                    break;
                }

                Console.WriteLine("Starting the extraction of cdb files..", Color.White);

                var file = new ZipFile(dipPath);
                file.Password = string.IsNullOrEmpty(pwdPath) ? Encoding.UTF8.GetString(key)
                                                          : Encoding.UTF8.GetString(File.ReadAllBytes(pwdPath));

                Console.WriteLine($"Entries found: {file.Entries.Count}\n", Color.White);
                foreach (var entry in file.Entries)
                {
                    Console.WriteFormatted("\t{0}: " + entry.FileName +
                                           "\n\t{1}: " + entry.CompressedSize +
                                           "\n\t{2}: " + entry.UsesEncryption +
                                           "\n\t{3}: " + entry.CompressionMethod + " [" + entry.CompressionLevel + "]" +
                                           "\n\t{4}: " + entry.Crc, Color.White, entryFormatter);

                    Console.WriteLine("\n\t-------------------\n\n", Color.White);
                    entry.Extract(outPath, ExtractExistingFileAction.OverwriteSilently);
                }

                Console.WriteLine("CDB files extracted", Color.Green);
                break;
            }
            }

            Close();
        }
Beispiel #14
0
        /// <summary>
        /// zipを解凍するメソッド
        /// </summary>
        /// <param name="filePath">解凍対象のzipファイル</param>
        /// <param name="tempPath">一時フォルダのパス</param>
        /// <param name="list">添付ファイルリスト</param>
        /// <returns>添付ファイルリスト</returns>
        public List <ClsFilePropertyList> UnZip(string filePath, string tempPath, List <ClsFilePropertyList> list, ref bool error)
        {
            error = false;

            var status = System.Console.Out;
            var encode = System.Text.Encoding.GetEncoding("Shift_JIS");

            string[] extractDir   = filePath.Split('/');
            string   dirName      = filePath.Replace(".zip", "");
            string   highTempPath = (tempPath.EndsWith(".zip") == true) ? tempPath.Substring(0, tempPath.Length - 4) : tempPath;

            dirName = Path.Combine(highTempPath, extractDir[extractDir.Length - 1].Replace(".zip", ""));

            dirName += "\\" + UNZIP_FOLDER;

            // 解凍先ディレクトリを作成する
            if (!Directory.Exists(dirName))
            {
                Directory.CreateDirectory(dirName);
            }
            // 同名のディレクトリが存在する場合はフォルダ名末尾に数字を追加
            else
            {
                for (int i = 1; ; i++)
                {
                    if (!Directory.Exists(dirName + i.ToString()))
                    {
                        dirName = dirName + "_" + i.ToString();
                        Directory.CreateDirectory(dirName);
                        break;
                    }
                }
            }

            List <ClsFilePropertyList> file_list = new List <ClsFilePropertyList>();

            try
            {
                var enc = new ReadOptions()
                {
                    Encoding = Encoding.GetEncoding("shift_jis")
                };                                                                              // 2020/09/10  文字化け対応

                using (ZipFile zip = ZipFile.Read(filePath, enc))
                {
                    // zipにパスワードが設定されているかチェック
                    bool passCheck = ZipFile.CheckZipPassword(zip.Name, "");
                    if (passCheck == false)
                    {
                        string[] passFileArray = new string[zip.EntryFileNames.Count];
                        zip.EntryFileNames.CopyTo(passFileArray, 0);
                        throw new BadPasswordException();
                    }
                    // 展開して一つ一つリストに入れていく
                    foreach (ZipEntry entry in zip)
                    {
                        // zipが出てきた場合再帰呼び出しをして解凍する
                        if (entry.FileName.EndsWith(".zip") == true)
                        {
                            // zipファイルと同名のフォルダがあるか調べる
                            var           entryCollection = zip.EntryFileNames;
                            List <string> entryList       = new List <string>();
                            entryList.AddRange(entryCollection);

                            List <string> entryFolderName = entryList.FindAll(x => x.Contains('/'));
                            List <string> entFolderList   = new List <string>();
                            for (int i = 0; i < entryFolderName.Count; i++)
                            {
                                entFolderList.Add(entryFolderName[i].Split('/')[0]);
                            }
                            string entryName = entry.FileName.Substring(0, entry.FileName.Length - 4);

                            // zipと同名のフォルダがあった場合展開先のフォルダ名の末尾に数字を追加
                            if (entFolderList.Contains(entryName))
                            {
                                string newDirName = "";
                                for (int i = 1; ; i++)
                                {
                                    if (!Directory.Exists(dirName + i.ToString()))
                                    {
                                        newDirName = Path.Combine(dirName, entryName) + "_" + i.ToString();
                                        Directory.CreateDirectory(newDirName);
                                        break;
                                    }
                                }
                                entry.Extract(newDirName);
                                string file_path = Path.Combine(newDirName, entry.FileName);

                                string deployPath = Path.Combine(newDirName, entry.FileName.Substring(0, entry.FileName.Length - 4));

                                file_list.Add(new ClsFilePropertyList {
                                    fileName = entry.FileName, filePath = Path.Combine(newDirName, entry.FileName), fileExtension = ".zip", file_list = UnZip(file_path, deployPath, file_list, ref error)
                                });
                            }
                            else
                            {
                                // 展開先フォルダを作ってその中に展開する
                                entry.Extract(dirName);
                                string file_path  = Path.Combine(dirName, entry.FileName);
                                string deployPath = Path.Combine(dirName, entry.FileName.Substring(0, entry.FileName.Length - 4));
                                file_list.Add(new ClsFilePropertyList {
                                    fileName = entry.FileName, filePath = Path.Combine(dirName, entry.FileName), fileExtension = ".zip", file_list = UnZip(file_path, deployPath, file_list, ref error)
                                });
                            }
                        }
                        else if (entry.IsDirectory == false)
                        {
                            entry.Extract(dirName);
                            string file_path = Path.Combine(dirName, entry.FileName);
                            file_list.Add(new ClsFilePropertyList {
                                fileName = entry.FileName, filePath = file_path, fileExtension = entry.FileName.Substring(entry.FileName.LastIndexOf("."))
                            });
                        }
                    }
                }
            }
            catch (BadPasswordException e)
            {
                file_list.Clear();

                MessageBox.Show(AddInsLibrary.Properties.Resources.msgPasswordZip,
                                AddInsLibrary.Properties.Resources.msgError,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Hand);

                error = true;
            }
            catch (Ionic.Zlib.ZlibException e)
            {
                string ErrorMsg = "";
                if (e.ToString().Contains("(oversubscribed dynamic bit lengths tree)") == true)
                {
                    ErrorMsg = AddInsLibrary.Properties.Resources.msgPasswordZip;
                }
                else
                {
                    ErrorMsg = AddInsLibrary.Properties.Resources.msgUnZipError;
                }

                file_list.Clear();

                MessageBox.Show(ErrorMsg,
                                AddInsLibrary.Properties.Resources.msgError,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Hand);

                error = true;
            }
            catch (Exception e)
            {
                file_list.Clear();

                MessageBox.Show(AddInsLibrary.Properties.Resources.msgUnZipError,
                                AddInsLibrary.Properties.Resources.msgError,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Hand);

                error = true;
            }

            return(file_list);
        }
 // Get if the zip file is protected by password
 public bool IsPasswordProtected()
 {
     // If not protected, an empty password will return true
     return(!ZipFile.CheckZipPassword(mFileName, ""));
 }
Beispiel #16
0
 /// <summary>
 ///  A COM-friendly wrapper for the static method <see cref="ZipFile.CheckZipPassword(string,string)"/>.
 /// </summary>
 ///
 /// <param name="filename">The filename to of the zip file to check.</param>
 ///
 /// <param name="password">The password to check.</param>
 ///
 /// <returns>true if the named zip file checks OK. Otherwise, false. </returns>
 public bool CheckZipPassword(string filename, string password)
 {
     return(ZipFile.CheckZipPassword(filename, password));
 }