getDownloadedModelsWithInfo static method
Get downloaded models with their file sizes.
Returns a list of StoredModel objects with size information populated from the actual files on disk.
Matches Swift: RunAnywhere.getDownloadedModelsWithInfo()
Implementation
static Future<List<StoredModel>> getDownloadedModelsWithInfo() async {
if (!_isInitialized) {
return [];
}
try {
// Get all models that have localPath set (are downloaded)
final allModels = await availableModels();
final downloadedModels =
allModels.where((m) => m.localPath != null).toList();
final storedModels = <StoredModel>[];
for (final model in downloadedModels) {
// Get the actual file size
final localPath = model.localPath!.toFilePath();
int fileSize = 0;
try {
// Check if it's a directory (for multi-file models) or single file
final file = File(localPath);
final dir = Directory(localPath);
if (await file.exists()) {
fileSize = await file.length();
} else if (await dir.exists()) {
fileSize = await _getDirectorySize(localPath);
}
} catch (e) {
SDKLogger('RunAnywhere.Storage')
.debug('Could not get size for ${model.id}: $e');
}
storedModels.add(StoredModel(
modelInfo: model,
size: fileSize,
));
}
return storedModels;
} catch (e) {
SDKLogger('RunAnywhere.Storage')
.error('Failed to get downloaded models: $e');
return [];
}
}