Skip to content

Commit 76d1341

Browse files
Fixed Daz archive loader to properly build the filepath for subarchives.
1 parent 4051d6f commit 76d1341

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

DazContentInstaller/Services/DazArchiveLoder.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

DazContentInstaller/ViewModels/MainWindowViewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,12 @@ private async Task InstallArchives()
207207
var archivesToInstallNames = archivesToInstall.Select(GetLoadedArchiveName).ToArray();
208208
var existingArchives = await dbContext.Archives
209209
.Where(a => archivesToInstallNames.Contains(a.ArchiveName))
210+
.Include(a => a.AssetFiles)
210211
.ToListAsync();
211212

213+
existingArchives = existingArchives.Where(e => archivesToInstall.Any(a =>
214+
a.ContainedFiles.Count == e.AssetFiles.Count && GetLoadedArchiveName(a).Equals(e.ArchiveName))).ToList();
215+
212216
var loadedArchivesToSkip = archivesToInstall
213217
.IntersectBy(existingArchives.Select(d => d.ArchiveName), GetLoadedArchiveName).ToList();
214218
loadedArchivesToSkip.ForEach(d => d.ArchiveStatus = ArchiveStatus.Duplicate);
@@ -288,7 +292,7 @@ private async Task UninstallArchiveAsync()
288292

289293
dbContext.Archives.Remove(archive);
290294
await dbContext.SaveChangesAsync();
291-
295+
292296
messageProgress.Report($"Uninstalled {archive.ArchiveName}");
293297
percentageProgress.Report(index * increment);
294298
await Task.Yield();

0 commit comments

Comments
 (0)