public static bool CheckIfModelInstalled(ModelSaber.ModelSaberEntry model) { string modelFileName = model.Download.Substring(model.Download.LastIndexOf("/") + 1); if (model.Type == "saber") { return(InstalledSabers.Contains(modelFileName)); } else if (model.Type == "bloq") { return(InstalledBloqs.Contains(modelFileName)); } else if (model.Type == "avatar") { return(InstalledAvatars.Contains(modelFileName)); } else if (model.Type == "platform") { return(InstalledPlatforms.Contains(modelFileName)); } else { return(false); } }
public static async void DownloadModel(ModelSaber.ModelSaberEntry model, string DownloadPath) { byte[] fileBytes = await ModelSaber.ModelSaberUtils.GetModelBytes(model); string modelFileName = model.Download.Substring(model.Download.LastIndexOf("/") + 1); Plugin.Log.Info("Checking hash..."); if (model.Hash.ToLower() == MD5Checksum(fileBytes).ToLower()) { Plugin.Log.Info($"Hash check for {model.Name} passed!"); } else { Plugin.Log.Error($"HASH CHECK FAILED FOR {model.Name}!"); return; } // Actually save the file if (!Directory.Exists(DownloadPath)) { Directory.CreateDirectory(DownloadPath); } string downloadPath = Path.Combine(DownloadPath, modelFileName); if (!File.Exists(downloadPath)) { File.WriteAllBytes(downloadPath, fileBytes); AddToInstalledList(model); } }
public static void DownloadModel(ModelSaber.ModelSaberEntry model) { if (model.Type == "saber") { DownloadModel(model, Path.Combine(UnityGame.InstallPath, "CustomSabers")); } else if (model.Type == "bloq") { DownloadModel(model, Path.Combine(UnityGame.InstallPath, "CustomNotes")); } else if (model.Type == "avatar") { DownloadModel(model, Path.Combine(UnityGame.InstallPath, "CustomAvatars")); } else if (model.Type == "platform") { DownloadModel(model, Path.Combine(UnityGame.InstallPath, "CustomPlatforms")); } }
// Some methods to help with previews public static async Task <AssetBundle> DownloadModelAsPreview(ModelSaber.ModelSaberEntry model) { byte[] fileBytes = await ModelSaber.ModelSaberUtils.GetModelBytes(model); string modelFileName = model.Download.Substring(model.Download.LastIndexOf("/") + 1); Plugin.Log.Info("Checking hash..."); if (model.Hash.ToLower() == MD5Checksum(fileBytes).ToLower()) { Plugin.Log.Info($"Hash check for {model.Name} passed!"); } else { Plugin.Log.Error($"HASH CHECK FAILED FOR {model.Name}!"); return(null); } return(AssetBundle.LoadFromMemory(fileBytes)); }
internal static void ShowPreviewAsset(ModelSaber.ModelSaberEntry asset, int position) { var prv = Downloading.DownloadModelAsPreview(asset); while (!prv.IsCompleted) { Thread.Sleep(10); } switch (asset.Type.ToLower()) { case "saber": previewObjects.Add(ShowSaber(prv.Result, position)); break; case "bloq": previewObjects.Add(ShowNote(prv.Result, position)); break; } }
public static void AddToInstalledList(ModelSaber.ModelSaberEntry model) { string modelFileName = model.Download.Substring(model.Download.LastIndexOf("/") + 1); if (model.Type == "saber") { InstalledSabers.Add(modelFileName); } else if (model.Type == "bloq") { InstalledBloqs.Add(modelFileName); } else if (model.Type == "avatar") { InstalledAvatars.Add(modelFileName); } else if (model.Type == "platform") { InstalledPlatforms.Add(modelFileName); } }