Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 50b17d2

Browse files
authored
Merge pull request #78 from lolPants/version-select
Version Selector
2 parents 7b5c104 + b1eeb10 commit 50b17d2

File tree

5 files changed

+96
-18
lines changed

5 files changed

+96
-18
lines changed

BeatSaberModManager/BeatSaberModManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="Core\PathLogic.cs" />
6565
<Compile Include="Core\RemoteLogic.cs" />
6666
<Compile Include="Core\UpdateLogic.cs" />
67+
<Compile Include="DataModels\GameVersion.cs" />
6768
<Compile Include="DataModels\ModLink.cs" />
6869
<Compile Include="DataModels\Platform.cs" />
6970
<Compile Include="DataModels\ReleaseInfo.cs" />

BeatSaberModManager/Core/RemoteLogic.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,44 @@ public class RemoteLogic
1818
private const string ApiVersion = "1.0";
1919
private readonly string ApiURL = $"{ModSaberURL}/api/v{ApiVersion}";
2020

21-
private string currentGameVersion = string.Empty;
21+
public GameVersion[] gameVersions;
22+
public GameVersion selectedGameVersion;
23+
2224
public List<ReleaseInfo> releases;
25+
2326
public RemoteLogic()
2427
{
2528
releases = new List<ReleaseInfo>();
2629
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
2730
}
2831

29-
public void GetCurrentGameVersion()
32+
public void GetGameVersions()
3033
{
3134
string raw = Fetch($"{ApiURL}/site/gameversions");
32-
var decoded = JSON.Parse(raw);
33-
var current = decoded[0];
34-
var value = current["value"];
35-
currentGameVersion = value;
35+
var gameVersionsRaw = JSON.Parse(raw);
36+
37+
List<GameVersion> gvList = new List<GameVersion>();
38+
for (int i = 0; i < gameVersionsRaw.Count; i++)
39+
{
40+
var current = gameVersionsRaw[i];
41+
42+
GameVersion gv = new GameVersion(
43+
current["id"],
44+
current["value"],
45+
current["manifest"]
46+
);
47+
48+
gvList.Add(gv);
49+
}
50+
51+
gameVersions = gvList.ToArray();
52+
selectedGameVersion = gameVersions[0];
3653
}
3754

3855
public void PopulateReleases()
3956
{
57+
releases.Clear();
58+
4059
string raw = GetModSaberReleases();
4160
if (raw != null)
4261
{
@@ -126,7 +145,7 @@ private string GetModSaberReleases()
126145

127146
private void CreateRelease(ReleaseInfo release)
128147
{
129-
if (release.gameVersion == currentGameVersion)
148+
if (release.gameVersion == selectedGameVersion.value)
130149
releases.Add(release);
131150
}
132151
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace BeatSaberModManager.DataModels
8+
{
9+
public struct GameVersion
10+
{
11+
public string id;
12+
public string value;
13+
public string manifest;
14+
15+
public GameVersion(string _id, string _value, string _manifest)
16+
{
17+
id = _id;
18+
value = _value;
19+
manifest = _manifest;
20+
}
21+
}
22+
}

BeatSaberModManager/Forms/FormMain.Designer.cs

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BeatSaberModManager/Forms/FormMain.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ private void FormMain_Load(object sender, EventArgs e)
4040
textBoxDirectory.Text = path.GetInstallationPath();
4141
updater.CheckForUpdates();
4242

43+
remote.GetGameVersions();
44+
for (int i = 0; i < remote.gameVersions.Length; i++)
45+
{
46+
GameVersion gv = remote.gameVersions[i];
47+
comboBox_gameVersions.Items.Add(gv.value);
48+
}
49+
50+
comboBox_gameVersions.SelectedIndex = 0;
51+
4352
new Thread(() => { RemoteLoad(); }).Start();
4453
}
4554
catch (Exception ex)
@@ -48,16 +57,28 @@ private void FormMain_Load(object sender, EventArgs e)
4857
Environment.Exit(0);
4958
}
5059
}
60+
5161
private void RemoteLoad()
5262
{
53-
UpdateStatus("Loading latest releases...");
54-
remote.GetCurrentGameVersion();
63+
UpdateStatus("Loading releases...");
64+
5565
remote.PopulateReleases();
5666
installer = new InstallerLogic(remote.releases, path.installPath);
5767
installer.StatusUpdate += Installer_StatusUpdate;
5868
this.Invoke((MethodInvoker)(() => { ShowReleases(); }));
5969
}
6070

71+
private void comboBox_gameVersions_SelectedIndexChanged(object sender, EventArgs e)
72+
{
73+
ComboBox comboBox = (ComboBox)sender;
74+
GameVersion gameVersion = remote.gameVersions[comboBox.SelectedIndex];
75+
76+
remote.selectedGameVersion = gameVersion;
77+
remote.PopulateReleases();
78+
79+
this.Invoke((MethodInvoker)(() => { ShowReleases(); }));
80+
}
81+
6182
private void ShowReleases()
6283
{
6384
Dictionary<string, int> groups = new Dictionary<string, int>();
@@ -100,17 +121,17 @@ private void ShowReleases()
100121
}
101122
}
102123

103-
ReRenderListView();
104-
105124
ListViewGroup[] sortedGroups = new ListViewGroup[this.listViewMods.Groups.Count];
106125

107-
this.listViewMods.Groups.CopyTo(sortedGroups, 0);
126+
listViewMods.Groups.CopyTo(sortedGroups, 0);
108127
Array.Sort(sortedGroups, new GroupComparer());
109128

110-
this.listViewMods.BeginUpdate();
111-
this.listViewMods.Groups.Clear();
112-
this.listViewMods.Groups.AddRange(sortedGroups);
113-
this.listViewMods.EndUpdate();
129+
listViewMods.BeginUpdate();
130+
listViewMods.Groups.Clear();
131+
listViewMods.Groups.AddRange(sortedGroups);
132+
listViewMods.EndUpdate();
133+
134+
ReRenderListView();
114135

115136
UpdateStatus("Releases loaded.");
116137
tabControlMain.Enabled = true;

0 commit comments

Comments
 (0)