mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 12:34:45 +08:00
移除 rust 多线程下载器
This commit is contained in:
@ -1,24 +0,0 @@
|
||||
// This file is automatically generated, so please do not edit it.
|
||||
// Generated by `flutter_rust_bridge`@ 2.0.0-dev.24.
|
||||
|
||||
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
|
||||
|
||||
import '../downloader.dart';
|
||||
import '../frb_generated.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
|
||||
|
||||
Stream<DownloadCallbackData> startDownload(
|
||||
{required String url,
|
||||
required String savePath,
|
||||
required String fileName,
|
||||
required int connectionCount,
|
||||
dynamic hint}) =>
|
||||
RustLib.instance.api.startDownload(
|
||||
url: url,
|
||||
savePath: savePath,
|
||||
fileName: fileName,
|
||||
connectionCount: connectionCount,
|
||||
hint: hint);
|
||||
|
||||
Future<void> cancelDownload({required String id, dynamic hint}) =>
|
||||
RustLib.instance.api.cancelDownload(id: id, hint: hint);
|
@ -3,11 +3,9 @@
|
||||
|
||||
// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field
|
||||
|
||||
import 'api/downloader_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'downloader.dart';
|
||||
import 'frb_generated.io.dart' if (dart.library.html) 'frb_generated.web.dart';
|
||||
import 'http_package.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
|
||||
@ -65,15 +63,6 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
|
||||
}
|
||||
|
||||
abstract class RustLibApi extends BaseApi {
|
||||
Future<void> cancelDownload({required String id, dynamic hint});
|
||||
|
||||
Stream<DownloadCallbackData> startDownload(
|
||||
{required String url,
|
||||
required String savePath,
|
||||
required String fileName,
|
||||
required int connectionCount,
|
||||
dynamic hint});
|
||||
|
||||
Future<List<String>> dnsLookupTxt({required String host, dynamic hint});
|
||||
|
||||
Future<RustHttpResponse> fetch(
|
||||
@ -104,64 +93,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
required super.portManager,
|
||||
});
|
||||
|
||||
@override
|
||||
Future<void> cancelDownload({required String id, dynamic hint}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
callFfi: (port_) {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_String(id, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 2, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_unit,
|
||||
decodeErrorData: null,
|
||||
),
|
||||
constMeta: kCancelDownloadConstMeta,
|
||||
argValues: [id],
|
||||
apiImpl: this,
|
||||
hint: hint,
|
||||
));
|
||||
}
|
||||
|
||||
TaskConstMeta get kCancelDownloadConstMeta => const TaskConstMeta(
|
||||
debugName: "cancel_download",
|
||||
argNames: ["id"],
|
||||
);
|
||||
|
||||
@override
|
||||
Stream<DownloadCallbackData> startDownload(
|
||||
{required String url,
|
||||
required String savePath,
|
||||
required String fileName,
|
||||
required int connectionCount,
|
||||
dynamic hint}) {
|
||||
return handler.executeStream(StreamTask(
|
||||
callFfi: (port_) {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_String(url, serializer);
|
||||
sse_encode_String(savePath, serializer);
|
||||
sse_encode_String(fileName, serializer);
|
||||
sse_encode_u_8(connectionCount, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 1, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_download_callback_data,
|
||||
decodeErrorData: null,
|
||||
),
|
||||
constMeta: kStartDownloadConstMeta,
|
||||
argValues: [url, savePath, fileName, connectionCount],
|
||||
apiImpl: this,
|
||||
hint: hint,
|
||||
));
|
||||
}
|
||||
|
||||
TaskConstMeta get kStartDownloadConstMeta => const TaskConstMeta(
|
||||
debugName: "start_download",
|
||||
argNames: ["url", "savePath", "fileName", "connectionCount"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<List<String>> dnsLookupTxt({required String host, dynamic hint}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
@ -169,7 +100,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_String(host, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 5, port: port_);
|
||||
funcId: 3, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_list_String,
|
||||
@ -202,7 +133,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_opt_Map_String_String(headers, serializer);
|
||||
sse_encode_opt_list_prim_u_8_strict(inputData, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 4, port: port_);
|
||||
funcId: 2, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_rust_http_response,
|
||||
@ -228,7 +159,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_Map_String_String(headers, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 3, port: port_);
|
||||
funcId: 1, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_unit,
|
||||
@ -295,21 +226,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return dco_decode_u_64(raw);
|
||||
}
|
||||
|
||||
@protected
|
||||
DownloadCallbackData dco_decode_download_callback_data(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
final arr = raw as List<dynamic>;
|
||||
if (arr.length != 5)
|
||||
throw Exception('unexpected arr length: expect 5 but see ${arr.length}');
|
||||
return DownloadCallbackData(
|
||||
id: dco_decode_String(arr[0]),
|
||||
total: dco_decode_u_64(arr[1]),
|
||||
progress: dco_decode_u_64(arr[2]),
|
||||
speed: dco_decode_u_64(arr[3]),
|
||||
status: dco_decode_my_downloader_status(arr[4]),
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
int dco_decode_i_32(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@ -334,42 +250,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return (raw as List<dynamic>).map(dco_decode_record_string_string).toList();
|
||||
}
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus dco_decode_my_downloader_status(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
switch (raw[0]) {
|
||||
case 0:
|
||||
return const MyDownloaderStatus_NoStart();
|
||||
case 1:
|
||||
return const MyDownloaderStatus_Running();
|
||||
case 2:
|
||||
return MyDownloaderStatus_Pending(
|
||||
dco_decode_my_network_item_pending_type(raw[1]),
|
||||
);
|
||||
case 3:
|
||||
return MyDownloaderStatus_Error(
|
||||
dco_decode_String(raw[1]),
|
||||
);
|
||||
case 4:
|
||||
return const MyDownloaderStatus_Finished();
|
||||
default:
|
||||
throw Exception("unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
MyMethod dco_decode_my_method(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
return MyMethod.values[raw as int];
|
||||
}
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType dco_decode_my_network_item_pending_type(
|
||||
dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
return MyNetworkItemPendingType.values[raw as int];
|
||||
}
|
||||
|
||||
@protected
|
||||
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@ -496,23 +382,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return (sse_decode_u_64(deserializer));
|
||||
}
|
||||
|
||||
@protected
|
||||
DownloadCallbackData sse_decode_download_callback_data(
|
||||
SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var var_id = sse_decode_String(deserializer);
|
||||
var var_total = sse_decode_u_64(deserializer);
|
||||
var var_progress = sse_decode_u_64(deserializer);
|
||||
var var_speed = sse_decode_u_64(deserializer);
|
||||
var var_status = sse_decode_my_downloader_status(deserializer);
|
||||
return DownloadCallbackData(
|
||||
id: var_id,
|
||||
total: var_total,
|
||||
progress: var_progress,
|
||||
speed: var_speed,
|
||||
status: var_status);
|
||||
}
|
||||
|
||||
@protected
|
||||
int sse_decode_i_32(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@ -551,30 +420,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return ans_;
|
||||
}
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus sse_decode_my_downloader_status(
|
||||
SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
|
||||
var tag_ = sse_decode_i_32(deserializer);
|
||||
switch (tag_) {
|
||||
case 0:
|
||||
return const MyDownloaderStatus_NoStart();
|
||||
case 1:
|
||||
return const MyDownloaderStatus_Running();
|
||||
case 2:
|
||||
var var_field0 = sse_decode_my_network_item_pending_type(deserializer);
|
||||
return MyDownloaderStatus_Pending(var_field0);
|
||||
case 3:
|
||||
var var_field0 = sse_decode_String(deserializer);
|
||||
return MyDownloaderStatus_Error(var_field0);
|
||||
case 4:
|
||||
return const MyDownloaderStatus_Finished();
|
||||
default:
|
||||
throw UnimplementedError('');
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
MyMethod sse_decode_my_method(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@ -582,14 +427,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return MyMethod.values[inner];
|
||||
}
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType sse_decode_my_network_item_pending_type(
|
||||
SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var inner = sse_decode_i_32(deserializer);
|
||||
return MyNetworkItemPendingType.values[inner];
|
||||
}
|
||||
|
||||
@protected
|
||||
Map<String, String>? sse_decode_opt_Map_String_String(
|
||||
SseDeserializer deserializer) {
|
||||
@ -733,17 +570,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_u_64(self, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_download_callback_data(
|
||||
DownloadCallbackData self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_String(self.id, serializer);
|
||||
sse_encode_u_64(self.total, serializer);
|
||||
sse_encode_u_64(self.progress, serializer);
|
||||
sse_encode_u_64(self.speed, serializer);
|
||||
sse_encode_my_downloader_status(self.status, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_i_32(int self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@ -777,39 +603,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_my_downloader_status(
|
||||
MyDownloaderStatus self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
switch (self) {
|
||||
case MyDownloaderStatus_NoStart():
|
||||
sse_encode_i_32(0, serializer);
|
||||
case MyDownloaderStatus_Running():
|
||||
sse_encode_i_32(1, serializer);
|
||||
case MyDownloaderStatus_Pending(field0: final field0):
|
||||
sse_encode_i_32(2, serializer);
|
||||
sse_encode_my_network_item_pending_type(field0, serializer);
|
||||
case MyDownloaderStatus_Error(field0: final field0):
|
||||
sse_encode_i_32(3, serializer);
|
||||
sse_encode_String(field0, serializer);
|
||||
case MyDownloaderStatus_Finished():
|
||||
sse_encode_i_32(4, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_my_method(MyMethod self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_i_32(self.index, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_my_network_item_pending_type(
|
||||
MyNetworkItemPendingType self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_i_32(self.index, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_opt_Map_String_String(
|
||||
Map<String, String>? self, SseSerializer serializer) {
|
||||
|
@ -3,12 +3,10 @@
|
||||
|
||||
// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field
|
||||
|
||||
import 'api/downloader_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi' as ffi;
|
||||
import 'downloader.dart';
|
||||
import 'frb_generated.dart';
|
||||
import 'http_package.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart';
|
||||
@ -47,9 +45,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int dco_decode_box_autoadd_u_64(dynamic raw);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData dco_decode_download_callback_data(dynamic raw);
|
||||
|
||||
@protected
|
||||
int dco_decode_i_32(dynamic raw);
|
||||
|
||||
@ -62,15 +57,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
List<(String, String)> dco_decode_list_record_string_string(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus dco_decode_my_downloader_status(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyMethod dco_decode_my_method(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType dco_decode_my_network_item_pending_type(dynamic raw);
|
||||
|
||||
@protected
|
||||
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw);
|
||||
|
||||
@ -124,10 +113,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int sse_decode_box_autoadd_u_64(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData sse_decode_download_callback_data(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
int sse_decode_i_32(SseDeserializer deserializer);
|
||||
|
||||
@ -141,17 +126,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
List<(String, String)> sse_decode_list_record_string_string(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus sse_decode_my_downloader_status(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyMethod sse_decode_my_method(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType sse_decode_my_network_item_pending_type(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
Map<String, String>? sse_decode_opt_Map_String_String(
|
||||
SseDeserializer deserializer);
|
||||
@ -211,10 +188,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_box_autoadd_u_64(int self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_download_callback_data(
|
||||
DownloadCallbackData self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_i_32(int self, SseSerializer serializer);
|
||||
|
||||
@ -229,17 +202,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
void sse_encode_list_record_string_string(
|
||||
List<(String, String)> self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_downloader_status(
|
||||
MyDownloaderStatus self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_method(MyMethod self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_network_item_pending_type(
|
||||
MyNetworkItemPendingType self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_opt_Map_String_String(
|
||||
Map<String, String>? self, SseSerializer serializer);
|
||||
|
@ -3,11 +3,9 @@
|
||||
|
||||
// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field
|
||||
|
||||
import 'api/downloader_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'downloader.dart';
|
||||
import 'frb_generated.dart';
|
||||
import 'http_package.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart';
|
||||
@ -46,9 +44,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int dco_decode_box_autoadd_u_64(dynamic raw);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData dco_decode_download_callback_data(dynamic raw);
|
||||
|
||||
@protected
|
||||
int dco_decode_i_32(dynamic raw);
|
||||
|
||||
@ -61,15 +56,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
List<(String, String)> dco_decode_list_record_string_string(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus dco_decode_my_downloader_status(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyMethod dco_decode_my_method(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType dco_decode_my_network_item_pending_type(dynamic raw);
|
||||
|
||||
@protected
|
||||
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw);
|
||||
|
||||
@ -123,10 +112,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int sse_decode_box_autoadd_u_64(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData sse_decode_download_callback_data(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
int sse_decode_i_32(SseDeserializer deserializer);
|
||||
|
||||
@ -140,17 +125,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
List<(String, String)> sse_decode_list_record_string_string(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus sse_decode_my_downloader_status(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyMethod sse_decode_my_method(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType sse_decode_my_network_item_pending_type(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
Map<String, String>? sse_decode_opt_Map_String_String(
|
||||
SseDeserializer deserializer);
|
||||
@ -210,10 +187,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_box_autoadd_u_64(int self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_download_callback_data(
|
||||
DownloadCallbackData self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_i_32(int self, SseSerializer serializer);
|
||||
|
||||
@ -228,17 +201,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
void sse_encode_list_record_string_string(
|
||||
List<(String, String)> self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_downloader_status(
|
||||
MyDownloaderStatus self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_method(MyMethod self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_network_item_pending_type(
|
||||
MyNetworkItemPendingType self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_opt_Map_String_String(
|
||||
Map<String, String>? self, SseSerializer serializer);
|
||||
|
@ -1,68 +0,0 @@
|
||||
import 'package:file_sizes/file_sizes.dart';
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
|
||||
import 'downloader_dialog_ui_model.dart';
|
||||
|
||||
class DownloaderDialogUI extends BaseUI<DownloaderDialogUIModel> {
|
||||
@override
|
||||
Widget? buildBody(BuildContext context, DownloaderDialogUIModel model) {
|
||||
return ContentDialog(
|
||||
constraints:
|
||||
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .54),
|
||||
title: const Text("文件下载..."),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("文件名:${model.fileName}"),
|
||||
const SizedBox(height: 6),
|
||||
Text("保存位置:${model.savePath}"),
|
||||
const SizedBox(height: 6),
|
||||
Text("线程数:${model.threadCount}"),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
"文件大小: ${FileSize.getSize(model.count ?? 0)} / ${FileSize.getSize(model.total ?? 0)}"),
|
||||
const SizedBox(height: 6),
|
||||
Text("下载速度: ${FileSize.getSize(model.speed?.toInt() ?? 0)}/s"),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Text(getStatus(model)),
|
||||
const SizedBox(width: 24),
|
||||
Expanded(
|
||||
child: ProgressBar(
|
||||
value: model.progress == 100 ? null : model.progress,
|
||||
)),
|
||||
const SizedBox(width: 24),
|
||||
],
|
||||
),
|
||||
if (model.isP4kDownload) ...[
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
"提示:因网络波动,若下载进度长时间卡住或速度变慢,可尝试点击暂停下载,之后重新点击P4K分流下载。",
|
||||
style:
|
||||
TextStyle(fontSize: 13, color: Colors.white.withOpacity(.7)),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
FilledButton(
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
||||
child: Text("暂停下载"),
|
||||
),
|
||||
onPressed: () => model.doCancel()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String getUITitle(BuildContext context, DownloaderDialogUIModel model) => "";
|
||||
|
||||
String getStatus(DownloaderDialogUIModel model) {
|
||||
if (model.progress == null && !model.isInMerging) return "准备中...";
|
||||
if (model.isInMerging) return "正在处理文件...";
|
||||
return "${model.progress?.toStringAsFixed(2) ?? "0"}% ";
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/downloader_api.dart'
|
||||
as rust_downloader;
|
||||
import 'package:starcitizen_doctor/common/rust/downloader.dart';
|
||||
|
||||
class DownloaderDialogUIModel extends BaseUIModel {
|
||||
final String fileName;
|
||||
String savePath;
|
||||
final String downloadUrl;
|
||||
final bool showChangeSavePathDialog;
|
||||
final int threadCount;
|
||||
final bool isP4kDownload;
|
||||
|
||||
DownloaderDialogUIModel(this.fileName, this.savePath, this.downloadUrl,
|
||||
{this.showChangeSavePathDialog = false,
|
||||
this.threadCount = 1,
|
||||
this.isP4kDownload = false});
|
||||
|
||||
bool isInMerging = false;
|
||||
|
||||
String? downloadTaskId;
|
||||
|
||||
double? progress;
|
||||
int? speed;
|
||||
int? count;
|
||||
int? total;
|
||||
|
||||
@override
|
||||
void initModel() {
|
||||
super.initModel();
|
||||
_initDownload();
|
||||
}
|
||||
|
||||
_initDownload() async {
|
||||
if (showChangeSavePathDialog) {
|
||||
final userSelect = await FilePicker.platform.saveFile(
|
||||
initialDirectory: savePath,
|
||||
fileName: fileName,
|
||||
lockParentWindow: true);
|
||||
if (userSelect == null) {
|
||||
Navigator.pop(context!);
|
||||
return;
|
||||
}
|
||||
final f = File(userSelect);
|
||||
if (await f.exists()) {
|
||||
await f.delete();
|
||||
}
|
||||
savePath = userSelect;
|
||||
dPrint(savePath);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
if (savePath.endsWith("\\$fileName")) {
|
||||
savePath = savePath.substring(0, savePath.length - fileName.length - 1);
|
||||
}
|
||||
|
||||
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 {
|
||||
rust_downloader
|
||||
.startDownload(
|
||||
url: downloadUrl,
|
||||
savePath: savePath,
|
||||
fileName: "$fileName.downloading",
|
||||
connectionCount: 10)
|
||||
.listen((event) async {
|
||||
dPrint(
|
||||
"id == ${event.id} p ==${event.progress} t==${event.total} s==${event.speed} st==${event.status}");
|
||||
|
||||
downloadTaskId = event.id;
|
||||
count = event.progress;
|
||||
if (event.total != 0) {
|
||||
total = event.total;
|
||||
}
|
||||
speed = event.speed;
|
||||
if (total != null && total != 0 && event.progress != 0) {
|
||||
progress = (event.progress / total!) * 100;
|
||||
}
|
||||
notifyListeners();
|
||||
|
||||
if (progress != null &&
|
||||
progress != 0 &&
|
||||
event.status == const MyDownloaderStatus.noStart()) {
|
||||
Navigator.pop(context!, "cancel");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.status == const MyDownloaderStatus.finished()) {
|
||||
count = total;
|
||||
isInMerging = true;
|
||||
notifyListeners();
|
||||
await File(downloaderSavePath)
|
||||
.rename(downloaderSavePath.replaceAll(".downloading", ""));
|
||||
final bsonFile = File("$downloaderSavePath.bson");
|
||||
if (await bsonFile.exists()) {
|
||||
bsonFile.delete();
|
||||
}
|
||||
Navigator.pop(context!, "$savePath\\$fileName");
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
Navigator.pop(context!, e);
|
||||
}
|
||||
}
|
||||
|
||||
doCancel() async {
|
||||
try {
|
||||
if (downloadTaskId != null) {
|
||||
await rust_downloader.cancelDownload(id: downloadTaskId!);
|
||||
downloadTaskId = null;
|
||||
} else {
|
||||
Navigator.pop(context!, "cancel");
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
@ -3,18 +3,11 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.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/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/ui/tools/downloader/downloader_dialog_ui_model.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:xml/xml.dart';
|
||||
|
||||
import 'downloader/downloader_dialog_ui.dart';
|
||||
|
||||
class ToolsUIModel extends BaseUIModel {
|
||||
bool _working = false;
|
||||
|
||||
@ -341,76 +334,76 @@ class ToolsUIModel extends BaseUIModel {
|
||||
}
|
||||
|
||||
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;
|
||||
if (downloadUrl == null || downloadUrl.isEmpty) {
|
||||
showToast(context!, "该功能维护中,请稍后再试!");
|
||||
return;
|
||||
}
|
||||
if ((await SystemHelper.getPID("\"RSI Launcher\"")).isNotEmpty) {
|
||||
showToast(context!, "RSI启动器正在运行,请先关闭启动器再使用此功能!",
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context!).size.width * .35));
|
||||
return;
|
||||
}
|
||||
final lastSavePath = (box.get("last_save_dir", defaultValue: {}) as Map);
|
||||
dPrint("lastSavePath === $lastSavePath");
|
||||
if (lastSavePath.isNotEmpty) {
|
||||
final s = lastSavePath["save_path"] ?? "";
|
||||
final f = lastSavePath["file_name"] ?? "";
|
||||
if ((await File("$s/$f.downloading").exists()) &&
|
||||
(await File("$s/$f.downloading.bson").exists())) {
|
||||
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(
|
||||
context: context!,
|
||||
dismissWithEsc: false,
|
||||
builder: (context) {
|
||||
return BaseUIContainer(
|
||||
uiCreate: () => DownloaderDialogUI(),
|
||||
modelCreate: () => DownloaderDialogUIModel(
|
||||
fileName, savePath, downloadUrl,
|
||||
showChangeSavePathDialog: !isResumeDownload,
|
||||
threadCount: 10,
|
||||
isP4kDownload: true));
|
||||
});
|
||||
|
||||
if (r != null) {
|
||||
if (r == "cancel") {
|
||||
return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。");
|
||||
} else {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
// String savePath = scInstalledPath;
|
||||
// String fileName = "Data.p4k";
|
||||
// bool isResumeDownload = false;
|
||||
// final box = await Hive.openBox("p4k_cache");
|
||||
// var downloadUrl = AppConf.networkVersionData?.p4kDownloadUrl;
|
||||
// if (downloadUrl == null || downloadUrl.isEmpty) {
|
||||
// showToast(context!, "该功能维护中,请稍后再试!");
|
||||
// return;
|
||||
// }
|
||||
// if ((await SystemHelper.getPID("\"RSI Launcher\"")).isNotEmpty) {
|
||||
// showToast(context!, "RSI启动器正在运行,请先关闭启动器再使用此功能!",
|
||||
// constraints: BoxConstraints(
|
||||
// maxWidth: MediaQuery.of(context!).size.width * .35));
|
||||
// return;
|
||||
// }
|
||||
// final lastSavePath = (box.get("last_save_dir", defaultValue: {}) as Map);
|
||||
// dPrint("lastSavePath === $lastSavePath");
|
||||
// if (lastSavePath.isNotEmpty) {
|
||||
// final s = lastSavePath["save_path"] ?? "";
|
||||
// final f = lastSavePath["file_name"] ?? "";
|
||||
// if ((await File("$s/$f.downloading").exists()) &&
|
||||
// (await File("$s/$f.downloading.bson").exists())) {
|
||||
// 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(
|
||||
// context: context!,
|
||||
// dismissWithEsc: false,
|
||||
// builder: (context) {
|
||||
// return BaseUIContainer(
|
||||
// uiCreate: () => DownloaderDialogUI(),
|
||||
// modelCreate: () => DownloaderDialogUIModel(
|
||||
// fileName, savePath, downloadUrl,
|
||||
// showChangeSavePathDialog: !isResumeDownload,
|
||||
// threadCount: 10,
|
||||
// isP4kDownload: true));
|
||||
// });
|
||||
//
|
||||
// if (r != null) {
|
||||
// if (r == "cancel") {
|
||||
// return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。");
|
||||
// } else {
|
||||
// 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");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Future<bool> _checkPhotographyStatus({bool? setMode}) async {
|
||||
|
Reference in New Issue
Block a user