Skip to content

Commit

Permalink
Merge pull request #23 from DubyaDude/master
Browse files Browse the repository at this point in the history
Move to api/v1 + additional QOL changes
  • Loading branch information
knah authored Jun 16, 2022
2 parents 992480f + b74c421 commit f905428
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 42 deletions.
24 changes: 15 additions & 9 deletions VRCMelonAssistant/Classes/InstallHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal static async Task<Stream> DownloadFileToMemory(string link)

public static async Task InstallMod(Mod mod)
{
string downloadLink = mod.versions[0].downloadlink;
string downloadLink = mod.versions[0].downloadLink;

if (string.IsNullOrEmpty(downloadLink))
{
Expand All @@ -90,22 +90,28 @@ public static async Task InstallMod(Mod mod)

if (mod.installedFilePath != null)
File.Delete(mod.installedFilePath);


var modUri = new Uri(downloadLink);
var targetFilePath = Path.Combine(App.VRChatInstallDirectory, mod.versions[0].IsPlugin ? "Plugins" : "Mods",
mod.versions[0].IsBroken ? "Broken" : "", modUri.Segments.Last());
string targetFilePath = "";

Directory.CreateDirectory(Path.GetDirectoryName(targetFilePath));

using (Stream stream = await DownloadFileToMemory(downloadLink))
using (var resp = await Http.HttpClient.GetAsync(downloadLink))
{
var stream = new MemoryStream();
await resp.Content.CopyToAsync(stream);
stream.Position = 0;

targetFilePath = Path.Combine(App.VRChatInstallDirectory, mod.versions[0].IsPlugin ? "Plugins" : "Mods",
mod.versions[0].IsBroken ? "Broken" : (mod.versions[0].IsRetired ? "Retired" : ""), resp.RequestMessage.RequestUri.Segments.Last());

Directory.CreateDirectory(Path.GetDirectoryName(targetFilePath));

using var targetFile = File.OpenWrite(targetFilePath);
await stream.CopyToAsync(targetFile);
}

mod.ListItem.IsInstalled = true;
mod.installedFilePath = targetFilePath;
mod.ListItem.InstalledVersion = mod.versions[0].modversion;
mod.ListItem.InstalledVersion = mod.versions[0].modVersion;
mod.ListItem.InstalledModInfo = mod;
}
}
Expand Down
20 changes: 11 additions & 9 deletions VRCMelonAssistant/Classes/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,35 @@ namespace VRCMelonAssistant
public class Mod
{
public int _id;
public string uploaddate;
public string uploadDate;
public string category;
public string[] aliases;
public ModVersion[] versions;
public Mods.ModListItem ListItem;
public string installedFilePath;
public string installedVersion;
public bool installedInBrokenDir;
public bool installedInRetiredDir;

public class ModVersion
{
public int _version;
public string name;
public string modversion;
public string modtype;
public string modVersion;
public string modType;
public string author;
public string description;
public string downloadlink;
public string sourcelink;
public string downloadLink;
public string sourceLink;
public string hash;
public string updatedate;
public string vrchatversion;
public string loaderversion;
public string updateDate;
public string vrchatVersion;
public string loaderVersion;
public int approvalStatus;

public bool IsBroken => approvalStatus == 2;
public bool IsPlugin => modtype.Equals("plugin", StringComparison.InvariantCultureIgnoreCase);
public bool IsRetired => approvalStatus == 3;
public bool IsPlugin => modType.Equals("plugin", StringComparison.InvariantCultureIgnoreCase);
}
}
}
2 changes: 1 addition & 1 deletion VRCMelonAssistant/Classes/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Utils
public class Constants
{
public const string VRChatAppId = "438100";
public const string VRCMGModsJson = "https://api.vrcmg.com/v0/mods.json";
public const string VRCMGModsJson = "https://api.vrcmg.com/v1/mods";
public const string WeebCDNAPIURL = "https://pat.assistant.moe/api/v1.0/";
public const string MD5Spacer = " ";
public static readonly char[] IllegalCharacters = new char[]
Expand Down
2 changes: 1 addition & 1 deletion VRCMelonAssistant/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal void MarkModsPageForRefresh()
InstallButton.IsEnabled = false;
}

