示例#1
0
 def _credentials_changed():
     """Check if credentials have changed"""
     old_hash = get_setting('credentials_hash')
     username = get_setting('username')
     password = get_setting('password')
     new_hash = ''
     if username or password:
         from hashlib import md5
         new_hash = md5((username + password).encode('utf-8')).hexdigest()
     if new_hash != old_hash:
         set_setting('credentials_hash', new_hash)
         return True
     return False
    def _first_run():
        '''Check if this add-on version is run for the first time'''

        # Get version from settings.xml
        settings_version = get_setting('version', default='')

        # Get version from addon.xml
        addon_version = get_addon_info('version')

        # Compare versions (settings_version was not present in version 1.10.0 and older)
        settings_comp = tuple(map(int, settings_version.split('+')[0].split('.'))) if settings_version != '' else (1, 10, 0)
        addon_comp = tuple(map(int, addon_version.split('+')[0].split('.')))

        if addon_comp > settings_comp:
            # New version found, save addon version to settings
            set_setting('version', addon_version)
            return True, settings_version, addon_version

        return False, settings_version, addon_version
    def _version_check(self):
        first_run, settings_version, addon_version = self._first_run()
        if first_run:
            # 2.2.3 version: max_log_level to be an integer
            try:
                int(get_setting('max_log_level', 0))  # May return string
            except ValueError:
                set_setting('max_log_level', 0)

            # 2.0.0 version: changed plugin:// url interface: show warning that Kodi favourites and what-was-watched will break
            if settings_version == '' and has_credentials():
                ok_dialog(localize(30978), localize(30979))

            if addon_version == '2.2.1':
                # 2.2.1 version: changed artwork: delete old cached artwork
                delete_cached_thumbnail(
                    get_addon_info('fanart').replace('.png', '.jpg'))
                delete_cached_thumbnail(get_addon_info('icon'))
                # 2.2.1 version: moved tokens: delete old tokens
                from tokenresolver import TokenResolver
                TokenResolver().delete_tokens()