Skip to content

Commit

Permalink
- Issue #538: impossible rename file during installation; added `File…
Browse files Browse the repository at this point in the history
….TargetFileName`

- Fixed problem with locating latest (v3.11) WiX Toolset installed
  • Loading branch information
oleg-shilo committed Nov 27, 2018
1 parent eb3d297 commit c48da69
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 48 deletions.
14 changes: 8 additions & 6 deletions Source/src/WixSharp.Samples/Wix# Samples/Install Files/setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ class Script
{
static public void Main(string[] args)
{
var project =
File f;
var project =
new Project("MyProduct",
new Dir(new Id("MY_INSTALLDIR"), @"%ProgramFiles%\My Company\My Product",
new File("MyApp_file".ToId(),
f = new File("MyApp_file".ToId(),
@"Files\Bin\MyApp.exe",
new FileAssociation("cstm", "application/custom", "open", "\"%1\"")
{
Advertise = true,
Icon = "wixsharp.ico"
}
),
})
{
TargetFileName = "app.exe"
},
new Dir(@"Docs\Manual",
new File(@"Files\Docs\Manual.txt")
{
Expand Down Expand Up @@ -61,5 +64,4 @@ static void Compiler_WixSourceGenerated(XDocument document)
.Single(x => x.HasAttribute("Id", value => value.Contains("MyApp_file")))
.AddElement("CreateFolder/Permission", "User=Everyone;GenericAll=yes");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static public void Main(string[] args)
project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default;
project.MajorUpgradeStrategy.RemoveExistingProductAfter = Step.InstallInitialize;
project.BeforeInstall += project_BeforeInstall;
project.PreserveTempFiles = true;

Compiler.BuildMsi(project, "setup.1.msi");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static public void Main()
};

project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");
// project.PreserveTempFiles = true;
project.PreserveTempFiles = true;

Compiler.BuildMsi(project);
}
Expand Down
33 changes: 32 additions & 1 deletion Source/src/WixSharp/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,37 @@ public static Dictionary<string, string> MergeReplace(this Dictionary<string, st
return map;
}

/// <summary>
/// Gets the value by specified key. Return <c>null</c> if the dictionary does not contains
/// the specified key.
/// </summary>
/// <typeparam name="T1">The type of the 1.</typeparam>
/// <typeparam name="T2">The type of the 2.</typeparam>
/// <param name="map">The map.</param>
/// <param name="key">The key.</param>
/// <returns></returns>
public static T2 Get<T1, T2>(this Dictionary<T1, T2> map, T1 key) where T2 : class
=> map.ContainsKey(key) ? map[key] : null;

/// <summary>
/// Sets the adds or sets key/value pair. <para>Removes the key/value pair if the specified
/// value is <c>null</c>.</para>
/// </summary>
/// <typeparam name="T1">The type of the 1.</typeparam>
/// <typeparam name="T2">The type of the 2.</typeparam>
/// <param name="map">The map.</param>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
public static Dictionary<T1, T2> Set<T1, T2>(this Dictionary<T1, T2> map, T1 key, T2 value) where T2 : class
{
if (value != null)
map[key] = value;
else if (map.ContainsKey(key))
map.Remove(key);
return map;
}

/// <summary>
/// Clones the specified collection.
/// </summary>
Expand Down Expand Up @@ -2155,7 +2186,7 @@ static internal bool IsCancelRequestedFromUI(this Session session)

/// <summary>
/// <para>
/// Gets the main window of the <c>msiexec.exe</c> process that has 'MainWindowTitle' containing the name of the product being installed.
/// Gets the main window of the <c>msiexec.exe</c> process that has 'MainWindowTitle' containing the name of the product being installed.
/// </para>
/// This method is a convenient way to display message box from a custom action with properly specified parent window.
/// </summary>
Expand Down
46 changes: 25 additions & 21 deletions Source/src/WixSharp/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void AddItems(WixEntity[] items)
/// Set this field to the properly initialized instance of <see cref="ServiceInstaller"/> if the file is a windows service module.
/// </summary>
public IGenericEntity ServiceInstaller = null;

/// <summary>
/// Collection of the contained <see cref="IISVirtualDir"/>s.
/// </summary>
Expand All @@ -193,13 +193,13 @@ void AddItems(WixEntity[] items)
/// <summary>
/// Controls if an existing file should be overwritten during the installation.
/// By default MSI runtime does not install the file if it already exists at the
/// deployment destination on the target system. This field allows changing
/// this behaviour and ensuring that a file installed always even when existed
/// prior the installation.
/// <para>If this field is set to <c>true</c> the WixSharp injects the following
/// element into the file's parent component.
/// deployment destination on the target system. This field allows changing
/// this behaviour and ensuring that a file installed always even when existed
/// prior the installation.
/// <para>If this field is set to <c>true</c> the WixSharp injects the following
/// element into the file's parent component.
/// <pre>&lt;RemoveFile Id="Remove_Filetxt" Name="File.txt" On="install" /&gt;</pre>
///
///
/// </para>
/// </summary>
public bool OverwriteOnInstall = false;
Expand Down Expand Up @@ -229,20 +229,24 @@ void AddItems(WixEntity[] items)
/// </value>
public bool? NeverOverwrite
{
get
{
if (attributesBag.ContainsKey("Component:NeverOverwrite"))
return (attributesBag["Component:NeverOverwrite"] == "yes");
else
return null;
}
set
{
if (value.HasValue)
attributesBag["Component:NeverOverwrite"] = value.Value.ToYesNo();
else if (attributesBag.ContainsKey("Component:NeverOverwrite"))
attributesBag.Remove("Component:NeverOverwrite");
}
get => attributesBag.Get("Component:NeverOverwrite") == "yes";

set => attributesBag.Set("Component:NeverOverwrite", value.ToNullOrYesNo());
}

/// <summary>
/// Gets or sets the custom name of the target file. By default the name is
/// the same name as the source file. IE file <c>c:\files\app.exe</c> will be installed
/// as <c>app.exe</c>.
/// </summary>
/// <value>
/// The name of the target file.
/// </value>
public string TargetFileName
{
get => attributesBag.Get("Name");

set => attributesBag.Set("Name", value);
}
}
}
25 changes: 9 additions & 16 deletions Source/src/WixSharp/RegValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,25 @@ public RegistryHive(string value) : base(value) { }
/// The classes root. Equivalent of `HKCR`.
/// </summary>
public static RegistryHive ClassesRoot = new RegistryHive("HKCR");

/// <summary>
/// The current user. Equivalent of `HKCU`.
/// </summary>
public static RegistryHive CurrentUser = new RegistryHive("HKCU");

/// <summary>
/// The local machine. Equivalent of `HKLM`.
/// </summary>
public static RegistryHive LocalMachine = new RegistryHive("HKLM");

/// <summary>
/// The users. Equivalent of `HKU`.
/// </summary>
public static RegistryHive Users = new RegistryHive("HKU");

/// <summary>
/// Defines ”HKMU” value, which makes it so the registry entry will appear in HKLM
/// when a per-machine install is run and in HKCU when a per-user install us run.
/// Defines ”HKMU” value, which makes it so the registry entry will appear in HKLM
/// when a per-machine install is run and in HKCU when a per-user install us run.
/// </summary>
public static RegistryHive LocalMachineOrUsers = new RegistryHive("HKMU");
}
Expand Down Expand Up @@ -296,20 +300,9 @@ public RegValue(Id id, Feature feature, RegistryHive root, string key, string na
/// </value>
public bool? NeverOverwrite
{
get
{
if (attributesBag.ContainsKey("Component:NeverOverwrite"))
return (attributesBag["Component:NeverOverwrite"] == "yes");
else
return null;
}
set
{
if (value.HasValue)
attributesBag["Component:NeverOverwrite"] = value.Value.ToYesNo();
else if (attributesBag.ContainsKey("Component:NeverOverwrite"))
attributesBag.Remove("Component:NeverOverwrite");
}
get => attributesBag.Get("Component:NeverOverwrite") == "yes";

set => attributesBag.Set("Component:NeverOverwrite", value.ToNullOrYesNo());
}

internal string RegValueString
Expand Down
7 changes: 4 additions & 3 deletions Source/src/WixSharp/Utilities/WixBinLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static string FindWixBinLocation()
{
return Path.GetFullPath(msBuildArgument);
}

// Now check to see if the environment variable was set
var environmentVar = Environment.GetEnvironmentVariable("WIXSHARP_WIXDIR");
if (environmentVar.IsNotEmpty() && Directory.Exists(environmentVar))
Expand All @@ -53,12 +53,13 @@ public static string FindWixBinLocation()
return Path.GetFullPath(wixInstallDir.PathJoin("bin"));
}

// C:\Program Files (x86)\WiX Toolset v3.11\bin\candle.exe
// Try a secondary location
wixInstallDir = Directory.GetDirectories(Utils.ProgramFilesDirectory, "WiX Toolset v3*")
.Order()
.LastOrDefault();

if (!wixInstallDir.IsNotEmpty() && Directory.Exists(wixInstallDir))
if (wixInstallDir.IsNotEmpty() && Directory.Exists(wixInstallDir))
{
return Path.GetFullPath(wixInstallDir.PathJoin("bin"));
}
Expand All @@ -70,4 +71,4 @@ public static string FindWixBinLocation()
"downloading Wix# suite or by adding WixSharp.wix.bin NuGet package to your project.");
}
}
}
}

0 comments on commit c48da69

Please sign in to comment.