diff --git a/App.config b/App.config
index fe810b1..abb25f0 100644
--- a/App.config
+++ b/App.config
@@ -61,7 +61,7 @@
-
+
diff --git a/GeekDesk.csproj b/GeekDesk.csproj
index cf1a9b1..37c64fa 100644
--- a/GeekDesk.csproj
+++ b/GeekDesk.csproj
@@ -257,6 +257,7 @@
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 872c561..392a8aa 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -227,13 +227,11 @@ namespace GeekDesk
//更新线程开启 检测更新
UpdateThread.Update();
- //自动备份一次数据
- appData.AppConfig.SysBakTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- CommonCode.SaveAppData(appData, Constants.DATA_FILE_BAK_PATH);
+ //建立相对路径
+ RelativePathThread.MakeRelativePath();
//毛玻璃 暂时未解决阴影问题
//BlurGlassUtil.EnableBlur(this);
- AeroGlassUtil.GlassWindow(this);
}
///
diff --git a/MyThread/RelativePathThread.cs b/MyThread/RelativePathThread.cs
new file mode 100644
index 0000000..c723caa
--- /dev/null
+++ b/MyThread/RelativePathThread.cs
@@ -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 menuList = MainWindow.appData.MenuList;
+
+ string myExePath = Constants.APP_DIR + "GeekDesk.exe";
+ foreach (MenuInfo mi in menuList)
+ {
+ ObservableCollection 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();
+ }
+ }
+}
diff --git a/Util/CommonCode.cs b/Util/CommonCode.cs
index 4b3c545..08be339 100644
--- a/Util/CommonCode.cs
+++ b/Util/CommonCode.cs
@@ -94,6 +94,7 @@ namespace GeekDesk.Util
///
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("\\"))))
{
Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf("\\")));
@@ -161,7 +162,7 @@ namespace GeekDesk.Util
// ext = System.IO.Path.GetExtension(path).ToLower();
//}
- string iconPath = null;
+ string iconPath;
//if (".lnk".Equals(ext))
//{
@@ -180,17 +181,18 @@ namespace GeekDesk.Util
BitmapImage bi = ImageUtil.GetBitmapIconByPath(iconPath);
IconInfo iconInfo = new IconInfo
{
- Path = path,
- LnkPath = tempPath,
- BitmapImage = bi,
- StartArg = FileUtil.GetArgByLnk(tempPath)
+ Path_NoWrite = path,
+ LnkPath_NoWrite = tempPath,
+ BitmapImage_NoWrite = bi,
+ StartArg_NoWrite = FileUtil.GetArgByLnk(tempPath)
};
- iconInfo.DefaultImage = iconInfo.ImageByteArr;
- iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(tempPath);
+ iconInfo.DefaultImage_NoWrite = iconInfo.ImageByteArr;
+ iconInfo.Name_NoWrite = System.IO.Path.GetFileNameWithoutExtension(tempPath);
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;
}
diff --git a/Util/FileUtil.cs b/Util/FileUtil.cs
index eb5a180..89423ab 100644
--- a/Util/FileUtil.cs
+++ b/Util/FileUtil.cs
@@ -1,5 +1,6 @@
using IWshRuntimeLibrary;
using System;
+using System.IO;
using System.Runtime.InteropServices;
using System.Text;
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;
+ }
+
}
}
diff --git a/ViewModel/IconInfo.cs b/ViewModel/IconInfo.cs
index b5b8aba..6501010 100644
--- a/ViewModel/IconInfo.cs
+++ b/ViewModel/IconInfo.cs
@@ -24,9 +24,36 @@ namespace GeekDesk.ViewModel
private string startArg; //启动参数
private string lnkPath;
+ private string relativePath; //相对路径
+
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
{
get