Added option to have OCI window close after its finished

This commit is contained in:
Assistant 2020-05-19 16:48:35 -06:00
parent dba0a7d951
commit ec03c8127b
10 changed files with 71 additions and 2 deletions

View file

@ -50,6 +50,9 @@
<setting name="ReinstallInstalled" serializeAs="String">
<value>True</value>
</setting>
<setting name="CloseWindowOnFinish" serializeAs="String">
<value>False</value>
</setting>
</ModAssistant.Properties.Settings>
<ModAssistant.Settings1>
<setting name="InstallFolder" serializeAs="String">

View file

@ -21,6 +21,7 @@ namespace ModAssistant
public static bool CheckInstalledMods;
public static bool SelectInstalledMods;
public static bool ReinstallInstalledMods;
public static bool CloseWindowOnFinish;
public static string Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public static List<string> SavedMods = ModAssistant.Properties.Settings.Default.SavedMods.Split(',').ToList();
public static MainWindow window;
@ -69,6 +70,7 @@ namespace ModAssistant
CheckInstalledMods = ModAssistant.Properties.Settings.Default.CheckInstalled;
SelectInstalledMods = ModAssistant.Properties.Settings.Default.SelectInstalled;
ReinstallInstalledMods = ModAssistant.Properties.Settings.Default.ReinstallInstalled;
CloseWindowOnFinish = ModAssistant.Properties.Settings.Default.CloseWindowOnFinish;
await ArgumentHandler(e.Args);
await Init();
@ -108,6 +110,12 @@ namespace ModAssistant
await OneClickInstaller.InstallAsset(args[1]);
}
if (CloseWindowOnFinish)
{
await Task.Delay(5 * 1000);
Current.Shutdown();
}
Update = false;
GUI = false;
args = Shift(args, 2);

View file

@ -61,6 +61,7 @@ namespace ModAssistant.API
{
ModAssistant.Utils.Log($"Failed downloading BeatSaver map: {id} | Error: {e.Message}", "ERROR");
Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("OneClick:Failed"), (map.Name ?? id))}");
App.CloseWindowOnFinish = false;
}
return map;
}
@ -71,6 +72,7 @@ namespace ModAssistant.API
{
ModAssistant.Utils.Log($"Max tries reached: Skipping {url}", "ERROR");
Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("OneClick:RatelimitSkip"), url)}");
App.CloseWindowOnFinish = false;
throw new Exception("Max retries allowed");
}
@ -97,6 +99,7 @@ namespace ModAssistant.API
else
{
Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("OneClick:Failed"), url)}");
App.CloseWindowOnFinish = false;
return response;
}
}
@ -197,9 +200,9 @@ namespace ModAssistant.API
return mapName;
}
public static BeatSaver.BeatSaverRatelimit GetRatelimit(HttpResponseHeaders headers)
public static BeatSaverRatelimit GetRatelimit(HttpResponseHeaders headers)
{
BeatSaver.BeatSaverRatelimit ratelimit = new BeatSaver.BeatSaverRatelimit();
BeatSaverRatelimit ratelimit = new BeatSaverRatelimit();
if (headers.TryGetValues("Rate-Limit-Remaining", out IEnumerable<string> _remaining))
@ -241,6 +244,8 @@ namespace ModAssistant.API
{
if (retries == 0)
{
Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("OneClick:RatelimitSkip"), url)}");
App.CloseWindowOnFinish = false;
ModAssistant.Utils.Log($"Max tries reached: Couldn't download {url}", "ERROR");
throw new Exception("Max retries allowed");
}

View file

@ -77,6 +77,7 @@ namespace ModAssistant.API
{
Utils.SetMessage($"{string.Format((string)Application.Current.FindResource("Options:FailedPlaylistSong"), song.songName)}");
ModAssistant.Utils.Log($"Failed installing BeatSaver map: {song.songName} | {song.key} | {song.hash} | ({response?.response?.ratelimit?.Remaining})");
App.CloseWindowOnFinish = false;
await Task.Delay(3 * 1000);
Errors++;
}

View file

@ -69,6 +69,7 @@ namespace ModAssistant.API
catch
{
SetMessage((string)Application.Current.FindResource("OneClick:AssetInstallFailed"));
App.CloseWindowOnFinish = false;
}
}
}

View file

@ -141,6 +141,7 @@
<sys:String x:Key="Options:BeatSaver">BeatSaver</sys:String>
<sys:String x:Key="Options:ModelSaber">ModelSaber</sys:String>
<sys:String x:Key="Options:Playlists">Playlists</sys:String>
<sys:String x:Key="Options:CloseWindow">Close window when finished</sys:String>
<sys:String x:Key="Options:GameType">Game Type</sys:String>
<sys:String x:Key="Options:GameType:Steam">Steam</sys:String>
<sys:String x:Key="Options:GameType:Oculus">Oculus</sys:String>

View file

@ -218,6 +218,23 @@
IsChecked="{Binding PlaylistsProtocolHandlerEnabled}"
Unchecked="PlaylistsProtocolHandler_Unchecked" />
<TextBlock
Grid.Row="11"
Margin="50,5,5,5"
HorizontalAlignment="Left"
FontSize="16"
FontWeight="Bold"
Text="{DynamicResource Options:CloseWindow}" />
<CheckBox
Name="CloseWindowToggle"
Grid.Row="11"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Checked="CloseWindowOnFinish_Checked"
IsChecked="{Binding CloseWindowOnFinish}"
Unchecked="CloseWindowOnFinish_Unchecked" />
<StackPanel
Grid.Row="12"
Margin="5"

View file

@ -25,6 +25,7 @@ namespace ModAssistant.Pages
public bool ModelSaberProtocolHandlerEnabled { get; set; }
public bool BeatSaverProtocolHandlerEnabled { get; set; }
public bool PlaylistsProtocolHandlerEnabled { get; set; }
public bool CloseWindowOnFinish { get; set; }
public string LogURL { get; private set; }
public Options()
@ -36,6 +37,7 @@ namespace ModAssistant.Pages
CheckInstalledMods = App.CheckInstalledMods;
SelectInstalledMods = App.SelectInstalledMods;
ReinstallInstalledMods = App.ReinstallInstalledMods;
CloseWindowOnFinish = App.CloseWindowOnFinish;
if (!CheckInstalledMods)
{
SelectInstalled.IsEnabled = false;
@ -116,6 +118,22 @@ namespace ModAssistant.Pages
}
}
private void CloseWindowOnFinish_Checked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.CloseWindowOnFinish = true;
App.CloseWindowOnFinish = true;
CloseWindowOnFinish = true;
Properties.Settings.Default.Save();
}
private void CloseWindowOnFinish_Unchecked(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.CloseWindowOnFinish = false;
App.CloseWindowOnFinish = false;
CloseWindowOnFinish = false;
Properties.Settings.Default.Save();
}
public void ModelSaberProtocolHandler_Checked(object sender, RoutedEventArgs e)
{
OneClickInstaller.Register("modelsaber");

View file

@ -178,5 +178,17 @@ namespace ModAssistant.Properties {
this["ReinstallInstalled"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool CloseWindowOnFinish {
get {
return ((bool)(this["CloseWindowOnFinish"]));
}
set {
this["CloseWindowOnFinish"] = value;
}
}
}
}

View file

@ -41,5 +41,8 @@
<Setting Name="ReinstallInstalled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CloseWindowOnFinish" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>