生成单文件
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Nancy.Hosting.Self;
|
||||
//using Nancy;
|
||||
//using Nancy.Hosting.Self;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -13,7 +14,7 @@ namespace 电子展板.Base
|
||||
{
|
||||
public class GlobalVariable
|
||||
{
|
||||
public static NancyHost WebServer;
|
||||
//public static NancyHost WebServer;
|
||||
|
||||
private static MyConfig _config;
|
||||
/// <summary>
|
||||
@@ -24,7 +25,38 @@ namespace 电子展板.Base
|
||||
get
|
||||
{
|
||||
if (_config == null)
|
||||
_config = File.ReadAllText(MyEnvironment.Root("/Configs/Config.json")).ToObject<MyConfig>();
|
||||
{
|
||||
try
|
||||
{
|
||||
_config = File.ReadAllText(MyEnvironment.Root("/Config.json"), Encoding.UTF8).ToObject<MyConfig>();
|
||||
//删除缓存没用到的图片
|
||||
List<string> list = new List<string>
|
||||
{
|
||||
_config.CPCMember1Path,
|
||||
_config.CPCMember2Path,
|
||||
_config.CPCMember3Path,
|
||||
_config.CPCMember4Path
|
||||
};
|
||||
list = list.Where(it => !it.IsNullOrEmpty()).Select(it => it.Replace("/upload/", "")).ToList();
|
||||
if (_config.FileUploadList == null)
|
||||
_config.FileUploadList = new List<UploadFiles>();
|
||||
_config.FileUploadList = _config.FileUploadList.Where(it => list.Contains(it.Name)).ToList();
|
||||
File.WriteAllText(MyEnvironment.Root("/Config.json"), _config.ToJson(), Encoding.UTF8);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string packUri = $"pack://application:,,,/Assets/InitConfig.json";
|
||||
string json = "";
|
||||
using (Stream stream = System.Windows.Application.GetResourceStream(new Uri(packUri, UriKind.RelativeOrAbsolute)).Stream)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
||||
{
|
||||
json = new StreamReader(stream, Encoding.UTF8).ReadToEnd();
|
||||
}
|
||||
}
|
||||
_config = json.ToObject<MyConfig>();
|
||||
}
|
||||
}
|
||||
return _config;
|
||||
}
|
||||
set
|
||||
@@ -35,7 +67,7 @@ namespace 电子展板.Base
|
||||
|
||||
public static void SaveConfig()
|
||||
{
|
||||
File.WriteAllText(MyEnvironment.Root("/Configs/Config.json"), Config.ToJson());
|
||||
File.WriteAllText(MyEnvironment.Root("/Config.json"), Config.ToJson(), Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user