Skip to content

Commit de963f8

Browse files
committed
Add Assets Download Server Selection
1 parent 85bc9be commit de963f8

File tree

10 files changed

+148
-38
lines changed

10 files changed

+148
-38
lines changed

ModAssistant/App.config

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<userSettings>
1313
<ModAssistant.Properties.Settings>
1414
<setting name="InstallFolder" serializeAs="String">
15-
<value/>
15+
<value />
1616
</setting>
1717
<setting name="StoreType" serializeAs="String">
18-
<value/>
18+
<value />
1919
</setting>
2020
<setting name="SaveSelected" serializeAs="String">
2121
<value>False</value>
@@ -33,22 +33,19 @@
3333
<value>False</value>
3434
</setting>
3535
<setting name="GameVersion" serializeAs="String">
36-
<value/>
36+
<value />
3737
</setting>
3838
<setting name="AllGameVersions" serializeAs="String">
39-
<value/>
39+
<value />
4040
</setting>
4141
<setting name="UpgradeRequired" serializeAs="String">
4242
<value>True</value>
4343
</setting>
4444
<setting name="LastTab" serializeAs="String">
45-
<value/>
45+
<value />
4646
</setting>
4747
<setting name="SelectedTheme" serializeAs="String">
48-
<value/>
49-
</setting>
50-
<setting name="AppliedAnniversaryTheme" serializeAs="String">
51-
<value>False</value>
48+
<value />
5249
</setting>
5350
<setting name="ReinstallInstalled" serializeAs="String">
5451
<value>True</value>
@@ -57,17 +54,23 @@
5754
<value>False</value>
5855
</setting>
5956
<setting name="LanguageCode" serializeAs="String">
60-
<value/>
57+
<value />
6158
</setting>
6259
<setting name="OCIWindow" serializeAs="String">
63-
<value/>
60+
<value />
6461
</setting>
6562
<setting name="DownloadServer" serializeAs="String">
6663
<value>国际源@BeatMods</value>
6764
</setting>
6865
<setting name="Setting" serializeAs="String">
6966
<value />
7067
</setting>
68+
<setting name="AppliedAnniversaryTheme" serializeAs="String">
69+
<value>False</value>
70+
</setting>
71+
<setting name="AssetsDownloadServer" serializeAs="String">
72+
<value>默认@default</value>
73+
</setting>
7174
</ModAssistant.Properties.Settings>
7275
<ModAssistant.Settings1>
7376
<setting name="InstallFolder" serializeAs="String">

ModAssistant/App.xaml.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ private async void Application_Startup(object sender, StartupEventArgs e)
5454
Languages.LoadLanguages();
5555

5656
Options.Instance.DownloadServerSelectComboBox.ItemsSource = Options.serverList.ToList();
57-
Options.Instance.DownloadServerSelectComboBox.SelectedIndex = Options.serverList.ToList().FindIndex((string server) => server == ModAssistant.Properties.Settings.Default.DownloadServer);
57+
int DownloadServerIndex = Options.serverList.ToList().FindIndex((string server) => server == ModAssistant.Properties.Settings.Default.DownloadServer);
58+
Options.Instance.DownloadServerSelectComboBox.SelectedIndex = DownloadServerIndex == -1 ? 0 : DownloadServerIndex;
59+
60+
Options.Instance.AssetsDownloadServerSelectComboBox.ItemsSource = Options.assetsServerList.ToList();
61+
int AssetsDownloadServerIndex = Options.assetsServerList.ToList().FindIndex((string server) => server == ModAssistant.Properties.Settings.Default.AssetsDownloadServer);
62+
Options.Instance.AssetsDownloadServerSelectComboBox.SelectedIndex = AssetsDownloadServerIndex == -1 ? 0 : AssetsDownloadServerIndex;
5863

