@@ -71,72 +71,6 @@ public void Dispose()
7171 m_resourceReaders . Clear ( ) ;
7272 }
7373
74- private UnityFileReader GetResourceReader ( string filename )
75- {
76- var slashPos = filename . LastIndexOf ( '/' ) ;
77- if ( slashPos > 0 )
78- {
79- filename = filename . Remove ( 0 , slashPos + 1 ) ;
80- }
81-
82- if ( ! m_resourceReaders . TryGetValue ( filename , out var reader ) )
83- {
84- try
85- {
86- reader = new UnityFileReader ( "archive:/" + filename , 4 * 1024 * 1024 ) ;
87- }
88- catch ( Exception )
89- {
90- try
91- {
92- reader = new UnityFileReader ( Path . Join ( m_Folder , filename ) , 4 * 1024 * 1024 ) ;
93- }
94- catch ( Exception )
95- {
96- Console . Error . WriteLine ( ) ;
97- Console . Error . WriteLine ( $ "Error opening resource file { filename } ") ;
98- reader = null ;
99- }
100- }
101-
102- m_resourceReaders [ filename ] = reader ;
103- }
104-
105- return reader ;
106- }
107-
108- // Extends the CRC with a range of the main serialized file, unless CRC is disabled.
109- private void AppendCrc ( long offset , int size )
110- {
111- if ( ! m_SkipCrc )
112- m_Crc32 = m_Reader . ComputeCRC ( offset , size , m_Crc32 ) ;
113- }
114-
115- // Extends the CRC with the content of an external stream segment (StreamingInfo /
116- // StreamedResource), unless CRC is disabled. Content-addressed paths fold in the path
117- // string; other paths read the actual bytes from the companion resource file.
118- private void AppendStreamCrc ( long offset , int size , string path )
119- {
120- if ( m_SkipCrc )
121- return ;
122-
123- // A cah:/ stream always references the entire resource file: the hash in the path
124- // is the hash of the whole file, so the path uniquely identifies the bytes and we
125- // fold it into the CRC rather than reading them. The offset/size fields only exist
126- // for backward compatibility with the older output format that packed multiple
127- // resources into one file; ContentDirectory builds never do this (offset is 0 and
128- // size is the full file), which is why ignoring offset/size here is correct.
129- if ( path . StartsWith ( ContentAddressedPrefix , StringComparison . OrdinalIgnoreCase ) )
130- {
131- m_Crc32 = Crc32Algorithm . Append ( m_Crc32 , Encoding . UTF8 . GetBytes ( path ) ) ;
132- return ;
133- }
134-
135- var resourceFile = GetResourceReader ( path ) ;
136- if ( resourceFile != null )
137- m_Crc32 = resourceFile . ComputeCRC ( offset , size , m_Crc32 ) ;
138- }
139-
14074 // Walks the serialized object rooted at `node`, whose data starts at `offset` in the reader,
14175 // emitting every PPtr through the callback. Returns a CRC32 fingerprint of the object's content
14276 // (0 when CRC is disabled). `objectId` is the analyzer id of this object, forwarded to the callback.
@@ -409,4 +343,71 @@ private void ExtractPPtr(string referencedType)
409343 }
410344 }
411345 }
346+
347+ // Extends the CRC with a range of the main serialized file, unless CRC is disabled.
348+ private void AppendCrc ( long offset , int size )
349+ {
350+ if ( ! m_SkipCrc )
351+ m_Crc32 = m_Reader . ComputeCRC ( offset , size , m_Crc32 ) ;
352+ }
353+
354+ // Extends the CRC with the content of an external stream segment (StreamingInfo /
355+ // StreamedResource), unless CRC is disabled. Content-addressed paths fold in the path
356+ // string; other paths read the actual bytes from the companion resource file.
357+ private void AppendStreamCrc ( long offset , int size , string path )
358+ {
359+ if ( m_SkipCrc )
360+ return ;
361+
362+ // A cah:/ stream always references the entire resource file: the hash in the path
363+ // is the hash of the whole file, so the path uniquely identifies the bytes and we
364+ // fold it into the CRC rather than reading them. The offset/size fields only exist
365+ // for backward compatibility with the older output format that packed multiple
366+ // resources into one file; ContentDirectory builds never do this (offset is 0 and
367+ // size is the full file), which is why ignoring offset/size here is correct.
368+ if ( path . StartsWith ( ContentAddressedPrefix , StringComparison . OrdinalIgnoreCase ) )
369+ {
370+ m_Crc32 = Crc32Algorithm . Append ( m_Crc32 , Encoding . UTF8 . GetBytes ( path ) ) ;
371+ return ;
372+ }
373+
374+ var resourceFile = GetResourceReader ( path ) ;
375+ if ( resourceFile != null )
376+ m_Crc32 = resourceFile . ComputeCRC ( offset , size , m_Crc32 ) ;
377+ }
378+
379+ private UnityFileReader GetResourceReader ( string filename )
380+ {
381+ var slashPos = filename . LastIndexOf ( '/' ) ;
382+ if ( slashPos > 0 )
383+ {
384+ filename = filename . Remove ( 0 , slashPos + 1 ) ;
385+ }
386+
387+ if ( ! m_resourceReaders . TryGetValue ( filename , out var reader ) )
388+ {
389+ try
390+ {
391+ reader = new UnityFileReader ( "archive:/" + filename , 4 * 1024 * 1024 ) ;
392+ }
393+ catch ( Exception )
394+ {
395+ try
396+ {
397+ reader = new UnityFileReader ( Path . Join ( m_Folder , filename ) , 4 * 1024 * 1024 ) ;
398+ }
399+ catch ( Exception )
400+ {
401+ Console . Error . WriteLine ( ) ;
402+ Console . Error . WriteLine ( $ "Error opening resource file { filename } ") ;
403+ reader = null ;
404+ }
405+ }
406+
407+ m_resourceReaders [ filename ] = reader ;
408+ }
409+
410+ return reader ;
411+ }
412+
412413}
0 commit comments