61 lines
2.1 KiB
Dart
61 lines
2.1 KiB
Dart
// This entire file could be easily autogenerated.
|
|
|
|
import 'dart:ffi' as ffi;
|
|
import 'dart:io' show Directory, Platform;
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
typedef _GetBoolFunc = ffi.Bool Function(
|
|
ffi.Pointer<Utf8> clientId, ffi.Pointer<Utf8> cacheDir);
|
|
typedef GetBool = bool Function(
|
|
ffi.Pointer<Utf8> clientId, ffi.Pointer<Utf8> cacheDir);
|
|
|
|
typedef _GetStringFunc = ffi.Pointer<Utf8> Function(
|
|
ffi.Pointer<Utf8> clientId, ffi.Pointer<Utf8> cacheDir);
|
|
typedef GetString = ffi.Pointer<Utf8> Function(
|
|
ffi.Pointer<Utf8> clientId, ffi.Pointer<Utf8> cacheDir);
|
|
|
|
typedef _GetVoidFunc = ffi.Void Function(
|
|
ffi.Pointer<Utf8> clientId, ffi.Pointer<Utf8> cacheDir);
|
|
typedef GetVoid = void Function(
|
|
ffi.Pointer<Utf8> clientId, ffi.Pointer<Utf8> cacheDir);
|
|
|
|
typedef _FreeStringFunc = ffi.Void Function(ffi.Pointer<Utf8> str);
|
|
typedef FreeString = void Function(ffi.Pointer<Utf8> str);
|
|
|
|
class UpdaterBindings {
|
|
final ffi.DynamicLibrary _updater;
|
|
|
|
late GetBool checkForUpdate;
|
|
late GetString activeVersion;
|
|
late GetString activePath;
|
|
late FreeString freeString;
|
|
late GetVoid update;
|
|
|
|
static ffi.DynamicLibrary loadLibrary(String directory, String name) {
|
|
if (Platform.isMacOS) {
|
|
return ffi.DynamicLibrary.open(path.join(directory, 'lib$name.dylib'));
|
|
}
|
|
if (Platform.isWindows) {
|
|
return ffi.DynamicLibrary.open(path.join(directory, '$name.dll'));
|
|
}
|
|
// Assume everything else follows the Linux pattern.
|
|
return ffi.DynamicLibrary.open(path.join(directory, 'lib$name.so'));
|
|
}
|
|
|
|
UpdaterBindings()
|
|
: _updater = loadLibrary(
|
|
path.join(Directory.current.path, 'target', 'debug'), "updater") {
|
|
checkForUpdate =
|
|
_updater.lookupFunction<_GetBoolFunc, GetBool>('check_for_update');
|
|
activeVersion =
|
|
_updater.lookupFunction<_GetStringFunc, GetString>('active_version');
|
|
activePath =
|
|
_updater.lookupFunction<_GetStringFunc, GetString>('active_path');
|
|
freeString =
|
|
_updater.lookupFunction<_FreeStringFunc, FreeString>('free_string');
|
|
update = _updater.lookupFunction<_GetVoidFunc, GetVoid>('update');
|
|
}
|
|
}
|