2019-04-22 18:41:43 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-04-30 04:34:41 +12:00
|
|
|
|
using System.IO;
|
2019-04-22 18:41:43 +12:00
|
|
|
|
using System.Linq;
|
2019-04-30 04:34:41 +12:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Web;
|
2019-04-22 18:41:43 +12:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-04-30 04:34:41 +12:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Security.Principal;
|
2019-04-22 18:41:43 +12:00
|
|
|
|
|
|
|
|
|
namespace ModAssistant
|
|
|
|
|
{
|
|
|
|
|
class OneClickInstaller
|
|
|
|
|
{
|
2019-04-30 04:34:41 +12:00
|
|
|
|
private const string ModelSaberURLPrefix = "https://modelsaber.com/files/";
|
2019-04-22 18:41:43 +12:00
|
|
|
|
|
|
|
|
|
private const string CustomAvatarsFolder = "CustomAvatars";
|
|
|
|
|
private const string CustomSabersFolder = "CustomSabers";
|
|
|
|
|
private const string CustomPlatformsFolder = "CustomPlatforms";
|
|
|
|
|
|
2019-04-30 04:34:41 +12:00
|
|
|
|
private static readonly string[] Protocols = new[] { "modelsaber" };
|
|
|
|
|
|
|
|
|
|
private static bool IsElevated => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
2019-04-22 18:41:43 +12:00
|
|
|
|
|
|
|
|
|
public static void InstallAsset(string link)
|
|
|
|
|
{
|
|
|
|
|
Uri uri = new Uri(link);
|
|
|
|
|
if (!Protocols.Contains(uri.Scheme)) return;
|
|
|
|
|
|
2019-04-30 04:34:41 +12:00
|
|
|
|
switch (uri.Scheme)
|
|
|
|
|
{
|
|
|
|
|
case "modelsaber":
|
|
|
|
|
ModelSaber(uri);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-22 18:41:43 +12:00
|
|
|
|
|
2019-04-30 04:34:41 +12:00
|
|
|
|
private static void ModelSaber(Uri uri)
|
|
|
|
|
{
|
|
|
|
|
switch (uri.Host)
|
|
|
|
|
{
|
|
|
|
|
case "avatar":
|
|
|
|
|
DownloadAsset(ModelSaberURLPrefix + uri.Host + uri.AbsolutePath, CustomAvatarsFolder);
|
|
|
|
|
break;
|
|
|
|
|
case "saber":
|
|
|
|
|
DownloadAsset(ModelSaberURLPrefix + uri.Host + uri.AbsolutePath, CustomSabersFolder);
|
|
|
|
|
break;
|
|
|
|
|
case "platform":
|
|
|
|
|
DownloadAsset(ModelSaberURLPrefix + uri.Host + uri.AbsolutePath, CustomPlatformsFolder);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-22 18:41:43 +12:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 04:34:41 +12:00
|
|
|
|
private static void DownloadAsset(string link, string folder)
|
2019-04-22 18:41:43 +12:00
|
|
|
|
{
|
2019-04-30 04:34:41 +12:00
|
|
|
|
string BeatSaberPath = App.BeatSaberInstallDirectory;
|
2019-04-22 18:41:43 +12:00
|
|
|
|
if (string.IsNullOrEmpty(BeatSaberPath))
|
|
|
|
|
{
|
|
|
|
|
Utils.SendNotify("Beat Saber installation path not found.");
|
|
|
|
|
}
|
2019-04-30 04:34:41 +12:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string fileName = WebUtility.UrlDecode(Path.Combine(BeatSaberPath, folder, new Uri(link).Segments.Last()));
|
2019-05-05 03:05:48 +12:00
|
|
|
|
Utils.Download(link, fileName);
|
2019-04-30 04:34:41 +12:00
|
|
|
|
Utils.SendNotify("Installed: " + Path.GetFileNameWithoutExtension(fileName));
|
2019-04-22 18:41:43 +12:00
|
|
|
|
|
2019-04-30 04:34:41 +12:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Utils.SendNotify("Failed to install.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-22 18:41:43 +12:00
|
|
|
|
|
2019-05-05 04:08:54 +12:00
|
|
|
|
public static void Register()
|
|
|
|
|
{
|
|
|
|
|
foreach (string protocol in Protocols)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsRegistered()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-22 18:41:43 +12:00
|
|
|
|
}
|
|
|
|
|
}
|