When do you use a prefs or other file ?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

When do you use a prefs or other file ?

Post by Simon Knight » Fri Dec 27, 2019 9:38 am

Hi,

I'm curious how you would deal with the following situation. I am writing a small utility to aid the renaming and moving of raw image files created by a digital camera. While I'm going to be the primary user I can see that such an application may be of use to others so I need to include more raw formats in the application as the present version is hard coded only to deal with the two raw file types that I shoot. I wish to extend this to all common raw types by including a list of raw file extensions. The chances are that this list is unlikely to change in the near future as camera manufactures continue with the same extension even if the file format changes. For example a Nikon NEF file created by a Nikon D70 is different from that created by a Nikon D850 but both use the .nef extension.

So should I give the end user the option of adding new file types given that the base list is unlikely to change very often? If I do then what method should be employed? The methods I have thought of are :

1) Hard code the list into the application and only update the application when someone needs it updated.
2) Store the list as a prefs file. This needs some OS juggling but I have a library I can use.
3) Use a compiled "splash" stack and save the data as part of the working stack which may be saved.
4) Save the data as a text file that is saved to the same folder as the application stack.

5) Some elegant solution I have not thought of.

best wishes

Simon K.
best wishes
Skids

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: When do you use a prefs or other file ?

Post by bogs » Fri Dec 27, 2019 1:02 pm

1) Hard code the list into the application and only update the application when someone needs it updated.
2) Store the list as a prefs file. This needs some OS juggling but I have a library I can use.
3) Use a compiled "splash" stack and save the data as part of the working stack which may be saved.
4) Save the data as a text file that is saved to the same folder as the application stack.
1.) downside might be application size for the end user.
2.) downside might be the OS juggling, but I have no idea what juggling you would need to do for what amounts to a simple list.
3.) I use this myself a lot.
4.) Well, I don't use or develop for mobile devices, so I don't know their abilities / allowances for retrieving remote information, but it seems to me you could put a simple text file on any server and retrieve that from inside the application.The text file would contain a list of the different formats your program would work with, you'd retrieve it in program using the url format. That keeps it under your control, as much as anything else might, but you could do the same with the remote stack thing without using the launcher method.

Really, I think this kind of thing comes down to your own comfort levels / preferences in programming, but where 1.) is concerned, although no one else seems to think it makes much difference, if I have to force an update/download on the end user, I'd prefer it be as small as possible (KBs vs. MBs or bigger), so I prefer to work with (in order) :
plain text
stacks

Ultimately, I decided based on how much difficulty I want to present in modifying the information, a binary stack is a little more difficult to get into than plain text, etc.

Just my take.
Image

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: When do you use a prefs or other file ?

Post by jmburnod » Fri Dec 27, 2019 6:28 pm

Hi Simon,
i always use .txt file in a subfolder of documents folder for OS X, Windows and iOS. I choosed this way because my app is for multi users who have own prefs.
Best regards
jean-Marc
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10055
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: When do you use a prefs or other file ?

Post by FourthWorld » Fri Dec 27, 2019 7:12 pm

Simon Knight wrote:
Fri Dec 27, 2019 9:38 am
2) Store the list as a prefs file. This needs some OS juggling but I have a library I can use.
^ this.

When in doubt, do what nearly all other applications do.

The task of finding the user's Documents folder is made simple with the specialFolderPath function.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: When do you use a prefs or other file ?

Post by Simon Knight » Sat Dec 28, 2019 9:12 am

Hi,

Thanks for all your thoughts, I will probably store the data in ~users/Library/ApplicationSupport/ folder as this appears to be the correct location for such things on a mac :
Contains all app-specific data and support files. These are the files that your app creates and manages on behalf of the user and can include files that contain user data.

By convention, all of these items should be put in a subdirectory whose name matches the bundle identifier of the app. For example, if your app is named MyApp and has the bundle identifier com.example.MyApp, you would put your app’s user-specific data files and resources in the ~/Library/Application Support/com.example.MyApp/ directory. Your app is responsible for creating this directory as needed.

Resources required by the app to run must be placed inside the app bundle itself.
The livecode SpecialFolderPath function returns the correct folder : answer specialFolderPath("Support") = /Users/UserName/Library/Application Support.

Does anyone know why bundle identifiers are formatted the way they are? I found this on the web but it does not really explain why the com dot notation is used.
The bundle identifier is an ID for your application used by the system as a domain for which it can store settings and reference your application uniquely. The Bundle ID must be in the format com.pressmatrix.ExampleApp, in which “Example App” should be replaced with your app name.
Lastly, although I have read the dictionary entry I am uncertain what is returned on Windows and Linux when the SpecialFolderPath is used so if any users of these OS's have time please would they post the results?

best wishes

Simon K.
best wishes
Skids

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: When do you use a prefs or other file ?

Post by bogs » Sat Dec 28, 2019 12:39 pm

Heh, all the special folder path related paths are listed in the dictionary under "specialFolderPath".
Lc Dictionary wrote: Windows folder names:
"home": The current user's profile folder
"desktop": The current user's desktop folder
"documents": The current user's "My Documents" folder
"support": The current user's application-specific data ("AppData") folder
"system": The Windows System folder
"start": The folder that contains Start Menu items
"fonts": The folder that contains fonts
"temporary": The folder where temporary files can be placed
"engine": The folder containing the LiveCode engine and the executable files copied in the standalone application
"resources": In development mode, the current stack's folder. In a standalone, the resources folder where files or folders specified in the Standalone Builder are located.
On Linux, there is no such special folder path, but you could just write it out to a folder of your own creation in the home folder. If you want the folder hidden, you would create it with a period in front of the name, such as -
/home/userName/.myPrefs
Image

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: When do you use a prefs or other file ?

