diff --git a/lib/settings/path.dart b/lib/settings/path.dart new file mode 100644 index 000000000..3af32ca88 --- /dev/null +++ b/lib/settings/path.dart @@ -0,0 +1,66 @@ +// This source code is a part of Project Violet. +// Copyright (C) 2020-2023. violet-team. Licensed under the Apache-2.0 License. + +import 'dart:io'; + +import 'package:path_provider/path_provider.dart'; +import 'package:sqflite/sqflite.dart'; +import 'package:violet/log/log.dart'; + +class DefaultPathProvider { + static Future getHomeDirectory() async{ + var home = ''; + if(Platform.isLinux){ + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + return home; + } + Logger.error('[getHomeDirectory] unsupported os'); + throw Error(); + } + static Future getBaseDirectory() async { + if(Platform.isAndroid){ + return '${(await getApplicationDocumentsDirectory()).path}'; + } else if(Platform.isIOS){ + return '${(await getDatabasesPath())}'; + } else if(Platform.isLinux){ + return '${(await getHomeDirectory())}/.violet'; + } + Logger.error('[getBaseDirectory] unsupported os'); + throw Error(); + } + static Future getDocumentsDirectory() async { + if(Platform.isAndroid || Platform.isIOS){ + return '${(await getApplicationDocumentsDirectory()).path}'; + } else if(Platform.isLinux){ + return '${(await getHomeDirectory())}/.violet'; + } + Logger.error('[getDocumentsDirectory] unsupported os'); + throw Error(); + } + static Future getSupportDirectory() async { + if(Platform.isAndroid){ + return '${(await getApplicationDocumentsDirectory()).path}'; + } else if(Platform.isIOS){ + return '${(await getApplicationSupportDirectory()).path}'; + } else if(Platform.isLinux){ + return '${(await getHomeDirectory())}/.violet'; + } + Logger.error('[getSupportDirectory] unsupported os'); + throw Error(); + } + static Future getExportDirectory() async { + if(Platform.isAndroid){ + return '${(await getExternalStorageDirectory())}'; + } else if(Platform.isIOS){ + return '${(await getApplicationSupportDirectory()).path}'; + } else if(Platform.isLinux){ + return '${(await getHomeDirectory())}/.violet'; + } + Logger.error('[getExportDirectory] unsupported os'); + throw Error(); + } +} \ No newline at end of file