using AllBase; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Work; namespace _29WxOrder { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main(string[] args) { try { //设置应用程序处理异常方式:ThreadException处理 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); StartUp.Init(); new Initialization().Get(); //BaseClass.IsPinbaobao = true; //BaseClass.Ico = Resource1.icoy; //BaseClass.ToolName = "拍单王"; //GetAuthConfig(); #region 贴牌 //本地缓存文件 string IgPakFile = "locales/ig.pak";//贴牌客服端码 string OenVersionFile = "locales/igv.pak";//贴牌资源配置版本 string IaPakFile = "locales/ia.pak";//logo //string IbPakFile = "locales/ib.pak";//ico string LoPakFile = "locales/lo.pak"; string IcPakFile = "locales/ic.pak";//功能配置 OenMechanism(IgPakFile, OenVersionFile, IaPakFile, LoPakFile, IcPakFile); #endregion //启动界面 LoginForm login = new LoginForm(args); login.ShowDialog(); if (login.DialogResult == DialogResult.OK) { login.Dispose(); Application.Run(new MainForm()); } } catch (Exception ex) { string str = GetExceptionMsg(ex, string.Empty); NaiBa.Util.Helper.LogHelper.WriteWithTime("SystemError:" + str); MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { string str = GetExceptionMsg(e.Exception, e.ToString()); NaiBa.Util.Helper.LogHelper.WriteWithTime("SystemError:" + str); MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); //LogManager.WriteLog(str); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString()); NaiBa.Util.Helper.LogHelper.WriteWithTime("SystemError:" + str); MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); //LogManager.WriteLog(str); } /// /// 生成自定义异常消息 /// /// 异常对象 /// 备用异常消息:当ex为null时有效 /// 异常字符串文本 static string GetExceptionMsg(Exception ex, string backStr) { StringBuilder sb = new StringBuilder(); sb.AppendLine("****************************异常文本****************************"); sb.AppendLine("【出现时间】:" + DateTime.Now.ToString()); if (ex != null) { sb.AppendLine("【异常类型】:" + ex.GetType().Name); sb.AppendLine("【异常信息】:" + ex.Message); sb.AppendLine("【堆栈调用】:" + ex.StackTrace); } else { sb.AppendLine("【未处理异常】:" + backStr); } sb.AppendLine("***************************************************************"); NaiBa.Util.Helper.LogHelper.WriteWithTime("Error:" + sb); return sb.ToString(); } #region 贴牌 /// /// Oen贴牌机制 /// /// 贴牌商客户端码文件 /// 贴牌配置版本号文件 /// ico本地缓存文件 /// logo本地缓存文件 /// 贴牌配置本地缓存文件 private static void OenMechanism(string IgPakFile, string OenVersionFile, string IaPakFile, string LogoBitmapFile, string IcPakFile) { //先检测是否是贴牌版本 if (!FileBase.Exists(IgPakFile)) { return; } string sOenCode = FileBase.ReadAllText(IgPakFile); if (string.IsNullOrEmpty(sOenCode)) { MessageBox.Show("缺少配置数据,请重试或联系客服\r\nMissing ig", "提示"); Process.GetCurrentProcess().Kill(); return; } string data = UserLogin.GetSignaturex() + "&agent_code=" + sOenCode; string url = BaseClass.Build29WxObjString("oem_config&act=get_version"); string html = GetHtml.PostUtf8(url, data); string oem_version = "0"; if (JObject.Parse(html)["code"].ToString() == "200") { oem_version = JObject.Parse(html)["data"].ToString(); data = UserLogin.GetSignaturex() + "&agent_code=" + sOenCode; url = BaseClass.Build29WxObjString("oem_config&act=get_config_info"); if (Convert.ToInt32(oem_version) > BaseClass.oem_version) { html = GetHtml.PostUtf8(url, data); if (JObject.Parse(html)["code"].ToString() == "200") { //还差 判断没有贴牌文件就自动下载, 把贴牌图标引用到所有窗体中 string agent_name = JObject.Parse(html)["data"]["agent_name"].ToString(); string softname = JObject.Parse(html)["data"]["oem_title"].ToString(); string oem_logo_link = JObject.Parse(html)["data"]["oem_logo_link"].ToString();//logo图片 ia string oem_icon_link = JObject.Parse(html)["data"]["oem_icon_link"].ToString();//icon图片 ib string version = JObject.Parse(html)["data"]["version"].ToString(); FileBase.WriteAllText(OenVersionFile, version); FileBase.WriteAllText(IcPakFile, agent_name + "\r\n" + softname); if (!GetHtml.DownloadFile(oem_logo_link, IaPakFile))//logo图片 { OenArchieveFailedToExit(); } if (!GetHtml.DownloadFile(oem_icon_link, LogoBitmapFile))//icon图片 { OenArchieveFailedToExit(); } } else { MessageBox.Show("缺少配置数据,请重试或联系客服\r\nError19238", "提示"); Process.GetCurrentProcess().Kill(); return; } } if (!FileBase.Exists(IaPakFile)) { html = GetHtml.PostUtf8(url, data); string oem_logo_link = JObject.Parse(html)["data"]["oem_logo_link"].ToString();//logo图片 ia if (JObject.Parse(html)["code"].ToString() == "200") { if (!GetHtml.DownloadFile(oem_logo_link, IaPakFile))//logo图片 { OenArchieveFailedToExit(); } } } if (!FileBase.Exists(LogoBitmapFile)) { html = GetHtml.PostUtf8(url, data); string oem_icon_link = JObject.Parse(html)["data"]["oem_icon_link"].ToString();//icon图片 ib if (JObject.Parse(html)["code"].ToString() == "200") { if (!GetHtml.DownloadFile(oem_icon_link, IaPakFile))//logo图片 { OenArchieveFailedToExit(); } } } if (!FileBase.Exists(IcPakFile)) { html = GetHtml.PostUtf8(url, data); if (JObject.Parse(html)["code"].ToString() == "200") { string agent_name = JObject.Parse(html)["data"]["agent_name"].ToString(); string softname = JObject.Parse(html)["data"]["oem_title"].ToString(); FileBase.WriteAllText(IcPakFile, agent_name + "\r\n" + softname); } } } else { MessageBox.Show("缺少配置数据,请重试或联系客服\r\nError26730", "提示"); Process.GetCurrentProcess().Kill(); return; } #region 读贴牌 //BaseClass.ProgromLogo = Environment.CurrentDirectory + "\\locales\\ia.pak";//logo //BaseClass.ProgromLogoIco = Environment.CurrentDirectory + "\\locales\\ib.pak";//ico //var config = FileBase.ReadAllText("locales\\ic.pak"); //var configArr = config.Split(new string[] { "\r\n" }, StringSplitOptions.None); //if (configArr.Length >= 2) //{ // BaseClass.ProgramName = configArr[1]; // BaseClass.AgentName = configArr[0]; //} #endregion } /// /// Oen资源有更新 /// /// 服务端版本号 /// 本地版本号 /// private static bool NeedUpdate(int iSvrOenVer, int iLocOenVer) { return iSvrOenVer > iLocOenVer; } /// /// OEN资源无更新,但是本地缓存的资源配置不完整 /// /// 服务端版本号 /// 客户端版本号 /// 本地缓存资源文件ia /// 本地缓存资源文件ib /// 本地缓存资源文件ic /// private static bool LocalOenResourceLost(int iSvrOenVer, int iLocOenVer, string sIaPakFile, string sIbPakFile, string sIcPakFile) { return iSvrOenVer == iLocOenVer && (!FileBase.Exists(sIaPakFile) || !FileBase.Exists(sIbPakFile) || !FileBase.Exists(sIcPakFile)); } /// /// 当OEN贴牌配置数据获取失败时应用程序退出 /// private static void OenArchieveFailedToExit() { LogSave.Add("下载或生成Oen配置出现异常!"); Process.GetCurrentProcess().Kill(); } #endregion } }