@@ -61,7 +61,75 @@ public FolderTreeViewModel(ObjectEditorModel model)
61
61
[ Reactive ]
62
62
public float IndexingProgress { get ; set ; }
63
63
64
- private async Task LoadObjDirectoryAsync ( string directory , bool useExistingIndex )
64
+ async Task LoadObjDirectoryAsync ( string directory , bool useExistingIndex )
65
+ {
66
+ DirectoryItems = new ( await LoadObjDirectoryCoreAsync ( directory , useExistingIndex ) ) ;
67
+
68
+ async Task < List < FileSystemItemBase > > LoadObjDirectoryCoreAsync ( string directory , bool useExistingIndex )
69
+ {
70
+ var result = new List < FileSystemItemBase > ( ) ;
71
+
72
+ if ( string . IsNullOrEmpty ( directory ) )
73
+ {
74
+ return result ;
75
+ }
76
+
77
+ var dirInfo = new DirectoryInfo ( directory ) ;
78
+
79
+ if ( ! dirInfo . Exists )
80
+ {
81
+ return result ;
82
+ }
83
+
84
+ await Model . LoadObjDirectoryAsync ( directory , Progress , useExistingIndex ) ;
85
+
86
+ var groupedObjects = Model . HeaderIndex
87
+ . Where ( o => ( string . IsNullOrEmpty ( FilenameFilter ) || o . Value . Name . Contains ( FilenameFilter , StringComparison . CurrentCultureIgnoreCase ) ) && ( ! DisplayVanillaOnly || o . Value . SourceGame == SourceGame . Vanilla ) )
88
+ . GroupBy ( o => o . Value . ObjectType )
89
+ . OrderBy ( fsg => fsg . Key . ToString ( ) ) ;
90
+
91
+ foreach ( var objGroup in groupedObjects )
92
+ {
93
+ ObservableCollection < FileSystemItemBase > subNodes ; //(objGroup.Select(o => new FileSystemItemBase(o.Key, o.Value.DatFileInfo.S5Header.Name.Trim())));
94
+ if ( objGroup . Key == ObjectType . Vehicle )
95
+ {
96
+ subNodes = [ ] ;
97
+ foreach ( var vg in objGroup
98
+ . GroupBy ( o => o . Value . VehicleType )
99
+ . OrderBy ( vg => vg . Key . ToString ( ) ) )
100
+ {
101
+ var vehicleSubNodes = new ObservableCollection < FileSystemItemBase > ( vg . Select ( o => new FileSystemItem ( o . Key , o . Value . Name . Trim ( ) , o . Value . SourceGame ) ) ) ;
102
+
103
+ if ( vg . Key == null )
104
+ {
105
+ // this should be impossible - object says its a vehicle but doesn't have a vehicle type
106
+ // todo: move validation into the loading stage or cstr of IndexObjectHeader
107
+ continue ;
108
+ }
109
+
110
+ subNodes . Add ( new FileSystemVehicleGroup (
111
+ string . Empty ,
112
+ vg . Key . Value ,
113
+ vehicleSubNodes ) ) ;
114
+ }
115
+ }
116
+ else
117
+ {
118
+ subNodes = new ObservableCollection < FileSystemItemBase > (
119
+ objGroup . Select ( o => new FileSystemItem ( o . Key , o . Value . Name . Trim ( ) , o . Value . SourceGame ) ) ) ;
120
+ }
121
+
122
+ result . Add ( new FileSystemItemGroup (
123
+ string . Empty ,
124
+ objGroup . Key ,
125
+ subNodes ) ) ;
126
+ }
127
+
128
+ return result ;
129
+ }
130
+ }
131
+
132
+ async Task LoadObjDirectoryAsyncNew ( string directory , bool useExistingIndex )
65
133
{
66
134
DirectoryItems = new ( await LoadObjDirectoryCoreAsync ( directory , useExistingIndex ) ) ;
67
135
0 commit comments