Skip to content

Commit

Permalink
fix(TextUtils): Add utf8 decode
Browse files Browse the repository at this point in the history
Modify TextUtils.stdDecode() to accept an optional boolean parameter isGBK indicating whether the input is encoded in GBK or UTF-8. If isGBK is true, the method uses the gbk.decode() function to convert the input from byte array to a string, followed by removing escape sequences and extra line breaks with removeEscapeSequences() and removeExtraBreaks(). Otherwise, the method uses utf8.decode() to decode the input.

#1
  • Loading branch information
Xmarmalade committed May 6, 2023
1 parent c8011b2 commit 239361b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/provider/alist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class AlistNotifier extends StateNotifier<AlistState> {
var process = await Process.start('$workingDirectory\\alist.exe', alistArgs,
workingDirectory: workingDirectory);
process.stdout.listen((data) {
String text = TextUtils.stdDecode(data);
String text = TextUtils.stdDecode(data,false);
addOutput(text);
});
process.stderr.listen((data) {
String text = TextUtils.stdDecode(data);
String text = TextUtils.stdDecode(data,false);
addOutput(text);
});
}
Expand All @@ -57,7 +57,7 @@ class AlistNotifier extends StateNotifier<AlistState> {
state = state.copyWith(isRunning: false);
var process = await Process.start('taskkill', ['/f', '/im', 'alist.exe']);
process.stdout.listen((data) {
String text = TextUtils.stdDecode(data);
String text = TextUtils.stdDecode(data,true);
addOutput(text);
});
}
Expand All @@ -72,7 +72,7 @@ class AlistNotifier extends StateNotifier<AlistState> {
'$workingDirectory\\alist.exe', ['admin'],
workingDirectory: workingDirectory);
alistAdmin.stderr.listen((data) {
String text = TextUtils.stdDecode(data);
String text = TextUtils.stdDecode(data,false);
addOutput(text);
});
}
Expand All @@ -83,7 +83,7 @@ class AlistNotifier extends StateNotifier<AlistState> {
'$workingDirectory\\alist.exe', ['version'],
workingDirectory: workingDirectory);
alistVersion.stdout.listen((data) {
String text = TextUtils.stdDecode(data);
String text = TextUtils.stdDecode(data,false);
if (text.contains('Version')) {
String versionInfo = text
.split('Go Version:')[1]
Expand All @@ -105,7 +105,7 @@ class AlistNotifier extends StateNotifier<AlistState> {
final json = jsonDecode(response.body) as Map<String, dynamic>;
final latest = json['tag_name'] as String;
state = state.copyWith(latestVersion: latest);
print('Latest release: $latest');
//print('Latest release: $latest');
}

Future<void> isAlistRunning() async {
Expand Down
9 changes: 7 additions & 2 deletions lib/utils/textutils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:fast_gbk/fast_gbk.dart';

class TextUtils {
Expand All @@ -16,8 +18,11 @@ class TextUtils {
return input;
}

static String stdDecode(List<int> input) {
return removeEscapeSequences(gbk.decode(removeExtraBreaks(input)));
static String stdDecode(List<int> input,bool isGBK) {
if (isGBK) {
return removeEscapeSequences(gbk.decode(removeExtraBreaks(input)));
}
return removeEscapeSequences(utf8.decode(removeExtraBreaks(input)));
}

static bool isNewVersion(String currentVersion, String latestVersion) {
Expand Down

0 comments on commit 239361b

Please # to comment.