locateDeviceHid function

String? locateDeviceHid({
  1. Map<String, String>? env,
  2. String? scriptPath,
})

The helper: deviceHidEnv, then a build inside glint's package, then the download cache; null when none exists.

Implementation

String? locateDeviceHid({Map<String, String>? env, String? scriptPath}) {
  final e = env ?? Platform.environment;
  final fromEnv = e[deviceHidEnv];
  if (fromEnv != null && fromEnv.isNotEmpty) return fromEnv;
  Directory dir;
  try {
    dir = File(scriptPath ?? Platform.script.toFilePath()).parent;
  } catch (_) {
    dir = Directory.current;
  }
  for (var i = 0; i < 6; i++) {
    final p = '${dir.path}/$kDeviceHidBuild';
    if (File(p).existsSync()) return p;
    final parent = dir.parent;
    if (parent.path == dir.path) break;
    dir = parent;
  }
  final cached = cachedDeviceHidPath(env: e);
  return File(cached).existsSync() ? markHelperUsed(cached) : null;
}