@@ -111,7 +111,10 @@ public void Refresh( string path )
111
111
fileSizes = new long [ dependencies . Length ] ;
112
112
113
113
for ( int i = 0 ; i < dependencies . Length ; i ++ )
114
- fileSizes [ i ] = new FileInfo ( dependencies [ i ] ) . Length ;
114
+ {
115
+ FileInfo assetFile = new FileInfo ( dependencies [ i ] ) ;
116
+ fileSizes [ i ] = assetFile . Exists ? assetFile . Length : 0L ;
117
+ }
115
118
}
116
119
}
117
120
#endregion
@@ -384,12 +387,17 @@ public SearchResult Run( Parameters searchParameters )
384
387
// Initialize the nodes of searched asset(s)
385
388
foreach ( Object obj in objectsToSearchSet )
386
389
{
387
- BeginSearchObject ( obj ) ;
388
-
389
390
string objHash = obj . Hash ( ) ;
390
- ReferenceNode referenceNode ;
391
- if ( ! searchedObjects . TryGetValue ( objHash , out referenceNode ) || referenceNode == null )
392
- searchedObjects [ objHash ] = PopReferenceNode ( obj ) ;
391
+ if ( searchParameters . dontSearchInSourceAssets )
392
+ searchedObjects . Add ( objHash , PopReferenceNode ( obj ) ) ;
393
+ else
394
+ {
395
+ BeginSearchObject ( obj ) ;
396
+
397
+ ReferenceNode referenceNode ;
398
+ if ( ! searchedObjects . TryGetValue ( objHash , out referenceNode ) || referenceNode == null )
399
+ searchedObjects [ objHash ] = PopReferenceNode ( obj ) ;
400
+ }
393
401
}
394
402
395
403
// Progressbar values
@@ -1149,29 +1157,35 @@ private VariableGetterHolder[] GetFilteredVariablesForType( Type type )
1149
1157
FieldInfo [ ] fields = currType . GetFields ( fieldModifiers ) ;
1150
1158
for ( int i = 0 ; i < fields . Length ; i ++ )
1151
1159
{
1160
+ FieldInfo field = fields [ i ] ;
1161
+
1152
1162
// Skip obsolete fields
1153
- if ( Attribute . IsDefined ( fields [ i ] , typeof ( ObsoleteAttribute ) ) )
1163
+ if ( Attribute . IsDefined ( field , typeof ( ObsoleteAttribute ) ) )
1154
1164
continue ;
1155
1165
1156
1166
// Skip primitive types
1157
- Type variableType = fields [ i ] . FieldType ;
1167
+ Type variableType = field . FieldType ;
1158
1168
if ( variableType . IsPrimitiveUnityType ( ) )
1159
1169
continue ;
1160
1170
1161
1171
// Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime
1162
1172
if ( typeof ( Type ) . IsAssignableFrom ( variableType ) || variableType . Namespace == reflectionNameSpace )
1163
1173
continue ;
1164
1174
1175
+ // Searching pointer variables for reference throws ArgumentException
1176
+ if ( variableType . IsPointer )
1177
+ continue ;
1178
+
1165
1179
// Additional filtering for fields:
1166
1180
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
1167
- string fieldName = fields [ i ] . Name ;
1181
+ string fieldName = field . Name ;
1168
1182
if ( typeof ( Graphic ) . IsAssignableFrom ( currType ) &&
1169
1183
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
1170
1184
continue ;
1171
1185
1172
- VariableGetVal getter = fields [ i ] . CreateGetter ( type ) ;
1186
+ VariableGetVal getter = field . CreateGetter ( type ) ;
1173
1187
if ( getter != null )
1174
- validVariables . Add ( new VariableGetterHolder ( fields [ i ] , getter , fields [ i ] . IsSerializable ( ) ) ) ;
1188
+ validVariables . Add ( new VariableGetterHolder ( field , getter , field . IsSerializable ( ) ) ) ;
1175
1189
}
1176
1190
1177
1191
currType = currType . BaseType ;
@@ -1186,28 +1200,43 @@ private VariableGetterHolder[] GetFilteredVariablesForType( Type type )
1186
1200
PropertyInfo [ ] properties = currType . GetProperties ( propertyModifiers ) ;
1187
1201
for ( int i = 0 ; i < properties . Length ; i ++ )
1188
1202
{
1203
+ PropertyInfo property = properties [ i ] ;
1204
+
1189
1205
// Skip obsolete properties
1190
- if ( Attribute . IsDefined ( properties [ i ] , typeof ( ObsoleteAttribute ) ) )
1206
+ if ( Attribute . IsDefined ( property , typeof ( ObsoleteAttribute ) ) )
1191
1207
continue ;
1192
1208
1193
1209
// Skip primitive types
1194
- Type variableType = properties [ i ] . PropertyType ;
1210
+ Type variableType = property . PropertyType ;
1195
1211
if ( variableType . IsPrimitiveUnityType ( ) )
1196
1212
continue ;
1197
1213
1198
1214
// Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime
1199
1215
if ( typeof ( Type ) . IsAssignableFrom ( variableType ) || variableType . Namespace == reflectionNameSpace )
1200
1216
continue ;
1201
1217
1218
+ // Searching pointer variables for reference throws ArgumentException
1219
+ if ( variableType . IsPointer )
1220
+ continue ;
1221
+
1222
+ // Skip properties without a getter function
1223
+ MethodInfo propertyGetter = property . GetGetMethod ( true ) ;
1224
+ if ( propertyGetter == null )
1225
+ continue ;
1226
+
1227
+ // Skip indexer properties
1228
+ if ( property . GetIndexParameters ( ) . Length > 0 )
1229
+ continue ;
1230
+
1202
1231
// No need to check properties with 'override' keyword
1203
- if ( properties [ i ] . IsOverridden ( ) )
1232
+ if ( propertyGetter . GetBaseDefinition ( ) . DeclaringType != propertyGetter . DeclaringType )
1204
1233
continue ;
1205
1234
1206
1235
// Additional filtering for properties:
1207
1236
// 1- Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of Component's to get more useful results
1208
1237
// 2- Ignore "canvasRenderer" and "canvas" properties of Graphic components
1209
1238
// 3 & 4- Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
1210
- string propertyName = properties [ i ] . Name ;
1239
+ string propertyName = property . Name ;
1211
1240
if ( typeof ( Component ) . IsAssignableFrom ( currType ) && ( propertyName == "gameObject" ||
1212
1241
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
1213
1242
continue ;
@@ -1230,9 +1259,9 @@ private VariableGetterHolder[] GetFilteredVariablesForType( Type type )
1230
1259
continue ;
1231
1260
else
1232
1261
{
1233
- VariableGetVal getter = properties [ i ] . CreateGetter ( ) ;
1262
+ VariableGetVal getter = property . CreateGetter ( ) ;
1234
1263
if ( getter != null )
1235
- validVariables . Add ( new VariableGetterHolder ( properties [ i ] , getter , properties [ i ] . IsSerializable ( ) ) ) ;
1264
+ validVariables . Add ( new VariableGetterHolder ( property , getter , property . IsSerializable ( ) ) ) ;
1236
1265
}
1237
1266
}
1238
1267
@@ -1271,13 +1300,16 @@ private bool AssetHasAnyReference( string assetPath )
1271
1300
{
1272
1301
// If a dependency was renamed (which doesn't affect the verified hash, unfortunately),
1273
1302
// force refresh the asset's dependencies and search it again
1274
- FileInfo assetFile = new FileInfo ( dependencies [ i ] ) ;
1275
- if ( ! assetFile . Exists || assetFile . Length != fileSizes [ i ] )
1303
+ if ( ! Directory . Exists ( dependencies [ i ] ) ) // Calling FileInfo.Length on a directory throws FileNotFoundException
1276
1304
{
1277
- cacheEntry . Refresh ( assetPath ) ;
1278
- cacheEntry . searchResult = CacheEntry . Result . Unknown ;
1305
+ FileInfo assetFile = new FileInfo ( dependencies [ i ] ) ;
1306
+ if ( ! assetFile . Exists || assetFile . Length != fileSizes [ i ] )
1307
+ {
1308
+ cacheEntry . Refresh ( assetPath ) ;
1309
+ cacheEntry . searchResult = CacheEntry . Result . Unknown ;
1279
1310
1280
- return AssetHasAnyReference ( assetPath ) ;
1311
+ return AssetHasAnyReference ( assetPath ) ;
1312
+ }
1281
1313
}
1282
1314
1283
1315
if ( assetsToSearchPathsSet . Contains ( dependencies [ i ] ) )
0 commit comments