New topic: Preference (config) file using FolderItem
<http://forums.realsoftware.com/viewtopic.php?t=46600> Page 1 of 1 [ 2 posts ] Previous topic | Next topic Author Message richmanscott Post subject: Preference (config) file using FolderItemPosted: Fri Jan 18, 2013 12:28 am Joined: Fri Feb 24, 2012 2:25 am Posts: 38 I would like to store the config.xml file in the appropriate directory for each OS. If one or more of the directories do not exist, I need to create it as well as the config.xml file itself. I then want to return a FolderItem to the config.xml file (or .plist on Mac). Linux: SpecialFolders.Etc/{app}/config.xml Mac: SpecialFolder.SharedPreferences/com.company.app.plist Windows: SpecialFolder.SharedPreferences\{company}\{app}\config.xml I don't know why the FolderItem concept is giving me grief so I need some help. What am I doing wrong? I get an IOException when trying to create the file on MAC; haven't tried it on either of the other OSs. ' Verifies existence of the config file. If it does not exist, we create the subdirectory structure, config file, and set the App.ConfigFile variable with the appropriate filename. ' If creation of any subdirectory or file fails, we return nil, otherwise, we return a FolderItem reference to the forlder or directory containing the config file. Dim f As FolderItem Dim Preferences As FolderItem Dim ConfigFile As String = Lowercase(App.DisplayName) + ".xml" #If TargetLinux then Preferences = SpecialFolder.Etc f = Preferences.Child("company/" + Lowercase(App.DisplayName)) if not f.Exists then f.CreateAsFolder f = Preferences.Child("company/" + Lowercase(App.DisplayName) + "/" + App.ConfigFile) #elseif TargetMacOS then Preferences = SpecialFolder.SharedPreferences ConfigFile = "com.company." + Lowercase(App.DisplayName) + ".plist" f = Preferences.Child(ConfigFile) if not f.Exists then Try Dim t As TextOutputStream = TextOutputStream.Create(f) t.Close t = nil Catch e As IOException Return nil end Try end if App.ConfigFile = ConfigFile Return f #else Preferences = SpecialFolder.SharedPreferences #endif Top kermit Post subject: Re: Preference (config) file using FolderItemPosted: Fri Jan 18, 2013 1:45 am Joined: Mon May 30, 2011 12:56 am Posts: 592 I have no doubt someone will pipe in with a more detailed explanation, but here is my 'high level no nonsense' explanation. Although there is a preferences folder in OSX, for some reason, Apple dont like you to use it any more. You wont have permission to write there. In my apps, I now store my user's preferences in a file (the format doesnt matter) in the user's Documents folder. I have an app property called prefs_folder I set this to a suitable value per OS when the app starts. For me, this is now prefs_folder = specialfolder.Documents (in fact it is prefs_folder = specialfolder.Documents.child("MyAppName") , because I created a folder in documents for my stuff) Anywhere else in the app, it is now safe for me to read or write app.prefs_folder.child("MyPrefsFile.txt") Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 2 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
