Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. unlodctr.c
  5. Abstract:
  6. Program to remove the counter names belonging to the driver specified
  7. in the command line and update the registry accordingly
  8. Author:
  9. Bob Watson (a-robw) 12 Feb 93
  10. Revision History:
  11. --*/
  12. // Windows Include files
  13. //
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <locale.h>
  19. #include "strsafe.h"
  20. #include <loadperf.h>
  21. ////////////////////////////////////////////////////////////////////////////
  22. //
  23. // MySetThreadUILanguage
  24. //
  25. // This routine sets the thread UI language based on the console codepage.
  26. //
  27. // 9-29-00 WeiWu Created.
  28. // Copied from Base\Win32\Winnls so that it works in W2K as well
  29. ////////////////////////////////////////////////////////////////////////////
  30. LANGID WINAPI MySetThreadUILanguage(WORD wReserved)
  31. {
  32. // Cache system locale and CP info
  33. //
  34. static LCID s_lidSystem = 0;
  35. static UINT s_uiSysCp = 0;
  36. static UINT s_uiSysOEMCp = 0;
  37. ULONG uiUserUICp;
  38. ULONG uiUserUIOEMCp;
  39. WCHAR szData[16];
  40. UNICODE_STRING ucStr;
  41. LANGID lidUserUI = GetUserDefaultUILanguage();
  42. LCID lcidThreadOld = GetThreadLocale();
  43. //
  44. // Set default thread locale to EN-US
  45. //
  46. // This allow us to fall back to English UI to avoid trashed characters
  47. // when console doesn't meet the criteria of rendering native UI.
  48. //
  49. LCID lcidThread = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
  50. UINT uiConsoleCp = GetConsoleOutputCP();
  51. //
  52. // Make sure nobody uses it yet
  53. //
  54. ASSERT(wReserved == 0);
  55. //
  56. // Get cached system locale and CP info.
  57. //
  58. if (!s_uiSysCp) {
  59. LCID lcidSystem = GetSystemDefaultLCID();
  60. if (lcidSystem) {
  61. //
  62. // Get ANSI CP
  63. //
  64. GetLocaleInfoW(lcidSystem, LOCALE_IDEFAULTANSICODEPAGE, szData, sizeof(szData)/sizeof(WCHAR));
  65. RtlInitUnicodeString(& ucStr, szData);
  66. RtlUnicodeStringToInteger(& ucStr, 10, &uiUserUICp);
  67. //
  68. // Get OEM CP
  69. //
  70. GetLocaleInfoW(lcidSystem, LOCALE_IDEFAULTCODEPAGE, szData, sizeof(szData)/sizeof(WCHAR));
  71. RtlInitUnicodeString(& ucStr, szData);
  72. RtlUnicodeStringToInteger(& ucStr, 10, &s_uiSysOEMCp);
  73. //
  74. // Cache system primary langauge
  75. //
  76. s_lidSystem = PRIMARYLANGID(LANGIDFROMLCID(lcidSystem));
  77. }
  78. }
  79. //
  80. // Don't cache user UI language and CP info, UI language can be changed without system reboot.
  81. //
  82. if (lidUserUI) {
  83. GetLocaleInfoW(MAKELCID(lidUserUI,SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, szData, sizeof(szData)/sizeof(WCHAR));
  84. RtlInitUnicodeString(& ucStr, szData);
  85. RtlUnicodeStringToInteger(& ucStr, 10, & uiUserUICp);
  86. GetLocaleInfoW(MAKELCID(lidUserUI,SORT_DEFAULT), LOCALE_IDEFAULTCODEPAGE, szData, sizeof(szData)/sizeof(WCHAR));
  87. RtlInitUnicodeString(& ucStr, szData);
  88. RtlUnicodeStringToInteger(& ucStr, 10, &uiUserUIOEMCp);
  89. }
  90. //
  91. // Complex scripts cannot be rendered in the console, so we
  92. // force the English (US) resource.
  93. //
  94. if (uiConsoleCp && s_lidSystem != LANG_ARABIC && s_lidSystem != LANG_HEBREW &&
  95. s_lidSystem != LANG_VIETNAMESE && s_lidSystem != LANG_THAI) {
  96. //
  97. // Use UI language for console only when console CP, system CP and UI language CP match.
  98. //
  99. if ((uiConsoleCp == s_uiSysCp || uiConsoleCp == s_uiSysOEMCp) &&
  100. (uiConsoleCp == uiUserUICp || uiConsoleCp == uiUserUIOEMCp)) {
  101. lcidThread = MAKELCID(lidUserUI, SORT_DEFAULT);
  102. }
  103. }
  104. //
  105. // Set the thread locale if it's different from the currently set
  106. // thread locale.
  107. //
  108. if ((lcidThread != lcidThreadOld) && (!SetThreadLocale(lcidThread))) {
  109. lcidThread = lcidThreadOld;
  110. }
  111. //
  112. // Return the thread locale that was set.
  113. //
  114. return (LANGIDFROMLCID(lcidThread));
  115. }
  116. int __cdecl main(int argc, char * argv[])
  117. /*++
  118. main
  119. entry point to Counter Name Unloader
  120. Arguments
  121. argc
  122. # of command line arguments present
  123. argv
  124. array of pointers to command line strings
  125. (note that these are obtained from the GetCommandLine function in
  126. order to work with both UNICODE and ANSI strings.)
  127. ReturnValue
  128. 0 (ERROR_SUCCESS) if command was processed
  129. Non-Zero if command error was detected.
  130. --*/
  131. {
  132. LPWSTR lpCommandLine;
  133. UNREFERENCED_PARAMETER(argc);
  134. UNREFERENCED_PARAMETER(argv);
  135. setlocale(LC_ALL, ".OCP");
  136. MySetThreadUILanguage(0);
  137. lpCommandLine = GetCommandLineW();
  138. return (int) UnloadPerfCounterTextStringsW(lpCommandLine, FALSE);
  139. }