static void Main() { RegisterAppDomainExceptionLogging(); if (ShouldQuitWithoutProperDotNetFramework()) { return; } Log4NetLogger.Initialize(); var appInfo = new ApplicationInfo { Version = Application.ProductVersion, OS = Environment.OSVersion.VersionString, DotNet = NetFrameworkVersionExtension.FriendlyName(NewestFrameworkVersion) }; LogServiceLocator.Get(typeof(Program)).Info(appInfo); var pluginTypes = new List <Type> { typeof(Plugin.Autosplits.Plugin), typeof(Plugin.FileWriter.Plugin), typeof(Plugin.HttpClient.Plugin), typeof(Plugin.PipeServer.Plugin), typeof(Plugin.Updater.Plugin), }; using (var di = DiabloInterface.Create(appInfo, pluginTypes)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainWindow(di)); } }
static void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { MessageBox.Show(e.ExceptionObject.ToString(), @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); var logger = LogServiceLocator.Get(typeof(Program)); logger?.Fatal("Unhandled Exception", (Exception)e.ExceptionObject); }
static void LogApplicationInfo() { var logger = LogServiceLocator.Get(typeof(Program)); logger.Info($"Diablo Interface Version {Application.ProductVersion}"); logger.Info($"Operating system: {Environment.OSVersion}"); var versionName = NetFrameworkVersionExtension.FriendlyName(NewestFrameworkVersion); logger.Info($".NET Framework: {versionName}"); }
static DiabloInterfaceServer CreatePipeServer(GameService gameService, SettingsService settingsService) { var logger = LogServiceLocator.Get(typeof(Program)); logger.Info("Initializing pipe server."); var pipeServer = new DiabloInterfaceServer(settingsService.CurrentSettings.PipeName); var dataReader = gameService.DataReader; pipeServer.AddRequestHandler(@"version", () => new VersionRequestHandler(Assembly.GetEntryAssembly())); pipeServer.AddRequestHandler(@"items", () => new AllItemsRequestHandler(dataReader)); pipeServer.AddRequestHandler(@"items/(\w+)", () => new ItemRequestHandler(dataReader)); pipeServer.AddRequestHandler(@"characters/(current|active)", () => new CharacterRequestHandler(dataReader)); pipeServer.AddRequestHandler(@"quests/(\d+)", () => new QuestRequestHandler(dataReader)); return(pipeServer); }
static string GetUpdateUrl() { Match verMatch = Regex.Match(Application.ProductVersion, @"^(\d+)\.(\d+)\.(\d+)(?:\.PR\.(\d+))?$"); if (!verMatch.Success) { return(null); } string location; try { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; HttpWebRequest r = (HttpWebRequest)WebRequest.Create(ReleasesLatestUrl); r.Method = WebRequestMethods.Http.Head; r.AllowAutoRedirect = false; using (var response = r.GetResponse() as HttpWebResponse) { location = response.GetResponseHeader("Location"); } } catch (WebException e) { LogServiceLocator.Get(typeof(VersionChecker)).Error("Failed to retrieve latest release from Url", e); return(null); } Match tagMatch = Regex.Match(location, @"/releases/tag/v(\d+)\.(\d+)\.(\d+)$"); if (!tagMatch.Success) { return(null); } // version compare. int major = Convert.ToInt32(verMatch.Groups[1].Value); int majorNew = Convert.ToInt32(tagMatch.Groups[1].Value); if (majorNew > major) { return(location); } if (majorNew < major) { return(null); } int minor = Convert.ToInt32(verMatch.Groups[2].Value); int minorNew = Convert.ToInt32(tagMatch.Groups[2].Value); if (minorNew > minor) { return(location); } if (minorNew < minor) { return(null); } int patch = Convert.ToInt32(verMatch.Groups[3].Value); int patchNew = Convert.ToInt32(tagMatch.Groups[3].Value); if (patchNew > patch) { return(location); } if (patchNew < patch) { return(null); } try { int pre = Convert.ToInt32(verMatch.Groups[4].Value); if (pre > 0) { return(location); } } catch { } return(null); }