55 lines
1.6 KiB
Dart
55 lines
1.6 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:logger/logger.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
import 'platform_adapter.dart';
|
|
|
|
class MoneroLibraryLoader {
|
|
MoneroLibraryLoader({required this.logger, PlatformAdapter? adapter})
|
|
: _adapter = adapter ?? const PlatformAdapter();
|
|
|
|
final Logger logger;
|
|
final PlatformAdapter _adapter;
|
|
|
|
String locate() {
|
|
final overridePath = Platform.environment['PEYA_LIBWALLET'] ??
|
|
Platform.environment['PEYA_WALLET_LIB'] ??
|
|
Platform.environment['SALVIUM_LIBWALLET'] ??
|
|
Platform.environment['SALVIUM_WALLET_LIB'];
|
|
if (overridePath != null && overridePath.isNotEmpty) {
|
|
return _validatePath(overridePath);
|
|
}
|
|
|
|
final searchBases = <String>{
|
|
Directory.current.path,
|
|
p.dirname(Platform.resolvedExecutable),
|
|
};
|
|
|
|
for (final base in searchBases) {
|
|
for (final root in _adapter.moneroLibrarySearchPaths()) {
|
|
for (final libName in _adapter.moneroLibraryNames()) {
|
|
final candidate = p.normalize(p.join(base, root, libName));
|
|
if (File(candidate).existsSync()) {
|
|
logger.i('Using Peya libwallet2_api_c from $candidate');
|
|
return candidate;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
throw StateError(
|
|
'Peya libwallet2_api_c not found. Set PEYA_LIBWALLET or build monero_c.',
|
|
);
|
|
}
|
|
|
|
String _validatePath(String rawPath) {
|
|
final resolved = p.normalize(rawPath);
|
|
if (!File(resolved).existsSync()) {
|
|
throw StateError('Peya libwallet2_api_c not found at $resolved');
|
|
}
|
|
logger.i('Using Peya libwallet2_api_c from $resolved');
|
|
return resolved;
|
|
}
|
|
}
|