|
1 | 1 | import 'dart:io';
|
2 | 2 | import 'package:path/path.dart' as p;
|
3 | 3 |
|
4 |
| -Future<void> main(List<String> args) async { |
5 |
| - if (!(Platform.isMacOS || Platform.isWindows)) { |
6 |
| - throw UnsupportedError('auto_updater:sign_update'); |
7 |
| - } |
| 4 | +class SignUpdateResult { |
| 5 | + const SignUpdateResult({ |
| 6 | + required this.signature, |
| 7 | + required this.length, |
| 8 | + }); |
8 | 9 |
|
| 10 | + final String signature; |
| 11 | + final int length; |
| 12 | +} |
| 13 | + |
| 14 | +SignUpdateResult signUpdate(List<String> args) { |
9 | 15 | String executable = Platform.isMacOS
|
10 | 16 | ? '${Directory.current.path}/macos/Pods/Sparkle/bin/sign_update'
|
11 | 17 | : p.joinAll(
|
@@ -35,14 +41,34 @@ Future<void> main(List<String> args) async {
|
35 | 41 | );
|
36 | 42 |
|
37 | 43 | int exitCode = processResult.exitCode;
|
| 44 | + |
| 45 | + String? signUpdateOutput; |
38 | 46 | if (exitCode == 0) {
|
39 |
| - String signature = processResult.stdout.toString(); |
| 47 | + signUpdateOutput = processResult.stdout.toString(); |
40 | 48 | if (Platform.isWindows) {
|
41 |
| - signature = signature.replaceFirst('\r\n', '').trim(); |
42 |
| - signature = 'sparkle:dsaSignature="$signature" length="0"'; |
| 49 | + signUpdateOutput = signUpdateOutput.replaceFirst('\r\n', '').trim(); |
| 50 | + signUpdateOutput = 'sparkle:dsaSignature="$signUpdateOutput" length="0"'; |
43 | 51 | }
|
44 |
| - stdout.write(signature); |
| 52 | + stdout.write(signUpdateOutput); |
45 | 53 | } else {
|
46 | 54 | stderr.write(processResult.stderr);
|
47 | 55 | }
|
| 56 | + |
| 57 | + RegExp regex = RegExp(r'sparkle:(dsa|ed)Signature="([^"]+)" length="(\d+)"'); |
| 58 | + RegExpMatch? match = regex.firstMatch(signUpdateOutput!); |
| 59 | + |
| 60 | + if (match == null) { |
| 61 | + throw Exception('Failed to sign update'); |
| 62 | + } |
| 63 | + return SignUpdateResult( |
| 64 | + signature: match.group(2)!, |
| 65 | + length: int.tryParse(match.group(3)!)!, |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +Future<void> main(List<String> args) async { |
| 70 | + if (!(Platform.isMacOS || Platform.isWindows)) { |
| 71 | + throw UnsupportedError('auto_updater:sign_update'); |
| 72 | + } |
| 73 | + signUpdate(args); |
48 | 74 | }
|
0 commit comments