Skip to content

Commit 5d8dcbb

Browse files
committed
Fix: uninitialized setting; Typed Settings
1 parent 7070266 commit 5d8dcbb

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

Files/Files.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<Compile Include="Search.xaml.cs">
208208
<DependentUpon>Search.xaml</DependentUpon>
209209
</Compile>
210+
<Compile Include="Settings.cs" />
210211
<Compile Include="Settings.xaml.cs">
211212
<DependentUpon>Settings.xaml</DependentUpon>
212213
</Compile>

Files/Filesystem/ListedItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public static string GetFriendlyDate(DateTimeOffset d)
4242
{
4343
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
4444
var elapsed = DateTimeOffset.Now - d;
45-
string returnformat = Enum.Parse<TimeStyle>(localSettings.Values["datetimeformat"].ToString()) == TimeStyle.Application ? "D" : "g";
45+
46+
string returnformat = Enum.Parse<TimeStyle>(localSettings.Values[LocalSettings.DateTimeFormat].ToString()) == TimeStyle.Application ? "D" : "g";
4647

4748
if (elapsed.TotalDays > 7)
4849
{

Files/Settings.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Files
8+
{
9+
public static class LocalSettings
10+
{
11+
public const string DateTimeFormat = "datetimeformat";
12+
}
13+
}

Files/View Models/SettingsViewModel.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,21 @@ private void DetectSidebarOpacity()
5353

5454
private void DetectDateTimeFormat()
5555
{
56-
if (localSettings.Values["datetimeformat"] != null)
56+
if (localSettings.Values[LocalSettings.DateTimeFormat] != null)
5757
{
58-
if (localSettings.Values["datetimeformat"].ToString() == "Application")
58+
if (localSettings.Values[LocalSettings.DateTimeFormat].ToString() == "Application")
5959
{
6060
DisplayedTimeStyle = TimeStyle.Application;
6161
}
62-
else if (localSettings.Values["datetimeformat"].ToString() == "System")
62+
else if (localSettings.Values[LocalSettings.DateTimeFormat].ToString() == "System")
6363
{
6464
DisplayedTimeStyle = TimeStyle.System;
6565
}
6666
}
67+
else
68+
{
69+
localSettings.Values[LocalSettings.DateTimeFormat] = "System";
70+
}
6771
}
6872

6973
private async void DetectCustomLocations()
@@ -243,11 +247,11 @@ public TimeStyle DisplayedTimeStyle
243247
Set(ref _DisplayedTimeStyle, value);
244248
if (value.Equals(TimeStyle.Application))
245249
{
246-
localSettings.Values["datetimeformat"] = "Application";
250+
localSettings.Values[LocalSettings.DateTimeFormat] = "Application";
247251
}
248252
else if (value.Equals(TimeStyle.System))
249253
{
250-
localSettings.Values["datetimeformat"] = "System";
254+
localSettings.Values[LocalSettings.DateTimeFormat] = "System";
251255
}
252256
}
253257
}

0 commit comments

Comments
 (0)