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.

240 lines
7.8 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: MAKEINI.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 1 Jan, 1997
  12. *
  13. * DESCRIPTION:
  14. * Main code for the default power schemes ini file generator, MAKEINI.EXE.
  15. * Generates a registry specification file which can be read by REGINI.EXE.
  16. *
  17. *******************************************************************************/
  18. #include "parse.h"
  19. #define SRC_NAME "..\\DEFAULTS.CSV"
  20. VOID GetPolicyInf(void)
  21. {
  22. return;
  23. }
  24. /*******************************************************************************
  25. *
  26. * WriteRegBinary
  27. *
  28. * DESCRIPTION:
  29. * Write binary data out to the registry specification file.
  30. *
  31. * PARAMETERS:
  32. *
  33. *******************************************************************************/
  34. VOID WriteRegBinary(FILE *fIni, PVOID pv, UINT uiSize, char *pszIndent)
  35. {
  36. PDWORD pdw = pv;
  37. DWORD dw;
  38. PBYTE pb;
  39. UINT uiRow = 2;
  40. UINT uiNumDWords, uiNumBytes;
  41. fprintf(fIni, "REG_BINARY 0x%08X ", uiSize);
  42. uiNumDWords = uiSize / sizeof(DWORD);
  43. uiNumBytes = uiSize % sizeof(DWORD);
  44. while (uiNumDWords) {
  45. fprintf(fIni, "0x%08X ", *pdw++);
  46. uiNumDWords--;
  47. if (uiRow++ == 3) {
  48. uiRow = 0;
  49. fprintf(fIni, "\\\n%s", pszIndent);
  50. }
  51. }
  52. if (uiNumBytes) {
  53. pb = (PBYTE)pdw;
  54. dw = (DWORD)*pb++;
  55. if (uiNumBytes >= 2) {
  56. dw |= ((DWORD)*pb++ << 8);
  57. }
  58. if (uiNumBytes == 3) {
  59. dw |= ((DWORD)*pb << 16);
  60. }
  61. }
  62. }
  63. /*******************************************************************************
  64. *
  65. * WriteRegSpec
  66. *
  67. * DESCRIPTION:
  68. * Write out the registry specification file in REGINI format.
  69. *
  70. * PARAMETERS:
  71. *
  72. *******************************************************************************/
  73. BOOLEAN WriteRegSpec(FILE *fIni, char **pszName, char **pszDesc, UINT uiCount)
  74. {
  75. UINT i;
  76. // PowerCfg sound events
  77. fprintf(fIni, "USER:\\AppEvents\n");
  78. fprintf(fIni, " EventLabels\n");
  79. fprintf(fIni, " LowBatteryAlarm\n");
  80. fprintf(fIni, " = Low Battery Alarm\n");
  81. fprintf(fIni, " CriticalBatteryAlarm\n");
  82. fprintf(fIni, " = Critical Battery Alarm\n\n");
  83. fprintf(fIni, "USER:\\AppEvents\n");
  84. fprintf(fIni, " Schemes\n");
  85. fprintf(fIni, " Apps\n");
  86. fprintf(fIni, " PowerCfg\n");
  87. fprintf(fIni, " = Power Management\n");
  88. fprintf(fIni, " LowBatteryAlarm\n");
  89. fprintf(fIni, " .Current\n");
  90. fprintf(fIni, " = ding.wav\n");
  91. fprintf(fIni, " .Default\n");
  92. fprintf(fIni, " =\n");
  93. fprintf(fIni, " CriticalBatteryAlarm\n");
  94. fprintf(fIni, " .Current\n");
  95. fprintf(fIni, " = ding.wav\n");
  96. fprintf(fIni, " .Default\n");
  97. fprintf(fIni, " =\n\n");
  98. // User misc.
  99. fprintf(fIni, "USER:\\Control Panel\\PowerCfg\n");
  100. fprintf(fIni, " CurrentPowerPolicy = 0\n");
  101. // User global policies.
  102. fprintf(fIni, " GlobalPowerPolicy\n");
  103. fprintf(fIni, " Policies = ");
  104. WriteRegBinary(fIni, &g_gupp, sizeof(GLOBAL_USER_POWER_POLICY),
  105. " ");
  106. fprintf(fIni, "\n\n");
  107. // User power schemes.
  108. fprintf(fIni, " PowerPolicies\n");
  109. for (i = 0; i < uiCount; i++) {
  110. fprintf(fIni, " %d\n", i);
  111. fprintf(fIni, " Name = %s\n", pszName[i]);
  112. fprintf(fIni, " Description = %s\n", pszDesc[i]);
  113. fprintf(fIni, " Policies = ");
  114. WriteRegBinary(fIni, g_pupp[i], sizeof(USER_POWER_POLICY),
  115. " ");
  116. fprintf(fIni, "\n\n");
  117. }
  118. // Machine misc.
  119. fprintf(fIni, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\n");
  120. fprintf(fIni, " DiskSpinDownMax = 3600\n");
  121. fprintf(fIni, " DiskSpinDownMin = 3\n");
  122. fprintf(fIni, " LastID = %d\n", uiCount - 1);
  123. fprintf(fIni, " GlobalPowerPolicy\n");
  124. fprintf(fIni, " Policies = ");
  125. WriteRegBinary(fIni, &g_gmpp, sizeof(GLOBAL_MACHINE_POWER_POLICY),
  126. " ");
  127. fprintf(fIni, "\n\n");
  128. fprintf(fIni, " PowerPolicies\n");
  129. for (i = 0; i < uiCount; i++) {
  130. fprintf(fIni, " %d\n", i);
  131. fprintf(fIni, " Policies = ");
  132. WriteRegBinary(fIni, g_pmpp[i], sizeof(MACHINE_POWER_POLICY),
  133. " ");
  134. fprintf(fIni, "\n\n");
  135. }
  136. fprintf(fIni, "\n\n");
  137. fprintf(fIni, " ProcessorPolicies\n");
  138. for (i = 0; i < uiCount; i++) {
  139. fprintf(fIni, " %d\n", i);
  140. fprintf(fIni, " Policies = ");
  141. WriteRegBinary(fIni, g_ppmpp[i], sizeof(MACHINE_PROCESSOR_POWER_POLICY),
  142. " ");
  143. fprintf(fIni, "\n\n");
  144. }
  145. return TRUE;
  146. }
  147. /*******************************************************************************
  148. *
  149. * main
  150. *
  151. * DESCRIPTION:
  152. *
  153. * PARAMETERS:
  154. *
  155. *******************************************************************************/
  156. void __cdecl main (int argc, char **argv)
  157. {
  158. DWORD dwSize;
  159. char *psz;
  160. FILE *fIni;
  161. UINT uiNameCount, uiDescCount;
  162. char *pszName[MAX_PROFILES];
  163. char *pszDesc[MAX_PROFILES];
  164. printf("Processing: %s\n", SRC_NAME);
  165. printf("Building name and description arrays...\n");
  166. ReadSource();
  167. BuildLineArray();
  168. if ((fIni = fopen(INI_NAME, "w+")) != NULL) {
  169. printf("Writing registry specification file: %s\n", INI_NAME);
  170. }
  171. else {
  172. DefFatalExit(TRUE, "Error opening registry specification file: %s for output\n", INI_NAME);
  173. }
  174. printf(" Parsing names.");
  175. GetCheckLabelToken(NAME_LINE, "Name", 0);
  176. uiNameCount = GetTokens(NULL, REGSTR_MAX_VALUE_LENGTH, pszName,
  177. MAX_PROFILES, DELIMITERS);
  178. if (uiNameCount) {
  179. printf(" Parsed %d names successfully.\n", uiNameCount);
  180. printf(" Parsing descriptions.");
  181. GetCheckLabelToken(DESCRIPTION_LINE, "Description", 0);
  182. uiDescCount = GetTokens(NULL, MAX_DESC_LEN, pszDesc,
  183. MAX_PROFILES, DELIMITERS);
  184. if (uiDescCount == uiNameCount) {
  185. printf(" Parsed %d descriptions successfully.\n", uiDescCount);
  186. g_uiPoliciesCount[0] = uiNameCount;
  187. // Get the power policies, schemes
  188. GetPolicies();
  189. // Get the global power policies
  190. GetGlobalPolicies();
  191. // Write the registry specification file.
  192. WriteRegSpec(fIni, pszName, pszDesc, g_uiPoliciesCount[0]);
  193. printf("Registry specification file: %s, written sucessfully \n", INI_NAME);
  194. fclose(fIni);
  195. printf("\n\nDefault Processing Success. Output file is valid.\n");
  196. exit(0);
  197. }
  198. else {
  199. printf(" Name count: %d != description count: %d.\n", uiNameCount, uiDescCount);
  200. }
  201. }
  202. else {
  203. printf(" Name parsing failure.\n");
  204. }
  205. printf("ProcessAndWrite failed, Last Error: %d\n", GetLastError());
  206. exit(1);
  207. }