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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. /// <summary>
  121. /// 是否正在
  122. /// </summary>
  123. public static bool IsUpLoad = false;
  124. #region 点阵笔
  125. /// <summary>
  126. /// 点阵笔
  127. /// </summary>
  128. public static DigitalPenHID digitalPen;
  129. /// <summary>
  130. /// 笔序号
  131. /// </summary>
  132. public static string PenSerial;
  133. /// <summary>
  134. /// 笔状态,是否已连接
  135. /// </summary>
  136. public static bool PenStatus;
  137. #endregion
  138. #region 页面
  139. /// <summary>
  140. /// 主页面
  141. /// </summary>
  142. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  143. /// <summary>
  144. /// 创建微课页面
  145. /// </summary>
  146. public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  147. /// <summary>
  148. /// 开始录像
  149. /// </summary>
  150. public static CountdownWindow W_CountdownWindow = null;
  151. /// <summary>
  152. /// 录像工具栏
  153. /// </summary>
  154. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  155. /// <summary>
  156. /// 登陆
  157. /// </summary>
  158. public static LoginWindow W_LoginWindow = null;
  159. /// <summary>
  160. /// 截图
  161. /// </summary>
  162. public static JieTuWindow W_JieTuWindow = null;
  163. /// <summary>
  164. /// 批注
  165. /// </summary>
  166. public static PracticeWindow W_PracticeWindow = null;
  167. /// <summary>
  168. /// 我的视频
  169. /// </summary>
  170. public static FileDirectoryWindow fileDirectoryWindow = null;
  171. /// <summary>
  172. /// 打印
  173. /// </summary>
  174. public static PrintWindow W_PrintWindow = null;
  175. /// <summary>
  176. /// 提示窗口
  177. /// </summary>
  178. public static PromptWindow W_PromptWindow = null;
  179. /// <summary>
  180. /// loding页面
  181. /// </summary>
  182. public static LoadDialog myloading;
  183. /// <summary>
  184. /// 上传页面
  185. /// </summary>
  186. public static UploadWindow W_UploadWindow = null;
  187. /// <summary>
  188. /// 最小化工具栏
  189. /// </summary>
  190. public static MinToolbar W_MinToolbar = null;
  191. #endregion
  192. #endregion
  193. [STAThread]
  194. private static void Main()
  195. {
  196. myloading = new LoadDialog();
  197. StopSameProcess();
  198. Killffmpeg();
  199. LatticeFileHelper.RunPrintConfig();
  200. try
  201. {
  202. UserInfo = new Model_UserInfo();
  203. WKDataList = new List<Model_WKData>();
  204. VideoList = new List<Model_Video>();
  205. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  206. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  207. WindowsPrincipal principal = new WindowsPrincipal(identity);
  208. //判断当前登录用户是否为管理员
  209. //if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  210. //{
  211. // //如果是管理员,则直接运行
  212. // W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
  213. // // 定义Application对象作为整个应用程序入口
  214. // Application app = new Application();
  215. // app.Run(W_CreateAMicroLessonWindow);
  216. // //Application.Run(W_CreateAMicroLessonWindow);
  217. //}
  218. //else
  219. //{
  220. // //创建启动对象
  221. // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  222. // {
  223. // UseShellExecute = true,
  224. // WorkingDirectory = Environment.CurrentDirectory,
  225. // FileName = Assembly.GetExecutingAssembly().Location,
  226. // //设置启动动作,确保以管理员身份运行
  227. // Verb = "runas"
  228. // };
  229. // try
  230. // {
  231. // System.Diagnostics.Process.Start(startInfo);
  232. // }
  233. // catch
  234. // {
  235. // return;
  236. // }
  237. // //退出
  238. // //Current.Shutdown();
  239. // Environment.Exit(0);
  240. //}
  241. #endregion
  242. try
  243. {
  244. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))//清除临时文件
  245. {
  246. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
  247. }
  248. }
  249. catch (Exception)
  250. {
  251. }
  252. //如果本地文件为空,弹出弹窗 输密匙
  253. //本地文件不为空, 解析
  254. if (!File.Exists(APP.dataPath + "signature.txt"))//上次登陆时间为空 或者签名为空 或者上次登陆时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  255. {
  256. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  257. {
  258. //如果是管理员,则直接运行
  259. KeyVerification wins = new KeyVerification();
  260. // 定义Application对象作为整个应用程序入口
  261. Application app = new Application();
  262. app.Run(wins);
  263. }
  264. else
  265. {
  266. //创建启动对象
  267. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  268. {
  269. UseShellExecute = true,
  270. WorkingDirectory = Environment.CurrentDirectory,
  271. FileName = Assembly.GetExecutingAssembly().Location,
  272. //设置启动动作,确保以管理员身份运行
  273. Verb = "runas"
  274. };
  275. try
  276. {
  277. System.Diagnostics.Process.Start(startInfo);
  278. }
  279. catch
  280. {
  281. return;
  282. }
  283. //退出
  284. //Current.Shutdown();
  285. Environment.Exit(0);
  286. }
  287. }
  288. else
  289. {
  290. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  291. {
  292. ProductVerification wins = new ProductVerification();
  293. Application app = new Application();
  294. app.Run(wins);
  295. }
  296. else
  297. {
  298. //创建启动对象
  299. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  300. {
  301. UseShellExecute = true,
  302. WorkingDirectory = Environment.CurrentDirectory,
  303. FileName = Assembly.GetExecutingAssembly().Location,
  304. //设置启动动作,确保以管理员身份运行
  305. Verb = "runas"
  306. };
  307. try
  308. {
  309. System.Diagnostics.Process.Start(startInfo);
  310. }
  311. catch
  312. {
  313. return;
  314. }
  315. //退出
  316. //Current.Shutdown();
  317. Environment.Exit(0);
  318. }
  319. }
  320. }
  321. catch (Exception ex)
  322. {
  323. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  324. LogHelper.WriteErrLog(ErrMessage, ex);
  325. }
  326. }
  327. #region 杀死已存在的进程
  328. /// <summary>
  329. /// 结束已运行的程序
  330. /// </summary>
  331. private static void StopSameProcess()
  332. {
  333. Process current = Process.GetCurrentProcess();
  334. Process[] processList = Process.GetProcesses();
  335. foreach (Process process in processList)
  336. {
  337. if (process.ProcessName.ToUpper() == "星火微课")
  338. {
  339. if (process.Id != current.Id) //忽略当前进程
  340. {
  341. try
  342. {
  343. process.Kill(); //结束进程
  344. }
  345. catch (Exception)
  346. {
  347. }
  348. }
  349. }
  350. }
  351. }
  352. /// <summary>
  353. /// 杀死正在运行的ffmpeg
  354. /// </summary>
  355. public static void Killffmpeg()
  356. {
  357. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  358. foreach (Process KillProcess in KillProcessArray)
  359. {
  360. KillProcess.Kill();
  361. }
  362. }
  363. #endregion
  364. /// <summary>
  365. /// 错误处理
  366. /// </summary>
  367. /// <param name="sender"></param>
  368. /// <param name="e"></param>
  369. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  370. {
  371. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  372. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  373. e.Handled = true;
  374. }
  375. #region 数据保存和读取
  376. /// <summary>
  377. /// 保存微课信息
  378. /// </summary>
  379. public static void SaveWkData()
  380. {
  381. try
  382. {
  383. WKData.VideoList = VideoList;
  384. if (WKDataList != null)
  385. {
  386. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  387. }
  388. else
  389. {
  390. WKDataList = new List<Model_WKData>();
  391. }
  392. WKDataList.Add(WKData);
  393. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  394. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  395. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  396. FileToolsCommon.CreateDirectory(SavePath);
  397. string SaveName = SavePath + "WkDate.d";
  398. FileToolsCommon.DeleteFile(SaveName);
  399. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  400. }
  401. catch (Exception ex)
  402. {
  403. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  404. }
  405. }
  406. /// <summary>
  407. /// 读取微课信息
  408. /// </summary>
  409. public static void ReadWkData(string WkPath)
  410. {
  411. try
  412. {
  413. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  414. FileToolsCommon.CreateDirectory(SavePath);
  415. string SaveName = SavePath + "WkDate.d";
  416. //文件若存在则读取
  417. if (FileToolsCommon.IsExistFile(SaveName))
  418. {
  419. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  420. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  421. foreach (Model_WKData wklist in WKDataList)
  422. {
  423. //移除找不到视频的微课数据
  424. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  425. }
  426. if (WKDataList.Exists(x => x.WkPath == WkPath))
  427. {
  428. WKData = WKDataList.Find(x => x.WkPath == WkPath);
  429. VideoList = new List<Model_Video>();
  430. VideoList = WKData.VideoList;
  431. }
  432. }
  433. }
  434. catch (Exception ex)
  435. {
  436. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  437. }
  438. }
  439. /// <summary>
  440. /// 保存画板数据
  441. /// </summary>
  442. public static void SaveDraw()
  443. {
  444. try
  445. {
  446. if (PageDrawList == null)
  447. {
  448. return;
  449. }
  450. if (PageDrawList.Count < 1)
  451. {
  452. return;
  453. }
  454. FileToolsCommon.CreateDirectory(WKData.WkPath);
  455. string SavePath = WKData.WkPath + "PageData.d";
  456. FileToolsCommon.DeleteFile(SavePath);
  457. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  458. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  459. }
  460. catch (Exception ex)
  461. {
  462. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  463. }
  464. }
  465. /// <summary>
  466. /// 读取文件
  467. /// </summary>
  468. public static void ReadDrawData()
  469. {
  470. try
  471. {
  472. PageDrawList = new List<Model_DrawData>();
  473. string SavePath = WKData.WkPath + "PageData.d";
  474. if (FileToolsCommon.IsExistFile(SavePath))
  475. {
  476. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  477. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  478. }
  479. }
  480. catch (Exception ex)
  481. {
  482. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  483. }
  484. }
  485. #endregion
  486. #region 检测安装Screen Capturer Recorder
  487. /// <summary>
  488. /// 检测是否安装了Screen Capturer Recorder
  489. /// </summary>
  490. /// <returns></returns>
  491. public static bool CheckScreenCapturerRecorder()
  492. {
  493. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  494. {
  495. //已经安装
  496. return true;
  497. }
  498. else
  499. {
  500. return false;
  501. }
  502. }
  503. /// <summary>
  504. /// 安装Screen Capturer Recorder
  505. /// </summary>
  506. /// <returns></returns>
  507. public static bool InstallScreenCapturerRecorder()
  508. {
  509. Process InstallProcess = new Process();
  510. string StandardError = "";
  511. string StandardOutput = "";
  512. try
  513. {
  514. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/SSCR/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  515. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  516. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  517. InstallProcess.StartInfo.RedirectStandardOutput = true;
  518. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  519. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  520. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  521. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  522. InstallProcess.Start(); //启动线程
  523. InstallProcess.WaitForExit(); //阻塞等待进程结束
  524. StandardError = InstallProcess.StandardError.ReadToEnd();
  525. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  526. int ExitCode = InstallProcess.ExitCode;
  527. InstallProcess.Close(); //关闭进程
  528. InstallProcess.Dispose(); //释放资源
  529. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  530. {
  531. return true;
  532. }
  533. else
  534. {
  535. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否现在安装?", "安装", MessageBoxButton.OKCancel);
  536. if (br == MessageBoxResult.OK)
  537. {
  538. return InstallScreenCapturerRecorder();
  539. }
  540. else
  541. {
  542. return false;
  543. }
  544. }
  545. }
  546. catch (Exception ex)
  547. {
  548. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  549. if (string.IsNullOrWhiteSpace(StandardError))
  550. {
  551. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  552. }
  553. if (string.IsNullOrWhiteSpace(StandardOutput))
  554. {
  555. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  556. }
  557. return false;
  558. }
  559. }
  560. /// <summary>
  561. /// 安装失败信息
  562. /// </summary>
  563. /// <param name="sender"></param>
  564. /// <param name="e"></param>
  565. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  566. {
  567. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  568. //MessageWindow.Show(e.Data);
  569. }
  570. #endregion
  571. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  572. /// <summary>
  573. /// 内存释放压缩
  574. /// </summary>
  575. /// <param name="e"></param>
  576. protected override void OnStartup(StartupEventArgs e)
  577. {
  578. //private LierdaCracker cracker = new LierdaCracker();
  579. //cracker.Cracker(5000);//间隔时间
  580. //base.OnStartup(e);
  581. new Thread(o =>
  582. {
  583. while (true)
  584. {
  585. try
  586. {
  587. //FreeMemoryHelper.SetDate();
  588. FreeMemoryHelper.ReallocateMemory();
  589. Thread.Sleep(20000);//暂定每20秒释放一次
  590. }
  591. catch (Exception ex)
  592. {
  593. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  594. }
  595. }
  596. }).Start();
  597. }
  598. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  599. }
  600. }