Skip to content

Commit 4051d6f

Browse files
Start fixing weird filePath detection.
1 parent a9fc9ff commit 4051d6f

2 files changed

Lines changed: 42 additions & 15 deletions

File tree

DazContentInstaller/Services/DazArchiveLoder.cs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public class DazArchiveLoader : IDisposable
4949
private static readonly string[] PackagedArchiveFileExtensions =
5050
[".jpg", ".png", ".zip", ".rar", ".txt"];
5151

52+
// "Documentation" is not part of this on purpose, as some people have a separate documentation directory in their template archive.
5253
private static readonly string[] StandardAssetsBasePaths =
53-
["data", "documentation", "people", "props", "environments", "runtime", "scene", "scripts"];
54+
["data", "people", "props", "environments", "runtime", "scene", "scripts"];
5455

5556
private readonly string _archivePath;
5657
private readonly DirectoryInfo _workingPath;
@@ -69,7 +70,8 @@ public DazArchiveLoader(string archivePath, string workingPathOverride, LoadedAr
6970
_parentArchive = parentArchive;
7071
}
7172

72-
public async Task<IEnumerable<LoadedArchive>> LoadArchiveAsync(IProgress<string>? messageProgress = null, IProgress<int>? percentProgress = null)
73+
public async Task<IEnumerable<LoadedArchive>> LoadArchiveAsync(IProgress<string>? messageProgress = null,
74+
IProgress<int>? percentProgress = null)
7375
{
7476
var archives = new List<LoadedArchive>();
7577

@@ -86,25 +88,30 @@ public async Task<IEnumerable<LoadedArchive>> LoadArchiveAsync(IProgress<string>
8688
? GetSubArchivePath(_archivePath, _parentArchive)
8789
: _archivePath;
8890

89-
var loadedArchive = new LoadedArchive(Path.GetFileNameWithoutExtension(_archivePath), filePath,
91+
var fileName = _parentArchive is not null
92+
? Path.Combine(
93+
_parentArchive.ParentArchive is null
94+
? Path.GetFileName(_parentArchive.FilePath)
95+
: _parentArchive.Name, Path.GetFileName(_archivePath))
96+
: Path.GetFileNameWithoutExtension(_archivePath);
97+
var loadedArchive = new LoadedArchive(fileName, filePath,
9098
archive.UnpackedSize, _parentArchive, DigArchiveBaseDirectory(archive.ArchiveFileNames));
9199

92100
if (!archive.ArchiveFileData.Where(d => !d.IsDirectory)
93-
.All(d => PackagedArchiveFileExtensions.Contains(Path.GetExtension(d.FileName))))
101+
.All(d => PackagedArchiveFileExtensions.Contains(Path.GetExtension(d.FileName))) &&
102+
!IsTemplateArchive(archive))
94103
{
95-
if (IsTemplateArchive(archive))
96-
return archives;
97-
98104
await HandleArchiveAsync(loadedArchive, archive, messageProgress, percentProgress);
99105
messageProgress?.Report($"Analyzed {archive.FileName}");
100106
}
101-
107+
102108
var subArchives = archive.ArchiveFileData
103109
.Where(d => ArchiveFileExtensions.Contains(Path.GetExtension(d.FileName)))
104110
.ToList();
105111

106112
var increment = Math.Ceiling(100D / subArchives.Count);
107113
var progress = 0;
114+
percentProgress?.Report(0);
108115
foreach (var subArchive in subArchives)
109116
{
110117
var subArchiveFile = new FileInfo(Path.Combine(_workingPath.FullName, subArchive.FileName));
@@ -119,7 +126,7 @@ public async Task<IEnumerable<LoadedArchive>> LoadArchiveAsync(IProgress<string>
119126
progress += (int)increment;
120127
percentProgress?.Report(progress);
121128
}
122-
129+
123130
percentProgress?.Report(100);
124131

125132
return [..archives, loadedArchive];
@@ -132,13 +139,22 @@ public void Dispose()
132139

133140
private static string GetSubArchivePath(string archivePath, LoadedArchive parentArchive)
134141
{
142+
var fullPath = GetFullParentArchivePath(parentArchive);
143+
135144
var splitter = archivePath.Split(Path.DirectorySeparatorChar)
136145
.First(p => p.Contains(Path.GetFileNameWithoutExtension(parentArchive.FilePath)));
137146

138147
var index = archivePath.IndexOf(splitter, StringComparison.Ordinal) + splitter.Length;
139148
return archivePath[index..].Trim(Path.DirectorySeparatorChar);
140149
}
141150

151+
private static string GetFullParentArchivePath(LoadedArchive parentArchive)
152+
{
153+
return parentArchive.ParentArchive is null
154+
? Path.GetFileNameWithoutExtension(parentArchive.FilePath)
155+
: Path.Combine(GetFullParentArchivePath(parentArchive.ParentArchive), parentArchive.FilePath);
156+
}
157+
142158
private static bool IsTemplateArchive(SharpSevenZipExtractor archive)
143159
{
144160
var fileNames = archive.ArchiveFileNames;
@@ -147,22 +163,27 @@ private static bool IsTemplateArchive(SharpSevenZipExtractor archive)
147163
f.Contains($"{Path.DirectorySeparatorChar}{b}{Path.DirectorySeparatorChar}",
148164
StringComparison.OrdinalIgnoreCase)));
149165
}
150-
166+
151167
private static string? DigArchiveBaseDirectory(IEnumerable<string> fileNames, string? starter = null)
152168
{
153169
var depth = 0;
154170
while (true)
155171
{
156-
if (depth > 10) return starter;
172+
if (depth > 10) return starter?.Trim(Path.DirectorySeparatorChar);
157173

158174
var basePaths = fileNames.GroupBy(d => d.Split(Path.DirectorySeparatorChar).First()).ToList();
159175
if (StandardAssetsBasePaths.Any(b =>
160-
basePaths.Any(p => p.Key.Equals(b, StringComparison.OrdinalIgnoreCase)))) return starter;
176+
basePaths.Any(p => p.Key.Equals(b, StringComparison.OrdinalIgnoreCase))))
177+
return starter?.Trim(Path.DirectorySeparatorChar);
161178

162179
var deeperLevel =
163180
basePaths.SelectMany(g => g.Select(p => p.Split(g.Key + Path.DirectorySeparatorChar).Last()));
164181
fileNames = deeperLevel;
165-
starter = basePaths.First().Key;
182+
starter += Path.DirectorySeparatorChar + basePaths.FirstOrDefault(d =>
183+
d.Any(b => b.Split(Path.DirectorySeparatorChar).Any(s =>
184+
StandardAssetsBasePaths.Any(p => p.Equals(s, StringComparison.OrdinalIgnoreCase)))))?.Key;
185+
186+
starter ??= basePaths.First().Key;
166187
depth++;
167188
}
168189
}
@@ -192,7 +213,10 @@ private static async Task ExtractMetadataAsync(LoadedArchive loadedArchive, Shar
192213
loadedArchive.Metadata[archiveFileInfo.FileName] = content;
193214

194215
if (metadataFile.EndsWith("Supplement.dsx"))
195-
loadedArchive.Metadata["ProductName"] = GetProductName(loadedArchive, content);
216+
{
217+
var name = GetProductName(loadedArchive, content);
218+
loadedArchive.Metadata["ProductName"] = loadedArchive.Name = name;
219+
}
196220
}
197221

