Exemplo n.º 1
0
        private async void extractMenuItem(object sender, RoutedEventArgs e)
        {
            if (file == null)
            {
                return;
            }
            List <BarEntry> entries;

            if ((sender as MenuItem).Tag.ToString() == "Selected")
            {
                entries = files.SelectedItems.Cast <BarEntry>().ToList();
            }
            else
            {
                entries = file.barFile.BarFileEntrys.ToList();
            }


            if (entries.Count != 0)
            {
                string RootPath;


                ExtractDialog ExtractDialog = new ExtractDialog(file.barFilePath);
                if (ExtractDialog.ShowDialog() != true)
                {
                    return;
                }

                RootPath = ExtractDialog.Path;


                mainMenu.IsEnabled        = false;
                tbExtract.Text            = "Extracting";
                SpinnerExtract.Visibility = Visibility.Visible;
                bPause.IsEnabled          = true;
                bStop.IsEnabled           = true;
                bRun.IsEnabled            = false;
                bool decompress = ExtractDialog.AutoDecompress;

                file.extractingState = 0;
                CancelTokenSource    = new CancellationTokenSource();
                Token = CancelTokenSource.Token;
                try
                {
                    await Task.Run(async() =>
                    {
                        await file.saveFiles(entries, RootPath, decompress, Token, ExtractDialog.AutoDDTConversion, ExtractDialog.AutoXMBConversion);
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                bPause.IsEnabled          = false;
                bStop.IsEnabled           = false;
                bRun.IsEnabled            = false;
                tbExtract.Text            = "Extract";
                SpinnerExtract.Visibility = Visibility.Collapsed;
                mainMenu.IsEnabled        = true;
            }
        }
        private async void extractMenuItem(object sender, RoutedEventArgs e)
        {
            if (file == null)
            {
                return;
            }
            mainMenu.IsEnabled        = false;
            tbExtract.Text            = "Extracting";
            SpinnerExtract.Visibility = Visibility.Visible;
            List <BarEntry> entries;

            if ((sender as MenuItem).Tag.ToString() == "Selected")
            {
                entries = files.SelectedItems.Cast <BarEntry>().ToList();
            }
            else if ((sender as MenuItem).Tag.ToString() == "List")
            {
                entries = new List <BarEntry>();
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "Text files (*.txt)|*.txt";
                if (openFileDialog.ShowDialog() == true)
                {
                    List <string> icons = new List <string>(await File.ReadAllLinesAsync(openFileDialog.FileName));
                    entries = file.barFile.BarFileEntrys.Where(x =>
                                                               icons.Any(y => x.FileNameWithRoot.ToLower().EndsWith(y.Replace('/', '\\').ToLower()))).ToList();
                }
            }
            else
            {
                entries = file.SourceCollection.Cast <BarEntry>().ToList();
            }

            if (entries.Count != 0)
            {
                string RootPath;


                ExtractDialog ExtractDialog = new ExtractDialog(file.barFilePath);
                if (ExtractDialog.ShowDialog() == true)
                {
                    RootPath         = ExtractDialog.Path;
                    bPause.IsEnabled = true;
                    bStop.IsEnabled  = true;
                    bRun.IsEnabled   = false;
                    bool decompress = ExtractDialog.AutoDecompress;

                    file.extractingState = 0;
                    CancelTokenSource    = new CancellationTokenSource();
                    Token = CancelTokenSource.Token;
                    try
                    {
                        await Task.Run(async() =>
                        {
                            await file.saveFiles(entries, RootPath, decompress, Token, ExtractDialog.AutoDDTToPNGConversion, ExtractDialog.AutoDDTToTGAConversion, ExtractDialog.AutoXMBConversion, ExtractDialog.OneFolder, ExtractDialog.SavePNGasBMP, ExtractDialog.AutoJSONConversion, ExtractDialog.OverlayColor);
                        });
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    bPause.IsEnabled = false;
                    bStop.IsEnabled  = false;
                    bRun.IsEnabled   = false;
                }
            }
            tbExtract.Text            = "Extract";
            SpinnerExtract.Visibility = Visibility.Collapsed;
            mainMenu.IsEnabled        = true;
        }
Exemplo n.º 3
0
        private async void extractMenuItem(object sender, RoutedEventArgs e)
        {
            if (file == null)
            {
                return;
            }
            List <BarEntry> entries;

            if ((sender as MenuItem).Tag.ToString() == "Selected")
            {
                entries = files.SelectedItems.Cast <BarEntry>().ToList();
            }
            else
            {
                entries = file.barFile.BarFileEntrys.ToList();
            }


            if (entries.Count != 0)
            {
                string RootPath;


                ExtractDialog ExtractDialog = new ExtractDialog();
                if (ExtractDialog.ShowDialog() != true)
                {
                    return;
                }

                RootPath = ExtractDialog.Path;


                mainMenu.IsEnabled        = false;
                tbExtract.Text            = "Extracting";
                SpinnerExtract.Visibility = Visibility.Visible;
                bPause.IsEnabled          = true;
                bStop.IsEnabled           = true;
                bRun.IsEnabled            = false;
                bool decompress = ExtractDialog.AutoDecompress;
                if (file.barFile.barFileHeader.Version > 3 && !ExtractDialog.AutoDecompress)
                {
                    decompress = MessageBox.Show("Do you want to decompress compressed files? (If you do not decompress them, you will not be able to open and edit these files.)", "Decompress files", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes;
                }

                file.extractingState = 0;
                CancelTokenSource    = new CancellationTokenSource();
                Token = CancelTokenSource.Token;
                try
                {
                    await Task.Run(async() =>
                    {
                        await file.saveFiles(entries, RootPath, decompress, Token);
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                bPause.IsEnabled          = false;
                bStop.IsEnabled           = false;
                bRun.IsEnabled            = false;
                tbExtract.Text            = "Extract";
                SpinnerExtract.Visibility = Visibility.Collapsed;
                mainMenu.IsEnabled        = true;
            }
        }