Exemplo n.º 1
0
	public static int Main(string[] args)
	{
		if(!(args.Length == 2 || args.Length == 3))
		{
			Usage(Console.Out);
			return -1;
		}

		string msiFile = args[0];

		string option = args[1].ToLowerInvariant();
		if(option.StartsWith("-", StringComparison.Ordinal)) option = "/" + option.Substring(1);

		string[] fileNames = null;
		if(args.Length == 3)
		{
			fileNames = args[2].Split(',');
		}

		try
		{
			switch(option)
			{
				case "/l":
					using(InstallPackage pkg = new InstallPackage(msiFile, DatabaseOpenMode.ReadOnly))
					{
						pkg.Message += new InstallPackageMessageHandler(Console.WriteLine);
						IEnumerable<string> fileKeys = (fileNames != null ? FindFileKeys(pkg, fileNames) : pkg.Files.Keys);

						foreach(string fileKey in fileKeys)
						{
							Console.WriteLine(pkg.Files[fileKey]);
						}
					}
					break;

				case "/x":
					using(InstallPackage pkg = new InstallPackage(msiFile, DatabaseOpenMode.ReadOnly))
					{
						pkg.Message += new InstallPackageMessageHandler(Console.WriteLine);
						ICollection<string> fileKeys = FindFileKeys(pkg, fileNames);

						pkg.ExtractFiles(fileKeys);
					}
					break;

				case "/u":
					using(InstallPackage pkg = new InstallPackage(msiFile, DatabaseOpenMode.Transact))
					{
						pkg.Message += new InstallPackageMessageHandler(Console.WriteLine);
                        ICollection<string> fileKeys = FindFileKeys(pkg, fileNames);

						pkg.UpdateFiles(fileKeys);
						pkg.Commit();
					}
					break;

				default:
                    Usage(Console.Out);
					return -1;
			}
		}
		catch(InstallerException iex)
		{
			Console.WriteLine("Error: " + iex.Message);
			return iex.ErrorCode != 0 ? iex.ErrorCode : 1;
		}
		catch(FileNotFoundException fnfex)
		{
			Console.WriteLine(fnfex.Message);
			return 2;
		}
		catch(Exception ex)
		{
			Console.WriteLine("Error: " + ex.Message);
			return 1;
		}
		return 0;
	}
Exemplo n.º 2
0
        private void MergeCubes(InstallPackage db)
        {
            if (!this.NoDefault)
            {
                string darice = ComponentSearcher.Find(ComponentSearcher.KnownComponent.Darice);
                if (!string.IsNullOrEmpty(darice))
                {
                    this.MergeCube(db, darice);
                }
                else
                {
                    this.WriteWarning(Resources.Error_DefaultCubNotFound);
                }
            }

            if (null != this.AdditionalCube)
            {
                foreach (string cube in this.ResolveFiles(this.AdditionalCube))
                {
                    this.MergeCube(db, cube);
                }

                db.Commit();
            }
        }
Exemplo n.º 3
0
		public override bool GetDiff(string diffInput1, string diffInput2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
		{
			bool difference = false;

			InstallPackage db1, db2;
			if(IsMspPatch(diffInput1))
			{
				string patchTargetDbFile = GetPatchTargetOption(options);
				if(patchTargetDbFile == null) patchTargetDbFile = diffInput2;
				string tempPatchedDbFile = Path.GetTempFileName();
				File.Copy(patchTargetDbFile, tempPatchedDbFile, true);
				File.SetAttributes(tempPatchedDbFile, File.GetAttributes(tempPatchedDbFile) & ~System.IO.FileAttributes.ReadOnly);
				db1 = new InstallPackage(tempPatchedDbFile, DatabaseOpenMode.Direct);
				db1.ApplyPatch(new PatchPackage(diffInput1), null);
				db1.Commit();
			}
			else
			{
				db1 = new InstallPackage(diffInput1, DatabaseOpenMode.ReadOnly);
			}
			if(IsMspPatch(diffInput2))
			{
				string patchTargetDbFile = GetPatchTargetOption(options);
				if(patchTargetDbFile == null) patchTargetDbFile = diffInput1;
				string tempPatchedDbFile = Path.GetTempFileName();
				File.Copy(patchTargetDbFile, tempPatchedDbFile, true);
				File.SetAttributes(tempPatchedDbFile, File.GetAttributes(tempPatchedDbFile) & ~System.IO.FileAttributes.ReadOnly);
				db2 = new InstallPackage(tempPatchedDbFile, DatabaseOpenMode.Direct);
				db2.ApplyPatch(new PatchPackage(diffInput2), null);
				db2.Commit();
			}
			else
			{
				db2 = new InstallPackage(diffInput2, DatabaseOpenMode.ReadOnly);
			}

			if(GetSummaryInfoDiff(db1, db2, options, diffOutput, linePrefix, diffFactory)) difference = true;
			if(GetDatabaseDiff(db1, db2, options, diffOutput, linePrefix, diffFactory)) difference = true;
			if(GetStreamsDiff(db1, db2, options, diffOutput, linePrefix, diffFactory)) difference = true;

			db1.Close();
			db2.Close();

			try
			{
				if(IsMspPatch(diffInput1)) File.Delete(db1.FilePath);
				if(IsMspPatch(diffInput1)) File.Delete(db2.FilePath);
			}
			catch(IOException)
			{
				#if DEBUG
				Console.WriteLine("Could not delete temporary files {0} and {1}", db1.FilePath, db2.FilePath);
				#endif
			}

			if(IsMspPatch(diffInput1) && IsMspPatch(diffInput2))
			{
				Database dbp1 = new Database(diffInput1, DatabaseOpenMode.ReadOnly);
				Database dbp2 = new Database(diffInput2, DatabaseOpenMode.ReadOnly);

				if(GetStreamsDiff(dbp1, dbp2, options, diffOutput, linePrefix, diffFactory)) difference = true;
				dbp1.Close();
				dbp2.Close();
			}

			return difference;
		}
Exemplo n.º 4
0
        /// <summary>
        /// Applies any applicable transforms from <see cref="Patch"/> and <see cref="Transform"/> to the given package.
        /// </summary>
        /// <param name="db">The <see cref="InstallPackage"/> database to which applicable transforms are applied.</param>
        protected void ApplyTransforms(InstallPackage db)
        {
            // Apply transforms first since they likely apply to the unpatched product.
            if (0 < this.Transform.Count())
            {
                this.Transform = this.ResolveFiles(this.Transform).ToArray();

                foreach (string path in this.Transform)
                {
                    try
                    {
                        db.ApplyTransform(path, PatchApplicator.IgnoreErrors);
                        db.ApplyTransform(path, PatchApplicator.IgnoreErrors | TransformErrors.ViewTransform);
                    }
                    catch (InstallerException ex)
                    {
                        using (var pse = new PSInstallerException(ex))
                        {
                            if (null != pse.ErrorRecord)
                            {
                                base.WriteError(pse.ErrorRecord);
                            }
                        }
                    }
                }

                db.Commit();
            }

            // Apply applicable patch transforms.
            if (0 < this.Patch.Count())
            {
                this.Patch = this.ResolveFiles(this.Patch).ToArray();

                var applicator = new PatchApplicator(db);
                foreach (string path in this.Patch)
                {
                    applicator.Add(path);
                }

                applicator.InapplicablePatch += (source, args) =>
                {
                    var message = string.Format(CultureInfo.CurrentCulture, Resources.Error_InapplicablePatch, args.Patch, args.Product);
                    base.WriteVerbose(message);
                };

                // The applicator will commit the changes.
                applicator.Apply();
            }
        }