198222
// Analyze folder structure for better naming
@@ -270,7 +294,7 @@ private async Task HandleArchiveAsync(LoadedArchive loadedArchive, SharpSevenZip
270294
}
271295

272296
private void AnalyzeZipContents(LoadedArchive loadedArchive, SharpSevenZipExtractor archiveFile,
273-
IProgress<string>? messageProgress, IProgress<int>? percentProgress)
297+
IProgress<string>? messageProgress, IProgress<int>? percentProgress)
274298
{
275299
var categories = new HashSet<string>();
276300
var assetTypes = new HashSet<AssetType>();

DazContentInstaller/ViewModels/MainWindowViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ private async Task InstallArchives()
197197
var archivesToInstall =
198198
SelectedArchives.Count > 0 ? SelectedArchives.ToList() : LoadedArchives.ToList();
199199

200+
StatusProgress = 0;
200201
IProgress<string> messageProgress = new Progress<string>(s => StatusText = s);
201202
StatusBarColor = Brushes.DodgerBlue;
202203
IProgress<double> percentageProgress = new Progress<double>(s => StatusProgress = (int)s);
@@ -275,6 +276,7 @@ private async Task UninstallArchiveAsync()
275276
IProgress<string> messageProgress = new Progress<string>(s => StatusText = s);
276277
IProgress<double> percentageProgress = new Progress<double>(s => StatusProgress = (int)s);
277278
StatusBarColor = Brushes.DodgerBlue;
279+
StatusProgress = 0;
278280
var increment = Math.Ceiling(100D / archives.Count);
279281

280282
var index = 0;
@@ -301,6 +303,7 @@ private async Task UninstallArchiveAsync()
301303
public async Task LoadArchiveFilesAsync(List<string> filePaths)
302304
{
303305
StatusBarMax = 100 * filePaths.Count;
306+
StatusProgress = 0;
304307
StatusBarColor = Brushes.DodgerBlue;
305308

306309
var index = 0;

0 commit comments

Comments
 (0)