Source code of Windows XP (NT5)
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.

212 lines
5.9 KiB

  1. #include "fdisk.h"
  2. #include <stdio.h>
  3. int ProfileWindowX,
  4. ProfileWindowY,
  5. ProfileWindowW,
  6. ProfileWindowH;
  7. BOOL ProfileIsMaximized,ProfileIsIconic;
  8. #ifdef JAPAN
  9. //Don't use IDS_APPNAME as registry key,
  10. //because it is also used window's caption and it was localized.
  11. CHAR SectionName[] = "Disk Administrator";
  12. #else
  13. CHAR SectionName[80];
  14. #endif
  15. CHAR szWindowPosition[] = "WindowPosition";
  16. CHAR szWindowMaximized[] = "WindowMaximized";
  17. CHAR szWindowIconic[] = "WindowIconic";
  18. CHAR szWindowPosFormatString[] = "%d,%d,%d,%d";
  19. CHAR szStatusBar[] = "StatusBar";
  20. CHAR szLegend[] = "Legend";
  21. CHAR szElementN[] = "Element %u Color/Pattern";
  22. VOID
  23. WriteProfile(
  24. VOID
  25. )
  26. {
  27. CHAR SectionLocation[128], SectionMapping[128];
  28. HKEY Key1, Key2;
  29. RECT rc;
  30. CHAR text[100],text2[100];
  31. int i;
  32. DWORD Disposition;
  33. LONG Err;
  34. #ifdef JAPAN
  35. //Don't use IDS_APPNAME as registry key,
  36. //because it is also used window's caption and it was localized.
  37. #else
  38. LoadStringA(hModule,IDS_APPNAME,SectionName,sizeof(SectionName));
  39. #endif
  40. // Make sure that the appropriate registry keys exits:
  41. //
  42. // windisk.ini key:
  43. //
  44. Err = RegCreateKeyExA( HKEY_LOCAL_MACHINE,
  45. "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\IniFileMapping\\windisk.ini",
  46. 0,
  47. NULL,
  48. REG_OPTION_NON_VOLATILE,
  49. KEY_WRITE,
  50. NULL,
  51. &Key1,
  52. &Disposition );
  53. if( Err != ERROR_SUCCESS ) {
  54. return;
  55. }
  56. if( Disposition == REG_CREATED_NEW_KEY ) {
  57. // We need to set up the registry keys for the INI mapping.
  58. // First, create the Disk Administrator value on the windisk.ini
  59. // key, which indicates the location of the key which maps
  60. // the Disk Administrator section.
  61. //
  62. strcpy( SectionLocation, "Software\\Microsoft\\" );
  63. strcat( SectionLocation, SectionName );
  64. strcpy( SectionMapping, "USR:" );
  65. strcat( SectionMapping, SectionLocation );
  66. Err = RegSetValueEx( Key1,
  67. SectionName,
  68. 0,
  69. REG_SZ,
  70. SectionMapping,
  71. strlen( SectionMapping ) + 1 );
  72. if( Err != ERROR_SUCCESS ) {
  73. RegCloseKey( Key1 );
  74. return;
  75. }
  76. // Now create the key to which the section mapping points:
  77. //
  78. Err = RegCreateKeyEx( HKEY_CURRENT_USER,
  79. SectionLocation,
  80. 0,
  81. NULL,
  82. REG_OPTION_NON_VOLATILE,
  83. KEY_WRITE,
  84. NULL,
  85. &Key2,
  86. &Disposition );
  87. RegCloseKey( Key2 );
  88. }
  89. RegCloseKey( Key1 );
  90. // OK, the registry location is set up. Write the initialization
  91. // information.
  92. //
  93. // write window position
  94. GetWindowRect(hwndFrame,&rc);
  95. wsprintf(text,
  96. szWindowPosFormatString,
  97. ProfileWindowX,
  98. ProfileWindowY,
  99. ProfileWindowW,
  100. ProfileWindowH
  101. );
  102. WritePrivateProfileStringA(SectionName,szWindowPosition,text,"windisk.ini");
  103. wsprintf(text,"%u",IsZoomed(hwndFrame));
  104. WritePrivateProfileStringA(SectionName,szWindowMaximized,text,"windisk.ini");
  105. wsprintf(text,"%u",IsIconic(hwndFrame));
  106. WritePrivateProfileStringA(SectionName,szWindowIconic,text,"windisk.ini");
  107. // status bar and legend stuff
  108. wsprintf(text,
  109. "%u",
  110. StatusBar
  111. );
  112. WritePrivateProfileStringA(SectionName,szStatusBar,text,"windisk.ini");
  113. wsprintf(text,
  114. "%u",
  115. Legend
  116. );
  117. WritePrivateProfileStringA(SectionName,szLegend,text,"windisk.ini");
  118. // disk graph colors/patterns
  119. for(i=0; i<LEGEND_STRING_COUNT; i++) {
  120. wsprintf(text2,szElementN,i);
  121. wsprintf(text,"%u/%u",BrushColors[i],BrushHatches[i]);
  122. WritePrivateProfileStringA(SectionName,text2,text,"windisk.ini");
  123. }
  124. }
  125. VOID
  126. ReadProfile(
  127. VOID
  128. )
  129. {
  130. CHAR text[100],text2[100];
  131. int i;
  132. #ifdef JAPAN
  133. //Don't use IDS_APPNAME as registry key,
  134. //because it is also used window's caption and it was localized.
  135. #else
  136. LoadStringA(hModule,IDS_APPNAME,SectionName,sizeof(SectionName));
  137. #endif
  138. // get the window position data
  139. ProfileIsMaximized = GetPrivateProfileIntA(SectionName,szWindowMaximized,0,"windisk.ini");
  140. ProfileIsIconic = GetPrivateProfileIntA(SectionName,szWindowIconic ,0,"windisk.ini");
  141. *text = 0;
  142. if(GetPrivateProfileStringA(SectionName,szWindowPosition,"",text,sizeof(text),"windisk.ini")
  143. && *text)
  144. {
  145. sscanf(text,
  146. szWindowPosFormatString,
  147. &ProfileWindowX,
  148. &ProfileWindowY,
  149. &ProfileWindowW,
  150. &ProfileWindowH
  151. );
  152. } else {
  153. ProfileWindowX = CW_USEDEFAULT;
  154. ProfileWindowY = 0;
  155. ProfileWindowW = CW_USEDEFAULT;
  156. ProfileWindowH = 0;
  157. }
  158. // status bar and legend stuff
  159. StatusBar = GetPrivateProfileIntA(SectionName,szStatusBar,1,"windisk.ini");
  160. Legend = GetPrivateProfileIntA(SectionName,szLegend ,1,"windisk.ini");
  161. // disk graph colors/patterns
  162. for(i=0; i<LEGEND_STRING_COUNT; i++) {
  163. wsprintf(text2,szElementN,i);
  164. *text = 0;
  165. if(GetPrivateProfileStringA(SectionName,text2,"",text,sizeof(text),"windisk.ini") && *text) {
  166. sscanf(text,"%u/%u",&BrushColors[i],&BrushHatches[i]);
  167. if( BrushHatches[i] >= NUM_AVAILABLE_HATCHES ) {
  168. BrushHatches[i] = NUM_AVAILABLE_HATCHES - 1;
  169. }
  170. }
  171. }
  172. }