Skip to content

Commit

Permalink
refactor: adapt parseWgetProgress to parseCurlProgress
Browse files Browse the repository at this point in the history
Since Quickemu 4.9.3 quickget downloads everything except Ubuntu daily images with curl, via the web_get() function internal to quickget.

This change adapts the progress parsing to curl's progress output and accounts for a bug in quickget where it stopped reporting if wget/curl is the external download tool.
  • Loading branch information
flexiondotorg committed Jun 26, 2024
1 parent 7a21dd2 commit a8ada5a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Future<List<OperatingSystem>> loadOperatingSystems(bool showUbuntus) async {
Tuple5 supportedVersion;
if (chunks.length == 4) // Legacy version of quickget
{
supportedVersion = Tuple5.fromList([...chunks, "wget"]);
supportedVersion = Tuple5.fromList([...chunks, "curl"]);
} else {
var t5 = [chunks[0], chunks[1], chunks[2], chunks[3], chunks[4]].toList();
supportedVersion = Tuple5.fromList(t5);
Expand Down
14 changes: 7 additions & 7 deletions lib/src/pages/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Downloader extends StatefulWidget {

class _DownloaderState extends State<Downloader> {
final notificationsClient = NotificationsClient();
final wgetPattern = RegExp("( [0-9.]+%)");
final curlPattern = RegExp("( [0-9.]+%)");
late final Stream<double> _progressStream;
bool _downloadFinished = false;
var controller = StreamController<double>();
Expand All @@ -43,8 +43,8 @@ class _DownloaderState extends State<Downloader> {
super.initState();
}

void parseWgetProgress(String line) {
var matches = wgetPattern.allMatches(line).toList();
void parseCurlProgress(String line) {
var matches = curlPattern.allMatches(line).toList();
if (matches.isNotEmpty) {
var percent = matches[0].group(1);
if (percent != null) {
Expand All @@ -60,9 +60,9 @@ class _DownloaderState extends State<Downloader> {
options.add(widget.option!.option);
}
Process.start('quickget', options).then((process) {
if (widget.option!.downloader == 'wget') {
process.stderr.transform(utf8.decoder).forEach(parseWgetProgress);
} else if (widget.option!.downloader == 'zsync') {
if (widget.option!.downloader != 'zsync') {
process.stderr.transform(utf8.decoder).forEach(parseCurlProgress);
} else {
controller.add(-1);
}

Expand Down Expand Up @@ -118,7 +118,7 @@ class _DownloaderState extends State<Downloader> {
stream: _progressStream,
builder: (context, AsyncSnapshot<double> snapshot) {
var data = !snapshot.hasData ||
widget.option!.downloader != 'wget'
widget.option!.downloader != 'curl'
? null
: snapshot.data;
return Column(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/downloader/download_label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DownloadLabel extends StatelessWidget {
? Text(context.t('Download finished.'))
: data != null
? downloader != 'zsync'
? downloader == 'wget' || downloader == 'aria2c'
? downloader == 'curl' || downloader == ''
? Text(context.t('Downloading... {0}%',
args: [(data! * 100).toInt()]))
: Text(context.t('{0} Mbs downloaded', args: [data!]))
Expand Down

0 comments on commit a8ada5a

Please sign in to comment.