public static void DumpSystemInfo() { OperatingSystemInfo osInfo = OperatingSystemInfo.GetOperatingSystemInfo(); Console.WriteLine(""); Console.WriteLine("---------------------------------"); Console.WriteLine($"OS Name: {osInfo.Name}"); Console.WriteLine($"Architecture: {osInfo.Architecture}"); Console.WriteLine($".NET Framework: {GetCurrentFrameworkVersionBasedOnWindowsRegistry()} (CLR {osInfo.FrameworkVersion})"); Console.WriteLine(""); // CPUs int idx = 0; foreach (CPUInfo cpuInfo in osInfo.Hardware.CPUs) { Console.WriteLine($"CPU {idx}"); Console.WriteLine($" Brand: {cpuInfo.Brand}"); Console.WriteLine($" Name: {cpuInfo.Name}"); Console.WriteLine($" Architecture: {cpuInfo.Architecture}"); Console.WriteLine($" Cores: {cpuInfo.Cores}"); Console.WriteLine($" Frequency: {cpuInfo.Frequency}"); idx++; } RAMInfo ramInfo = osInfo.Hardware.RAM; Console.WriteLine(""); Console.WriteLine($"RAM {ramInfo.Total:#,###} kilobytes"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); }
private static IFolder GetFolder() { var steamID = string.Empty; if (SteamAPI.Init()) { LogManager.WriteLine("SteamAPI.Init() success."); steamID = SteamUser.GetSteamID().GetAccountID().ToString(); SteamAPI.Shutdown(); LogManager.WriteLine("SteamAPI.Shutdown()."); } else { LogManager.WriteLine("SteamAPI.Init() failure."); switch (OperatingSystemInfo.GetOperatingSystemInfo().OperatingSystemType) { case OperatingSystemType.Windows: if (Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Valve\Steam\ActiveProcess", "ActiveUser", null) is int userID) { steamID = userID.ToString(); } break; default: LogManager.WriteLine("Couldn't get Steam data."); break; } } return(string.IsNullOrEmpty(steamID) ? (IFolder) new NonExistingFolder("") : (IFolder) new SteamUserDataFolder().GetFolder(steamID)); }
public static void DumpSystemInfo() { OperatingSystemInfo osInfo = OperatingSystemInfo.GetOperatingSystemInfo(); Console.WriteLine(""); Console.WriteLine("---------------------------------"); Console.WriteLine($"OS Name: {osInfo.Name}"); Console.WriteLine($"Architecture: {osInfo.Architecture}"); Console.WriteLine($"dotnet RuntimeInformation.FrameworkDescription: {RuntimeInformation.FrameworkDescription}"); Console.WriteLine(""); // CPUs int idx = 0; foreach (CPUInfo cpuInfo in osInfo.Hardware.CPUs) { Console.WriteLine($"CPU {idx}"); Console.WriteLine($" Brand: {cpuInfo.Brand}"); Console.WriteLine($" Name: {cpuInfo.Name}"); Console.WriteLine($" Architecture: {cpuInfo.Architecture}"); Console.WriteLine($" Cores: {cpuInfo.Cores}"); Console.WriteLine($" Frequency: {cpuInfo.Frequency}"); idx++; } RAMInfo ramInfo = osInfo.Hardware.RAM; Console.WriteLine(""); Console.WriteLine($"RAM {ramInfo.Total:#,###} kilobytes"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); }
private static IFolder GetFolder() { if (Settings.Default.RunFactorioViaSteam) { if (SteamAPI.Init()) { LogManager.WriteLine("SteamAPI.Init() success."); SteamAppList.GetAppInstallDir(new AppId_t(427520), out var factorioInstallPath, 260); SteamAPI.Shutdown(); LogManager.WriteLine("SteamAPI.Shutdown()."); return(new FolderFromPath(factorioInstallPath)); } else { LogManager.WriteLine("SteamAPI.Init() failure."); switch (OperatingSystemInfo.GetOperatingSystemInfo().OperatingSystemType) { case OperatingSystemType.Windows: if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 427520", "InstallLocation", null) is string path) { return(new FolderFromPath(path)); } break; default: LogManager.WriteLine("Couldn't get Steam data."); break; } } } else { switch (OperatingSystemInfo.GetOperatingSystemInfo().OperatingSystemType) { case OperatingSystemType.Windows: if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Factorio_is1", "InstallLocation", null) is string path) { return(new FolderFromPath(path)); } break; } return(new FolderFromPath(Settings.Default.FactorioNonSteamFolderPath)); } return(new NonExistingFolder("")); }
private static IFolder GetFolder() { var steamProcess = System.Array.Find(Process.GetProcessesByName("steam"), p => p.MainModule.FileVersionInfo.CompanyName.Equals("Valve Corporation") && p.MainModule.FileVersionInfo.ProductName.Equals("Steam Client Bootstrapper")); if (steamProcess != null) { return(new FolderFromPath(System.IO.Path.GetDirectoryName(steamProcess.MainModule.FileName))); } switch (OperatingSystemInfo.GetOperatingSystemInfo().OperatingSystemType) { case OperatingSystemType.Windows: return(Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Valve\Steam", "SteamPath", null) is string steamPath ? (IFolder) new FolderFromPath(steamPath) : (IFolder) new NonExistingFolder("")); default: LogManager.WriteLine("Couldn't get Steam folder."); break; } return(new NonExistingFolder("")); }
private void GetInfo() { ushort i = 0; ushort j = 0; while (true) { if (_abort) { break; } i++; j++; if (ushort.MaxValue - i < 100) { i = 0; } if (ushort.MaxValue - j < 100) { j = 0; } lock (_lockObj) { if ((j % 10 == 0 || j == 1)) //10秒更新一次内存情况 { _operatingSystemInfo = null !; _operatingSystemInfo = OperatingSystemInfo.GetOperatingSystemInfo(); _operatingSystemType = _operatingSystemInfo.OperatingSystemType; _globalSystemInfo.MemoryInfo = getMeminfo(); } if (i % 120 == 0 || i == 1) //2分钟更新一次硬盘情况 { _globalSystemInfo.DriveInfo = DiskInfoValue.GetDrivesInfo(); } switch (_operatingSystemType) { case OperatingSystemType.Windows: _globalSystemInfo.CpuLoad = CPUWinLoadValue.CPULOAD; _globalSystemInfo.NetWorkStat = NetWorkWinValue3.GetNetworkStat(); break; case OperatingSystemType.MacOSX: _globalSystemInfo.CpuLoad = CPUMacOSLoadValue.CPULOAD; _globalSystemInfo.NetWorkStat = NetWorkMacValue.GetNetworkStat(); break; case OperatingSystemType.Linux: _globalSystemInfo.CpuLoad = CPULinuxLoadValue.CPULOAD; _globalSystemInfo.NetWorkStat = NetWorkLinuxValue.GetNetworkStat(); break; } _globalSystemInfo.UpdateTime = DateTime.Now; } Thread.Sleep(1000); } }
public static void CatchError(this Exception ex) { try { OperatingSystemInfo osInfo = OperatingSystemInfo.GetOperatingSystemInfo(); string errorLog = $@"[CODE] Pokemon 3D Server Application Crash Log v{Core.Settings.Application.Version.ToString()} -------------------------------------------------- System specifications: Software: OS: {osInfo.Name} {osInfo.Architecture} [{(Type.GetType("Mono.Runtime") != null ? "Mono" : ".NET")}] Language: {CultureInfo.CurrentCulture.EnglishName}, LCID {osInfo.LocaleID} Framework: Version {osInfo.FrameworkVersion} Hardware: CPU: Physical count: {osInfo.Hardware.CPUs.Count} Name: {osInfo.Hardware.CPUs.First().Name} Brand: {osInfo.Hardware.CPUs.First().Brand} Architecture: {osInfo.Hardware.CPUs.First().Architecture} Cores: {osInfo.Hardware.CPUs.First().Cores} GPU: Physical count: {(Type.GetType("Mono.Runtime") != null ? "0" : osInfo.Hardware.GPUs.Count.ToString())} Name: {(Type.GetType("Mono.Runtime") != null ? "" : osInfo.Hardware.GPUs.First().Name)} Brand: {(Type.GetType("Mono.Runtime") != null ? "" : osInfo.Hardware.GPUs.First().Brand)} Resolution: {(Type.GetType("Mono.Runtime") != null ? "0x0" : osInfo.Hardware.GPUs.First().Resolution)} {(Type.GetType("Mono.Runtime") != null ? "0" : osInfo.Hardware.GPUs.First().RefreshRate.ToString())} Hz Memory Total: {(Type.GetType("Mono.Runtime") != null ? "0" : osInfo.Hardware.GPUs.First().MemoryTotal.ToString())} KB RAM: Memory Total: {osInfo.Hardware.RAM.Total} KB Memory Free: {osInfo.Hardware.RAM.Free} KB -------------------------------------------------- Error information: Message: {ex.Message} InnerException: {GenerateInnerExceptionMessage(ex)} Source: {ex.Source} -------------------------------------------------- CallStack: {GenerateInnerExceptionStackTrace(ex)} -------------------------------------------------- You should report this error if it is reproduceable or you could not solve it by yourself. Go to: <INSERTURL> to report this crash. [/CODE]"; DateTime errorTime = DateTime.Now; int randomIndetifier = MathHelper.Random(0, int.MaxValue); string Path = $"{Core.Settings.Directories.CrashLogDirectory}/Crash_{errorTime.ToString("yyyy-MM-dd_HH.mm.ss")}.{randomIndetifier.ToString("0000000000")}.dat".GetFullPath(); using (StreamWriter writer = new StreamWriter(new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite), Encoding.UTF8)) { writer.WriteLine(errorLog); writer.Flush(); } Core.Logger.Log(ex.Message + Environment.NewLine + $"Error Log saved at: {Path}", "Error"); } catch (Exception ex2) { Core.Logger.Log(ex2.Message + Environment.NewLine + GenerateInnerExceptionStackTrace(ex2), "Error"); } }
private void GetInfo() { ushort i = 0; ushort j = 0; while (true) { if (_abort) { break; } i++; j++; if (ushort.MaxValue - i < 100) { i = 0; } if (ushort.MaxValue - j < 100) { j = 0; } lock (_lockObj) { if ((j % 10 == 0 || j == 1) && _operatingSystemType != OperatingSystemType.Windows) //10秒更新一次内存情况 { _operatingSystemInfo = null !; _hardwareInfo = null !; _operatingSystemInfo = OperatingSystemInfo.GetOperatingSystemInfo(); _hardwareInfo = _operatingSystemInfo.Hardware; _operatingSystemType = _operatingSystemInfo.OperatingSystemType; _globalSystemInfo.MemoryInfo = getMeminfo(); } if (i % 120 == 0 || i == 1) //2分钟更新一次硬盘情况 { _globalSystemInfo.DriveInfo = DiskInfoValue.GetDrivesInfo(); } switch (_operatingSystemType) { case OperatingSystemType.Windows: _globalSystemInfo.CpuLoad = CPUWinLoadValue.CPULOAD; /* * 由于.net core下无法正确获取到windows的流量信息,这边将Windows系统的网络参数略过 * 在Windows平台上,需要自己把各配置文件写好,系统自动生成可能会存在问题 */ //_globalSystemInfo.NetWorkStat = NetWorkWinValue.GetNetworkStat(); _globalSystemInfo.NetWorkStat = new NetWorkStat(); _globalSystemInfo.NetWorkStat.Mac = "00:00:00:00:00"; _globalSystemInfo.NetWorkStat.UpdateTime = DateTime.Now; _globalSystemInfo.NetWorkStat.CurrentRecvBytes = 0; _globalSystemInfo.NetWorkStat.CurrentSendBytes = 0; _globalSystemInfo.NetWorkStat.TotalRecvBytes = 0; _globalSystemInfo.NetWorkStat.TotalSendBytes = 0; if ((j % 10 == 0 || j == 1) && _operatingSystemType == OperatingSystemType.Windows) //10秒更新一次内存情况 { _globalSystemInfo.MemoryInfo = MemoryWinValue.GetMemoryStatus(); } break; case OperatingSystemType.MacOSX: _globalSystemInfo.CpuLoad = CPUMacOSLoadValue.CPULOAD; _globalSystemInfo.NetWorkStat = NetWorkMacValue.GetNetworkStat(); break; case OperatingSystemType.Unix: _globalSystemInfo.CpuLoad = CPULinuxLoadValue.CPULOAD; _globalSystemInfo.NetWorkStat = NetWorkLinuxValue.GetNetworkStat(); break; } _globalSystemInfo.UpdateTime = DateTime.Now; } Thread.Sleep(1000); } }
private static IFolder GetFolder() => OperatingSystemInfo.GetOperatingSystemInfo().OperatingSystemType switch {
public static string LogCrash(Exception ex) { //return String.Empty; try { OperatingSystemInfo osInfo = OperatingSystemInfo.GetOperatingSystemInfo(); int w32ErrorCode = -1; var w32 = ex as Win32Exception; if (w32 != null) { w32ErrorCode = w32.ErrorCode; } string logName = ""; var _with1 = DateTime.Now.ToLocalTime(); string month = _with1.Month.ToString(NumberFormatInfo.InvariantInfo); if (month.Length == 1) { month = "0" + month; } string day = _with1.Day.ToString(NumberFormatInfo.InvariantInfo); if (day.Length == 1) { day = "0" + day; } string hour = _with1.Hour.ToString(NumberFormatInfo.InvariantInfo); if (hour.Length == 1) { hour = "0" + hour; } string minute = _with1.Minute.ToString(NumberFormatInfo.InvariantInfo); if (minute.Length == 1) { minute = "0" + minute; } string second = _with1.Second.ToString(NumberFormatInfo.InvariantInfo); if (second.Length == 1) { second = "0" + second; } logName = _with1.Year + "-" + month + "-" + day + "_" + hour + "." + minute + "." + second + "_crash.dat"; string ContentPacks = "{}"; if ((Core.GameOptions != null)) { ContentPacks = Core.GameOptions.ContentPackNames.ArrayToString(); } string GameMode = "[No GameMode loaded]"; if ((GameModeManager.ActiveGameMode != null)) { GameMode = GameModeManager.ActiveGameMode.Name; } string OnlineInformation = "GameJolt Account: FALSE"; if ((Core.Player != null)) { OnlineInformation = "GameJolt Account: " + Core.Player.IsGameJoltSave.ToString(NumberFormatInfo.InvariantInfo).ToUpper(); if (Core.Player.IsGameJoltSave) { OnlineInformation += " (" + Core.GameJoltSave.GameJoltID + ")"; } } string ScriptInfo = "Actionscript: No script running"; if ((Core.CurrentScreen != null)) { if (Core.CurrentScreen.Identification == Screen.Identifications.OverworldScreen) { if (!((BaseOverworldScreen)Core.CurrentScreen).ActionScriptIsReady) { ScriptInfo = "Actionscript: " + ActionScript.CSL().ScriptName + "; Line: " + ActionScript.CSL().CurrentLine; } } } string ServerInfo = "FALSE"; if (BaseConnectScreen.Connected) { ServerInfo = "TRUE (" + BaseJoinServerScreen.SelectedServer.GetName() + "/" + BaseJoinServerScreen.SelectedServer.GetAddressString() + ")"; } string GameEnvironment = "[No Game Environment loaded]"; if ((Core.CurrentScreen != null)) { GameEnvironment = Core.CurrentScreen.Identification.ToString(); } string IsSandboxMode = "False"; if ((Core.Player != null)) { IsSandboxMode = Core.Player.SandBoxMode.ToString(NumberFormatInfo.InvariantInfo); } string gameInformation = GameController.GAMENAME + " " + GameController.GAMEDEVELOPMENTSTAGE + " version: " + GameController.GAMEVERSION + " (" + GameController.RELEASEVERSION + ")" + Environment.NewLine + "Content Packs: " + ContentPacks + Environment.NewLine + "Active GameMode: " + GameMode + Environment.NewLine + OnlineInformation + Environment.NewLine + "Playing on Servers: " + ServerInfo + Environment.NewLine + "Game Environment: " + GameEnvironment + Environment.NewLine + ScriptInfo + Environment.NewLine + "File Validation: " + Security.FileValidation.IsValid(true).ToString(NumberFormatInfo.InvariantInfo) + Environment.NewLine + "Sandboxmode: " + IsSandboxMode; string ScreenState = "[Screen state object not available]"; if ((Core.CurrentScreen != null)) { ScreenState = "Screen state for the current screen (" + Core.CurrentScreen.Identification + ")" + Environment.NewLine + Environment.NewLine + Core.CurrentScreen.GetScreenStatus(); } string architectureString = "32 Bit"; if (Environment.Is64BitOperatingSystem == true) { architectureString = "64 Bit"; } var specs = $@"Software: OS: {osInfo.Name} {osInfo.Architecture} [{(Type.GetType("Mono.Runtime") != null ? "Mono" : ".NET")}] Language: {CultureInfo.CurrentCulture.EnglishName}, LCID {osInfo.LocaleID} Framework: Version {osInfo.FrameworkVersion} Hardware: {RecursiveCPU(osInfo.Hardware.CPUs, 0)} {RecursiveGPU(osInfo.Hardware.GPUs, 0)} RAM: Memory Total: {osInfo.Hardware.RAM.Total} KB Memory Free: {osInfo.Hardware.RAM.Free} KB"; /* * string specs = "Operating system: " + osInfo.Name + " [" + Environment.OSVersion + "]" + * Environment.NewLine + "Core architecture: " + architectureString + Environment.NewLine + * "System time: " + DateTime.Now.ToLocalTime().ToString(NumberFormatInfo.InvariantInfo) + * Environment.NewLine + "System language: " + CultureInfo.CurrentCulture.EnglishName + * "(" + CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName + * ") / Loaded game language: " + Localization.Language.Name + Environment.NewLine + * "Decimal separator: " + GameController.DecSeparator + Environment.NewLine + * "Available physical memory: " + osInfo.Hardware.RAM.Free + * "Available logical processors: " + * Environment.ProcessorCount.ToString(NumberFormatInfo.InvariantInfo); */ string innerException = "NOTHING"; if ((ex.InnerException != null)) { innerException = ex.InnerException.Message; } string message = "NOTHING"; if ((ex.Message != null)) { message = ex.Message; } string source = "NOTHING"; if ((ex.Source != null)) { source = ex.Source; } string StackTrace = "NOTHING"; if ((ex.StackTrace != null)) { StackTrace = ex.StackTrace; } string helpLink = "No helplink available."; if ((ex.HelpLink != null)) { helpLink = ex.HelpLink; } Exception BaseException = ex.GetBaseException(); string data = "NOTHING"; /* * if ((ex.Data != null)) * { * data = "Items: " + ex.Data.Count; * if (ex.Data.Count > 0) * { * data = ""; * for (var i = 0; i <= ex.Data.Count - 1; i++) * { * if (!string.IsNullOrEmpty(data)) * { * data += Environment.NewLine; * } * data += "[" + ex.Data.Keys[i].ToString(NumberFormatInfo.InvariantInfo) + ": \"" + ex.Data.Values[i].ToString(NumberFormatInfo.InvariantInfo) + "\"]"; * } * } * } */ ErrorInformation informationItem = new ErrorInformation(ex); //ObjectDump objDump = new ObjectDump(Core.CurrentScreen); //string screenDump = objDump.Dump; string screenDump = ""; string content = "Kolben Games Crash Log V " + LOGVERSION + Environment.NewLine + GameController.GAMENAME + " has crashed!" + Environment.NewLine + "// " + ErrorHeaders[new Random().Next(0, ErrorHeaders.Length)] + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + "Game information:" + Environment.NewLine + Environment.NewLine + gameInformation + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + ScreenState + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + "System specifications:" + Environment.NewLine + Environment.NewLine + specs + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + ".Net installation information:" + Environment.NewLine + Environment.NewLine + DotNetVersion.GetInstalled() + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + "Error information:" + Environment.NewLine + Environment.NewLine + "Message: " + message + Environment.NewLine + "InnerException: " + innerException + Environment.NewLine + "BaseException: " + BaseException.Message + Environment.NewLine + "HelpLink: " + helpLink + Environment.NewLine + "Data: " + data + Environment.NewLine + "Source: " + source + Environment.NewLine + "Win32 Errorcode: " + w32ErrorCode.ToString(NumberFormatInfo.InvariantInfo) + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + informationItem + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + "CallStack: " + Environment.NewLine + Environment.NewLine + StackTrace + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + "Enviornment dump: " + Environment.NewLine + Environment.NewLine + screenDump + Environment.NewLine + Environment.NewLine + CRASHLOGSEPARATOR + Environment.NewLine + Environment.NewLine + "You should report this error." + Environment.NewLine + Environment.NewLine + "Go to \"http://pokemon3d.net/forum/forums/6/create-thread\" to report this crash there."; File.WriteAllText(GameController.GamePath + "\\" + logName, content); Interaction.MsgBox(GameController.GAMENAME + " has crashed!" + Environment.NewLine + "---------------------------" + Environment.NewLine + Environment.NewLine + "Here is further information:" + Environment.NewLine + "Message: " + ex.Message + Environment.NewLine + Environment.NewLine + "You should report this error. When you do this, please attach the crash log to the report. You can find the file in your \"Pokemon\" folder." + Environment.NewLine + Environment.NewLine + "The name of the file is: \"" + logName + "\".", MsgBoxStyle.Critical, "Pokémon3D crashed!"); Process.Start("explorer.exe", "/select,\"" + GameController.GamePath + "\\" + logName + "\""); //Returns the argument to start the launcher with: return("\"CRASHLOG_" + GameController.GamePath + "\\" + logName + "\" " + "\"ERRORTYPE_" + informationItem.ErrorType + "\" " + "\"ERRORID_" + informationItem.ErrorID + "\" " + "\"GAMEVERSION_" + GameController.GAMEDEVELOPMENTSTAGE + " " + GameController.GAMEVERSION + "\" " + "\"CODESOURCE_" + ex.Source + "\" " + "\"TOPSTACK_" + ErrorInformation.GetStackItem(ex.StackTrace, 0) + "\""); } catch (Exception exs) { Interaction.MsgBox(exs.Message + Environment.NewLine + exs.StackTrace); } return(""); }