Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 96d5873

Browse files
authored
Merge pull request #62 from Lenny4/dev
show the size of all folders
2 parents 3961c56 + 6a16043 commit 96d5873

12 files changed

Lines changed: 270 additions & 73 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
### Removed
1212

13+
## [0.2.0] - 2023-06-18
14+
15+
### Added
16+
17+
- Show the size of all folders in workspace
18+
1319
## [0.1.2] - 2023-06-14
1420

1521
Note: need to install it manually from the github if on windows.

lib/class/folder_property.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
part 'folder_property.g.dart';
4+
5+
@JsonSerializable()
6+
class FolderProperty {
7+
int? size;
8+
String path;
9+
int? nbChildren;
10+
List<FolderProperty> folderProperties;
11+
12+
FolderProperty(
13+
{this.size,
14+
required this.path,
15+
this.nbChildren,
16+
required this.folderProperties});
17+
18+
factory FolderProperty.fromJson(Map<String, dynamic> json) =>
19+
_$FolderPropertyFromJson(json);
20+
21+
Map<String, dynamic> toJson() => _$FolderPropertyToJson(this);
22+
}

lib/class/folder_property.g.dart

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/class/workspace.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:deepfacelab_client/class/folder_property.dart';
12
import 'package:deepfacelab_client/class/locale_storage_question.dart';
23
import 'package:json_annotation/json_annotation.dart';
34

@@ -8,9 +9,13 @@ class Workspace {
89
String name;
910
String path;
1011
List<LocaleStorageQuestion>? localeStorageQuestions;
12+
FolderProperty? folderProperty;
1113

1214
Workspace(
13-
{required this.name, required this.path, this.localeStorageQuestions});
15+
{required this.name,
16+
required this.path,
17+
this.localeStorageQuestions,
18+
this.folderProperty});
1419

1520
factory Workspace.fromJson(Map<String, dynamic> json) =>
1621
_$WorkspaceFromJson(json);

lib/class/workspace.g.dart

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:deepfacelab_client/screens/window_command_screen.dart';
1313
import 'package:deepfacelab_client/screens/workspace_screen.dart';
1414
import 'package:deepfacelab_client/service/locale_storage_service.dart';
1515
import 'package:deepfacelab_client/widget/installation/has_requirements_widget.dart';
16+
import 'package:file_sizes/file_sizes.dart';
1617
import 'package:filesystem_picker/filesystem_picker.dart';
1718
import 'package:flutter/gestures.dart';
1819
import 'package:flutter/material.dart';
@@ -112,7 +113,8 @@ class Root extends HookWidget {
112113
destination: NavigationRailDestination(
113114
icon: const Icon(Icons.movie),
114115
selectedIcon: const Icon(Icons.movie),
115-
label: Text(workspace.name),
116+
label: Text(
117+
'${workspace.name}\n${FileSize.getSize(workspace.folderProperty?.size ?? 0)}'),
116118
),
117119
widget: WorkspaceScreen(initWorkspace: workspace)),
118120
);

lib/screens/workspace_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class WorkspaceScreen extends HookWidget {
6868
if (initWorkspace != null) ...[
6969
const Divider(),
7070
FileManagerWidget(
71-
rootPath: initWorkspace!.path,
71+
workspace: initWorkspace,
7272
controller: mainController.value,
7373
updateFileMissing: updateFileMissingController,
7474
),
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import 'dart:io';
2+
3+
import 'package:collection/collection.dart';
4+
import 'package:deepfacelab_client/class/folder_property.dart';
5+
import 'package:deepfacelab_client/service/workspace_service.dart';
6+
7+
import '../class/workspace.dart';
8+
9+
class FileManagerService {
10+
Future<FolderProperty> _updateFolderProperty(
11+
{required FolderProperty folderProperty,
12+
required List<FileSystemEntity> fileSystemEntities}) async {
13+
folderProperty.nbChildren = fileSystemEntities.length;
14+
var size = 0;
15+
List<String> foldersFound = [];
16+
for (var fileSystemEntity in fileSystemEntities) {
17+
if (fileSystemEntity is File) {
18+
size += await fileSystemEntity.length();
19+
}
20+
if (fileSystemEntity is Directory) {
21+
var thisFileSystemEntities =
22+
await Directory(fileSystemEntity.path).list().toList();
23+
foldersFound.add(fileSystemEntity.path);
24+
var thisFolderProperty = folderProperty.folderProperties
25+
.firstWhereOrNull(
26+
(FolderProperty f) => f.path == fileSystemEntity.path);
27+
if (thisFolderProperty == null) {
28+
thisFolderProperty =
29+
FolderProperty(path: fileSystemEntity.path, folderProperties: []);
30+
folderProperty.folderProperties.add(thisFolderProperty);
31+
}
32+
await _updateFolderProperty(
33+
folderProperty: thisFolderProperty,
34+
fileSystemEntities: thisFileSystemEntities);
35+
size += thisFolderProperty.size!;
36+
}
37+
}
38+
folderProperty.folderProperties = folderProperty.folderProperties
39+
.where((f) => foldersFound.contains(f.path))
40+
.toList();
41+
folderProperty.size = size;
42+
return folderProperty;
43+
}
44+
45+
Future<FolderProperty> updateFolderProperty(
46+
{required String path,
47+
required Workspace workspace,
48+
List<FileSystemEntity>? fileSystemEntities,
49+
bool force = false}) async {
50+
// region get thisFolderProperty
51+
workspace.folderProperty ??=
52+
FolderProperty(path: workspace.path, folderProperties: []);
53+
FolderProperty? thisFolderProperty = workspace.folderProperty;
54+
var pathArray = path
55+
.replaceAll(workspace.path, '')
56+
.split(Platform.pathSeparator)
57+
.where((element) => element != '')
58+
.toList();
59+
var i = 0;
60+
while (thisFolderProperty != null && thisFolderProperty.path != path) {
61+
thisFolderProperty = thisFolderProperty.folderProperties.firstWhereOrNull(
62+
(f) => f.path.endsWith(Platform.pathSeparator + pathArray[i]));
63+
i++;
64+
}
65+
// endregion
66+
if (thisFolderProperty == null) {
67+
return await updateFolderProperty(
68+
path: workspace.path, workspace: workspace, force: true);
69+
}
70+
fileSystemEntities ??= await Directory(path).list().toList();
71+
if (!force && thisFolderProperty.nbChildren == fileSystemEntities.length) {
72+
return thisFolderProperty;
73+
}
74+
if (thisFolderProperty.path != workspace.path) {
75+
return await updateFolderProperty(
76+
path: workspace.path, workspace: workspace, force: true);
77+
}
78+
thisFolderProperty = await _updateFolderProperty(
79+
folderProperty: thisFolderProperty,
80+
fileSystemEntities: fileSystemEntities);
81+
workspace.folderProperty = thisFolderProperty;
82+
WorkspaceService().createUpdateWorkspace(
83+
oldWorkspace: workspace, newWorkspace: workspace);
84+
return thisFolderProperty;
85+
}
86+
}

lib/service/workspace_service.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class WorkspaceService {
4646
if (index != null) {
4747
storage?.workspaces![index] = newWorkspace;
4848
}
49-
storage?.workspaces =
50-
storage.workspaces?.map((w) => Workspace.fromJson(w.toJson())).toList();
49+
storage?.workspaces = [...?storage.workspaces];
5150
store.dispatch({'storage': storage});
5251
}
5352

0 commit comments

Comments
 (0)