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

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