3 using System.Windows.Forms;
5 using System.Runtime.InteropServices;
10 internal static class NativeMethods
12 [DllImport("msi.dll", CharSet = CharSet.Unicode)]
13 internal static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);
15 [DllImport("msi.dll", CharSet = CharSet.Unicode)]
16 internal static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
21 public static string Icinga2InstallDir
25 StringBuilder szProduct;
27 for (int index = 0; ; index++) {
28 szProduct = new StringBuilder(39);
29 if (NativeMethods.MsiEnumProducts(index, szProduct) != 0)
33 StringBuilder szName = new StringBuilder(cbName);
35 if (NativeMethods.MsiGetProductInfo(szProduct.ToString(), "ProductName", szName, ref cbName) != 0)
38 if (szName.ToString() != "Icinga 2")
41 int cbLocation = 1024;
42 StringBuilder szLocation = new StringBuilder(cbLocation);
43 if (NativeMethods.MsiGetProductInfo(szProduct.ToString(), "InstallLocation", szLocation, ref cbLocation) == 0)
44 return szLocation.ToString();
51 public static string Icinga2DataDir
55 return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\icinga2";
59 public static string Icinga2User
63 if (!File.Exists(Icinga2DataDir + "\\etc\\icinga2\\user"))
64 return "NT AUTHORITY\\NetworkService";
65 System.IO.StreamReader file = new System.IO.StreamReader(Icinga2DataDir + "\\etc\\icinga2\\user");
66 string line = file.ReadLine();
72 return "NT AUTHORITY\\NetworkService";
77 public static void FatalError(Form owner, string message)
79 MessageBox.Show(owner, message, "Icinga 2 Setup Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
84 /// The main entry point for the application.
89 Application.EnableVisualStyles();
90 Application.SetCompatibleTextRenderingDefault(false);
92 string installDir = Program.Icinga2InstallDir;
94 if (installDir == "") {
95 FatalError(null, "Icinga 2 does not seem to be installed properly.");
101 if (File.Exists(Program.Icinga2DataDir + "\\etc\\icinga2\\features-enabled\\api.conf"))
102 form = new ServiceStatus();
104 form = new SetupWizard();
106 Application.Run(form);