Skip to content

Commit 746f435

Browse files
Support checking portable or installation in windows
1 parent 5e2e44d commit 746f435

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

lib/Utils/file_util.dart

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -426,38 +426,35 @@ class FileUtil {
426426
}
427427

428428
WindowsVersion checkWindowsVersion() {
429+
WindowsVersion tmp = WindowsVersion.portable;
430+
429431
final key = calloc<IntPtr>();
432+
final installPathPtr = calloc<Uint16>(260);
433+
final dataSize = calloc<Uint32>();
434+
dataSize.value = 260 * 2;
435+
430436
final result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(windowsKeyPath), 0,
431437
REG_SAM_FLAGS.KEY_READ, key);
432438
if (result == WIN32_ERROR.ERROR_SUCCESS) {
439+
final queryResult = RegQueryValueEx(key.value, TEXT('InstallPath'),
440+
nullptr, nullptr, installPathPtr.cast(), dataSize);
433441

434-
WindowsVersion tmp = WindowsVersion.installed;
435-
436-
// final installPathPtr = calloc<Uint16>(260);
437-
// final dataSize = calloc<Uint32>();
438-
// dataSize.value = 260 * 2;
439-
// final queryResult = RegQueryValueEx(key.value, TEXT('InstallPath'),
440-
// nullptr, nullptr, installPathPtr.cast(), dataSize);
441-
// if (queryResult == WIN32_ERROR.ERROR_SUCCESS) {
442-
// final currentPath = Platform.resolvedExecutable;
443-
// final installPath = installPathPtr.toDartString();
444-
// print("currentPath: $currentPath installPath: $installPath");
445-
// tmp = installPath == currentPath
446-
// ? WindowsVersion.installed
447-
// : WindowsVersion.portable;
448-
// } else {
449-
// tmp = WindowsVersion.portable;
450-
// }
451-
452-
RegCloseKey(key.value);
453-
calloc.free(key);
454-
// calloc.free(installPathPtr);
455-
// calloc.free(dataSize);
456-
return tmp;
457-
} else {
458-
calloc.free(key);
459-
return WindowsVersion.portable;
442+
if (queryResult == WIN32_ERROR.ERROR_SUCCESS) {
443+
final currentPath = Platform.resolvedExecutable;
444+
final installPath = installPathPtr.cast<Utf16>().toDartString();
445+
ILogger.info("Get install path: $installPath and current path: $currentPath");
446+
tmp = installPath == currentPath
447+
? WindowsVersion.installed
448+
: WindowsVersion.portable;
449+
} else {
450+
tmp = WindowsVersion.portable;
451+
}
460452
}
453+
RegCloseKey(key.value);
454+
calloc.free(key);
455+
calloc.free(installPathPtr);
456+
calloc.free(dataSize);
457+
return tmp;
461458
}
462459

463460
static ReleaseAsset getWindowsAsset(String latestVersion, ReleaseItem item) {

0 commit comments

Comments
 (0)