initArgon2 function
Argon2FfiFlutter
initArgon2()
Implementation
Argon2FfiFlutter initArgon2() {
if (Platform.isMacOS) {
Argon2.resolveLibraryForceDynamic = true;
}
return Argon2FfiFlutter(resolveLibrary: (libraryName) {
var insideSdk = path.join('znn_sdk_dart', 'lib', 'src', 'argon2', 'blobs');
var currentPathListParts = path.split(Directory.current.path);
currentPathListParts.removeLast();
var executablePathListParts = path.split(Platform.resolvedExecutable);
executablePathListParts.removeLast();
var possiblePaths = List<String>.empty(growable: true);
possiblePaths.add(Directory.current.path);
possiblePaths.add(path.joinAll(executablePathListParts));
executablePathListParts.removeLast();
possiblePaths
.add(path.join(path.joinAll(executablePathListParts), 'Resources'));
possiblePaths.add(path.join(path.joinAll(currentPathListParts), insideSdk));
possiblePaths.add(
path.join(path.joinAll(currentPathListParts), 'packages', insideSdk));
var libraryPath = '';
var found = false;
for (var currentPath in possiblePaths) {
libraryPath = path.join(currentPath, libraryName);
var libFile = File(libraryPath);
if (libFile.existsSync()) {
found = true;
break;
}
}
if (!found) {
throw invalidArgon2LibPathException;
}
logger.info('Loading ' + libraryName + ' from path ' + libraryPath);
return libraryPath;
});
}