星火微课系统客户端
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.

App.cs 23KB

4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. using ComeCapture;
  2. using Common.system;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Security.Principal;
  9. using System.Threading;
  10. using System.Windows;
  11. using System.Windows.Threading;
  12. using TStudyDigitalPen.HID;
  13. using XHWK.Model;
  14. using XHWK.WKTool.Helpers;
  15. namespace XHWK.WKTool
  16. {
  17. public partial class APP : Application
  18. {
  19. #region 全局变量
  20. /// <summary>
  21. /// 是否为测试版
  22. /// </summary>
  23. public static bool isDebug =FileToolsCommon.GetConfigValue("IsDebug")!="0";
  24. /// <summary>
  25. /// 接口地址
  26. /// </summary>
  27. public static string apiUrl = isDebug ? "http://schoolapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("APIRequestAddress");
  28. /// <summary>
  29. /// 图片地址
  30. /// </summary>
  31. public static string uploadUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/" : FileToolsCommon.GetConfigValue("FileRequestAddress");
  32. /// <summary>
  33. /// 展示文件
  34. /// </summary>
  35. public static string showImageUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
  36. /// <summary>
  37. /// 认证接口地址
  38. /// </summary>
  39. public static string certapiUrl = isDebug ? "http://certapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("CertapiRequestAddress");
  40. /// <summary>
  41. /// 数据存放目录
  42. /// </summary>
  43. public static string dataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
  44. /// <summary>
  45. /// 后台线程帮助类
  46. /// </summary>
  47. public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
  48. /// <summary>
  49. /// 签名
  50. /// </summary>
  51. public static string Signature = "";
  52. public static string secretKey = "nanhuakaizhangjianwangni";
  53. /// <summary>
  54. /// 用户信息
  55. /// </summary>
  56. public static Model_UserInfo UserInfo = null;
  57. /// <summary>
  58. /// 接口返回消息
  59. /// </summary>
  60. public static string ServerMsg = string.Empty;
  61. /// <summary>
  62. /// 用户微课列表模型
  63. /// </summary>
  64. public static List<Model_WKData> WKDataList = null;
  65. /// <summary>
  66. /// 微课模型
  67. /// </summary>
  68. public static Model_WKData WKData = null;
  69. /// <summary>
  70. /// 微课视频列表
  71. /// </summary>
  72. public static List<Model_Video> VideoList = null;
  73. /// <summary>
  74. /// 画板模型
  75. /// </summary>
  76. public static List<Model_DrawData> PageDrawList = null;
  77. /// <summary>
  78. /// 录屏工具
  79. /// </summary>
  80. public static FFMpeg FFmpeg = new FFMpeg();
  81. /// <summary>
  82. /// 登陆状态 false 未登录 true已登陆
  83. /// </summary>
  84. public static bool IsLoginType = false;
  85. public static readonly Model_Page pageData = new Model.Model_Page();
  86. /// <summary>
  87. /// 防止图片地址重复
  88. /// </summary>
  89. public static long num = 9999;
  90. /// <summary>
  91. /// 导入图片路径
  92. /// </summary>
  93. public static string[] Paths = new string[] { };
  94. /// <summary>
  95. /// 截图图片路径
  96. /// </summary>
  97. public static string[] JPaths = new string[999];
  98. public static string ImgPath = string.Empty;
  99. /// <summary>
  100. /// 页码IP
  101. /// </summary>
  102. public static string[] OutPut = new string[] { };
  103. public static string CameraPosition = string.Empty;
  104. /// <summary>
  105. /// 数据存放目录
  106. /// </summary>
  107. public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
  108. /// <summary>
  109. /// 教材列表
  110. /// </summary>
  111. public static List<Model_TsubjectbookList> TsubjectbookList = null;
  112. /// <summary>
  113. /// 章节列表
  114. /// </summary>
  115. public static List<Model_DirectorList> DirectorList = null;
  116. /// <summary>
  117. /// 上传个人空间 入参
  118. /// </summary>
  119. public static Model_ResourceAddTwo ResourceAddTwo = null;
  120. #region 点阵笔
  121. /// <summary>
  122. /// 点阵笔
  123. /// </summary>
  124. public static DigitalPenHID digitalPen;
  125. /// <summary>
  126. /// 笔序号
  127. /// </summary>
  128. public static string PenSerial;
  129. /// <summary>
  130. /// 笔状态,是否已连接
  131. /// </summary>
  132. public static bool PenStatus;
  133. #endregion
  134. #region 页面
  135. /// <summary>
  136. /// 主页面
  137. /// </summary>
  138. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  139. /// <summary>
  140. /// 创建微课页面
  141. /// </summary>
  142. public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  143. /// <summary>
  144. /// 开始录像
  145. /// </summary>
  146. public static CountdownWindow W_CountdownWindow = null;
  147. /// <summary>
  148. /// 录像工具栏
  149. /// </summary>
  150. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  151. /// <summary>
  152. /// 登陆
  153. /// </summary>
  154. public static LoginWindow W_LoginWindow = null;
  155. /// <summary>
  156. /// 截图
  157. /// </summary>
  158. public static JieTuWindow W_JieTuWindow = null;
  159. /// <summary>
  160. /// 批注
  161. /// </summary>
  162. public static PracticeWindow W_PracticeWindow = null;
  163. /// <summary>
  164. /// 我的视频
  165. /// </summary>
  166. public static FileDirectoryWindow fileDirectoryWindow = null;
  167. /// <summary>
  168. /// 打印
  169. /// </summary>
  170. public static PrintWindow W_PrintWindow = null;
  171. /// <summary>
  172. /// 提示窗口
  173. /// </summary>
  174. public static PromptWindow W_PromptWindow = null;
  175. /// <summary>
  176. /// loding页面
  177. /// </summary>
  178. public static LoadDialog myloading;
  179. /// <summary>
  180. /// 上传页面
  181. /// </summary>
  182. public static UploadWindow W_UploadWindow = null;
  183. #endregion
  184. #endregion
  185. [STAThread]
  186. private static void Main()
  187. {
  188. myloading = new LoadDialog();
  189. StopSameProcess();
  190. Killffmpeg();
  191. LatticeFileHelper.RunPrintConfig();
  192. try
  193. {
  194. UserInfo = new Model_UserInfo();
  195. WKDataList = new List<Model_WKData>();
  196. VideoList = new List<Model_Video>();
  197. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  198. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  199. WindowsPrincipal principal = new WindowsPrincipal(identity);
  200. //判断当前登录用户是否为管理员
  201. //if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  202. //{
  203. // //如果是管理员,则直接运行
  204. // W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  205. // // 定义Application对象作为整个应用程序入口
  206. // Application app = new Application();
  207. // app.Run(W_CreateAMicroLessonWindow);
  208. // //Application.Run(W_CreateAMicroLessonWindow);
  209. //}
  210. //else
  211. //{
  212. // //创建启动对象
  213. // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  214. // {
  215. // UseShellExecute = true,
  216. // WorkingDirectory = Environment.CurrentDirectory,
  217. // FileName = Assembly.GetExecutingAssembly().Location,
  218. // //设置启动动作,确保以管理员身份运行
  219. // Verb = "runas"
  220. // };
  221. // try
  222. // {
  223. // System.Diagnostics.Process.Start(startInfo);
  224. // }
  225. // catch
  226. // {
  227. // return;
  228. // }
  229. // //退出
  230. // //Current.Shutdown();
  231. // Environment.Exit(0);
  232. //}
  233. #endregion
  234. //如果本地文件为空,弹出弹窗 输密匙
  235. //本地文件不为空, 解析
  236. if (!File.Exists(APP.dataPath + "signature.txt"))//上次登陆时间为空 或者签名为空 或者上次登陆时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  237. {
  238. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  239. {
  240. //如果是管理员,则直接运行
  241. KeyVerification wins = new KeyVerification();
  242. // 定义Application对象作为整个应用程序入口
  243. Application app = new Application();
  244. app.Run(wins);
  245. }
  246. else
  247. {
  248. //创建启动对象
  249. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  250. {
  251. UseShellExecute = true,
  252. WorkingDirectory = Environment.CurrentDirectory,
  253. FileName = Assembly.GetExecutingAssembly().Location,
  254. //设置启动动作,确保以管理员身份运行
  255. Verb = "runas"
  256. };
  257. try
  258. {
  259. System.Diagnostics.Process.Start(startInfo);
  260. }
  261. catch
  262. {
  263. return;
  264. }
  265. //退出
  266. //Current.Shutdown();
  267. Environment.Exit(0);
  268. }
  269. }
  270. else
  271. {
  272. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  273. {
  274. ProductVerification wins = new ProductVerification();
  275. Application app = new Application();
  276. app.Run(wins);
  277. }
  278. else
  279. {
  280. //创建启动对象
  281. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  282. {
  283. UseShellExecute = true,
  284. WorkingDirectory = Environment.CurrentDirectory,
  285. FileName = Assembly.GetExecutingAssembly().Location,
  286. //设置启动动作,确保以管理员身份运行
  287. Verb = "runas"
  288. };
  289. try
  290. {
  291. System.Diagnostics.Process.Start(startInfo);
  292. }
  293. catch
  294. {
  295. return;
  296. }
  297. //退出
  298. //Current.Shutdown();
  299. Environment.Exit(0);
  300. }
  301. }
  302. }
  303. catch (Exception ex)
  304. {
  305. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  306. LogHelper.WriteErrLog(ErrMessage, ex);
  307. }
  308. }
  309. #region 杀死已存在的进程
  310. /// <summary>
  311. /// 结束已运行的程序
  312. /// </summary>
  313. private static void StopSameProcess()
  314. {
  315. Process current = Process.GetCurrentProcess();
  316. Process[] processList = Process.GetProcesses();
  317. foreach (Process process in processList)
  318. {
  319. if (process.ProcessName.ToUpper() == "星火微课")
  320. {
  321. if (process.Id != current.Id) //忽略当前进程
  322. {
  323. try
  324. {
  325. process.Kill(); //结束进程
  326. }
  327. catch (Exception)
  328. {
  329. }
  330. }
  331. }
  332. }
  333. }
  334. /// <summary>
  335. /// 杀死正在运行的ffmpeg
  336. /// </summary>
  337. public static void Killffmpeg()
  338. {
  339. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  340. foreach (Process KillProcess in KillProcessArray)
  341. {
  342. KillProcess.Kill();
  343. }
  344. }
  345. #endregion
  346. /// <summary>
  347. /// 错误处理
  348. /// </summary>
  349. /// <param name="sender"></param>
  350. /// <param name="e"></param>
  351. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  352. {
  353. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  354. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  355. e.Handled = true;
  356. }
  357. #region 数据保存和读取
  358. /// <summary>
  359. /// 保存微课信息
  360. /// </summary>
  361. public static void SaveWkData()
  362. {
  363. try
  364. {
  365. WKData.VideoList = VideoList;
  366. if (WKDataList != null)
  367. {
  368. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  369. }
  370. else
  371. {
  372. WKDataList = new List<Model_WKData>();
  373. }
  374. WKDataList.Add(WKData);
  375. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  376. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  377. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  378. FileToolsCommon.CreateDirectory(SavePath);
  379. string SaveName = SavePath + "WkDate.d";
  380. FileToolsCommon.DeleteFile(SaveName);
  381. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  382. }
  383. catch (Exception ex)
  384. {
  385. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  386. }
  387. }
  388. /// <summary>
  389. /// 读取微课信息
  390. /// </summary>
  391. public static void ReadWkData(string WkPath)
  392. {
  393. try
  394. {
  395. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  396. FileToolsCommon.CreateDirectory(SavePath);
  397. string SaveName = SavePath + "WkDate.d";
  398. //文件若存在则读取
  399. if (FileToolsCommon.IsExistFile(SaveName))
  400. {
  401. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  402. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  403. foreach (Model_WKData wklist in WKDataList)
  404. {
  405. //移除找不到视频的微课数据
  406. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  407. }
  408. if (WKDataList.Exists(x => x.WkPath == WkPath))
  409. {
  410. WKData = WKDataList.Find(x => x.WkPath == WkPath);
  411. VideoList = new List<Model_Video>();
  412. VideoList = WKData.VideoList;
  413. }
  414. }
  415. }
  416. catch (Exception ex)
  417. {
  418. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  419. }
  420. }
  421. /// <summary>
  422. /// 保存画板数据
  423. /// </summary>
  424. public static void SaveDraw()
  425. {
  426. try
  427. {
  428. if (PageDrawList == null)
  429. {
  430. return;
  431. }
  432. if (PageDrawList.Count < 1)
  433. {
  434. return;
  435. }
  436. FileToolsCommon.CreateDirectory(WKData.WkPath);
  437. string SavePath = WKData.WkPath + "PageData.d";
  438. FileToolsCommon.DeleteFile(SavePath);
  439. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  440. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  441. }
  442. catch (Exception ex)
  443. {
  444. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  445. }
  446. }
  447. /// <summary>
  448. /// 读取文件
  449. /// </summary>
  450. public static void ReadDrawData()
  451. {
  452. try
  453. {
  454. PageDrawList = new List<Model_DrawData>();
  455. string SavePath = WKData.WkPath + "PageData.d";
  456. if (FileToolsCommon.IsExistFile(SavePath))
  457. {
  458. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  459. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  460. }
  461. }
  462. catch (Exception ex)
  463. {
  464. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  465. }
  466. }
  467. #endregion
  468. #region 检测安装Screen Capturer Recorder
  469. /// <summary>
  470. /// 检测是否安装了Screen Capturer Recorder
  471. /// </summary>
  472. /// <returns></returns>
  473. public static bool CheckScreenCapturerRecorder()
  474. {
  475. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  476. {
  477. //已经安装
  478. return true;
  479. }
  480. else
  481. {
  482. return false;
  483. }
  484. }
  485. /// <summary>
  486. /// 安装Screen Capturer Recorder
  487. /// </summary>
  488. /// <returns></returns>
  489. public static bool InstallScreenCapturerRecorder()
  490. {
  491. Process InstallProcess = new Process();
  492. string StandardError = "";
  493. string StandardOutput = "";
  494. try
  495. {
  496. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  497. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  498. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  499. InstallProcess.StartInfo.RedirectStandardOutput = true;
  500. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  501. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  502. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  503. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  504. InstallProcess.Start(); //启动线程
  505. InstallProcess.WaitForExit(); //阻塞等待进程结束
  506. StandardError = InstallProcess.StandardError.ReadToEnd();
  507. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  508. int ExitCode = InstallProcess.ExitCode;
  509. InstallProcess.Close(); //关闭进程
  510. InstallProcess.Dispose(); //释放资源
  511. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  512. {
  513. return true;
  514. }
  515. else
  516. {
  517. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否重新安装?", "安装", MessageBoxButton.OKCancel);
  518. if (br == MessageBoxResult.OK)
  519. {
  520. return InstallScreenCapturerRecorder();
  521. }
  522. else
  523. {
  524. return false;
  525. }
  526. }
  527. }
  528. catch (Exception ex)
  529. {
  530. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  531. if (string.IsNullOrWhiteSpace(StandardError))
  532. {
  533. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  534. }
  535. if (string.IsNullOrWhiteSpace(StandardOutput))
  536. {
  537. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  538. }
  539. return false;
  540. }
  541. }
  542. /// <summary>
  543. /// 安装失败信息
  544. /// </summary>
  545. /// <param name="sender"></param>
  546. /// <param name="e"></param>
  547. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  548. {
  549. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  550. //MessageWindow.Show(e.Data);
  551. }
  552. #endregion
  553. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  554. /// <summary>
  555. /// 内存释放压缩
  556. /// </summary>
  557. /// <param name="e"></param>
  558. protected override void OnStartup(StartupEventArgs e)
  559. {
  560. //private LierdaCracker cracker = new LierdaCracker();
  561. //cracker.Cracker(5000);//间隔时间
  562. //base.OnStartup(e);
  563. new Thread(o =>
  564. {
  565. while (true)
  566. {
  567. try
  568. {
  569. //FreeMemoryHelper.SetDate();
  570. FreeMemoryHelper.ReallocateMemory();
  571. Thread.Sleep(20000);//暂定每20秒释放一次
  572. }
  573. catch (Exception ex)
  574. {
  575. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  576. }
  577. }
  578. }).Start();
  579. }
  580. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  581. }
  582. }