星火直播PC
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. using Common;
  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 XHZB.Model;
  13. namespace XHZB.Desktop
  14. {
  15. public partial class APP : Application
  16. {
  17. #region 全局变量
  18. public static int testdata=0;
  19. /// <summary>
  20. /// 是否为测试版
  21. /// </summary>
  22. public static bool isDebug = FileToolsCommon.GetConfigValue("IsDebug") != "0";
  23. /// <summary>
  24. /// RTMP服务器地址
  25. /// </summary>
  26. public static string RTMPServerPath = FileToolsCommon.GetConfigValue("ServerPath");
  27. /// <summary>
  28. /// AES账号加密字符串
  29. /// </summary>
  30. public static string AESAccountStr = null;
  31. /// <summary>
  32. /// AES密码加密字符串
  33. /// </summary>
  34. public static string AESPassWordStr = null;
  35. /// <summary>
  36. /// 接口地址
  37. /// </summary>
  38. public static string apiUrl = isDebug ? "http://schoolapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("APIRequestAddress");
  39. /// <summary>
  40. /// 图片地址
  41. /// </summary>
  42. public static string uploadUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/" : FileToolsCommon.GetConfigValue("FileRequestAddress");
  43. /// <summary>
  44. /// 展示文件
  45. /// </summary>
  46. public static string showImageUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
  47. /// <summary>
  48. /// 认证接口地址
  49. /// </summary>
  50. public static string certapiUrl = isDebug ? "http://certapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("CertapiRequestAddress");
  51. /// <summary>
  52. /// 数据存放目录
  53. /// </summary>
  54. public static string dataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHZB\\";
  55. /// <summary>
  56. /// 签名
  57. /// </summary>
  58. public static string Signature = "";
  59. public static string secretKey = "nanhuakaizhangjianwangni";
  60. /// <summary>
  61. /// 录屏工具
  62. /// </summary>
  63. public static FFMpeg FFmpeg = new FFMpeg();
  64. /// <summary>
  65. /// 登陆状态 false 未登录 true已登陆
  66. /// </summary>
  67. public static bool IsLoginType = false;
  68. /// <summary>
  69. /// 防止图片地址重复
  70. /// </summary>
  71. public static long num = 9999;
  72. /// <summary>
  73. /// 导入图片路径
  74. /// </summary>
  75. public static string[] Paths = new string[] { };
  76. /// <summary>
  77. /// 截图图片路径
  78. /// </summary>
  79. public static string[] JPaths = new string[999];
  80. public static string ImgPath = string.Empty;
  81. /// <summary>
  82. /// 页码IP
  83. /// </summary>
  84. public static string[] OutPut = new string[] { };
  85. public static string CameraPosition = string.Empty;
  86. public static string fileStorageAddress = "";
  87. /// <summary>
  88. /// 数据存放目录
  89. /// </summary>
  90. public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHZB\\";
  91. /// <summary>
  92. /// 是否正在
  93. /// </summary>
  94. public static bool IsUpLoad = false;
  95. /// <summary>
  96. /// 后台线程帮助类
  97. /// </summary>
  98. public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
  99. /// <summary>
  100. /// 提示信息
  101. /// </summary>
  102. public static string ErrorMessage = string.Empty;
  103. /// <summary>
  104. /// 服务调用成功代码
  105. /// </summary>
  106. public const int ServerScuessCode = 0;
  107. public static int classid;
  108. public static long roomid;
  109. public static long askid;
  110. public static int lsbid;
  111. /// <summary>
  112. /// 登陆数据
  113. /// </summary>
  114. public static LoginModel LoginUser;
  115. private static List<ClassListModel> _ClassList;
  116. /// <summary>
  117. /// 教师任教班级出参
  118. /// </summary>
  119. public static List<ClassListModel> ClassList
  120. {
  121. get
  122. {
  123. if (_ClassList == null)
  124. {
  125. _ClassList = new List<ClassListModel>();
  126. }
  127. return _ClassList;
  128. }
  129. set => _ClassList = value;
  130. }
  131. private static List<TsubjectbookListModel> _TsubjectbookList;
  132. /// <summary>
  133. /// 教师教材列表
  134. /// </summary>
  135. public static List<TsubjectbookListModel> TsubjectbookList
  136. {
  137. get
  138. {
  139. if (_TsubjectbookList == null)
  140. {
  141. _TsubjectbookList = new List<TsubjectbookListModel>();
  142. }
  143. return _TsubjectbookList;
  144. }
  145. set => _TsubjectbookList = value;
  146. }
  147. private static List<DirectorListModel> _DirectorList;
  148. /// <summary>
  149. /// 章节列表 出参
  150. /// </summary>
  151. public static List<DirectorListModel> DirectorList
  152. {
  153. get
  154. {
  155. if (_DirectorList == null)
  156. {
  157. _DirectorList = new List<DirectorListModel>();
  158. }
  159. return _DirectorList;
  160. }
  161. set => _DirectorList = value;
  162. }
  163. private static REQStartClassModel _REQStartClass;
  164. /// <summary>
  165. /// 开始课堂入参
  166. /// </summary>
  167. public static REQStartClassModel REQStartClass
  168. {
  169. get
  170. {
  171. if (_REQStartClass == null)
  172. {
  173. _REQStartClass = new REQStartClassModel();
  174. }
  175. return _REQStartClass;
  176. }
  177. set => _REQStartClass = value;
  178. }
  179. /// <summary>
  180. /// 抢答
  181. /// </summary>
  182. public static List<RollCallModel> RollCallList = new List<RollCallModel>();
  183. /// <summary>
  184. /// 在线用户
  185. /// </summary>
  186. public static List<OnlineUserModel> OnlineUserList = new List<OnlineUserModel>();
  187. private static List<ClassStudentListModel> _ClassStudentList;
  188. /// <summary>
  189. /// 班级学生--列表 出参
  190. /// </summary>
  191. public static List<ClassStudentListModel> ClassStudentList
  192. {
  193. get
  194. {
  195. if (_ClassStudentList == null)
  196. {
  197. _ClassStudentList = new List<ClassStudentListModel>();
  198. }
  199. return _ClassStudentList;
  200. }
  201. set => _ClassStudentList = value;
  202. }
  203. #region 页面
  204. public static LoadDialog myloading;
  205. /// <summary>
  206. /// 主页面
  207. /// </summary>
  208. public static LoginWindow W_LoginWindow = null;
  209. /// <summary>
  210. /// 工具栏
  211. /// </summary>
  212. public static ToolbarWindow W_ToolbarWindow = null;
  213. /// <summary>
  214. /// 个人空间
  215. /// </summary>
  216. public static UserCenterWindow W_UserCenterWindow = null;
  217. /// <summary>
  218. /// 抢答点名
  219. /// </summary>
  220. public static RollCallWindow W_RollCallWindow = null;
  221. /// <summary>
  222. /// 考勤
  223. /// </summary>
  224. public static AttendanceWindow W_AttendanceWindow = null;
  225. /// <summary>
  226. /// 黑板
  227. /// </summary>
  228. public static ZBlackboardWindow W_ZBlackboardWindow = null;
  229. /// <summary>
  230. /// 批注
  231. /// </summary>
  232. public static PracticeWindow W_PracticeWindow = null;
  233. /// <summary>
  234. /// 摄像头
  235. /// </summary>
  236. public static CameraWindow W_CameraWindow = null;
  237. #endregion
  238. #endregion
  239. /// <summary>
  240. /// 启动入口
  241. /// </summary>
  242. /// <param name="args">参数1:账号加密字符串 参数1:密码加密字符串</param>
  243. [STAThread]
  244. private static void Main(string[] args)
  245. {
  246. myloading = new LoadDialog();
  247. StopSameProcess();
  248. Killffmpeg();
  249. UnZipFFmpeg();
  250. try
  251. {
  252. if (args != null&&args.Length>1)
  253. {
  254. AESAccountStr = args[0];
  255. AESPassWordStr = args[1];
  256. ////解密
  257. //string Account= AESHelper.AESDecrypt(AESAccountStr);
  258. //string PassWord = AESHelper.AESDecrypt(AESPassWordStr);
  259. }
  260. }
  261. catch (Exception ex)
  262. {
  263. LogHelper.WriteErrLog("参数接收失败:" + ex.Message, ex);
  264. throw;
  265. }
  266. try
  267. {
  268. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  269. WindowsPrincipal principal = new WindowsPrincipal(identity);
  270. try
  271. {
  272. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))//清除临时文件
  273. {
  274. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
  275. }
  276. }
  277. catch (Exception)
  278. {
  279. }
  280. //如果本地文件为空,弹出弹窗 输密匙
  281. //本地文件不为空, 解析
  282. if (!File.Exists(APP.dataPath + "signature.txt"))//上次登陆时间为空 或者签名为空 或者上次登陆时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  283. {
  284. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  285. {
  286. ////如果是管理员,则直接运行
  287. //KeyVerification wins = new KeyVerification();
  288. // 定义Application对象作为整个应用程序入口
  289. //Application app = new Application();
  290. //app.Run(wins);
  291. W_LoginWindow = new LoginWindow();
  292. Application app = new Application();
  293. app.Run(W_LoginWindow);
  294. }
  295. else
  296. {
  297. //创建启动对象
  298. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  299. {
  300. UseShellExecute = true,
  301. WorkingDirectory = Environment.CurrentDirectory,
  302. FileName = Assembly.GetExecutingAssembly().Location,
  303. //设置启动动作,确保以管理员身份运行
  304. Verb = "runas"
  305. };
  306. try
  307. {
  308. System.Diagnostics.Process.Start(startInfo);
  309. }
  310. catch
  311. {
  312. return;
  313. }
  314. //退出
  315. //Current.Shutdown();
  316. Environment.Exit(0);
  317. }
  318. }
  319. else
  320. {
  321. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  322. {
  323. //ProductVerification wins = new ProductVerification();
  324. //Application app = new Application();
  325. //app.Run(wins);
  326. W_LoginWindow = new LoginWindow();
  327. Application app = new Application();
  328. app.Run(W_LoginWindow);
  329. }
  330. else
  331. {
  332. //创建启动对象
  333. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  334. {
  335. UseShellExecute = true,
  336. WorkingDirectory = Environment.CurrentDirectory,
  337. FileName = Assembly.GetExecutingAssembly().Location,
  338. //设置启动动作,确保以管理员身份运行
  339. Verb = "runas"
  340. };
  341. try
  342. {
  343. System.Diagnostics.Process.Start(startInfo);
  344. }
  345. catch
  346. {
  347. return;
  348. }
  349. //退出
  350. //Current.Shutdown();
  351. Environment.Exit(0);
  352. }
  353. }
  354. }
  355. catch (Exception ex)
  356. {
  357. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  358. LogHelper.WriteErrLog(ErrMessage, ex);
  359. }
  360. }
  361. #region 杀死已存在的进程
  362. /// <summary>
  363. /// 结束已运行的程序
  364. /// </summary>
  365. private static void StopSameProcess()
  366. {
  367. Process current = Process.GetCurrentProcess();
  368. Process[] processList = Process.GetProcesses();
  369. foreach (Process process in processList)
  370. {
  371. if (process.ProcessName.ToUpper() == "星火直播")
  372. {
  373. if (process.Id != current.Id) //忽略当前进程
  374. {
  375. try
  376. {
  377. process.Kill(); //结束进程
  378. }
  379. catch (Exception)
  380. {
  381. }
  382. }
  383. }
  384. }
  385. }
  386. /// <summary>
  387. /// 杀死正在运行的ffmpeg
  388. /// </summary>
  389. public static void Killffmpeg()
  390. {
  391. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  392. foreach (Process KillProcess in KillProcessArray)
  393. {
  394. KillProcess.Kill();
  395. }
  396. }
  397. #endregion
  398. /// <summary>
  399. /// 错误处理
  400. /// </summary>
  401. /// <param name="sender"></param>
  402. /// <param name="e"></param>
  403. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  404. {
  405. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  406. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  407. e.Handled = true;
  408. }
  409. #region 检测解压ffmpeg
  410. public static void UnZipFFmpeg()
  411. {
  412. new Thread(o =>
  413. {
  414. if (!FileToolsCommon.IsExistDirectory(FileToolsCommon.GetFileAbsolutePath("/ffmpeg/")))
  415. {
  416. try
  417. {
  418. //根据系统解压ffmpeg
  419. if (Environment.Is64BitOperatingSystem)
  420. {
  421. //64
  422. ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath());
  423. }
  424. else
  425. {
  426. //32
  427. ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx32.zip"), FileToolsCommon.GetFileAbsolutePath());
  428. }
  429. }
  430. catch (Exception)
  431. {
  432. ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath());
  433. }
  434. }
  435. }).Start();
  436. }
  437. #endregion
  438. #region 检测安装Screen Capturer Recorder
  439. /// <summary>
  440. /// 检测是否安装了Screen Capturer Recorder
  441. /// </summary>
  442. /// <returns></returns>
  443. public static bool CheckScreenCapturerRecorder()
  444. {
  445. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  446. {
  447. //已经安装
  448. return true;
  449. }
  450. else
  451. {
  452. return false;
  453. }
  454. }
  455. /// <summary>
  456. /// 安装Screen Capturer Recorder
  457. /// </summary>
  458. /// <returns></returns>
  459. public static bool InstallScreenCapturerRecorder()
  460. {
  461. Process InstallProcess = new Process();
  462. string StandardError = "";
  463. string StandardOutput = "";
  464. try
  465. {
  466. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/SSCR/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  467. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  468. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  469. InstallProcess.StartInfo.RedirectStandardOutput = true;
  470. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  471. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  472. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  473. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  474. InstallProcess.Start(); //启动线程
  475. InstallProcess.WaitForExit(); //阻塞等待进程结束
  476. StandardError = InstallProcess.StandardError.ReadToEnd();
  477. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  478. int ExitCode = InstallProcess.ExitCode;
  479. InstallProcess.Close(); //关闭进程
  480. InstallProcess.Dispose(); //释放资源
  481. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  482. {
  483. return true;
  484. }
  485. else
  486. {
  487. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否现在安装?", "安装", MessageBoxButton.OKCancel);
  488. if (br == MessageBoxResult.OK)
  489. {
  490. return InstallScreenCapturerRecorder();
  491. }
  492. else
  493. {
  494. return false;
  495. }
  496. }
  497. }
  498. catch (Exception ex)
  499. {
  500. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  501. if (string.IsNullOrWhiteSpace(StandardError))
  502. {
  503. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  504. }
  505. if (string.IsNullOrWhiteSpace(StandardOutput))
  506. {
  507. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  508. }
  509. return false;
  510. }
  511. }
  512. /// <summary>
  513. /// 安装失败信息
  514. /// </summary>
  515. /// <param name="sender"></param>
  516. /// <param name="e"></param>
  517. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  518. {
  519. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  520. //MessageWindow.Show(e.Data);
  521. }
  522. #endregion
  523. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  524. /// <summary>
  525. /// 内存释放压缩
  526. /// </summary>
  527. /// <param name="e"></param>
  528. protected override void OnStartup(StartupEventArgs e)
  529. {
  530. //private LierdaCracker cracker = new LierdaCracker();
  531. //cracker.Cracker(5000);//间隔时间
  532. //base.OnStartup(e);
  533. new Thread(o =>
  534. {
  535. while (true)
  536. {
  537. try
  538. {
  539. //FreeMemoryHelper.SetDate();
  540. FreeMemoryHelper.ReallocateMemory();
  541. Thread.Sleep(20000);//暂定每20秒释放一次
  542. }
  543. catch (Exception ex)
  544. {
  545. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  546. }
  547. }
  548. }).Start();
  549. }
  550. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  551. #region 测试
  552. public static void AddTestData()
  553. {
  554. testdata = 1;
  555. }
  556. /// <summary>
  557. /// 图片真实路径
  558. /// </summary>
  559. /// <returns></returns>
  560. public static string classRoomImagePath()
  561. {
  562. //string path = $"{nginxHtml}school\\{ZCommonData.loginUser.schoolid}\\class\\{ZCommonData.roomid}\\";
  563. string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\"; ;
  564. return path;
  565. }
  566. /// <summary>
  567. /// 本地服务器存储路径
  568. /// </summary>
  569. /// <returns></returns>
  570. public static string dbImagePath()
  571. {
  572. //string path = $"school\\{ZCommonData.loginUser.schoolid}\\class\\{ZCommonData.roomid}\\";
  573. string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  574. return path;
  575. }
  576. /// <summary>
  577. /// 获取图片保存路径 设置服务器存储路径 创建人:赵耀 创建时间:2020年8月11日
  578. /// </summary>
  579. /// <returns></returns>
  580. public static string GetImagePath(out string ServerSavePath)
  581. {
  582. string imagepath = APP.classRoomImagePath();
  583. if (!Directory.Exists(imagepath))
  584. {
  585. Directory.CreateDirectory(imagepath);
  586. }
  587. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  588. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  589. string filepath = Path.Combine(imagepath, timestr + ".jpg");
  590. ServerSavePath = APP.dbImagePath() + timestr + ".jpg";
  591. return filepath;
  592. }
  593. #endregion
  594. }
  595. }