Skip to content

Commit aafef39

Browse files
committed
windows mwebd.exe verification fix
1 parent 27b1675 commit aafef39

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

tool/wl_templates/MWEBD_mwebd_server_interface_impl.template.dart

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,37 @@ class _MwebdServerInterfaceImpl extends MwebdServerInterface {
2929

3030
static const _kExe = "mwebd.exe";
3131

32+
static String? _cachedWinExePath;
33+
3234
Future<String> _prepareWindowsExeDirPath() async {
33-
final dir = (await StackFileSystem.applicationMwebdDirectory(
34-
"dummy",
35-
)).parent.path;
36-
final exe = File(join(dir, _kExe));
35+
if (_cachedWinExePath == null) {
36+
final dir = (await StackFileSystem.applicationMwebdDirectory(
37+
"dummy",
38+
)).parent.path;
39+
40+
final exe = File(join(dir, _kExe));
41+
42+
if (await exe.exists()) {
43+
await exe.delete();
44+
}
3745

38-
if (!(await exe.exists())) {
3946
final bytes = await rootBundle.load("assets/windows/mwebd.exe");
4047
await exe.writeAsBytes(
4148
bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes),
4249
flush: true,
4350
);
51+
_cachedWinExePath = exe.parent.path;
4452
}
4553

46-
final hash = await sha256.bind(exe.openRead()).first;
54+
final hash = await sha256
55+
.bind(File(join(_cachedWinExePath!, _kExe)).openRead())
56+
.first;
4757
final hexHash = Uint8List.fromList(hash.bytes).toHex;
4858
if (AppConfig.windowsMwebdExeHash != hexHash) {
4959
throw Exception("Windows mwebd.exe sha256 has mismatch!!!");
5060
}
5161

52-
return exe.parent.path;
62+
return _cachedWinExePath!;
5363
}
5464

5565
@override

0 commit comments

Comments
 (0)