Made installed detection faster

This commit is contained in:
Assistant 2019-05-12 14:37:29 -04:00
parent 1b2b26865f
commit 646c6b29ae
2 changed files with 28 additions and 16 deletions

View file

@ -30,6 +30,7 @@ namespace ModAssistant.Pages
public List<string> DefaultMods = new List<string>(){ "SongLoader", "ScoreSaber", "BeatSaverDownloader" };
public Mod[] ModsList;
public Mod[] AllModsList;
public static List<Mod> InstalledMods = new List<Mod>();
public List<string> CategoryNames = new List<string>();
public CollectionView view;
@ -81,6 +82,19 @@ namespace ModAssistant.Pages
private void CheckInstalledMods()
{
string json = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Utils.Constants.BeatModsAPIUrl + "mod");
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();
AllModsList = serializer.Deserialize<Mod[]>(reader.ReadToEnd());
}
List<string> empty = new List<string>();
CheckInstallDir("Plugins", empty);
CheckInstallDir(@"IPA\Libs", empty);
@ -110,25 +124,20 @@ namespace ModAssistant.Pages
private Mod GetModFromHash(string hash)
{
string json = string.Empty;
Mod[] modMatches;
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())
using (StreamReader reader = new StreamReader(stream))
foreach (Mod mod in AllModsList)
{
var serializer = new JavaScriptSerializer();
modMatches = serializer.Deserialize<Mod[]>(reader.ReadToEnd());
foreach (Mod.DownloadLink download in mod.downloads)
{
foreach (Mod.FileHashes fileHash in download.hashMd5)
{
if (fileHash.hash == hash)
return mod;
}
}
}
if (modMatches.Length == 0)
return null;
return modMatches[0];
return null;
}
public void PopulateModsList()

View file

@ -1,2 +1,5 @@
# ModAssistant
Simple Beat Saber Mod Installer
Simple Beat Saber Mod Installer similar to the [Beat Saber Mod Manager](https://github.com/beat-saber-modding-group/BeatSaberModInstaller)
![Preview](https://assistant.moe/files/ModAssistant.png)