星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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