using Base.Utility;
using Microsoft.Win32; 
using System.Collections.Generic;
using System.Linq; 
using 常用工具集.Base;

namespace 常用工具集.ViewModel._04破解及系统相关
{
    public class 删除WPS图标ViewModel : ViewModelBase
    {
        private string name1 = "{7AE6DE87-C956-4B40-9C89-3D166C9841D3}";
        private string name2 = "{5FCD4425-CA3A-48F4-A57C-B8A75C32ACB1}";
        private string name3 = "{19ADA707-057F-45EF-8985-305FEE233FAB}";
        public DelegateCommand ClearCmd { get; set; }
        public 删除WPS图标ViewModel()
        {
            ClearCmd = new DelegateCommand(ClearCmdFunc);
        }

        private void ClearCmdFunc(object obj)
        {
            Delete(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\", name2);
            Delete(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\", name1);
            Delete(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\", name2);
            Delete(@"SOFTWARE\Classes\CLSID", name1);
            Delete(@"SOFTWARE\Classes\CLSID", name2);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Classes\CLSID", name1);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Classes\CLSID", name2);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Classes\Wow6432Node\CLSID", name3);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Classes\Wow6432Node\CLSID", name2);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Classes\Wow6432Node\CLSID", name1);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace", name1);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace", name2);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace", name1);
            Delete(@"SOFTWARE\Classes\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace", name2);
            DeleteKey(@"SOFTWARE\Classes\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name1);
            DeleteKey(@"SOFTWARE\Classes\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name2);
            DeleteKey(@"SOFTWARE\Classes\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name1);
            DeleteKey(@"SOFTWARE\Classes\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name2);
            DeleteKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name1);
            DeleteKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name2);
            DeleteKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name1);
            DeleteKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved", name2);
            Delete(@"SOFTWARE\Classes\WOW6432Node\CLSID", name3);
            Delete(@"SOFTWARE\Classes\WOW6432Node\CLSID", name2);
            Delete(@"SOFTWARE\Classes\WOW6432Node\CLSID", name1);
            Delete(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace", name1);
            //重新打开桌面
            DesktopRefurbish.DeskRef();
        }

        private void DeleteKey(string path, string name1)
        {
            try
            {
                RegistryKey user = Registry.CurrentUser;
                RegistryKey key = user.OpenSubKey(path, true);
                key.DeleteValue(name1);
            }
            catch { }
        }

        private void Delete(string path, string name1)
        {
            try
            {
                RegistryKey user = Registry.CurrentUser;
                RegistryKey key = user.OpenSubKey(path, true);
                List<string> names = key.GetSubKeyNames().ToList();
                if (names.Contains(name1))
                {
                    key.DeleteSubKey(name1);
                }
            }
            catch { }
        }
    }
}