5964
while (string.IsNullOrEmpty(BeatSaberInstallDirectory))
6065
{

ModAssistant/Classes/External Interfaces/BeatSaver.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ namespace ModAssistant.API
1414
{
1515
public class BeatSaver
1616
{
17-
private const string BeatSaverURLPrefix = "https://api.beatsaver.com";
17+
private static string BeatSaverURLPrefix { get =>
18+
Properties.Settings.Default.AssetsDownloadServer == AssetsServer.Default ? ModAssistant.Utils.Constants.BeatSaverURLPrefix_default :
19+
(Properties.Settings.Default.AssetsDownloadServer == AssetsServer.WGZeyu ? ModAssistant.Utils.Constants.BeatSaverURLPrefix_wgzeyu :
20+
ModAssistant.Utils.Constants.BeatSaverURLPrefix_beatsaberchina);
21+
}
22+
23+
private static string BeatSaverCDNURLPrefix
24+
{
25+
get =>
26+
Properties.Settings.Default.AssetsDownloadServer == AssetsServer.Default ? ModAssistant.Utils.Constants.BeatSaverCDNURLPrefix_default :
27+
(Properties.Settings.Default.AssetsDownloadServer == AssetsServer.WGZeyu ? ModAssistant.Utils.Constants.BeatSaverCDNURLPrefix_wgzeyu :
28+
ModAssistant.Utils.Constants.BeatSaverCDNURLPrefix_beatsaberchina);
29+
}
1830
private static readonly string CustomSongsFolder = Path.Combine("Beat Saber_Data", "CustomLevels");
1931
private static readonly string CustomWIPSongsFolder = Path.Combine("Beat Saber_Data", "CustomWIPLevels");
2032
private const bool BypassDownloadCounter = false;
@@ -253,6 +265,7 @@ public static DateTime UnixTimestampToDateTime(double unixTime)
253265

254266
public static async Task Download(string url, string output, int retries = 3)
255267
{
268+
url = proxyURL(url);
256269
if (retries == 0)
257270
{
258271
Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("OneClick:RatelimitSkip"), url)}");
@@ -389,6 +402,13 @@ public class ParitySummary
389402
public int resets { get; set; }
390403
}
391404
}
405+
406+
public static string proxyURL(string url) {
407+
return url.Replace("https://as.cdn.beatsaver.com", "https://cdn.beatsaver.com")
408+
.Replace("https://na.cdn.beatsaver.com", "https://cdn.beatsaver.com")
409+
.Replace("https://r2cdn.beatsaver.com", "https://cdn.beatsaver.com")
410+
.Replace("https://cdn.beatsaver.com", BeatSaverCDNURLPrefix);
411+
}
392412
}
393413
}
394414
#pragma warning restore IDE1006 // Naming Styles

ModAssistant/Classes/External Interfaces/ModelSaber.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ namespace ModAssistant.API
55
{
66
class ModelSaber
77
{
8-
private const string ModelSaberURLPrefix = "https://modelsaber.com/files/";
8+
private static string ModelSaberURLPrefix
9+
{
10+
get =>
11+
Properties.Settings.Default.AssetsDownloadServer == AssetsServer.Default ? ModAssistant.Utils.Constants.ModelSaberURLPrefix_default :
12+
(Properties.Settings.Default.AssetsDownloadServer == AssetsServer.WGZeyu ? ModAssistant.Utils.Constants.ModelSaberURLPrefix_wgzeyu :
13+
ModAssistant.Utils.Constants.ModelSaberURLPrefix_beatsaberchina);
14+
}
915
private const string CustomAvatarsFolder = "CustomAvatars";
1016
private const string CustomSabersFolder = "CustomSabers";
1117
private const string CustomPlatformsFolder = "CustomPlatforms";

ModAssistant/Classes/Server.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ public static class Server
1212
public const string WGZeyu = "国内源@WGzeyu";
1313
public const string BeatModsTop = "包子源@BeatTop";
1414
}
15+
16+
public static class AssetsServer
17+
{
18+
public const string Default = "默认@default";
19+
public const string WGZeyu = "国内源@WGzeyu";
20+
public const string BeatSaberChina = "光剑中文社区源@BeatSaberChina";
21+
}
1522
}

ModAssistant/Classes/Utils.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ public class Constants
5050
public const string BeatModsAlias_bmtop = "https://alias-beatmods.beatmods.top/aliases.json";
5151
public const string WeebCDNAPIURL_bmtop = "https://pat-assistant-moe.beatmods.top/api/v1.0/";
5252

53+
public const string BeatSaverURLPrefix_default = "https://api.beatsaver.com";
54+
public const string BeatSaverURLPrefix_wgzeyu = "https://beatsaver.wgzeyu.vip/api";
55+
public const string BeatSaverURLPrefix_beatsaberchina = "https://beatsaver.beatsaberchina.com/api";
56+
57+
public const string BeatSaverCDNURLPrefix_default = "https://cdn.beatsaver.com";
58+
public const string BeatSaverCDNURLPrefix_wgzeyu = "https://beatsaver.wgzeyu.vip/cdn";
59+
public const string BeatSaverCDNURLPrefix_beatsaberchina = "https://beatsaver-cdn.beatsaberchina.com";
60+
61+
public const string ModelSaberURLPrefix_default = "https://modelsaber.com/files/";
62+
public const string ModelSaberURLPrefix_wgzeyu = "https://modelsaber.wgzeyu.vip/files/";
63+
public const string ModelSaberURLPrefix_beatsaberchina = "https://modelsaber.beatsaberchina.com/files/";
64+
5365
public static string BeatModsAPIUrl;
5466
public static string TeknikAPIUrl;
5567
public static string BeatModsURL;

