You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
9.3 KiB
199 lines
9.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Xml;
|
|
using Lierda.WPFHelper;
|
|
using log4net;
|
|
using PCScreenSavers.Business;
|
|
using PCScreenSavers.Common;
|
|
using PCScreenSavers.ViewModel;
|
|
using PCScreenSavers.Win;
|
|
using WebSocket4Net;
|
|
|
|
namespace PCScreenSavers
|
|
{
|
|
/// <summary>
|
|
/// App.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
internal string HttpUrl = "";
|
|
internal string KioskURL = "";
|
|
internal string LocalIP = "";
|
|
internal string configwebsocket = "ws://192.168.0.250:8111";
|
|
internal string isOnlyScreensaver = "0";
|
|
internal string Appversion = "";
|
|
internal string TouchType = "";
|
|
internal NavViewModel navModel = new NavViewModel();
|
|
internal static bool Downloaddone = false;
|
|
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
Class_Log clog = new Class_Log();
|
|
internal List<string> TopSubTitle = new List<string> { };
|
|
internal List<string> BottomSubTitle = new List<string> { };
|
|
internal int TopSubTitleIndex = 0;
|
|
internal int BottomSubTitleIndex = 0;
|
|
internal bool isGotoStart = false;
|
|
internal string StartTime = "";
|
|
internal bool isSameScreen = false;
|
|
internal int PlayTime = 0;
|
|
internal WebSocket websocket = null;
|
|
//LierdaCracker cracker = new LierdaCracker();
|
|
//e:Url|IP
|
|
private void Application_Startup(object sender, StartupEventArgs e)
|
|
{
|
|
//cracker.Cracker(300);//垃圾回收间隔时间
|
|
try
|
|
{
|
|
|
|
string info = "";
|
|
bool update = true;
|
|
clog.WriteLogFile("收到:" + e.Args.Count(), "Loadargs");
|
|
if (e.Args.Count() > 0)
|
|
{
|
|
clog.WriteLogFile("收到:"+e.Args[0].ToString(),"Loadargs");
|
|
string[] inf = e.Args[0].ToString().Split('&');
|
|
clog.WriteLogFile("inf.Count():" + inf.Count().ToString(), "Loadargs");
|
|
if (inf.Count() > 0)
|
|
{
|
|
if (!string.IsNullOrEmpty(inf[0]))
|
|
{
|
|
clog.WriteLogFile("inf[0]:" + inf[0].ToString(), "Loadargs");
|
|
string[] str = inf[0].Split('|');
|
|
clog.WriteLogFile("str.Count():" + str.Count().ToString(), "Loadargs");
|
|
if (str.Count() > 1)
|
|
{
|
|
clog.WriteLogFile("str[0]:" + str[0].ToString(), "Loadargs");
|
|
clog.WriteLogFile("str[1]:" + str[1].ToString(), "Loadargs");
|
|
HttpUrl = str[0];
|
|
LocalIP = str[1];
|
|
configwebsocket = str[2];
|
|
isOnlyScreensaver = str[3];
|
|
info = str[0] + "|" + str[1] + "|" + str[2]+"|"+ str[3];
|
|
clog.WriteLogFile("info:" + info.ToString(), "Loadargs");
|
|
}
|
|
|
|
}
|
|
}
|
|
//if (inf.Count() > 1)
|
|
// update = false;
|
|
}
|
|
VersionUpdate version = new VersionUpdate();
|
|
string currentVersion = string.Empty;
|
|
List<XmlNodeItem> updateList = version.IsUpdate(out currentVersion, "http://"+ HttpUrl + "/update/PCScreen.xml");
|
|
if (updateList.Count>0)
|
|
{
|
|
System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
|
|
//创建Windows用户主题
|
|
System.Windows.Forms.Application.EnableVisualStyles();
|
|
System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
|
|
//判断当前登录用户是否为管理员
|
|
if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
|
|
{
|
|
//创建启动对象
|
|
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
|
|
//设置运行文件
|
|
startInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录
|
|
startInfo.FileName = startInfo.WorkingDirectory + "/PCStart.exe"; //设置启动参数
|
|
startInfo.Arguments = info;
|
|
//设置启动动作,确保以管理员身份运行
|
|
startInfo.Verb = "runas";
|
|
//如果不是管理员,则启动UAC
|
|
//log.WriteLogFile("工作路径:" + startInfo.WorkingDirectory, "APPError");
|
|
System.Diagnostics.Process.Start(startInfo);
|
|
//退出
|
|
System.Windows.Forms.Application.Exit();
|
|
}
|
|
else
|
|
{
|
|
System.Diagnostics.Process p = new System.Diagnostics.Process();
|
|
p.StartInfo.WorkingDirectory = System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"));//设置应用程序在其所在目录
|
|
p.StartInfo.FileName = p.StartInfo.WorkingDirectory + "/PCStart.exe";
|
|
p.StartInfo.Arguments = info;
|
|
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
|
|
p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
|
|
p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
|
|
p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
|
|
p.StartInfo.CreateNoWindow = false;//不显示程序窗口
|
|
p.Start();//启动程序
|
|
}
|
|
Environment.Exit(0);
|
|
}
|
|
//if (e.Args.Count() > 0)
|
|
//{
|
|
// string[] str = e.Args[0].ToString().Split('|');
|
|
|
|
|
|
//}
|
|
this.LoadInitialConfig();
|
|
Class_Config config = new Class_Config();
|
|
config.LoadProgramConfig();
|
|
//MainWindow window = new MainWindow();
|
|
//window.Show();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString());
|
|
}
|
|
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
|
Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
|
|
}
|
|
|
|
public void LoadInitialConfig()
|
|
{
|
|
try
|
|
{
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//Screensaver.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Config");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("Parameter");
|
|
if (xnSecond == null)
|
|
{
|
|
this.TouchType = "";
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (xnSecond.SelectSingleNode("TouchType").InnerText != ""&&isOnlyScreensaver=="0")
|
|
this.TouchType = xnSecond.SelectSingleNode("TouchType").InnerText;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
this.TouchType = "";
|
|
}
|
|
}
|
|
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
log.Error(e.Exception.Message + e.Exception.StackTrace);
|
|
e.Handled = true;
|
|
}
|
|
|
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
Exception ex = (Exception)e.ExceptionObject;
|
|
log.Error(ex.Message + ex.StackTrace);
|
|
}
|
|
private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
|
|
{
|
|
}
|
|
internal int currentIndex = 0;
|
|
internal WindowView view;
|
|
|
|
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
log.Error(e.Exception.Message + e.Exception.StackTrace);
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
|