星火直播PC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. try
  269. {
  270. if (args != null&&args.Length>1)
  271. {
  272. AESAccountStr = args[0];
  273. AESPassWordStr = args[1];
  274. ////解密
  275. //string Account= AESHelper.AESDecrypt(AESAccountStr);
  276. //string PassWord = AESHelper.AESDecrypt(AESPassWordStr);
  277. }
  278. }
  279. catch (Exception ex)
  280. {
  281. LogHelper.WriteErrLog("参数接收失败:" + ex.Message, ex);
  282. throw;
  283. }
  284. try
  285. {
  286. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  287. WindowsPrincipal principal = new WindowsPrincipal(identity);
  288. try
  289. {
  290. if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))//清除临时文件
  291. {
  292. Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
  293. }
  294. }
  295. catch (Exception)
  296. {
  297. }
  298. //如果本地文件为空,弹出弹窗 输密匙
  299. //本地文件不为空, 解析
  300. if (!File.Exists(APP.dataPath + "signature.txt"))//上次登陆时间为空 或者签名为空 或者上次登陆时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  301. {
  302. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  303. {
  304. ////如果是管理员,则直接运行
  305. //KeyVerification wins = new KeyVerification();
  306. // 定义Application对象作为整个应用程序入口
  307. //Application app = new Application();
  308. //app.Run(wins);
  309. W_LoginWindow = new LoginWindow();
  310. Application app = new Application();
  311. app.Run(W_LoginWindow);
  312. }
  313. else
  314. {
  315. //创建启动对象
  316. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  317. {
  318. UseShellExecute = true,
  319. WorkingDirectory = Environment.CurrentDirectory,
  320. FileName = Assembly.GetExecutingAssembly().Location,
  321. //设置启动动作,确保以管理员身份运行
  322. Verb = "runas"
  323. };
  324. try
  325. {
  326. System.Diagnostics.Process.Start(startInfo);
  327. }
  328. catch
  329. {
  330. return;
  331. }
  332. //退出
  333. //Current.Shutdown();
  334. Environment.Exit(0);
  335. }
  336. }
  337. else
  338. {
  339. if (principal.IsInRole(WindowsBuiltInRole.Administrator))
  340. {
  341. //ProductVerification wins = new ProductVerification();
  342. //Application app = new Application();
  343. //app.Run(wins);
  344. W_LoginWindow = new LoginWindow();
  345. Application app = new Application();
  346. app.Run(W_LoginWindow);
  347. }
  348. else
  349. {
  350. //创建启动对象
  351. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
  352. {
  353. UseShellExecute = true,
  354. WorkingDirectory = Environment.CurrentDirectory,
  355. FileName = Assembly.GetExecutingAssembly().Location,
  356. //设置启动动作,确保以管理员身份运行
  357. Verb = "runas"
  358. };
  359. try
  360. {
  361. System.Diagnostics.Process.Start(startInfo);
  362. }
  363. catch
  364. {
  365. return;
  366. }
  367. //退出
  368. //Current.Shutdown();
  369. Environment.Exit(0);
  370. }
  371. }
  372. }
  373. catch (Exception ex)
  374. {
  375. string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
  376. LogHelper.WriteErrLog(ErrMessage, ex);
  377. }
  378. }
  379. #region 杀死已存在的进程
  380. /// <summary>
  381. /// 结束已运行的程序
  382. /// </summary>
  383. private static void StopSameProcess()
  384. {
  385. Process current = Process.GetCurrentProcess();
  386. Process[] processList = Process.GetProcesses();
  387. foreach (Process process in processList)
  388. {
  389. if (process.ProcessName.ToUpper() == "星火直播")
  390. {
  391. if (process.Id != current.Id) //忽略当前进程
  392. {
  393. try
  394. {
  395. process.Kill(); //结束进程
  396. }
  397. catch (Exception)
  398. {
  399. }
  400. }
  401. }
  402. }
  403. }
  404. /// <summary>
  405. /// 杀死正在运行的ffmpeg
  406. /// </summary>
  407. public static void Killffmpeg()
  408. {
  409. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  410. foreach (Process KillProcess in KillProcessArray)
  411. {
  412. KillProcess.Kill();
  413. }
  414. }
  415. #endregion
  416. /// <summary>
  417. /// 错误处理
  418. /// </summary>
  419. /// <param name="sender"></param>
  420. /// <param name="e"></param>
  421. private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  422. {
  423. LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
  424. MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
  425. e.Handled = true;
  426. }
  427. #region 检测解压ffmpeg
  428. public void UnZipFFmpeg()
  429. {
  430. new Thread(o =>
  431. {
  432. if (!FileToolsCommon.IsExistDirectory(FileToolsCommon.GetFileAbsolutePath("/ffmpeg/")))
  433. {
  434. try
  435. {
  436. //根据系统解压ffmpeg
  437. if (Environment.Is64BitOperatingSystem)
  438. {
  439. //64
  440. ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath());
  441. }
  442. else
  443. {
  444. //32
  445. ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx32.zip"), FileToolsCommon.GetFileAbsolutePath());
  446. }
  447. }
  448. catch (Exception)
  449. {
  450. ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath());
  451. }
  452. }
  453. }).Start();
  454. }
  455. #endregion
  456. #region 检测安装Screen Capturer Recorder
  457. /// <summary>
  458. /// 检测是否安装了Screen Capturer Recorder
  459. /// </summary>
  460. /// <returns></returns>
  461. public static bool CheckScreenCapturerRecorder()
  462. {
  463. if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
  464. {
  465. //已经安装
  466. return true;
  467. }
  468. else
  469. {
  470. return false;
  471. }
  472. }
  473. /// <summary>
  474. /// 安装Screen Capturer Recorder
  475. /// </summary>
  476. /// <returns></returns>
  477. public static bool InstallScreenCapturerRecorder()
  478. {
  479. Process InstallProcess = new Process();
  480. string StandardError = "";
  481. string StandardOutput = "";
  482. try
  483. {
  484. InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/SSCR/Setup Screen Capturer Recorder v0.12.10.exe"); //绝对路径
  485. InstallProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  486. InstallProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  487. InstallProcess.StartInfo.RedirectStandardOutput = true;
  488. InstallProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  489. InstallProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  490. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  491. InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
  492. InstallProcess.Start(); //启动线程
  493. InstallProcess.WaitForExit(); //阻塞等待进程结束
  494. StandardError = InstallProcess.StandardError.ReadToEnd();
  495. StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
  496. int ExitCode = InstallProcess.ExitCode;
  497. InstallProcess.Close(); //关闭进程
  498. InstallProcess.Dispose(); //释放资源
  499. if (ExitCode == 0) //非0则为安装失败 1为取消安装
  500. {
  501. return true;
  502. }
  503. else
  504. {
  505. MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否现在安装?", "安装", MessageBoxButton.OKCancel);
  506. if (br == MessageBoxResult.OK)
  507. {
  508. return InstallScreenCapturerRecorder();
  509. }
  510. else
  511. {
  512. return false;
  513. }
  514. }
  515. }
  516. catch (Exception ex)
  517. {
  518. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
  519. if (string.IsNullOrWhiteSpace(StandardError))
  520. {
  521. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
  522. }
  523. if (string.IsNullOrWhiteSpace(StandardOutput))
  524. {
  525. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
  526. }
  527. return false;
  528. }
  529. }
  530. /// <summary>
  531. /// 安装失败信息
  532. /// </summary>
  533. /// <param name="sender"></param>
  534. /// <param name="e"></param>
  535. private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
  536. {
  537. LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
  538. //MessageWindow.Show(e.Data);
  539. }
  540. #endregion
  541. #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  542. /// <summary>
  543. /// 内存释放压缩
  544. /// </summary>
  545. /// <param name="e"></param>
  546. protected override void OnStartup(StartupEventArgs e)
  547. {
  548. //private LierdaCracker cracker = new LierdaCracker();
  549. //cracker.Cracker(5000);//间隔时间
  550. //base.OnStartup(e);
  551. new Thread(o =>
  552. {
  553. while (true)
  554. {
  555. try
  556. {
  557. //FreeMemoryHelper.SetDate();
  558. FreeMemoryHelper.ReallocateMemory();
  559. Thread.Sleep(20000);//暂定每20秒释放一次
  560. }
  561. catch (Exception ex)
  562. {
  563. LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
  564. }
  565. }
  566. }).Start();
  567. }
  568. #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
  569. #region 测试
  570. public static void AddTestData()
  571. {
  572. testdata = 1;
  573. }
  574. /// <summary>
  575. /// 图片真实路径
  576. /// </summary>
  577. /// <returns></returns>
  578. public static string classRoomImagePath()
  579. {
  580. //string path = $"{nginxHtml}school\\{ZCommonData.loginUser.schoolid}\\class\\{ZCommonData.roomid}\\";
  581. string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\"; ;
  582. return path;
  583. }
  584. /// <summary>
  585. /// 本地服务器存储路径
  586. /// </summary>
  587. /// <returns></returns>
  588. public static string dbImagePath()
  589. {
  590. //string path = $"school\\{ZCommonData.loginUser.schoolid}\\class\\{ZCommonData.roomid}\\";
  591. string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  592. return path;
  593. }
  594. /// <summary>
  595. /// 获取图片保存路径 设置服务器存储路径 创建人:赵耀 创建时间:2020年8月11日
  596. /// </summary>
  597. /// <returns></returns>
  598. public static string GetImagePath(out string ServerSavePath)
  599. {
  600. string imagepath = APP.classRoomImagePath();
  601. if (!Directory.Exists(imagepath))
  602. {
  603. Directory.CreateDirectory(imagepath);
  604. }
  605. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  606. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  607. string filepath = Path.Combine(imagepath, timestr + ".jpg");
  608. ServerSavePath = APP.dbImagePath() + timestr + ".jpg";
  609. return filepath;
  610. }
  611. #endregion
  612. }
  613. }