From 1c8af7f31b5a3f8def373de661fc6d3494063564 Mon Sep 17 00:00:00 2001 From: Charles Ewert Date: Thu, 21 Sep 2023 14:46:18 -0400 Subject: [PATCH] Move migration logic to functions in their own file --- source/Main.brs | 44 +++------------------------------------ source/migrations.bs | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 source/migrations.bs diff --git a/source/Main.brs b/source/Main.brs index b235cdba1..83400c6e4 100644 --- a/source/Main.brs +++ b/source/Main.brs @@ -61,47 +61,9 @@ sub Main (args as dynamic) as void end if end if - ' Global registry migrations - if isValid(m.global.app.lastRunVersion) and not versionChecker(m.global.app.lastRunVersion, "1.7.0") - ' last app version used was less than 1.7.0 - print "Running 1.7.0 global registry migrations" - ' no longer saving raw password to registry - ' auth token and username are now stored in user settings and not global settings - unset_setting("port") - unset_setting("token") - unset_setting("username") - unset_setting("password") - ' remove saved credentials from saved_servers - saved = get_setting("saved_servers") - if isValid(saved) - savedServers = ParseJson(saved) - if isValid(savedServers.serverList) and savedServers.serverList.Count() > 0 - newServers = { serverList: [] } - for each item in savedServers.serverList - item.Delete("username") - item.Delete("password") - newServers.serverList.Push(item) - end for - set_setting("saved_servers", FormatJson(newServers)) - end if - end if - ' now saving LastRunVersion globally and per user so that we can run user specific registry migrations - ' duplicate LastRunVersion to all user settings in the registry so that we can run user specific migrations - regSections = getRegistrySections() - for each section in regSections - if section <> "Jellyfin" - registry_write("LastRunVersion", m.global.app.version, section) - end if - end for - end if - - ' User registry migrations - if m.global.session.user.lastRunVersion <> invalid and not versionChecker(m.global.session.user.lastRunVersion, "1.7.0") - ' last run version was less than 1.7.0 - print "Running 1.7.0 user registry migrations" - ' no longer saving password to registry - unset_user_setting("password") - end if + ' migrate registry if needed + runGlobalMigrations() + runUserMigrations() ' Save the global last run version of the app if m.global.app.version <> m.global.app.lastRunVersion diff --git a/source/migrations.bs b/source/migrations.bs new file mode 100644 index 000000000..f73dbbbe0 --- /dev/null +++ b/source/migrations.bs @@ -0,0 +1,49 @@ +' Functions that update the registry based on the last run version and the currently running version + +' Run all necessary registry mirations on the "global" Jellyfin registry section +sub runGlobalMigrations() + ' Global registry migrations + if isValid(m.global.app.lastRunVersion) and not versionChecker(m.global.app.lastRunVersion, "1.7.0") + ' last app version used was less than 1.7.0 + print "Running 1.7.0 global registry migrations" + ' no longer saving raw password to registry + ' auth token and username are now stored in user settings and not global settings + unset_setting("port") + unset_setting("token") + unset_setting("username") + unset_setting("password") + ' remove saved credentials from saved_servers + saved = get_setting("saved_servers") + if isValid(saved) + savedServers = ParseJson(saved) + if isValid(savedServers.serverList) and savedServers.serverList.Count() > 0 + newServers = { serverList: [] } + for each item in savedServers.serverList + item.Delete("username") + item.Delete("password") + newServers.serverList.Push(item) + end for + set_setting("saved_servers", FormatJson(newServers)) + end if + end if + ' now saving LastRunVersion globally and per user so that we can run user specific registry migrations + ' duplicate LastRunVersion to all user settings in the registry so that we can run user specific migrations + regSections = getRegistrySections() + for each section in regSections + if section <> "Jellyfin" + registry_write("LastRunVersion", m.global.app.version, section) + end if + end for + end if +end sub + +' Run all necessary registry mirations on the user specific registry section +sub runUserMigrations() + ' User registry migrations + if m.global.session.user.lastRunVersion <> invalid and not versionChecker(m.global.session.user.lastRunVersion, "1.7.0") + ' last run version was less than 1.7.0 + print "Running 1.7.0 user registry migrations" + ' no longer saving password to registry + unset_user_setting("password") + end if +end sub