Exemplo n.º 1
0
        /// <summary>
        /// Processes a previously-extracted subfile that's open in an editor. This process runs its translation steps backwards,
        /// before finally re-packing the final product into the original SPC file it came from.
        /// </summary>
        /// <param name="tempDir">The temporary directory where the extracted subfile data is located.</param>
        /// <param name="info">The <see cref="EditorTrackingInfo"/> associated with the editor and subfile.</param>
        private void RepackArchiveSubfile(string tempDir, EditorTrackingInfo info)
        {
            // First, run all translation steps in reverse
            var translationSteps    = info.SelectedAssociation.TranslationSteps;
            var translatedFilenames = info.SubfileNameHistory;

            for (int step = (translationSteps.Count - 1); step >= 0; --step)
            {
                // Resolve internal/external translator
                object resolvedTranslator = Config.FileAssociationConfig.ResolveInternalExternal(translationSteps[step]) as Process;

                // Run the translation step
                if (resolvedTranslator is Window)
                {
                    Window translatorWindow = resolvedTranslator as Window;

                    // Finally, open the target editor window as blocking
                    translatorWindow.ShowDialog();
                }
                else if (resolvedTranslator is Process)
                {
                    Process translatorProcess = resolvedTranslator as Process;

                    // Setup the target process' launch args
                    translatorProcess.StartInfo.Arguments = Path.Combine(tempDir, translatedFilenames[step + 1]);

                    translatorProcess.Start();
                    translatorProcess.WaitForExit();
                }
                else
                {
                    // If we get here, there's been an error and we should abort
                    return;
                }
            }

            // The final translated filename is the original file & format, repack it
            SpcFile spc = new SpcFile();

            spc.Load(info.OriginArchivePath);
            string fullSubfilePath = Path.Combine(tempDir, translatedFilenames[0]);

            spc.InsertSubfile(fullSubfilePath);
            spc.Save(info.OriginArchivePath);
        }
Exemplo n.º 2
0
        private void Insert(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                DefaultExt  = ".SPC",
                Filter      = "SPC Archive (*.SPC)|*.SPC|All Files (*.*)|*.*",
                Multiselect = true
            };

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

            statusText.Text = $"Inserting {dialog.FileNames.Length} files...";
            foreach (var filename in dialog.FileNames)
            {
                currentSPC.InsertSubfile(filename);
            }
            statusText.Text = $"Sucessfully inserted {dialog.FileNames.Length} files.";
            RefreshListViewItems();
        }