3 using System.Windows.Forms;
5 using System.Runtime.InteropServices;
12 [DllImport("msi.dll", SetLastError = true)]
13 static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);
15 [DllImport("msi.dll", CharSet = CharSet.Unicode)]
16 static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
18 public static string Icinga2InstallDir
22 StringBuilder szProduct;
24 for (int index = 0; ; index++) {
25 szProduct = new StringBuilder(39);
26 if (MsiEnumProducts(index, szProduct) != 0)
30 StringBuilder szName = new StringBuilder(cbName);
32 if (MsiGetProductInfo(szProduct.ToString(), "ProductName", szName, ref cbName) != 0)
35 if (szName.ToString() != "Icinga 2")
38 int cbLocation = 1024;
39 StringBuilder szLocation = new StringBuilder(cbLocation);
40 if (MsiGetProductInfo(szProduct.ToString(), "InstallLocation", szLocation, ref cbLocation) == 0)
41 return szLocation.ToString();
48 public static string Icinga2DataDir
52 return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\icinga2";
56 public static string Icinga2User
60 if (!File.Exists(Icinga2DataDir + "\\etc\\icinga2\\user"))
61 return "NT AUTHORITY\\NetworkService";
62 System.IO.StreamReader file = new System.IO.StreamReader(Icinga2DataDir + "\\etc\\icinga2\\user");
63 string line = file.ReadLine();
69 return "NT AUTHORITY\\NetworkService";
74 public static void FatalError(Form owner, string message)
76 MessageBox.Show(owner, message, "Icinga 2 Setup Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
81 /// The main entry point for the application.
86 Application.EnableVisualStyles();
87 Application.SetCompatibleTextRenderingDefault(false);
89 string installDir = Program.Icinga2InstallDir;
91 if (installDir == "") {
92 FatalError(null, "Icinga 2 does not seem to be installed properly.");
98 if (File.Exists(Program.Icinga2DataDir + "\\etc\\icinga2\\features-enabled\\api.conf"))
99 form = new ServiceStatus();
101 form = new SetupWizard();
103 Application.Run(form);