Exemplo n.º 1
0
 private static void Handler_GameExit(object sender, GameExitArg arg)
 {
     Console.WriteLine("The game is exit with code:{0}", arg.ExitCode);
     if (arg.ExitCode != 0)
     {
         CrashHelper crashHelper = new CrashHelper();
         crashHelper.GetCrashInfo(handler, arg);
     }
 }
Exemplo n.º 2
0
 private void Handler_GameExit(object sender, GameExitArg arg)
 {
     this.Dispatcher.Invoke(new Action(() =>
     {
         this.WindowState = WindowState.Normal;
         if (!arg.IsNormalExit())
         {
             this.ShowMessageAsync("游戏非正常退出", "这很有可能是因为游戏崩溃导致的,退出代码:" + arg.ExitCode);
         }
     }));
 }
Exemplo n.º 3
0
 private void Handler_GameExit(object sender, GameExitArg arg)
 {
     this.Dispatcher.Invoke(new Action(() =>
     {
         this.WindowState = WindowState.Normal;
         if (!arg.IsNormalExit())
         {
             this.ShowMessageAsync("游戏非正常退出",
                                   string.Format("这很有可能是因为游戏崩溃导致的,退出代码:{0},游戏持续时间:{1}",
                                                 arg.ExitCode, arg.Duration));
         }
     }));
 }
Exemplo n.º 4
0
        public string GetCrashInfo(LaunchHandler handler, GameExitArg exitArg)
        {
            if (!exitArg.Process.HasExited)
            {
                throw new Exception("The game is running.");
            }
            if (exitArg.IsNormalExit())
            {
                throw new ArgumentException("It seems that the game is safe exit.Exit code equal zero");
            }
            Process  process        = exitArg.Process;
            DateTime launchTime     = process.StartTime;
            DateTime exitTime       = process.ExitTime;
            string   verRootDir     = handler.GetGameVersionRootDir(exitArg.Version);
            string   crashreportDir = verRootDir + "\\crash-reports";
            string   latestlogPath  = verRootDir + "\\logs\\latest.log";

            if (Directory.Exists(crashreportDir))
            {
                var files = Directory.EnumerateFiles(crashreportDir);
                var logs  = files.Where((x) =>
                {
                    string time = Path.GetFileName(x).Substring(6, 19).Replace('-', '/').Replace('_', ' ').Replace('.', ':');
                    if (DateTime.TryParse(time, out DateTime logtime))
                    {
                        return((launchTime < logtime) && (logtime < exitTime));
                    }
                    else
                    {
                        return(false);
                    }
                });
                if (logs.Count() != 0)
                {
                    return(File.ReadAllText(logs.FirstOrDefault()));
                }
                else
                {
                    return(null);
                }
            }

            //没有崩溃日志直接查找log
            else if (File.Exists(latestlogPath))
            {
                DateTime lastWrtTime = File.GetLastWriteTime(latestlogPath);
                if ((launchTime < lastWrtTime) && (lastWrtTime < exitTime))
                {
                    string[]      allLogArr = File.ReadAllLines(latestlogPath);
                    List <int>    valiLogNo = new List <int>();
                    bool          keepRead  = false;
                    StringBuilder builder   = new StringBuilder();
                    for (int i = 0; i < allLogArr.Length; i++)
                    {
                        string current = allLogArr[i];

                        if (keepRead)
                        {
                            builder.AppendLine(allLogArr[i - 1]);
                        }

                        //最简单的检查
                        if (!current.StartsWith("["))
                        {
                            continue;
                        }

                        //寻找第一个固定要素区块
                        var firstLBrac = current.IndexOf('[');
                        if (firstLBrac == -1)
                        {
                            continue;
                        }
                        var firstRBrac = current.IndexOf(']');
                        if (firstRBrac == -1)
                        {
                            continue;
                        }
                        var firstBlock = current.Substring(firstLBrac + 1, firstRBrac - firstLBrac - 1);

                        //寻找第二个固定要素区块
                        var secondLBrac = current.IndexOf('[', firstRBrac);
                        if (secondLBrac == -1)
                        {
                            continue;
                        }
                        var secondRBrac = current.IndexOf(']', secondLBrac);
                        if (secondRBrac == -1)
                        {
                            continue;
                        }
                        var secondBlock = current.Substring(secondLBrac + 1, secondRBrac - secondLBrac - 1);

                        if (DateTime.TryParse(firstBlock, out DateTime time))
                        {
                            if (secondBlock.Contains("ERROR"))
                            {
                                keepRead = true;
                            }
                            else
                            {
                                keepRead = false;
                            }
                        }
                    }
                    return(builder.ToString());
                }
                else
                {
                    return(null);
                }
            }

            else
            {
                return(null);
            }
        }