validateModelFiles static method

Future<bool> validateModelFiles(
  1. ModelSpec spec
)

Validates all files in a model specification

Implementation

static Future<bool> validateModelFiles(ModelSpec spec) async {
  for (final file in spec.files) {
    // Get file path based on source type
    final String filePath;

    if (file.source is FileSource) {
      // External file - use path from source
      filePath = (file.source as FileSource).path;
    } else if (file.source is BundledSource) {
      // Bundled source - get platform-specific bundled path
      final bundledSource = file.source as BundledSource;
      filePath = await _getBundledResourcePath(bundledSource.resourceName);
    } else {
      // Downloaded/Asset file - use standard app directory
      filePath = await getModelFilePath(file.filename);
    }

    // Platform-specific validation for bundled files
    if (file.source is BundledSource) {
      if (!await _validateBundledResource(filePath)) {
        debugPrint('Bundled resource validation failed: ${file.filename}');
        return false;
      }
    } else {
      // Standard file validation
      final minSize = getMinimumSize(file.extension);

      if (!await isFileValid(filePath, minSizeBytes: minSize)) {
        debugPrint('Model file validation failed: ${file.filename}');
        return false;
      }
    }
  }
  return true;
}