private async Task ShowModsPage()
public async Task ShowModsPage()
{
void OpenModsPage()
{
Expand Down
6 changes: 3 additions & 3 deletions VRCMelonAssistant/ModInfoWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public void SetMod(Mod mod)
ModDescription.Text = mod.versions[0].description ?? (string) FindResource("ModInfoWindow:NoDescription");
ModName.Text = mod.versions[0].name;
ModAuthor.Text = string.Format((string) FindResource("ModInfoWindow:Author"), mod.versions[0].author ?? FindResource("ModInfoWindow:NoAuthor"));
ModVersion.Text = mod.versions[0].modversion;
ModVersion.Text = mod.versions[0].modVersion;

var dlLink = mod.versions[0].downloadlink;
var dlLink = mod.versions[0].downloadLink;
DownloadLink.Text = (string) FindResource("ModInfoWindow:DownloadLink");
DownloadLink.Inlines.Add(new Run(" "));
if (dlLink?.StartsWith("http") == true)
DownloadLink.Inlines.Add(CreateHyperlink(dlLink));
else
DownloadLink.Inlines.Add(new Run(dlLink));

var srcLink = mod.versions[0].sourcelink;
var srcLink = mod.versions[0].sourceLink;
SourceCodeLink.Text = (string) FindResource("ModInfoWindow:SourceCodeLink");
SourceCodeLink.Inlines.Add(new Run(" "));
if (srcLink?.StartsWith("http") == true)
Expand Down
3 changes: 2 additions & 1 deletion VRCMelonAssistant/Pages/Intro.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ private void Agree_Click(object sender, RoutedEventArgs e)
MainWindow.Instance.ModsButton.IsEnabled = true;

string text = (string) FindResource("Intro:ModsTabEnabled");
Utils.SendNotify(text);
MainWindow.Instance.MainText = text;
Properties.Settings.Default.Agreed = true;
Properties.Settings.Default.Save();

MainWindow.Instance.ShowModsPage().NoAwait();
}
}
}
4 changes: 2 additions & 2 deletions VRCMelonAssistant/Pages/Mods.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<TextBlock
Name="SearchText"
Grid.Row="0"
Height="0"
Height="20"
Padding="5,0,0,0"
Panel.ZIndex="1"
Background="{DynamicResource BottomStatusBarBackground}"
Expand All @@ -37,7 +37,7 @@
<TextBox
Name="SearchBar"
Grid.Row="0"
Height="0"
Height="20"
Margin="0,-1,0,0"
Padding="3,1,0,0"
Panel.ZIndex="2"
Expand Down
39 changes: 25 additions & 14 deletions VRCMelonAssistant/Pages/Mods.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed partial class Mods : Page
public static Mods Instance = new Mods();

private static readonly ModListItem.CategoryInfo BrokenCategory = new("Broken", "These mods were broken by a game update. They will be temporarily removed and restored once they are updated for the current game version");
private static readonly ModListItem.CategoryInfo RetiredCategory = new("Retired", "These mods are either no longer needed due to VRChat updates or are no longer being maintained");
private static readonly ModListItem.CategoryInfo UncategorizedCategory = new("Uncategorized", "Mods without a category assigned");
private static readonly ModListItem.CategoryInfo UnknownCategory = new("Unknown/Unverified", "Mods not coming from VRCMG. Potentially dangerous.");

Expand Down Expand Up @@ -138,10 +139,12 @@ public async Task CheckInstalledMods()

await Task.Run(() =>
{
CheckInstallDir("Plugins", false);
CheckInstallDir("Mods", false);
CheckInstallDir("Plugins/Broken", true);
CheckInstallDir("Mods/Broken", true);
CheckInstallDir("Plugins");
CheckInstallDir("Mods");
CheckInstallDir("Plugins/Broken", isBrokenDir: true);
CheckInstallDir("Mods/Broken", isBrokenDir: true);
CheckInstallDir("Plugins/Retired", isRetiredDir: true);
CheckInstallDir("Mods/Retired", isRetiredDir: true);
});
}

Expand All @@ -168,7 +171,7 @@ public async Task GetAllMods()
}
}

