18a4cdafaa
Related Work Items: #227
187 lines
4.7 KiB
C#
187 lines
4.7 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using Windows.ApplicationModel;
|
|
using Windows.Storage;
|
|
|
|
namespace FoxTube
|
|
{
|
|
public static class SettingsStorage
|
|
{
|
|
public static string VideoQuality
|
|
{
|
|
get { return (string)settings[0]; }
|
|
set
|
|
{
|
|
settings[0] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
public static string RememberedQuality
|
|
{
|
|
get { return (string)settings[1]; }
|
|
set
|
|
{
|
|
settings[1] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
|
|
public static bool VideoNotifications
|
|
{
|
|
get { return (bool)settings[2]; }
|
|
set
|
|
{
|
|
settings[2] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
public static bool DevNotifications
|
|
{
|
|
get { return (bool)settings[3]; }
|
|
set
|
|
{
|
|
settings[3] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
|
|
public static bool CheckConnection
|
|
{
|
|
get { return (bool)settings[4]; }
|
|
set
|
|
{
|
|
settings[4] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
public static bool Autoplay
|
|
{
|
|
get { return (bool)settings[5]; }
|
|
set
|
|
{
|
|
settings[5] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
public static int Volume
|
|
{
|
|
get { return Convert.ToInt32(settings[6]); }
|
|
set
|
|
{
|
|
settings[6] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
|
|
public static string Language
|
|
{
|
|
get { return (string)settings[7]; }
|
|
set
|
|
{
|
|
settings[7] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
public static string Region
|
|
{
|
|
get { return (string)settings[8]; }
|
|
set
|
|
{
|
|
settings[8] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
public static int SafeSearch
|
|
{
|
|
get { return Convert.ToInt32(settings[9]); }
|
|
set
|
|
{
|
|
settings[9] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
|
|
public static int Theme
|
|
{
|
|
get { return Convert.ToInt32(settings[10]); }
|
|
set
|
|
{
|
|
settings[10] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
public static bool HasAccount
|
|
{
|
|
get { return (bool)settings[11]; }
|
|
set
|
|
{
|
|
settings[11] = value;
|
|
SaveData();
|
|
}
|
|
}
|
|
|
|
public static string Version
|
|
{
|
|
get
|
|
{
|
|
if (storage.Values["ver"] == null)
|
|
{
|
|
PackageVersion ver = Package.Current.Id.Version;
|
|
storage.Values["version"] = $"{ver.Major}.{ver.Minor}";
|
|
return $"{ver.Major}.{ver.Minor}";
|
|
}
|
|
else return (string)storage.Values["version"];
|
|
}
|
|
set
|
|
{
|
|
storage.Values["version"] = value;
|
|
}
|
|
}
|
|
|
|
//Settings storage
|
|
private static readonly ApplicationDataContainer storage = ApplicationData.Current.LocalSettings;
|
|
|
|
//Predefined preferences
|
|
private static object[] settings = new object[]
|
|
{
|
|
"remember",
|
|
"1080p",
|
|
|
|
true,
|
|
true,
|
|
|
|
true,
|
|
true,
|
|
100,
|
|
|
|
(new[] { "ua", "ru", "by", "kz", "kg", "md", "lv", "ee" }).Contains(CultureInfo.InstalledUICulture.TwoLetterISOLanguageName) ? "ru-RU" : "en-US",
|
|
CultureInfo.CurrentCulture.Name,
|
|
0,
|
|
|
|
2,
|
|
false
|
|
};
|
|
|
|
public static void LoadData()
|
|
{
|
|
try
|
|
{
|
|
settings = JsonConvert.DeserializeObject<object[]>(storage.Values["settings"] as string);
|
|
}
|
|
catch (ArgumentNullException) { }
|
|
}
|
|
|
|
public static async void SaveData()
|
|
{
|
|
storage.Values["settings"] = JsonConvert.SerializeObject(settings);
|
|
|
|
bool[] notificationsSettings = new[] { VideoNotifications, DevNotifications };
|
|
await FileIO.WriteTextAsync(
|
|
await ApplicationData.Current.RoamingFolder.CreateFileAsync("notifications.json", CreationCollisionOption.ReplaceExisting),
|
|
JsonConvert.SerializeObject(notificationsSettings));
|
|
}
|
|
}
|
|
}
|