feat: Add file selector support and enhance game data directory management
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ class DefaultGameDataDirectoryPersistence {
|
||||
return _resolvedPath!;
|
||||
}
|
||||
|
||||
_resolvedPath = '$platformConfigDir/data_source.json';
|
||||
_resolvedPath = '$platformConfigDir/settings.json';
|
||||
return _resolvedPath!;
|
||||
}
|
||||
|
||||
@@ -61,18 +61,36 @@ class DefaultGameDataDirectoryPersistence {
|
||||
try {
|
||||
final normalized = directoryPath?.trim();
|
||||
final file = File(filePath);
|
||||
Map<String, Object?> existingPayload = <String, Object?>{};
|
||||
|
||||
if (await file.exists()) {
|
||||
try {
|
||||
final String raw = await file.readAsString();
|
||||
final Object? decoded = jsonDecode(raw);
|
||||
if (decoded is Map<String, Object?>) {
|
||||
existingPayload = decoded;
|
||||
}
|
||||
} catch (_) {
|
||||
// Ignore malformed existing content.
|
||||
}
|
||||
}
|
||||
|
||||
await file.parent.create(recursive: true);
|
||||
if (normalized == null || normalized.isEmpty) {
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
existingPayload.remove('dataDirectory');
|
||||
if (existingPayload.isEmpty) {
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
return;
|
||||
}
|
||||
final payload = jsonEncode(existingPayload);
|
||||
await file.writeAsString(payload, flush: true);
|
||||
return;
|
||||
}
|
||||
|
||||
final payload = jsonEncode(<String, Object>{
|
||||
'dataDirectory': normalized,
|
||||
});
|
||||
existingPayload['dataDirectory'] = normalized;
|
||||
final payload = jsonEncode(existingPayload);
|
||||
await file.writeAsString(payload, flush: true);
|
||||
} catch (_) {
|
||||
// Best-effort only.
|
||||
|
||||
Reference in New Issue
Block a user