Skip to content

Commit

Permalink
Documentation, cleanup...
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Apr 14, 2018
1 parent 371290e commit 95b3c6a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions Source/src/WixSharp.Samples/Support/testpad/setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static void Issue_298()
GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b")
};

project.AddRegValue(new RegValue(RegistryHive.LocalMachine, @"Software\test", "foo_value", "bar") { Win64 = true });
project.AddRegValue(new RegValue(RegistryHive.LocalMachine, @"Software\test", "foo_value", "bar") { Win64 = false });

// Compiler.LightOptions += " -sice:ICE80";
Expand Down
4 changes: 2 additions & 2 deletions Source/src/WixSharp.Samples/Wix# Samples/Extensions/setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public class RemoveFolderEx : WixEntity, IGenericEntity
[Xml]
public new string Id
{
get => base.Id;
set => base.Id = value;
get { return base.Id; }
set { base.Id = value; }
}

/// <summary>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ static public void Main(string[] args)

//Note if the property 'PASSWORD' is not preserved as deferred then it will not be available
//from the Project_AfterInstall, which is a deferred custom action.
AutoElements.LagacyDummyDirAlgorithm = true;

var project = new ManagedProject("ManagedSetup",
new User
{
Expand Down
13 changes: 13 additions & 0 deletions Source/src/WixSharp.Samples/WixSharp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,19 @@
Forces all <see cref="T:WixSharp.Condition"/> values to be always encoded as CDATA.
</summary>
</member>
<member name="F:WixSharp.AutoElements.LegacyDummyDirAlgorithm">
<summary>
Flag indicating if the legacy algorithm should be used for handling setups with no directories
to be installed but only non-file system components (e.g. RegKey, User, Firewall exceptions).
<para>The algorithm used in early versions of WixSharp (legacy algorithm) injects a dummy
directory into the setup definition so it satisfies the MSI constraint that every component must
belong to a directory. As many other rules this one has no practical value and rather reflection
of the outdated (~20 years ago) deployment approaches.</para>
<para>The current algorithm also ensures the that there is a XML directory to host the components.
However instead of custom (dummy) directory it inserts 'ProgramFilesFolder'. This way MSI constraint
is satisfied and yet there is no impact on the target file system.</para>
</summary>
</member>
<member name="F:WixSharp.AutoElements.DisableAutoUserProfileRegistry">
<summary>
Disables automatic insertion of user profile registry elements.
Expand Down
15 changes: 13 additions & 2 deletions Source/src/WixSharp/AutoElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,18 @@ public static class AutoElements
/// </summary>
public static bool ForceCDataForConditions = false;

public static bool LagacyDummyDirAlgorithm = false;
/// <summary>
/// Flag indicating if the legacy algorithm should be used for handling setups with no directories
/// to be installed but only non-file system components (e.g. RegKey, User, Firewall exceptions).
/// <para>The algorithm used in early versions of WixSharp (legacy algorithm) injects a dummy
/// directory into the setup definition so it satisfies the MSI constraint that every component must
/// belong to a directory. As many other rules this one has no practical value and rather reflection
/// of the outdated (~20 years ago) deployment approaches.</para>
/// <para>The current algorithm also ensures the that there is a XML directory to host the components.
/// However instead of custom (dummy) directory it inserts 'ProgramFilesFolder'. This way MSI constraint
/// is satisfied and yet there is no impact on the target file system.</para>
/// </summary>
public static bool LegacyDummyDirAlgorithm = false;

/// <summary>
/// Disables automatic insertion of user profile registry elements.
Expand Down Expand Up @@ -549,7 +560,7 @@ internal static void HandleEmptyDirectories(XDocument doc)
//'EMPTY DIRECTORY' support processing section
foreach (XElement item in componentsWithNoFiles)
{
// Ridiculous MSI constrains:
// Ridiculous MSI constraints:
// * you cannot install install empty folders
// - workaround is to insert empty component with CreateFolder element
// * if Component+CreateFolder element is inserted the folder will not be removed on uninstall
Expand Down
14 changes: 14 additions & 0 deletions Source/src/WixSharp/CommonTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,20 @@ static public XElement CreateParentComponent(this WixEntity entity)
return new XElement("Component").AddAttributes($@"Id={entity.Id}; Guid={WixGuid.NewGuid(entity.Id)}");
}

static public XElement FistProgramFilesDir(this XElement element)
{
XElement dir = element.FindFirst("Directory");
while (dir != null)
{
if (dir.HasAttribute("Name", x => x.StartsWith("ProgramFiles") && x.EndsWith("Folder")))
return dir;

dir = dir.Elements("Directory").FirstOrDefault();
}

return null;
}

/// <summary>
/// Installs the windows service. It uses InstallUtil.exe to complete the actual installation/uninstallation.
/// During the run for the InstallUtil.exe console window is hidden.
Expand Down
8 changes: 4 additions & 4 deletions Source/src/WixSharp/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ public static XDocument GenerateWixProj(Project project)
if (!project.LicenceFile.IsEmpty())
{
if (!AllowNonRtfLicense && !project.LicenceFile.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
throw new ApplicationException("License file must have 'rtf' file extension. Specify 'Compiler.AllowNonRtfLicense=true' to overcome this constrain.");
throw new ApplicationException("License file must have 'rtf' file extension. Specify 'Compiler.AllowNonRtfLicense=true' to overcome this constraint.");

product.Add(
new XElement("WixVariable",
Expand Down Expand Up @@ -1450,7 +1450,7 @@ static string AutoAssignInstallDirId(Dir[] wDirs, string dirId)
Compiler.OutputWriteLine($"WARNING: Special folder directory ID '{firstDirWithItems.Id}' has been reset to '{dirId}'.\n" +
"If it was not intended disable auto assignment by setting 'Compiler.AutoGeneration.InstallDirDefaultId' to null.\n" +
"Or set 'Dir.IsInstallDir = true' for the installation directory.\r" +
"Or use instead of 'new Dir(...' use 'new InstallDir(...' for the installation directory.");
"Or instead of 'new Dir(...' use 'new InstallDir(...' for the installation directory.");

firstDirWithItems.Id = dirId;
return logicalPath;
Expand Down Expand Up @@ -1709,7 +1709,7 @@ static void ProcessDirectory(Dir wDir, Project wProject, Dictionary<Feature, Lis
{
var existingCompElement = dirItem.Elements("Component");

if (existingCompElement.Count() == 0 && AutoElements.LagacyDummyDirAlgorithm)
if (existingCompElement.Count() == 0 && AutoElements.LegacyDummyDirAlgorithm)
{
string compId = wDir.Id + ".EmptyDirectory";

Expand Down Expand Up @@ -2193,7 +2193,7 @@ static void ProcessDirectories(Project wProject, Dictionary<Feature, List<string
//WIX/MSI does not like no-directory deployments thus create fake one
string dummyDir = @"%ProgramFiles%";

if (AutoElements.LagacyDummyDirAlgorithm)
if (AutoElements.LegacyDummyDirAlgorithm)
dummyDir = @"%ProgramFiles%\WixSharp\DummyDir";

if (wProject.Platform == Platform.x64)
Expand Down
6 changes: 5 additions & 1 deletion Source/src/WixSharp/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ public void Process(ProcessingContext context)

XElement component = this.CreateParentComponent();
component.Add(this.ToXElement(WixExtension.Util, "User"));
context.XParent.FindFirst("Component").Parent?.Add(component);

XElement bestParent = context.XParent.FindFirst("Component")?.Parent ??
context.XParent.FistProgramFilesDir();

bestParent.Add(component);

MapComponentToFeatures(component.Attr("Id"), ActualFeatures, context);
}
Expand Down

0 comments on commit 95b3c6a

Please sign in to comment.