Browse Source

Added some error checking

Moved some stuff around
pull/11/head
Anairkoen Schno 5 years ago
parent
commit
cfbf40c2a1
5 changed files with 241 additions and 216 deletions
  1. +1
    -0
      BSIPA-ModList/BSIPA-ModList.csproj
  2. +228
    -0
      BSIPA-ModList/UI/ViewControllers/ModCells.cs
  3. +2
    -214
      BSIPA-ModList/UI/ViewControllers/ModListController.cs
  4. +9
    -1
      IPA.Injector/Updates.cs
  5. +1
    -1
      IPA.Loader/Updating/BeatMods/Updater.cs

+ 1
- 0
BSIPA-ModList/BSIPA-ModList.csproj View File

@ -72,6 +72,7 @@
<Compile Include="UI\ButtonUI.cs" />
<Compile Include="UI\ModListFlowCoordinator.cs" />
<Compile Include="UI\ViewControllers\BackButtonNavigationController.cs" />
<Compile Include="UI\ViewControllers\ModCells.cs" />
<Compile Include="UI\ViewControllers\ModInfoViewController.cs" />
<Compile Include="UI\ViewControllers\ModListController.cs" />
</ItemGroup>


+ 228
- 0
BSIPA-ModList/UI/ViewControllers/ModCells.cs View File

