コード例 #1
0
        void RemoveItems()
        {
            ABORT = false;
            bool result = false;
            try
            {
                cLightning lightning = new cLightning();
                // iterate through and remove
                ObservableCollection<ScanData> itemsToDelete = new ObservableCollection<ScanData>();
                int i = 0;
                foreach (ScanData o in RegistrySubCategories)
                {
                    i++;
                    if (ABORT)
                    {
                        cancelComplete();
                        return;
                    }
                    if (o.Check)
                    {
                        switch (o.Id)
                        {
                            // delete value
                            case 1:
                            case 2:
                            case 3:
                            case 4:
                            case 5:
                            case 7:
                            case 9:
                            case 10:
                            case 11:
                            case 12:
                            case 13:
                            case 14:
                            case 15:
                            case 16:
                            case 17:
                            case 18:
                            case 19:
                            case 21:
                            case 22:
                            case 23:
                            case 24:
                            case 25:
                            case 26:
                            case 27:
                                {
                                    if (o.Value == "Default")
                                    {
                                        o.Value = string.Empty;
                                    }

                                    result = lightning.DeleteValue(o.Root, o.Key, o.Value);
                                    if (result == false)
                                    {
                                        ModSecVal(o.Root, o.Key, cSecurity.InheritenceFlags.Child_Inherit_Level);
                                        result = lightning.DeleteValue(o.Root, o.Key, o.Value);
                                    }

                                    callback((int)((double)i / RegistrySubCategories.Count() * 100), o.Key);

                                    itemsToDelete.Add(o);
                                    break;
                                }
                            // delete key
                            case 6:
                            case 8:
                                {
                                    result = (lightning.DeleteKey(o.Root, o.Key));
                                    if (result == false)
                                    {
                                        ModSecVal(o.Root, o.Key, cSecurity.InheritenceFlags.Container_Inherit);
                                        result = lightning.DeleteValue(o.Root, o.Key, o.Value);
                                    }

                                    callback((int)((double)i / RegistrySubCategories.Count() * 100), o.Key);

                                    itemsToDelete.Add(o);
                                    break;
                                }
                            // recreate value
                            case 20:
                                {
                                    result = (lightning.DeleteValue(o.Root, o.Key, o.Value));
                                    lightning.WriteMulti(o.Root, o.Key, "VDD", string.Empty);

                                    callback((int)((double)i / RegistrySubCategories.Count() * 100), o.Key);

                                    itemsToDelete.Add(o);
                                    break;
                                }
                        }
                    }
                }

                foreach (ScanData o in itemsToDelete)
                {
                    if (ABORT)
                    {
                        cancelComplete();
                        return;
                    }

                    RegistrySubCategories.Remove(o);
                }

                removedItemsCount = itemsToDelete.Count;
            }
            catch (Exception ex)
            {
                // ToDo: send exception details via SmartAssembly bug reporting!
            }

            complete(fixAfterScan);
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: nullkuhl/fsu-dev
        /// <summary>
        /// Removes items
        /// </summary>
        void RemoveItems()
        {
            try
            {
                bool ret = false;

                // test for checked items first
                bool val = RegistrySubCategories.Any(o => o.Check);
                if (val)
                {
                    //set a restore point
                    bool res = Settings.Default.SettingRestore;
                    if (res)
                    {
                        MessageBoxResult chc = MessageBox.Show(Properties.Resources.WouldYouLikeToCreateRestorePoint,
                                                               Properties.Resources.SystemRestore, MessageBoxButton.YesNo,
                                                               MessageBoxImage.Question);
                        if (chc == MessageBoxResult.Yes)
                        {
                            // restore visual
                            RestoreProgressStart();

                            if (!_bRestoreSucess)
                            {
                                RestoreProgressStop();
                                res = false;

                                // Simplified code for a message box that just say: sys restore disabled, please, enable it
                                MessageBoxResult msg = MessageBox.Show(
                                    Properties.Resources.SystemRestoreUnavailableRunFixAnyway,
                                    Properties.Resources.RestoreDisabled,
                                    MessageBoxButton.YesNo);
                                if (msg == MessageBoxResult.No)
                                {
                                    return;
                                }
                            }
                            else
                            {
                                RestoreProgressStop();
                            }
                        }
                    }

                    cLightning lightning = new cLightning();

                    // iterate through and remove
                    var itemsToDelete = new ObservableCollection<ScanData>();

                    foreach (ScanData o in RegistrySubCategories)
                    {
                        if (o.Check)
                        {
                            switch (o.Id)
                            {
                                // delete value
                                case 1:
                                case 2:
                                case 3:
                                case 4:
                                case 5:
                                case 7:
                                case 9:
                                case 10:
                                case 11:
                                case 12:
                                case 13:
                                case 14:
                                case 15:
                                case 16:
                                case 17:
                                case 18:
                                case 19:
                                case 21:
                                case 22:
                                case 23:
                                case 24:
                                case 25:
                                case 26:
                                case 27:
                                    {
                                        if (o.Value == "Default")
                                            o.Value = string.Empty;

                                        ret = lightning.DeleteValue(o.Root, o.Key, o.Value);
                                        if (ret == false)
                                        {
                                            ModSecVal(o.Root, o.Key, cSecurity.InheritenceFlags.Child_Inherit_Level);
                                            ret = lightning.DeleteValue(o.Root, o.Key, o.Value);
                                        }
                                        itemsToDelete.Add(o);
                                        break;
                                    }
                                // delete key
                                case 6:
                                case 8:
                                    {
                                        ret = (lightning.DeleteKey(o.Root, o.Key));
                                        if (ret == false)
                                        {
                                            ModSecVal(o.Root, o.Key, cSecurity.InheritenceFlags.Container_Inherit);
                                            ret = lightning.DeleteValue(o.Root, o.Key, o.Value);
                                        }
                                        itemsToDelete.Add(o);
                                        break;
                                    }
                                // recreate value
                                case 20:
                                    {
                                        ret = (lightning.DeleteValue(o.Root, o.Key, o.Value));
                                        lightning.WriteMulti(o.Root, o.Key, "VDD", "");
                                        itemsToDelete.Add(o);
                                        break;
                                    }
                            }
                        }
                    }

                    foreach (ScanData o in itemsToDelete)
                    {
                        RegistrySubCategories.Remove(o);
                    }

                    // finalize restore
                    if (res)
                    {
                        _Restore.EndRestore(false);
                    }

                    // set AllSubcategoriesChecked to false as we removed all checked items
                    AllSubcategoriesChecked = false;

                    removedItemsCount = itemsToDelete.Count;

                    SetStatus(OperationStatus.CleaningFinished);
                }
                else
                {
                    MessageBoxResult can = MessageBox.Show(Properties.Resources.SelectItemsToRemove,
                                                           Properties.Resources.NoItemsSelected, MessageBoxButton.OK,
                                                           MessageBoxImage.Exclamation);
                }
            }
            catch (Exception)
            {
            }
        }