mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 06:33:43 +08:00
https://github.com/StarCitizenToolBox/app/issues/1 分流下载:增加一种快速恢复卡住的下载的方法。
This commit is contained in:
parent
9ab6f6056c
commit
8159e9b70e
@ -106,7 +106,10 @@ Future showBaseDialog(BuildContext context,
|
|||||||
builder: (context) => ContentDialog(
|
builder: (context) => ContentDialog(
|
||||||
title: Text(title),
|
title: Text(title),
|
||||||
content: content,
|
content: content,
|
||||||
constraints: constraints ?? kDefaultContentDialogConstraints,
|
constraints: constraints ?? const BoxConstraints(
|
||||||
|
maxWidth: 512,
|
||||||
|
maxHeight: 756.0,
|
||||||
|
),
|
||||||
actions: actions,
|
actions: actions,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -36,13 +36,21 @@ class DownloaderDialogUI extends BaseUI<DownloaderDialogUIModel> {
|
|||||||
const SizedBox(width: 24),
|
const SizedBox(width: 24),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
if (model.isP4kDownload) ...[
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
Text(
|
||||||
|
"提示:因网络波动,若下载进度长时间卡住或速度变慢,可尝试点击暂停下载,之后重新点击P4K分流下载。",
|
||||||
|
style:
|
||||||
|
TextStyle(fontSize: 13, color: Colors.white.withOpacity(.7)),
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
FilledButton(
|
FilledButton(
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
||||||
child: Text("取消下载"),
|
child: Text("暂停下载"),
|
||||||
),
|
),
|
||||||
onPressed: () => model.doCancel()),
|
onPressed: () => model.doCancel()),
|
||||||
],
|
],
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||||
import 'package:starcitizen_doctor/common/rust/ffi.dart';
|
import 'package:starcitizen_doctor/common/rust/ffi.dart';
|
||||||
|
|
||||||
@ -10,9 +11,12 @@ class DownloaderDialogUIModel extends BaseUIModel {
|
|||||||
final String downloadUrl;
|
final String downloadUrl;
|
||||||
final bool showChangeSavePathDialog;
|
final bool showChangeSavePathDialog;
|
||||||
final int threadCount;
|
final int threadCount;
|
||||||
|
final bool isP4kDownload;
|
||||||
|
|
||||||
DownloaderDialogUIModel(this.fileName, this.savePath, this.downloadUrl,
|
DownloaderDialogUIModel(this.fileName, this.savePath, this.downloadUrl,
|
||||||
{this.showChangeSavePathDialog = false, this.threadCount = 1});
|
{this.showChangeSavePathDialog = false,
|
||||||
|
this.threadCount = 1,
|
||||||
|
this.isP4kDownload = false});
|
||||||
|
|
||||||
bool isInMerging = false;
|
bool isInMerging = false;
|
||||||
|
|
||||||
@ -52,8 +56,15 @@ class DownloaderDialogUIModel extends BaseUIModel {
|
|||||||
savePath = savePath.substring(0, savePath.length - fileName.length - 1);
|
savePath = savePath.substring(0, savePath.length - fileName.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
final downloaderSavePath = "$savePath//$fileName.downloading";
|
if (isP4kDownload) {
|
||||||
|
final box = await Hive.openBox("p4k_cache");
|
||||||
|
await box.put(
|
||||||
|
"last_save_dir",
|
||||||
|
{"save_path": savePath, "file_name": fileName},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final downloaderSavePath = "$savePath//$fileName.downloading";
|
||||||
try {
|
try {
|
||||||
rustFii
|
rustFii
|
||||||
.startDownload(
|
.startDownload(
|
||||||
|
@ -4,6 +4,7 @@ import 'dart:io';
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||||||
@ -354,6 +355,10 @@ class ToolsUIModel extends BaseUIModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _downloadP4k() async {
|
Future<void> _downloadP4k() async {
|
||||||
|
String savePath = scInstalledPath;
|
||||||
|
String fileName = "Data.p4k";
|
||||||
|
bool isResumeDownload = false;
|
||||||
|
final box = await Hive.openBox("p4k_cache");
|
||||||
var downloadUrl = AppConf.networkVersionData?.p4kDownloadUrl;
|
var downloadUrl = AppConf.networkVersionData?.p4kDownloadUrl;
|
||||||
if (downloadUrl == null || downloadUrl.isEmpty) {
|
if (downloadUrl == null || downloadUrl.isEmpty) {
|
||||||
showToast(context!, "该功能维护中,请稍后再试!");
|
showToast(context!, "该功能维护中,请稍后再试!");
|
||||||
@ -365,14 +370,36 @@ class ToolsUIModel extends BaseUIModel {
|
|||||||
maxWidth: MediaQuery.of(context!).size.width * .35));
|
maxWidth: MediaQuery.of(context!).size.width * .35));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await showToast(
|
final lastSavePath = (box.get("last_save_dir", defaultValue: {}) as Map);
|
||||||
context!,
|
dPrint("lastSavePath === $lastSavePath");
|
||||||
"P4k 是星际公民的核心游戏文件,高达近 100GB,盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户。"
|
if (lastSavePath.isNotEmpty) {
|
||||||
"\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。");
|
final s = lastSavePath["save_path"] ?? "";
|
||||||
|
final f = lastSavePath["file_name"] ?? "";
|
||||||
AnalyticsApi.touch("p4k_download");
|
if ((await File("$s/$f.downloading").exists()) &&
|
||||||
launchUrlString(
|
(await File("$s/$f.downloading.bson").exists())) {
|
||||||
"https://citizenwiki.cn/SC%E6%B1%89%E5%8C%96%E7%9B%92%E5%AD%90#%E5%88%86%E6%B5%81%E4%B8%8B%E8%BD%BD%E6%95%99%E7%A8%8B");
|
final ok = await showConfirmDialogs(context!, "是否恢复下载?",
|
||||||
|
const Text("检测到未完成的下载,点击确认即可恢复下载,点击取消将会删除之前的临时文件,并开始一个新的下载。"));
|
||||||
|
if (ok) {
|
||||||
|
savePath = s;
|
||||||
|
fileName = f;
|
||||||
|
isResumeDownload = true;
|
||||||
|
} else {
|
||||||
|
// del last cache and del file
|
||||||
|
await box.delete("last_save_dir");
|
||||||
|
await File("$s/$f.downloading").delete();
|
||||||
|
await File("$s/$f.downloading.bson").delete();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// del last cache
|
||||||
|
await box.delete("last_save_dir");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await showToast(
|
||||||
|
context!,
|
||||||
|
"P4k 是星际公民的核心游戏文件,高达近 100GB,盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户。"
|
||||||
|
"\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。");
|
||||||
|
AnalyticsApi.touch("p4k_download");
|
||||||
|
}
|
||||||
final r = await showDialog(
|
final r = await showDialog(
|
||||||
context: context!,
|
context: context!,
|
||||||
dismissWithEsc: false,
|
dismissWithEsc: false,
|
||||||
@ -380,16 +407,24 @@ class ToolsUIModel extends BaseUIModel {
|
|||||||
return BaseUIContainer(
|
return BaseUIContainer(
|
||||||
uiCreate: () => DownloaderDialogUI(),
|
uiCreate: () => DownloaderDialogUI(),
|
||||||
modelCreate: () => DownloaderDialogUIModel(
|
modelCreate: () => DownloaderDialogUIModel(
|
||||||
"Data.p4k", scInstalledPath, downloadUrl,
|
fileName, savePath, downloadUrl,
|
||||||
showChangeSavePathDialog: true, threadCount: 10));
|
showChangeSavePathDialog: !isResumeDownload,
|
||||||
|
threadCount: 10,
|
||||||
|
isP4kDownload: true));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
if (r == "cancel") {
|
if (r == "cancel") {
|
||||||
return showToast(context!, "下载已取消,下载进度已保留,如果您无需恢复下载,请手动删除下载临时文件。");
|
return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。");
|
||||||
} else if (r is DioException) {
|
} else if (r is DioException) {
|
||||||
showToast(context!, "下载失败:$r");
|
showToast(context!, "下载失败:$r");
|
||||||
} else {
|
} else {
|
||||||
showToast(context!, "下载完毕,文件已保存到:$r");
|
final ok = await showConfirmDialogs(
|
||||||
|
context!, "下载完毕!", Text("文件已保存到:$r\n\n是否查看P4K操作教程?"));
|
||||||
|
if (ok == true) {
|
||||||
|
launchUrlString(
|
||||||
|
"https://citizenwiki.cn/SC%E6%B1%89%E5%8C%96%E7%9B%92%E5%AD%90#%E5%88%86%E6%B5%81%E4%B8%8B%E8%BD%BD%E6%95%99%E7%A8%8B");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user