|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- using ComeCapture;
-
- using Common.system;
-
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Reflection;
- using System.Security.Principal;
- using System.Threading;
- using System.Windows;
- using System.Windows.Threading;
-
- using TStudyDigitalPen.HID;
-
- using XHWK.Model;
- using XHWK.WKTool.Helpers;
-
- namespace XHWK.WKTool
- {
- public partial class APP : Application
- {
- #region 全局变量
- /// <summary>
- /// 是否为测试版
- /// </summary>
- public static bool isDebug =FileToolsCommon.GetConfigValue("IsDebug")!="0";
- /// <summary>
- /// 接口地址
- /// </summary>
- public static string apiUrl = isDebug ? "http://schoolapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("APIRequestAddress");
- /// <summary>
- /// 图片地址
- /// </summary>
- public static string uploadUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/" : FileToolsCommon.GetConfigValue("FileRequestAddress");
- /// <summary>
- /// 展示文件
- /// </summary>
- public static string showImageUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
- /// <summary>
- /// 认证接口地址
- /// </summary>
- public static string certapiUrl = isDebug ? "http://certapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("CertapiRequestAddress");
- /// <summary>
- /// 数据存放目录
- /// </summary>
- public static string dataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
- /// <summary>
- /// 后台线程帮助类
- /// </summary>
- public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
- /// <summary>
- /// 签名
- /// </summary>
- public static string Signature = "";
- public static string secretKey = "nanhuakaizhangjianwangni";
- /// <summary>
- /// 用户信息
- /// </summary>
- public static Model_UserInfo UserInfo = null;
- /// <summary>
- /// 接口返回消息
- /// </summary>
- public static string ServerMsg = string.Empty;
- /// <summary>
- /// 用户微课列表模型
- /// </summary>
- public static List<Model_WKData> WKDataList = null;
- /// <summary>
- /// 微课模型
- /// </summary>
- public static Model_WKData WKData = null;
- /// <summary>
- /// 微课视频列表
- /// </summary>
- public static List<Model_Video> VideoList = null;
- /// <summary>
- /// 画板模型
- /// </summary>
- public static List<Model_DrawData> PageDrawList = null;
- /// <summary>
- /// 录屏工具
- /// </summary>
- public static FFMpeg FFmpeg = new FFMpeg();
- /// <summary>
- /// 登陆状态 false 未登录 true已登陆
- /// </summary>
- public static bool IsLoginType = false;
- public static readonly Model_Page pageData = new Model.Model_Page();
- /// <summary>
- /// 防止图片地址重复
- /// </summary>
- public static long num = 9999;
- /// <summary>
- /// 导入图片路径
- /// </summary>
- public static string[] Paths = new string[] { };
- /// <summary>
- /// 截图图片路径
- /// </summary>
- public static string[] JPaths = new string[999];
- public static string ImgPath = string.Empty;
- /// <summary>
- /// 页码IP
- /// </summary>
- public static string[] OutPut = new string[] { };
- public static string CameraPosition = string.Empty;
- /// <summary>
- /// 数据存放目录
- /// </summary>
- public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
- /// <summary>
- /// 教材列表
- /// </summary>
- public static List<Model_TsubjectbookList> TsubjectbookList = null;
- /// <summary>
- /// 章节列表
- /// </summary>
- public static List<Model_DirectorList> DirectorList = null;
- /// <summary>
- /// 上传个人空间 入参
- /// </summary>
- public static Model_ResourceAddTwo ResourceAddTwo = null;
- /// <summary>
- /// 是否正在
- /// </summary>
- public static bool IsUpLoad = false;
- #region 点阵笔
- /// <summary>
- /// 点阵笔
- /// </summary>
- public static DigitalPenHID digitalPen;
- /// <summary>
- /// 笔序号
- /// </summary>
- public static string PenSerial;
- /// <summary>
- /// 笔状态,是否已连接
- /// </summary>
- public static bool PenStatus;
- #endregion
- #region 页面
- /// <summary>
- /// 主页面
- /// </summary>
- public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
- /// <summary>
- /// 创建微课页面
- /// </summary>
- public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
- /// <summary>
- /// 开始录像
- /// </summary>
- public static CountdownWindow W_CountdownWindow = null;
- /// <summary>
- /// 录像工具栏
- /// </summary>
- public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
- /// <summary>
- /// 登陆
- /// </summary>
- public static LoginWindow W_LoginWindow = null;
- /// <summary>
- /// 截图
- /// </summary>
- public static JieTuWindow W_JieTuWindow = null;
- /// <summary>
- /// 批注
- /// </summary>
- public static PracticeWindow W_PracticeWindow = null;
- /// <summary>
- /// 我的视频
- /// </summary>
- public static FileDirectoryWindow fileDirectoryWindow = null;
- /// <summary>
- /// 打印
- /// </summary>
- public static PrintWindow W_PrintWindow = null;
- /// <summary>
- /// 提示窗口
- /// </summary>
- public static PromptWindow W_PromptWindow = null;
- /// <summary>
- /// loding页面
- /// </summary>
- public static LoadDialog myloading;
- /// <summary>
- /// 上传页面
- /// </summary>
- public static UploadWindow W_UploadWindow = null;
- #endregion
- #endregion
-
- [STAThread]
- private static void Main()
- {
- myloading = new LoadDialog();
- StopSameProcess();
- Killffmpeg();
- LatticeFileHelper.RunPrintConfig();
- try
- {
- UserInfo = new Model_UserInfo();
- WKDataList = new List<Model_WKData>();
- VideoList = new List<Model_Video>();
- #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
- WindowsIdentity identity = WindowsIdentity.GetCurrent();
- WindowsPrincipal principal = new WindowsPrincipal(identity);
- //判断当前登录用户是否为管理员
- //if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- //{
- // //如果是管理员,则直接运行
- // W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
- // // 定义Application对象作为整个应用程序入口
- // Application app = new Application();
- // app.Run(W_CreateAMicroLessonWindow);
- // //Application.Run(W_CreateAMicroLessonWindow);
- //}
- //else
- //{
- // //创建启动对象
- // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
- // {
- // UseShellExecute = true,
- // WorkingDirectory = Environment.CurrentDirectory,
- // FileName = Assembly.GetExecutingAssembly().Location,
- // //设置启动动作,确保以管理员身份运行
- // Verb = "runas"
- // };
- // try
- // {
- // System.Diagnostics.Process.Start(startInfo);
- // }
- // catch
- // {
- // return;
- // }
- // //退出
- // //Current.Shutdown();
- // Environment.Exit(0);
-
- //}
- #endregion
-
- try
- {
- if(Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+"temp"))//清除临时文件
- {
- Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp",true);
- }
- }
- catch (Exception)
- {
- }
-
- //如果本地文件为空,弹出弹窗 输密匙
- //本地文件不为空, 解析
- if (!File.Exists(APP.dataPath + "signature.txt"))//上次登陆时间为空 或者签名为空 或者上次登陆时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
- {
- if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- {
- //如果是管理员,则直接运行
- KeyVerification wins = new KeyVerification();
- // 定义Application对象作为整个应用程序入口
- Application app = new Application();
- app.Run(wins);
- }
- else
- {
- //创建启动对象
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
- {
- UseShellExecute = true,
- WorkingDirectory = Environment.CurrentDirectory,
- FileName = Assembly.GetExecutingAssembly().Location,
- //设置启动动作,确保以管理员身份运行
- Verb = "runas"
- };
- try
- {
- System.Diagnostics.Process.Start(startInfo);
- }
- catch
- {
- return;
- }
- //退出
- //Current.Shutdown();
- Environment.Exit(0);
-
- }
- }
- else
- {
- if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- {
- ProductVerification wins = new ProductVerification();
- Application app = new Application();
- app.Run(wins);
- }
- else
- {
- //创建启动对象
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
- {
- UseShellExecute = true,
- WorkingDirectory = Environment.CurrentDirectory,
- FileName = Assembly.GetExecutingAssembly().Location,
- //设置启动动作,确保以管理员身份运行
- Verb = "runas"
- };
- try
- {
- System.Diagnostics.Process.Start(startInfo);
- }
- catch
- {
- return;
- }
- //退出
- //Current.Shutdown();
- Environment.Exit(0);
-
- }
- }
- }
- catch (Exception ex)
- {
-
- string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- }
- }
-
- #region 杀死已存在的进程
- /// <summary>
- /// 结束已运行的程序
- /// </summary>
- private static void StopSameProcess()
- {
- Process current = Process.GetCurrentProcess();
- Process[] processList = Process.GetProcesses();
- foreach (Process process in processList)
- {
- if (process.ProcessName.ToUpper() == "星火微课")
- {
- if (process.Id != current.Id) //忽略当前进程
- {
- try
- {
- process.Kill(); //结束进程
- }
- catch (Exception)
- {
- }
- }
- }
- }
- }
- /// <summary>
- /// 杀死正在运行的ffmpeg
- /// </summary>
- public static void Killffmpeg()
- {
- Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
- foreach (Process KillProcess in KillProcessArray)
- {
- KillProcess.Kill();
- }
- }
- #endregion
-
- /// <summary>
- /// 错误处理
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
- MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
- e.Handled = true;
- }
-
- #region 数据保存和读取
- /// <summary>
- /// 保存微课信息
- /// </summary>
- public static void SaveWkData()
- {
- try
- {
- WKData.VideoList = VideoList;
- if (WKDataList != null)
- {
- WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
- }
- else
- {
- WKDataList = new List<Model_WKData>();
- }
- WKDataList.Add(WKData);
- //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
- string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
- string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
- FileToolsCommon.CreateDirectory(SavePath);
- string SaveName = SavePath + "WkDate.d";
- FileToolsCommon.DeleteFile(SaveName);
- FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 读取微课信息
- /// </summary>
- public static void ReadWkData(string WkPath)
- {
- try
- {
- string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
- FileToolsCommon.CreateDirectory(SavePath);
- string SaveName = SavePath + "WkDate.d";
- //文件若存在则读取
- if (FileToolsCommon.IsExistFile(SaveName))
- {
- string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
- WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
- foreach (Model_WKData wklist in WKDataList)
- {
- //移除找不到视频的微课数据
- wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
- }
- if (WKDataList.Exists(x => x.WkPath == WkPath))
- {
- WKData = WKDataList.Find(x => x.WkPath == WkPath);
- VideoList = new List<Model_Video>();
- VideoList = WKData.VideoList;
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 保存画板数据
- /// </summary>
- public static void SaveDraw()
- {
- try
- {
- if (PageDrawList == null)
- {
- return;
- }
- if (PageDrawList.Count < 1)
- {
- return;
- }
- FileToolsCommon.CreateDirectory(WKData.WkPath);
- string SavePath = WKData.WkPath + "PageData.d";
- FileToolsCommon.DeleteFile(SavePath);
- string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
- FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 读取文件
- /// </summary>
- public static void ReadDrawData()
- {
- try
- {
- PageDrawList = new List<Model_DrawData>();
- string SavePath = WKData.WkPath + "PageData.d";
- if (FileToolsCommon.IsExistFile(SavePath))
- {
- string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
- PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
- }
- }
- #endregion
-
- #region 检测安装Screen Capturer Recorder
- /// <summary>
- /// 检测是否安装了Screen Capturer Recorder
- /// </summary>
- /// <returns></returns>
- public static bool CheckScreenCapturerRecorder()
- {
- if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
- {
- //已经安装
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 安装Screen Capturer Recorder
- /// </summary>
- /// <returns></returns>
- public static bool InstallScreenCapturerRecorder()
- {
- Process InstallProcess = new Process();
- string StandardError = "";
- string StandardOutput = "";
- try
- {
- InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
- InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
- InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
- InstallProcess.StartInfo.RedirectStandardOutput = true;
- InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
- InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
- //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
- InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
- InstallProcess.Start(); //启动线程
- InstallProcess.WaitForExit(); //阻塞等待进程结束
- StandardError = InstallProcess.StandardError.ReadToEnd();
- StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
- int ExitCode = InstallProcess.ExitCode;
- InstallProcess.Close(); //关闭进程
- InstallProcess.Dispose(); //释放资源
- if (ExitCode == 0) //非0则为安装失败 1为取消安装
- {
- return true;
- }
- else
- {
- MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否重新安装?", "安装", MessageBoxButton.OKCancel);
- if (br == MessageBoxResult.OK)
- {
- return InstallScreenCapturerRecorder();
- }
- else
- {
- return false;
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
- if (string.IsNullOrWhiteSpace(StandardError))
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
- }
- if (string.IsNullOrWhiteSpace(StandardOutput))
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
- }
- return false;
- }
- }
- /// <summary>
- /// 安装失败信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
- //MessageWindow.Show(e.Data);
- }
-
- #endregion
- #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
-
- /// <summary>
- /// 内存释放压缩
- /// </summary>
- /// <param name="e"></param>
- protected override void OnStartup(StartupEventArgs e)
- {
- //private LierdaCracker cracker = new LierdaCracker();
- //cracker.Cracker(5000);//间隔时间
- //base.OnStartup(e);
- new Thread(o =>
- {
- while (true)
- {
- try
- {
- //FreeMemoryHelper.SetDate();
- FreeMemoryHelper.ReallocateMemory();
- Thread.Sleep(20000);//暂定每20秒释放一次
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
- }
- }
- }).Start();
- }
-
- #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
- }
- }
|