I'd like to deploy a ClickOnce application, but would like to have a configurable user file to store settings and preferences that does not get overwritten everytime I publish a new version. Is there to specify that a particular file should get deployed in any installation that doesn't already have one, but not overwrite any previous versions?
The only workaround that I can envision is to store the data in a database, but it's so user-centric that it seems like a lot of overhead to re-invent the config file.
One approach is to use application settings, which we used for a WPF application deployed with ClickOnce. We have multiple settings for such things as user specified download folders, default settings, etc. For each such setting, the Scope is set to User. When the setting is changed by the user the new values are persisted with a call such as:
YourProject.Properties.Settings.Default.UserSetting1 = "New Value";
YourProject.Properties.Settings.Default.Save(); // persists the new value for the current user
Even with multiple updates of the application via ClickOnce, these settings are persisted for each user. Note that the settings are persisted on a per-machine basis, so if a user goes to a new machine and downloads the application, their settings will not be transferred.
Hope this helps,
Related
I am working on a application in which i have to update all app related settings remotely.
App setings include
Text Font
List item
Text Color
background Color
Images
Url etc..
My idea is something like this, the first time when the user install the app it start downloading all images and settings like text color, font etc.
And when ever any changes happen the app itself downlaod those changes and store it locally.
Currently i am using a constant file where i have written all required settings.
Tell me some best way to achieve this and also tell me where to save the settings.
If is there any sample app available please provide me the link.
Thanks.
You could try something like GroundControl. It updates values in NSUserDefaults from a file found on a web server.
If you have a constant file from which you read all your settings, you can place an identically formatted file on a server, (maybe have a "last updated" date saved inside these files). Upon every session init, try to download the remote settings file - if it is "later" than the one you have, or any settings is different than the one you have saved, save the newly downloaded file instead of the old one, and act upon the changes.
The settings' flags and vars may change instantly across the app, while downloading images for skin and UI occurs immidiately after this, and take effect after they have completed downloading (which may look awkward to the user) or, more plausibly, upon init of the next session.
IMHO, using NSUSerDefaults settings and downloading a remote plist with the same keys and structure is most convenient file format for settings stuff.
Also, you may place the remote file in a web service, and have the client send that web service the request for the file accompanied with a "my last updated settings are of the date X" - the date of the latest settings you have locally. Then, the server may return a file, or an "you already have the latest file" response.
is there anyway to add new entries to the Settings bundle during run time?
We would like to be able to turn-off and on options depending on what information the user have entered. Seems like all Apple documentation talks about modifying preferences, but not the Setings page itself.
thanks!
The settings.bundle is read-only. You can NOT modify it during run time.
If you want to be able to change settings during run time, you have include the app settings from within the app.
My iPhone app uses a small database to store its settings and saved files. How can I ensure that the default database, with its default settings, gets distributed to anyone who downloads it along with the application files?
EDIT Sorry, I was in a rush when I posted this. I forgot to mention that the database needs to end up in the 'Documents' folder of the application so that it can be backed up at a later date by the user.
-Ash
Put it in "Resources". Then on your first launch, you'll need to load that file out of your mainBundle and save it to the Documents directory. The file will "come with" the app, but it won't live in the right place to get caught by backup.
A side-effect is that restoring the app to factory settings is as easy as deleting that file. Next launch, you can see you don't have your file, and copy a fresh one out of your bundle.
You include it as a file in the Resources folder of your application.
How do you distribute other files needed by your application that aren't in a jar file? For example, the application at http://www.javabeginner.com/java-swing/java-swing-shuffle-game . The download contains Shuffle.jar, Shuffle.bat, Score.dat, and an images folder with 3 images in it. I can see possibly putting the images directly in Shuffle.jar, but you wouldn't want to put Score.dat in the jar file because it changes. Is there somewhere you could identify this type of file in the jnlp?
The non-java files should be stored as resources. For files that change, you store the original or template file also as a resource in your jar. When the program starts, you have it check the local system to see if that file exists. If not, it creates the local file by copying the template file from the JAR resource. If the file already exists, then it is used as is.
To save files to the local system, even when running in the sandbox (unsigned), you can use the PersistenceService (javadoc / example). If your java application is signed, then you can use the regular File apis to write the file to the local machine, such as in a ".yourgame" subfolder under the user's home folder.
You can put all those files (except the scores file) in your jar file and load the contents using resource loading.
I've just deleted and restarted my reply twice now, changing my answer each time; this is confusing and needs a bit more clarification.
Are you SURE that application is supposed to be a Web Start app? On the site you linked to, it doesn't appear to be. Are you trying to take an application that was not designed as a Web Start application and change it into one that can be Web Start?
If it's not a Web Start app as your tag implies, then this question is open ended. You can distribute it 100 different ways.
If you are indeed trying to convert it into a Web Start app, you can start by packaging the images into the jar and that will alleviate your first headache if you just read them from there instead of from a File(). If it's going to be Web Start, then you need to decide how you want to keep scores. You have to decide what the scoring system is like before you can decide on how to go about it; will all the scores be kept on the web site hosting the Web Start app? Will that part still be local? If you want to get access to the local file system, you need to sign the jar, then you can extract the score.dat to the file system and do whatever you want with it if the end user accepts.
You need to figure out what you want to do before you can do it, or at least clear it up for us if you already know more than we know you know.
I have an .xml file that is going to be shipped within my app.
This file contains values that are read from it and saved as an array when the app launches.
Each time the app is run, I want to check with the server if there is an internet connection. If so, I want to get the newest version of the .xml file from the server and replace the one that I currently have saved in my app (this way, the next time the user logs in and doesn't have internet access, he/she will be able to use the old (yet most up to date) data).
What is the best way to do this?
Thanks,
The best way to probably do this is to copy the XML file from the app bundle to a location in the app's sandbox, e.g. the Documents folder. Thereafter you can update the XML content as necessary with newer data from the server. The copy is necessary to allow you to write to the file, since you cannot change the content of your app's bundle because it is signed.
Alternatively, if the data is simple enough, you can just save it to user defaults on first launch and change the defaults on subsequent updates
I might skip the XML altogether, unless it contains a baseline of default settings, and just sync user defaults over the Internet. You can't modify files in the bundle, so your only option would be to copy over a "default-settings" XML file to the application's Documents folder to make it editable.