diff --git a/Control/Other/IconInfoDialog.xaml b/Control/Other/IconInfoDialog.xaml
index 7d75221..f094620 100644
--- a/Control/Other/IconInfoDialog.xaml
+++ b/Control/Other/IconInfoDialog.xaml
@@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
+ xmlns:cvt="clr-namespace:GeekDesk.Converts"
CornerRadius="4"
Width="350"
Height="450"
@@ -10,29 +11,39 @@
+
-
+
-
-
+
+
+
+
+
-
-
+
@@ -41,12 +52,11 @@
-
-
+
-
+
diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml.cs b/Control/UserControls/PannelCard/RightCardControl.xaml.cs
index a5d17c3..3dec0ff 100644
--- a/Control/UserControls/PannelCard/RightCardControl.xaml.cs
+++ b/Control/UserControls/PannelCard/RightCardControl.xaml.cs
@@ -171,33 +171,51 @@ namespace GeekDesk.Control.UserControls.PannelCard
StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE);
}
- private void StartIconApp(IconInfo icon, IconStartType type)
+ private void StartIconApp(IconInfo icon, IconStartType type, bool useRelativePath = false)
{
+
try
{
using (Process p = new Process())
{
string startArg = icon.StartArg;
-
+
if (startArg != null && Constants.SYSTEM_ICONS.ContainsKey(startArg))
{
StartSystemApp(startArg, type);
}
else
{
- p.StartInfo.FileName = icon.Path;
+ string path;
+ if (useRelativePath)
+ {
+ string fullPath = Path.Combine(Constants.APP_DIR, icon.RelativePath);
+ path = Path.GetFullPath(fullPath);
+ } else
+ {
+ path = icon.Path;
+ }
+ p.StartInfo.FileName = path;
if (!StringUtil.IsEmpty(startArg))
{
p.StartInfo.Arguments = startArg;
}
if (icon.IconType == IconType.OTHER)
{
- if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
+ if (!File.Exists(path) && !Directory.Exists(path))
{
- HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
- return;
+ //如果没有使用相对路径 那么使用相对路径启动一次
+ if (!useRelativePath)
+ {
+ StartIconApp(icon, type, true);
+ return;
+ } else
+ {
+ HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
+ return;
+ }
}
- p.StartInfo.WorkingDirectory = icon.Path.Substring(0, icon.Path.LastIndexOf("\\"));
+ p.StartInfo.WorkingDirectory = path.Substring(0, path.LastIndexOf("\\"));
switch (type)
{
case IconStartType.ADMIN_STARTUP:
@@ -265,6 +283,11 @@ namespace GeekDesk.Control.UserControls.PannelCard
}
}
p.Start();
+ if (useRelativePath)
+ {
+ //如果使用相对路径启动成功 那么重新设置程序绝对路径
+ icon.Path = path;
+ }
}
}
icon.Count++;
@@ -277,8 +300,15 @@ namespace GeekDesk.Control.UserControls.PannelCard
}
catch (Exception e)
{
- HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
- LogUtil.WriteErrorLog(e, "程序启动失败:path=" + icon.Path + ",type=" + type);
+ if (!useRelativePath)
+ {
+ StartIconApp(icon, type, true);
+ }
+ else
+ {
+ HandyControl.Controls.Growl.WarningGlobal("程序启动失败(可能为不支持的启动方式)!");
+ LogUtil.WriteErrorLog(e, "程序启动失败:path=" + icon.Path + ",type=" + type);
+ }
}
}
diff --git a/Control/UserControls/ToDo/TodoControl.xaml b/Control/UserControls/ToDo/TodoControl.xaml
index 657799d..97fbd84 100644
--- a/Control/UserControls/ToDo/TodoControl.xaml
+++ b/Control/UserControls/ToDo/TodoControl.xaml
@@ -6,7 +6,6 @@
xmlns:local="clr-namespace:GeekDesk.Control.UserControls.PannelCard"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:ToDoInfo}"
mc:Ignorable="d"
- xmlns:cst="clr-namespace:GeekDesk.Converts"
Background="Transparent"
>
diff --git a/Converts/StringAppendConvert.cs b/Converts/StringAppendConvert.cs
index e769f2e..1e046fd 100644
--- a/Converts/StringAppendConvert.cs
+++ b/Converts/StringAppendConvert.cs
@@ -8,7 +8,10 @@ namespace GeekDesk.Converts
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
- if (value == null) return null;
+ if (value == null)
+ {
+ value = "";
+ }
if (parameter == null)
{
return value.ToString();
@@ -16,7 +19,14 @@ namespace GeekDesk.Converts
else
{
string val = value.ToString();
+ if (string.IsNullOrEmpty(val))
+ {
+ return parameter.ToString()
+ .Replace("\\n", "")
+ .Replace("{}", "");
+ }
string param = parameter.ToString();
+ param = param.Replace("\\n", "\n");
return param.Replace("{}", val);
}
}
diff --git a/Interface/IWindowCommon.cs b/Interface/IWindowCommon.cs
index b74eba7..675d450 100644
--- a/Interface/IWindowCommon.cs
+++ b/Interface/IWindowCommon.cs
@@ -4,6 +4,6 @@ namespace GeekDesk.Interface
{
public interface IWindowCommon
{
- void OnKeyDown(object sender, KeyEventArgs e);
+ void OnKeyDown(object sender, KeyEventArgs e);
}
}
diff --git a/MyThread/RelativePathThread.cs b/MyThread/RelativePathThread.cs
index c723caa..3d79893 100644
--- a/MyThread/RelativePathThread.cs
+++ b/MyThread/RelativePathThread.cs
@@ -18,8 +18,6 @@ namespace GeekDesk.MyThread
{
new Thread(() =>
{
- Thread.Sleep(1000);
-
ObservableCollection menuList = MainWindow.appData.MenuList;
string myExePath = Constants.APP_DIR + "GeekDesk.exe";
@@ -28,7 +26,12 @@ namespace GeekDesk.MyThread
ObservableCollection iconList = mi.IconList;
foreach (IconInfo icon in iconList)
{
- icon.RelativePath_NoWrite = FileUtil.MakeRelativePath(myExePath, icon.Path);
+ string relativePath = FileUtil.MakeRelativePath(myExePath, icon.Path);
+ if (File.Exists(icon.Path)
+ && !string.IsNullOrEmpty(relativePath)
+ && !relativePath.Equals(icon.Path)) {
+ icon.RelativePath_NoWrite = relativePath;
+ }
}
}
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
diff --git a/Util/CommonCode.cs b/Util/CommonCode.cs
index 08be339..889b787 100644
--- a/Util/CommonCode.cs
+++ b/Util/CommonCode.cs
@@ -88,22 +88,27 @@ namespace GeekDesk.Util
return appData;
}
+ private readonly static object _MyLock = new object();
///
/// 保存app 数据
///
///
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("\\"))))
+ lock (_MyLock)
{
- Directory.CreateDirectory(filePath.Substring(0, filePath.LastIndexOf("\\")));
- }
- using (FileStream fs = new FileStream(filePath, FileMode.Create))
- {
- BinaryFormatter bf = new BinaryFormatter();
- bf.Serialize(fs, appData);
+ 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("\\")));
+ }
+ using (FileStream fs = new FileStream(filePath, FileMode.Create))
+ {
+ BinaryFormatter bf = new BinaryFormatter();
+ bf.Serialize(fs, appData);
+ }
}
+
}
public static void BakAppData()
@@ -192,7 +197,11 @@ namespace GeekDesk.Util
{
iconInfo.Name_NoWrite = path;
}
- iconInfo.RelativePath_NoWrite = FileUtil.MakeRelativePath(Constants.APP_DIR + "GeekDesk.exe", iconInfo.Path);
+ string relativePath = FileUtil.MakeRelativePath(Constants.APP_DIR + "GeekDesk.exe", iconInfo.Path);
+ if (!string.IsNullOrEmpty(relativePath) && !relativePath.Equals(iconInfo.Path))
+ {
+ iconInfo.RelativePath_NoWrite = relativePath;
+ }
return iconInfo;
}
diff --git a/Util/FileUtil.cs b/Util/FileUtil.cs
index 89423ab..10f63db 100644
--- a/Util/FileUtil.cs
+++ b/Util/FileUtil.cs
@@ -157,24 +157,32 @@ namespace GeekDesk.Util
}
}
- public static String MakeRelativePath(String fromPath, String toPath)
+ public static string MakeRelativePath(string fromPath, string toPath)
{
- if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
- if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("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);
+ //Uri fromUri = new Uri(fromPath);
+ //Uri toUri = new Uri(toPath);
- if (fromUri.Scheme != toUri.Scheme) { return toPath; } // path can't be made relative.
+ //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);
- }
+ //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);
+ //}
+ 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)
+ );
return relativePath;
}