This commit is contained in:
liufei
2021-04-13 15:26:19 +08:00
parent cc399e2ef7
commit 5f38782623
26 changed files with 1778 additions and 1787 deletions

View File

@@ -1,12 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using GeekDesk.Constant;
using GeekDesk.ViewModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
/// <summary>
/// 提取一些代码
@@ -15,45 +10,49 @@ namespace GeekDesk.Util
{
class CommonCode
{
private static string appConfigFilePath = AppDomain.CurrentDomain.BaseDirectory.Trim() + "\\config";
/// <summary>
/// 获取app配置
/// 获取app 数据
/// </summary>
/// <returns></returns>
public static AppConfig GetAppConfig()
public static AppData GetAppData()
{
AppConfig config;
if (!File.Exists(appConfigFilePath))
AppData appData;
if (!File.Exists(AppConstant.DATA_FILE_PATH))
{
using (FileStream fs = File.Create(appConfigFilePath)) { }
config = new AppConfig();
SaveAppConfig(config);
using (FileStream fs = File.Create(AppConstant.DATA_FILE_PATH)) { }
appData = new AppData();
SaveAppData(appData);
}
else
{
using (FileStream fs = new FileStream(appConfigFilePath, FileMode.Open))
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
string json = bf.Deserialize(fs) as string;
config = JsonConvert.DeserializeObject<AppConfig>(json);
appData = bf.Deserialize(fs) as AppData;
}
}
return config;
return appData;
}
/// <summary>
/// 保存app配置
/// 保存app 数据
/// </summary>
/// <param name="config"></param>
public static void SaveAppConfig(AppConfig config)
/// <param name="appData"></param>
public static void SaveAppData(AppData appData)
{
using (FileStream fs = new FileStream(appConfigFilePath, FileMode.Create))
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
string json = JsonConvert.SerializeObject(config);
bf.Serialize(fs, json);
bf.Serialize(fs, appData);
}
}
}
}

View File

