Open-source Xbox-inspired desktop launcher for Xodus on Linux
TypeScript
--- a/dlls/xgameruntime/xpackage_chunks.h
+++ b/dlls/xgameruntime/xpackage_chunks.h
@@ -3,6 +3,14 @@
* licensing or download capability is inferred from a layout declaration. */
#define CHUNKS_MAX 4096
#define CHUNKS_TEXT_MAX 1024
+#define CHUNKS_FILES_MAX 65536
+
+struct chunk_file
+{
+ WCHAR path[MAX_PATH];
+ UINT64 bytes;
+ UINT chunk; /* CHUNKS_MAX denotes the registration chunk. */
+};
struct installed_chunk
{
@@ -14,6 +22,9 @@
{
UINT count, groups;
XPackageChunkAvailability registration;
+ BOOL track_sizes;
+ UINT file_count, file_capacity;
+ struct chunk_file *files;
struct installed_chunk chunks[CHUNKS_MAX];
};
@@ -23,6 +34,7 @@
if (!snapshot) return;
for (i = 0; i < snapshot->count; i++)
for (j = 0; j < 3; j++) free(snapshot->chunks[i].attributes[j]);
+ free(snapshot->files);
free(snapshot);
}
@@ -159,8 +171,29 @@
* extracted destination is queried, with Windows case-insensitive lookup.
* Symbolic links in a legitimate temporary launch view are readable files too;
* no file content is read, and no ownership assertion is made. */
+static HRESULT chunks_record_file( struct chunk_snapshot *snapshot, UINT chunk, const WCHAR *path, UINT64 bytes )
+{
+ struct chunk_file *files, *file;
+ UINT capacity;
+ if (!snapshot->track_sizes) return S_OK;
+ if (snapshot->file_count == CHUNKS_FILES_MAX) return HRESULT_FROM_WIN32(ERROR_MORE_DATA);
+ if (snapshot->file_count == snapshot->file_capacity)
+ {
+ capacity = snapshot->file_capacity ? snapshot->file_capacity * 2 : 64;
+ if (!(files = realloc(snapshot->files, capacity * sizeof(*files)))) return E_OUTOFMEMORY;
+ snapshot->files = files;
+ snapshot->file_capacity = capacity;
+ }
+ file = &snapshot->files[snapshot->file_count++];
+ wcscpy(file->path, path);
+ file->bytes = bytes;
+ file->chunk = chunk;
+ return S_OK;
+}
+
static HRESULT chunks_files( const WCHAR *root, xmlNodePtr chunk,
- struct chunk_snapshot *snapshot, XPackageChunkAvailability *availability )
+ struct chunk_snapshot *snapshot, UINT chunk_index,
+ XPackageChunkAvailability *availability )
{
xmlNodePtr node;
char location[MAX_PATH], include[MAX_PATH];
@@ -171,6 +204,8 @@
HANDLE find, readable;
UINT entries;
BOOL found;
+ LARGE_INTEGER size;
+ HRESULT hr;
*availability = XPackageChunkAvailability_Ready;
for (node = chunk->children; node; node = node->next)
{
@@ -214,7 +249,18 @@
readable = CreateFileW(file, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (readable == INVALID_HANDLE_VALUE) *availability = XPackageChunkAvailability_Unavailable;
- else CloseHandle(readable);
+ else
+ {
+ hr = S_OK;
+ if (snapshot->track_sizes)
+ {
+ if (!GetFileSizeEx(readable, &size) || size.QuadPart < 0)
+ *availability = XPackageChunkAvailability_Unavailable;
+ else hr = chunks_record_file(snapshot, chunk_index, file, size.QuadPart);
+ }
+ CloseHandle(readable);
+ if (FAILED(hr)) { FindClose(find); return hr; }
+ }
} while (FindNextFileW(find, &data));
FindClose(find);
if (!found) *availability = XPackageChunkAvailability_Unavailable;
@@ -258,7 +304,7 @@
return S_OK;
}
-static HRESULT chunks_load( const char *identifier, struct chunk_snapshot **out )
+static HRESULT chunks_load( const char *identifier, BOOL track_sizes, struct chunk_snapshot **out )
{
WCHAR path[MAX_PATH], pattern[MAX_PATH], file[MAX_PATH];
WIN32_FIND_DATAW data;
@@ -273,6 +319,7 @@
*out = NULL;
if (FAILED(hr = chunks_resolve(identifier, path))) return hr;
if (!(snapshot = calloc(1, sizeof(*snapshot)))) return E_OUTOFMEMORY;
+ snapshot->track_sizes = track_sizes;
if (!content_join(path, L"layout_*.xml", pattern) ||
(find = FindFirstFileW(pattern, &data)) == INVALID_HANDLE_VALUE)
{ chunks_free(snapshot); return E_GAMEPACKAGE_NO_PACKAGE_IDENTIFIER; }
@@ -298,7 +345,7 @@
{
if (registration) goto done;
registration = TRUE;
- if (FAILED(hr = chunks_files(path, node, snapshot, &snapshot->registration))) goto done;
+ if (FAILED(hr = chunks_files(path, node, snapshot, CHUNKS_MAX, &snapshot->registration))) goto done;
hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
continue;
}
@@ -309,7 +356,7 @@
if (FAILED(hr = chunks_attribute(node, "Languages", &chunk->attributes[0])) ||
FAILED(hr = chunks_attribute(node, "Tags", &chunk->attributes[1])) ||
FAILED(hr = chunks_attribute(node, "Features", &chunk->attributes[2])) ||
- FAILED(hr = chunks_files(path, node, snapshot, &chunk->availability))) goto done;
+ FAILED(hr = chunks_files(path, node, snapshot, snapshot->count - 1, &chunk->availability))) goto done;
hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
}
if (FAILED(hr = chunks_features(snapshot, root))) goto done;
@@ -337,7 +384,7 @@
case XPackageChunkSelectorType_Feature: attribute = 2; break;
default: return E_INVALIDARG;
}
- if (FAILED(hr = chunks_load(identifier, &snapshot))) return hr;
+ if (FAILED(hr = chunks_load(identifier, FALSE, &snapshot))) return hr;
selector.type = type;
/* Each call owns a stable snapshot, holds no lock while calling title code,
* and can safely be reentered or stopped by the callback. */
--- a/dlls/xgameruntime/xpackage_monitors.h
+++ b/dlls/xgameruntime/xpackage_monitors.h
@@ -73,19 +73,33 @@
return TRUE;
}
+static int __cdecl installation_file_compare( const void *a, const void *b )
+{
+ const struct chunk_file *left = a, *right = b;
+ return wcsicmp(left->path, right->path);
+}
+
static HRESULT installation_snapshot( struct installation_monitor *monitor, XPackageInstallationProgress *progress )
{
struct chunk_snapshot *snapshot;
UINT i, j;
BOOL ready, matched;
+ BOOL selected[CHUNKS_MAX] = {0};
+ const WCHAR *last = NULL;
+ UINT64 total = 0;
HRESULT hr;
memset(progress, 0, sizeof(*progress));
- if (FAILED(hr = chunks_load(monitor->identifier, &snapshot))) return hr;
+ /* The SDK uses UINT64_MAX, not zero, while an install total is unknown. */
+ progress->totalBytes = ~(UINT64)0;
+ if (FAILED(hr = chunks_load(monitor->identifier, TRUE, &snapshot))) return hr;
ready = snapshot->registration == XPackageChunkAvailability_Ready;
if (!monitor->count)
{
for (j = 0; j < snapshot->count; j++)
+ {
+ selected[j] = TRUE;
ready &= snapshot->chunks[j].availability == XPackageChunkAvailability_Ready;
+ }
}
for (i = 0; i < monitor->count; i++)
{
@@ -100,16 +114,40 @@
chunks_contains(chunk->attributes[attribute], selector->language, attribute == 0))
{
matched = TRUE;
+ selected[j] = TRUE;
ready &= chunk->availability == XPackageChunkAvailability_Ready;
}
else if (selector->type != XPackageChunkSelectorType_Chunk && !chunk->attributes[attribute])
+ {
+ selected[j] = TRUE;
ready &= chunk->availability == XPackageChunkAvailability_Ready;
+ }
}
ready &= matched;
}
- /* Extracted layouts do not carry trustworthy installed/download byte totals.
- * Preserve zero (unknown), rather than inventing progress or network work. */
- progress->completed = progress->launchable = ready;
+ if (ready)
+ {
+ /* A complete extracted selection has a real installed byte total.
+ * Count only its declared readable files (plus registration), once per
+ * case-insensitive destination path even with overlapping selectors or
+ * FileGroups. Never scan unrelated files or invent a nonzero divisor.
+ * Incomplete layouts have no known size for missing files: leave the
+ * documented unknown state instead of reporting partial bytes as 100%. */
+ if (snapshot->file_count > 1)
+ qsort(snapshot->files, snapshot->file_count, sizeof(*snapshot->files), installation_file_compare);
+ for (j = 0; j < snapshot->file_count; j++)
+ {
+ const struct chunk_file *file = &snapshot->files[j];
+ if (file->chunk != CHUNKS_MAX && !selected[file->chunk]) continue;
+ if (last && !wcsicmp(last, file->path)) continue;
+ if (file->bytes >= ~(UINT64)0 - total)
+ { chunks_free(snapshot); return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); }
+ total += file->bytes;
+ last = file->path;
+ }
+ progress->totalBytes = progress->installedBytes = progress->launchBytes = total;
+ progress->completed = progress->launchable = TRUE;
+ }
chunks_free(snapshot);
return S_OK;
}
@@ -123,7 +161,10 @@
AcquireSRWLockExclusive(&installation_lock);
/* Invalid/disappearing metadata must never retain a stale complete result. */
if (!monitor->closed && (monitor->progress.completed != progress.completed ||
- monitor->progress.launchable != progress.launchable))
+ monitor->progress.launchable != progress.launchable ||
+ monitor->progress.totalBytes != progress.totalBytes ||
+ monitor->progress.installedBytes != progress.installedBytes ||
+ monitor->progress.launchBytes != progress.launchBytes))
{
monitor->progress = progress;
++monitor->revision;