Skip to content

Commit

Permalink
Add cache configuration patch, compatible with older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ikas-mc committed Apr 6, 2022
1 parent 237c5c9 commit 070f5c3
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
1 change: 1 addition & 0 deletions ContextMenuCustom/ContextMenuCustomApp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
Patchs.Patch1.Run();
}

protected override void OnLaunched(LaunchActivatedEventArgs e)
Expand Down
18 changes: 18 additions & 0 deletions ContextMenuCustom/ContextMenuCustomApp/AppVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel;

namespace ContextMenuCustomApp
{
public static class AppVersion
{
public static int Current()
{
var version = Package.Current.Id.Version;
return version.Major * 1000 + version.Minor;
}
}
}
35 changes: 27 additions & 8 deletions ContextMenuCustom/ContextMenuCustomApp/Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,47 @@

namespace ContextMenuCustomApp.Common
{

public class Settings
{
private readonly static IPropertySet settings;

public readonly static Settings INS;
static Settings() {
static Settings()
{
settings = ApplicationData.Current.LocalSettings.CreateContainer("app-settings", ApplicationDataCreateDisposition.Always).Values;
INS = new Settings();
}

public bool CacheEnabled {
get {
return GetValue(nameof(CacheEnabled),false);
public bool CacheEnabled
{
get
{
return GetValue(nameof(CacheEnabled), false);
}
set {
set
{
SetValue(nameof(CacheEnabled), value);
}
}

private T GetValue<T>(string key,T defaultValue= default) {
if (settings[key] is T value) {

public int PatchVersion
{
get
{
return GetValue(nameof(PatchVersion), 0);
}
set
{
SetValue(nameof(PatchVersion), value);
}
}

private T GetValue<T>(string key, T defaultValue = default)
{
if (settings[key] is T value)
{
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Common\Settings.cs" />
<Compile Include="Patchs\Patch1.cs" />
<Compile Include="AppVersion.cs" />
<Compile Include="View\Common\Alert.cs" />
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
Expand Down
47 changes: 47 additions & 0 deletions ContextMenuCustom/ContextMenuCustomApp/Patchs/Patch1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using ContextMenuCustomApp.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.Storage;

namespace ContextMenuCustomApp.Patchs
{
public class Patch1
{

public static void Run()
{
var appVersion = AppVersion.Current();
var patchVersion = Settings.INS.PatchVersion;
if (patchVersion < 2003)
{
FixCacheSetting();
}

if (patchVersion != appVersion)
{
Settings.INS.PatchVersion = appVersion;
}
}

private static void FixCacheSetting()
{
try
{
var cacheTimeValue = ApplicationData.Current.LocalSettings.Values["Cache_Time"];
if (cacheTimeValue is string cacheTime)
{
Settings.INS.CacheEnabled = !string.IsNullOrEmpty(cacheTime);
}
}
catch
{

}
}

}
}

0 comments on commit 070f5c3

Please sign in to comment.