Esempio n. 1
0
        private void OpenMsiFile(string filename)
        {
            try
            {
                msiFile = new MsiFile(filename);

                dtGrvProperties.Rows.Clear();
                dtGrvProperties.Columns.Clear();
                cmbBxPropertyNames.Items.Clear();

                SortedDictionary <string, Table> tables = msiFile.GetAllTables();
                int propertyIndex = -1;

                foreach (KeyValuePair <string, Table> pair in tables)
                {
                    if (pair.Value.IsOrdered)
                    {
                        int index = cmbBxPropertyNames.Items.Add(pair.Value);
                        if (String.Compare(pair.Value.Name, "Property", true) == 0)
                        {
                            propertyIndex = index;
                        }
                    }
                }
                if (propertyIndex != -1)
                {
                    cmbBxPropertyNames.SelectedIndex = propertyIndex;
                    dtGrvProperties.Sort(dtGrvProperties.Columns[0], ListSortDirection.Ascending);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Displays the list of files in the extract tab.
        /// </summary>
        /// <param name="msidb">The msi database.</param>
        private void ViewFiles(Database msidb)
        {
            if (msidb == null)
            {
                return;
            }

            using (new DisposableCursor(View))
            {
                try
                {
                    Status("");

                    MsiFile[]         dataItems = MsiFile.CreateMsiFilesFromMSI(msidb);
                    MsiFileItemView[] viewItems = Array.ConvertAll <MsiFile, MsiFileItemView>(dataItems,
                                                                                              inItem => new MsiFileItemView(inItem)
                                                                                              );
                    var fileDataSource = new SortableBindingList <MsiFileItemView>(viewItems);
                    View.fileGrid.DataSource = fileDataSource;
                    View.AutoSizeFileGridColumns();
                    Status(fileDataSource.Count + " files found.");
                }
                catch (Exception eUnexpected)
                {
                    Error(string.Concat("Cannot view files:", eUnexpected.Message), eUnexpected);
                }
            }
        }
Esempio n. 3
0
 private void ResolveFile(MsiFile file) => file.FullPath = _directories[file.DirectoryId].FullPath + "/" + file.Name;
Esempio n. 4
0
 public MsiFileItemView(MsiFile msiDataFile)
 {
     _file = msiDataFile;
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
 private void ResolveFile(MsiFile file)
 {
     file.FullPath = _directories[file.DirectoryId].FullPath + "/" + file.Name;
 }