示例#1
0
        private void btnExtract_Click(object sender, EventArgs e)
        {
            //TODO: Refactor to Presenter
            var selectedFiles = new List <MsiFile>();

            if (fileGrid.SelectedRows.Count == 0)
            {
                ShowUserMessageBox("Please select some or all of the files to extract them.");
                return;
            }

            //TODO: Refactor to Presenter
            FileInfo msiFile = Presenter.SelectedMsiFile;

            if (msiFile == null)
            {
                return;
            }

            if (folderBrowser.SelectedPath == null || folderBrowser.SelectedPath.Length <= 0)
            {
                folderBrowser.SelectedPath = msiFile.DirectoryName;
            }

            if (DialogResult.OK != folderBrowser.ShowDialog(this))
            {
                return;
            }

            btnExtract.Enabled = false;
            using (var progressDialog = BeginShowingProgressDialog())
            {
                try
                {
                    DirectoryInfo outputDir = new DirectoryInfo(folderBrowser.SelectedPath);
                    foreach (DataGridViewRow row in fileGrid.SelectedRows)
                    {
                        MsiFileItemView fileToExtract = (MsiFileItemView)row.DataBoundItem;
                        selectedFiles.Add(fileToExtract.File);
                    }


                    var filesToExtract = selectedFiles.ToArray();
                    Wixtracts.ExtractFiles(msiFile, outputDir, filesToExtract,
                                           new AsyncCallback(progressDialog.UpdateProgress));
                }
                catch (Exception err)
                {
                    MessageBox.Show(this,
                                    "The following error occured extracting the MSI: " + err.ToString(), "MSI Error!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error
                                    );
                }
            }
            btnExtract.Enabled = true;
        }
示例#2
0
 private static string GetFromMsi(string nameOfFileToCheck, string zipPath)
 {
     Wixtracts.ExtractFiles(zipPath, Path.GetDirectoryName(zipPath));
     foreach (string file in Directory.GetFiles(Path.GetDirectoryName(zipPath), "*", SearchOption.AllDirectories))
     {
         if (Path.GetFileName(file).Equals(nameOfFileToCheck, StringComparison.InvariantCultureIgnoreCase))
         {
             return(TelimenaVersionReader.Read(file, VersionTypes.FileVersion));
         }
     }
     return(null);
 }
示例#3
0
        /// <summary>
        /// Extracts all files contained in the specified .msi file into the specified output directory.
        /// </summary>
        /// <param name="msiFileName">The path of the specified MSI file.</param>
        /// <param name="outDirName">The directory to extract to. If empty it will use the current directory.</param>
        /// <param name="filesToExtract">The files to be extracted from the msi. If empty all files will be extracted.</param>
        public static void DoExtraction(string msiFileName, string outDirName, List <string> filesToExtract)
        {
            if (string.IsNullOrEmpty(outDirName))
            {
                outDirName = Path.GetFileNameWithoutExtension(msiFileName);
            }
            EnsureFileRooted(ref msiFileName);
            EnsureFileRooted(ref outDirName);

            var msiFile = new LessIO.Path(msiFileName);

            Console.WriteLine("Extracting \'" + msiFile + "\' to \'" + outDirName + "\'.");

            Wixtracts.ExtractFiles(msiFile, outDirName, filesToExtract.ToArray());
        }
示例#4
0
        private void ExtractCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (FileListView.SelectedItems.Count == 0)
            {
                // Shouldn't happen (due to ExtractCommand_CanExecute), but check anyway.
                return;
            }

            AppModel model = (AppModel)DataContext;

            using var browserDialog = new FolderBrowserDialog
                  {
                      ShowNewFolderButton    = true,
                      UseDescriptionForTitle = true,
                      Description            = "Select folder to extract to",
                  };

            Window window = Window.GetWindow(this);

            if (!browserDialog.ShowDialog(window))
            {
                return;
            }

            MsiFile[] filesToExtract = new MsiFile[FileListView.SelectedItems.Count];
            FileListView.SelectedItems.CopyTo(filesToExtract, 0);

            string text = $"Extracting {filesToExtract.Length} files...";

            if (filesToExtract.Length == 1)
            {
                text = "Extracting one file...";
            }

            using var progressDialog = new ProgressDialog
                  {
                      MinimizeBox      = false,
                      WindowTitle      = "Extracting Files...",
                      CancellationText = "Canceling...",
                      UseCompactPathsForDescription = true,
                      Text = text,
                  };

            void DoWork(object?sender, DoWorkEventArgs e)
            {
                if (string.IsNullOrEmpty(model.MsiPath))
                {
                    throw new InvalidOperationException("MsiPath not set, we should not have gotten here");
                }

                try
                {
                    Wixtracts.ExtractFiles(new LessIO.Path(model.MsiPath), browserDialog.SelectedPath, filesToExtract, (arg) =>
                    {
                        var progress = (Wixtracts.ExtractionProgress)arg;
                        if (progressDialog.CancellationPending)
                        {
                            throw new OperationCanceledException();
                        }

                        int percentProgress;
                        string message;

                        if (progress.Activity == Wixtracts.ExtractionActivity.Initializing)
                        {
                            message         = "Initializing extraction";
                            percentProgress = 0;
                        }
                        else if (progress.Activity == Wixtracts.ExtractionActivity.Uncompressing)
                        {
                            message         = "Decompressing CAB file";
                            percentProgress = 0;
                        }
                        else if (progress.Activity == Wixtracts.ExtractionActivity.ExtractingFile)
                        {
                            double fraction = (double)progress.FilesExtractedSoFar / (double)progress.TotalFileCount;
                            percentProgress = (int)Math.Round(fraction * 100);
                            message         = progress.CurrentFileName;
                        }
                        else if (progress.Activity == Wixtracts.ExtractionActivity.Complete)
                        {
                            message         = "Finishing up";
                            percentProgress = 100;
                        }
                        else
                        {
                            throw new ArgumentException("Invalid ExtractionActivity");
                        }

                        this.Dispatcher.Invoke(() => progressDialog.ReportProgress(percentProgress, null, message));
                    });
                }
                catch (System.IO.FileNotFoundException ex)
                {
#pragma warning disable SA1130 // Use lambda syntax (not valid syntax here for some reason)
                    Dispatcher.BeginInvoke((Action) delegate
#pragma warning restore SA1130 // Use lambda syntax
                    {
                        TaskDialogPage page = new TaskDialogPage();
                        page.Instruction    = "Cannot extract the specified files.";
                        page.Text           = $"The file \"{ex.FileName}\" was not found.";
                        page.Icon           = TaskDialogIcon.Get(TaskDialogStandardIcon.Error);
                        page.StandardButtons.Add(TaskDialogResult.Close);
                        page.AllowCancel = true;

                        TaskDialog dialog = new TaskDialog();
                        dialog.Page       = page;
                        dialog.Show(window);
                    });

                    return;
                }
                catch (Exception ex)
                {
                    // Rethrow the exception on the main thread.
                    Dispatcher.Invoke(() => throw ex);
                }
            }

            progressDialog.DoWork += DoWork;
            progressDialog.ShowDialog(window);
        }