コード例 #1
0
        public async Task ExtractFiles()
        {
            try
            {
                IsExtracting = true;
                if (ExtractAll)
                {
                    await ArchiveInfo.ExtractAllAsync(DestinationFolder, cancellationToken.Token, ExtractionProgress);
                }
                else
                {
                    await ArchiveInfo.ExtractFilesAsync(FilesToExtract, DestinationFolder, ExtractionProgress, Timeout.InfiniteTimeSpan,
                                                        cancellationToken.Token);
                }

                ExtractionState = ExtractionFinishedState.Succeed;
            }
            catch (OperationCanceledException)
            {
                ExtractionState = ExtractionFinishedState.Canceled;
            }
            catch (BA2ExtractionException)
            {
                ExtractionState = ExtractionFinishedState.Failed;
            }
            finally
            {
                IsExtracting = false;
                OnFinished?.Invoke(this, ExtractionState);
            }
        }
コード例 #2
0
 public void SetExtractFiles(ArchiveInfo archive, string destFolder, IEnumerable <int> files)
 {
     Reset();
     ExtractAll        = false;
     DestinationFolder = destFolder;
     ArchiveInfo       = archive;
     FilesToExtract    = files;
 }
コード例 #3
0
 public void SetExtractAll(ArchiveInfo archive, string destFolder)
 {
     Reset();
     ExtractAll        = true;
     DestinationFolder = destFolder;
     ArchiveInfo       = archive;
     FilesToExtract    = null;
 }
コード例 #4
0
ファイル: MainViewModel.cs プロジェクト: clayne/ba2explorer
        /// <summary>
        /// Unregisters this instance from the Messenger class.
        /// <para>To cleanup additional resources, override this method, clean
        /// up and then call base.Cleanup().</para>
        /// </summary>
        public override void Cleanup()
        {
            if (ArchiveInfo != null && !ArchiveInfo.IsDisposed)
            {
                ArchiveInfo.Dispose();
            }

            base.Cleanup();
        }
コード例 #5
0
        public void SetArchive(ArchiveInfo archive)
        {
            if (archive == null)
            {
                throw new ArgumentNullException(nameof(archive));
            }

            Archive = archive;
        }
コード例 #6
0
        public static ArchiveInfo Open(string path)
        {
            BA2Archive archive = BA2Loader.Load(path,
                                                AppSettings.Instance.Global.MultithreadedExtraction ? BA2LoaderFlags.Multithreaded : BA2LoaderFlags.None);

            ArchiveInfo info = new ArchiveInfo();

            info.Archive   = archive;
            info.FileNames = new ObservableCollection <string>(archive.FileList);
            info.FilePath  = path;
            info.FileName  = Path.GetFileName(info.FilePath);

            return(info);
        }
コード例 #7
0
ファイル: MainViewModel.cs プロジェクト: clayne/ba2explorer
        /// <summary>
        /// Closes archive and optionally changes application
        /// title back to normal.
        /// </summary>
        /// <param name="resetUI">Reset user interface?</param>
        public void CloseArchive(bool resetUI)
        {
            if (ArchiveInfo == null)
            {
                return;
            }

            if (!ArchiveInfo.IsDisposed)
            {
                ArchiveInfo.Dispose();
            }

            ArchiveInfo = null;
            OnArchiveClosed?.Invoke(this, resetUI);
        }
コード例 #8
0
ファイル: MainViewModel.cs プロジェクト: clayne/ba2explorer
        /// <summary>
        /// Extracts file from archive to some file in user file system, asking him where to save file using SaveFileDialog.
        /// </summary>
        /// <param name="fileName">File name in archive.</param>
        /// <returns>Task.</returns>
        public async Task ExtractFileWithDialog(int fileIndex)
        {
            string fileName = ArchiveInfo.Archive.FileList[fileIndex];

            if (fileName == null)
            {
                throw new Exception($"no file with index {fileIndex} exists.");
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.CheckPathExists = true;
            dialog.OverwritePrompt = true;
            dialog.ValidateNames   = true;
            dialog.Title           = "Extract file as...";
            dialog.FileName        = LowerFileNameExtension(Path.GetFileName(fileName));

            if (!String.IsNullOrWhiteSpace(AppSettings.Instance.Global.ExtractionLatestFolder))
            {
                dialog.InitialDirectory = AppSettings.Instance.Global.ExtractionLatestFolder;
            }

            string ext = Path.GetExtension(dialog.SafeFileName).ToLower();

            dialog.Filter = "Specified file|*" + ext + "|All files|*.*";

            var result = dialog.ShowDialog();

            if (result.HasValue && result.Value == true)
            {
                await ArchiveInfo.ExtractFileAsync(fileIndex, dialog.FileName);

                string destFolder = Path.GetDirectoryName(dialog.FileName);
                AppSettings.Instance.Global.ExtractionLatestFolder = destFolder;

                OnExtractionCompleted?.Invoke(this, new ExtractionEventArgs(dialog.FileName, 1, destFolder,
                                                                            ExtractionFinishedState.Succeed));
            }
        }
コード例 #9
0
ファイル: MainViewModel.cs プロジェクト: clayne/ba2explorer
        /// <summary>
        /// Opens the archive from file path.
        /// </summary>
        /// <exception cref="ArgumentException" />
        public bool OpenArchive(string path)
        {
            if (String.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException(nameof(path));
            }

            // Requested same archive.
            if (archiveInfo != null)
            {
                if (path.Equals(this.archiveInfo.FilePath, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            if (ArchiveInfo != null)
            {
                CloseArchive(false);
            }

            try
            {
                ArchiveInfo = ArchiveInfo.Open(path);
            }
            catch (Exception e)
            {
                MessageBox.Show($"Unable to open archive:{ Environment.NewLine }{ Environment.NewLine }{ e.Message }", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            AppSettings.Instance.Global.OpenArchiveLatestFolder = Path.GetDirectoryName(path);
            App.Logger.Log(LogPriority.Info, "Opened archive {0}", path);

            AppSettings.Instance.MainWindow.PushRecentArchive(path, this.RecentArchives);
            OnArchiveOpened?.Invoke(this, EventArgs.Empty);
            return(true);
        }