🎉 增加了相对路径

This commit is contained in:
liufei
2022-06-07 16:34:07 +08:00
parent 9d174ed2fc
commit 7d061abadc
7 changed files with 102 additions and 13 deletions

View File

@@ -61,7 +61,7 @@
<add key="GiteeUpdateUrl" value="https://gitee.com/BookerLiu/GeekDesk/raw/master/Update.json" /> <add key="GiteeUpdateUrl" value="https://gitee.com/BookerLiu/GeekDesk/raw/master/Update.json" />
<!--<add key="GiteeUpdateUrl" value="file:///C:/Users/Fei/Desktop/GeekDesk/Update.json" />--> <!--<add key="GiteeUpdateUrl" value="file:///C:/Users/Fei/Desktop/GeekDesk/Update.json" />-->
<add key="ClientSettingsProvider.ServiceUri" value="" /> <add key="ClientSettingsProvider.ServiceUri" value="" />
<add key="CustomIconTeachUrl" value="https://mp.weixin.qq.com/s/LxoHAekho9HBVl4FRw_Law" /> <add key="CustomIconTeachUrl" value="https://mp.weixin.qq.com/s/LxoHAekho9HBVl4FRw_Law" />
</appSettings> </appSettings>
<system.web> <system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider"> <membership defaultProvider="ClientAuthenticationMembershipProvider">

View File

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

View File

@@ -227,13 +227,11 @@ namespace GeekDesk
//更新线程开启 检测更新 //更新线程开启 检测更新
UpdateThread.Update(); UpdateThread.Update();
//自动备份一次数据 //建立相对路径
appData.AppConfig.SysBakTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); RelativePathThread.MakeRelativePath();
CommonCode.SaveAppData(appData, Constants.DATA_FILE_BAK_PATH);
//毛玻璃 暂时未解决阴影问题 //毛玻璃 暂时未解决阴影问题
//BlurGlassUtil.EnableBlur(this); //BlurGlassUtil.EnableBlur(this);
AeroGlassUtil.GlassWindow(this);
} }
/// <summary> /// <summary>

View File

@@ -0,0 +1,39 @@
using GeekDesk.Constant;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace GeekDesk.MyThread
{
public class RelativePathThread
{
public static void MakeRelativePath()
{
new Thread(() =>
{
Thread.Sleep(1000);
ObservableCollection<MenuInfo> menuList = MainWindow.appData.MenuList;
string myExePath = Constants.APP_DIR + "GeekDesk.exe";
foreach (MenuInfo mi in menuList)
{
ObservableCollection<IconInfo> iconList = mi.IconList;
foreach (IconInfo icon in iconList)
{
icon.RelativePath_NoWrite = FileUtil.MakeRelativePath(myExePath, icon.Path);
}
}
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_BAK_PATH);
}).Start();
}
}
}

View File

@@ -94,6 +94,7 @@ namespace GeekDesk.Util
/// <param name="appData"></param> /// <param name="appData"></param>
public static void SaveAppData(AppData appData, string filePath) public static void SaveAppData(AppData appData, string filePath)
{ {
appData.AppConfig.SysBakTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
if (!Directory.Exists(filePath.Substring(0, filePath.LastIndexOf("\\")))) if (!Directory.Exists(filePath.Substring(0, filePath.LastIndexOf("\\"))))
{ {
Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf("\\"))); Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf("\\")));
@@ -161,7 +162,7 @@ namespace GeekDesk.Util
// ext = System.IO.Path.GetExtension(path).ToLower(); // ext = System.IO.Path.GetExtension(path).ToLower();
//} //}
string iconPath = null; string iconPath;
//if (".lnk".Equals(ext)) //if (".lnk".Equals(ext))
//{ //{
@@ -180,17 +181,18 @@ namespace GeekDesk.Util
BitmapImage bi = ImageUtil.GetBitmapIconByPath(iconPath); BitmapImage bi = ImageUtil.GetBitmapIconByPath(iconPath);
IconInfo iconInfo = new IconInfo IconInfo iconInfo = new IconInfo
{ {
Path = path, Path_NoWrite = path,
LnkPath = tempPath, LnkPath_NoWrite = tempPath,
BitmapImage = bi, BitmapImage_NoWrite = bi,
StartArg = FileUtil.GetArgByLnk(tempPath) StartArg_NoWrite = FileUtil.GetArgByLnk(tempPath)
}; };
iconInfo.DefaultImage = iconInfo.ImageByteArr; iconInfo.DefaultImage_NoWrite = iconInfo.ImageByteArr;
iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(tempPath); iconInfo.Name_NoWrite = System.IO.Path.GetFileNameWithoutExtension(tempPath);
if (StringUtil.IsEmpty(iconInfo.Name)) if (StringUtil.IsEmpty(iconInfo.Name))
{ {
iconInfo.Name = path; iconInfo.Name_NoWrite = path;
} }
iconInfo.RelativePath_NoWrite = FileUtil.MakeRelativePath(Constants.APP_DIR + "GeekDesk.exe", iconInfo.Path);
return iconInfo; return iconInfo;
} }

View File

@@ -1,5 +1,6 @@
using IWshRuntimeLibrary; using IWshRuntimeLibrary;
using System; using System;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@@ -156,5 +157,26 @@ namespace GeekDesk.Util
} }
} }
public static String MakeRelativePath(String fromPath, String toPath)
{
if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
Uri fromUri = new Uri(fromPath);
Uri toUri = new Uri(toPath);
if (fromUri.Scheme != toUri.Scheme) { return toPath; } // path can't be made relative.
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
{
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
return relativePath;
}
} }
} }

View File

@@ -24,9 +24,36 @@ namespace GeekDesk.ViewModel
private string startArg; //启动参数 private string startArg; //启动参数
private string lnkPath; private string lnkPath;
private string relativePath; //相对路径
private IconType iconType = IconType.OTHER; private IconType iconType = IconType.OTHER;
public string RelativePath_NoWrite
{
get
{
return relativePath;
}
set
{
relativePath = value;
}
}
public string RelativePath
{
get
{
return relativePath;
}
set
{
relativePath = value;
OnPropertyChanged("RelativePath");
}
}
public string LnkPath_NoWrite public string LnkPath_NoWrite
{ {
get get