2023-06-01 12:43:27 +00:00
|
|
|
' needed for set_user_setting() and unset_user_setting()
|
|
|
|
import "pkg:/source/utils/session.bs"
|
2019-02-10 19:15:20 +00:00
|
|
|
|
2022-05-01 10:51:28 +00:00
|
|
|
' Read config tree from json config file and return
|
|
|
|
function GetConfigTree()
|
|
|
|
return ParseJSON(ReadAsciiFile("pkg:/settings/settings.json"))
|
|
|
|
end function
|
|
|
|
|
2019-02-10 19:15:20 +00:00
|
|
|
' Generic registry accessors
|
2021-07-09 20:08:32 +00:00
|
|
|
function registry_read(key, section = invalid)
|
|
|
|
if section = invalid then return invalid
|
|
|
|
reg = CreateObject("roRegistrySection", section)
|
|
|
|
if reg.exists(key) then return reg.read(key)
|
|
|
|
return invalid
|
2019-02-10 19:15:20 +00:00
|
|
|
end function
|
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
sub registry_write(key, value, section = invalid)
|
|
|
|
if section = invalid then return
|
|
|
|
reg = CreateObject("roRegistrySection", section)
|
|
|
|
reg.write(key, value)
|
|
|
|
reg.flush()
|
2021-06-26 13:38:52 +00:00
|
|
|
end sub
|
2019-02-10 19:15:20 +00:00
|
|
|
|
2021-07-09 20:08:32 +00:00
|
|
|
sub registry_delete(key, section = invalid)
|
|
|
|
if section = invalid then return
|
|
|
|
reg = CreateObject("roRegistrySection", section)
|
|
|
|
reg.delete(key)
|
|
|
|
reg.flush()
|
2021-06-26 13:38:52 +00:00
|
|
|
end sub
|
2019-02-10 19:15:20 +00:00
|
|
|
|
2023-06-01 12:43:27 +00:00
|
|
|
' Return all data found inside a registry section
|
|
|
|
function RegistryReadAll(section as string) as dynamic
|
|
|
|
if section = "" then return invalid
|
|
|
|
|
|
|
|
registry = CreateObject("roRegistrySection", section)
|
|
|
|
regKeyList = registry.GetKeyList()
|
|
|
|
registryData = {}
|
|
|
|
for each item in regKeyList
|
|
|
|
' ignore session related tokens
|
|
|
|
if item <> "token" and item <> "username" and item <> "password"
|
|
|
|
if registry.Exists(item)
|
|
|
|
registryData.AddReplace(item, registry.Read(item))
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
|
|
|
return registryData
|
|
|
|
end function
|
2019-02-10 19:15:20 +00:00
|
|
|
|
|
|
|
' "Jellyfin" registry accessors for the default global settings
|
2021-07-09 20:08:32 +00:00
|
|
|
function get_setting(key, default = invalid)
|
|
|
|
value = registry_read(key, "Jellyfin")
|
|
|
|
if value = invalid then return default
|
|
|
|
return value
|
2019-02-10 19:15:20 +00:00
|
|
|
end function
|
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub set_setting(key, value)
|
2021-07-09 20:08:32 +00:00
|
|
|
registry_write(key, value, "Jellyfin")
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2019-02-10 19:15:20 +00:00
|
|
|
|
2021-06-26 10:18:09 +00:00
|
|
|
sub unset_setting(key)
|
2021-07-09 20:08:32 +00:00
|
|
|
registry_delete(key, "Jellyfin")
|
2021-06-26 10:18:09 +00:00
|
|
|
end sub
|
2019-02-10 19:15:20 +00:00
|
|
|
|
|
|
|
' User registry accessors for the currently active user
|
2023-06-01 12:43:27 +00:00
|
|
|
function get_user_setting(key as string) as dynamic
|
|
|
|
if key = "" or m.global.session.user.id = invalid then return invalid
|
|
|
|
value = registry_read(key, m.global.session.user.id)
|
2021-07-09 20:08:32 +00:00
|
|
|
return value
|
2019-02-10 19:15:20 +00:00
|
|
|
end function
|
|
|
|
|
2023-06-01 12:43:27 +00:00
|
|
|
sub set_user_setting(key as string, value as dynamic)
|
|
|
|
if m.global.session.user.id = invalid then return
|
|
|
|
session.user.settings.Save(key, value)
|
|
|
|
registry_write(key, value, m.global.session.user.id)
|
2021-06-26 13:38:52 +00:00
|
|
|
end sub
|
2019-02-10 19:15:20 +00:00
|
|
|
|
2023-06-01 12:43:27 +00:00
|
|
|
sub unset_user_setting(key as string)
|
|
|
|
if m.global.session.user.id = invalid then return
|
|
|
|
session.user.settings.Delete(key)
|
|
|
|
registry_delete(key, m.global.session.user.id)
|
2021-06-26 13:38:52 +00:00
|
|
|
end sub
|
2022-05-01 10:51:28 +00:00
|
|
|
|
|
|
|
' Recursivly search the config tree for entry with settingname equal to key
|
|
|
|
function findConfigTreeKey(key as string, tree)
|
|
|
|
for each item in tree
|
|
|
|
if item.settingName <> invalid and item.settingName = key then return item
|
|
|
|
|
|
|
|
if item.children <> invalid and item.children.Count() > 0
|
|
|
|
result = findConfigTreeKey(key, item.children)
|
|
|
|
if result <> invalid then return result
|
|
|
|
end if
|
|
|
|
end for
|
|
|
|
|
|
|
|
return invalid
|
|
|
|
end function
|