private void CheckInstallDir(string directory, bool isBrokenDir)
private void CheckInstallDir(string directory, bool isBrokenDir = false, bool isRetiredDir = false)
{
if (!Directory.Exists(Path.Combine(App.VRChatInstallDirectory, directory)))
{
Expand All @@ -193,6 +196,7 @@ private void CheckInstallDir(string directory, bool isBrokenDir)
mod.installedFilePath = file;
mod.installedVersion = modInfo.ModVersion;
mod.installedInBrokenDir = isBrokenDir;
mod.installedInRetiredDir = isRetiredDir;
break;
}

Expand All @@ -203,12 +207,13 @@ private void CheckInstallDir(string directory, bool isBrokenDir)
installedFilePath = file,
installedVersion = modInfo.ModVersion,
installedInBrokenDir = isBrokenDir,
installedInRetiredDir = isRetiredDir,
versions = new []
{
new Mod.ModVersion()
{
name = modInfo.ModName,
modversion = modInfo.ModVersion,
modVersion = modInfo.ModVersion,
author = modInfo.ModAuthor,
description = ""
}
Expand Down Expand Up @@ -255,11 +260,17 @@ private void CheckInstallDir(string directory, bool isBrokenDir)

public async Task PopulateModsList()
{
foreach (Mod mod in AllModsList)
foreach (Mod mod in AllModsList.Where(x => !x.versions[0].IsBroken && !x.versions[0].IsRetired))
AddModToList(mod);

foreach (var mod in UnknownMods)
AddModToList(mod, UnknownCategory);

foreach (Mod mod in AllModsList.Where(x => x.versions[0].IsBroken))
AddModToList(mod);

foreach (Mod mod in AllModsList.Where(x => x.versions[0].IsRetired))
AddModToList(mod);
}

private void AddModToList(Mod mod, ModListItem.CategoryInfo categoryOverride = null)
Expand All @@ -285,14 +296,14 @@ ModListItem.CategoryInfo GetCategory(Mod mod)
IsSelected = preSelected,
IsEnabled = true,
ModName = latestVersion.name,
ModVersion = latestVersion.modversion,
ModVersion = latestVersion.modVersion,
ModAuthor = HardcodedCategories.FixupAuthor(latestVersion.author),
ModDescription = latestVersion.description.Replace("\r\n", " ").Replace("\n", " "),
ModInfo = mod,
IsInstalled = mod.installedFilePath != null,
InstalledVersion = mod.installedVersion,
InstalledModInfo = mod,
Category = categoryOverride ?? (latestVersion.IsBroken ? BrokenCategory : GetCategory(mod))
Category = categoryOverride ?? (latestVersion.IsBroken ? BrokenCategory : (latestVersion.IsRetired ? RetiredCategory : GetCategory(mod)))
};

foreach (Promotion promo in Promotions.ActivePromotions)
Expand All @@ -319,7 +330,7 @@ public async void InstallMods()
foreach (Mod mod in AllModsList)
{
// Ignore mods that are newer than installed version or up-to-date
if (mod.ListItem.GetVersionComparison >= 0 && mod.installedInBrokenDir == mod.versions[0].IsBroken) continue;
if (mod.ListItem.GetVersionComparison >= 0 && mod.installedInBrokenDir == mod.versions[0].IsBroken && mod.installedInRetiredDir == mod.versions[0].IsRetired) continue;

if (mod.ListItem.IsSelected)
{
Expand Down Expand Up @@ -506,14 +517,14 @@ private void SearchButton_Click(object sender, RoutedEventArgs e)
if (SearchBar.Height == 0)
{
SearchBar.Focus();
Animate(SearchBar, 0, 16, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchText, 0, 16, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchBar, 0, 20, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchText, 0, 20, new TimeSpan(0, 0, 0, 0, 300));
ModsListView.Items.Filter = new Predicate<object>(SearchFilter);
}
else
{
Animate(SearchBar, 16, 0, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchText, 16, 0, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchBar, 20, 0, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchText, 20, 0, new TimeSpan(0, 0, 0, 0, 300));
ModsListView.Items.Filter = null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions VRCMelonAssistant/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 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.1.23.1029")]
[assembly: AssemblyFileVersion("1.1.23.1029+vrc")]
[assembly: AssemblyVersion("1.1.26.1029")]
[assembly: AssemblyFileVersion("1.1.26.1029+vrc")]

0 comments on commit f905428

Please sign in to comment.