SymphonyElectron/installer/win/WixSharpInstaller/WelcomeDialog.cs

107 lines
4.3 KiB
C#
Raw Normal View History

using WixSharp;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Symphony
{
2020-10-26 07:17:05 -05:00
public partial class WelcomeDialog : WixSharp.UI.Forms.ManagedForm, IManagedDialog
{
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.
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()
{
InitializeComponent();
}
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
void dialog_Load(object sender, System.EventArgs e)
{
SetForegroundWindow(this.Handle);
// 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");
this.radioButtonCurrentUser.Text = "Only for me (" + getUserName() + ")";
if (Runtime.Session["ALLUSERS"] != "")
{
2020-10-30 03:09:17 -05:00
this.radioButtonAllUsers.Checked = true;
}
else
{
this.radioButtonCurrentUser.Checked = true;
2020-10-30 03:09:17 -05:00
}
// Detect if Symphony is running
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";
}
}
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
Runtime.Session["ALLUSERS"] = "2";
var installDir = "";
if (radioButtonCurrentUser.Checked)
{
2020-09-04 08:19:15 -05:00
// Install for current user
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);
}
else if (radioButtonAllUsers.Checked)
{
2020-09-04 08:19:15 -05:00
// Install for all users
Runtime.Session["MSIINSTALLPERUSER"] = ""; // per-machine
Runtime.Session["INSTALLDIR"] = Runtime.Session["PROGRAMSFOLDER"] + @"\Symphony\" + Runtime.ProductName;
}
// Set INSTALLDIR
if (Runtime.Session["APPDIR"] != "")
{
// 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;
}
// Detect if Symphony is running
bool isRunning = (System.Diagnostics.Process.GetProcessesByName("Symphony").Length > 1 || System.Diagnostics.Process.GetProcessesByName("C9Shell").Length >= 1);
if (isRunning)
{
// If it is running, continue to the "Close Symphony" screen
2020-10-30 03:09:17 -05:00
Shell.GoNext();
}
else
{
2020-10-30 03:09:17 -05:00
// If it is not running, proceed to progress dialog
Shell.GoTo<Symphony.ProgressDialog>();
}
}
void cancel_Click(object sender, System.EventArgs e)
{
// TODO: Localization
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)
{
Shell.Cancel();
}
}
}
}