Post by Simon Knight » Sat Dec 28, 2019 4:48 pm

all the special folder path related paths are listed in the dictionary under "specialFolderPath".
ooo that is clever - why didn't I think of that ...... oh I did ;-)

For example what does "asup" resolve to ? On mac it appears to be the main library folder as opposed to the users library folder but unfortunately the dictionary does not actually mention it:
On Mac OS systems, the following folderIdentifier values are supported:

"home": The current user's home folder
"desktop": The current user's desktop folder
"preferences": The current user's preferences folder
"documents": The current user's documents folder
"support": The current user's application-specific data folder
"system": The System Folder (usually /System)
"fonts": The folder that contains fonts
"temporary": The folder where temporary files can be placed
"engine": The folder containing the LiveCode engine and the executable files copied in the standalone application
"resources": In development mode, the current stack's folder. In a standalone, the resources folder where files or folders specified in the Standalone Builder are located.
Yet it is shown as an example:

Code: Select all

local appSupportFolder
put specialFolderPath("asup") into appSupportFolder
Got to love the dictionary .

On Linux, there is no such special folder path (support)
so does this return a folder not found as described in the dictionary?


best wishes

Simon K.
best wishes
Skids

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: When do you use a prefs or other file ?

Post by Simon Knight » Sat Dec 28, 2019 5:13 pm

Here is some code that might work across platform. Its difficult to test as I only have access to MacOS. Thoughts, comments, bricks etc....

Code: Select all

function GetPathToSupportFolder pAppSupportFolderName
   
   ## pAppSupportFolderName should be a valid name for a folder
   
   ## This function will return the path to the current users
   # preferences folder which is different on each OS.
   
   ## UNTESTED!
   
   ## Check the platform to decide where to store the file(s)
   switch the platform
      case "MacOS"
         put specialFolderPath("support") into tAppDatafp
         break
      case "Win32"
         put specialFolderPath("support") into tAppDatafp
         break
      case "Linux"
         ## Linux
         ## The current users HOME folder
         put specialFolderPath("home") into tAppDatafp
         break
      case "iphone"
         ## The current application HOME folder
         put specialFolderPath("home") into tAppDatafp
         break
      case "android"
         --put specialFolderPath("engine") into tAppDatafp -- access files included in the build
         put specialFolderPath("documents") into tAppDatafp -- valuable files used by application
         break
   end switch
   
   put  "/" after tAppDatafp
   
   ## Create subfolder with the name of APP or Company.
   
   -- pPrefsFolderName is passed to this handler
   if there is not a folder (tAppDatafp  & pAppSupportFolderName) then
      create folder (tAppDatafp  & pAppSupportFolderName)
   end if
   
   ## Return the path including trailing SLASH, ready for use!
   return (tAppDatafp  & pAppSupportFolderName & "/")
end GetPathToSupportFolder
best wishes
Skids

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: When do you use a prefs or other file ?

Post by bogs » Sat Dec 28, 2019 5:16 pm

Simon Knight wrote:
Sat Dec 28, 2019 4:48 pm
all the special folder path related paths are listed in the dictionary under "specialFolderPath".
ooo that is clever - why didn't I think of that ...... oh I did ;-)
Must have been the way you asked this -
Lastly, although I have read the dictionary entry I am uncertain what is returned on Windows and Linux when the SpecialFolderPath is used so if any users of these OS's have time please would they post the results?
- that threw me off and made me think you hadn't seen it :P
Simon Knight wrote:
Sat Dec 28, 2019 4:48 pm
For example what does "asup" resolve to ?
On OSX (only, as far as I know, I don't do anything with mobile anything) it resolves as you say (easily tested in the MsgBox) to
/Library/Application Support

On win and 'nix it does nothing.
Simon Knight wrote:
Sat Dec 28, 2019 4:48 pm
Got to love the dictionary .
On Linux, there is no such special folder path (support)
so does this return a folder not found as described in the dictionary?
It returned empty in the message box.

As I was preparing to submit, I noticed you put your function code post in :D
I don't know about the mobile stuff, but doesn't Lc determine between win and 'nix 64 bit now? I don't know for sure, since I don't often go into the newer ide.

By the by, just as a short aside, you could easily test all 3 Operating system reactions by installing a virtual machine. Virtual box for instance is -
1.) open source,
2.) easily installed on all major OS desktops,
3.) completely free,
4.) will run all major OS desktops**, although you are already running OSX as your base system, so I don't see an issue with the legal disclaimer presented below :P :P :P

**legal disclaimer - Apple does not like this and legally, you have no right to run OSX on any virtual machine, so while it is possible to do, it is highly frowned upon by Apple and the ghost of Steve Jobs.
Image

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: When do you use a prefs or other file ?

Post by Simon Knight » Sat Dec 28, 2019 5:38 pm

Must have been the way you asked this -
No worries - I confuse myself most of the time.

I don't do much for other OS either but its good to have a look behind the curtain now and again.

best wishes

Simon
best wishes
Skids

Post Reply