Ejemplo n.º 1
0
        private void buttonRestore_Click(object sender, EventArgs e)
        {
            long lSeqNum = 0;

            if (this.listViewFiles.SelectedIndices.Count > 0 && this.listViewFiles.Items.Count > 0)
            {
                string strFile     = this.listViewFiles.SelectedItems[0].Text;
                string strFilePath = string.Format("{0}\\{1}", Properties.Settings.Default.strOptionsBackupDir, strFile);

                if (!File.Exists(strFilePath))
                {
                    MessageBox.Show(this, Properties.Resources.restoreFileNotFound, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // Remove from list
                    this.listViewFiles.Items[this.listViewFiles.SelectedItems[0].Index].Remove();

                    // Clear selection
                    this.listViewFiles.SelectedItems.Clear();

                    return;
                }

                if (MessageBox.Show(this, Properties.Resources.restoreAsk, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    SysRestore.StartRestore("Before Little Registry Cleaner Restore", out lSeqNum);

                    if (xmlReg.loadAsXml(xmlReader, strFilePath))
                    {
                        MessageBox.Show(this, Properties.Resources.restoreRestored, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (Properties.Settings.Default.bOptionsDelBackup)
                        {
                            File.Delete(strFilePath);
                            this.listViewFiles.SelectedItems[0].Remove();
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, Properties.Resources.restoreError, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    SysRestore.EndRestore(lSeqNum);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// If problems were found, removes them from registry
        /// </summary>
        private void FixProblems()
        {
            xmlRegistry xmlReg  = new xmlRegistry();
            long        lSeqNum = 0;

            if (this.treeModel.Nodes.Count > 0)
            {
                if (!Properties.Settings.Default.bOptionsAutoRepair)
                {
                    if (MessageBox.Show(this, Properties.Resources.mainProblemsFix, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                    {
                        return;
                    }
                }

                // Send usage data to Little Software Stats
                Watcher.Event("Functions", "Fix Problems");

                // Create Restore Point
                SysRestore.StartRestore("Before Little Registry Cleaner Registry Fix", out lSeqNum);

                // Generate filename to backup registry
                string strBackupFile = string.Format("{0}\\{1:yyyy}_{1:MM}_{1:dd}_{1:HH}{1:mm}{1:ss}.xml", Properties.Settings.Default.strOptionsBackupDir, DateTime.Now);

                BadRegKeyArray arrBadRegKeys = new BadRegKeyArray();
                foreach (BadRegistryKey badRegKeyRoot in this.treeModel.Nodes)
                {
                    foreach (BadRegistryKey badRegKey in badRegKeyRoot.Nodes)
                    {
                        if (badRegKey.Checked == CheckState.Checked)
                        {
                            arrBadRegKeys.Add(badRegKey);
                        }
                    }
                }

                // Generate a restore file and delete keys & values
                xmlReg.deleteAsXml(arrBadRegKeys, strBackupFile);

                SysRestore.EndRestore(lSeqNum);

                // Disable menu items
                this.fixToolStripMenuItem.Enabled = false;
                this.toolStripButtonFix.Enabled   = false;

                // Clear status text
                ResourceManager rm = new ResourceManager(this.GetType());
                this.toolStripStatusLabel1.Text = rm.GetString("toolStripStatusLabel1.Text");
                this.toolStripStatusLabel1.Tag  = "toolStripStatusLabel1.Text";

                // Display message box
                if (!Properties.Settings.Default.bOptionsAutoExit)
                {
                    MessageBox.Show(this, Properties.Resources.mainProblemsRemoved, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                // Clear old results
                this.treeModel.Nodes.Clear();

                // If power user option selected, Automatically exit program
                if (Properties.Settings.Default.bOptionsAutoExit)
                {
                    this.bDisplayExitMsgBox = false;
                    this.Close();
                    return;
                }

                // Scan again
                if (Properties.Settings.Default.bOptionsRescan)
                {
                    ScanRegistry();
                }
            }
        }