123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- using Common;
- using Common.system;
-
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Reflection;
- using System.Security.Principal;
- using System.Threading;
- using System.Windows;
- using System.Windows.Threading;
- using XHZB.Model;
-
- namespace XHZB.Desktop
- {
- public partial class APP : Application
- {
- #region 全局变量
- public static int testdata=0;
-
-
-
- public static bool isDebug = FileToolsCommon.GetConfigValue("IsDebug") != "0";
-
-
-
- public static string RTMPServerPath = FileToolsCommon.GetConfigValue("ServerPath");
-
-
-
- public static string AESAccountStr = null;
-
-
-
- public static string AESPassWordStr = null;
-
-
-
- public static string apiUrl = isDebug ? "http://schoolapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("APIRequestAddress");
-
-
-
- public static string uploadUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/" : FileToolsCommon.GetConfigValue("FileRequestAddress");
-
-
-
- public static string showImageUrl = isDebug ? "http://schoolfiletest.xhkjedu.com/static/" : FileToolsCommon.GetConfigValue("SchoolfileRequestAddress") + "/static/";
-
-
-
- public static string certapiUrl = isDebug ? "http://certapitest.xhkjedu.com" : FileToolsCommon.GetConfigValue("CertapiRequestAddress");
-
-
-
- public static string dataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHZB\\";
-
-
-
- public static string Signature = "";
- public static string secretKey = "nanhuakaizhangjianwangni";
-
-
-
- public static FFMpeg FFmpeg = new FFMpeg();
-
-
-
- public static bool IsLoginType = false;
-
-
-
- public static long num = 9999;
-
-
-
- public static string[] Paths = new string[] { };
-
-
-
- public static string[] JPaths = new string[999];
- public static string ImgPath = string.Empty;
-
-
-
- public static string[] OutPut = new string[] { };
- public static string CameraPosition = string.Empty;
- public static string fileStorageAddress = "";
-
-
-
- public static string DataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\XHZB\\";
-
-
-
- public static bool IsUpLoad = false;
-
-
-
- public static BackgroundWorkerHelper BackgroundWorkerHelper => BackgroundWorkerHelper.GetInstance();
-
-
-
- public static string ErrorMessage = string.Empty;
-
-
-
- public const int ServerScuessCode = 0;
- public static int classid;
- public static long roomid;
- public static long askid;
-
- public static int lsbid;
-
-
-
- public static LoginModel LoginUser;
- private static List<ClassListModel> _ClassList;
-
-
-
- public static List<ClassListModel> ClassList
- {
- get
- {
- if (_ClassList == null)
- {
- _ClassList = new List<ClassListModel>();
- }
- return _ClassList;
- }
- set => _ClassList = value;
- }
- private static List<TsubjectbookListModel> _TsubjectbookList;
-
-
-
- public static List<TsubjectbookListModel> TsubjectbookList
- {
- get
- {
- if (_TsubjectbookList == null)
- {
- _TsubjectbookList = new List<TsubjectbookListModel>();
- }
- return _TsubjectbookList;
- }
- set => _TsubjectbookList = value;
- }
- private static List<DirectorListModel> _DirectorList;
-
-
-
- public static List<DirectorListModel> DirectorList
- {
- get
- {
- if (_DirectorList == null)
- {
- _DirectorList = new List<DirectorListModel>();
- }
- return _DirectorList;
- }
- set => _DirectorList = value;
- }
- private static REQStartClassModel _REQStartClass;
-
-
-
- public static REQStartClassModel REQStartClass
- {
- get
- {
- if (_REQStartClass == null)
- {
- _REQStartClass = new REQStartClassModel();
- }
- return _REQStartClass;
- }
- set => _REQStartClass = value;
- }
-
-
-
- public static List<RollCallModel> RollCallList = new List<RollCallModel>();
-
-
-
- public static List<OnlineUserModel> OnlineUserList = new List<OnlineUserModel>();
- private static List<ClassStudentListModel> _ClassStudentList;
-
-
-
- public static List<ClassStudentListModel> ClassStudentList
- {
- get
- {
- if (_ClassStudentList == null)
- {
- _ClassStudentList = new List<ClassStudentListModel>();
- }
- return _ClassStudentList;
- }
- set => _ClassStudentList = value;
- }
- #region 页面
- public static LoadDialog myloading;
-
-
-
- public static LoginWindow W_LoginWindow = null;
-
-
-
- public static ToolbarWindow W_ToolbarWindow = null;
-
-
-
- public static UserCenterWindow W_UserCenterWindow = null;
-
-
-
- public static RollCallWindow W_RollCallWindow = null;
-
-
-
- public static AttendanceWindow W_AttendanceWindow = null;
-
-
-
- public static ZBlackboardWindow W_ZBlackboardWindow = null;
-
-
-
- public static PracticeWindow W_PracticeWindow = null;
-
-
-
- public static CameraWindow W_CameraWindow = null;
- #endregion
- #endregion
-
-
-
-
- [STAThread]
- private static void Main(string[] args)
- {
- myloading = new LoadDialog();
- StopSameProcess();
- Killffmpeg();
- UnZipFFmpeg();
- try
- {
- if (args != null&&args.Length>0)
- {
- AESAccountStr = args[0];
- AESPassWordStr = args[1];
-
-
-
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("参数接收失败:" + ex.Message, ex);
- }
- try
- {
- WindowsIdentity identity = WindowsIdentity.GetCurrent();
- WindowsPrincipal principal = new WindowsPrincipal(identity);
- try
- {
- if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "temp"))
- {
- Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + "temp", true);
- }
- }
- catch (Exception)
- {
- }
-
-
-
- if (!File.Exists(APP.dataPath + "signature.txt"))
- {
- if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- {
-
-
-
-
-
- W_LoginWindow = new LoginWindow();
- Application app = new Application();
- app.Run(W_LoginWindow);
- }
- else
- {
-
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
- {
- UseShellExecute = true,
- WorkingDirectory = Environment.CurrentDirectory,
- FileName = Assembly.GetExecutingAssembly().Location,
-
- Verb = "runas"
- };
- try
- {
- System.Diagnostics.Process.Start(startInfo);
- }
- catch
- {
- return;
- }
-
-
- Environment.Exit(0);
-
- }
- }
- else
- {
- if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- {
-
-
-
-
- W_LoginWindow = new LoginWindow();
- Application app = new Application();
- app.Run(W_LoginWindow);
- }
- else
- {
-
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo
- {
- UseShellExecute = true,
- WorkingDirectory = Environment.CurrentDirectory,
- FileName = Assembly.GetExecutingAssembly().Location,
-
- Verb = "runas"
- };
- try
- {
- System.Diagnostics.Process.Start(startInfo);
- }
- catch
- {
- return;
- }
-
-
- Environment.Exit(0);
-
- }
- }
- }
- catch (Exception ex)
- {
-
- string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- }
- }
-
- #region 杀死已存在的进程
-
-
-
- private static void StopSameProcess()
- {
- Process current = Process.GetCurrentProcess();
- Process[] processList = Process.GetProcesses();
- foreach (Process process in processList)
- {
- if (process.ProcessName.ToUpper() == "星火直播")
- {
- if (process.Id != current.Id)
- {
- try
- {
- process.Kill();
- }
- catch (Exception)
- {
- }
- }
- }
- }
- }
-
-
-
- public static void Killffmpeg()
- {
- Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
- foreach (Process KillProcess in KillProcessArray)
- {
- KillProcess.Kill();
- }
- }
- #endregion
-
-
-
-
-
-
- private void MyApp_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- LogHelper.WriteErrLog("未标示错误:" + e.Exception.Message, e.Exception);
- MessageWindow.Show("程序异常." + Environment.NewLine + e.Exception.Message);
- e.Handled = true;
- }
-
- #region 检测解压ffmpeg
- public static void UnZipFFmpeg()
- {
- new Thread(o =>
- {
- if (!FileToolsCommon.IsExistDirectory(FileToolsCommon.GetFileAbsolutePath("/ffmpeg/")))
- {
- try
- {
-
- if (Environment.Is64BitOperatingSystem)
- {
-
- ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath());
- }
- else
- {
-
- ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx32.zip"), FileToolsCommon.GetFileAbsolutePath());
- }
- }
- catch (Exception)
- {
- ZipHelper.UnZip(FileToolsCommon.GetFileAbsolutePath("/ffmpegx64.zip"), FileToolsCommon.GetFileAbsolutePath());
- }
- }
- }).Start();
- }
- #endregion
-
- #region 检测安装Screen Capturer Recorder
-
-
-
-
- public static bool CheckScreenCapturerRecorder()
- {
- if (FileToolsCommon.CheckSoftWartInstallState("Screen Capturer Recorder"))
- {
-
- return true;
- }
- else
- {
- return false;
- }
- }
-
-
-
-
- public static bool InstallScreenCapturerRecorder()
- {
- Process InstallProcess = new Process();
- string StandardError = "";
- string StandardOutput = "";
- try
- {
- InstallProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/SSCR/Setup Screen Capturer Recorder v0.12.10.exe");
- InstallProcess.StartInfo.UseShellExecute = false;
- InstallProcess.StartInfo.RedirectStandardError = true;
- InstallProcess.StartInfo.RedirectStandardOutput = true;
- InstallProcess.StartInfo.CreateNoWindow = true;
- InstallProcess.StartInfo.RedirectStandardInput = true;
-
- InstallProcess.ErrorDataReceived += new DataReceivedEventHandler(InstallProcess_ErrorDataReceived);
- InstallProcess.Start();
- InstallProcess.WaitForExit();
- StandardError = InstallProcess.StandardError.ReadToEnd();
- StandardOutput = InstallProcess.StandardOutput.ReadToEnd();
- int ExitCode = InstallProcess.ExitCode;
- InstallProcess.Close();
- InstallProcess.Dispose();
- if (ExitCode == 0)
- {
- return true;
- }
- else
- {
- MessageBoxResult br = MessageWindow.Show("不安装环境将无法使用微课录制系统,是否现在安装?", "安装", MessageBoxButton.OKCancel);
- if (br == MessageBoxResult.OK)
- {
- return InstallScreenCapturerRecorder();
- }
- else
- {
- return false;
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + ex.Message, ex);
- if (string.IsNullOrWhiteSpace(StandardError))
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + StandardError, null);
- }
- if (string.IsNullOrWhiteSpace(StandardOutput))
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装返回信息:" + StandardOutput, null);
- }
- return false;
- }
- }
-
-
-
-
-
- private static void InstallProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
- {
- LogHelper.WriteErrLog("【ScreenCapturerRecorder安装】(installScreenCapturerRecorder)安装失败:" + e.Data, null);
-
- }
-
- #endregion
-
- #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
-
-
-
-
- protected override void OnStartup(StartupEventArgs e)
- {
-
-
-
- new Thread(o =>
- {
- while (true)
- {
- try
- {
-
- FreeMemoryHelper.ReallocateMemory();
- Thread.Sleep(20000);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【释放内存(MyApp)" + ex.Message, ex);
- }
- }
- }).Start();
- }
-
- #endregion 内存处理 -创建人:赵耀 -创建时间:2020年8月12日
-
- #region 测试
- public static void AddTestData()
- {
- testdata = 1;
- }
-
-
-
-
- public static string classRoomImagePath()
- {
-
- string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\"; ;
- return path;
- }
-
-
-
-
-
- public static string dbImagePath()
- {
-
- string path = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
- return path;
- }
-
-
-
-
- public static string GetImagePath(out string ServerSavePath)
- {
- string imagepath = APP.classRoomImagePath();
-
- if (!Directory.Exists(imagepath))
- {
- Directory.CreateDirectory(imagepath);
- }
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- string filepath = Path.Combine(imagepath, timestr + ".jpg");
-
- ServerSavePath = APP.dbImagePath() + timestr + ".jpg";
- return filepath;
- }
- #endregion
-
- #region 写入注册表
-
-
-
- public static RegistryHelper reg = new RegistryHelper("XHZB\\", RegDomain.ClassesRoot);
-
- public static void WriteRegistry()
- {
- if(IsSubKeyExist())
- {
-
- string regStr = ReadRegeditKey();
- string pathStr = FileToolsCommon.GetFileAbsolutePath("/星火直播.exe").Replace("/","\\\\");
- if(regStr!= pathStr)
- {
-
- }
- }
- else
- {
-
- }
- }
-
-
-
- public static bool IsSubKeyExist()
- {
- return reg.IsSubKeyExist();
- }
-
-
-
-
- public static string ReadRegeditKey()
- {
- if(reg.IsRegeditKeyExist("URL Protocol"))
- {
- return reg.ReadRegeditKey("URL Protocol").ToString();
- }
- else
- {
- return "";
- }
- }
-
- public static void CreateRegeditKey()
- {
- reg.CreateSubKey();
- string pathStr = FileToolsCommon.GetFileAbsolutePath("/星火直播.exe").Replace("/", "\\\\");
- reg.WriteRegeditKey("@","星火直播");
- reg.WriteRegeditKey("URL Protocol", pathStr);
-
-
- RegistryHelper reg1 = new RegistryHelper("XHZB\\DefaultIcon\\", RegDomain.ClassesRoot);
- reg1.CreateSubKey();
- reg1.WriteRegeditKey("@", pathStr+",1");
-
-
- RegistryHelper reg2 = new RegistryHelper("XHZB\\shell\\open\\command\\", RegDomain.ClassesRoot);
- reg2.CreateSubKey();
- reg2.WriteRegeditKey("@", "\""+pathStr + "\"\"%1\"");
-
-
-
-
-
-
-
-
-
-
-
- }
- #endregion
- }
- }
|