How is it possible to save some basic, small amount of data to the registry. I wish to store a zip code to be retrieved when the app is loaded. Since you can't write to a file and retain it after the app closes, the only way to save it is in the registry, but how? Thanks
I have looked at the sdk and see what it says on creating a section in the registry to save info to and also the example on reading it. But how do you assign the info back to say a variable to work with it. For example, I used the following to save the info to the registry, the result comes from user input thru the on screen keyboard.
- in the SDK - '****************************************************** 'Registry Helper Functions '****************************************************** Function RegRead(key,section=invalid) If section=invalid section="Default" sec=CreateObject("roRegistrySection",section) If sec.Exists(key) Return sec.Read(key) Return invalid End Function
Function RegWrite(key,val,section=invalid) If section=invalid section="Default" sec=CreateObject("roRegistrySection",section) sec.Write(key,val) sec.Flush() 'commit it End Function
Function RegDelete(key,section=invalid) If section=invalid section="Default" sec=CreateObject("roRegistrySection",section) sec.Delete(key) sec.Flush() End Function
so to read and store in a variable you would use variablename=regread("keyname","registrysectionname") to write the variable back you would use regwrite("keyname",data to write,"registrysectionname") to delete the value from the registry is regdelete("keyname","registrysectionname")
AFAIK the roku registry saves/reads all data as a string. So if your zipcode is numeric, you might need to change it to a string first before writing - but definitely after reading it will be in string form and you'll need to convert it back to an integer if you are using it as an integer. In addition to storing the data to the roku registry (limited to 16KB), you could fairly easily send the data to your server and have the server store it in a database or text file or something on the server. This way if your client has 4 or 5 rokus, the value of this data will persist between physical devices instead of being limited to the roku they used to save to the registry - it's how NetFlix and Amazon do it - saving data to their servers.
The section=invalid sets a default value if it's not specified when calling the function. It's also not 'creating the section' - it's specifying the section, which is required if you use more than one section. I'd think of it this way - suppose you use the registry for saving bookmarks for video, saving user data like email address, name, and user number. I'd use one section for the bookmarks for the channel (independent of channel within the same devid) and a second section for the user data (shared between channels on the same devid) This way I could sort the bookmarks, limit the number of bookmarks, etc, through the registry without modifying the user data using for each based on the section instead of having to track each key, date, video position, etc. Sure, you could do it all in the same section, just it makes it a little more complicated as you eliminate stuff you don't want to mess with. I think you could improve this code easily by setting the sec createobject line as an AA - but really in practice it's not much slower to create it as needed for the relatively slow operation of writing or reading or deleting a value from the registry.
Any clues on how this is really taken up? For instance, is one character 1 byte? Does each key/value pair take up some set amount of space? Can we use keys/values of very long length, like big sentences or paragraphs? Do I just have to test all this myself and see what works?
Well, it's a little complicated. Each registry entry stores the name and value, with a two byte header in front of each (so 4 extra bytes per entry). In addition there is a small header for each registry section (2 bytes plus the section name I think), and another header for the whole registry (about 30 bytes). However, the whole thing is zlib compressed before storing it, and it's the compressed file that is limited to 16K. This makes it rather difficult to predict exactly how much space you will be using. I'm not sure how knowing the exact size would be helpful, unless you're caching things in the registry that can be obtained elsewhere.
I appreciate the detailed insight into space usage with the extra bytes here and there. Basically I'm implementing a save game file using the registry, with quite a bit of info, so I'm trying to get a feel for how much practical room I really have.
Any idea how much the zlib compression helps? 50%? Varies?