Skip to content

Commit

Permalink
修复openp2p进程崩溃后,自动重启后主进程会卡死
Browse files Browse the repository at this point in the history
修复第一次打开情况下点快捷添加会有没有将类匹配到对象的异常抛出
  • Loading branch information
Guailoudou committed Dec 20, 2024
1 parent dce8c53 commit 40e5adb
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 6 deletions.
7 changes: 5 additions & 2 deletions WpfApp1/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ private IntPtr FindWindowByClassName(string className)

void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show("出现未经处理的异常,如果影响到看功能的使用,可以的话,请将该页面截图给开发者,这有助于解决这个问题: \n" + e.Exception.Message);
e.Handled = true;
MessageBox.Show($"出现未经处理的异常,如果影响到看功能的使用,可以的话,请将该页面截图给开发者,这有助于解决这个问题: \nMessage:{e.Exception.Message}\nSource: {e.Exception.Source}\nStack Trace: {e.Exception.StackTrace}");
Logger.Log($"Message: {e.Exception.Message}","错误");
Logger.Log($"Source: {e.Exception.Source}", "错误");
Logger.Log($"Stack Trace: {e.Exception.StackTrace}", "错误");
e.Handled = true;
}
}
}
24 changes: 21 additions & 3 deletions WpfApp1/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using ColorConverter = System.Windows.Media.ColorConverter;
using FontFamily = System.Windows.Media.FontFamily;
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
using System.Threading;

namespace OPL_WpfApp
{
Expand Down Expand Up @@ -489,7 +490,7 @@ private void Button_Click_open(object sender, RoutedEventArgs e)
Strapp();
else
{
MessageBox.Show("暂时无法启动,正在进行关键文件下载,请等待片刻,如果下载失败可以尝试下载压缩包,并解压使用,完成下载后会有弹窗提示", "提示");
MessageBox.Show("暂时无法启动,正在进行关键文件下载,请等待片刻后再试,如果下载失败可以尝试下载压缩包,并解压使用,完成下载后会有日志提示", "提示");
}

}
Expand Down Expand Up @@ -890,7 +891,7 @@ private void Quick_Add(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{
Logger.Log($"无法识别的连接码: {pastedText} - {ex.Message}");
Logger.Log($"无法识别的连接码: {pastedText} - {ex.Message} - {ex.Source} - {ex.StackTrace}");
MessageBox.Show($"无法识别的连接码: {pastedText} \n请复制连接码后点击\r该功能为一键添加/编辑隧道为连接码隧道,房主可直接编辑发送连接码供连接方使用。 \r\r连接码用法: \r用法1:\r uid:端口 --> tcp协议连接码 \r示例:qwertyuioop:25565 \r\r 用法2:\r<1/2>:uid:端口[:本地端口] --> 1为tcp,2为udp 本地端口可省略\r示例:1:qwertyuiop:25565:25575 \r多个连接可以用;间隔同时输入\r复制后直接点击该按钮即可完成添加,后直接启动即可 \r如果确认你复制的符合格式,可尝试点击右边按钮自行添加隧道\r\r {ex.Message}", "错误");
}
}
Expand Down Expand Up @@ -1023,7 +1024,24 @@ async Task DelayAndExecute()
{
Logger.Log("将在2s后自动重新启动...");
await Task.Delay(2000);
Strapp();

// 假设这是一个需要在主线程上执行的方法
Action actionOnMainThread = () =>
{
// 调用主进程中的方法
Strapp();
};

if (SynchronizationContext.Current != null)
{
// 如果存在同步上下文,则使用它来调度操作
SynchronizationContext.Current.Post(state => actionOnMainThread(), null);
}
else
{
// 如果没有同步上下文(例如控制台应用程序),则直接调用
actionOnMainThread();
}
}
private void Initialization(bool temp =false)
{
Expand Down
4 changes: 4 additions & 0 deletions WpfApp1/cs/json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public void Add1link(string type, string uid, int port,int cport)
public int Finduid(string uid,string type)
{
int index = 0;
if (config.Apps == null)
{
return -1;
}
foreach (App app in config.Apps)
{
if (app.PeerNode==uid && app.Protocol==type && !oindex.Contains(index))
Expand Down
2 changes: 1 addition & 1 deletion WpfApp1/cs/net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace userdata
{
internal class Net
{
private static readonly int pvn = 46;//协议版本号
private static readonly int pvn = 47;//协议版本号
public static int Getpvn()
{
return pvn;
Expand Down
73 changes: 73 additions & 0 deletions updata/Properties/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 清单选项
如果想要更改 Windows 用户帐户控制级别,请使用
以下节点之一替换 requestedExecutionLevel 节点。
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
如果你的应用程序需要此虚拟化来实现向后兼容性,则移除此
元素。
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
Windows 版本的列表。取消评论适当的元素,
Windows 将自动选择最兼容的环境。 -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- 指示该应用程序可感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
选择加入。选择加入此设置的 Windows 窗体应用程序(面向 .NET Framework 4.6)还应
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。
将应用程序设为感知长路径。请参阅 https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
37 changes: 37 additions & 0 deletions updata/updata.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -32,6 +47,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -60,6 +84,19 @@
<ItemGroup>
<EmbeddedResource Include="App.config" />
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 和 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit 40e5adb

Please sign in to comment.