load method

  1. @override
Future<void> load()
override

Implementation

@override
Future<void> load() async {
  logger.info('Fetching branch index $branchUrl');
  final html = await fetcher.readAsString(branchUrl);

  for (final match in _hrefRe.allMatches(html)) {
    final href = match.group(1)!;
    if (href.contains('.map')) continue;

    final fileMatch = _fileNameRe.matchAsPrefix(href);
    if (fileMatch == null) continue;

    final target = fileMatch.group(1)!;
    final fileType = fileMatch.group(2)!;
    final version = fileMatch.group(3)!;
    final ext = fileMatch.group(4)!;

    final typeId = '${fileType}_$ext'.toLowerCase();
    final known = UfbtFileType.values.where((type) => type.id == typeId);
    if (known.isNotEmpty) {
      _branchFiles['${known.first.id}|$target'] = href;
    }
    if (_version == null) {
      _version = version;
    } else if (!version.startsWith(_version!)) {
      throw UfbtRuntimeError(
        'Found multiple versions: $_version and $version',
      );
    }
  }

  logger.info('Found version $_version');
}