星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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