Ejemplo n.º 1
0
        private MsiDataContainer(LessIO.Path msiDatabaseFilePath)
        {
            using var db = new Database(msiDatabaseFilePath.PathString, DatabaseOpenMode.ReadOnly);
            this.files   = MsiFile.CreateMsiFilesFromMSI(db);

            this.tables = db.Tables.OrderBy(tab => tab.Name).Select(table => TableWithData.Create(db, table.Name)).ToArray();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a list of <see cref="MsiFile"/> objects from the specified database.
 /// </summary>
 public static MsiFile[] CreateMsiFilesFromMSI(LessIO.Path msiDatabaseFilePath)
 {
     using (var db = new Database(msiDatabaseFilePath.PathString, DatabaseOpenMode.ReadOnly))
     {
         return(CreateMsiFilesFromMSI(db));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves this <see cref="FileEntryGraph"/> to the specified file.
        /// </summary>
        /// <param name="file">The file that this graph will be saved to.</param>
        public void Save(LessIO.Path file)
        {
            //save it as csv:
            if (file.Exists)
            {
                LessIO.FileSystem.RemoveFile(file);
            }
            using (var f = file.CreateText())
            {
                f.WriteLine("Path,Size,CreationTime,LastWriteTime,Attributes");

                foreach (var e in this.Entries)
                {
                    f.Write(e.Path);
                    f.Write(",");
                    f.Write(e.Size);
                    f.Write(",");
                    f.Write(SerializeDate(e.CreationTime));
                    f.Write(",");
                    f.Write(SerializeDate(e.LastWriteTime));
                    f.Write(",");
                    f.Write(SerializeAttributes(e.Attributes));
                    f.WriteLine();
                }
            }
        }
Ejemplo n.º 4
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
            if (Presenter.SelectedMsiFile == null)
            {
                return;
            }
            LessIO.Path msiFile = new LessIO.Path(Presenter.SelectedMsiFile.FullName);

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

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

            btnExtract.Enabled = false;
            using (var progressDialog = BeginShowingProgressDialog())
            {
                try
                {
                    string outputDir = 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;
        }
Ejemplo n.º 5
0
 public void LongExtractionPath()
 {
     var msiFileName = "python-2.7.3.msi";
     LessIO.Path outputDir = new LessIO.Path(@"long-directory-name\very\unusually\long\directory\name\with\cream\sugar\and\chocolate\topping\long-directory-name\very\unusually\long\directory\name\with\cream\sugar\and\chocolate\toppinglong-directory-name\very\unusually\long\directory\name\with\cream\sugar\and\chocolate\topping");
     /* Since System.IO doesn't support long path names, supporting 
      comparison of output as is done for other tests is a big effort. 
      So we ignore output only for this test.
      As long as we don't get an error we're happy.
     */
     var returnFileEntryGraph = false;
     var actualFileEntries = ExtractFilesFromMsi(msiFileName, null, outputDir, returnFileEntryGraph);
 }
Ejemplo n.º 6
0
        public void LongExtractionPath()
        {
            var msiFileName = "python-2.7.3.msi";

            LessIO.Path outputDir = new LessIO.Path(@"long-directory-name\very\unusually\long\directory\name\with\cream\sugar\and\chocolate\topping\long-directory-name\very\unusually\long\directory\name\with\cream\sugar\and\chocolate\toppinglong-directory-name\very\unusually\long\directory\name\with\cream\sugar\and\chocolate\topping");

            /* Since System.IO doesn't support long path names, supporting
             * comparison of output as is done for other tests is a big effort.
             * So we ignore output only for this test.
             * As long as we don't get an error we're happy.
             */
            var returnFileEntryGraph = false;
            var actualFileEntries    = ExtractFilesFromMsi(msiFileName, null, outputDir, returnFileEntryGraph);
        }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads a <see cref="FileEntryGraph"/> from the specified file.
        /// </summary>
        /// <param name="file">The file to load a new <see cref="FileEntryGraph"/> from.</param>
        /// <param name="forFileName">The initial value for the returned objects <see cref="FileEntryGraph.ForFileName"/></param>
        /// <returns>The newly loaded <see cref="FileEntryGraph"/>.</returns>
        public static FileEntryGraph Load(LessIO.Path file, string forFileName)
        {
            var graph = new FileEntryGraph(forFileName);

            using (var f = System.IO.File.OpenText(file.PathString))
            {
                f.ReadLine();//headings
                while (!f.EndOfStream)
                {
                    var line = f.ReadLine().Split(',');
                    if (line.Length != 5)
                    {
                        throw new IOException("Expected 5 fields!");
                    }

                    /* FIX for github issue #23:
                     * The problem was that old ExpectedOutput files were all prefixed with C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\<msiFileNameWithoutExtension> (something like C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\NUnit-2.5.2.9222\SourceDir\PFiles\NUnit 2.5.2\fit-license.txt)
                     * We need to remove Since we don't reasonably know what the original msi filename was, we do know it was the subdirectory of C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\. So we should remove C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\ and the next subdirectory from the path.
                     * HACK: A better fix would undoubtedly be to cleanup those old file swith code like this and remove this hack from this code forever!
                     */
                    var          path        = line[0];
                    const string oldRootPath = @"C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\";
                    if (path.StartsWith(oldRootPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //this is an old file that would trigger github issue #23, so we'll fix it here...
                        // first remove the old root path:
                        path = path.Substring(oldRootPath.Length);
                        // now romove the msi filename (which we don't know, but we know it is the next subdirectory of the old root):
                        var lengthOfSubDirectoryName = path.IndexOf('\\', 0);
                        path = path.Substring(lengthOfSubDirectoryName);
                    }
                    graph.Add(new FileEntry(path, Int64.Parse(line[1]), DeserializeDate(line[2]), DeserializeDate(line[3]), DeserializeAttributes(line[4])));
                }
            }
            return(graph);
        }
Ejemplo n.º 9
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
            if (Presenter.SelectedMsiFile == null)
                return;
			LessIO.Path msiFile = new LessIO.Path(Presenter.SelectedMsiFile.FullName);

			if (folderBrowser.SelectedPath == null || folderBrowser.SelectedPath.Length <= 0)
				folderBrowser.SelectedPath = msiFile.Parent.PathString;

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

			btnExtract.Enabled = false;
			using (var progressDialog = BeginShowingProgressDialog())
			{
				try
				{
					string outputDir = 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;
		}
Ejemplo n.º 10
0
        public void WithPrefixShouldIncludeUNCPrefix()
        {
            var p = new LessIO.Path(@"\\ComputerName\SharedFolder");

            Assert.Equal(Win32LongPathPrefixUNC + @"ComputerName\SharedFolder", p.WithWin32LongPathPrefix());
        }
Ejemplo n.º 11
0
        public void UNCLongFormPathsShouldBeRooted()
        {
            var p = new LessIO.Path(@"\\?\UNC\server\thing\stuff");

            Assert.True(p.IsPathRooted);
        }
Ejemplo n.º 12
0
 public void PathWithDoubleSeperatorShouldStillWorkInFileSystem()
 {
     LessIO.Path p = GetTestPath(@"oneLevel\\test.txt");
     Assert.True(FileSystem.Exists(p), "Path with duplicate seperator should still be found");
 }
Ejemplo n.º 13
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());
		}
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a <see cref="MsiDataContainer"/> object from the specified database.
 /// This contains a list of the files in the database, and all tables.
 /// </summary>
 public static MsiDataContainer CreateFromPath(LessIO.Path msiDatabaseFilePath)
 {
     return(new MsiDataContainer(msiDatabaseFilePath));
 }