VPet/VPet-Simulator.Windows/App.xaml.cs

101 lines
4.2 KiB
C#
Raw Normal View History

2023-08-12 09:58:57 +00:00
using LinePutScript.Localization.WPF;
2024-02-22 14:58:06 +00:00
using System;
2023-10-11 17:24:35 +00:00
using System.Collections.Generic;
using System.IO;
2023-10-12 05:15:54 +00:00
using System.Linq;
2023-08-12 09:58:57 +00:00
using System.Windows;
2023-10-11 17:24:35 +00:00
using VPet_Simulator.Windows.Interface;
2022-12-13 07:10:18 +00:00
namespace VPet_Simulator.Windows
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
2023-01-24 06:56:16 +00:00
public App() : base()
{
2023-01-29 08:27:24 +00:00
#if !DEBUG
2024-02-22 14:58:06 +00:00
base.DispatcherUnhandledException += (s, e) => { e.Handled = true; UnhandledException(e.Exception, false); };
AppDomain.CurrentDomain.UnhandledException += (s, e) => { UnhandledException((e.ExceptionObject as Exception), true); };
2023-01-29 08:27:24 +00:00
#endif
2023-01-24 06:56:16 +00:00
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
2023-10-10 17:03:23 +00:00
public static string[] Args { get; set; }
2023-10-11 17:24:35 +00:00
/// <summary>
/// 多存档系统名称
/// </summary>
public static List<string> MutiSaves { get; set; } = new List<string>();
public static List<MainWindow> MainWindows { get; set; } = new List<MainWindow>();
2023-10-10 17:03:23 +00:00
protected override void OnStartup(StartupEventArgs e)
{
Args = e.Args;
2023-10-11 17:24:35 +00:00
foreach (var mss in new DirectoryInfo(ExtensionValue.BaseDirectory).GetFiles("Setting*.lps"))
{
var n = mss.Name.Substring(7).Trim('-');
MutiSaves.Add(n.Substring(0, n.Length - 4));
}
if (MutiSaves.Count == 0)
{
MutiSaves.Add("");
}
2023-10-10 17:03:23 +00:00
}
2023-01-24 06:56:16 +00:00
2024-02-22 14:58:06 +00:00
private void UnhandledException(Exception e, bool isFatality)
2023-01-24 06:56:16 +00:00
{
2024-02-22 14:58:06 +00:00
var expt = e.ToString();
2024-03-26 11:27:56 +00:00
if (expt.Contains("MainWindow.Close"))
return;
else if ((expt.ToLower().Contains("value") && expt.ToLower().Contains("nan")) ||
expt.Contains("System.OverflowException") || expt.Contains("System.DivideByZeroException"))
2023-08-16 18:21:46 +00:00
{
2023-10-10 17:03:23 +00:00
MessageBox.Show("由于修改游戏数据导致数据溢出,存档可能会出错\n开发者提醒您请不要使用过于超模的MOD".Translate());
2023-08-21 18:26:27 +00:00
return;
}
else if (expt.Contains("System.IO.FileNotFoundException") && expt.Contains("cache"))
{
MessageBox.Show("缓存被其他软件删除,游戏无法继续运行\n请重启游戏重新生成缓存".Translate());
return;
2023-10-10 17:03:23 +00:00
}
else if (expt.Contains("0x80070008"))
2023-08-21 18:26:27 +00:00
{
MessageBox.Show("游戏内存不足,请修改设置中渲染分辨率以便降低内存使用".Translate());
2023-10-12 05:15:54 +00:00
return;
}
2023-11-02 16:01:18 +00:00
else if (expt.Contains("UnauthorizedAccessException"))
{
MessageBox.Show("游戏权限不足,无法写入游戏存档和设置,请检查设置文件是否被其他软件占用".Translate());
return;
}
2023-10-12 05:15:54 +00:00
else if (expt.Contains("VPet.Plugin"))
{
var exptin = expt.Split('\n').First(x => x.Contains("VPet.Plugin"));
2023-11-24 05:41:18 +00:00
exptin = exptin.Substring(exptin.IndexOf("VPet.Plugin") + 12).Split('.')[0];
MessageBox.Show("游戏发生错误,可能是".Translate() + $"MOD({exptin.Translate()})" +
2023-10-12 05:15:54 +00:00
"导致的\n如有可能请发送 错误信息截图和引发错误之前的操作给相应MOD作者\n感谢您对MOD开发的支持\n".Translate()
+ expt, "游戏发生错误,可能是".Translate() + exptin);
return;
2023-08-16 18:21:46 +00:00
}
2023-08-12 09:58:57 +00:00
string errstr = "游戏发生错误,可能是".Translate() + (string.IsNullOrWhiteSpace(CoreMOD.NowLoading) ?
"游戏或者MOD".Translate() : $"MOD({CoreMOD.NowLoading})") +
"导致的\n如有可能请发送 错误信息截图和引发错误之前的操作 给开发者:service@exlb.net\n感谢您对游戏开发的支持\n".Translate()
2023-08-16 18:21:46 +00:00
+ expt;
2024-02-22 14:58:06 +00:00
if (isFatality || MainWindow == null)
2023-01-24 06:56:16 +00:00
{
2023-08-13 17:29:45 +00:00
MessageBox.Show(errstr, "游戏致命性错误".Translate());
2023-01-24 06:56:16 +00:00
return;
}
2023-01-24 07:55:02 +00:00
else
{
new winReport(((MainWindow)MainWindow), errstr).Show();
return;
}
2023-01-24 06:56:16 +00:00
}
2022-12-13 07:10:18 +00:00
}
}