Azzera filtri
Azzera filtri

Matlab compiler/installer: how to add data file and use "appdata" as default localtion

12 visualizzazioni (ultimi 30 giorni)
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:
  1. 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).
  2. 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

Risposte (1)

Karanjot
Karanjot il 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.
  1 Commento
Jacorem
Jacorem il 25 Mar 2024
Dear Karanjot,
thanks for your answer, but I think that it will NOT solve my problem: doing as you suggest, I can set a default instal location that perfectly work on the machine I'm compiling the code on (the conversion/explicitation is made at compile time), but that will fail on any other machines (i.e. where the appdata is located in a disk with a diffferent letter label or if the user has a different window username; for this to work the conversion/explicitation must be done at instal time).
For that side I fotunately found what the problem was: it is neccessary to use %AppData% instead of %appdata% (case matter).
As for the bundling files, the stack trace is exactly what I said: the compiler.package.InstallerOptions object does not have a property called "AdditionalFiles" and so, when you try to set/change it, it comply that such property does not exist.

Accedi per commentare.

Categorie

Scopri di più su Package and Share Apps in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by