生成单文件

This commit is contained in:
2025-09-26 17:42:33 +08:00
parent 0884292626
commit 13b838c7c7
17 changed files with 1671 additions and 206 deletions

View File

@@ -1,19 +1,20 @@
using Nancy;
using Nancy.Hosting.Self;
using Nancy.Json;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using .Base;
using .Models;
using .Utility;
using .Utility.Core;
using .Utility.Extension;
namespace .ViewModels
@@ -28,7 +29,7 @@ namespace 电子展板.ViewModels
public DelegateCommand<Window> LoadedCommand { get; set; }
public DelegateCommand<CancelEventArgs> WindowClosingCommand { get; set; }
public MainWindowViewModel()
{
{
LoadedCommand = new DelegateCommand<Window>(Loaded);
WindowClosingCommand = new DelegateCommand<CancelEventArgs>(WindowClosing);
EventBus.Instance.Subscribe(this, "save", ReloadImage);
@@ -43,15 +44,18 @@ namespace 电子展板.ViewModels
this.window.Top = (int)(Screen.AllScreens[screenIndex].Bounds.Top / GetDpiScaleX());
this.window.Width = (int)(Screen.AllScreens[screenIndex].Bounds.Width / GetDpiScaleX());
this.window.Height = (int)(Screen.AllScreens[screenIndex].Bounds.Height / GetDpiScaleX());
GlobalVariable.WebServer = new NancyHost(new Uri("http://localhost:80"));
GlobalVariable.WebServer.Start();
WebServer.Start();
//GlobalVariable.WebServer = new NancyHost(new Uri("http://localhost:80"));
//GlobalVariable.WebServer.Start();
}
private void WindowClosing(CancelEventArgs args)
{
GlobalVariable.WebServer?.Stop();
GlobalVariable.WebServer?.Dispose();
GlobalVariable.WebServer = null;
WebServer.Stop();
//GlobalVariable.WebServer?.Stop();
//GlobalVariable.WebServer?.Dispose();
//GlobalVariable.WebServer = null;
Environment.Exit(0);
}
public double GetDpiScaleX()
@@ -70,62 +74,32 @@ namespace 电子展板.ViewModels
private void InitImage()
{
try
{
BitmapImage image1 = new BitmapImage();
image1.BeginInit();
image1.CacheOption = BitmapCacheOption.OnLoad;
image1.StreamSource = new MemoryStream(File.ReadAllBytes(MyEnvironment.Root(Config.CPCMember1Path)));
image1.EndInit();
image1.Freeze();
Image1 = image1;
}
catch (Exception ex)
{
Image1 = null;
}
try
{
BitmapImage image2 = new BitmapImage();
image2.BeginInit();
image2.CacheOption = BitmapCacheOption.OnLoad;
image2.StreamSource = new MemoryStream(File.ReadAllBytes(MyEnvironment.Root(Config.CPCMember2Path)));
image2.EndInit();
image2.Freeze();
Image2 = image2;
}
catch (Exception ex)
{
Image2 = null;
Image1 = GetImage(Config.CPCMember1Path);
Image2 = GetImage(Config.CPCMember2Path);
Image3 = GetImage(Config.CPCMember3Path);
Image4 = GetImage(Config.CPCMember4Path);
}
}
private ImageSource GetImage(string path)
{
try
{
BitmapImage image3 = new BitmapImage();
image3.BeginInit();
image3.CacheOption = BitmapCacheOption.OnLoad;
image3.StreamSource = new MemoryStream(File.ReadAllBytes(MyEnvironment.Root(Config.CPCMember3Path)));
image3.EndInit();
image3.Freeze();
Image3 = image3;
if (path.IsNullOrEmpty())
return null;
UploadFiles uploadFiles = GlobalVariable.Config.FileUploadList.FirstOrDefault(x => path.EndsWith(x.Name));
if (uploadFiles == null)
return null;
BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.StreamSource = new ByteArrayStream(uploadFiles.Bin);
image.EndInit();
image.Freeze();
return image;
}
catch (Exception ex)
{
Image3 = null;
}
try
{
BitmapImage image4 = new BitmapImage();
image4.BeginInit();
image4.CacheOption = BitmapCacheOption.OnLoad;
image4.StreamSource = new MemoryStream(File.ReadAllBytes(MyEnvironment.Root(Config.CPCMember4Path)));
image4.EndInit();
image4.Freeze();
Image4 = image4;
}
catch (Exception ex)
{
Image4 = null;
return null;
}
}
}