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.

120 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. SystemRestore.cpp
  5. Abstract:
  6. Implements a function to set/clear
  7. a system restore point.
  8. Notes:
  9. Unicode only.
  10. History:
  11. 04/09/2001 markder Created
  12. --*/
  13. #include "precomp.h"
  14. #include "srrestoreptapi.h"
  15. extern SETUP_INFO g_si;
  16. STATEMGRSTATUS g_SMgrStatus = { NULL };
  17. RESTOREPOINTINFO g_RestPtInfo = { NULL };
  18. BOOL SystemRestorePointStart(BOOL bInstall)
  19. {
  20. ZeroMemory(&g_SMgrStatus, sizeof(STATEMGRSTATUS));
  21. ZeroMemory(&g_RestPtInfo, sizeof(RESTOREPOINTINFO));
  22. // Initialize the RESTOREPOINTINFO structure
  23. g_RestPtInfo.dwEventType = BEGIN_SYSTEM_CHANGE;
  24. // Notify the system that changes are about to be made.
  25. // An application is to be installed/uninstalled.
  26. g_RestPtInfo.dwRestorePtType = bInstall ? APPLICATION_INSTALL : APPLICATION_UNINSTALL;
  27. // Set g_RestPtInfo.llSequenceNumber.
  28. g_RestPtInfo.llSequenceNumber = 0;
  29. // String to be displayed by System Restore for this restore point.
  30. if (0 == LoadString(g_si.hInstance,
  31. bInstall ? IDS_SYSRESTORE_INST_LABEL : IDS_SYSRESTORE_UNINST_LABEL,
  32. g_RestPtInfo.szDescription, MAX_DESC))
  33. {
  34. printf("Couldn't get friendly name for restore point.\n");
  35. return FALSE;
  36. }
  37. // Notify the system that changes are to be made and that
  38. // the beginning of the restore point should be marked.
  39. if(!SRSetRestorePoint(&g_RestPtInfo, &g_SMgrStatus))
  40. {
  41. printf("Couldn't set the beginning of the restore point.\n");
  42. return FALSE;
  43. }
  44. return TRUE;
  45. }
  46. BOOL SystemRestorePointEnd()
  47. {
  48. if (g_SMgrStatus.llSequenceNumber == 0)
  49. {
  50. return TRUE;
  51. }
  52. // Initialize the RESTOREPOINTINFO structure to notify the
  53. // system that the operation is finished.
  54. g_RestPtInfo.dwEventType = END_SYSTEM_CHANGE;
  55. // End the system change by returning the sequence number
  56. // received from the first call to SRSetRestorePoint.
  57. g_RestPtInfo.llSequenceNumber = g_SMgrStatus.llSequenceNumber;
  58. // Notify the system that the operation is done and that this
  59. // is the end of the restore point.
  60. if(!SRSetRestorePoint(&g_RestPtInfo, &g_SMgrStatus))
  61. {
  62. printf("Couldn't set the end of the restore point.\n");
  63. return FALSE;
  64. }
  65. ZeroMemory(&g_SMgrStatus, sizeof(STATEMGRSTATUS));
  66. return TRUE;
  67. }
  68. BOOL SystemRestorePointCancel()
  69. {
  70. if (g_SMgrStatus.llSequenceNumber == 0)
  71. {
  72. return TRUE;
  73. }
  74. // Restore Point Spec to cancel the previous restore point.
  75. g_RestPtInfo.dwEventType=END_SYSTEM_CHANGE;
  76. g_RestPtInfo.dwRestorePtType=CANCELLED_OPERATION;
  77. g_RestPtInfo.llSequenceNumber=g_SMgrStatus.llSequenceNumber;
  78. // Canceling the previous restore point
  79. if (!SRSetRestorePoint(&g_RestPtInfo, &g_SMgrStatus))
  80. {
  81. printf("Couldn't cancel restore point.\n");
  82. return FALSE;
  83. }
  84. printf("Restore point canceled. Restore point data:\n");
  85. printf("Sequence Number=%lld\n",g_SMgrStatus.llSequenceNumber);
  86. printf("Status=%u\n",g_SMgrStatus.nStatus);
  87. ZeroMemory(&g_SMgrStatus, sizeof(STATEMGRSTATUS));
  88. return TRUE;
  89. }