星火直播PC
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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