internal void CreatePerfCounterCategory() { int num = 0; int num2 = 15000; LoadUnloadPerfCounterLocalizedText loadUnloadPerfCounterLocalizedText = new LoadUnloadPerfCounterLocalizedText(); TaskLogger.LogEnter(); base.WriteVerbose(Strings.PerfCounterCategoryDefinition(this.CategoryName)); if (!this.unmanagedCategory) { bool flag; do { Exception ex = null; try { PerformanceCounterCategory.Create(this.CategoryName, string.Empty, this.categoryType, this.counterDataCollection); } catch (InvalidOperationException ex2) { if (!PerformanceCounterCategory.Exists(this.CategoryName)) { ex = ex2; } } catch (Win32Exception ex3) { ex = ex3; } if (ex == null) { break; } num++; flag = (num < 5); if (flag) { base.WriteVerbose(Strings.PerfCounterFileInUse(this.CategoryName, num2 / 1000, 5 - num)); Thread.Sleep(num2); } else { base.WriteError(ex, ErrorCategory.InvalidData, null); } }while (flag); if (this.fileMappingSize > 0) { string name = string.Format(CultureInfo.InvariantCulture, "SYSTEM\\CurrentControlSet\\Services\\{0}\\Performance", new object[] { this.CategoryName }); using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(name, true)) { registryKey.SetValue("FileMappingSize", this.fileMappingSize); } } try { loadUnloadPerfCounterLocalizedText.UnloadLocalizedText(this.iniFileName, this.CategoryName); loadUnloadPerfCounterLocalizedText.LoadLocalizedText(this.iniFileName, this.CategoryName); goto IL_251; } catch (FileNotFoundException exception) { base.WriteError(exception, ErrorCategory.InvalidData, null); goto IL_251; } catch (TaskException exception2) { base.WriteError(exception2, ErrorCategory.InvalidData, null); goto IL_251; } } string subkey = string.Format(CultureInfo.InvariantCulture, "SYSTEM\\CurrentControlSet\\Services\\{0}\\Performance", new object[] { this.CategoryName }); using (RegistryKey registryKey2 = Registry.LocalMachine.CreateSubKey(subkey)) { if (this.extensionDllInfo.UseExpandedStringForLibrary) { registryKey2.SetValue("Library", this.extensionDllInfo.Library, RegistryValueKind.ExpandString); } else { registryKey2.SetValue("Library", this.extensionDllInfo.Library); } registryKey2.SetValue("Open", this.extensionDllInfo.Open); registryKey2.SetValue("Collect", this.extensionDllInfo.Collect); registryKey2.SetValue("Close", this.extensionDllInfo.Close); } try { loadUnloadPerfCounterLocalizedText.LoadLocalizedText(this.iniFileName, this.CategoryName); } catch (FileNotFoundException exception3) { base.WriteError(exception3, ErrorCategory.InvalidData, null); } catch (TaskException exception4) { base.WriteError(exception4, ErrorCategory.InvalidData, null); } IL_251: TaskLogger.LogExit(); }
private void LogInstalledCategoryNames(string iniFileName, string action_prefix) { int num = 40000; SafeHGlobalHandle safeHGlobalHandle2; SafeHGlobalHandle safeHGlobalHandle = safeHGlobalHandle2 = new SafeHGlobalHandle(Marshal.AllocHGlobal(num * 2)); try { int privateProfileStringSpecial = LoadUnloadPerfCounterLocalizedText.GetPrivateProfileStringSpecial("objects", null, null, safeHGlobalHandle, num, iniFileName); if (privateProfileStringSpecial > 0 && privateProfileStringSpecial < num - 2) { int num2 = 160000; SafeHGlobalHandle safeHGlobalHandle4; SafeHGlobalHandle safeHGlobalHandle3 = safeHGlobalHandle4 = new SafeHGlobalHandle(Marshal.AllocHGlobal(num2 * 2)); try { int privateProfileStringSpecial2 = LoadUnloadPerfCounterLocalizedText.GetPrivateProfileStringSpecial("text", null, null, safeHGlobalHandle3, num2, iniFileName); if (privateProfileStringSpecial2 > 0 && privateProfileStringSpecial2 < num2 - 2) { StringBuilder stringBuilder = new StringBuilder(10000); string path = Path.Combine(ConfigurationContext.Setup.LoggingPath, "lodctr_backups\\InstalledPerfCategories.log"); IntPtr ptr = safeHGlobalHandle.DangerousGetHandle(); for (;;) { string text = Marshal.PtrToStringUni(ptr); if (string.IsNullOrEmpty(text)) { break; } int num3 = text.LastIndexOf('_'); if (num3 > 0) { int num4 = text.LastIndexOf('_', num3 - 1, num3); if (num4 > 0) { string strA = text.Substring(0, num4); IntPtr ptr2 = safeHGlobalHandle3.DangerousGetHandle(); for (;;) { string text2 = Marshal.PtrToStringUni(ptr2); if (string.IsNullOrEmpty(text2)) { break; } int num5 = text2.LastIndexOf('_'); if (num5 > 0) { int num6 = text2.LastIndexOf('_', num5 - 1, num5); if (num6 > 0) { string strB = text2.Substring(0, num6); if (string.Compare(strA, strB) == 0 && !text2.EndsWith("_HELP") && LoadUnloadPerfCounterLocalizedText.GetPrivateProfileString("text", text2, null, stringBuilder, stringBuilder.Capacity, iniFileName) != 0) { File.AppendAllText(path, string.Format("{0}-{1}-{2}={3}\r\n", new object[] { action_prefix, Path.GetFileName(iniFileName), text2, stringBuilder }), new UnicodeEncoding()); } } } ptr2 = (IntPtr)(ptr2.ToInt64() + (long)((text2.Length + 1) * 2)); } } } ptr = (IntPtr)(ptr.ToInt64() + (long)((text.Length + 1) * 2)); } } } finally { if (safeHGlobalHandle4 != null) { ((IDisposable)safeHGlobalHandle4).Dispose(); } } } } finally { if (safeHGlobalHandle2 != null) { ((IDisposable)safeHGlobalHandle2).Dispose(); } } }
internal void DeletePerfCounterCategory() { int num = 0; bool flag = false; int num2 = 15000; LoadUnloadPerfCounterLocalizedText loadUnloadPerfCounterLocalizedText = new LoadUnloadPerfCounterLocalizedText(); TaskLogger.LogEnter(); base.WriteVerbose(Strings.PerfCounterCategoryDefinition(this.CategoryName)); if (!this.unmanagedCategory) { this.LogInstalledCategoryNames(Path.GetFullPath(this.iniFileName), "Rem"); do { try { PerformanceCounterCategory.Delete(this.CategoryName); } catch (Win32Exception exception) { num++; flag = (num < 5); if (flag) { base.WriteVerbose(Strings.PerfCounterFileInUse(this.CategoryName, num2 / 1000, 5 - num)); Thread.Sleep(num2); } else { base.WriteError(exception, ErrorCategory.InvalidData, null); } } catch (InvalidOperationException exception2) { if (PerformanceCounterCategory.Exists(this.CategoryName)) { base.WriteError(exception2, ErrorCategory.InvalidData, null); } flag = false; } }while (flag); } else { try { loadUnloadPerfCounterLocalizedText.UnloadLocalizedText(this.iniFileName, this.CategoryName); } catch (Win32Exception exception3) { base.WriteError(exception3, ErrorCategory.InvalidData, null); } catch (TaskException exception4) { base.WriteError(exception4, ErrorCategory.InvalidData, null); } string subkey = string.Format(CultureInfo.InvariantCulture, "SYSTEM\\CurrentControlSet\\Services\\{0}", new object[] { this.CategoryName }); Registry.LocalMachine.DeleteSubKeyTree(subkey); } TaskLogger.LogExit(); }