@ -0,0 +1,228 @@
using CustomUI.BeatSaber;
using CustomUI.Utilities;
using IPA.Loader;
using IPA.Loader.Features;
using IPA.Old;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace BSIPA_ModList.UI.ViewControllers
{
internal interface IClickableCell
{
void OnSelect(ModListController cntrl);
}
internal class BSIPAModCell : CustomCellInfo, IClickableCell
{
private static Sprite _defaultIcon;
public static Sprite DefaultIcon
{
get
{
if (_defaultIcon == null)
_defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.mod_bsipa.png");
return _defaultIcon;
}
}
internal PluginLoader.PluginInfo Plugin;
private ModListController list;
public BSIPAModCell(ModListController list, PluginLoader.PluginInfo plugin)
: base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
{
Plugin = plugin;
this.list = list;
if (string.IsNullOrWhiteSpace(subtext))
subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
if (plugin.Metadata.Manifest.IconPath != null)
{
try
{
icon = UIUtilities.LoadSpriteRaw(UIUtilities.GetResource(plugin.Metadata.Assembly, plugin.Metadata.Manifest.IconPath));
}
catch (Exception e)
{
Logger.log.Error($"Error loading icon for {plugin.Metadata.Name}");
Logger.log.Error(e);
}
}
if (icon == null)
icon = DefaultIcon;
Logger.log.Debug($"BSIPAModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected BSIPAModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
if (infoView == null)
{
var desc = Plugin.Metadata.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
desc, Plugin.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin.Metadata : null,
Plugin.Metadata.Manifest.Links);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
internal class BSIPAIgnoredModCell : CustomCellInfo, IClickableCell
{
internal PluginLoader.PluginMetadata Plugin;
private ModListController list;
private const string authorFormat = "{0} <color=#BFBFBF>- <i>Not loaded</i>";
private string authorText;
public BSIPAIgnoredModCell(ModListController list, PluginLoader.PluginMetadata plugin)
: base($"<color=#878787>{plugin.Name} <size=60%>v{plugin.Version}", "", BSIPAModCell.DefaultIcon)
{
Plugin = plugin;
this.list = list;
if (string.IsNullOrWhiteSpace(plugin.Manifest.Author))
authorText = "<color=#BFBFBF><i>Unspecified Author</i>";
else
authorText = plugin.Manifest.Author;
subtext = string.Format(authorFormat, authorText);
Logger.log.Debug($"BSIPAIgnoredModCell {plugin.Name} {plugin.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected BSIPAIgnoredModCell {Plugin.Name} {Plugin.Version}");
if (infoView == null)
{
var desc = Plugin.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), authorText,
desc, Plugin.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin : null,
Plugin.Manifest.Links);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
internal class LibraryModCell : CustomCellInfo, IClickableCell
{
private static Sprite _defaultIcon;
public static Sprite DefaultIcon
{
get
{
if (_defaultIcon == null)
_defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.library.png");
return _defaultIcon;
}
}
internal PluginLoader.PluginInfo Plugin;
private ModListController list;
public LibraryModCell(ModListController list, PluginLoader.PluginInfo plugin)
: base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
{
Plugin = plugin;
this.list = list;
if (string.IsNullOrWhiteSpace(subtext))
subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
icon = DefaultIcon;
Logger.log.Debug($"LibraryModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected LibraryModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
if (infoView == null)
{
var desc = Plugin.Metadata.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
desc, Plugin.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin.Metadata : null,
Plugin.Metadata.Manifest.Links);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
#pragma warning disable CS0618
internal class IPAModCell : CustomCellInfo, IClickableCell
{
private static Sprite _defaultIcon;
public static Sprite DefaultIcon
{
get
{
if (_defaultIcon == null)
_defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.mod_ipa.png");
return _defaultIcon;
}
}
internal IPlugin Plugin;
private ModListController list;
public IPAModCell(ModListController list, IPlugin plugin)
: base($"{plugin.Name} <size=60%>{plugin.Version}", "<color=#BFBFBF><i>Legacy</i>", DefaultIcon)
{
Plugin = plugin;
this.list = list;
Logger.log.Debug($"IPAModCell {plugin.Name} {plugin.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected IPAModCell {Plugin.Name} {Plugin.Version}");
if (infoView == null)
{
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), "<color=#BFBFBF><i>Unknown Author</i>",
"<color=#A0A0A0>This mod was written for IPA Reloaded. No metadata is avaliable for this mod. " +
"Please contact the mod author and ask them to port it to BSIPA to provide more information.", null);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
#pragma warning restore
}

+ 2
- 214
BSIPA-ModList/UI/ViewControllers/ModListController.cs View File

@ -10,224 +10,12 @@ using UnityEngine;
using VRUI;
using IPA.Loader.Features;
using TMPro;
using BSIPA_ModList.UI.ViewControllers;
namespace BSIPA_ModList.UI
{
internal class ModListController : CustomListViewController
{
private interface IClickableCell
{
void OnSelect(ModListController cntrl);
}
private class BSIPAModCell : CustomCellInfo, IClickableCell
{
private static Sprite _defaultIcon;
public static Sprite DefaultIcon
{
get
{
if (_defaultIcon == null)
_defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.mod_bsipa.png");
return _defaultIcon;
}
}
internal PluginLoader.PluginInfo Plugin;
private ModListController list;
public BSIPAModCell(ModListController list, PluginLoader.PluginInfo plugin)
: base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
{
Plugin = plugin;
this.list = list;
if (string.IsNullOrWhiteSpace(subtext))
subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
if (plugin.Metadata.Manifest.IconPath != null)
{
try
{
icon = UIUtilities.LoadSpriteRaw(UIUtilities.GetResource(plugin.Metadata.Assembly, plugin.Metadata.Manifest.IconPath));
}
catch (Exception e)
{
Logger.log.Error($"Error loading icon for {plugin.Metadata.Name}");
Logger.log.Error(e);
}
}
if (icon == null)
icon = DefaultIcon;
Logger.log.Debug($"BSIPAModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected BSIPAModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
if (infoView == null)
{
var desc = Plugin.Metadata.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
desc, Plugin.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin.Metadata : null,
Plugin.Metadata.Manifest.Links);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
private class BSIPAIgnoredModCell : CustomCellInfo, IClickableCell
{
internal PluginLoader.PluginMetadata Plugin;
private ModListController list;
private const string authorFormat = "{0} <color=#BFBFBF>- <i>Not loaded</i>";
private string authorText;
public BSIPAIgnoredModCell(ModListController list, PluginLoader.PluginMetadata plugin)
: base($"<color=#878787>{plugin.Name} <size=60%>v{plugin.Version}", "", BSIPAModCell.DefaultIcon)
{
Plugin = plugin;
this.list = list;
if (string.IsNullOrWhiteSpace(plugin.Manifest.Author))
authorText = "<color=#BFBFBF><i>Unspecified Author</i>";
else
authorText = plugin.Manifest.Author;
subtext = string.Format(authorFormat, authorText);
Logger.log.Debug($"BSIPAIgnoredModCell {plugin.Name} {plugin.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected BSIPAIgnoredModCell {Plugin.Name} {Plugin.Version}");
if (infoView == null)
{
var desc = Plugin.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), authorText,
desc, Plugin.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin : null,
Plugin.Manifest.Links);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
private class LibraryModCell : CustomCellInfo, IClickableCell
{
private static Sprite _defaultIcon;
public static Sprite DefaultIcon
{
get
{
if (_defaultIcon == null)
_defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.library.png");
return _defaultIcon;
}
}
internal PluginLoader.PluginInfo Plugin;
private ModListController list;
public LibraryModCell(ModListController list, PluginLoader.PluginInfo plugin)
: base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
{
Plugin = plugin;
this.list = list;
if (string.IsNullOrWhiteSpace(subtext))
subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
icon = DefaultIcon;
Logger.log.Debug($"LibraryModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected LibraryModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
if (infoView == null)
{
var desc = Plugin.Metadata.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,
desc, Plugin.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) != null ? Plugin.Metadata : null,
Plugin.Metadata.Manifest.Links);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
#pragma warning disable CS0618
private class IPAModCell : CustomCellInfo, IClickableCell
{
private static Sprite _defaultIcon;
public static Sprite DefaultIcon
{
get
{
if (_defaultIcon == null)
_defaultIcon = UIUtilities.LoadSpriteFromResources("BSIPA_ModList.Icons.mod_ipa.png");
return _defaultIcon;
}
}
internal IPlugin Plugin;
private ModListController list;
public IPAModCell(ModListController list, IPlugin plugin)
: base($"{plugin.Name} <size=60%>{plugin.Version}", "<color=#BFBFBF><i>Legacy</i>", DefaultIcon)
{
Plugin = plugin;
this.list = list;
Logger.log.Debug($"IPAModCell {plugin.Name} {plugin.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected IPAModCell {Plugin.Name} {Plugin.Version}");
if (infoView == null)
{
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), "<color=#BFBFBF><i>Unknown Author</i>",
"<color=#A0A0A0>This mod was written for IPA Reloaded. No metadata is avaliable for this mod. " +
"Please contact the mod author and ask them to port it to BSIPA to provide more information.", null);
}
list.flow.SetSelected(infoView, immediate: list.flow.HasSelected);
}
}
#pragma warning restore
public override TableCell CellForIdx(int idx)
{
var cell = base.CellForIdx(idx) as LevelListTableCell;
@ -236,7 +24,7 @@ namespace BSIPA_ModList.UI
return cell;
}
private ModListFlowCoordinator flow;
internal ModListFlowCoordinator flow;
#pragma warning disable CS0618
public void Init(ModListFlowCoordinator flow, IEnumerable<PluginLoader.PluginInfo> bsipaPlugins, IEnumerable<PluginLoader.PluginMetadata> ignoredPlugins, IEnumerable<IPlugin> ipaPlugins)


+ 9
- 1
IPA.Injector/Updates.cs View File

@ -110,7 +110,15 @@ namespace IPA.Injector
updater.Error(e);
}
Directory.Delete(pendingDir, true);
try
{
Directory.Delete(pendingDir, true);
}
catch (Exception e)
{
updater.Error("Something went wrong performing an operation that should never fail!");
updater.Error(e);
}
}
}
}

+ 1
- 1
IPA.Loader/Updating/BeatMods/Updater.cs View File

@ -431,7 +431,7 @@ namespace IPA.Updating.BeatMods
using (var request = UnityWebRequest.Get(url))
using (var taskTokenSource = new CancellationTokenSource())
{
var dlh = new StreamDownloadHandler(stream, (int i1, int i2, double d) => progress(item, i1, i2, d));
var dlh = new StreamDownloadHandler(stream, (int i1, int i2, double d) => progress?.Invoke(item, i1, i2, d));
request.downloadHandler = dlh;
downloadStart?.Invoke(item);


Loading…
Cancel
Save