-
Notifications
You must be signed in to change notification settings - Fork 43
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
9f6a832
commit b468a3d
Showing
1 changed file
with
66 additions
and
0 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,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<String> 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<String> 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<String> 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<String> 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<String> 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(); | ||
} | ||
} |