WEKIT-ECS / MIRAGE-XR

MirageXR is a reference implementation of an XR training system. MirageXR enables experts and learners to share experience via XR and wearables using ghost tracks, realtime feedback, and anchored instruction.
Other
28 stars 4 forks source link

sketchfab download throws error if two models have the same name #1453

Open fwild opened 1 year ago

fwild commented 1 year ago

The problem is in the way we store the models. Right now the identifier is the model name, and if we try to download one model named "Microscope" and then try to download another model with the same name "MicroScope" this will lead to the fact that we will store the second model data and the archive of the first, which leads us to an error when trying to unarchive the archive.

We have some strange logic in the code:

The error thrown is from the archive which we have created ourselves:

Size mismatch between central header(656) and local header(688)

Solution:

This is the relevant code:

public static async Task LoadModelAsync(ModelPreviewItem modelPreview)
{
    var modelsFolderPath = Path.Combine(Application.persistentDataPath, FOLDER_NAME);
    var archiveUrl = Path.Combine(modelsFolderPath, $"{modelPreview.name}.zip");
    var modelFolder = Path.Combine(modelsFolderPath, modelPreview.name);
    var targetDirectory = Path.Combine(RootObject.Instance.activityManager.ActivityPath, modelPreview.name);
    if (!Directory.Exists(targetDirectory)) Directory.CreateDirectory(targetDirectory);

    // build zip archive, if required (might be slow for big models)
    if (!File.Exists(archiveUrl))
    {
        Debug.Log("model archive not found, taking remedial action...");
        using (var stream = new FileStream(archiveUrl, FileMode.OpenOrCreate))
        using (var zipStream = new ZipOutputStream(stream))
        {
            await ZipUtilities.CompressFolderAsync($"{modelFolder}\\", zipStream);
        }
    }

    // unpack to session folder
    using (var stream = new FileStream(archiveUrl, FileMode.Open))
    {
        await ZipUtilities.ExtractZipFileAsync(stream, targetDirectory);
    }
}

image

cawke commented 1 year ago

The problem is in the way we store the models. Right now the identifier is the model name, and if we try to download one model named "Microscope" and then try to download another model with the same name "MicroScope" this will lead to the fact that we will store the second model data and the archive of the first, which leads us to an error when trying to unarchive the archive. instead of the name as an identifier you should use the uid of the object.

fwild commented 1 year ago

Moreover: currently there is not way to 'flush' the download folder - the only way to clean up space is to uninstall the app. This needs remediation.