| 17 | } |
| 18 | |
| 19 | static class Program |
| 20 | { |
| 21 | public static string Icinga2InstallDir |
| 22 | { |
| 23 | get |
| 24 | { |
| 25 | StringBuilder szProduct; |
| 26 | |
| 27 | for (int index = 0; ; index++) { |
| 28 | szProduct = new StringBuilder(39); |
| 29 | if (NativeMethods.MsiEnumProducts(index, szProduct) != 0) |
| 30 | break; |
| 31 | |
| 32 | int cbName = 128; |
| 33 | StringBuilder szName = new StringBuilder(cbName); |
| 34 | |
| 35 | if (NativeMethods.MsiGetProductInfo(szProduct.ToString(), "ProductName", szName, ref cbName) != 0) |
| 36 | continue; |
| 37 | |
| 38 | if (szName.ToString() != "Icinga 2") |
| 39 | continue; |
| 40 | |
| 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(); |
| 45 | } |
| 46 | |
| 47 | return ""; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | public static string Icinga2DataDir |
| 52 | { |
| 53 | get |
| 54 | { |
| 55 | return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\icinga2"; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | public static string Icinga2User |
| 60 | { |
| 61 | get |
| 62 | { |
| 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(); |
| 67 | file.Close(); |
| 68 | |
| 69 | if (line != null) |
| 70 | return line; |
| 71 | else |
| 72 | return "NT AUTHORITY\\NetworkService"; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 |
nothing calls this directly
no test coverage detected