2014-04-18 12:39:50 +02:00
|
|
|
|
using System;
|
2015-05-12 13:49:52 +02:00
|
|
|
|
using System.IO;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
using System.Windows.Forms;
|
2015-05-12 13:49:52 +02:00
|
|
|
|
using Microsoft.Win32;
|
2016-03-30 11:47:39 +02:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
2014-04-18 12:39:50 +02:00
|
|
|
|
|
|
|
|
|
namespace Icinga
|
|
|
|
|
{
|
|
|
|
|
static class Program
|
|
|
|
|
{
|
2016-03-30 11:47:39 +02:00
|
|
|
|
[DllImport("msi.dll", SetLastError = true)]
|
|
|
|
|
static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
2016-03-30 11:47:39 +02:00
|
|
|
|
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
|
|
|
|
|
static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
|
|
|
|
|
|
|
|
|
|
public static string Icinga2InstallDir
|
2015-05-12 13:49:52 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-03-30 11:47:39 +02:00
|
|
|
|
StringBuilder szProduct;
|
|
|
|
|
|
|
|
|
|
for (int index = 0; ; index++) {
|
|
|
|
|
szProduct = new StringBuilder(39);
|
|
|
|
|
if (MsiEnumProducts(index, szProduct) != 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
int cbName = 128;
|
|
|
|
|
StringBuilder szName = new StringBuilder(cbName);
|
|
|
|
|
|
|
|
|
|
if (MsiGetProductInfo(szProduct.ToString(), "ProductName", szName, ref cbName) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (szName.ToString() != "Icinga 2")
|
|
|
|
|
continue;
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
2016-03-30 11:47:39 +02:00
|
|
|
|
int cbLocation = 1024;
|
|
|
|
|
StringBuilder szLocation = new StringBuilder(cbLocation);
|
|
|
|
|
if (MsiGetProductInfo(szProduct.ToString(), "InstallLocation", szLocation, ref cbLocation) == 0)
|
|
|
|
|
return szLocation.ToString();
|
|
|
|
|
}
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
2016-03-30 11:47:39 +02:00
|
|
|
|
return "";
|
2015-05-12 13:49:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-01 11:40:01 +02:00
|
|
|
|
public static string Icinga2DataDir
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\icinga2";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void FatalError(Form owner, string message)
|
2015-05-12 13:49:52 +02:00
|
|
|
|
{
|
2015-11-23 14:12:25 +01:00
|
|
|
|
MessageBox.Show(owner, message, "Icinga 2 Setup Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2015-05-12 13:49:52 +02:00
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-18 12:39:50 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
static void Main()
|
|
|
|
|
{
|
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
|
|
|
|
string installDir = Program.Icinga2InstallDir;
|
|
|
|
|
|
2016-03-30 09:58:01 +02:00
|
|
|
|
if (installDir == "") {
|
|
|
|
|
FatalError(null, "Icinga 2 does not seem to be installed properly.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-12 13:49:52 +02:00
|
|
|
|
|
|
|
|
|
Form form;
|
|
|
|
|
|
2016-04-01 11:40:01 +02:00
|
|
|
|
if (File.Exists(Program.Icinga2DataDir + "\\etc\\icinga2\\features-enabled\\api.conf"))
|
2015-05-12 13:49:52 +02:00
|
|
|
|
form = new ServiceStatus();
|
|
|
|
|
else
|
|
|
|
|
form = new SetupWizard();
|
|
|
|
|
|
|
|
|
|
Application.Run(form);
|
2014-04-18 12:39:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|