@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.Util
{

View File

@@ -1,175 +1,170 @@
// Copyright (C) Josh Smith - January 2007
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Controls;
namespace WPF.JoshSmith.Adorners
{
/// <summary>
/// Renders a visual which can follow the mouse cursor,
/// such as during a drag-and-drop operation.
/// </summary>
public class DragAdorner : Adorner
{
#region Data
/// <summary>
/// Renders a visual which can follow the mouse cursor,
/// such as during a drag-and-drop operation.
/// </summary>
public class DragAdorner : Adorner
{
#region Data
private Rectangle child = null;
private double offsetLeft = 0;
private double offsetTop = 0;
private Rectangle child = null;
private double offsetLeft = 0;
private double offsetTop = 0;
#endregion // Data
#endregion // Data
#region Constructor
#region Constructor
/// <summary>
/// Initializes a new instance of DragVisualAdorner.
/// </summary>
/// <param name="adornedElement">The element being adorned.</param>
/// <param name="size">The size of the adorner.</param>
/// <param name="brush">A brush to with which to paint the adorner.</param>
public DragAdorner( UIElement adornedElement, Size size, Brush brush )
: base( adornedElement )
{
Rectangle rect = new Rectangle();
rect.Fill = brush;
rect.Width = size.Width;
rect.Height = size.Height;
rect.IsHitTestVisible = false;
this.child = rect;
}
/// <summary>
/// Initializes a new instance of DragVisualAdorner.
/// </summary>
/// <param name="adornedElement">The element being adorned.</param>
/// <param name="size">The size of the adorner.</param>
/// <param name="brush">A brush to with which to paint the adorner.</param>
public DragAdorner(UIElement adornedElement, Size size, Brush brush)
: base(adornedElement)
{
Rectangle rect = new Rectangle();
rect.Fill = brush;
rect.Width = size.Width;
rect.Height = size.Height;
rect.IsHitTestVisible = false;
this.child = rect;
}
#endregion // Constructor
#endregion // Constructor
#region Public Interface
#region Public Interface
#region GetDesiredTransform
#region GetDesiredTransform
/// <summary>
/// Override.
/// </summary>
/// <param name="transform"></param>
/// <returns></returns>
public override GeneralTransform GetDesiredTransform( GeneralTransform transform )
{
GeneralTransformGroup result = new GeneralTransformGroup();
result.Children.Add( base.GetDesiredTransform( transform ) );
result.Children.Add( new TranslateTransform( this.offsetLeft, this.offsetTop ) );
return result;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="transform"></param>
/// <returns></returns>
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
GeneralTransformGroup result = new GeneralTransformGroup();
result.Children.Add(base.GetDesiredTransform(transform));
result.Children.Add(new TranslateTransform(this.offsetLeft, this.offsetTop));
return result;
}
#endregion // GetDesiredTransform
#endregion // GetDesiredTransform
#region OffsetLeft
#region OffsetLeft
/// <summary>
/// Gets/sets the horizontal offset of the adorner.
/// </summary>
public double OffsetLeft
{
get { return this.offsetLeft; }
set
{
this.offsetLeft = value;
UpdateLocation();
}
}
/// <summary>
/// Gets/sets the horizontal offset of the adorner.
/// </summary>
public double OffsetLeft
{
get { return this.offsetLeft; }
set
{
this.offsetLeft = value;
UpdateLocation();
}
}
#endregion // OffsetLeft
#endregion // OffsetLeft
#region SetOffsets
#region SetOffsets
/// <summary>
/// Updates the location of the adorner in one atomic operation.
/// </summary>
/// <param name="left"></param>
/// <param name="top"></param>
public void SetOffsets( double left, double top )
{
this.offsetLeft = left;
this.offsetTop = top;
this.UpdateLocation();
}
/// <summary>
/// Updates the location of the adorner in one atomic operation.
/// </summary>
/// <param name="left"></param>
/// <param name="top"></param>
public void SetOffsets(double left, double top)
{
this.offsetLeft = left;
this.offsetTop = top;
this.UpdateLocation();
}
#endregion // SetOffsets
#endregion // SetOffsets
#region OffsetTop
#region OffsetTop
/// <summary>
/// Gets/sets the vertical offset of the adorner.
/// </summary>
public double OffsetTop
{
get { return this.offsetTop; }
set
{
this.offsetTop = value;
UpdateLocation();
}
}
/// <summary>
/// Gets/sets the vertical offset of the adorner.
/// </summary>
public double OffsetTop
{
get { return this.offsetTop; }
set
{
this.offsetTop = value;
UpdateLocation();
}
}
#endregion // OffsetTop
#endregion // OffsetTop
#endregion // Public Interface
#endregion // Public Interface
#region Protected Overrides
#region Protected Overrides
/// <summary>
/// Override.
/// </summary>
/// <param name="constraint"></param>
/// <returns></returns>
protected override Size MeasureOverride( Size constraint )
{
this.child.Measure( constraint );
return this.child.DesiredSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="constraint"></param>
/// <returns></returns>
protected override Size MeasureOverride(Size constraint)
{
this.child.Measure(constraint);
return this.child.DesiredSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="finalSize"></param>
/// <returns></returns>
protected override Size ArrangeOverride( Size finalSize )
{
this.child.Arrange( new Rect( finalSize ) );
return finalSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="finalSize"></param>
/// <returns></returns>
protected override Size ArrangeOverride(Size finalSize)
{
this.child.Arrange(new Rect(finalSize));
return finalSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
protected override Visual GetVisualChild( int index )
{
return this.child;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
protected override Visual GetVisualChild(int index)
{
return this.child;
}
/// <summary>
/// Override. Always returns 1.
/// </summary>
protected override int VisualChildrenCount
{
get { return 1; }
}
/// <summary>
/// Override. Always returns 1.
/// </summary>
protected override int VisualChildrenCount
{
get { return 1; }
}
#endregion // Protected Overrides
#endregion // Protected Overrides
#region Private Helpers
#region Private Helpers
private void UpdateLocation()
{
AdornerLayer adornerLayer = this.Parent as AdornerLayer;
if( adornerLayer != null )
adornerLayer.Update( this.AdornedElement );
}
private void UpdateLocation()
{
AdornerLayer adornerLayer = this.Parent as AdornerLayer;
if (adornerLayer != null)
adornerLayer.Update(this.AdornedElement);
}
#endregion // Private Helpers
}
#endregion // Private Helpers
}
}

View File

@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;
namespace GeekDesk.Util
@@ -46,12 +40,12 @@ namespace GeekDesk.Util
Bitmap bmp = ico.ToBitmap();
MemoryStream strm = new MemoryStream();
bmp.Save(strm, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bmpImage = new BitmapImage();
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
strm.Seek(0, SeekOrigin.Begin);
bmpImage.StreamSource = strm;
bmpImage.EndInit();
return bmpImage.Clone();
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace GeekDesk.Util
@@ -12,10 +8,11 @@ namespace GeekDesk.Util
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null && value.ToString().Length>0)
if (value != null && value.ToString().Length > 0)
{
return System.Convert.ToDouble(value.ToString()) - 10d;
} else
}
else
{
return 0d;
}

View File

@@ -1,58 +1,56 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Media;
namespace WPF.JoshSmith.Controls.Utilities
{
/// <summary>
/// Provides access to the mouse location by calling unmanaged code.
/// </summary>
/// <remarks>
/// This class was written by Dan Crevier (Microsoft).
/// http://blogs.msdn.com/llobo/archive/2006/09/06/Scrolling-Scrollviewer-on-Mouse-Drag-at-the-boundaries.aspx
/// </remarks>
public class MouseUtilities
{
[StructLayout( LayoutKind.Sequential )]
private struct Win32Point
{
public Int32 X;
public Int32 Y;
};
/// <summary>
/// Provides access to the mouse location by calling unmanaged code.
/// </summary>
/// <remarks>
/// This class was written by Dan Crevier (Microsoft).
/// http://blogs.msdn.com/llobo/archive/2006/09/06/Scrolling-Scrollviewer-on-Mouse-Drag-at-the-boundaries.aspx
/// </remarks>
public class MouseUtilities
{
[StructLayout(LayoutKind.Sequential)]
private struct Win32Point
{
public Int32 X;
public Int32 Y;
};
[DllImport( "user32.dll" )]
private static extern bool GetCursorPos( ref Win32Point pt );
[DllImport("user32.dll")]
private static extern bool GetCursorPos(ref Win32Point pt);
[DllImport( "user32.dll" )]
private static extern bool ScreenToClient( IntPtr hwnd, ref Win32Point pt );
[DllImport("user32.dll")]
private static extern bool ScreenToClient(IntPtr hwnd, ref Win32Point pt);
/// <summary>
/// Returns the mouse cursor location. This method is necessary during
/// a drag-drop operation because the WPF mechanisms for retrieving the
/// cursor coordinates are unreliable.
/// </summary>
/// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
public static Point GetMousePosition( Visual relativeTo )
{
Win32Point mouse = new Win32Point();
GetCursorPos( ref mouse );
/// <summary>
/// Returns the mouse cursor location. This method is necessary during
/// a drag-drop operation because the WPF mechanisms for retrieving the
/// cursor coordinates are unreliable.
/// </summary>
/// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
public static Point GetMousePosition(Visual relativeTo)
{
Win32Point mouse = new Win32Point();
GetCursorPos(ref mouse);
// Using PointFromScreen instead of Dan Crevier's code (commented out below)
// is a bug fix created by William J. Roberts. Read his comments about the fix
// here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx
return relativeTo.PointFromScreen( new Point( (double)mouse.X, (double)mouse.Y ) );
// Using PointFromScreen instead of Dan Crevier's code (commented out below)
// is a bug fix created by William J. Roberts. Read his comments about the fix
// here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx
return relativeTo.PointFromScreen(new Point((double)mouse.X, (double)mouse.Y));
#region Commented Out
//System.Windows.Interop.HwndSource presentationSource =
// (System.Windows.Interop.HwndSource)PresentationSource.FromVisual( relativeTo );
//ScreenToClient( presentationSource.Handle, ref mouse );
//GeneralTransform transform = relativeTo.TransformToAncestor( presentationSource.RootVisual );
//Point offset = transform.Transform( new Point( 0, 0 ) );
//return new Point( mouse.X - offset.X, mouse.Y - offset.Y );
#endregion // Commented Out
}
}
#region Commented Out
//System.Windows.Interop.HwndSource presentationSource =
// (System.Windows.Interop.HwndSource)PresentationSource.FromVisual( relativeTo );
//ScreenToClient( presentationSource.Handle, ref mouse );
//GeneralTransform transform = relativeTo.TransformToAncestor( presentationSource.RootVisual );
//Point offset = transform.Transform( new Point( 0, 0 ) );
//return new Point( mouse.X - offset.X, mouse.Y - offset.Y );
#endregion // Commented Out
}
}
}

View File

@@ -1,13 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using GeekDesk.Util;
namespace GeekDesk.Util
{