diff --git a/Constant/AppConstant.cs b/Constant/AppConstant.cs
deleted file mode 100644
index 9d0d042..0000000
--- a/Constant/AppConstant.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System;
-
-namespace GeekDesk.Constant
-{
- class AppConstant
- {
- private static string APP_DIR = AppDomain.CurrentDomain.BaseDirectory.Trim();
- ///
- /// app数据文件路径
- ///
- public static string DATA_FILE_PATH = APP_DIR + "//Data"; //app数据文件路径
- }
-}
diff --git a/Constant/Constants.cs b/Constant/Constants.cs
index 6badcf3..3089cf7 100644
--- a/Constant/Constants.cs
+++ b/Constant/Constants.cs
@@ -8,6 +8,12 @@ namespace GeekDesk.Constant
{
public class Constants
{
+ public static string APP_DIR = AppDomain.CurrentDomain.BaseDirectory.Trim();
+ ///
+ /// app数据文件路径
+ ///
+ public static string DATA_FILE_PATH = APP_DIR + "//Data"; //app数据文件路径
+
//默认文件夹图标
public static string DEFAULT_DIR_IMAGE_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAASISURBVHhe7dvPi9R1HMfx/Qu6RYfqEp1CZ8Yko0MQRNEPgnQ36FJEFyPoF/0DHbx06dSlnVkF6SgEgocOYUEG0cFWpQ476yhbQfTDslJxk+k79S1IP/NSF3f2O+7jBY/TKgvz/j5nXMUZMzMzMzMzMzMzMzMzMzMzu959023dsbSw9YGlbuchyk7v3XbP0t5tt9Yvmd3MW3r//luWu623TvbahytDrtvBQa/9xvJ85776JbWbZf359s7quCcKR2cNqjeaQ/35zgv1y2vTvOqgOy4/MDdG9abzwWC+06lfapu2jf4cXTosN9SZ5W7n9folt2nZ6Ifw6niDy47JelloH6hfepuGLffa7xQPyfpZaL9Xv/zW5K307r27eEDWXfXG9GJ9BmvqqneyV0rHYzL63a3b61NYEzfodT4rHY4J8UetZq/6mF8pHo6J8SnS4JUOxqS19tTnsKatfDAm7Hh9DmvaCsdiAwx6rcfqk1iTVjo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10G4AYgAAAABJRU5ErkJggg==";
diff --git a/Control/ConfigWindow.xaml.cs b/Control/ConfigWindow.xaml.cs
index ed502fe..f38bf96 100644
--- a/Control/ConfigWindow.xaml.cs
+++ b/Control/ConfigWindow.xaml.cs
@@ -46,5 +46,6 @@ namespace GeekDesk.Control
{
this.Close();
}
+
}
}
diff --git a/Control/IconInfoDialog.xaml.cs b/Control/IconInfoDialog.xaml.cs
index 862664c..9321217 100644
--- a/Control/IconInfoDialog.xaml.cs
+++ b/Control/IconInfoDialog.xaml.cs
@@ -1,6 +1,7 @@
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Microsoft.Win32;
+using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
@@ -58,17 +59,24 @@ namespace GeekDesk.Control
///
private void EditImage(object sender, RoutedEventArgs e)
{
- OpenFileDialog ofd = new OpenFileDialog
+ try
{
- Multiselect = false, //只允许选中单个文件
- Filter = "所有文件(*.*)|*.*"
- };
- if (ofd.ShowDialog() == true)
+ OpenFileDialog ofd = new OpenFileDialog
+ {
+ Multiselect = false, //只允许选中单个文件
+ Filter = "所有文件(*.*)|*.*"
+ };
+ if (ofd.ShowDialog() == true)
+ {
+ IconInfo info = this.DataContext as IconInfo;
+ info.BitmapImage = ImageUtil.GetBitmapIconByPath(ofd.FileName);
+ CommonCode.SaveAppData(MainWindow.appData);
+ }
+ } catch (Exception)
{
- IconInfo info = this.DataContext as IconInfo;
- info.BitmapImage = ImageUtil.GetBitmapIconByPath(ofd.FileName);
- CommonCode.SaveAppData(MainWindow.appData);
+ HandyControl.Controls.Growl.WarningGlobal("修改图标失败,已重置为默认图标!");
}
+
}
}
}
diff --git a/Control/UserControls/SettingControl.xaml b/Control/UserControls/SettingControl.xaml
index 261bddf..77d6a68 100644
--- a/Control/UserControls/SettingControl.xaml
+++ b/Control/UserControls/SettingControl.xaml
@@ -61,7 +61,7 @@
-
+
diff --git a/Control/UserControls/SettingControl.xaml.cs b/Control/UserControls/SettingControl.xaml.cs
index 0fd5252..5c8c6a3 100644
--- a/Control/UserControls/SettingControl.xaml.cs
+++ b/Control/UserControls/SettingControl.xaml.cs
@@ -1,4 +1,6 @@
using GeekDesk.Util;
+using GeekDesk.ViewModel;
+using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -36,8 +38,30 @@ namespace GeekDesk.Control.UserControls
}
- private void Button_Click(object sender, RoutedEventArgs e)
+ ///
+ /// 修改背景图片
+ ///
+ ///
+ ///
+ private void BGButton_Click(object sender, RoutedEventArgs e)
{
+ AppConfig appConfig = MainWindow.appData.AppConfig;
+
+ try
+ {
+ OpenFileDialog ofd = new OpenFileDialog
+ {
+ Multiselect = false, //只允许选中单个文件
+ Filter = "图像文件(*.png, *.jpg)|*.png;*.jpg;*.gif"
+ };
+ if (ofd.ShowDialog() == true)
+ {
+ appConfig.BitmapImage = ImageUtil.GetBitmapImageByFile(ofd.FileName);
+ }
+ } catch (Exception)
+ {
+ HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
+ }
}
}
diff --git a/GeekDesk.csproj b/GeekDesk.csproj
index 532c9a3..ae84a77 100644
--- a/GeekDesk.csproj
+++ b/GeekDesk.csproj
@@ -38,6 +38,9 @@
true
+
+ packages\SharpShellTools.2.2.0.0\lib\Apex.WinForms.dll
+
packages\CommonServiceLocator.2.0.6\lib\net45\CommonServiceLocator.dll
@@ -53,12 +56,23 @@
packages\HandyControl.3.1.0\lib\net452\HandyControl.dll
+
+ packages\SharpShellTools.2.2.0.0\lib\ServerManager.exe
+
+
+ packages\SharpShellTools.2.2.0.0\lib\SharpShell.dll
+
+
+ packages\SharpShellTools.2.2.0.0\lib\srm.exe
+ True
+
packages\System.Drawing.Common.6.0.0-preview.3.21201.4\lib\net461\System.Drawing.Common.dll
+
packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll
@@ -82,7 +96,6 @@
-
@@ -113,6 +126,7 @@
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index ba248a7..1d1cdb2 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -3,15 +3,16 @@ using GeekDesk.Constant;
using GeekDesk.Control;
using GeekDesk.Util;
using GeekDesk.ViewModel;
+using SharpShell.SharpContextMenu;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
-using System.Drawing.Imaging;
+using System.Drawing;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
-
+using System.Windows.Media;
namespace GeekDesk
{
@@ -216,7 +217,7 @@ namespace GeekDesk
p.Start();
icon.Count++;
} catch (Exception)
- {
+ {
HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
}
}
@@ -446,7 +447,7 @@ namespace GeekDesk
private void ShowAppAndFollowMouse()
{
//获取鼠标位置
- Point p = MouseUtil.GetMousePosition();
+ System.Windows.Point p = MouseUtil.GetMousePosition();
double left = SystemParameters.VirtualScreenLeft;
double top = SystemParameters.VirtualScreenTop;
double width = SystemParameters.VirtualScreenWidth;
@@ -550,7 +551,10 @@ namespace GeekDesk
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
-
+ IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
+ System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
+ psi.Arguments = "/e,/select," + icon.Path;
+ System.Diagnostics.Process.Start(psi);
}
///
diff --git a/Util/CommonCode.cs b/Util/CommonCode.cs
index 5da8c9d..c2e8d5e 100644
--- a/Util/CommonCode.cs
+++ b/Util/CommonCode.cs
@@ -18,16 +18,16 @@ namespace GeekDesk.Util
public static AppData GetAppDataByFile()
{
AppData appData;
- if (!File.Exists(AppConstant.DATA_FILE_PATH))
+ if (!File.Exists(Constants.DATA_FILE_PATH))
{
- using (FileStream fs = File.Create(AppConstant.DATA_FILE_PATH)) { }
+ using (FileStream fs = File.Create(Constants.DATA_FILE_PATH)) { }
appData = new AppData();
SaveAppData(appData);
}
else
{
- using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Open))
+ using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
appData = bf.Deserialize(fs) as AppData;
@@ -43,7 +43,7 @@ namespace GeekDesk.Util
public static void SaveAppData(AppData appData)
{
- using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Create))
+ using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, appData);
diff --git a/Util/ImageUtil.cs b/Util/ImageUtil.cs
index 58e7410..8cf4c93 100644
--- a/Util/ImageUtil.cs
+++ b/Util/ImageUtil.cs
@@ -1,8 +1,11 @@
using GeekDesk.Constant;
using System;
using System.Drawing;
+using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
+using System.Windows;
+using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace GeekDesk.Util
@@ -66,7 +69,7 @@ namespace GeekDesk.Util
{
if (IsImage(filePath)) {
//图片
- return GetThumbnail(filePath, 256, 256);
+ return GetThumbnailByFile(filePath, 256, 256);
} else
{ //其它文件
return FileIcon.GetBitmapImage(filePath);
@@ -86,47 +89,128 @@ namespace GeekDesk.Util
/// 缩略图的宽度
/// 缩略图的高度
///
- public static BitmapImage GetThumbnail(string lcFilename, int lnWidth, int lnHeight)
+ //public static BitmapImage GetThumbnail(string lcFilename, int lnWidth, int lnHeight)
+ //{
+ // Bitmap bmpOut = null;
+ // try
+ // {
+ // Bitmap loBMP = new Bitmap(lcFilename);
+ // ImageFormat loFormat = loBMP.RawFormat;
+
+ // decimal lnRatio;
+ // int lnNewWidth = 0;
+ // int lnNewHeight = 0;
+
+ // //如果图像小于缩略图直接返回原图,因为upfront
+ // if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)
+ // return BitmapToBitmapImage(loBMP);
+ // if (loBMP.Width > loBMP.Height)
+ // {
+ // lnRatio = (decimal)lnWidth / loBMP.Width;
+ // lnNewWidth = lnWidth;
+ // decimal lnTemp = loBMP.Height * lnRatio;
+ // lnNewHeight = (int)lnTemp;
+ // }
+ // else
+ // {
+ // lnRatio = (decimal)lnHeight / loBMP.Height;
+ // lnNewHeight = lnHeight;
+ // decimal lnTemp = loBMP.Width * lnRatio;
+ // lnNewWidth = (int)lnTemp;
+ // }
+ // bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
+ // Graphics g = Graphics.FromImage(bmpOut);
+ // g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
+ // g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
+ // g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
+ // loBMP.Dispose();
+ // }
+ // catch (Exception e)
+ // {
+ // return Base64ToBitmapImage(Constants.DEFAULT_IMG_IMAGE_BASE64);
+ // }
+ // return BitmapToBitmapImage(bmpOut);
+ //}
+
+ public static BitmapImage GetThumbnailByFile(string filePath, int tWidth, int tHeight)
{
- Bitmap bmpOut = null;
+
try
{
- Bitmap loBMP = new Bitmap(lcFilename);
- ImageFormat loFormat = loBMP.RawFormat;
-
- decimal lnRatio;
- int lnNewWidth = 0;
- int lnNewHeight = 0;
-
- //如果图像小于缩略图直接返回原图,因为upfront
- if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)
- return BitmapToBitmapImage(bmpOut);
- if (loBMP.Width > loBMP.Height)
+ Image img = Image.FromFile(filePath);
+ if (img.Width <= tWidth && img.Height <= tHeight)
{
- lnRatio = (decimal)lnWidth / loBMP.Width;
- lnNewWidth = lnWidth;
- decimal lnTemp = loBMP.Height * lnRatio;
- lnNewHeight = (int)lnTemp;
+ return GetBitmapImageByFile(filePath);
}
else
{
- lnRatio = (decimal)lnHeight / loBMP.Height;
- lnNewHeight = lnHeight;
- decimal lnTemp = loBMP.Width * lnRatio;
- lnNewWidth = (int)lnTemp;
+ Bitmap loBMP = new Bitmap(filePath);
+ ImageFormat loFormat = loBMP.RawFormat;
+
+ decimal lnRatio;
+ int lnNewWidth;
+ int lnNewHeight;
+ if (loBMP.Width > loBMP.Height)
+ {
+ lnRatio = (decimal)tWidth / loBMP.Width;
+ lnNewWidth = tWidth;
+ decimal lnTemp = loBMP.Height * lnRatio;
+ lnNewHeight = (int)lnTemp;
+ }
+ else
+ {
+ lnRatio = (decimal)tHeight / loBMP.Height;
+ lnNewHeight = tHeight;
+ decimal lnTemp = loBMP.Width * lnRatio;
+ lnNewWidth = (int)lnTemp;
+ }
+ Bitmap bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
+ Graphics g = Graphics.FromImage(bmpOut);
+ g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
+ g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
+ g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
+ loBMP.Dispose();
+ string tempPath = Constants.APP_DIR + "\\temp";
+ if (File.Exists(tempPath))
+ {
+ File.Delete(tempPath);
+ }
+ bmpOut.Save(tempPath, loFormat);
+ BitmapImage bm = GetBitmapImageByFile(tempPath);
+ File.Delete(tempPath);
+ return bm;
}
- bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
- Graphics g = Graphics.FromImage(bmpOut);
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
- g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
- loBMP.Dispose();
}
- catch
+ catch (Exception)
{
return Base64ToBitmapImage(Constants.DEFAULT_IMG_IMAGE_BASE64);
}
- return BitmapToBitmapImage(bmpOut);
+
+ }
+
+
+ public static BitmapImage GetBitmapImageByFile(string filePath)
+ {
+ BitmapImage bmImg = new BitmapImage();
+ bmImg.BeginInit();
+ bmImg.CacheOption = BitmapCacheOption.OnLoad;
+ using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
+ {
+ bmImg.StreamSource = fs;
+ bmImg.EndInit();
+ }
+ return bmImg;
+ }
+
+ public static BitmapImage MemoryStremToBitMapImage(MemoryStream ms)
+ {
+ BitmapImage bi = new BitmapImage();
+ bi.BeginInit();
+ bi.StreamSource = ms;
+ bi.CacheOption = BitmapCacheOption.OnLoad;
+ bi.EndInit();
+ bi.Freeze();
+ return bi;
}
@@ -135,12 +219,24 @@ namespace GeekDesk.Util
///
///
///
- private static BitmapImage BitmapToBitmapImage(Bitmap bitmap)
+ public static BitmapImage BitmapToBitmapImage(Bitmap bitmap)
+ {
+ return BitmapToBitmapImage(bitmap, null);
+ }
+
+ public static BitmapImage BitmapToBitmapImage(Image bitmap, ImageFormat format)
{
BitmapImage bitmapImage = new BitmapImage();
using (MemoryStream ms = new MemoryStream())
{
- bitmap.Save(ms, bitmap.RawFormat);
+ if (format == null)
+ {
+ bitmap.Save(ms, bitmap.RawFormat);
+ }
+ else
+ {
+ bitmap.Save(ms, format);
+ }
bitmapImage.BeginInit();
bitmapImage.StreamSource = ms;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
@@ -150,6 +246,29 @@ namespace GeekDesk.Util
return bitmapImage;
}
+ [System.Runtime.InteropServices.DllImport("gdi32.dll")]
+ public static extern bool DeleteObject(IntPtr hObject);
+
+ public static BitmapImage Bitmap2BitmapImage(Bitmap bitmap)
+ {
+ IntPtr hBitmap = bitmap.GetHbitmap();
+ BitmapImage retval;
+ try
+ {
+ retval = (BitmapImage)Imaging.CreateBitmapSourceFromHBitmap(
+ hBitmap,
+ IntPtr.Zero,
+ Int32Rect.Empty,
+ BitmapSizeOptions.FromEmptyOptions());
+ }
+ finally
+ {
+ DeleteObject(hBitmap);
+ }
+ return retval;
+ }
+
+
///
/// 图片文件转base64
///
diff --git a/Util/ShellContextMenu.cs b/Util/ShellContextMenu.cs
new file mode 100644
index 0000000..d4067f6
--- /dev/null
+++ b/Util/ShellContextMenu.cs
@@ -0,0 +1,23 @@
+using SharpShell.SharpContextMenu;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace GeekDesk.Util
+{
+ class ShellContextMenu : SharpContextMenu
+ {
+ protected override bool CanShowMenu()
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override ContextMenuStrip CreateMenu()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/packages.config b/packages.config
index 9b33ab1..a284de5 100644
--- a/packages.config
+++ b/packages.config
@@ -3,5 +3,7 @@
+
+
\ No newline at end of file