示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            // Get selected restore point
            SystemRestoreItem selectedSystemRestoreItem = null;
            string            time = lvRestorePoints.Items[lvRestorePoints.SelectedIndices[0]].Text;
            DateTime          selectedCreationTime = DateTime.Parse(time);

            foreach (SystemRestoreItem sri in systemRestorePoints)
            {
                if (sri.CreationTime.ToLocalTime().CompareTo(selectedCreationTime) == 0)
                {
                    selectedSystemRestoreItem = sri;
                    break;
                }
            }

            if (selectedSystemRestoreItem.SequenceNumber > 0)
            {
                // Need to display are you sure dialog!
                string           prompt = "Are you sure you want to remove system restore point?";
                TaskDialogResult tdr    = TaskDialog.Show(this, selectedSystemRestoreItem.CreationTime.ToString() + "\n" + selectedSystemRestoreItem.Description, prompt, this.Text, TaskDialogButtons.Yes | TaskDialogButtons.No, TaskDialogIcon.Warning);

                // If the user is sure
                if (tdr == TaskDialogResult.Yes)
                {
                    // Remove the restore point
                    uint result = VolumeNativeMethods.SRRemoveRestorePoint(selectedSystemRestoreItem.SequenceNumber);

                    // If success
                    if (result == 0)
                    {
                        // Update internal data on system restore points and shadow storage
                        systemRestorePoints = new SystemRestorePoints();
                        shadowStorage       = new ShadowStorage();

                        lblDiskSpace.Text = shadowStorage.UsedSpaceString;
                        UpdateListView(sender, e);

                        // Only show chkOlder if there are older restore points
                        int olderCount = 0;

                        foreach (SystemRestoreItem sri in systemRestorePoints)
                        {
                            if (sri.CreationTime.ToLocalTime().CompareTo(DateTime.Now.Subtract(TimeSpan.FromDays(5))) < 0)
                            {
                                olderCount++;
                            }
                        }

                        if (olderCount > 0)
                        {
                            chkHideNewest.Visible = true;
                        }
                        else
                        {
                            chkHideNewest.Visible = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error deleting restore point");
                    }
                }
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            // Get selected restore point
            SystemRestoreItem selectedSystemRestoreItem = null;
            string time = lvRestorePoints.Items[lvRestorePoints.SelectedIndices[0]].Text;
            DateTime selectedCreationTime = DateTime.Parse(time);

            foreach (SystemRestoreItem sri in systemRestorePoints)
            {
                if (sri.CreationTime.ToLocalTime().CompareTo(selectedCreationTime) == 0)
                {
                    selectedSystemRestoreItem = sri;
                    break;
                }
            }

            if (selectedSystemRestoreItem.SequenceNumber > 0)
            {
                // Need to display are you sure dialog!
                string prompt = "Are you sure you want to remove system restore point?";
                TaskDialogResult tdr = TaskDialog.Show(this, selectedSystemRestoreItem.CreationTime.ToString() + "\n" + selectedSystemRestoreItem.Description, prompt, this.Text, TaskDialogButtons.Yes | TaskDialogButtons.No, TaskDialogIcon.Warning);

                // If the user is sure
                if (tdr == TaskDialogResult.Yes)
                {
                    // Remove the restore point
                    uint result = VolumeNativeMethods.SRRemoveRestorePoint(selectedSystemRestoreItem.SequenceNumber);

                    // If success
                    if (result == 0)
                    {
                        // Update internal data on system restore points and shadow storage
                        systemRestorePoints = new SystemRestorePoints();
                        shadowStorage = new ShadowStorage();

                        lblDiskSpace.Text = shadowStorage.UsedSpaceString;
                        UpdateListView(sender, e);

                        // Only show chkOlder if there are older restore points
                        int olderCount = 0;

                        foreach (SystemRestoreItem sri in systemRestorePoints)
                        {
                            if (sri.CreationTime.ToLocalTime().CompareTo(DateTime.Now.Subtract(TimeSpan.FromDays(5))) < 0)
                            {
                                olderCount++;
                            }
                        }

                        if (olderCount > 0)
                        {
                            chkHideNewest.Visible = true;
                        }
                        else
                        {
                            chkHideNewest.Visible = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error deleting restore point");
                    }
                }
            }
        }