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.

260 lines
9.0 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. * rplog.cpp
  7. *
  8. * Abstract:
  9. * Tool for enumerating the restore points - forward/reverse
  10. *
  11. * Revision History:
  12. * Brijesh Krishnaswami (brijeshk) 04/13/2000
  13. * created
  14. * SHeffner, I just copied this source, and using the existing API's so that
  15. * srdiag will also be in sync as changes occur to the file structure.
  16. *
  17. *****************************************************************************/
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Common Includes
  21. //
  22. //----------------------------------------------------------------------------
  23. #include <windows.h>
  24. #include <shellapi.h>
  25. #include <enumlogs.h>
  26. #include <cab.h>
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Function Proto types
  30. //
  31. //----------------------------------------------------------------------------
  32. void GetRPLogs(HFCI hc, char *szLogFile, WCHAR *szVolumePath);
  33. void GetSRRPLogs(HFCI hc, WCHAR *szVolumePath, WCHAR *szRPDir, WCHAR *szFileName);
  34. extern void GetRestoreGuid(char *szString); //Gets the restore point GUID, code in main.cpp
  35. //+---------------------------------------------------------------------------
  36. //
  37. // Files to collect for each Restore Point, on all drives.
  38. //
  39. //----------------------------------------------------------------------------
  40. WCHAR *wszRPFileList[] = { TEXT("restorepointsize"),
  41. TEXT("drivetable.txt"),
  42. TEXT("rp.log"),
  43. TEXT("") };
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Types of restorepoints, based off of Brijesh's code
  47. //
  48. //----------------------------------------------------------------------------
  49. WCHAR *szRPDescrip[] = { TEXT("APPLICATION_INSTALL"),
  50. TEXT("APPLICATION_UNINSTALL"),
  51. TEXT("DESKTOP_SETTING"),
  52. TEXT("ACCESSIBILITY_SETTING"),
  53. TEXT("OE_SETTING"),
  54. TEXT("APPLICATION_RUN"),
  55. TEXT("RESTORE"),
  56. TEXT("CHECKPOINT"),
  57. TEXT("WINDOWS_SHUTDOWN"),
  58. TEXT("WINDOWS_BOOT"),
  59. TEXT("DEVICE_DRIVER_CHANGE"),
  60. TEXT("FIRSTRUN"),
  61. TEXT("MODIFY_SETTINGS"),
  62. TEXT("CANCELLED_OPERATION") };
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Simple Array's to say how to print the Month, and Day's
  66. //
  67. //----------------------------------------------------------------------------
  68. WCHAR *szMonth[] = { TEXT("January"), TEXT("Feburary"), TEXT("March"), TEXT("April"), TEXT("May"), TEXT("June"),
  69. TEXT("July"), TEXT("August"), TEXT("September"), TEXT("October"), TEXT("November"), TEXT("December") };
  70. WCHAR *szDay[] = { TEXT("Sunday"), TEXT("Monday"), TEXT("Tuesday"), TEXT("Wednesday"), TEXT("Thursday"), TEXT("Friday"), TEXT("Saturday") };
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Function: RPEnumDrive
  74. //
  75. // Synopsis: Via the FindFirstVolume, and FindNext get all of the valid volumes on the system
  76. // I then transulate this volume, to the actual path and then pass that information
  77. // to GetRPLogs which will get the restore point logs.
  78. //
  79. // Arguments: [hc] -- Handle to my current Cab
  80. // [szLogFile] -- File name and path to where I log my restore point log information.
  81. //
  82. // Returns: void
  83. //
  84. // History: 9/21/00 SHeffner Created
  85. //
  86. //
  87. //----------------------------------------------------------------------------
  88. void RPEnumDrive(HFCI hc, char *szLogFile)
  89. {
  90. WCHAR szString[_MAX_PATH] = {TEXT("")}, szMount[_MAX_PATH] = {TEXT("")};
  91. DWORD dLength = 0, dSize = 0;
  92. HANDLE hVolume = 0, hMount = 0;
  93. dLength = _MAX_PATH;
  94. if( INVALID_HANDLE_VALUE != (hVolume = FindFirstVolume( szString, dLength)) )
  95. {
  96. do
  97. {
  98. dLength = dSize = _MAX_PATH;
  99. //Check to make sure that this is a fixed volume, and then get the change log, else skip.
  100. if ( DRIVE_FIXED == GetDriveType(szString) )
  101. {
  102. //First get the Friendly name for the current Volume, and get log
  103. GetVolumePathNamesForVolumeName(szString, szMount, _MAX_PATH, &dSize);
  104. GetRPLogs(hc, szLogFile, szMount);
  105. }
  106. } while (TRUE == FindNextVolume(hVolume, szString, dLength) );
  107. }
  108. //Cleanup code
  109. FindVolumeClose(hVolume);
  110. }
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Function: GetRPLogs
  114. //
  115. // Synopsis: This will enumerate the restore points on the volume path that is provided, writting
  116. // this information out the logfile specified.
  117. //
  118. // Arguments: [hc] -- Handle to my current Cab
  119. // [szLogFile] -- File name and path to where I log my restore point log information.
  120. // [szVolumePath] -- Path to the Volume for the restore point API to work.
  121. //
  122. // Returns: void
  123. //
  124. // History: 9/21/00 SHeffner Created
  125. //
  126. //
  127. //----------------------------------------------------------------------------
  128. void GetRPLogs(HFCI hc, char *szLogFile, WCHAR *szVolumePath)
  129. {
  130. INT64 i64Size=0;
  131. int iCount=0;
  132. WCHAR szString[_MAX_PATH] = {TEXT("")};
  133. char szRestoreGuid[_MAX_PATH] = {""};
  134. RESTOREPOINTINFOW pRpinfo;
  135. FILETIME *ft;
  136. SYSTEMTIME st;
  137. FILE *fStream = NULL, *fStream2 = NULL;
  138. //Initialization of the Restore point
  139. CRestorePointEnum RPEnum(szVolumePath, TRUE, FALSE);
  140. CRestorePoint RP;
  141. DWORD dwRc;
  142. //Get restore GUID, and open up log file, and write out our mount point
  143. GetRestoreGuid(szRestoreGuid);
  144. fStream = fopen(szLogFile, "a");
  145. fprintf(fStream, "\nProcessing Mount Point [%S]\n", szVolumePath);
  146. // If we have a valid restore point, enumerate through all of them and log the results.
  147. if (ERROR_SUCCESS == RPEnum.FindFirstRestorePoint(RP))
  148. {
  149. do
  150. {
  151. //Get RestorePoint Size for the restore point log.
  152. swprintf(szString, L"%sSystem Volume Information\\_restore%S\\%s\\restorepointsize", szVolumePath, szRestoreGuid, RP.GetDir());
  153. if( NULL != (fStream2 = _wfopen(szString, L"r")) )
  154. {
  155. fread(&i64Size, sizeof(i64Size), 1, fStream2);
  156. fclose(fStream2);
  157. }
  158. else {
  159. i64Size=0;
  160. }
  161. if (RP.GetName() == NULL) // not system-drive
  162. {
  163. //format should be field=value, field=value, ...
  164. fprintf(fStream, "DirectoryName=%S, Size=%I64ld, Number=%ul\n",
  165. RP.GetDir(), i64Size, RP.GetNum());
  166. }
  167. else
  168. {
  169. //Get the time, and then convert it to localsystemtime, and then pump out the rest of the DataStructures
  170. ft = RP.GetTime();
  171. FileTimeToSystemTime( ft, &st);
  172. //format should be field=value, field=value, ...
  173. fprintf(fStream, "DirectoryName=%S, Size=%I64ld, Type=%ld[%S], RestorePointName=%S, RestorePointStatus=%S, Number=%ul, Date=%S %S %lu, %lu %lu:%lu:%lu\n",
  174. RP.GetDir(), i64Size, RP.GetType(), szRPDescrip[RP.GetType()], RP.GetName(),
  175. RP.IsDefunct() ? TEXT("[Cancelled]") : TEXT("[VALID]"), RP.GetNum(), szDay[st.wDayOfWeek],
  176. szMonth[st.wMonth-1], st.wDay, st.wYear, st.wHour, st.wMinute, st.wSecond);
  177. }
  178. //Now Add-in the files needed per restore point
  179. iCount = 0;
  180. while ( NULL != *wszRPFileList[iCount] )
  181. {
  182. GetSRRPLogs(hc, szVolumePath, RP.GetDir(), wszRPFileList[iCount]);
  183. iCount++;
  184. }
  185. } while (ERROR_SUCCESS == (dwRc = RPEnum.FindNextRestorePoint(RP)) );
  186. RPEnum.FindClose();
  187. }
  188. else
  189. {
  190. fprintf(fStream, "No restore points for Mount Point [%S]\n", szVolumePath);
  191. }
  192. //Close up file Handle
  193. fclose (fStream); //close out the file handle
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Function: GetSRRPLogs
  198. //
  199. // Synopsis: Routine will figure out 1) where the file in question is, 2) copy it to the temp directory
  200. // with the new name, 3) add to cab, 4) nuke temp file
  201. //
  202. // Arguments: [hc] -- Handle to my current Cab
  203. // [szVolumePath] -- File name and path to where I log my restore point log information.
  204. // [szRPDir] -- Name of the restore point directory
  205. // [szFileName] -- Name of the file in the restore point directory to collect
  206. //
  207. // Returns: void
  208. //
  209. // History: 9/21/00 SHeffner Created
  210. //
  211. //
  212. //----------------------------------------------------------------------------
  213. void GetSRRPLogs(HFCI hc, WCHAR *szVolumePath, WCHAR *szRPDir, WCHAR *szFileName)
  214. {
  215. char *szTest[1], *pszLoc;
  216. char szRestoreGuid[_MAX_PATH];
  217. char szTemp[_MAX_PATH], szSource[_MAX_PATH], szDest[_MAX_PATH];
  218. //Get restore GUID, and build the source path
  219. GetRestoreGuid(szRestoreGuid);
  220. sprintf(szSource, "%SSystem Volume Information\\_restore%s\\%S\\%S", szVolumePath, szRestoreGuid, szRPDir, szFileName);
  221. //Build Dest Path, swap out the \ and a : for a -
  222. sprintf(szTemp, "%S%S-%S", szVolumePath, szRPDir, szFileName);
  223. while(NULL != (pszLoc = strchr(szTemp, '\\')) )
  224. *pszLoc = '-';
  225. while(NULL != (pszLoc = strchr(szTemp, ':')) )
  226. *pszLoc = '-';
  227. sprintf(szDest, "%s\\%s", getenv("TEMP"), szTemp);
  228. //Copy to new location, overwrite if it exists.
  229. CopyFileA(szSource, szDest, FALSE);
  230. //Now Add to file to the cab file.
  231. szTest[0] = szDest;
  232. test_fci(hc, 1, szTest, "");
  233. DeleteFileA(szDest);
  234. }