From f2ffa26b8520f24ce39e4b0132838c77799410e1 Mon Sep 17 00:00:00 2001 From: Amine Date: Fri, 13 Aug 2021 13:42:38 +0200 Subject: [PATCH 1/3] Implement addon upgrade mechanism --- addon.xml | 2 +- resources/main.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 3adb65b..fc4401d 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + diff --git a/resources/main.py b/resources/main.py index 71a920a..9a22983 100644 --- a/resources/main.py +++ b/resources/main.py @@ -232,6 +232,22 @@ def main(): # first time run, store version __addon__.setSetting('version', __addon__.getAddonInfo('version')) + else: + previous_version= __addon__.getSetting('version').split(".") + previous_version= list(map(int, previous_version)) + + new_version= __addon__.getSetting('version').split(".") + new_version= list(map(int,new_version)) + + if previous_version[0] == 0 & previous_version[1] < 8: + #Starting with 0.8.0, the cache encoding changed and previous caches needs to be reset. + delete_cache() + + # Insert version upgrade mechanisms here before the following call + + __addon__.setSetting('version', __addon__.getAddonInfo('version')) + + # prompt the user to configure the plugin with their steam details if not all_required_credentials_available(): __addon__.openSettings() From 0ae1de00997372909529e062bb9d8975d1cbadbc Mon Sep 17 00:00:00 2001 From: Amine Date: Fri, 13 Aug 2021 15:20:19 +0200 Subject: [PATCH 2/3] Handle more scenarios in delete_cache() methods Properly recreates tables if the file had to be deleted --- resources/arts.py | 12 +++++++++++- resources/steam.py | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/resources/arts.py b/resources/arts.py index da47582..ed1c039 100644 --- a/resources/arts.py +++ b/resources/arts.py @@ -98,4 +98,14 @@ def delete_cache(): """ Deletes the cache containing the data about which art types are available or not """ - os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite") + # If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves + try: + cached_requests.cache.clear() + except Exception: + log('Failed to clear cache. Attempting manual deletion') + try: + os.remove(ART_AVAILABILITY_CACHE_FILE + ".sqlite") + except: + log('Failed to delete cache file') + cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'responses', fast_save=True) + cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(ART_AVAILABILITY_CACHE_FILE + ".sqlite", 'urls') diff --git a/resources/steam.py b/resources/steam.py index cfc58a0..539a1ca 100644 --- a/resources/steam.py +++ b/resources/steam.py @@ -20,7 +20,7 @@ STEAM_GAMES_CACHE_FILE = xbmc.translatePath(os.path.join(addonUserDataFolder, 'requests_cache_games')) # cache expires after: 86400=1 day 604800=7 days -cached_requests = requests_cache.core.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite', +cached_requests = requests_cache.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite', expire_after=60 * minutesBeforeGamesListsExpiration, old_data_on_error=True) @@ -106,4 +106,18 @@ def get_user_games(steam_api_key, steam_user_id, recent_only=False): def delete_cache(): - os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite") + """ + Deletes the cache containing the data about which games are owned or not + """ + # If Kodi's request-cache module is updated to >0.7.3 , we will only need to issue cached_requests.cache.clear() which will handle all scenarios. Until then, we must recreate the backend ourselves + try: + cached_requests.cache.clear() + except Exception: + log('Failed to clear cache. Attempting manual deletion') + try: + os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite") + except: + log('Failed to delete & recreate cache') + cached_requests.cache.responses = requests_cache.backends.storage.dbdict.DbPickleDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'responses', fast_save=True) + cached_requests.cache.keys_map = requests_cache.backends.storage.dbdict.DbDict(STEAM_GAMES_CACHE_FILE + ".sqlite", 'urls') + \ No newline at end of file From d2610e27fc7de798947bb99dcd9b56b81e891ae5 Mon Sep 17 00:00:00 2001 From: Amine Date: Fri, 13 Aug 2021 15:20:40 +0200 Subject: [PATCH 3/3] Bump dependencies version numbers --- addon.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon.xml b/addon.xml index fc4401d..6d46913 100644 --- a/addon.xml +++ b/addon.xml @@ -2,8 +2,8 @@ - - + +