Improve portable data path resolution logic
Updated getPortableDataPath to prefer storing 'user-data' in Documents/My Games/<AppName>, with a fallback to the app directory if necessary. This enhances data portability and aligns with common user data storage conventions.
This commit is contained in:
+16
-4
@@ -85,7 +85,8 @@ class PortableDataManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the portable data directory path
|
* Get the portable data directory path
|
||||||
* Uses NEBULA_PORTABLE_PATH if set, otherwise creates 'user-data' folder in app directory
|
* Uses NEBULA_PORTABLE_PATH if set, otherwise creates 'user-data' in Documents/My Games/<AppName>
|
||||||
|
* with a safe fallback to the app directory.
|
||||||
*/
|
*/
|
||||||
getPortableDataPath() {
|
getPortableDataPath() {
|
||||||
if (this._portableDataPath !== null) {
|
if (this._portableDataPath !== null) {
|
||||||
@@ -110,9 +111,20 @@ class PortableDataManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default: create 'user-data' folder in the application directory
|
// Default: prefer Documents/My Games/<AppName>/user-data
|
||||||
const appRoot = this._getAppRootDir();
|
let dataPath = '';
|
||||||
const dataPath = path.join(appRoot, 'user-data');
|
try {
|
||||||
|
const docsDir = app.getPath('documents');
|
||||||
|
const appName = app.getName() || 'NebulaBrowser';
|
||||||
|
dataPath = path.join(docsDir, 'My Games', appName, 'user-data');
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[Portable] Failed to resolve Documents path, using app directory');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dataPath) {
|
||||||
|
const appRoot = this._getAppRootDir();
|
||||||
|
dataPath = path.join(appRoot, 'user-data');
|
||||||
|
}
|
||||||
|
|
||||||
// Validate the path
|
// Validate the path
|
||||||
if (this._isPathSafe(dataPath)) {
|
if (this._isPathSafe(dataPath)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user