@@ -55,19 +55,22 @@ public class DazArchiveLoader : IDisposable
5555
5656 private readonly string _archivePath ;
5757 private readonly DirectoryInfo _workingPath ;
58+ private readonly string _baseTemporaryWorkingDirectory ;
5859 private readonly LoadedArchive ? _parentArchive ;
5960
6061 public DazArchiveLoader ( string archivePath )
6162 {
6263 _archivePath = archivePath ;
6364 _workingPath = Directory . CreateTempSubdirectory ( "DazLoader-" + Path . GetFileNameWithoutExtension ( archivePath ) ) ;
65+ _baseTemporaryWorkingDirectory = _workingPath . FullName ;
6466 }
6567
66- public DazArchiveLoader ( string archivePath , string workingPathOverride , LoadedArchive parentArchive )
68+ private DazArchiveLoader ( string archivePath , string workingPathOverride , LoadedArchive parentArchive , string baseTemporaryWorkingDirectory )
6769 {
6870 _archivePath = archivePath ;
6971 _workingPath = new DirectoryInfo ( workingPathOverride ) ;
7072 _parentArchive = parentArchive ;
73+ _baseTemporaryWorkingDirectory = baseTemporaryWorkingDirectory ;
7174 }
7275
7376 public async Task < IEnumerable < LoadedArchive > > LoadArchiveAsync ( IProgress < string > ? messageProgress = null ,
@@ -121,7 +124,7 @@ _parentArchive.ParentArchive is null
121124 Directory . CreateDirectory ( subArchiveWorkingDirectory ) ;
122125
123126 using var subArchiveLoader =
124- new DazArchiveLoader ( subArchiveFile . FullName , subArchiveWorkingDirectory , loadedArchive ) ;
127+ new DazArchiveLoader ( subArchiveFile . FullName , subArchiveWorkingDirectory , loadedArchive , _baseTemporaryWorkingDirectory ) ;
125128 archives . AddRange ( await subArchiveLoader . LoadArchiveAsync ( messageProgress ) ) ;
126129 progress += ( int ) increment ;
127130 percentProgress ? . Report ( progress ) ;
@@ -137,15 +140,18 @@ public void Dispose()
137140 _workingPath . Delete ( true ) ;
138141 }
139142
140- private static string GetSubArchivePath ( string archivePath , LoadedArchive parentArchive )
143+ private string GetSubArchivePath ( string archivePath , LoadedArchive parentArchive )
141144 {
142- var fullPath = GetFullParentArchivePath ( parentArchive ) ;
145+ var cut = archivePath [ _baseTemporaryWorkingDirectory . Length ..] . TrimStart ( Path . DirectorySeparatorChar ) ;
146+ if ( parentArchive . ParentArchive is null )
147+ return cut ;
143148
144- var splitter = archivePath . Split ( Path . DirectorySeparatorChar )
145- . First ( p => p . Contains ( Path . GetFileNameWithoutExtension ( parentArchive . FilePath ) ) ) ;
149+ var parentName = Path . GetFileNameWithoutExtension ( parentArchive . FilePath ) ;
150+ var parentIndex = cut . IndexOf ( parentName , StringComparison . OrdinalIgnoreCase ) ;
151+ if ( parentIndex > - 1 )
152+ cut = cut . Substring ( parentIndex + parentName . Length ) . TrimStart ( Path . DirectorySeparatorChar ) ;
146153
147- var index = archivePath . IndexOf ( splitter , StringComparison . Ordinal ) + splitter . Length ;
148- return archivePath [ index ..] . Trim ( Path . DirectorySeparatorChar ) ;
154+ return cut ;
149155 }
150156
151157 private static string GetFullParentArchivePath ( LoadedArchive parentArchive )
0 commit comments