Skip to content

Commit

Permalink
- #1739: Detection of upgrading in events (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Feb 21, 2025
1 parent 6cda49f commit 21316db
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
41 changes: 40 additions & 1 deletion Source/src/WixSharp.Samples/Wix# Samples/testpad/setup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//using Test1Library;
using System;
using System.Collections.Generic;
using static System.Collections.Specialized.BitVector32;
using System.Diagnostics;
using static System.Net.Mime.MediaTypeNames;
using System.Security.Cryptography;
using System.Windows.Forms;
using WixSharp;
using WixSharp.CommonTasks;
using WixToolset.Dtf.WindowsInstaller;

class Constants
Expand All @@ -28,7 +31,43 @@ class Program

static void Main()
{
issue_1727();
issue_1739();
}

static void issue_1739()
{
void build(string version)
{
var project =
new ManagedProject("My Product",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File(
@"D:\dev\wixsharp4\Source\src\WixSharp.Samples\Wix# Samples\testpad\setup.cs")));

project.GUID = new Guid("6f330b47-2577-43ad-9095-1361ba25889b");

project.UI = WUI.WixUI_ProgressOnly;
project.MajorUpgradeStrategy = MajorUpgradeStrategy.Default;

project.Version = new Version(version);

project.AfterInstall += (e) =>
{
if (e.Session.MyIsUpgradingInstalledVersion())
{
var isUpgrading = e.Session.IsUpgradingInstalledVersion();
MessageBox.Show(isUpgrading.ToString(), "");
}
// e.Result = ActionResult.Failure;
};

project.OutFileName = $"MyProduct.{project.Version}";
project.DefaultDeferredProperties += ";REMOVE;REINSTALL;Installed";

project.BuildMsi();
}
build("1.0.1");
build("1.0.2");
}

static void Main2()
Expand Down
9 changes: 8 additions & 1 deletion Source/src/WixSharp/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3152,7 +3152,14 @@ public static bool IsCancelledRaw(this Session session)
/// <returns></returns>
public static string QueryProperty(this Session session, string name)
{
return (string)session.Database.ExecuteScalar($"SELECT `Value` FROM `Property` WHERE `Property` = '{name}'");
try
{
return (string)session.Database.ExecuteScalar($"SELECT `Value` FROM `Property` WHERE `Property` = '{name}'");
}
catch (Exception)
{
return session.Property(name); // in case the db is disposed already
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/src/WixSharp/ManagedProject/ManagedProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public string DefaultDeferredProperties
}
}

string defaultDeferredProperties = "INSTALLDIR,UILevel,ProductName,FOUNDPREVIOUSVERSION,UpgradeCode,ManagedProjectElevatedEvents";
string defaultDeferredProperties = "INSTALLDIR,UILevel,ProductName,FOUNDPREVIOUSVERSION,UpgradeCode,ManagedProjectElevatedEvents;REMOVE;REINSTALL;Installed";

/// <summary>
/// Flags that indicates if <c>WixSharp_InitRuntime_Action</c> custom action should be
Expand Down

0 comments on commit 21316db

Please sign in to comment.