mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-05-21 21:03:44 +12:00
Started on argument handling
This commit is contained in:
parent
95494d576d
commit
f2ad770858
|
@ -28,6 +28,8 @@ namespace ModAssistant
|
|||
SaveModSelection = ModAssistant.Properties.Settings.Default.SaveSelected;
|
||||
CheckInstalledMods = ModAssistant.Properties.Settings.Default.CheckInstalled;
|
||||
|
||||
Update.Run();
|
||||
|
||||
if (e.Args.Length == 0)
|
||||
{
|
||||
MainWindow window = new MainWindow();
|
||||
|
@ -41,7 +43,25 @@ namespace ModAssistant
|
|||
|
||||
private void ArgumentHandler(string[] Args)
|
||||
{
|
||||
Utils.SendNotify(Args[0]);
|
||||
Utils.SendNotify(Args.Count().ToString());
|
||||
switch (Args[0])
|
||||
{
|
||||
case "--install":
|
||||
if (!String.IsNullOrEmpty(Args[1]))
|
||||
OneClickInstaller.InstallAsset(Args[1]);
|
||||
else
|
||||
Utils.SendNotify("Invalid argument! '--install' requires an option.");
|
||||
break;
|
||||
|
||||
case "--update":
|
||||
// Update
|
||||
break;
|
||||
|
||||
default:
|
||||
Utils.SendNotify("Unrecognized argument. Closing Mod Assistant.");
|
||||
break;
|
||||
}
|
||||
Current.Shutdown();
|
||||
}
|
||||
|
||||
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
||||
|
|
|
@ -1,41 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace ModAssistant
|
||||
{
|
||||
class OneClickInstaller
|
||||
{
|
||||
private const string ModelSaberURLPrefix = "https://modelsaber.com/files";
|
||||
private const string ModelSaberURLPrefix = "https://modelsaber.com/files/";
|
||||
|
||||
private const string CustomAvatarsFolder = "CustomAvatars";
|
||||
private const string CustomSabersFolder = "CustomSabers";
|
||||
private const string CustomPlatformsFolder = "CustomPlatforms";
|
||||
|
||||
private static readonly string[] Protocols = new[] { "modsaber" };
|
||||
private static readonly string[] Protocols = new[] { "modelsaber" };
|
||||
|
||||
private static bool IsElevated => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
|
||||
public static void InstallAsset(string link)
|
||||
{
|
||||
Uri uri = new Uri(link);
|
||||
if (!Protocols.Contains(uri.Scheme)) return;
|
||||
|
||||
|
||||
|
||||
switch (uri.Scheme)
|
||||
{
|
||||
case "modelsaber":
|
||||
ModelSaber(uri);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool DownloadAsset(string link, string folder)
|
||||
private static void ModelSaber(Uri uri)
|
||||
{
|
||||
string BeatSaberPath = "";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static void DownloadAsset(string link, string folder)
|
||||
{
|
||||
string BeatSaberPath = App.BeatSaberInstallDirectory;
|
||||
if (string.IsNullOrEmpty(BeatSaberPath))
|
||||
{
|
||||
Utils.SendNotify("Beat Saber installation path not found.");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
string fileName = WebUtility.UrlDecode(Path.Combine(BeatSaberPath, folder, new Uri(link).Segments.Last()));
|
||||
byte[] file = new WebClient().DownloadData(link);
|
||||
File.WriteAllBytes(fileName, file);
|
||||
Utils.SendNotify("Installed: " + Path.GetFileNameWithoutExtension(fileName));
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
Utils.SendNotify("Failed to install.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
26
ModAssistant/Classes/Update.cs
Normal file
26
ModAssistant/Classes/Update.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace ModAssistant
|
||||
{
|
||||
class Update
|
||||
{
|
||||
private static string ExePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
|
||||
|
||||
public static bool NeedsUpdate()
|
||||
{
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
//MessageBox.Show(Update.ExePath);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,6 +54,12 @@
|
|||
</Button>
|
||||
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="1" VerticalAlignment="Center">
|
||||
<TextBlock Text="Version" HorizontalAlignment="Center"/>
|
||||
<TextBlock Name="VersionText" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
|
||||
<Frame Grid.Column="1" Name="Main" NavigationUIVisibility="Hidden" />
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="1" >
|
||||
|
|
|
@ -17,6 +17,7 @@ using System.IO;
|
|||
using System.Web.Script.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
using ModAssistant.Pages;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ModAssistant
|
||||
{
|
||||
|
@ -26,8 +27,6 @@ namespace ModAssistant
|
|||
public partial class MainWindow : Window
|
||||
{
|
||||
public static MainWindow Instance;
|
||||
//private delegate void SetStatusCallback(string message);
|
||||
//public static Mods ModWindow = new Mods();
|
||||
|
||||
public string MainText
|
||||
{
|
||||
|
@ -46,12 +45,13 @@ namespace ModAssistant
|
|||
InitializeComponent();
|
||||
Instance = this;
|
||||
|
||||
VersionText.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
|
||||
if (Properties.Settings.Default.Agreed)
|
||||
{
|
||||
MainWindow.Instance.ModsButton.IsEnabled = true;
|
||||
}
|
||||
|
||||
//Main.Content = Mods.Instance;
|
||||
Main.Content = Intro.Instance;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Classes\Diagnostics.cs" />
|
||||
<Compile Include="Classes\Update.cs" />
|
||||
<Compile Include="Pages\Intro.xaml.cs">
|
||||
<DependentUpon>Intro.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
|
@ -51,5 +51,5 @@ using System.Windows;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("0.0.0.1")]
|
||||
[assembly: AssemblyFileVersion("0.0.0.1")]
|
||||
|
|
Loading…
Reference in a new issue