-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d20bc0
commit 91afa44
Showing
12 changed files
with
244 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:path_provider/path_provider.dart'; | ||
|
||
const quokkaSubDirectory = '/Linwood/Quokka'; | ||
|
||
Future<String> getQuokkaDirectory() async { | ||
String? path; | ||
if (Platform.isAndroid) { | ||
path ??= (await getExternalStorageDirectory())?.path; | ||
} | ||
path ??= (await getApplicationDocumentsDirectory()).path; | ||
path += quokkaSubDirectory; | ||
return path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,43 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:lw_file_system/lw_file_system.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
import 'package:quokka/api/storage.dart'; | ||
import 'package:quokka/models/definitions/pack.dart'; | ||
|
||
class PacksService { | ||
final PackData? _corePack; | ||
final TypedKeyFileSystem<PackData> _fileSystem; | ||
|
||
PacksService({ | ||
PackData? corePack, | ||
}) : _corePack = corePack; | ||
}) : _corePack = corePack, | ||
_fileSystem = TypedKeyFileSystem.build( | ||
FileSystemConfig( | ||
passwordStorage: SecureStoragePasswordStorage(), | ||
storeName: 'packs', | ||
getDirectory: (storage) async => | ||
'${await getQuokkaDirectory()}/Packs', | ||
database: 'quokka.db', | ||
), | ||
onDecode: (data) => PackData.fromData(data), | ||
onEncode: (data) => data.export(), | ||
); | ||
|
||
Future<PackData?> fetchCorePack() async => | ||
_corePack ?? await PackData.getCorePack(); | ||
|
||
Future<List<PackData>> getPacks() async => [ | ||
await fetchCorePack(), | ||
].whereNotNull().toList(); | ||
Future<Map<String, PackData>> getPacks() async { | ||
final corePack = await fetchCorePack(); | ||
await _fileSystem.initialize(); | ||
return { | ||
...Map.fromEntries((await _fileSystem.getFiles()) | ||
.map((file) => file.data == null | ||
? null | ||
: MapEntry(file.fileNameWithoutExtension, file.data!)) | ||
.whereNotNull()), | ||
if (corePack != null) '': corePack, | ||
}; | ||
} | ||
} |
Oops, something went wrong.