Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions ModAssistant/Pages/Mods.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public sealed partial class Mods : Page

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;
Expand Down Expand Up @@ -81,6 +82,19 @@ private async void LoadMods()

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);
Expand Down Expand Up @@ -110,25 +124,20 @@ private void CheckInstallDir(string directory, List<string> blacklist)

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()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# ModAssistant
Simple Beat Saber Mod Installer
Simple Beat Saber Mod Installer