def __init__(self):
        # 確認你的電腦有沒有安裝 AspenPlus
        self.check_aspen_exist()

        # 看看你的電腦裝了什麼版本的 AspenPlus
        self.aspen_version_list()
        self.aspen_version_label_dict()
        self.aspen_version_exe_dit()

        # 將以下三種屬性存起來,等等複製機碼會用到
        self.__CLSID = r.HKEY_CLASSES_ROOT(r"Apwn.Document\CLSID")[''].data
        self.__default_icon = r.HKEY_CLASSES_ROOT(
            r"Apwn.Document\DefaultIcon")[''].data
        self.__default_command = r.HKEY_CLASSES_ROOT(
            r"Apwn.Document\shell\Open\command")[''].data
    def restored_aspen_key(self):
        """
        Restore the AspenPlus key to Default.

        :return: None
        """
        self.delete_aspen_key()  # 如果發現沒有 Apwn.Document.UserDefine 機碼,會直接報錯誤
        r.HKEY_CLASSES_ROOT(".apw")[''] = 'Apwn.Document'
    def modified_aspen_key(self):
        """
        Modified the AspenPlus key to build the secondary list.

        :return: None
        """
        self.create_aspen_key()
        r.HKEY_CLASSES_ROOT(".apw")[''] = 'Apwn.Document.UserDefine'
    def save_curver(self):
        """
        Save the default value of HKEY_CLASSES_ROOT\Apwn.Document\CurVer.

        :return: None
        """
        curver = r.HKEY_CLASSES_ROOT("Apwn.Document").CurVer[''].data

        with open('data', 'wb') as f:
            pickle.dump(curver, f)
    def check_aspen_exist(self):
        """
        Check whether the AspenPlus install or not.

        :return: True for installed AspenPlus
        """
        try:
            r.HKEY_CLASSES_ROOT("Apwn.Document")
            return True
        except AttributeError as e:
            if e == "subkey 'Apwn.Document' does not exist":
                raise ValueError("There is no AspenPlus in the Computer !!")
            else:
                raise Exception(
                    'Unexpect Error, Please Connect to the developer !!')
    def aspen_version_label_dict(self):
        """
        Correspond the version label with version name.

        :return: dict.
        """
        # 先以 version name 找到對應的 version label
        l_list = []
        for version_name in self.__version_list:
            h_key = r.HKEY_CLASSES_ROOT(fr"{version_name}\shell")
            for item in h_key.subkeys():
                if re.match("Open with Aspen Plus V\d+.", item.name):
                    l_list.append(item.name)

        # 然後再將 name 與 label 變成字典
        self.__version_label_dict = dict(zip(self.__version_list, l_list))
    def create_aspen_key(self):
        """
        Create the Apwn.Document.UserDefine Key which contains bunch of keys to build the secondary list.

        :return: None
        """
        # 新增一個自創Aspen機碼
        r.HKEY_CLASSES_ROOT.set_subkey('Apwn.Document.UserDefine', r.Key)

        # 在這個新增的機碼新增 CLSID 機碼與設定其值
        r.HKEY_CLASSES_ROOT('Apwn.Document.UserDefine').set_subkey(
            'CLSID', {'': self.__CLSID})

        # 在這個新增的機碼新增 DefaultIcon 機碼與其設定值
        r.HKEY_CLASSES_ROOT('Apwn.Document.UserDefine').set_subkey(
            'DefaultIcon',
            {'': self.__default_icon})  # 在這個新增的機碼新增 DefaultIcon 機碼與其設定值

        # 在這個新增的機碼新增 shell\Open\Comman 機碼與其設定值
        r.HKEY_CLASSES_ROOT(r'Apwn.Document.UserDefine').set_subkey(
            'shell', {'': 'Open'})
        r.HKEY_CLASSES_ROOT(r'Apwn.Document.UserDefine\shell').set_subkey(
            'Open', {'': '&Open'})
        r.HKEY_CLASSES_ROOT(r'Apwn.Document.UserDefine\shell\Open').set_subkey(
            'command', {'': self.__default_command})

        # 在這個新增的機碼新增 shell\openaspen\shell\[open1, open2...] 機碼與其設定值
        r.HKEY_CLASSES_ROOT(r'Apwn.Document.UserDefine\shell').set_subkey(
            'openaspen', {
                '': '',
                "MUIVerb": "Open with Aspen Plus",
                "subcommands": ""
            })
        r.HKEY_CLASSES_ROOT(
            r'Apwn.Document.UserDefine\shell\openaspen').set_subkey(
                'shell', r.Key)
        h_key = r.HKEY_CLASSES_ROOT(
            r'Apwn.Document.UserDefine\shell\openaspen\shell')

        # 把次級選單的名子、執行檔路徑新增進去!
        for num_version, version in enumerate(self.__version_list):
            h_key.set_subkey(f'open{num_version}',
                             {'': self.__version_label_dict[version]})
            h_key(f'open{num_version}').set_subkey(
                'command', {'': self.__version_exe_dict[version]})
    def aspen_version_exe_dit(self):
        """
        Correspond the executive path with version name.

        :return: dict.
        """
        # 先以 version name 找到對應的 path
        e_list = []
        for version_name in self.__version_list:
            h_key = r.HKEY_CLASSES_ROOT(
                f"{version_name}\shell\{self.__version_label_dict[version_name]}\command"
            )
            e_list.append(h_key[''].data)

        # 再將 name 與 exe path 變成字典
        self.__version_exe_dict = dict(zip(self.__version_list, e_list))