From f3ab244cfcacbf079e3f328ecfa523c952e2a334 Mon Sep 17 00:00:00 2001 From: Oleg Shilo Date: Fri, 17 Jan 2025 23:43:22 +1100 Subject: [PATCH] - Codebase housekeeping --- .../Wix# Samples/Build-MSIX/build_msix.csproj | 2 +- .../Wix# Samples/Build-MSIX/setup.cs | 3 +- .../Wix# Samples/Install Files/setup.cs | 25 +++--- .../Wix# Samples/testpad/setup.cs | 90 +++++++++++++++---- .../Wix# Samples/testpad/testpad.csproj | 68 +++++++------- Source/src/WixSharp.Suite.sln | 11 +++ Source/src/WixSharp.UI/ManagedUI/ManagedUI.cs | 2 - .../ManagedUI/MsiSessionAdapter.cs | 5 +- Source/src/WixSharp/Enums.cs | 5 ++ Source/src/WixSharp/Extensions.cs | 41 +++++++++ 10 files changed, 181 insertions(+), 71 deletions(-) diff --git a/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/build_msix.csproj b/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/build_msix.csproj index 29ab3668..74ebfda7 100644 --- a/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/build_msix.csproj +++ b/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/build_msix.csproj @@ -40,6 +40,6 @@ - + diff --git a/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/setup.cs b/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/setup.cs index 98852ed9..56816f59 100644 --- a/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/setup.cs +++ b/Source/src/WixSharp.Samples/Wix# Samples/Build-MSIX/setup.cs @@ -17,7 +17,7 @@ static class Script { - static public void Main() + static public void Main(string[] args) { var project = new ManagedProject("MyProduct", @@ -27,7 +27,6 @@ static public void Main() TargetFileName = "app.exe" })); - project.ManagedUI = ManagedUI.DefaultWpf; project.GUID = new Guid("6fe30b47-2577-43ad-9a95-1861ba25889b"); var msi = project.BuildMsi(); diff --git a/Source/src/WixSharp.Samples/Wix# Samples/Install Files/setup.cs b/Source/src/WixSharp.Samples/Wix# Samples/Install Files/setup.cs index ae100c5a..977ae382 100644 --- a/Source/src/WixSharp.Samples/Wix# Samples/Install Files/setup.cs +++ b/Source/src/WixSharp.Samples/Wix# Samples/Install Files/setup.cs @@ -8,6 +8,7 @@ using System; using System.Diagnostics; using System.Linq; +using System.Security.Principal; using System.Windows.Forms; using System.Xml.Linq; using WixSharp; @@ -22,22 +23,22 @@ static public void Main() var project = new ManagedProject("MyProduct", - // new Dir(@"AppDataFolder\My ICompany\My Product", - new Dir(new Id("MY_INSTALLDIR"), @"%ProgramFiles%\My ICompany\My Product", + new Dir(@"%ProgramFiles%\My Company\My Product", 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" - }, + @"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") { - NeverOverwrite = true + NeverOverwrite = true, + Condition = new Condition("IS64=yes") })), new Property("PropName", "")); diff --git a/Source/src/WixSharp.Samples/Wix# Samples/testpad/setup.cs b/Source/src/WixSharp.Samples/Wix# Samples/testpad/setup.cs index 3fe10ea7..0058b578 100644 --- a/Source/src/WixSharp.Samples/Wix# Samples/testpad/setup.cs +++ b/Source/src/WixSharp.Samples/Wix# Samples/testpad/setup.cs @@ -1,6 +1,7 @@ -//using PirrosLibrary; +//using Test1Library; using System; using System.Collections.Generic; +using System.Diagnostics; using static System.Net.Mime.MediaTypeNames; using System.Security.Cryptography; using WixSharp; @@ -10,7 +11,7 @@ class Constants public static string PluginVersion = "2.3.0"; } -namespace Pirros.installer.wixsharp +namespace Test1.installer.wixsharp { class Program { @@ -20,19 +21,72 @@ class Program private static readonly string Configuration = "Release"; #endif - public static void Main() + static string companyName = "Demo Inc."; + static string productName = "DllExample"; + static string productVersion = "1.0.0"; + + static void Main() + { + Environment.CurrentDirectory = @"D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\Install Files"; + var msixTemplate = @".\MyProduct.msix.xml"; + + var startInfo = new ProcessStartInfo + { + FileName = "MsixPackagingTool.exe", + Arguments = $@"create-package --template {msixTemplate} -v", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + try + { + using (Process process = Process.Start(startInfo)) + { + string line = null; + while (null != (line = process.StandardOutput.ReadLine())) + Console.WriteLine(line); + + string error = process.StandardError.ReadToEnd(); + if (!error.IsEmpty()) + Console.WriteLine(error); + process.WaitForExit(); + } + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + + static void Main1() + { + var project = new ManagedProject(productName, + new Dir(@"%ProgramFiles%\" + companyName + @"\" + productName + @"\" + productVersion, + Files.FromBuildDir(@"D:\dev\support\wixsharp-issues\DllErrorExample\Contents"))); + + project.GUID = new Guid("5de17d40-9e25-49fe-a835-36d7e0b64062"); + project.Version = new Version(productVersion); + + project.ManagedUI = ManagedUI.DefaultWpf; // all stock UI dialogs + + project.BuildMsi(); + } + + public static void Test1() { return; // REMOVE THIS LINE TO ENABLE BUILDING - Environment.CurrentDirectory = @"D:\dev\support\wixsharp-issues\Pirros\WixSharp Setup1\WixSharp Setup1"; + Environment.CurrentDirectory = @"D:\dev\support\wixsharp-issues\Test1\WixSharp Setup1\WixSharp Setup1"; Constants.PluginVersion = "2.4.0"; - string Version = Constants.PluginVersion; // READ FROM PIRROS LIBRARY - Guid ProductId = GenerateProductId("Pirros" + Constants.PluginVersion); + string Version = Constants.PluginVersion; // READ FROM Test1 LIBRARY + Guid ProductId = GenerateProductId("Test1" + Constants.PluginVersion); Guid UpgradeCode = new Guid("6476F6DF-EB27-4CAB-9790-5FE5F1C39731"); // DO NOT TOUCH Project project = - new Project("Pirros", + new Project("Test1", new Media { EmbedCab = true }, // copied from old installer, don't know what it does CreateRevitAddinDir(2020)// , // CreateRevitAddinDir(2021), @@ -44,20 +98,20 @@ public static void Main() project.Scope = InstallScope.perUser; - project.Name = "Pirros Revit Plugin"; + project.Name = "Test1 Revit Plugin"; project.ProductId = ProductId; project.UpgradeCode = UpgradeCode; //project.GUID = new Guid("6476F6DF-EB27-4CAB-9790-5FE5F1C39735"); project.Version = new Version(Version); - project.Description = "Revit Plugin to interact with Pirros.com"; - project.ControlPanelInfo.Manufacturer = "Pirros Inc"; + project.Description = "Revit Plugin to interact with Test1.com"; + project.ControlPanelInfo.Manufacturer = "Test1 Inc"; project.ControlPanelInfo.ProductIcon = @".\Assets\icon.ico"; - project.ControlPanelInfo.UrlInfoAbout = "https://www.pirros.com"; + project.ControlPanelInfo.UrlInfoAbout = "https://www.Test1.com"; project.MajorUpgrade = new MajorUpgrade { - DowngradeErrorMessage = "A newer version of Pirros Plugin is already installed.", + DowngradeErrorMessage = "A newer version of Test1 Plugin is already installed.", }; project.UI = WUI.WixUI_Minimal; @@ -69,9 +123,9 @@ public static void Main() { "WixUIDialogBmp", @".\Assets\Background.png" } }; - project.OutFileName = $"Pirros.installer-V{Version}{(Configuration == "Debug" ? "-dev" : "")}"; + project.OutFileName = $"Test1.installer-V{Version}{(Configuration == "Debug" ? "-dev" : "")}"; - project.SourceBaseDir = @"D:\dev\support\wixsharp-issues\Pirros\WixSharp Setup1\WixSharp Setup1"; + project.SourceBaseDir = @"D:\dev\support\wixsharp-issues\Test1\WixSharp Setup1\WixSharp Setup1"; // Compiler.PreserveTempFiles = true; Compiler.EmitRelativePaths = false; @@ -88,11 +142,11 @@ private static Dir CreateRevitAddinDir(int year) string framework = GetFrameworkForYear(year); return new Dir($@"%AppDataFolder%\Autodesk\Revit\Addins\{year}", - new File(@"..\Pirros\Pirros.addin"), - new Dir("Pirros", - Files.FromBuildDir($@"..\Pirros\bin\{Configuration}{year}\{framework}"), + new File(@"..\Test1\Test1.addin"), + new Dir("Test1", + Files.FromBuildDir($@"..\Test1\bin\{Configuration}{year}\{framework}"), new Dir("Resources", - new Files(@"..\Pirros\Resources\*.*")))); + new Files(@"..\Test1\Resources\*.*")))); } private static Guid GenerateProductId(string input) diff --git a/Source/src/WixSharp.Samples/Wix# Samples/testpad/testpad.csproj b/Source/src/WixSharp.Samples/Wix# Samples/testpad/testpad.csproj index 70144d97..de7744d1 100644 --- a/Source/src/WixSharp.Samples/Wix# Samples/testpad/testpad.csproj +++ b/Source/src/WixSharp.Samples/Wix# Samples/testpad/testpad.csproj @@ -1,42 +1,42 @@  - - Exe - net472 - + + Exe + net472 + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - + + + + - - - - - - - + + + + + + + - - - + + + - - - + + + diff --git a/Source/src/WixSharp.Suite.sln b/Source/src/WixSharp.Suite.sln index eba2c655..63098703 100644 --- a/Source/src/WixSharp.Suite.sln +++ b/Source/src/WixSharp.Suite.sln @@ -242,6 +242,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixSharp.MsiEventHost", "Wi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "testpad", "WixSharp.Samples\Wix# Samples\testpad\testpad.csproj", "{33B0F443-DE35-44E9-848A-42ECF653D782}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "build_msix", "WixSharp.Samples\Wix# Samples\Build-MSIX\build_msix.csproj", "{B7EEE899-5CA9-48AB-94C0-04650D2CBC85}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1018,6 +1020,14 @@ Global {33B0F443-DE35-44E9-848A-42ECF653D782}.Release|Any CPU.Build.0 = Release|Any CPU {33B0F443-DE35-44E9-848A-42ECF653D782}.Release|x86.ActiveCfg = Release|Any CPU {33B0F443-DE35-44E9-848A-42ECF653D782}.Release|x86.Build.0 = Release|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Debug|x86.ActiveCfg = Debug|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Debug|x86.Build.0 = Debug|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Release|Any CPU.Build.0 = Release|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Release|x86.ActiveCfg = Release|Any CPU + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1120,6 +1130,7 @@ Global {B8FA0F17-1C07-4511-9FFA-3AD69B36B16C} = {DB40BEF1-64CF-4308-9740-AF22284F4491} {A88C3698-8BD1-49C1-999C-020B5E9312E1} = {DB40BEF1-64CF-4308-9740-AF22284F4491} {33B0F443-DE35-44E9-848A-42ECF653D782} = {DB40BEF1-64CF-4308-9740-AF22284F4491} + {B7EEE899-5CA9-48AB-94C0-04650D2CBC85} = {DB40BEF1-64CF-4308-9740-AF22284F4491} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {559711D5-4429-4577-BBC9-F0D973972079} diff --git a/Source/src/WixSharp.UI/ManagedUI/ManagedUI.cs b/Source/src/WixSharp.UI/ManagedUI/ManagedUI.cs index 97534489..0bddbce6 100644 --- a/Source/src/WixSharp.UI/ManagedUI/ManagedUI.cs +++ b/Source/src/WixSharp.UI/ManagedUI/ManagedUI.cs @@ -191,8 +191,6 @@ public static string LocalizationFilesLocation internal static string LocalizationFileFor(Project project) { - // return UIExtensions.UserOrDefaultContentOf(project.LocalizationFile, project.SourceBaseDir, project.OutDir, project.Name + ".wxl", Resources.WixUI_en_us); - // - if localization file specified by the user then just return it but merge with // the stock localization if found. // - if user did not specify it then find the stock localization file (in SDK folder) for the language diff --git a/Source/src/WixSharp.UI/ManagedUI/MsiSessionAdapter.cs b/Source/src/WixSharp.UI/ManagedUI/MsiSessionAdapter.cs index 1a3cbfda..5b9e0dc3 100644 --- a/Source/src/WixSharp.UI/ManagedUI/MsiSessionAdapter.cs +++ b/Source/src/WixSharp.UI/ManagedUI/MsiSessionAdapter.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Linq; using WixSharp.UI.Forms; @@ -162,7 +163,7 @@ public void Log(string msg) // issue. When part of the logging system does not work, it reduces // analysis time when other parts are still fed with relevant messages. // - List exceptions = new List(); + var exceptions = new List(); try { @@ -222,4 +223,4 @@ public string LogFile } } } -} +} \ No newline at end of file diff --git a/Source/src/WixSharp/Enums.cs b/Source/src/WixSharp/Enums.cs index f1333067..83148d27 100644 --- a/Source/src/WixSharp/Enums.cs +++ b/Source/src/WixSharp/Enums.cs @@ -774,6 +774,11 @@ public enum VariableType /// @string, + /// + /// The formatted type + /// + formatted, + /// /// The numeric type /// diff --git a/Source/src/WixSharp/Extensions.cs b/Source/src/WixSharp/Extensions.cs index 7440b663..a9ff2803 100644 --- a/Source/src/WixSharp/Extensions.cs +++ b/Source/src/WixSharp/Extensions.cs @@ -3739,6 +3739,47 @@ public static Process StartElevated(this string fileName, string args = "") }); } + /// + /// Starts a process resource by specifying the name of an application and a set of + /// command-line arguments, and associates the resource with a new + /// System.Diagnostics.Process component. + /// + /// Gets or sets the application or document to start. + /// + /// Gets or sets the set of command-line arguments to use when starting the application. + /// + /// + /// A new component that is associated with the + /// process, or null, if no process resource is started (for example, if an existing process + /// is reused). + /// + public static Process Run(this string fileName, string args = "", Action onOutput = null) + { + using (var proc = Process.Start( + new ProcessStartInfo + { + WorkingDirectory = fileName.PathGetFullPath().PathGetDirName(), + FileName = fileName, + Arguments = args, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + })) + { + string line = null; + while (null != (line = proc.StandardOutput.ReadLine())) + onOutput?.Invoke(line); + + string error = proc.StandardError.ReadToEnd(); + if (!error.IsEmpty()) + onOutput?.Invoke(error); + proc.WaitForExit(); + + return proc; + } + } + /// /// Starts a process resource by specifying the name of an application and a set of /// command-line arguments, and associates the resource with a new