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

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