设置文件在release时加密

croire 3 years ago
parent 4c09ded9c1
commit c2351ae21b

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

@ -27,7 +27,7 @@ namespace DownKyi.Core.Storage
public static string Config { get; } = $"{Root}/Config";
// 设置
public static string Settings { get; } = $"{Config}/Settings.json";
public static string Settings { get; } = $"{Config}/Settings";
// 登录cookies
public static string Login { get; } = $"{Config}/Login";

Loading…
Cancel
Save