星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. try
  235. {
  236. if(Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+"temp"))//清除临时文件
  237. {
  238. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp",true);
  239. }
  240. }
  241. catch (Exception ex)
  242. {
  243. }
  244. //如果本地文件为空,弹出弹窗 输密匙
  245. //本地文件不为空, 解析
  246. if (!File.Exists(APP.dataPath + "signature.txt"))//上次登陆时间为空 或者签名为空 或者上次登陆时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  247. {
  248. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  249. {
  250. //如果是管理员,则直接运行
  251. KeyVerification wins = new KeyVerification();
  252. // 定义Application对象作为整个应用程序入口
  253. Application app = new Application();
  254. app.Run(wins);
  255. }
  256. else
  257. {
  258. //创建启动对象
  259. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  260. {
  261. UseShellExecute = true,
  262. WorkingDirectory = Environment.CurrentDirectory,
  263. FileName = Assembly.GetExecutingAssembly().Location,
  264. //设置启动动作,确保以管理员身份运行
  265. Verb = "runas"
  266. };
  267. try
  268. {
  269. System.Diagnostics.Process.Start(startInfo);
  270. }
  271. catch
  272. {
  273. return;
  274. }
  275. //退出
  276. //Current.Shutdown();
  277. Environment.Exit(0);
  278. }
  279. }
  280. else
  281. {
  282. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  283. {
  284. ProductVerification wins = new ProductVerification();
  285. Application app = new Application();
  286. app.Run(wins);
  287. }
  288. else
  289. {
  290. //创建启动对象
  291. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  292. {
  293. UseShellExecute = true,
  294. WorkingDirectory = Environment.CurrentDirectory,
  295. FileName = Assembly.GetExecutingAssembly().Location,
  296. //设置启动动作,确保以管理员身份运行
  297. Verb = "runas"
  298. };
  299. try
  300. {
  301. System.Diagnostics.Process.Start(startInfo);
  302. }
  303. catch
  304. {
  305. return;
  306. }
  307. //退出
  308. //Current.Shutdown();
  309. Environment.Exit(0);
  310. }
  311. }
  312. }
  313. catch (Exception ex)
  314. {
  315. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  316. LogHelper.WriteErrLog(ErrMessage, ex);
  317. }
  318. }
  319. #region 杀死已存在的进程
  320. /// <summary>
  321. /// 结束已运行的程序
  322. /// </summary>
  323. private static void StopSameProcess()
  324. {
  325. Process current = Process.GetCurrentProcess();
  326. Process[] processList = Process.GetProcesses();
  327. foreach (Process process in processList)
  328. {
  329. if (process.ProcessName.ToUpper() == "星火微课")
  330. {
  331. if (process.Id != current.Id) //忽略当前进程
  332. {
  333. try
  334. {
  335. process.Kill(); //结束进程
  336. }
  337. catch (Exception)
  338. {
  339. }
  340. }
  341. }
  342. }
  343. }
  344. /// <summary>
  345. /// 杀死正在运行的ffmpeg
  346. /// </summary>
  347. public static void Killffmpeg()
  348. {
  349. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  350. foreach (Process KillProcess in KillProcessArray)
  351. {
  352. KillProcess.Kill();
  353. }
  354. }
  355. #endregion
  356. /// <summary>
  357. /// 错误处理
  358. /// </summary>
  359. /// <param name="sender"></param>
  360. /// <param name="e"></param>
  361. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  362. {
  363. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  364. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  365. e.Handled = true;
  366. }
  367. #region 数据保存和读取
  368. /// <summary>
  369. /// 保存微课信息
  370. /// </summary>
  371. public static void SaveWkData()
  372. {
  373. try
  374. {
  375. WKData.VideoList = VideoList;
  376. if (WKDataList != null)
  377. {
  378. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  379. }
  380. else
  381. {
  382. WKDataList = new List<Model_WKData>();
  383. }
  384. WKDataList.Add(WKData);
  385. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  386. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  387. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  388. FileToolsCommon.CreateDirectory(SavePath);
  389. string SaveName = SavePath + "WkDate.d";
  390. FileToolsCommon.DeleteFile(SaveName);
  391. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  392. }
  393. catch (Exception ex)
  394. {
  395. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  396. }
  397. }
  398. /// <summary>
  399. /// 读取微课信息
  400. /// </summary>
  401. public static void ReadWkData(string WkPath)
  402. {
  403. try
  404. {
  405. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  406. FileToolsCommon.CreateDirectory(SavePath);
  407. string SaveName = SavePath + "WkDate.d";
  408. //文件若存在则读取
  409. if (FileToolsCommon.IsExistFile(SaveName))
  410. {
  411. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  412. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  413. foreach (Model_WKData wklist in WKDataList)
  414. {
  415. //移除找不到视频的微课数据
  416. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  417. }
  418. if (WKDataList.Exists(x => x.WkPath == WkPath))
  419. {
  420. WKData = WKDataList.Find(x => x.WkPath == WkPath);
  421. VideoList = new List<Model_Video>();
  422. VideoList = WKData.VideoList;
  423. }
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  429. }
  430. }
  431. /// <summary>
  432. /// 保存画板数据
  433. /// </summary>
  434. public static void SaveDraw()
  435. {
  436. try
  437. {
  438. if (PageDrawList == null)
  439. {
  440. return;
  441. }
  442. if (PageDrawList.Count < 1)
  443. {
  444. return;
  445. }
  446. FileToolsCommon.CreateDirectory(WKData.WkPath);
  447. string SavePath = WKData.WkPath + "PageData.d";
  448. FileToolsCommon.DeleteFile(SavePath);
  449. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  450. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  451. }
  452. catch (Exception ex)
  453. {
  454. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  455. }
  456. }
  457. /// <summary>
  458. /// 读取文件
  459. /// </summary>
  460. public static void ReadDrawData()
  461. {
  462. try
  463. {
  464. PageDrawList = new List<Model_DrawData>();
  465. string SavePath = WKData.WkPath + "PageData.d";
  466. if (FileToolsCommon.IsExistFile(SavePath))
  467. {
  468. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  469. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  470. }
  471. }
  472. catch (Exception ex)
  473. {
  474. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  475. }
  476. }
  477. #endregion
  478. #region 检测安装Screen Capturer Recorder
  479. /// <summary>
  480. /// 检测是否安装了Screen Capturer Recorder
  481. /// </summary>
  482. /// <returns></returns>
  483. public static bool CheckScreenCapturerRecorder()
  484. {
  485. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  486. {
  487. //已经安装
  488. return true;
  489. }
  490. else
  491. {
  492. return false;
  493. }
  494. }
  495. /// <summary>
  496. /// 安装Screen Capturer Recorder
  497. /// </summary>
  498. /// <returns></returns>
  499. public static bool InstallScreenCapturerRecorder()
  500. {
  501. Process InstallProcess = new Process();
  502. string StandardError = "";
  503. string StandardOutput = "";
  504. try
  505. {
  506. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  507. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  508. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  509. InstallProcess.StartInfo.RedirectStandardOutput = true;
  510. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  511. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  512. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  513. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  514. InstallProcess.Start(); //启动线程
  515. InstallProcess.WaitForExit(); //阻塞等待进程结束
  516. StandardError = InstallProcess.StandardError.ReadToEnd();
  517. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  518. int ExitCode = InstallProcess.ExitCode;
  519. InstallProcess.Close(); //关闭进程
  520. InstallProcess.Dispose(); //释放资源
  521. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  522. {
  523. return true;
  524. }
  525. else
  526. {
  527. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否重新安装?", "安装", MessageBoxButton.OKCancel);
  528. if (br == MessageBoxResult.OK)
  529. {
  530. return InstallScreenCapturerRecorder();
  531. }
  532. else
  533. {
  534. return false;
  535. }
  536. }
  537. }
  538. catch (Exception ex)
  539. {
  540. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  541. if (string.IsNullOrWhiteSpace(StandardError))
  542. {
  543. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  544. }
  545. if (string.IsNullOrWhiteSpace(StandardOutput))
  546. {
  547. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  548. }
  549. return false;
  550. }
  551. }
  552. /// <summary>
  553. /// 安装失败信息
  554. /// </summary>
  555. /// <param name="sender"></param>
  556. /// <param name="e"></param>
  557. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  558. {
  559. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  560. //MessageWindow.Show(e.Data);
  561. }
  562. #endregion
  563. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  564. /// <summary>
  565. /// 内存释放压缩
  566. /// </summary>
  567. /// <param name="e"></param>
  568. protected override void OnStartup(StartupEventArgs e)
  569. {
  570. //private LierdaCracker cracker = new LierdaCracker();
  571. //cracker.Cracker(5000);//间隔时间
  572. //base.OnStartup(e);
  573. new Thread(o =>
  574. {
  575. while (true)
  576. {
  577. try
  578. {
  579. //FreeMemoryHelper.SetDate();
  580. FreeMemoryHelper.ReallocateMemory();
  581. Thread.Sleep(20000);//暂定每20秒释放一次
  582. }
  583. catch (Exception ex)
  584. {
  585. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  586. }
  587. }
  588. }).Start();
  589. }
  590. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  591. }
  592. }