123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import 'dart:io';
- import 'package:path_provider/path_provider.dart';
- import 'package:sport/bean/game.dart';
- class GameManager {
- static String getFileName(GameInfoData game) {
- return "${game.version}.apk";
- }
- static Future<File?> createFile(GameInfoData game) async {
- Directory? documentsDir = Platform.isIOS ? await getTemporaryDirectory() : await getExternalStorageDirectory();
- if(documentsDir == null)
- return null;
- String documentsPath = documentsDir.path;
- // 先创建目录
- Directory saveDir = Directory("$documentsPath/apk/${game.id}");
- if (!await saveDir.exists()) {
- saveDir.createSync(recursive: true);
- }
- String savePath = "${saveDir.path}/${getFileName(game)}";
- File _file = File(savePath);
- if (!await _file.exists()) {
- _file.createSync();
- }
- print("file: $_file");
- return _file;
- }
- static deleteFile(GameInfoData game) async {
- Directory? documentsDir = Platform.isIOS ? await getTemporaryDirectory() : await getExternalStorageDirectory();
- if(documentsDir == null)
- return null;
- String documentsPath = documentsDir.path;
- Directory saveDir = Directory("$documentsPath/apk/${game.id}");
- if (!await saveDir.exists()) {
- return;
- }
- var files = saveDir.listSync();
- files.forEach((element) {
- // if(!element.path.endsWith(".apk"))
- element.delete();
- });
- }
- }
|