星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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.Linq;
  8. using System.Reflection;
  9. using System.Security.Principal;
  10. using System.Threading;
  11. using System.Windows;
  12. using System.Windows.Threading;
  13. using TStudyDigitalPen.HID;
  14. using XHWK.Model;
  15. using XHWK.WKTool.Helpers;
  16. using XHWK.WKTool.Skin;
  17. namespace XHWK.WKTool
  18. {
  19. public partial class APP : Application
  20. {
  21. #region 全局变量
  22. #region 更新需改动
  23. /// <summary>
  24. /// 是否为测试版
  25. /// </summary>
  26. public static bool isDebug = FileToolsCommon.GetConfigValue("IsDebug") != "0";
  27. /// <summary>
  28. /// 参数是否加密
  29. /// </summary>
  30. public static bool IsParameterEncryption = FileToolsCommon.GetConfigValue("IsParameterEncryption") != "0";
  31. #endregion 更新需改动
  32. #region 接口地址
  33. /// <summary>
  34. /// 是否为校外接口
  35. /// </summary>
  36. public static bool IsOutsideSchool = FileToolsCommon.GetConfigValue("IsOutsideSchool") == "1";
  37. /// <summary>
  38. /// 服务地址
  39. /// </summary>
  40. public static Model_ServiceAddress ServiceAddress = null;
  41. /// <summary>
  42. /// 接口地址
  43. /// </summary>
  44. public static string apiUrl = isDebug ? "http://schoolapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("APIRequestAddress");
  45. /// <summary>
  46. /// 图片地址
  47. /// </summary>
  48. public static string uploadUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/" : FileToolsCommon.GetConfigValue("FileRequestAddress");
  49. /// <summary>
  50. /// 展示文件
  51. /// </summary>
  52. public static string showImageUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
  53. /// <summary>
  54. /// 认证接口地址
  55. /// </summary>
  56. public static string certapiUrl = isDebug ? "http://certapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("CertapiRequestAddress");
  57. #endregion 接口地址
  58. #region 配置项
  59. /// <summary>
  60. /// 是否输出测试记录日志
  61. /// </summary>
  62. public static bool IsOutputInfoLog = FileToolsCommon.GetConfigValue("IsOutputInfoLog") != "0";
  63. /// <summary>
  64. /// 是否隐藏录屏工具栏
  65. /// </summary>
  66. public static bool IsHideSRTool = FileToolsCommon.GetConfigValue("IsHideSRTool") != "0";
  67. /// <summary>
  68. /// 皮肤样式 0白 1蓝 2黑色
  69. /// </summary>
  70. public static string SkinStyle = FileToolsCommon.GetConfigValue("SkinStyle");
  71. /// <summary>
  72. /// 数据存放目录
  73. /// </summary>
  74. public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHMicroLesson\\";
  75. /// <summary>
  76. /// 摄像头位置
  77. /// </summary>
  78. public static string CameraPosition = string.Empty;
  79. /// <summary>
  80. /// 摄像头名
  81. /// </summary>
  82. public static string CameraName = "";
  83. /// <summary>
  84. /// 麦克风名
  85. /// </summary>
  86. public static string MicrophoneName = "";
  87. #endregion 配置项
  88. #region 记录数据
  89. /// <summary>
  90. /// 全局页面数据变量
  91. /// </summary>
  92. public static readonly Model_Page PageContextData = new Model.Model_Page();
  93. /// <summary>
  94. /// 录屏工具
  95. /// </summary>
  96. public static FFMpeg FFmpeg = new FFMpeg();
  97. /// <summary>
  98. /// 后台线程帮助类
  99. /// </summary>
  100. public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
  101. /// <summary>
  102. /// 签名
  103. /// </summary>
  104. public static string Signature = "";
  105. public static string secretKey = "nanhuakaizhangjianwangni";
  106. /// <summary>
  107. /// 用户信息
  108. /// </summary>
  109. public static Model_UserInfo UserInfo = null;
  110. /// <summary>
  111. /// 接口返回消息
  112. /// </summary>
  113. public static string ServerMsg = string.Empty;
  114. /// <summary>
  115. /// 登录状态 false 未登录 true已登录
  116. /// </summary>
  117. public static bool IsLoginType = false;
  118. /// <summary>
  119. /// 截图地址
  120. /// </summary>
  121. public static string ImgPath = string.Empty;
  122. /// <summary>
  123. /// 教材列表
  124. /// </summary>
  125. public static List<Model_TsubjectbookList> TsubjectbookList = null;
  126. /// <summary>
  127. /// 章节列表
  128. /// </summary>
  129. public static List<Model_DirectorList> DirectorList = null;
  130. /// <summary>
  131. /// 上传个人空间 入参
  132. /// </summary>
  133. public static Model_ResourceAddTwo ResourceAddTwo = null;
  134. /// <summary>
  135. /// 是否正在上传
  136. /// </summary>
  137. public static bool IsUpLoad = false;
  138. #endregion 记录数据
  139. #region 微课数据记录
  140. /// <summary>
  141. /// 用户微课列表模型
  142. /// </summary>
  143. public static List<Model_WKData> WKDataList = null;
  144. /// <summary>
  145. /// 微课模型
  146. /// </summary>
  147. public static Model_WKData WKData = null;
  148. /// <summary>
  149. /// 微课视频列表
  150. /// </summary>
  151. public static List<Model_Video> VideoList = null;
  152. /// <summary>
  153. /// 画板模型
  154. /// </summary>
  155. public static List<Model_DrawData> PageDrawList = null;
  156. #endregion 微课数据记录
  157. #region 点阵笔
  158. /// <summary>
  159. /// 点阵笔
  160. /// </summary>
  161. public static DigitalPenHID digitalPen;
  162. /// <summary>
  163. /// 笔序号
  164. /// </summary>
  165. public static string PenSerial;
  166. /// <summary>
  167. /// 笔状态,是否已连接
  168. /// </summary>
  169. public static bool PenStatus = false;
  170. /// <summary>
  171. /// 手写板状态,是否已连接
  172. /// </summary>
  173. public static bool BoardStatus = false;
  174. #endregion 点阵笔
  175. #region 腾千里手写笔
  176. ///// <summary>
  177. ///// 铺码服务请求
  178. ///// </summary>
  179. //public static DAL_TmatrixCode dAL_TmatrixCode;
  180. /// <summary>
  181. /// 腾千里手写笔事件
  182. /// </summary>
  183. public static PenEvents TQLPenevents;
  184. /// <summary>
  185. /// 腾千里手写笔是否已连接
  186. /// </summary>
  187. public static bool TQLPenStatus = false;
  188. #region 打印
  189. public static bool gbGenerateBGWithVImage = false;
  190. public static bool gbGenerateVImage = false;
  191. public static bool gbGenerateBGWithoutVImage = false;
  192. public static bool gbGenerateBGWithImage = false;
  193. public static bool gbGenPageSet = false;
  194. public static int[] gPointType = new int[5];
  195. public static int[] gPointDPI = new int[5];
  196. public static string gTMXElementFileName;
  197. public static string gNewProjectDirectory;
  198. public static bool gbElementFileExist { get; set; }
  199. #endregion 打印
  200. #endregion 腾千里手写笔
  201. #region 页面
  202. /// <summary>
  203. /// 主页面
  204. /// </summary>
  205. public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
  206. /// <summary>
  207. /// 创建微课页面
  208. /// </summary>
  209. public static CreateAMicroLessonWindow W_CreateAMicroLessonWindow = null;
  210. /// <summary>
  211. /// 开始录像
  212. /// </summary>
  213. public static CountdownWindow W_CountdownWindow = null;
  214. /// <summary>
  215. /// 录像工具栏
  216. /// </summary>
  217. public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
  218. /// <summary>
  219. /// 登录
  220. /// </summary>
  221. public static LoginWindow W_LoginWindow = null;
  222. /// <summary>
  223. /// 截图
  224. /// </summary>
  225. public static JieTuWindow W_JieTuWindow = null;
  226. /// <summary>
  227. /// 批注
  228. /// </summary>
  229. public static PracticeWindow W_PracticeWindow = null;
  230. /// <summary>
  231. /// 提示窗口
  232. /// </summary>
  233. public static PromptWindow W_PromptWindow = null;
  234. /// <summary>
  235. /// loding页面
  236. /// </summary>
  237. public static LoadDialog myloading;
  238. /// <summary>
  239. /// 上传页面
  240. /// </summary>
  241. public static UploadWindow W_UploadWindow = null;
  242. /// <summary>
  243. /// 最小化工具栏
  244. /// </summary>
  245. public static MinToolbar W_MinToolbar = null;
  246. /// <summary>
  247. /// 视频剪辑
  248. /// </summary>
  249. public static VideoClipWindow W_VideoClipWindow = null;
  250. /// <summary>
  251. /// 设备检测
  252. /// </summary>
  253. public static DeviceWindow W_DeviceWindow = null;
  254. #endregion 页面
  255. #endregion 全局变量
  256. [STAThread]
  257. private static void Main()
  258. {
  259. myloading = new LoadDialog();
  260. StopSameProcess();
  261. Killffmpeg();
  262. //拓思德打印配置生成
  263. //LatticeFileHelper.RunPrintConfig();
  264. try
  265. {
  266. UserInfo = new Model_UserInfo();
  267. WKDataList = new List<Model_WKData>();
  268. VideoList = new List<Model_Video>();
  269. #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  270. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  271. WindowsPrincipal principal = new WindowsPrincipal(identity);
  272. #endregion 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
  273. try
  274. {
  275. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Temp"))//清除临时文件
  276. {
  277. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "Temp", true);
  278. }
  279. }
  280. catch (Exception)
  281. {
  282. }
  283. //如果本地文件为空,弹出弹窗 输密匙
  284. //本地文件不为空, 解析
  285. if (!File.Exists(APP.DataPath + "signature.txt"))//上次登录时间为空 或者签名为空 或者上次登录时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  286. {
  287. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  288. {
  289. //如果是管理员,则直接运行
  290. KeyVerification wins = new KeyVerification();
  291. // 定义Application对象作为整个应用程序入口
  292. Application app = new Application();
  293. SkinConfig.InitSkin();
  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. else
  321. {
  322. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  323. {
  324. ProductVerification wins = new ProductVerification();
  325. Application app = new Application();
  326. SkinConfig.InitSkin();
  327. app.Run(wins);
  328. }
  329. else
  330. {
  331. //创建启动对象
  332. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  333. {
  334. UseShellExecute = true,
  335. WorkingDirectory = Environment.CurrentDirectory,
  336. FileName = Assembly.GetExecutingAssembly().Location,
  337. //设置启动动作,确保以管理员身份运行
  338. Verb = "runas"
  339. };
  340. try
  341. {
  342. System.Diagnostics.Process.Start(startInfo);
  343. }
  344. catch
  345. {
  346. return;
  347. }
  348. //退出
  349. //Current.Shutdown();
  350. Environment.Exit(0);
  351. }
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  357. LogHelper.WriteErrLog(ErrMessage, ex);
  358. }
  359. }
  360. #region 杀死已存在的进程
  361. /// <summary>
  362. /// 结束已运行的程序
  363. /// </summary>
  364. private static void StopSameProcess()
  365. {
  366. Process current = Process.GetCurrentProcess();
  367. Process[] processList = Process.GetProcesses();
  368. foreach (Process process in processList)
  369. {
  370. if (process.ProcessName.ToUpper() == "星火微课")
  371. {
  372. if (process.Id != current.Id) //忽略当前进程
  373. {
  374. try
  375. {
  376. process.Kill(); //结束进程
  377. }
  378. catch (Exception)
  379. {
  380. }
  381. }
  382. }
  383. }
  384. }
  385. /// <summary>
  386. /// 杀死正在运行的ffmpeg
  387. /// </summary>
  388. public static void Killffmpeg()
  389. {
  390. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  391. foreach (Process KillProcess in KillProcessArray)
  392. {
  393. KillProcess.Kill();
  394. }
  395. }
  396. #endregion 杀死已存在的进程
  397. /// <summary>
  398. /// 错误处理
  399. /// </summary>
  400. /// <param name="sender"></param>
  401. /// <param name="e"></param>
  402. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  403. {
  404. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  405. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  406. e.Handled = true;
  407. }
  408. #region 数据保存和读取
  409. /// <summary>
  410. /// 保存微课信息
  411. /// </summary>
  412. public static void SaveWkData()
  413. {
  414. try
  415. {
  416. VideoList = VideoList.Where((x, i) => VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  417. WKData.VideoList = VideoList;
  418. if (WKDataList != null)
  419. {
  420. WKDataList.RemoveAll(x => x.WkPath == WKData.WkPath);
  421. }
  422. else
  423. {
  424. WKDataList = new List<Model_WKData>();
  425. }
  426. WKDataList.Add(WKData);
  427. //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
  428. string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
  429. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  430. FileToolsCommon.CreateDirectory(SavePath);
  431. string SaveName = SavePath + "WkDate.d";
  432. FileToolsCommon.DeleteFile(SaveName);
  433. FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
  434. }
  435. catch (Exception ex)
  436. {
  437. LogHelper.WriteErrLog("【微课数据保存】(SaveWkData)保存失败:" + ex.Message, ex);
  438. }
  439. }
  440. /// <summary>
  441. /// 读取微课信息
  442. /// </summary>
  443. public static void ReadWkData(string WkPath)
  444. {
  445. try
  446. {
  447. string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/");
  448. FileToolsCommon.CreateDirectory(SavePath);
  449. string SaveName = SavePath + "WkDate.d";
  450. //文件若存在则读取
  451. if (FileToolsCommon.IsExistFile(SaveName))
  452. {
  453. string WkDateXmlStr = FileToolsCommon.FileToString(SaveName);
  454. WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
  455. foreach (Model_WKData wklist in WKDataList)
  456. {
  457. //移除找不到视频的微课数据
  458. wklist.VideoList.RemoveAll(x => !FileToolsCommon.IsExistFile(x.VideoPath));
  459. }
  460. if (WKDataList.Exists(x => x.WkPath == WkPath))
  461. {
  462. WKData = WKDataList.Find(x => x.WkPath == WkPath);
  463. VideoList = new List<Model_Video>();
  464. WKData.VideoList = WKData.VideoList.Where((x, i) => WKData.VideoList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  465. VideoList = WKData.VideoList;
  466. //List<Model_Video> companyList = WKData.VideoList;
  467. //VideoList = companyList.Where((x, i) => companyList.FindIndex(z => z.FileGuid == x.FileGuid) == i).ToList();
  468. //VideoList = companyList.Distinct().ToList();
  469. }
  470. }
  471. }
  472. catch (Exception ex)
  473. {
  474. LogHelper.WriteErrLog("【微课数据读取】(ReadWkData)读取失败:" + ex.Message, ex);
  475. }
  476. }
  477. /// <summary>
  478. /// 保存画板数据
  479. /// </summary>
  480. public static void SaveDraw()
  481. {
  482. try
  483. {
  484. if (PageDrawList == null)
  485. {
  486. return;
  487. }
  488. if (PageDrawList.Count < 1)
  489. {
  490. return;
  491. }
  492. FileToolsCommon.CreateDirectory(WKData.WkPath);
  493. string SavePath = WKData.WkPath + "PageData.d";
  494. FileToolsCommon.DeleteFile(SavePath);
  495. string PageDataXmlStr = XmlUtilHelper.XmlSerialize(PageDrawList);
  496. FileToolsCommon.WriteText(SavePath, PageDataXmlStr);
  497. }
  498. catch (Exception ex)
  499. {
  500. LogHelper.WriteErrLog("【画板数据保存】(SaveDraw)保存失败:" + ex.Message, ex);
  501. }
  502. }
  503. /// <summary>
  504. /// 读取文件
  505. /// </summary>
  506. public static void ReadDrawData()
  507. {
  508. try
  509. {
  510. PageDrawList = new List<Model_DrawData>();
  511. string SavePath = WKData.WkPath + "PageData.d";
  512. if (FileToolsCommon.IsExistFile(SavePath))
  513. {
  514. string PageDataXmlStr = FileToolsCommon.FileToString(SavePath);
  515. PageDrawList = XmlUtilHelper.DESerializer<List<Model_DrawData>>(PageDataXmlStr);
  516. }
  517. }
  518. catch (Exception ex)
  519. {
  520. LogHelper.WriteErrLog("【画板数据读取】(ReadDraw)读取失败:" + ex.Message, ex);
  521. }
  522. }
  523. #endregion 数据保存和读取
  524. #region 服务地址数据
  525. /// <summary>
  526. /// 服务地址存储到本地
  527. /// </summary>
  528. public static void SaveServiceAddressData()
  529. {
  530. try
  531. {
  532. if (ServiceAddress == null)
  533. {
  534. return;
  535. }
  536. string DateXmlStr = XmlUtilHelper.XmlSerialize(ServiceAddress);
  537. string SavePath = DataPath;
  538. FileToolsCommon.CreateDirectory(SavePath);
  539. string SaveName = SavePath + "ServiceAddress.d";
  540. FileToolsCommon.DeleteFile(SaveName);
  541. FileToolsCommon.WriteText(SaveName, DateXmlStr);
  542. }
  543. catch (Exception ex)
  544. {
  545. LogHelper.WriteErrLog("【服务地址存储】(SaveServiceAddressData)保存失败:" + ex.Message, ex);
  546. }
  547. }
  548. /// <summary>
  549. /// 从本地读取服务地址
  550. /// </summary>
  551. public static void ReadServiceAddressData()
  552. {
  553. try
  554. {
  555. string SavePath = DataPath;
  556. FileToolsCommon.CreateDirectory(SavePath);
  557. string SaveName = SavePath + "ServiceAddress.d";
  558. //文件若存在则读取
  559. if (FileToolsCommon.IsExistFile(SaveName))
  560. {
  561. string DateXmlStr = FileToolsCommon.FileToString(SaveName);
  562. ServiceAddress = XmlUtilHelper.DESerializer<Model_ServiceAddress>(DateXmlStr);
  563. SwitchAddress();
  564. }
  565. }
  566. catch (Exception ex)
  567. {
  568. LogHelper.WriteErrLog("【服务地址读取】(ReadServiceAddressData)读取失败:" + ex.Message, ex);
  569. }
  570. }
  571. /// <summary>
  572. /// 切换校内外网
  573. /// </summary>
  574. public static void SwitchAddress()
  575. {
  576. try
  577. {
  578. apiUrl = IsOutsideSchool ? ServiceAddress.wapi : ServiceAddress.napi;
  579. uploadUrl = (IsOutsideSchool ? ServiceAddress.wfile : ServiceAddress.nfile) + "/";
  580. showImageUrl = (IsOutsideSchool ? ServiceAddress.wdown : ServiceAddress.ndown) + "/static/";
  581. }
  582. catch (Exception ex)
  583. {
  584. LogHelper.WriteErrLog("【服务地址切换】(SwitchAddress)服务复制切换失败,请求地址为空!", ex);
  585. }
  586. }
  587. #endregion 服务地址数据
  588. #region 检测安装Screen Capturer Recorder
  589. /// <summary>
  590. /// 检测是否安装了Screen Capturer Recorder
  591. /// </summary>
  592. /// <returns></returns>
  593. public static bool CheckScreenCapturerRecorder()
  594. {
  595. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  596. {
  597. //已经安装
  598. return true;
  599. }
  600. else
  601. {
  602. return false;
  603. }
  604. }
  605. /// <summary>
  606. /// 安装Screen Capturer Recorder
  607. /// </summary>
  608. /// <returns></returns>
  609. public static bool InstallScreenCapturerRecorder()
  610. {
  611. Process InstallProcess = new Process();
  612. string StandardError = "";
  613. string StandardOutput = "";
  614. try
  615. {
  616. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/SSCR/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  617. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  618. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  619. InstallProcess.StartInfo.RedirectStandardOutput = true;
  620. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  621. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  622. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  623. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  624. InstallProcess.Start(); //启动线程
  625. InstallProcess.WaitForExit(); //阻塞等待进程结束
  626. StandardError = InstallProcess.StandardError.ReadToEnd();
  627. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  628. int ExitCode = InstallProcess.ExitCode;
  629. InstallProcess.Close(); //关闭进程
  630. InstallProcess.Dispose(); //释放资源
  631. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  632. {
  633. return true;
  634. }
  635. else
  636. {
  637. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否现在安装?", "安装", MessageBoxButton.OKCancel);
  638. if (br == MessageBoxResult.OK)
  639. {
  640. return InstallScreenCapturerRecorder();
  641. }
  642. else
  643. {
  644. return false;
  645. }
  646. }
  647. }
  648. catch (Exception ex)
  649. {
  650. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  651. if (string.IsNullOrWhiteSpace(StandardError))
  652. {
  653. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  654. }
  655. if (string.IsNullOrWhiteSpace(StandardOutput))
  656. {
  657. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  658. }
  659. return false;
  660. }
  661. }
  662. /// <summary>
  663. /// 安装失败信息
  664. /// </summary>
  665. /// <param name="sender"></param>
  666. /// <param name="e"></param>
  667. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  668. {
  669. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  670. //MessageWindow.Show(e.Data);
  671. }
  672. #endregion 检测安装Screen Capturer Recorder
  673. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  674. /// <summary>
  675. /// 内存释放压缩
  676. /// </summary>
  677. /// <param name="e"></param>
  678. protected override void OnStartup(StartupEventArgs e)
  679. {
  680. new Thread(o =>
  681. {
  682. while (true)
  683. {
  684. try
  685. {
  686. //FreeMemoryHelper.SetDate();
  687. FreeMemoryHelper.ReallocateMemory();
  688. Thread.Sleep(20000);//暂定每20秒释放一次
  689. }
  690. catch (Exception ex)
  691. {
  692. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  693. }
  694. }
  695. }).Start();
  696. }
  697. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  698. }
  699. }