ModAssistant/Pages/Options.xaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@
7373
FontSize="16"
7474
FontWeight="Bold"
7575
Text="{DynamicResource Options:InstallFolder}" />
76-
<TextBlock
76+
<TextBlock
7777
Grid.Row="1"
7878
Grid.Column="2"
7979
Margin="5"
8080
HorizontalAlignment="Right"
8181
FontSize="22"
8282
FontWeight="Bold"
8383
Text="" />
84-
<ComboBox
84+
<ComboBox
8585
Name="DownloadServerSelectComboBox"
8686
Grid.Row="1"
8787
Grid.Column="3"
8888
Height="30"
8989
HorizontalAlignment="Stretch"
9090
VerticalContentAlignment="Center"
9191
SelectionChanged="DownloadServerSelectComboBox_SelectionChanged" />
92-
<Border
92+
<Border
9393
Grid.Row="2"
9494
Grid.ColumnSpan="2"
9595
Height="30"
@@ -390,6 +390,21 @@
390390
<TextBlock Foreground="White" Text="{DynamicResource Options:RemoveAllModsButton}" />
391391
</Button>
392392
</StackPanel>
393+
<TextBlock
394+
Grid.Row="8"
395+
Grid.Column="2"
396+
Margin="72,37,0,4"
397+
HorizontalAlignment="Left"
398+
FontSize="22"
399+
FontWeight="Bold"
400+
Text="" Grid.RowSpan="2" />
401+
<ComboBox
402+
x:Name="AssetsDownloadServerSelectComboBox"
403+
Grid.Row="8"
404+
Grid.Column="2"
405+
Height="30"
406+
VerticalContentAlignment="Center"
407+
SelectionChanged="AssetsDownloadServerSelectComboBox_SelectionChanged" Margin="107,38,1,3" Grid.RowSpan="2" Grid.ColumnSpan="2" />
393408

394409
</Grid>
395410
</ScrollViewer>

ModAssistant/Pages/Options.xaml.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public partial class Options : Page
3333
public string OCIWindow { get; set; }
3434

3535
public static string[] serverList = { "国际源@BeatMods", "国内源@WGzeyu", "包子源@BeatTop" };
36+
public static string[] assetsServerList = { "默认@default", "国内源@WGzeyu", "光剑中文社区源@BeatSaberChina" };
3637

3738
public Options()
3839
{
@@ -367,8 +368,8 @@ public void DownloadServerSelectComboBox_SelectionChanged(object sender, Selecti
367368
if ((sender as ComboBox).SelectedItem == null)
368369
{
369370
// Apply default server config
370-
Console.WriteLine("Applying default server config");
371-
DownloadServerSelectComboBox.SelectedItem = Server.BeatMods;
371+
Console.WriteLine("Applying default assets server config");
372+
AssetsDownloadServerSelectComboBox.SelectedItem = Server.BeatMods;
372373
Properties.Settings.Default.DownloadServer = Server.BeatMods;
373374
Properties.Settings.Default.Save();
374375
Process.Start(Utils.ExePath, App.Arguments);
@@ -386,7 +387,6 @@ public void DownloadServerSelectComboBox_SelectionChanged(object sender, Selecti
386387
Process.Start(Utils.ExePath, App.Arguments);
387388
Application.Current.Dispatcher.Invoke(() => { Application.Current.Shutdown(); });
388389
}
389-
390390
}
391391
}
392392

@@ -444,5 +444,32 @@ public void UpdateOCIWindow(string state)
444444
Properties.Settings.Default.Save();
445445
}
446446
}
447+
448+
private void AssetsDownloadServerSelectComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
449+
{
450+
if ((sender as ComboBox).SelectedItem == null)
451+
{
452+
// Apply default server config
453+
Console.WriteLine("Applying default server config");
454+
DownloadServerSelectComboBox.SelectedItem = AssetsServer.Default;
455+
Properties.Settings.Default.AssetsDownloadServer = AssetsServer.Default;
456+
Properties.Settings.Default.Save();
457+
Process.Start(Utils.ExePath, App.Arguments);
458+
Application.Current.Dispatcher.Invoke(() => { Application.Current.Shutdown(); });
459+
}
460+
else
461+
{
462+
if (string.IsNullOrEmpty(Properties.Settings.Default.AssetsDownloadServer) || Properties.Settings.Default.AssetsDownloadServer != (sender as ComboBox).SelectedItem.ToString())
463+
{
464+
// Get the matching servers from the server array, then try and use it
465+
var serverName = (sender as ComboBox).SelectedItem.ToString();
466+
var selectedServer = (Array.IndexOf(serverList, serverName) == -1) ? AssetsServer.Default : serverName;
467+
Properties.Settings.Default.AssetsDownloadServer = serverName;
468+
Properties.Settings.Default.Save();
469+
Process.Start(Utils.ExePath, App.Arguments);
470+
Application.Current.Dispatcher.Invoke(() => { Application.Current.Shutdown(); });
471+
}
472+
}
473+
}
447474
}
448475
}

ModAssistant/Properties/Settings.Designer.cs

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

ModAssistant/Properties/Settings.settings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@
5656
<Setting Name="Setting" Type="System.String" Scope="User">
5757
<Value Profile="(Default)" />
5858
</Setting>
59+
<Setting Name="AppliedAnniversaryTheme" Type="System.Boolean" Scope="User">
60+
<Value Profile="(Default)">False</Value>
61+
</Setting>
62+
<Setting Name="AssetsDownloadServer" Type="System.String" Scope="User">
63+
<Value Profile="(Default)">默认@default</Value>
64+
</Setting>
5965
</Settings>
6066
</SettingsFile>

0 commit comments

Comments
 (0)