2020-09-04 08:02:47 -05:00
|
|
|
using WixSharp;
|
2021-11-15 07:15:15 -06:00
|
|
|
using System;
|
2020-09-04 08:02:47 -05:00
|
|
|
using System.Drawing;
|
2021-11-15 07:15:15 -06:00
|
|
|
using System.Runtime.InteropServices;
|
2020-09-04 08:02:47 -05:00
|
|
|
|
|
|
|
namespace Symphony
|
|
|
|
{
|
2020-10-26 07:17:05 -05:00
|
|
|
public partial class WelcomeDialog : WixSharp.UI.Forms.ManagedForm, IManagedDialog
|
2020-09-04 08:02:47 -05:00
|
|
|
{
|
2020-09-04 08:19:15 -05:00
|
|
|
// Helper function to retrive the user name of the current user. The user name returned from
|
|
|
|
// windows can be on the form DOMAIN\USER or USER@DOMAIN. This function strips away the domain
|
|
|
|
// name and separator, and returns the undecorated user name only.
|
2020-09-04 08:02:47 -05:00
|
|
|
private string getUserName()
|
|
|
|
{
|
|
|
|
var name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
|
|
|
|
var slashIndex = name.IndexOf("\\");
|
|
|
|
return slashIndex > -1 ? name.Substring(slashIndex + 1) : name.Substring(0, name.IndexOf("@"));
|
|
|
|
}
|
|
|
|
|
2020-10-26 07:17:05 -05:00
|
|
|
public WelcomeDialog()
|
2020-09-04 08:02:47 -05:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
2021-11-15 07:15:15 -06:00
|
|
|
[DllImport("user32.dll")]
|
|
|
|
static extern bool SetForegroundWindow(IntPtr hWnd);
|
2020-09-04 08:02:47 -05:00
|
|
|
void dialog_Load(object sender, System.EventArgs e)
|
|
|
|
{
|
2021-11-15 07:15:15 -06:00
|
|
|
SetForegroundWindow(this.Handle);
|
2020-09-10 02:15:10 -05:00
|
|
|
// Populate the dynamic UI elements that can't be set at compile time (background image and
|
2020-09-04 08:19:15 -05:00
|
|
|
// the label containing user name)
|
|
|
|
this.backgroundPanel.BackgroundImage = Runtime.Session.GetResourceBitmap("WixUI_Bmp_Dialog");
|
2020-09-04 08:02:47 -05:00
|
|
|
this.radioButtonCurrentUser.Text = "Only for me (" + getUserName() + ")";
|
2021-11-15 07:15:15 -06:00
|
|
|
if (Runtime.Session["ALLUSERS"] != "")
|
2020-09-10 02:15:10 -05:00
|
|
|
{
|
2020-10-30 03:09:17 -05:00
|
|
|
this.radioButtonAllUsers.Checked = true;
|
2020-09-10 02:15:10 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-15 07:15:15 -06:00
|
|
|
this.radioButtonCurrentUser.Checked = true;
|
2020-10-30 03:09:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Detect if Symphony is running
|
2022-07-05 02:43:35 -05:00
|
|
|
bool isRunning = (System.Diagnostics.Process.GetProcessesByName("Symphony").Length > 1 || System.Diagnostics.Process.GetProcessesByName("C9Shell").Length >= 1);
|
2020-10-30 03:09:17 -05:00
|
|
|
if (!isRunning)
|
|
|
|
{
|
|
|
|
// If it is not running, change the label of the "Next" button to "Install" as the CloseDialog will be skipped
|
|
|
|
this.next.Text = "Install";
|
2020-09-10 02:15:10 -05:00
|
|
|
}
|
2020-09-04 08:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void next_Click(object sender, System.EventArgs e)
|
|
|
|
{
|
2020-09-04 08:19:15 -05:00
|
|
|
// To enable Wix to use the "MSIINSTALLPERUSER" property being set below, ALLUSERS must be set to 2
|
2020-09-10 02:15:10 -05:00
|
|
|
Runtime.Session["ALLUSERS"] = "2";
|
|
|
|
|
2020-12-08 04:11:05 -06:00
|
|
|
var installDir = "";
|
2020-09-04 08:02:47 -05:00
|
|
|
if (radioButtonCurrentUser.Checked)
|
|
|
|
{
|
2020-09-04 08:19:15 -05:00
|
|
|
// Install for current user
|
2020-09-04 08:02:47 -05:00
|
|
|
Runtime.Session["MSIINSTALLPERUSER"] = "1"; // per-user
|
2020-10-30 03:09:17 -05:00
|
|
|
Runtime.Session["INSTALLDIR"] = System.Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Programs\Symphony\" + Runtime.ProductName);
|
2020-12-08 04:11:05 -06:00
|
|
|
}
|
|
|
|
else if (radioButtonAllUsers.Checked)
|
2020-09-04 08:02:47 -05:00
|
|
|
{
|
2020-09-04 08:19:15 -05:00
|
|
|
// Install for all users
|
2020-09-10 02:15:10 -05:00
|
|
|
Runtime.Session["MSIINSTALLPERUSER"] = ""; // per-machine
|
2021-11-15 07:15:15 -06:00
|
|
|
Runtime.Session["INSTALLDIR"] = Runtime.Session["PROGRAMSFOLDER"] + @"\Symphony\" + Runtime.ProductName;
|
2020-09-04 08:02:47 -05:00
|
|
|
}
|
2020-09-10 02:15:10 -05:00
|
|
|
|
2020-12-08 04:11:05 -06:00
|
|
|
// Set INSTALLDIR
|
2021-11-15 07:15:15 -06:00
|
|
|
if (Runtime.Session["APPDIR"] != "")
|
2020-12-08 04:11:05 -06:00
|
|
|
{
|
|
|
|
// If APPDIR param was specified, just use that as is
|
|
|
|
Runtime.Session["INSTALLDIR"] = Runtime.Session["APPDIR"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Apply the install dir as determined by radio buttons
|
|
|
|
Runtime.Session["INSTALLDIR"] = installDir;
|
|
|
|
}
|
|
|
|
|
2020-10-16 06:22:30 -05:00
|
|
|
// Detect if Symphony is running
|
2022-07-05 02:43:35 -05:00
|
|
|
bool isRunning = (System.Diagnostics.Process.GetProcessesByName("Symphony").Length > 1 || System.Diagnostics.Process.GetProcessesByName("C9Shell").Length >= 1);
|
2020-10-16 06:22:30 -05:00
|
|
|
if (isRunning)
|
|
|
|
{
|
|
|
|
// If it is running, continue to the "Close Symphony" screen
|
2020-10-30 03:09:17 -05:00
|
|
|
Shell.GoNext();
|
2020-10-16 06:22:30 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-30 03:09:17 -05:00
|
|
|
// If it is not running, proceed to progress dialog
|
|
|
|
Shell.GoTo<Symphony.ProgressDialog>();
|
2020-10-16 06:22:30 -05:00
|
|
|
}
|
2020-09-04 08:02:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void cancel_Click(object sender, System.EventArgs e)
|
|
|
|
{
|
2020-11-02 01:17:38 -06:00
|
|
|
// TODO: Localization
|
2021-11-15 07:15:15 -06:00
|
|
|
if (System.Windows.Forms.MessageBox.Show("Are you sure you want to cancel Symphony installation?",
|
|
|
|
"Symphony Setup", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
|
2020-10-26 02:46:07 -05:00
|
|
|
{
|
|
|
|
Shell.Cancel();
|
|
|
|
}
|
2020-09-04 08:02:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|