|
|
@ -3,12 +3,31 @@ using Newtonsoft.Json;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
using DownKyi.Core.Utils.Encryptor;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace DownKyi.Core.Settings
|
|
|
|
namespace DownKyi.Core.Settings
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public partial class SettingsManager
|
|
|
|
public partial class SettingsManager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private static SettingsManager instance;
|
|
|
|
private static SettingsManager instance;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 内存中保存一份配置
|
|
|
|
|
|
|
|
private AppSettings appSettings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
// 设置的配置文件
|
|
|
|
|
|
|
|
private readonly string settingsName = Storage.StorageManager.GetSettings() + "_debug.json";
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// 设置的配置文件
|
|
|
|
|
|
|
|
private readonly string settingsName = Storage.StorageManager.GetSettings();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 密钥
|
|
|
|
|
|
|
|
private readonly string password = "YO1J$4#p";
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取SettingsManager实例
|
|
|
|
/// 获取SettingsManager实例
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -30,12 +49,6 @@ namespace DownKyi.Core.Settings
|
|
|
|
appSettings = GetSettings();
|
|
|
|
appSettings = GetSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 内存中保存一份配置
|
|
|
|
|
|
|
|
private AppSettings appSettings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置的配置文件
|
|
|
|
|
|
|
|
private readonly string settingsName = Storage.StorageManager.GetSettings();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取AppSettingsModel
|
|
|
|
/// 获取AppSettingsModel
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -48,6 +61,12 @@ namespace DownKyi.Core.Settings
|
|
|
|
string jsonWordTemplate = streamReader.ReadToEnd();
|
|
|
|
string jsonWordTemplate = streamReader.ReadToEnd();
|
|
|
|
streamReader.Close();
|
|
|
|
streamReader.Close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// 解密字符串
|
|
|
|
|
|
|
|
jsonWordTemplate = Encryptor.DecryptString(jsonWordTemplate, password);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return JsonConvert.DeserializeObject<AppSettings>(jsonWordTemplate);
|
|
|
|
return JsonConvert.DeserializeObject<AppSettings>(jsonWordTemplate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
catch (Exception e)
|
|
|
@ -65,6 +84,12 @@ namespace DownKyi.Core.Settings
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string json = JsonConvert.SerializeObject(appSettings);
|
|
|
|
string json = JsonConvert.SerializeObject(appSettings);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// 加密字符串
|
|
|
|
|
|
|
|
json = Encryptor.EncryptString(json, password);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
File.WriteAllText(settingsName, json);
|
|
|
|
File.WriteAllText(settingsName, json);
|
|
|
|