Beispiel #1
0
        private void LoadFileOrDirectory(string path)
        {
            // 新規アーカイバ
            ArchiverBase archiver;

            // ファイル
            if (File.Exists(path))
            {
                // 拡張子取得
                string ext = Path.GetExtension(path);

                // 画像ファイル単体
                ImageFileContext ifc = NullArchiver.LoadImageFileContext(path);
                if (ifc != null)
                {
                    ImageFileContextList.Add(ifc);
                }

                // 圧縮ファイル / その他のファイル
                else
                {
                    if (ext == ".lnk")
                    {
                        // .lnkファイルの場合、ショートカット先のフルパスを取得し、やり直し
                        LoadFileOrDirectory(GetShortcutTargetPath(path));
                        return;
                    }
                    else
                    {
                        // 書庫
                        archiver = ArchiverFactory.Create(path, ext);
                        if (archiver == null)
                        {
                            return;
                        }
                        else
                        {
                            Archivers.Add(archiver);
                        }
                    }

                    ImageFileContextList.AddRange(archiver.LoadImageFileContextList());
                }
            }

            // フォルダ
            else if (Directory.Exists(path))
            {
                Archivers.Add(archiver = new FolderArchiver(path));
                ImageFileContextList.AddRange(archiver.LoadImageFileContextList());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Выполнить разархивацию файла.
        /// </summary>
        /// <param name="sourceFile">Архивированный файл.</param>
        /// <param name="targetFile">Разархивированный файл.</param>
        private static void Decompress(string sourceFile, string targetFile)
        {
            using (var sourceStream = new FileStream(sourceFile, FileMode.Open))
                using (var targetStream = new FileStream(targetFile, FileMode.Create))
                    using (var archiver = ArchiverFactory.GetArchiver(sourceStream, targetStream, ThreadExceptionHandler))
                    {
                        archiver.Decompress();
                    }

            if (threadException != null)
            {
                throw threadException;
            }

            Console.WriteLine($"File successfully decompressed to {targetFile}");
        }