Ejemplo n.º 1
0
        /// <summary>
        /// Replaces the selected item with a new item.
        /// </summary>
        /// <param name="item">The item to replace.</param>
        public async void ReplaceItem(NefsItem item)
        {
            if (item == null)
            {
                MessageBox.Show("No item selected to replace.");
                return;
            }

            /*
             * Open an open file dialog and get file to inject
             */
            var ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            var result = ofd.ShowDialog();

            if (result == DialogResult.OK)
            {
                /* Create a progress dialog form */
                var progressDialog = new ProgressDialogForm();

                /* Show the progress dialog asnyc */
                var progressDialogTask = progressDialog.ShowDialogAsync();

                /* Replace the item */
                await Task.Run(() =>
                {
                    try
                    {
                        log.Info("----------------------------");
                        log.Info(String.Format("Replacing {0} with {1}...", item.Filename, ofd.FileName));
                        item.Inject(ofd.FileName, progressDialog.ProgressInfo);
                        log.Info("Item successfully replaced with: " + ofd.FileName);
                    }
                    catch (Exception ex)
                    {
                        log.Error("Error replacing file.", ex);
                    }
                });

                /* Post-replace activites */
                updateTitle();

                /* Close the progress dialog */
                progressDialog.Close();
            }
        }
Ejemplo n.º 2
0
        private async void loadNefsAsync(string filePath)
        {
            /* Create a progress dialog form */
            var progressDialog = new ProgressDialogForm();

            /* Show the loading dialog asnyc */
            var progressDialogTask = progressDialog.ShowDialogAsync();

            /* Load the archive */
            var archive = await NefsArchive.LoadAsync(filePath, progressDialog.ProgressInfo);

            /* Close the progress dialog */
            progressDialog.Close();

            /* After loading activities */
            setArchive(archive);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the specified archive to the specified location.
        /// </summary>
        /// <param name="archive">The archive to save.</param>
        /// <param name="filename">Location to save to.</param>
        public async Task <bool> SaveArchiveAsync(NefsArchive archive, string filename)
        {
            var success = false;

            /* Create a progress dialog form */
            var progressDialog = new ProgressDialogForm();

            /* Show the progress dialog asnyc */
            var progressDialogTask = progressDialog.ShowDialogAsync();

            /* Replace the item */
            await Task.Run(() =>
            {
                try
                {
                    log.Info("----------------------------");
                    log.Info(String.Format("Saving archive to {0}...", filename));
                    archive.Save(filename, progressDialog.ProgressInfo);
                    log.Info("Item successfully saved: " + filename);
                    success = true;
                }
                catch (Exception ex)
                {
                    log.Error("Error saving archive.", ex);
                }
            });

            /* Update editor */
            setArchive(archive);
            SelectNefsItem(_selectedItems);
            updateTitle();

            /* Close the progress dialog */
            progressDialog.Close();

            return(success);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Extracts the specified items.
        /// </summary>
        /// <param name="items">The items to extract.</param>
        /// <param name="useQuickExtract">Whether or not to extract to the quick extract directory.</param>
        public async void ExtractItems(List <NefsItem> items, bool useQuickExtract)
        {
            if (items == null || items.Count == 0)
            {
                MessageBox.Show("No items selected to selected.");
                return;
            }

            var outputDir  = "";
            var outputFile = "";

            if (useQuickExtract)
            {
                /*
                 * Use the quick extraction directory
                 */
                if (!Directory.Exists(Settings.QuickExtractDir))
                {
                    /* Quick extract dir not set, have user choose one */
                    if (!Settings.ChooseQuickExtractDir())
                    {
                        /* User cancelled the directory selection */
                        return;
                    }
                }

                outputDir = Settings.QuickExtractDir;
            }
            else
            {
                /*
                 * Have user choose where to save the items
                 */
                var result = DialogResult.Cancel;

                /* Show either a directory chooser or a save file dialog */
                if (items.Count > 1 || items[0].Type == NefsItem.NefsItemType.Directory)
                {
                    /* Extracting multiple files or a directory - show folder browser */
                    var fbd = new FolderBrowserDialog();
                    fbd.Description         = "Choose where to extract the items to.";
                    fbd.ShowNewFolderButton = true;

                    result    = fbd.ShowDialog();
                    outputDir = fbd.SelectedPath;
                }
                else
                {
                    /* Extracting a file - show a save file dialog*/
                    var sfd = new SaveFileDialog();
                    sfd.OverwritePrompt = true;
                    sfd.FileName        = items[0].Filename;

                    result     = sfd.ShowDialog();
                    outputDir  = Path.GetDirectoryName(sfd.FileName);
                    outputFile = Path.GetFileName(sfd.FileName);
                }

                if (result != DialogResult.OK)
                {
                    /* Use canceled the dialog box */
                    return;
                }
            }

            /* Create a progress dialog form */
            var progressDialog = new ProgressDialogForm();

            /* Show the loading dialog asnyc */
            var progressDialogTask = progressDialog.ShowDialogAsync();

            /* Extract the item */
            await Task.Run(() =>
            {
                try
                {
                    var p        = progressDialog.ProgressInfo;
                    var numItems = _selectedItems.Count;

                    log.Info("----------------------------");
                    p.BeginTask(1.0f);

                    /* Extract each item */
                    for (int i = 0; i < numItems; i++)
                    {
                        var item = _selectedItems[i];
                        var dir  = outputDir;
                        var file = outputFile;

                        /* When extracting multiple items or using the quick extraction
                         * directory, use the original filenames and directory structure
                         * of the archive */
                        if (numItems > 0 || useQuickExtract)
                        {
                            var dirInArchive = Path.GetDirectoryName(item.FilePathInArchive);
                            dir  = Path.Combine(outputDir, dirInArchive);
                            file = Path.GetFileName(item.FilePathInArchive);
                        }

                        log.Info(String.Format("Extracting {0} to {1}...", item.FilePathInArchive, Path.Combine(dir, file)));
                        try
                        {
                            item.Extract(dir, file, p);
                        }
                        catch (Exception ex)
                        {
                            log.Error(String.Format("Error extracting item {0}.", item.FilePathInArchive));
                        }
                    }

                    p.EndTask();
                    log.Info("Extraction finished.");
                }
                catch (Exception ex)
                {
                    log.Error("Error extracting items.", ex);
                }
            });

            /* Close the progress dialog */
            progressDialog.Close();
        }