Matlab compiler/installer: how to add data file and use "appdata" as default localtion
8 views (last 30 days)
Show older comments
Hello,
I have several projects that I usually deploy as executable normally using the Application Compiler app. Maybe in a future I will move also to other OSs, but for now I'm focusing on Windows platforms, so now on let's suppose that I'm compiling and deploying on Windows only.
I wanted to move to a command-line approach (basically to both homogeneize the options and have more control over them, including readying the app version from a text file).
The idea is to produce a stand-alone executable using compiler.build.standaloneWindowsApplication and then to produce an installer using compiler.package.installer (mcc can be an alternative to get an executable, but I prefer the functional approach of standaloneApplication and the fact that you can use either name-calue pairs argument or an option object. Plus, I doubt it can work with the installer function).
Everything is working more or less fine except two points:
- My apps usually need to be able to write some file they are shipped with (i.e. log files), so I want them to use as default instal folder something in the user data (%appdata%) folder. I tried to do so by telling the installer to default to (for example) "%appdata%/My Code", but during the installation, "%appdata%" is not recognaised as a system environment variable, so basically it's not working (cannot use the default location and if trying to browse for a new one the installer window got blocked).
- How can I tell the compiler to install some files/folder containing some data (i.e. custom icons, some textual databases, etc) togheter with my app? (Notes: the executable compiler option "AdditionalFiles" nor the installer compiler option "AutoDetectDataFiles" do NOT work and in R2022a, compiler.package.InstallerOptions does NOT accept the "AdditionalFiles" parameter)
Thanks in advance for any help/tips,
Jacopo
P.S. In case you want some screenshoots/snapshoots/Minimum Working Example/etc, ask
0 Comments
Answers (1)
Karanjot
on 23 Mar 2024
Hi Jacopo,
As per my understanding, You want to access the (%appdata%) folder to write log files & install custom files together with your application.
Using environment variables like %appdata% directly in the path for the default installation directory of an installer created with MATLAB's compiler.package.installer function might not work as expected because the installer might not resolve environment variables at runtime.
To address the first, I recommend the following workaround:
Use the prefdir function in MATLAB. The prefdir function returns the path to the user's preferences folder, which is typically located in the %appdata% folder. You can then append your desired subfolder name to this path.
Here's an example of how you can set the default installation folder to %appdata%/My Code:
installFolder = fullfile(prefdir, 'My Code');
disp(installFolder);
This will display the full path to the installation folder in the user's %appdata% directory.
For the errors with bundling custom files with the application, Please share the exact error stack trace.
See Also
Categories
Find more on Package and Share Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!