🐛 修复了某些路径无法建立相对路径导致程序启动崩溃的bug

This commit is contained in:
liufei
2022-06-17 10:03:35 +08:00
parent 240008ce2c
commit 001d807bb3
7 changed files with 82 additions and 26 deletions

View File

@@ -54,7 +54,7 @@
</assemblyBinding>
</runtime>
<appSettings>
<add key="Version" value="2.5.10" />
<add key="Version" value="2.5.11" />
<add key="GitHubUrl" value="https://github.com/BookerLiu/GeekDesk" />
<add key="GiteeUrl" value="https://gitee.com/BookerLiu/GeekDesk/tree/master" />
<add key="GitHubUpdateUrl" value="https://raw.githubusercontent.com/BookerLiu/GeekDesk/master/Update.json" />

View File

@@ -265,6 +265,7 @@
<Compile Include="Converts\HideTypeConvert.cs" />
<Compile Include="Interface\IWindowCommon.cs" />
<Compile Include="MyThread\RelativePathThread.cs" />
<Compile Include="Task\ShowSecondTask.cs" />
<Compile Include="Task\ToDoTask.cs" />
<Compile Include="MyThread\MouseHookThread.cs" />
<Compile Include="MyThread\DispatcherBuild.cs" />

View File

@@ -185,7 +185,7 @@ namespace GeekDesk
{
ShowApp();
}
//ShowSecondTask.SHowSecond();
//给任务栏图标一个名字
BarIcon.Text = Constants.MY_NAME;
@@ -426,17 +426,6 @@ namespace GeekDesk
// return;
//}
MainWindow.mainWindow.Activate();
mainWindow.Show();
//mainWindow.Visibility = Visibility.Visible;
if (appData.AppConfig.AppAnimation)
{
appData.AppConfig.IsShow = true;
} else
{
appData.AppConfig.IsShow = null;
}
if (MarginHide.ON_HIDE)
{
//修改贴边隐藏状态为未隐藏
@@ -452,7 +441,19 @@ namespace GeekDesk
{
ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0);
}
MainWindow.mainWindow.Activate();
mainWindow.Show();
//mainWindow.Visibility = Visibility.Visible;
if (appData.AppConfig.AppAnimation)
{
appData.AppConfig.IsShow = true;
}
else
{
appData.AppConfig.IsShow = null;
}
//FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible);

31
Task/ShowSecondTask.cs Normal file
View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace GeekDesk.Task
{
internal class ShowSecondTask
{
public static void SHowSecond()
{
System.Timers.Timer timer = new System.Timers.Timer
{
Enabled = true,
Interval = 5000
};
timer.Start();
timer.Elapsed += Timer_Elapsed;
}
private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Process[] pcArr = Process.GetProcessesByName("ShellExperienceHost.exe");
Thread.Sleep(1000);
}
}
}

View File

@@ -1,9 +1,9 @@
{
"title": "GeekDesk版本更新",
"subTitle": "V2.5.10",
"subTitle": "V2.5.11",
"msgTitle": "本次更新内容如下",
"msg": "['依旧耗费了我大量精力开发,希望大家去给我点个免费的Star', '这个版本有一些优化点, 大家可以自行探索, 另外征集新Logo的设计, 要求美观并能体现\\'极客\\'风格','本次重新打包了程序文件(文件目录更清爽了,注意,这次不要使用覆盖升级), 可以将旧版本根目录下的Data文件复制到新版本根目录, 然后使用新版本启动','增加可拖动图标到其它菜单的功能,取消了拖动时的动画','增加了列表展开动画的开关','增加了数据备份功能','优化大部分动画','优化搜索功能(达到了可只用键盘或只用鼠标启动所需目标)','增加了相对路径(实验性,可能有bug)','增加列表加密功能(实验性,可能有bug)','其它已知问题修复']",
"githubUrl": "https://github.com/BookerLiu/GeekDesk/releases",
"giteeUrl": "https://gitee.com/BookerLiu/GeekDesk/releases",
"version": "2.5.10"
"version": "2.5.11"
}

View File

@@ -159,16 +159,23 @@ namespace GeekDesk.Util
public static string MakeRelativePath(string fromPath, string toPath)
{
if (string.IsNullOrEmpty(toPath) || string.IsNullOrEmpty(fromPath)) return null;
Uri file = new Uri(@toPath);
// Must end in a slash to indicate folder
Uri folder = new Uri(@fromPath);
string relativePath =
Uri.UnescapeDataString(
folder.MakeRelativeUri(file)
.ToString()
.Replace('/', Path.DirectorySeparatorChar)
);
string relativePath = null;
try
{
if (string.IsNullOrEmpty(toPath) || string.IsNullOrEmpty(fromPath)) return null;
Uri file = new Uri(@toPath);
// Must end in a slash to indicate folder
Uri folder = new Uri(@fromPath);
relativePath =
Uri.UnescapeDataString(
folder.MakeRelativeUri(file)
.ToString()
.Replace('/', Path.DirectorySeparatorChar)
);
} catch (Exception ex)
{
LogUtil.WriteErrorLog(ex, "建立相对路径出错:fromPath:" + fromPath + ",toPath:" + toPath);
}
return relativePath;
}

View File

@@ -205,6 +205,14 @@ namespace GeekDesk.ViewModel
set
{
name = value;
if (StringUtil.IsEmpty(Path))
{
content = Name + "\n使用次数: " + Count;
}
else
{
content = Path + "\n" + Name + "\n使用次数: " + Count;
}
}
}
@@ -238,6 +246,14 @@ namespace GeekDesk.ViewModel
set
{
path = value;
if (StringUtil.IsEmpty(Path))
{
content = Name + "\n使用次数: " + Count;
}
else
{
content = Path + "\n" + Name + "\n使用次数: " + Count;
}
}
}