Page 1 of 2

Save custom attributes in standalone

Posted: Tue Jun 13, 2017 9:33 pm
by Da_Elf
if i want to have some settings save for the next time i open the program without saving them to an external file how can i do it?

Re: Save custom attributes in standalone

Posted: Tue Jun 13, 2017 10:33 pm
by SparkOut
Simple answer: you can't. A standalone cannot modify itself. You can easily write to an external file on exit, and read in on starting up again. The external file can be a livecode stack too.
Additionally you can extend this idea to have a standalone that is just a launcher for your application which is a native livecode stack. Look up "splashstack technique" for more specifics.

Re: Save custom attributes in standalone

Posted: Tue Jun 13, 2017 10:46 pm
by dunbarx
Hi.

First you must know that the executable cannot save to itself. So any such settings must be stored either in another stack or in an external file. Are you familiar with both of these methods?

Craig Newman

Re: Save custom attributes in standalone

Posted: Tue Jun 13, 2017 11:07 pm
by Da_Elf
looks like it will have to be external file i guess

Re: Save custom attributes in standalone

Posted: Tue Jun 13, 2017 11:58 pm
by dunbarx
I always use the "splash" stack method, using external files seldomly

Invariably it is in the "working" stack(s) where I store properties and other data, and these are saved between sessions. I find this more comforting and accessible than using external files.

Unless I misunderstand what you meant by:
looks like it will have to be external file i guess
you can almost certainly keep whatever settings you like within your (working) stack.

Craig

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 12:50 am
by Da_Elf
Ok. So my program has need of a database. When the program first runs if it can't find a database, it will go to a card where the user puts in his database name, username and password. The database is then created and I want those settings saved so that whenever the program runs it has the right database name, username and password to use. I would love it if they were saved in the program as opposed to an external file

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 5:32 am
by dunbarx
OK.

So save all those preferences in a custom property of the stack. This is simple and straightforward unless we still do not grok the "Splash" thing.

Craig

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 11:28 am
by Klaus
Hi friends,

please don't forget that if the app/exe has been installed into the "correct" place ("Applications" on Mac and "Programm files..." on Windows)
only users with ADMIN permissions are allowed to write (= save a stack or anything else) in that directory!


Best

Klaus

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 12:48 pm
by Da_Elf
dunbarx how do i save to a stack AFTER the program has been compiled to a standalone is the question

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 1:51 pm
by dunbarx
You make a small stack that may have absolutely nothing on it or in it. Name it "splash".

In the standalone settings for this stack you can add other stack files to your heart's content . Those stack files contain "working" stacks (and substacks).

The stack "splash", upon opening, navigates to one or more of those other stacks. It can hide itself. ALL those other stacks can save their data between sessions. So the splash stack becomes the executable, "carrying" along with it other stacks that actually do the stuff you likely worked in the IDE.

In the IDE, you might liken it to the engine (LC itself) being the executable and any old stack you mess around with being the "working' stack. This analogy maps to a standalone, in that the splash stack is LC, and its attached stack files are the ordinary stacks that you play with.

Craig

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 3:43 pm
by FourthWorld
Da_Elf wrote:Ok. So my program has need of a database. When the program first runs if it can't find a database, it will go to a card where the user puts in his database name, username and password. The database is then created and I want those settings saved so that whenever the program runs it has the right database name, username and password to use. I would love it if they were saved in the program as opposed to an external file
Where will the database be stored?

As for the login credentials, you might as well save those to a separate file. There are ways to save the UI stack file itself, but with two trade-offs for doing so:

1. If you later update the UI in a future version you'll need to work out some way to get the data from the old stack before replacing it. For any app expected to live beyond one version, it's usually simpler to separate UI and data.

2. The data are login credentials, which should be stored encrypted on disk. There are clever ways to do this with stack files, but it's a lot of extra work.

Probably simpler to just package up the login data into a string, use the built-in encrypt command to encrypt the data, then write that to disk. When launching next time, read the data, use the decrypt command on it, then populate those three fields.

LiveCode's specialFolderPath function can be useful here. It accepts a variety of constants for different standard folders, such as specialFolderPath("Preferences"), which can then be appended with the name of the file you're using to store the data so your app can find it again next time it opens.

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 4:50 pm
by dunbarx
dunbarx how do i save to a stack AFTER the program has been compiled to a standalone is the question
Do you mean you already have a standalone, and want to modify it to allow data to be saved? That is not possible if the standalone is the executable. You have to modify the original stack(s) oin the IDE and save anew.

Craig

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 5:33 pm
by Da_Elf
fourthworld the database is a mySQL database stored locally in its default installed folder

dunbarx exactly. Ive created the whole program and exported as a standalone. When i put it on a computer and run it for the first time it goes to a setup page which will ask for my user information for this particular instance. It will use this information to create a mySQL database based on these preferences. I want to be able to save the database info at this point. Then once the setup is done it enters the main part of the software and uses the info. Each time after the 1st running i would like it to skip the setup because it will see that data is there. It will go direct to the main part and use the preferences as before.

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 5:56 pm
by FourthWorld
Did you mean SQLite? MySQL runs as a separate process, and unless your app is licensed under GPL there are licensing fees for distributing the MySQL dp package.

Either way, unless this is a one-off quickie app I think you'll find it easier over the long haul to just write that small login into to a small file in a default location.

Re: Save custom attributes in standalone

Posted: Wed Jun 14, 2017 7:03 pm
by Da_Elf
fouthworld im using mysql community on a local machine. My software isnt designed to be on the market or anything (im not that good yet). Ive just created some apps for my friends to use which use a database and since im used to using mysql online with PHP i thought what the hell. ill just install locally. I did look in to mysql lite but there were some things it couldnt do that mysql could do (i cant remember what they are now). Its looking like i will just end up using an external file which i will encrypt the information so no one can read it.