Skip to content

Commit c23d448

Browse files
committed
MACOS: Change default savepath to use the Application Support folder
The default savepath on macOS used to be in the user Document folder. However ScummVM requires special permission to access that folder, and if the user denied it, this caused various issues. This implement ticket #11428. This commit also contains migration code that that old configs that used the default path are set explicitly to use the old default path. So the change of savepath will only be for new users.
1 parent 8884cc4 commit c23d448

File tree

10 files changed

+36
-14
lines changed

10 files changed

+36
-14
lines changed

backends/platform/sdl/macosx/macosx.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ void OSystem_MacOSX::initBackend() {
117117
_textToSpeechManager = new MacOSXTextToSpeechManager();
118118
#endif
119119

120+
// Migrate savepath.
121+
// It used to be in ~/Documents/ScummVM Savegames/, but was changed to use the application support
122+
// directory. To migrate old config files we use a flag to indicate if the config file was migrated.
123+
// This allows detecting old config files. If the flag is not set we:
124+
// 1. Set the flag
125+
// 2. If the config file has no custom savepath and has some games, we set the savepath to the old default.
126+
if (!ConfMan.hasKey("macos_savepath_migrated", Common::ConfigManager::kApplicationDomain)) {
127+
if (!ConfMan.hasKey("savepath", Common::ConfigManager::kApplicationDomain) && !ConfMan.getGameDomains().empty()) {
128+
ConfMan.set("savepath", getDocumentsPathMacOSX() + "/ScummVM Savegames", Common::ConfigManager::kApplicationDomain);
129+
}
130+
ConfMan.setBool("macos_savepath_migrated", true, Common::ConfigManager::kApplicationDomain);
131+
ConfMan.flushToDisk();
132+
}
133+
120134
// Invoke parent implementation of this method
121135
OSystem_POSIX::initBackend();
122136
}

backends/platform/sdl/macosx/macosx_wrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <common/str.h>
2626

2727
Common::String getDesktopPathMacOSX();
28+
Common::String getDocumentsPathMacOSX();
2829
Common::String getResourceAppBundlePathMacOSX();
2930
Common::String getAppSupportPathMacOSX();
3031
Common::String getMacBundleName();

backends/platform/sdl/macosx/macosx_wrapper.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@
4646
return Common::String([path fileSystemRepresentation]);
4747
}
4848

49+
Common::String getDocumentsPathMacOSX() {
50+
// See comment in getDesktopPathMacOSX()
51+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
52+
if ([paths count] == 0)
53+
return Common::String();
54+
NSString *path = [paths objectAtIndex:0];
55+
if (path == nil)
56+
return Common::String();
57+
return Common::String([path fileSystemRepresentation]);
58+
}
59+
4960
Common::String getResourceAppBundlePathMacOSX() {
5061
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
5162
if (bundlePath == nil)

backends/saves/posix/posix-saves.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
#include "backends/saves/posix/posix-saves.h"
3434
#include "backends/fs/posix/posix-fs.h"
35+
#if defined(MACOSX)
36+
#include "backends/platform/sdl/macosx/macosx_wrapper.h"
37+
#endif
3538

3639
#include "common/config-manager.h"
3740
#include "common/savefile.h"
@@ -44,14 +47,11 @@ POSIXSaveFileManager::POSIXSaveFileManager() {
4447
Common::Path savePath;
4548

4649
#if defined(MACOSX)
47-
const char *home = getenv("HOME");
48-
if (home && *home && strlen(home) < MAXPATHLEN) {
49-
savePath = home;
50-
savePath.joinInPlace("Documents/ScummVM Savegames");
51-
50+
savePath = getAppSupportPathMacOSX();
51+
if (!savePath.empty()) {
52+
savePath.joinInPlace("Savegames");
5253
ConfMan.registerDefault("savepath", savePath);
5354
}
54-
5555
#else
5656
const char *envVar;
5757

dists/macosx/Info.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
<string>scummvm.docktileplugin</string>
7979
<key>NSRequiresAquaSystemAppearance</key>
8080
<false/>
81-
<key>NSDocumentsFolderUsageDescription</key>
82-
<string>ScummVM saves and loads savegames in the Documents folder by default.</string>
8381
<key>SUPublicDSAKeyFile</key>
8482
<string>dsa_pub.pem</string>
8583
<key>NSHighResolutionCapable</key>

dists/macosx/Info.plist.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
<string>scummvm.docktileplugin</string>
7979
<key>NSRequiresAquaSystemAppearance</key>
8080
<false/>
81-
<key>NSDocumentsFolderUsageDescription</key>
82-
<string>ScummVM saves and loads savegames in the Documents folder by default.</string>
8381
<key>SUPublicDSAKeyFile</key>
8482
<string>dsa_pub.pem</string>
8583
<key>NSHighResolutionCapable</key>

doc/cz/PrectiMe

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ Uložené hry jsou na některých platformách standardně umístěny do součas
13521352

13531353
Platformy, které v současnosti mají jiné výchozí složky jsou:
13541354
macOS:
1355-
$HOME/Documents/ScummVM Savegames/
1355+
$HOME/Library/Application Support/ScummVM/Savegames/
13561356

13571357
Jiné unixy:
13581358
Řídíme se specifikacemi základního adresáře XDG. To znamená, že nastavení lze nalézt v:

doc/de/LIESMICH

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,7 @@ Sehen Sie sich das Beispiel weiter unten in dieser Liesmich-Datei an.
20172017

20182018
Die folgenden Plattformen haben ein anderes Standard-Verzeichnis:
20192019
macOS:
2020-
$HOME/Documents/ScummVM Savegames/
2020+
$HOME/Library/Application Support/ScummVM/Savegames/
20212021

20222022
Andere UNIX-Systeme:
20232023
Wir befolgen die Spezifikation XDG Base Directory. Dies bedeutet, dass

doc/docportal/use_scummvm/save_load_games.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Default saved game paths are shown below.
6060

6161
.. tab-item:: macOS
6262

63-
``~/Documents/ScummVM Savegames/``
63+
``~/Library/Application Support/ScummVM/Savegames/`` (with versions of ScummVM prior to 2.9 it was in ``~/Documents/ScummVM Savegames/``).
6464

6565

6666
.. tab-item:: Linux/Unix

doc/se/LasMig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ Spardata lagras som standard i den aktiva katalogen på vissa plattformar och i
10311031

10321032
Plattformar som för närvarande har annorlunda standardkataloger:
10331033
macOS:
1034-
$HOME/Documents/ScummVM Savegames/
1034+
$HOME/Library/Application Support/ScummVM/Savegames/
10351035

10361036
Övriga unix-system:
10371037
$HOME/.scummvm/

0 commit comments

Comments
 (0)