mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-05-21 21:03:44 +12:00
Added update logic. Fixed Oculus detect bug thanks to Megalon.
This commit is contained in:
parent
0f374b32ab
commit
4e803c5585
|
@ -26,16 +26,17 @@ namespace ModAssistant
|
|||
|
||||
private void Application_Startup(object sender, StartupEventArgs e)
|
||||
{
|
||||
Version = Version.Substring(0, Version.Length - 2);
|
||||
BeatSaberInstallDirectory = Utils.GetInstallDir();
|
||||
BeatSaberInstallType = ModAssistant.Properties.Settings.Default.StoreType;
|
||||
SaveModSelection = ModAssistant.Properties.Settings.Default.SaveSelected;
|
||||
CheckInstalledMods = ModAssistant.Properties.Settings.Default.CheckInstalled;
|
||||
SelectInstalledMods = ModAssistant.Properties.Settings.Default.SelectInstalled;
|
||||
|
||||
Updater.Run();
|
||||
|
||||
if (e.Args.Length == 0)
|
||||
{
|
||||
Updater.Run();
|
||||
|
||||
MainWindow window = new MainWindow();
|
||||
window.Show();
|
||||
}
|
||||
|
@ -47,7 +48,6 @@ namespace ModAssistant
|
|||
|
||||
private void ArgumentHandler(string[] Args)
|
||||
{
|
||||
Utils.SendNotify(Args.Count().ToString());
|
||||
switch (Args[0])
|
||||
{
|
||||
case "--install":
|
||||
|
@ -58,7 +58,10 @@ namespace ModAssistant
|
|||
break;
|
||||
|
||||
case "--update":
|
||||
// Update
|
||||
Updater.Run();
|
||||
|
||||
MainWindow window = new MainWindow();
|
||||
window.Show();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -62,8 +62,7 @@ namespace ModAssistant
|
|||
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.Download(link, fileName);
|
||||
Utils.SendNotify("Installed: " + Path.GetFileNameWithoutExtension(fileName));
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Principal;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Windows;
|
||||
|
||||
namespace ModAssistant
|
||||
|
@ -10,19 +15,117 @@ namespace ModAssistant
|
|||
class Updater
|
||||
{
|
||||
private static string APILatestURL = "https://api.github.com/repos/Assistant/ModAssistant/releases/latest";
|
||||
|
||||
private static string ExePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
|
||||
private static Update LatestUpdate;
|
||||
private static Version CurrentVersion;
|
||||
private static Version LatestVersion;
|
||||
private static bool NeedsUpdate = false;
|
||||
private static bool IsAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
|
||||
public static bool CheckForUpdate()
|
||||
{
|
||||
return false;
|
||||
string json = string.Empty;
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(APILatestURL);
|
||||
request.AutomaticDecompression = DecompressionMethods.GZip;
|
||||
request.UserAgent = "ModAssistant/" + App.Version;
|
||||
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
using (Stream stream = response.GetResponseStream())
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
var serializer = new JavaScriptSerializer();
|
||||
LatestUpdate = serializer.Deserialize<Update>(reader.ReadToEnd());
|
||||
}
|
||||
|
||||
LatestVersion = new Version(LatestUpdate.tag_name.Substring(1));
|
||||
CurrentVersion = new Version(App.Version);
|
||||
|
||||
|
||||
return (LatestVersion > CurrentVersion);
|
||||
}
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
NeedsUpdate = CheckForUpdate();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Utils.SendNotify("Couldn't check for updates.");
|
||||
}
|
||||
|
||||
if (NeedsUpdate) RunUpdate();
|
||||
}
|
||||
|
||||
public static void RunUpdate()
|
||||
{
|
||||
if (IsAdmin)
|
||||
{
|
||||
StartUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
RestartAsAdmin();
|
||||
}
|
||||
}
|
||||
|
||||
private static void RestartAsAdmin()
|
||||
{
|
||||
Process process = new Process();
|
||||
process.StartInfo.FileName = ExePath;
|
||||
process.StartInfo.Arguments = "--update";
|
||||
process.StartInfo.UseShellExecute = true;
|
||||
process.StartInfo.Verb = "runas";
|
||||
try
|
||||
{
|
||||
process.Start();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Mod Assistant Updater needs to run as Admin. Please try again.");
|
||||
}
|
||||
App.Current.Shutdown();
|
||||
}
|
||||
|
||||
public static void StartUpdate()
|
||||
{
|
||||
string Directory = Path.GetDirectoryName(ExePath);
|
||||
string OldExe = Path.Combine(Directory, "ModAssistant.old.exe");
|
||||
|
||||
string DownloadLink = null;
|
||||
|
||||
foreach (Update.Asset asset in LatestUpdate.assets)
|
||||
{
|
||||
if (asset.name == "ModAssistant.exe")
|
||||
{
|
||||
DownloadLink = asset.browser_download_url;
|
||||
}
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(DownloadLink))
|
||||
{
|
||||
Utils.SendNotify("Couldn't download update.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (File.Exists(OldExe))
|
||||
File.Delete(OldExe);
|
||||
|
||||
File.Move(ExePath, OldExe);
|
||||
|
||||
Utils.Download(DownloadLink, ExePath);
|
||||
Process.Start(ExePath);
|
||||
App.Current.Shutdown();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Update
|
||||
public class Update
|
||||
{
|
||||
public string url;
|
||||
public string assets_url;
|
||||
|
@ -38,48 +141,48 @@ namespace ModAssistant
|
|||
public bool prerelease;
|
||||
public string created_at;
|
||||
public string published_at;
|
||||
public Assets[] assets;
|
||||
public Asset[] assets;
|
||||
public string tarball_url;
|
||||
public string zipball_url;
|
||||
public string body;
|
||||
}
|
||||
|
||||
class Assets
|
||||
{
|
||||
public string url;
|
||||
public int id;
|
||||
public string node_id;
|
||||
public string name;
|
||||
public string label;
|
||||
public User uploader;
|
||||
public string content_type;
|
||||
public string state;
|
||||
public int size;
|
||||
public string created_at;
|
||||
public string updated_at;
|
||||
public string browser_download_url;
|
||||
}
|
||||
public class Asset
|
||||
{
|
||||
public string url;
|
||||
public int id;
|
||||
public string node_id;
|
||||
public string name;
|
||||
public string label;
|
||||
public User uploader;
|
||||
public string content_type;
|
||||
public string state;
|
||||
public int size;
|
||||
public string created_at;
|
||||
public string updated_at;
|
||||
public string browser_download_url;
|
||||
}
|
||||
|
||||
class User
|
||||
{
|
||||
public string login;
|
||||
public int id;
|
||||
public string node_id;
|
||||
public string avatar_url;
|
||||
public string gravatar_id;
|
||||
public string url;
|
||||
public string html_url;
|
||||
public string followers_url;
|
||||
public string following_url;
|
||||
public string gists_url;
|
||||
public string starred_url;
|
||||
public string subscriptions_url;
|
||||
public string organizations_url;
|
||||
public string repos_url;
|
||||
public string events_url;
|
||||
public string received_events_url;
|
||||
public string type;
|
||||
public bool site_admin;
|
||||
public class User
|
||||
{
|
||||
public string login;
|
||||
public int id;
|
||||
public string node_id;
|
||||
public string avatar_url;
|
||||
public string gravatar_id;
|
||||
public string url;
|
||||
public string html_url;
|
||||
public string followers_url;
|
||||
public string following_url;
|
||||
public string gists_url;
|
||||
public string starred_url;
|
||||
public string subscriptions_url;
|
||||
public string organizations_url;
|
||||
public string repos_url;
|
||||
public string events_url;
|
||||
public string received_events_url;
|
||||
public string type;
|
||||
public bool site_admin;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
|||
using System.Windows;
|
||||
using System.Management;
|
||||
using ModAssistant.Properties;
|
||||
using System.Net;
|
||||
|
||||
namespace ModAssistant
|
||||
{
|
||||
|
@ -187,11 +188,15 @@ namespace ModAssistant
|
|||
using (RegistryKey libraryKey = librariesKey.OpenSubKey(libraryKeyName))
|
||||
{
|
||||
string libraryPath = (string)libraryKey.GetValue("Path");
|
||||
string finalPath = Path.Combine(guidLetterVolumes.First(x => libraryPath.Contains(x.Key)).Value, libraryPath.Substring(49), @"Software\hyperbolic-magnetism-beat-saber");
|
||||
|
||||
if (File.Exists(Path.Combine(finalPath, "Beat Saber.exe")))
|
||||
// Yoinked this code from Megalon's fix. <3
|
||||
string GUIDLetter = guidLetterVolumes.FirstOrDefault(x => libraryPath.Contains(x.Key)).Value;
|
||||
if (!String.IsNullOrEmpty(GUIDLetter))
|
||||
{
|
||||
return SetDir(finalPath, "Oculus");
|
||||
string finalPath = Path.Combine(GUIDLetter, libraryPath.Substring(49), @"Software\hyperbolic-magnetism-beat-saber");
|
||||
if (File.Exists(Path.Combine(finalPath, "Beat Saber.exe")))
|
||||
{
|
||||
return SetDir(finalPath, "Oculus");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,5 +257,14 @@ namespace ModAssistant
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static void Download(string link, string output)
|
||||
{
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Headers.Add("user-agent", "ModAssistant/" + App.Version);
|
||||
|
||||
byte[] file = webClient.DownloadData(link);
|
||||
File.WriteAllBytes(output, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,6 +115,7 @@ namespace ModAssistant.Pages
|
|||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Utils.Constants.BeatModsAPIUrl + "mod?hash=" + hash);
|
||||
request.AutomaticDecompression = DecompressionMethods.GZip;
|
||||
request.UserAgent = "ModAssistant/" + App.Version;
|
||||
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
using (Stream stream = response.GetResponseStream())
|
||||
|
@ -135,6 +136,7 @@ namespace ModAssistant.Pages
|
|||
string json = string.Empty;
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Utils.Constants.BeatModsAPIUrl + Utils.Constants.BeatModsModsOptions);
|
||||
request.AutomaticDecompression = DecompressionMethods.GZip;
|
||||
request.UserAgent = "ModAssistant/" + App.Version;
|
||||
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
||||
using (Stream stream = response.GetResponseStream())
|
||||
|
|
|
@ -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("0.0.0.1")]
|
||||
[assembly: AssemblyFileVersion("0.0.0.1")]
|
||||
[assembly: AssemblyVersion("0.0.1.0")]
|
||||
[assembly: AssemblyFileVersion("0.0.1.0")]
|
||||
|
|
Loading…
Reference in a new issue