星火直播PC
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

App.cs 27KB

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