Implement counting files only of the latest version
This commit is contained in:
71
lib/mod.dart
71
lib/mod.dart
@@ -215,18 +215,71 @@ class Mod {
|
||||
|
||||
int size = 0;
|
||||
if (!skipFileCount) {
|
||||
size =
|
||||
// Find all directories matching version pattern (like "1.0", "1.4", etc.)
|
||||
final versionDirs =
|
||||
Directory(path)
|
||||
.listSync(recursive: true)
|
||||
.listSync(recursive: false)
|
||||
.whereType<Directory>()
|
||||
.where(
|
||||
(entity) =>
|
||||
!entity.path
|
||||
.split(Platform.pathSeparator)
|
||||
.last
|
||||
.startsWith('.'),
|
||||
(dir) => RegExp(
|
||||
r'^\d+\.\d+$',
|
||||
).hasMatch(dir.path.split(Platform.pathSeparator).last),
|
||||
)
|
||||
.length;
|
||||
logger.info('File count in mod directory: $size');
|
||||
.toList();
|
||||
|
||||
// Find the latest version directory (if any)
|
||||
Directory? latestVersionDir;
|
||||
if (versionDirs.isNotEmpty) {
|
||||
// Sort by version number
|
||||
versionDirs.sort((a, b) {
|
||||
final List<int> vA =
|
||||
a.path
|
||||
.split(Platform.pathSeparator)
|
||||
.last
|
||||
.split('.')
|
||||
.map(int.parse)
|
||||
.toList();
|
||||
final List<int> vB =
|
||||
b.path
|
||||
.split(Platform.pathSeparator)
|
||||
.last
|
||||
.split('.')
|
||||
.map(int.parse)
|
||||
.toList();
|
||||
return vA[0] != vB[0]
|
||||
? vA[0] - vB[0]
|
||||
: vA[1] - vB[1]; // Compare major, then minor version
|
||||
});
|
||||
latestVersionDir = versionDirs.last;
|
||||
logger.info(
|
||||
'Latest version directory found: ${latestVersionDir.path.split(Platform.pathSeparator).last}',
|
||||
);
|
||||
}
|
||||
|
||||
// Count all files, excluding older version directories
|
||||
size =
|
||||
Directory(path).listSync(recursive: true).where((entity) {
|
||||
if (entity is! File ||
|
||||
entity.path
|
||||
.split(Platform.pathSeparator)
|
||||
.any((part) => part.startsWith('.'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip files in version directories except for the latest
|
||||
for (final verDir in versionDirs) {
|
||||
if (verDir != latestVersionDir &&
|
||||
entity.path.startsWith(verDir.path)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}).length;
|
||||
|
||||
logger.info(
|
||||
'File count in mod directory (with only latest version): $size',
|
||||
);
|
||||
}
|
||||
|
||||
// Check if this is RimWorld base game or expansion
|
||||
|
Reference in New Issue
Block a user