Add metrics and a UI of some sort
This commit is contained in:
@@ -46,12 +46,16 @@ class Mod {
|
||||
required this.size,
|
||||
});
|
||||
|
||||
static Mod fromDirectory(String path) {
|
||||
static Mod fromDirectory(String path, {bool skipFileCount = false}) {
|
||||
final stopwatch = Stopwatch()..start();
|
||||
|
||||
final aboutFile = File('$path/About/About.xml');
|
||||
if (!aboutFile.existsSync()) {
|
||||
throw Exception('About.xml file does not exist in $aboutFile');
|
||||
}
|
||||
|
||||
final aboutXml = XmlDocument.parse(aboutFile.readAsStringSync());
|
||||
final xmlTime = stopwatch.elapsedMilliseconds;
|
||||
|
||||
late final XmlElement metadata;
|
||||
try {
|
||||
@@ -99,7 +103,7 @@ class Mod {
|
||||
try {
|
||||
description = metadata.findElements('description').first.innerText;
|
||||
} catch (e) {
|
||||
print('$name has no description');
|
||||
// Silent error for optional element
|
||||
}
|
||||
|
||||
List<String> hardDependencies = [];
|
||||
@@ -115,7 +119,7 @@ class Mod {
|
||||
)
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print('$name has no hard dependencies');
|
||||
// Silent error for optional element
|
||||
}
|
||||
|
||||
List<String> softDependencies = [];
|
||||
@@ -128,7 +132,7 @@ class Mod {
|
||||
.map((e) => e.innerText.toLowerCase())
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print('$name has no soft dependencies');
|
||||
// Silent error for optional element
|
||||
}
|
||||
|
||||
List<String> incompatabilities = [];
|
||||
@@ -141,21 +145,31 @@ class Mod {
|
||||
.map((e) => e.innerText.toLowerCase())
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print('$name has no incompatabilities');
|
||||
// Silent error for optional element
|
||||
}
|
||||
|
||||
final metadataTime = stopwatch.elapsedMilliseconds - xmlTime;
|
||||
|
||||
final size =
|
||||
Directory(path)
|
||||
.listSync(recursive: true)
|
||||
.where(
|
||||
(entity) =>
|
||||
!entity.path
|
||||
.split(Platform.pathSeparator)
|
||||
.last
|
||||
.startsWith('.'),
|
||||
)
|
||||
.length;
|
||||
|
||||
int size = 0;
|
||||
if (!skipFileCount) {
|
||||
size = Directory(path)
|
||||
.listSync(recursive: true)
|
||||
.where(
|
||||
(entity) =>
|
||||
!entity.path
|
||||
.split(Platform.pathSeparator)
|
||||
.last
|
||||
.startsWith('.'),
|
||||
)
|
||||
.length;
|
||||
}
|
||||
|
||||
final fileCountTime = stopwatch.elapsedMilliseconds - metadataTime - xmlTime;
|
||||
final totalTime = stopwatch.elapsedMilliseconds;
|
||||
|
||||
// Uncomment for detailed timing
|
||||
print('Mod $name timing: XML=${xmlTime}ms, Metadata=${metadataTime}ms, FileCount=${fileCountTime}ms, Total=${totalTime}ms');
|
||||
|
||||
return Mod(
|
||||
name: name,
|
||||
id: id,
|
||||
@@ -177,7 +191,8 @@ class ModList {
|
||||
|
||||
ModList({required this.path});
|
||||
|
||||
Stream<Mod> load() async* {
|
||||
Stream<Mod> load({bool skipFileCount = false}) async* {
|
||||
final stopwatch = Stopwatch()..start();
|
||||
final directory = Directory(path);
|
||||
print('Loading configuration from: $path');
|
||||
|
||||
@@ -186,32 +201,34 @@ class ModList {
|
||||
final List<String> modDirectories =
|
||||
entities.whereType<Directory>().map((dir) => dir.path).toList();
|
||||
|
||||
print('Found ${modDirectories.length} mod directories:');
|
||||
print('Found ${modDirectories.length} mod directories (${stopwatch.elapsedMilliseconds}ms)');
|
||||
int processedCount = 0;
|
||||
int totalMods = modDirectories.length;
|
||||
|
||||
for (final modDir in modDirectories) {
|
||||
try {
|
||||
// Add a small delay to prevent UI freezing and give time for rendering
|
||||
await Future.delayed(const Duration(milliseconds: 5));
|
||||
final modStart = stopwatch.elapsedMilliseconds;
|
||||
|
||||
final mod = Mod.fromDirectory(modDir);
|
||||
final mod = Mod.fromDirectory(modDir, skipFileCount: skipFileCount);
|
||||
mods[mod.id] = mod;
|
||||
print(
|
||||
'Loaded mod: ${mod.name} (ID: ${mod.id}) from directory: $modDir. '
|
||||
'Size: ${mod.size}, '
|
||||
'Hard Dependencies: ${mod.hardDependencies.join(', ')}, '
|
||||
'Soft Dependencies: ${mod.softDependencies.join(', ')}, '
|
||||
'Incompatibilities: ${mod.incompatabilities.join(', ')}',
|
||||
);
|
||||
processedCount++;
|
||||
|
||||
final modTime = stopwatch.elapsedMilliseconds - modStart;
|
||||
if (processedCount % 50 == 0 || processedCount == totalMods) {
|
||||
print('Progress: Loaded $processedCount/$totalMods mods (${stopwatch.elapsedMilliseconds}ms, avg ${stopwatch.elapsedMilliseconds/processedCount}ms per mod)');
|
||||
}
|
||||
|
||||
yield mod;
|
||||
print('Current total mods loaded: ${mods.length}');
|
||||
} catch (e) {
|
||||
print('Error loading mod from directory: $modDir');
|
||||
print('Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
final totalTime = stopwatch.elapsedMilliseconds;
|
||||
print('Loading complete! Loaded ${mods.length} mods in ${totalTime}ms (${totalTime/mods.length}ms per mod)');
|
||||
} else {
|
||||
print('Mods root directory does not exist: $modsRoot');
|
||||
print('Mods root directory does not exist: $path');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user