@@ -64,7 +64,6 @@ public FilenameComponents(string filename) {
64
64
}
65
65
}
66
66
67
-
68
67
// Separator for metadata tokens in the supplied filename.
69
68
private static char [ ] FILENAME_TOKEN_SEPARATOR = new char [ ] { '_' } ;
70
69
// Separator for fields in each metadata token in the supplied
@@ -84,6 +83,8 @@ public FilenameComponents(string filename) {
84
83
public static string [ ] TOKEN_MANIFEST = new [ ] { "manifest" } ;
85
84
// Prefix which identifies the canonical name of this Linux library.
86
85
public static string [ ] TOKEN_LINUX_LIBRARY_BASENAME = new [ ] { "linuxlibname-" } ;
86
+ // Prefix which identifies the original path of a file when the package was exported.
87
+ public static string [ ] TOKEN_EXPORT_PATH = new [ ] { "exportpath-" } ;
87
88
88
89
// Delimiter for version numbers.
89
90
private static char [ ] VERSION_DELIMITER = new char [ ] { '.' } ;
@@ -94,6 +95,9 @@ public FilenameComponents(string filename) {
94
95
private static long VERSION_COMPONENT_MULTIPLIER = 1000 ;
95
96
// Prefix for labels which encode metadata of an asset.
96
97
private static string LABEL_PREFIX = "gvh_" ;
98
+ // Prefix for labels which encode metadata of the asset for 1.2.138 and above.
99
+ // These labels are never removed by the version handler.
100
+ private static string LABEL_PREFIX_PRESERVE = "gvhp_" ;
97
101
// Initialized depending on the version of unity we are running against
98
102
private static HashSet < BuildTarget > targetBlackList = null ;
99
103
// Initialized by parsing BuildTarget enumeration values from
@@ -298,15 +302,34 @@ public static string ScriptingRuntimeDotNetVersion {
298
302
/// </summary>
299
303
public string linuxLibraryBasename = null ;
300
304
305
+ /// <summary>
306
+ /// Path of the file when it was originally exported as a package.
307
+ /// </summary>
308
+ public string exportPath = "" ;
309
+
301
310
/// <summary>
302
311
/// Parse metadata from filename and store in this class.
303
312
/// </summary>
304
313
/// <param name="filename">Name of the file to parse.</param>
305
314
public FileMetadata ( string filename ) {
306
315
this . filename = FileUtils . NormalizePathSeparators ( filename ) ;
307
- filenameCanonical = this . filename ;
316
+ filenameCanonical = ParseMetadataFromFilename ( this . filename ) ;
317
+ ParseMetadataFromAssetLabels ( ) ;
318
+
319
+ // If the export path was specified, override the canonical filename.
320
+ if ( ! String . IsNullOrEmpty ( exportPath ) ) {
321
+ filenameCanonical = ParseMetadataFromFilename ( exportPath ) ;
322
+ }
323
+ UpdateAssetLabels ( ) ;
324
+ }
308
325
309
- var filenameComponents = new FilenameComponents ( filename ) ;
326
+ /// <summary>
327
+ /// Parse metadata from the specified filename and store in this class.
328
+ /// </summary>
329
+ /// <param name="filenameToParse">Parse metadata from the specified filename.</param>
330
+ /// <retuns>Filename with metadata removed.</returns>
331
+ private string ParseMetadataFromFilename ( string filenameToParse ) {
332
+ var filenameComponents = new FilenameComponents ( filenameToParse ) ;
310
333
// Parse metadata from the filename.
311
334
string [ ] tokens =
312
335
filenameComponents . basenameNoExtension . Split (
@@ -320,28 +343,31 @@ public FileMetadata(string filename) {
320
343
}
321
344
filenameComponents . basenameNoExtension = basenameNoExtension ;
322
345
}
323
- // Parse metadata from asset labels if it hasn't been specified in
324
- // the filename.
325
- AssetImporter importer = GetAssetImporter ( ) ;
326
- if ( importer != null ) {
327
- foreach ( string label in AssetDatabase . GetLabels ( importer ) ) {
328
- ParseLabel ( label ) ;
329
- }
330
-
331
- isHandledByPluginImporter = typeof ( PluginImporter ) . IsInstanceOfType ( importer ) ;
332
- }
333
-
334
346
// On Windows the AssetDatabase converts native path separators
335
347
// used by the .NET framework '\' to *nix style '/' such that
336
348
// System.IO.Path generated paths will not match those looked up
337
349
// in the asset database. So we convert the output of Path.Combine
338
350
// here to use *nix style paths so that it's possible to perform
339
351
// simple string comparisons to check for path equality.
340
- filenameCanonical = FileUtils . NormalizePathSeparators ( Path . Combine (
352
+ return FileUtils . NormalizePathSeparators ( Path . Combine (
341
353
filenameComponents . directory ,
342
354
filenameComponents . basenameNoExtension +
343
355
filenameComponents . extension ) ) ;
344
- UpdateAssetLabels ( ) ;
356
+ }
357
+
358
+ /// <summary>
359
+ /// Parse metadata from asset labels.
360
+ /// </summary>
361
+ public void ParseMetadataFromAssetLabels ( ) {
362
+ // Parse metadata from asset labels if it hasn't been specified in
363
+ // the filename.
364
+ AssetImporter importer = GetAssetImporter ( ) ;
365
+ if ( importer != null ) {
366
+ foreach ( string label in AssetDatabase . GetLabels ( importer ) ) {
367
+ ParseLabel ( label ) ;
368
+ }
369
+ isHandledByPluginImporter = typeof ( PluginImporter ) . IsInstanceOfType ( importer ) ;
370
+ }
345
371
}
346
372
347
373
/// <summary>
@@ -423,6 +449,12 @@ private bool ParseToken(string token, string prefix = null) {
423
449
linuxLibraryBasename = String . Join ( FIELD_SEPARATOR [ 0 ] . ToString ( ) , values ) ;
424
450
return true ;
425
451
}
452
+ values = MatchPrefixesGetValues ( token , TOKEN_EXPORT_PATH , prefix ) ;
453
+ if ( values != null ) {
454
+ exportPath = FileUtils . NormalizePathSeparators (
455
+ String . Join ( FIELD_SEPARATOR [ 0 ] . ToString ( ) , values ) ) ;
456
+ return true ;
457
+ }
426
458
return false ;
427
459
}
428
460
@@ -432,7 +464,8 @@ private bool ParseToken(string token, string prefix = null) {
432
464
/// <param name="label">Asset label to parse.</param>
433
465
/// <returns>true if the token is parsed, false otherwise.</returns>
434
466
private bool ParseLabel ( string label ) {
435
- return ParseToken ( label , prefix : LABEL_PREFIX ) ;
467
+ return ParseToken ( label , prefix : LABEL_PREFIX_PRESERVE ) ||
468
+ ParseToken ( label , prefix : LABEL_PREFIX ) ;
436
469
}
437
470
438
471
/// <summary>
@@ -453,11 +486,13 @@ private string CreateToken(string[] fieldPrefixes, string[] values) {
453
486
/// <param name="fieldPrefixes">The first item of this list is used as the prefix.
454
487
/// </param>
455
488
/// <param name="values">Set of values to store with the field.</param>
456
- private static string [ ] CreateLabels ( string [ ] fieldPrefixes , IEnumerable < string > values ) {
489
+ /// <param name="preserve">Always preserve these labels.</param>
490
+ private static string [ ] CreateLabels ( string [ ] fieldPrefixes , IEnumerable < string > values ,
491
+ bool preserve = false ) {
457
492
string prefix = fieldPrefixes [ 0 ] ;
458
493
List < string > labels = new List < string > ( ) ;
459
494
foreach ( var value in values ) {
460
- labels . Add ( CreateLabel ( prefix , value ) ) ;
495
+ labels . Add ( CreateLabel ( prefix , value , preserve : preserve ) ) ;
461
496
}
462
497
463
498
return labels . ToArray ( ) ;
@@ -469,8 +504,9 @@ private static string[] CreateLabels(string[] fieldPrefixes, IEnumerable<string>
469
504
/// <param name="prefix"> The field prefix to be applied to the label.
470
505
/// </param>
471
506
/// <param name="value">The value to store in the field</param>
472
- public static string CreateLabel ( string prefix , string value ) {
473
- return LABEL_PREFIX + prefix + value ;
507
+ /// <param name="preserve">Whether the label should be preserved.</param>
508
+ public static string CreateLabel ( string prefix , string value , bool preserve = false ) {
509
+ return ( preserve ? LABEL_PREFIX_PRESERVE : LABEL_PREFIX ) + prefix + value ;
474
510
}
475
511
476
512
/// <summary>
@@ -580,6 +616,9 @@ public void UpdateAssetLabels() {
580
616
if ( ! String . IsNullOrEmpty ( linuxLibraryBasename ) ) {
581
617
labels . Add ( CreateLabel ( TOKEN_LINUX_LIBRARY_BASENAME [ 0 ] , linuxLibraryBasename ) ) ;
582
618
}
619
+ if ( ! String . IsNullOrEmpty ( exportPath ) ) {
620
+ labels . Add ( CreateLabel ( TOKEN_EXPORT_PATH [ 0 ] , exportPath , preserve : true ) ) ;
621
+ }
583
622
if ( isManifest ) {
584
623
labels . Add ( CreateLabel ( TOKEN_MANIFEST [ 0 ] , null ) ) ;
585
624
}
0 commit comments