Skip to content

Commit 9224c1a

Browse files
committed
next attempt at fixing the music installer
1 parent a7fb2f0 commit 9224c1a

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ void DownloadUrl(string url)
240240

241241
if (packageLoader.TryParsePackage(stream, file, modData.ModFiles, out var package))
242242
{
243+
var contents = package.Contents.ToArray();
243244
foreach (var kv in download.Extract)
244245
{
245246
var sourcePath = kv.Value.Replace('\\', '/');
@@ -259,7 +260,58 @@ void DownloadUrl(string url)
259260
}
260261

261262
var folderPrefix = sourcePath.TrimEnd('/') + "/";
262-
var folderEntries = package.Contents.Where(entry => entry.StartsWith(folderPrefix, StringComparison.Ordinal));
263+
var folderEntries = contents.Where(entry => entry.StartsWith(folderPrefix, StringComparison.Ordinal)).ToArray();
264+
265+
if (folderEntries.Length == 0)
266+
{
267+
string archiveRoot = null;
268+
foreach (var entry in contents)
269+
{
270+
var separatorIndex = entry.IndexOf('/');
271+
if (separatorIndex <= 0)
272+
{
273+
archiveRoot = null;
274+
break;
275+
}
276+
277+
var entryRoot = entry[..separatorIndex];
278+
if (archiveRoot == null)
279+
archiveRoot = entryRoot;
280+
else if (!string.Equals(archiveRoot, entryRoot, StringComparison.Ordinal))
281+
{
282+
archiveRoot = null;
283+
break;
284+
}
285+
}
286+
287+
if (!string.IsNullOrEmpty(archiveRoot))
288+
{
289+
var nestedPrefix = $"{archiveRoot}/{folderPrefix}";
290+
var nestedEntries = contents.Where(entry => entry.StartsWith(nestedPrefix, StringComparison.Ordinal)).ToArray();
291+
if (nestedEntries.Length > 0)
292+
{
293+
folderPrefix = nestedPrefix;
294+
folderEntries = nestedEntries;
295+
}
296+
else if (string.IsNullOrEmpty(Path.GetExtension(sourcePath)))
297+
{
298+
var rootPrefix = archiveRoot + "/";
299+
var rootEntries = contents.Where(entry => entry.StartsWith(rootPrefix, StringComparison.Ordinal)).ToArray();
300+
if (rootEntries.Length > 0)
301+
{
302+
folderPrefix = rootPrefix;
303+
folderEntries = rootEntries;
304+
}
305+
}
306+
}
307+
308+
if (folderEntries.Length == 0 && string.IsNullOrEmpty(Path.GetExtension(sourcePath)) && contents.Length > 0)
309+
{
310+
folderPrefix = "";
311+
folderEntries = contents;
312+
}
313+
}
314+
263315
var extractedAny = false;
264316

265317
foreach (var entry in folderEntries)

0 commit comments

Comments
 (0)