open static method

FmodLibrary open()

Implementation

static FmodLibrary open() {
  final (coreName, studioName) = _names;

  final libraryDir = Platform.environment[_libraryPathEnv];
  if (libraryDir != null) {
    return FmodLibrary._(
      _openConfigured('$libraryDir/$coreName', _libraryPathEnv),
      _openConfigured('$libraryDir/$studioName', _libraryPathEnv),
    );
  }

  final sdkRoot = Platform.environment[_sdkPathEnv];
  if (sdkRoot != null) {
    final [coreDir, studioDir] = _sdkLibDirs;
    return FmodLibrary._(
      _openConfigured('$sdkRoot/$coreDir/$coreName', _sdkPathEnv),
      _openConfigured('$sdkRoot/$studioDir/$studioName', _sdkPathEnv),
    );
  }

  try {
    return FmodLibrary._(
      DynamicLibrary.open(coreName),
      DynamicLibrary.open(studioName),
    );
  } on ArgumentError {
    // Fall through to the process image (static or preloaded links).
  }
  final process = DynamicLibrary.process();
  if (process.providesSymbol('FMOD_Studio_System_Create')) {
    return FmodLibrary._(process, process);
  }
  throw StateError(
    'FMOD Engine libraries not found. Download the FMOD Engine SDK for '
    'this platform from fmod.com (registration required), then set '
    '$_sdkPathEnv to the extracted SDK root or $_libraryPathEnv to a '
    'directory containing $coreName and $studioName.',
  );
}