Skip to content

Commit

Permalink
still plenty more todo
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Feb 18, 2025
1 parent 7cee0d3 commit cd761ce
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 169 deletions.
56 changes: 26 additions & 30 deletions Basis/Packages/com.basis.framework/Avatar/BasisAvatarFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,39 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace Basis.Scripts.Avatar
{
public static class BasisAvatarFactory
{
public static BasisLoadableBundle LoadingAvatar = new BasisLoadableBundle()
{
BasisBundleInformation = new BasisBundleInformation()
{
BasisBundleDescription = new BasisBundleDescription()
{
AssetBundleDescription = "LoadingAvatar",
AssetBundleName = "LoadingAvatar"
},
HasError = false,
BasisBundleGenerated = new BasisBundleGenerated()
{
AssetBundleCRC = 0,
AssetBundleHash = "N/A",
AssetMode = "Gameobject"
},
},
UnlockPassword = "N/A",
BasisRemoteBundleEncrypted = new BasisRemoteEncyptedBundle()
{
BundleURL = "LoadingAvatar",
IsLocal = true,
MetaURL = "LoadingAvatar",
},
BasisLocalEncryptedBundle = new BasisStoredEncyptedBundle()
{
LocalBundleFile = "LoadingAvatar",
LocalMetaFile = "LoadingAvatar",
},
};
{
BasisBundleConnector = new BasisBundleConnector()
{
BasisBundleDescription = new BasisBundleDescription()
{
AssetBundleDescription = "LoadingAvatar",
AssetBundleName = "LoadingAvatar"
},
BasisBundleGenerated = new BasisBundleGenerated[]
{
new BasisBundleGenerated("N/A","Gameobject",string.Empty,0,true,string.Empty,string.Empty,true,string.Empty)
},
},
UnlockPassword = "N/A",
BasisRemoteBundleEncrypted = new BasisRemoteEncyptedBundle()
{
BundleURL = "LoadingAvatar",
IsLocal = true,
MetaURL = "LoadingAvatar",
},
BasisLocalEncryptedBundle = new BasisStoredEncyptedBundle()
{
LocalBundleFile = "LoadingAvatar",
LocalMetaFile = "LoadingAvatar",
},
};
public static async Task LoadAvatarLocal(BasisLocalPlayer Player,byte Mode, BasisLoadableBundle BasisLoadableBundle)
{
if (string.IsNullOrEmpty(BasisLoadableBundle.BasisRemoteBundleEncrypted.BundleURL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static BasisLoadableBundle ConvertFromNetwork(AvatarNetworkLoadInformatio
MetaURL = AvatarNetworkLoadInformation.AvatarMetaUrl,
BundleURL = AvatarNetworkLoadInformation.AvatarBundleUrl
},
BasisBundleInformation = new BasisBundleInformation(),
BasisBundleConnector = new BasisBundleConnector(),
BasisLocalEncryptedBundle = new BasisStoredEncyptedBundle(),
UnlockPassword = AvatarNetworkLoadInformation.UnlockPassword
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,36 @@ public static async Task<GameObject> LoadFromWrapper(BasisTrackedBundleWrapper B
if (BasisLoadableBundle.AssetBundle != null)
{
BasisLoadableBundle output = BasisLoadableBundle.LoadableBundle;
switch (output.BasisBundleInformation.BasisBundleGenerated.AssetMode)
if (output.BasisBundleConnector.GetPlatform(out BasisBundleGenerated Generated))
{
case "GameObject":
{
AssetBundleRequest Request = BasisLoadableBundle.AssetBundle.LoadAssetAsync<GameObject>(output.BasisBundleInformation.BasisBundleGenerated.AssetToLoadName);
await Request;
GameObject loadedObject = Request.asset as GameObject;
if (loadedObject == null)
{
BasisDebug.LogError("Unable to proceed, null Gameobject");
BasisLoadableBundle.DidErrorOccur = true;
await BasisLoadableBundle.AssetBundle.UnloadAsync(true);
return null;
}
ChecksRequired ChecksRequired = new ChecksRequired();
if (loadedObject.TryGetComponent<BasisAvatar>(out BasisAvatar BasisAvatar))
switch (Generated.AssetMode)
{
case "GameObject":
{
ChecksRequired.DisableAnimatorEvents = true;
AssetBundleRequest Request = BasisLoadableBundle.AssetBundle.LoadAssetAsync<GameObject>(Generated.AssetToLoadName);
await Request;
GameObject loadedObject = Request.asset as GameObject;
if (loadedObject == null)
{
BasisDebug.LogError("Unable to proceed, null Gameobject");
BasisLoadableBundle.DidErrorOccur = true;
await BasisLoadableBundle.AssetBundle.UnloadAsync(true);
return null;
}
ChecksRequired ChecksRequired = new ChecksRequired();
if (loadedObject.TryGetComponent<BasisAvatar>(out BasisAvatar BasisAvatar))
{
ChecksRequired.DisableAnimatorEvents = true;
}
ChecksRequired.UseContentRemoval = UseContentRemoval;
GameObject CreatedCopy = ContentPoliceControl.ContentControl(loadedObject, ChecksRequired, Position, Rotation, ModifyScale, Scale, Parent);
Incremented = BasisLoadableBundle.Increment();
return CreatedCopy;
}
ChecksRequired.UseContentRemoval = UseContentRemoval;
GameObject CreatedCopy = ContentPoliceControl.ContentControl(loadedObject, ChecksRequired, Position, Rotation, ModifyScale, Scale, Parent);
Incremented = BasisLoadableBundle.Increment();
return CreatedCopy;
}
default:
BasisDebug.LogError("Requested type " + output.BasisBundleInformation.BasisBundleGenerated.AssetMode + " has no handler");
return null;
default:
BasisDebug.LogError("Requested type " + Generated.AssetMode + " has no handler");
return null;
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ public static class BasisBundleManagement

// Dictionary to track ongoing downloads keyed by MetaURL
public static BasisProgressReport FindAllBundlesReport = new BasisProgressReport();
public static async Task DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper BasisTrackedBundleWrapper, BasisProgressReport progressCallback, CancellationToken cancellationToken)
public static async Task<bool> DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper BasisTrackedBundleWrapper, BasisProgressReport progressCallback, CancellationToken cancellationToken)
{
if (BasisTrackedBundleWrapper == null)
{
BasisDebug.LogError("Basis Tracked Bundle Wrapper is null.");
return;
return false;
}

if (BasisTrackedBundleWrapper.LoadableBundle == null || BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted == null)
{
BasisDebug.LogError("Loadable Bundle or Basis Remote Bundle Encrypted is null.");
return;
return false;
}

string metaUrl = BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted.MetaURL;

if (string.IsNullOrEmpty(metaUrl))
{
BasisDebug.LogError("MetaURL is null or empty.");
return;
return false;
}

BasisDebug.Log($"Starting download process for {metaUrl}");
Expand All @@ -44,14 +44,14 @@ public static async Task DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper Ba
if (string.IsNullOrEmpty(UniqueDownload))
{
BasisDebug.LogError("Failed to generate a unique ID.");
return;
return false;
}

string UniqueFilePath = BasisIOManagement.GenerateFilePath($"Temp_{UniqueDownload}{EncryptedMetaBasisSuffix}", LockedBundlesFolder);
if (string.IsNullOrEmpty(UniqueFilePath))
{
BasisDebug.LogError("Failed to generate file path for the unique file.");
return;
return false;
}

if (File.Exists(UniqueFilePath))
Expand All @@ -64,7 +64,7 @@ public static async Task DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper Ba
if (!File.Exists(BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted.MetaURL))
{
BasisDebug.LogError($"Local meta file not found: {metaUrl}");
return;
return false;
}

File.Copy(BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted.MetaURL, UniqueFilePath); // The goal here is just to get the data out
Expand All @@ -81,7 +81,7 @@ public static async Task DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper Ba
if (BasisTrackedBundleWrapper.LoadableBundle == null)
{
BasisDebug.LogError("Failed to decrypt meta file, Loadable Bundle is null.");
return;
return false;
}

// Step 4: Download the bundle file
Expand All @@ -90,27 +90,27 @@ public static async Task DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper Ba
if (string.IsNullOrEmpty(bundleUrl))
{
BasisDebug.LogError("BundleURL is null or empty.");
return;
return false;
}

BasisDebug.Log($"Downloading bundle file from {bundleUrl}");
if (BasisTrackedBundleWrapper.LoadableBundle.BasisBundleInformation == null)
if (BasisTrackedBundleWrapper.LoadableBundle.BasisBundleConnector == null)
{
BasisDebug.LogError("Missing Basis Bundle Information for Loaded Bundle ", BasisDebug.LogTag.System);
return;
return false;
}
if (BasisTrackedBundleWrapper.LoadableBundle.BasisBundleInformation.BasisBundleGenerated == null)
if (BasisTrackedBundleWrapper.LoadableBundle.BasisBundleConnector.BasisBundleGenerated == null)
{
BasisDebug.LogError("Missing Basis Bundle Generated for Loaded Bundle ", BasisDebug.LogTag.System);
return;
return false;
}
string FilePathMeta = BasisIOManagement.GenerateFilePath($"{BasisTrackedBundleWrapper.LoadableBundle.BasisBundleInformation.BasisBundleGenerated.AssetToLoadName}{EncryptedMetaBasisSuffix}", AssetBundlesFolder);
string FilePathBundle = BasisIOManagement.GenerateFilePath($"{BasisTrackedBundleWrapper.LoadableBundle.BasisBundleInformation.BasisBundleGenerated.AssetToLoadName}{EncryptedBundleBasisSuffix}", AssetBundlesFolder);
string FilePathMeta = BasisIOManagement.GenerateFilePath($"{BasisTrackedBundleWrapper.LoadableBundle.BasisBundleConnector.BasisBundleGenerated[0].AssetToLoadName}{EncryptedMetaBasisSuffix}", AssetBundlesFolder);
string FilePathBundle = BasisIOManagement.GenerateFilePath($"{BasisTrackedBundleWrapper.LoadableBundle.BasisBundleConnector.BasisBundleGenerated[0].AssetToLoadName}{EncryptedBundleBasisSuffix}", AssetBundlesFolder);

if (string.IsNullOrEmpty(FilePathMeta) || string.IsNullOrEmpty(FilePathBundle))
{
BasisDebug.LogError("Failed to generate file paths for meta or bundle.");
return;
return false;
}

if (File.Exists(FilePathMeta))
Expand All @@ -125,7 +125,7 @@ public static async Task DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper Ba
if (!File.Exists(bundleUrl))
{
BasisDebug.LogError($"Local bundle file not found: {bundleUrl}");
return;
return false;
}

if (File.Exists(FilePathBundle))
Expand All @@ -143,33 +143,34 @@ public static async Task DownloadStoreMetaAndBundle(BasisTrackedBundleWrapper Ba
BasisDebug.Log($"Successfully downloaded bundle file for {bundleUrl}");
BasisTrackedBundleWrapper.LoadableBundle.BasisLocalEncryptedBundle.LocalBundleFile = FilePathBundle;
BasisTrackedBundleWrapper.LoadableBundle.BasisLocalEncryptedBundle.LocalMetaFile = FilePathMeta;
return true;
}
catch (Exception ex)
{
BasisDebug.LogError($"Error during download and processing of meta: {ex.Message} {ex.StackTrace}");
BasisTrackedBundleWrapper.LoadableBundle.BasisBundleInformation.HasError = true;
return false;
}
}
public static async Task DownloadAndSaveMetaFile(BasisTrackedBundleWrapper BasisTrackedBundleWrapper, BasisProgressReport progressCallback, CancellationToken cancellationToken)
public static async Task<bool> DownloadAndSaveMetaFile(BasisTrackedBundleWrapper BasisTrackedBundleWrapper, BasisProgressReport progressCallback, CancellationToken cancellationToken)
{
if (BasisTrackedBundleWrapper == null)
{
BasisDebug.LogError("BasisTrackedBundleWrapper is null.");
return;
return false;
}

if (BasisTrackedBundleWrapper.LoadableBundle == null || BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted == null)
{
BasisDebug.LogError("LoadableBundle or BasisRemoteBundleEncrypted is null.");
return;
return false;
}

string metaUrl = BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted.MetaURL;

if (string.IsNullOrEmpty(metaUrl))
{
BasisDebug.LogError("MetaURL is null or empty.");
return;
return false;
}

BasisDebug.Log($"Starting download process for {metaUrl}");
Expand All @@ -182,14 +183,14 @@ public static async Task DownloadAndSaveMetaFile(BasisTrackedBundleWrapper Basis
if (string.IsNullOrEmpty(UniqueDownload))
{
BasisDebug.LogError("Failed to generate a unique ID.");
return;
return false;
}

string UniqueFilePath = BasisIOManagement.GenerateFilePath($"{UniqueDownload}{EncryptedMetaBasisSuffix}", LockedBundlesFolder);
if (string.IsNullOrEmpty(UniqueFilePath))
{
BasisDebug.LogError("Failed to generate file path for the unique file.");
return;
return false;
}

if (File.Exists(UniqueFilePath))
Expand All @@ -202,7 +203,7 @@ public static async Task DownloadAndSaveMetaFile(BasisTrackedBundleWrapper Basis
if (!File.Exists(BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted.MetaURL))
{
BasisDebug.LogError($"Local meta file not found: {metaUrl}");
return;
return false;
}

File.Copy(BasisTrackedBundleWrapper.LoadableBundle.BasisRemoteBundleEncrypted.MetaURL, UniqueFilePath); // The goal here is just to get the data out
Expand All @@ -219,16 +220,16 @@ public static async Task DownloadAndSaveMetaFile(BasisTrackedBundleWrapper Basis
if (BasisTrackedBundleWrapper.LoadableBundle == null)
{
BasisDebug.LogError("Failed to decrypt meta file, LoadableBundle is null.");
return;
return false;
}

// Move the meta file to its final destination
string FilePathMeta = BasisIOManagement.GenerateFilePath($"{BasisTrackedBundleWrapper.LoadableBundle.BasisBundleInformation.BasisBundleGenerated.AssetToLoadName}{EncryptedMetaBasisSuffix}", AssetBundlesFolder);
string FilePathMeta = BasisIOManagement.GenerateFilePath($"{BasisTrackedBundleWrapper.LoadableBundle.BasisBundleConnector.BasisBundleGenerated[0].AssetToLoadName}{EncryptedMetaBasisSuffix}", AssetBundlesFolder);

if (string.IsNullOrEmpty(FilePathMeta))
{
BasisDebug.LogError("Failed to generate file path for the meta file.");
return;
return false;
}

if (File.Exists(FilePathMeta))
Expand All @@ -241,11 +242,12 @@ public static async Task DownloadAndSaveMetaFile(BasisTrackedBundleWrapper Basis
BasisTrackedBundleWrapper.LoadableBundle.BasisLocalEncryptedBundle.LocalMetaFile = FilePathMeta;

BasisDebug.Log($"Meta file saved successfully at {FilePathMeta}");
return true;
}
catch (Exception ex)
{
BasisDebug.LogError($"Error during download and processing of meta: {ex.Message}");
BasisTrackedBundleWrapper.LoadableBundle.BasisBundleInformation.HasError = true;
return false;
}
}
public static async Task ProcessOnDiscMetaDataAsync(BasisTrackedBundleWrapper basisTrackedBundleWrapper, BasisStoredEncyptedBundle BasisStoredEncyptedBundle, BasisProgressReport progressCallback, CancellationToken cancellationToken)
Expand Down
Loading

0 comments on commit cd761ce

Please sign in to comment.