Hello fellow developers!
I’m sure many of you have read the blog post I wrote about sandboxing. Now that the Sailfish OS 4.3.0 has reached the Early Access stage, you can also move to the next stage with your app: Defining the profile for your app.
Like I mentioned in the blog, we used to have application configuration files in directories named in the format .config/harbour-appname
. In the future we no longer want that - the configuration files should instead be located in directories with the format .config/OrganizationName/ApplicationName
. So that’s where you should write your configurations from now on. But what about the old configuration files which were already written in .config/harbour-appname
? Do we lose access to them? Fear not, that is not the case!
Starting with Sailfish OS 4.3.0, if the .config/harbour-appname
directory exists, it will also be visible in the sandbox. So basically, this is what you should do in order to migrate your configuration:
-
If your configuration files exist in
.config/OrganizationName/ApplicationName
, use them -
If not, check if they exist in
.config/harbour-appname
, and if they do, read them from there -
Write configuration files to
.config/OrganizationName/ApplicationName
You can use something like the following code to migrate your configuration from the old location to the new:
void MySettings::migrateSettings()
{
// The new location of config file
QSettings settings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/my.domain/MyApp/MyApp.conf", QSettings::NativeFormat);
if (settings.contains("migrated"))
return;
QSettings oldSettings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/harbour-myapp/harbour-myapp.conf", QSettings::NativeFormat);
for (const QString& key : oldSettings.childKeys())
settings.setValue(key, oldSettings.value(key));
settings.setValue("migrated", "true");
}
Similar migration strategy could be used also for .local/share and .cache directories - you may also want to consider just copying the files over.