init method

Future<void> init({
  1. required Consoler<ConsoleProgram> console,
  2. bool verbose = false,
})

Implementation

Future<void> init({required Consoler console, bool verbose = false}) async {
  _packs.clear();
  final directory = Directory('packs');
  if (!await directory.exists()) {
    await directory.create();
    print(
        'WARNING: No packs directory found. Please add packs to the server.');
  }
  await for (final file in directory.list()) {
    if (file is File) {
      final fileName = p.basename(file.path);
      final extension = fileName.split('.').last;
      if (extension != _stnxExtension && extension != _metadataExtension) {
        console.print(
            'WARNING: Invalid pack file extension: $fileName. Skipping.',
            level: LogLevel.warning);
        continue;
      }
      var name =
          fileName.substring(0, fileName.length - _stnxExtension.length - 1);
      if (name.isEmpty) name = kCorePackId;
      if (extension == _stnxExtension) {
        final data = SetonixData.fromData(await file.readAsBytes());
        _packs[name] = data;
      } else {
        final metadata =
            ServerDataMetadataMapper.fromJson(await file.readAsString());
        _metadata[name] = metadata;
      }
    }
  }
  final coreIncluded = _packs.containsKey(kCorePackId);
  console.print(
      'Loaded ${_packs.length} pack(s). ${coreIncluded ? '(with core pack)' : '(without core pack)'}',
      level: LogLevel.info);
  if (_packs.isEmpty) {
    console.print('No packs loaded.', level: LogLevel.warning);
  } else {
    console.print('Loaded pack(s): ${_packs.keys.join(', ')}',
        level: LogLevel.verbose);
  }
}