Deployed exe with configuration file

My deployed Matlab apps include configuration data which is stored to custom *.cfg files. This works fine unless the installer is used in which case Windows locks the program directory and the config files cannot be updated.
There were a few old links on this topic but none seemed to address this specific issue. One referenced setpref/addpref, but that appeared to be configuring Matlab rather than the end user app. One suggested adding files to the deploytool "Shared" folder which does not exist. Some info on ctfroot() which seems to point to the app install folder but that is where files are being locked.
Restating the issue: I am compiling an app, it is being installed on a users computer, then the app needs to read/write the *.cfg file based on user interactions with the application. Some of the information is complex (such as custom filters); not just X = Y items.
Suggestions?

 采纳的回答

Rik
Rik 2021-4-19
It sounds like you need something very similar to my GetWritableFolder function.
You can use the second output to confirm the folder is persistent.

5 个评论

It looks like this would work but appears 'non-standard' in terms of Windows apps. Maybe the issue is I am searching for a Matlab solution and should be looking more generally at where config files are located in Windows and how the associated apps know where to find them...
Well, if you want specifically Windows: %APPDATA% will get you where you need to be. This function should always be able to find a writable folder, as either the application data folder, or the temp dir should be writable. The first should be persistent as well, and in networked settings it should follow users around through the roaming folder.
I wrote this function to cover most (if not all) configurations where Matlab would be used.
Do you have a specific question I could try to answer?
It sounds like I should be including a subfolder "config" in the app which is included in deploytool? The apps do currently have subfolders for test data which is included for the users to run the app to ensure it is working.
What I am lacking is an understanding of what Windows is automatically locking and what it allows write access to? My impression is that anything under "Program Files" gets locked and other apps are storing information to locations such as user\***, but these apps are not user specific. Can files that are deployed to the application folder or subfolders be written to?
As to APPDATA: In browsing the environment variables I see there are folders users\{me}\AppData\Local\{SpecificPrograms}. Using Matlab getenv(APPDATA) is comes back with users\{me}\AppData\Roaming; do not understand why roaming and not local? As long as this would be a) available on all computers, and b) consistent when used (not roaming one time and local another) it should solve the issue.
The default for APPDATA is the roaming folder (for reasons explained in a video by ThioJoe on YouTube recently).
My function has 3 possible outputs:
  1. A folder similar to where the AddOns are stored (%APPDATA% for Windows and ~\Documents\ for Mac/Unix)
  2. A folder in the tempdir
  3. A folder in the current directory
As long as the operating system paramaters do not change between calls, these paths should be stable, that is the whole point. This function should return the same output for a given OS/computer, and be able to return a folder.
You probably want this:
[f,status]=GetWritableFolder('ErrorOnNotFound',false);
if status~=1 && status ~=2
%handle the case of not finding a writable folder
end
Thanks for all the help - this will work.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Install Products 的更多信息

产品

版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by