@@ -135,43 +135,50 @@ private Dictionary<string, GameObject> LoadAssetsBundles()
135135 }
136136 }
137137
138- foreach ( FileInfo assetsFile in assetsDirectory . GetFiles ( "*" , SearchOption . AllDirectories ) . Concat ( globalCarsDirectory . GetFiles ( "*" , SearchOption . AllDirectories ) ) . OrderBy ( x => x . Name ) )
138+ try
139139 {
140- try
140+ foreach ( FileInfo assetsFile in assetsDirectory . GetFiles ( "*" , SearchOption . AllDirectories ) . Concat ( globalCarsDirectory . GetFiles ( "*" , SearchOption . AllDirectories ) ) . OrderBy ( x => x . Name ) )
141141 {
142- Assets assets = Assets . FromUnsafePath ( assetsFile . FullName ) ;
143- AssetBundle bundle = assets . Bundle as AssetBundle ;
144-
142+ try
143+ {
144+ Assets assets = Assets . FromUnsafePath ( assetsFile . FullName ) ;
145+ AssetBundle bundle = assets . Bundle as AssetBundle ;
145146
146- int foundPrefabCount = 0 ;
147147
148- foreach ( string assetName in from name in bundle . GetAllAssetNames ( ) where name . EndsWith ( ".prefab" , StringComparison . InvariantCultureIgnoreCase ) select name )
149- {
150- GameObject carPrefab = bundle . LoadAsset < GameObject > ( assetName ) ;
148+ int foundPrefabCount = 0 ;
149+
150+ foreach ( string assetName in from name in bundle . GetAllAssetNames ( ) where name . EndsWith ( ".prefab" , StringComparison . InvariantCultureIgnoreCase ) select name )
151+ {
152+ GameObject carPrefab = bundle . LoadAsset < GameObject > ( assetName ) ;
153+
154+ string assetKey = $ "{ assetsFile . FullName } ({ assetName } )";
151155
152- string assetKey = $ "{ assetsFile . FullName } ({ assetName } )";
156+ if ( ! assetsList . ContainsKey ( assetKey ) )
157+ {
158+ assetsList . Add ( assetKey , carPrefab ) ;
159+ foundPrefabCount ++ ;
160+ }
161+ }
153162
154- if ( ! assetsList . ContainsKey ( assetKey ) )
163+ if ( foundPrefabCount == 0 )
155164 {
156- assetsList . Add ( assetKey , carPrefab ) ;
157- foundPrefabCount ++ ;
165+ Mod . Instance . Errors . Add ( $ "Can't find a prefab in the asset bundle: { assetsFile . FullName } " ) ;
166+ Mod . Log . LogError ( $ "Can't find a prefab in the asset bundle: { assetsFile . FullName } " ) ;
158167 }
159168 }
160-
161- if ( foundPrefabCount == 0 )
169+ catch ( Exception ex )
162170 {
163- Mod . Instance . Errors . Add ( $ "Can't find a prefab in the asset bundle: { assetsFile . FullName } ") ;
164- Mod . Log . LogError ( $ "Can't find a prefab in the asset bundle: { assetsFile . FullName } ") ;
171+ Mod . Instance . Errors . Add ( $ "Could not load assets file: { assetsFile . FullName } ") ;
172+ Mod . Log . LogError ( $ "Could not load assets file: { assetsFile . FullName } ") ;
173+ Mod . Instance . Errors . Add ( ex ) ;
174+ Mod . Log . LogError ( ex ) ;
165175 }
166176 }
167- catch ( Exception ex )
168- {
169- Mod . Instance . Errors . Add ( $ "Could not load assets file: { assetsFile . FullName } ") ;
170- Mod . Log . LogError ( $ "Could not load assets file: { assetsFile . FullName } ") ;
171- Mod . Instance . Errors . Add ( ex ) ;
172- Mod . Log . LogError ( ex ) ;
173- }
174177 }
178+ catch ( Exception ex )
179+ {
180+ Mod . Log . LogWarning ( "No Assets folder in the custom car folder." ) ;
181+ }
175182
176183 try
177184 {
@@ -216,8 +223,7 @@ private Dictionary<string, GameObject> LoadAssetsBundles()
216223 }
217224 catch ( Exception ex )
218225 {
219- Mod . Log . LogWarning ( $ "Could not find the Assets folder in the toplevel directory. This is fine don't worry about it.") ;
220- Mod . Log . LogWarning ( ex ) ;
226+ Mod . Log . LogWarning ( $ "No Assets folder in toplevel directory.") ;
221227 }
222228
223229 DirectoryInfo profileDirectory = new DirectoryInfo ( Directory . GetParent ( Path . GetDirectoryName ( System . Reflection . Assembly . GetCallingAssembly ( ) . Location ) ) . ToString ( ) ) ;
0 commit comments