Skip to content

Commit

Permalink
Add persistence to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sabihoshi committed Apr 21, 2021
1 parent 2d0d705 commit 64932c3
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 12 deletions.
2 changes: 0 additions & 2 deletions GenshinLauncher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

<s:ApplicationLoader>
<s:ApplicationLoader.Bootstrapper>
<local:Bootstrapper />
Expand Down Expand Up @@ -35,7 +34,6 @@
</Style>
</Style.Resources>
</Style>

</ResourceDictionary>
</Application.Resources>
</Application>
5 changes: 5 additions & 0 deletions GenshinLauncher/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
using GenshinLauncher.ViewModels;
using Stylet;
Expand All @@ -23,6 +24,10 @@ protected override void Configure()
});
})
);

if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
{
}
}
}
}
62 changes: 62 additions & 0 deletions GenshinLauncher/Config.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions GenshinLauncher/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace GenshinLauncher {


// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Config {

public Config() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}

private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}

private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}
15 changes: 15 additions & 0 deletions GenshinLauncher/Config.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="GenshinLauncher" GeneratedClassName="Config">
<Profiles />
<Settings>
<Setting Name="GenshinLocation" Type="System.String" Scope="User">
<Value Profile="(Default)">C:\Program Files\Genshin Impact\Genshin Impact Game\GenshinImpact.exe</Value>
</Setting>
<Setting Name="Borderless" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Fullscreen" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
17 changes: 16 additions & 1 deletion GenshinLauncher/GenshinLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RepositoryUrl>https://github.com/sabihoshi/GenshinLauncher</RepositoryUrl>
<Description>A Genshin Impact launcher with more options in Modern Fluent UI.</Description>
<ApplicationIcon>GenshinImpactIcon.ico</ApplicationIcon>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -29,4 +29,19 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<Compile Update="Config.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Config.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Config.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Config.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>
17 changes: 10 additions & 7 deletions GenshinLauncher/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;
using CliWrap;
using Stylet;
Expand All @@ -13,10 +14,6 @@ public MainWindowViewModel()
Resolution = Resolution.Presets.Last();
}

public bool Fullscreen { get; set; } = true;

public bool Borderless { get; set; }

public Command Client => Cli.Wrap(GenshinLocation);

public QualityViewModel Quality { get; }
Expand All @@ -25,13 +22,19 @@ public MainWindowViewModel()

public string Title { get; } = "Genshin Impact Launcher";

[UserScopedSetting]
public string GenshinLocation { get; set; } =
@"C:\Program Files\Genshin Impact\Genshin Impact Game\GenshinImpact.exe";

public async Task<CommandResult> LaunchSelector() =>
await Client.WithArguments("-show-screen-selector")
.ExecuteAsync();

protected override void OnClose()
{
Config.Default.Save();
}

public void LaunchGame()
{
var client = Client
Expand All @@ -40,9 +43,9 @@ public void LaunchGame()
args
.Add("-screen-width").Add(Resolution.Width)
.Add("-screen-height").Add(Resolution.Height)
.Add("-screen-fullscreen").Add(Fullscreen ? 1 : 0);
.Add("-screen-fullscreen").Add(Config.Default.Fullscreen ? 1 : 0);

if (Borderless)
if (Config.Default.Borderless)
args.Add("-popupwindow");

if (Quality.SelectedQuality != Models.Quality.Default)
Expand Down
6 changes: 4 additions & 2 deletions GenshinLauncher/Views/MainWindowView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:s="https://github.com/canton7/Stylet"

xmlns:viewModels="clr-namespace:GenshinLauncher.ViewModels"
xmlns:genshinLauncher="clr-namespace:GenshinLauncher"
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}"

Title="{Binding Title}"
Expand All @@ -18,6 +19,7 @@
ui:TitleBar.ExtendViewIntoTitleBar="True">

<Window.Resources>
<genshinLauncher:Config x:Key="Config" />
<Style TargetType="ui:NumberBox">
<Setter Property="SpinButtonPlacementMode" Value="Compact" />
<Setter Property="Minimum" Value="0" />
Expand All @@ -33,11 +35,11 @@
<ui:SimpleStackPanel Orientation="Horizontal">
<ui:ToggleSwitch
Header="Fullscreen"
IsOn="{Binding Fullscreen}" />
IsOn="{Binding Default.Fullscreen, Source={StaticResource Config}}" />

<ui:ToggleSwitch
Header="Borderless"
IsOn="{Binding Borderless}" />
IsOn="{Binding Default.Borderless, Source={StaticResource Config}}" />
</ui:SimpleStackPanel>

<GroupBox Header="Quality">
Expand Down

0 comments on commit 64932c3

Please sign in to comment.