增加添加系统应用功能

This commit is contained in:
liufei
2022-01-06 17:45:25 +08:00
parent 1125432c41
commit d092db8b5c
35 changed files with 950 additions and 293 deletions

View File

@@ -1,5 +1,22 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<configSections>
<section
name="SystemIcons"
type="System.Configuration.DictionarySectionHandler" />
</configSections>
<SystemIcons>
<add key="Calculator" value="计算器"/>
<add key="Computer" value="此电脑"/>
<add key="GroupPolicy" value="组策略"/>
<add key="Network" value="网络连接"/>
<add key="RecycleBin" value="回收站"/>
<add key="Registry" value="注册表编辑器"/>
<add key="Notepad" value="记事本"/>
<add key="Mstsc" value="远程桌面连接"/>
<add key="Control" value="控制面板"/>
<add key="CMD" value="命令行"/>
</SystemIcons>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup> </startup>
@@ -34,7 +51,9 @@
<add key="GitHubUpdateUrl" value="https://demo-liu.github.io/GeekDesk/Update.json" /> <add key="GitHubUpdateUrl" value="https://demo-liu.github.io/GeekDesk/Update.json" />
<add key="GiteeUpdateUrl" value="https://demo-liu.github.io/GeekDesk/Update.json" /> <add key="GiteeUpdateUrl" value="https://demo-liu.github.io/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"/>
</appSettings> </appSettings>
<system.web> <system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider"> <membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers> <providers>

View File

@@ -5,8 +5,8 @@ namespace GeekDesk.Constant
{ {
public enum CommonEnum public enum CommonEnum
{ {
WINDOW_WIDTH = 666, //默认窗体宽度 WINDOW_WIDTH = 950, //默认窗体宽度
WINDOW_HEIGHT = 500, //默认窗体高度 WINDOW_HEIGHT = 650, //默认窗体高度
MENU_CARD_WIDHT = 165, //默认菜单栏宽度 MENU_CARD_WIDHT = 165, //默认菜单栏宽度
IMAGE_WIDTH = 45, //默认图标宽度 IMAGE_WIDTH = 45, //默认图标宽度
IMAGE_HEIGHT = 45, //默认图标高度 IMAGE_HEIGHT = 45, //默认图标高度

File diff suppressed because one or more lines are too long

View File

@@ -35,9 +35,11 @@
</hc:UniformSpacingPanel> </hc:UniformSpacingPanel>
<TextBlock Text="注: 需配置正确的url方可加载远程图标!" Foreground="Red" Margin="10,95,-10,-92" /> <TextBlock Text="注: 需配置正确的url方可加载远程图标!" Foreground="Red" Margin="10,95,-10,-92" />
<hc:UniformSpacingPanel Spacing="10" Margin="246.206,124.551,-246.206,-124.551"> <hc:UniformSpacingPanel Spacing="10" Margin="203,125,-203,-125">
<Button Content="取消" Command="hc:ControlCommands.Close" <Button Content="取消" Command="hc:ControlCommands.Close" HorizontalAlignment="Stretch" Margin="-1,1,1,1" VerticalAlignment="Stretch"
/> />
<Button Content="教程" Click="Teach_Click"
Style="{StaticResource Btn1}"/>
<Button Content="保存" Click="Confirm_Click" <Button Content="保存" Click="Confirm_Click"
Command="hc:ControlCommands.Close" Command="hc:ControlCommands.Close"
Style="{StaticResource Btn1}"/> Style="{StaticResource Btn1}"/>

View File

@@ -3,6 +3,8 @@ using GeekDesk.Util;
using GeekDesk.ViewModel; using GeekDesk.ViewModel;
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Configuration;
using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
@@ -40,5 +42,12 @@ namespace GeekDesk.Control.Other
IconfontWindow.vm.IsSettingUrl = "false"; IconfontWindow.vm.IsSettingUrl = "false";
} }
} }
private void Teach_Click(object sender, RoutedEventArgs e)
{
string url = ConfigurationManager.AppSettings["CustomIconTeachUrl"];
Process.Start(url);
}
} }
} }

View File

@@ -3,13 +3,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:hc="https://handyorg.github.io/handycontrol"
CornerRadius="4" CornerRadius="4"
Width="300" Width="350"
Height="340" Height="450"
Style="{StaticResource BorderBG}" Style="{StaticResource BorderBG}"
> >
<Border.Resources> <Border.Resources>
<Style x:Key="LeftTB" TargetType="TextBlock" BasedOn="{StaticResource TextBlockBaseStyle}"> <Style x:Key="LeftTB" TargetType="TextBlock" BasedOn="{StaticResource TextBlockBaseStyle}">
<Setter Property="Width" Value="40"/> <Setter Property="Width" Value="75"/>
<Setter Property="TextAlignment" Value="Center"/> <Setter Property="TextAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/>
@@ -22,7 +22,7 @@
<Button Width="22" Height="22" Command="hc:ControlCommands.Close" Style="{StaticResource ButtonIcon}" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" hc:IconElement.Geometry="{StaticResource ErrorGeometry}" Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top"/> <Button Width="22" Height="22" Command="hc:ControlCommands.Close" Style="{StaticResource ButtonIcon}" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" hc:IconElement.Geometry="{StaticResource ErrorGeometry}" Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top"/>
<hc:UniformSpacingPanel Spacing="10"> <hc:UniformSpacingPanel Spacing="10">
<TextBlock Text="名称:" Style="{StaticResource LeftTB}"/> <TextBlock Text="名称:" Style="{StaticResource LeftTB}"/>
<TextBox x:Name="IconName" Text="{Binding Name, Mode=OneWay}" Width="180" FontSize="14"/> <TextBox x:Name="IconName" Text="{Binding Name, Mode=OneWay}" Width="230" FontSize="14"/>
</hc:UniformSpacingPanel> </hc:UniformSpacingPanel>
<hc:Divider LineStrokeDashArray="3,3" LineStroke="Black"/> <hc:Divider LineStrokeDashArray="3,3" LineStroke="Black"/>
<hc:UniformSpacingPanel Spacing="10" Grid.ColumnSpan="4"> <hc:UniformSpacingPanel Spacing="10" Grid.ColumnSpan="4">
@@ -42,8 +42,12 @@
</CheckBox> </CheckBox>
</hc:UniformSpacingPanel> </hc:UniformSpacingPanel>
<hc:Divider LineStrokeDashArray="3,3" LineStroke="Black" Grid.ColumnSpan="4"/> <hc:Divider LineStrokeDashArray="3,3" LineStroke="Black" Grid.ColumnSpan="4"/>
<hc:UniformSpacingPanel Spacing="10">
<TextBlock Text="启动参数:" Style="{StaticResource LeftTB}"/>
<TextBox x:Name="StartArg" Text="{Binding StartArg, Mode=OneWay}" Width="230" Height="100" TextWrapping="Wrap" FontSize="14"/>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="10" Grid.ColumnSpan="4"> <hc:UniformSpacingPanel Spacing="10" Grid.ColumnSpan="4">
<Button Content="保存" Style="{StaticResource Btn1}" Click="SaveProperty" Margin="208,0,0,0"/> <Button Content="保存" Style="{StaticResource Btn1}" Click="SaveProperty" Margin="265,10,0,0"/>
</hc:UniformSpacingPanel> </hc:UniformSpacingPanel>
</StackPanel> </StackPanel>
</hc:SimplePanel> </hc:SimplePanel>

View File

@@ -38,6 +38,7 @@ namespace GeekDesk.Control.Other
info.BitmapImage = IconImg.Source as BitmapImage; info.BitmapImage = IconImg.Source as BitmapImage;
info.Name = IconName.Text; info.Name = IconName.Text;
info.AdminStartUp = IconIsAdmin.IsChecked.Value; info.AdminStartUp = IconIsAdmin.IsChecked.Value;
info.StartArg = StartArg.Text;
CommonCode.SaveAppData(MainWindow.appData); CommonCode.SaveAppData(MainWindow.appData);
dialog.Close(); dialog.Close();
} }

View File

@@ -9,7 +9,6 @@
xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
> >
<UserControl.Resources> <UserControl.Resources>
<!--右侧栏样式动画--> <!--右侧栏样式动画-->
@@ -48,6 +47,7 @@
<hc:Card.ContextMenu> <hc:Card.ContextMenu>
<ContextMenu Width="200"> <ContextMenu Width="200">
<MenuItem Header="添加URL项目" Click="AddUrlIcon"/> <MenuItem Header="添加URL项目" Click="AddUrlIcon"/>
<MenuItem Header="添加系统项目" Click="AddSystemIcon"/>
</ContextMenu> </ContextMenu>
</hc:Card.ContextMenu> </hc:Card.ContextMenu>
<WrapPanel Orientation="Horizontal" VirtualizingPanel.VirtualizationMode="Recycling" <WrapPanel Orientation="Horizontal" VirtualizingPanel.VirtualizationMode="Recycling"
@@ -76,6 +76,7 @@
<MenuItem Header="管理员方式运行" Click="IconAdminStart" Tag="{Binding}"/> <MenuItem Header="管理员方式运行" Click="IconAdminStart" Tag="{Binding}"/>
<MenuItem Header="打开文件所在位置" Click="ShowInExplore" Tag="{Binding}"/> <MenuItem Header="打开文件所在位置" Click="ShowInExplore" Tag="{Binding}"/>
<MenuItem Header="添加URL项目" Click="AddUrlIcon"/> <MenuItem Header="添加URL项目" Click="AddUrlIcon"/>
<MenuItem Header="添加系统项目" Click="AddSystemIcon"/>
<MenuItem Header="资源管理器菜单" Click="SystemContextMenu" Tag="{Binding}"/> <MenuItem Header="资源管理器菜单" Click="SystemContextMenu" Tag="{Binding}"/>
<MenuItem Header="属性" Click="PropertyConfig" Tag="{Binding}"/> <MenuItem Header="属性" Click="PropertyConfig" Tag="{Binding}"/>
<MenuItem Header="从列表移除" Click="RemoveIcon" Tag="{Binding}"/> <MenuItem Header="从列表移除" Click="RemoveIcon" Tag="{Binding}"/>

View File

@@ -1,6 +1,7 @@
using DraggAnimatedPanelExample; using DraggAnimatedPanelExample;
using GeekDesk.Constant; using GeekDesk.Constant;
using GeekDesk.Control.Other; using GeekDesk.Control.Other;
using GeekDesk.Control.Windows;
using GeekDesk.Util; using GeekDesk.Util;
using GeekDesk.ViewModel; using GeekDesk.ViewModel;
using HandyControl.Controls; using HandyControl.Controls;
@@ -119,80 +120,96 @@ namespace GeekDesk.Control.UserControls.PannelCard
try try
{ {
Process p = new Process(); Process p = new Process();
p.StartInfo.FileName = icon.Path;
if (icon.IconType == IconType.OTHER)
{
if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
{
HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
return;
}
p.StartInfo.WorkingDirectory = icon.Path.Substring(0, icon.Path.LastIndexOf("\\"));
switch (type)
{
case IconStartType.ADMIN_STARTUP:
p.StartInfo.Arguments = "1";//启动参数
p.StartInfo.Verb = "runas";
p.StartInfo.CreateNoWindow = false; //设置显示窗口
p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
p.StartInfo.ErrorDialog = false;
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MainWindow.hide.IsMargin())
{
MainWindow.HideApp();
}
}
else
{
MainWindow.HideApp();
}
} string startArg = icon.StartArg;
break;// c#好像不能case穿透
case IconStartType.DEFAULT_STARTUP: if (Constants.SYSTEM_ICONS.ContainsKey(startArg))
if (appData.AppConfig.AppHideType == AppHideType.START_EXE) {
{ StartSystemApp(startArg, type);
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MainWindow.hide.IsMargin())
{
MainWindow.HideApp();
}
} else
{
MainWindow.HideApp();
}
}
break;
case IconStartType.SHOW_IN_EXPLORE:
p.StartInfo.FileName = "Explorer.exe";
p.StartInfo.Arguments = "/e,/select," + icon.Path;
break;
}
} else } else
{ {
if (appData.AppConfig.AppHideType == AppHideType.START_EXE) p.StartInfo.FileName = icon.Path;
if (!StringUtil.IsEmpty(icon.StartArg))
{ {
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 p.StartInfo.Arguments = icon.StartArg;
if (appData.AppConfig.MarginHide) }
if (icon.IconType == IconType.OTHER)
{
if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
{ {
if (!MainWindow.hide.IsMargin()) HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
return;
}
p.StartInfo.WorkingDirectory = icon.Path.Substring(0, icon.Path.LastIndexOf("\\"));
switch (type)
{
case IconStartType.ADMIN_STARTUP:
//p.StartInfo.Arguments = "1";//启动参数
p.StartInfo.Verb = "runas";
p.StartInfo.CreateNoWindow = false; //设置显示窗口
p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
p.StartInfo.ErrorDialog = false;
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MainWindow.hide.IsMargin())
{
MainWindow.HideApp();
}
}
else
{
MainWindow.HideApp();
}
}
break;// c#好像不能case穿透
case IconStartType.DEFAULT_STARTUP:
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MainWindow.hide.IsMargin())
{
MainWindow.HideApp();
}
}
else
{
MainWindow.HideApp();
}
}
break;
case IconStartType.SHOW_IN_EXPLORE:
p.StartInfo.FileName = "Explorer.exe";
p.StartInfo.Arguments = "/e,/select," + icon.Path;
break;
}
}
else
{
if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
{
//如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
if (appData.AppConfig.MarginHide)
{
if (!MainWindow.hide.IsMargin())
{
MainWindow.HideApp();
}
}
else
{ {
MainWindow.HideApp(); MainWindow.HideApp();
} }
} }
else
{
MainWindow.HideApp();
}
} }
p.Start();
} }
p.Start();
icon.Count++; icon.Count++;
} }
catch (Exception e) catch (Exception e)
@@ -204,7 +221,68 @@ namespace GeekDesk.Control.UserControls.PannelCard
private void StartSystemApp(string startArg, IconStartType type)
{
if (type == IconStartType.SHOW_IN_EXPLORE)
{
Growl.WarningGlobal("系统项目不支持打开文件位置操作!");
return;
}
switch (startArg)
{
case "Calculator":
Process.Start("calc.exe");
break;
case "Computer":
Process.Start("explorer.exe");
break;
case "GroupPolicy":
Process.Start("gpedit.msc");
break;
case "Notepad":
Process.Start("notepad");
break;
case "Network":
Process.Start("ncpa.cpl");
break;
case "RecycleBin":
Process.Start("shell:RecycleBinFolder");
break;
case "Registry":
Process.Start("regedit.exe");
break;
case "Mstsc":
if (type == IconStartType.ADMIN_STARTUP)
{
Process.Start("mstsc", "-admin");
} else
{
Process.Start("mstsc");
}
break;
case "Control":
Process.Start("Control");
break;
case "CMD":
if (type == IconStartType.ADMIN_STARTUP)
{
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Verb = "runas";
process.Start();
} else
{
Process.Start("cmd");
}
break;
}
}
/// <summary>
/// 拖动添加项目
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Wrap_Drop(object sender, DragEventArgs e) private void Wrap_Drop(object sender, DragEventArgs e)
{ {
Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop); Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
@@ -212,36 +290,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
foreach (object obj in dropObject) foreach (object obj in dropObject)
{ {
string path = (string)obj; string path = (string)obj;
string tempPath = path; IconInfo iconInfo = CommonCode.GetIconInfoByPath(path);
//string base64 = ImageUtil.FileImageToBase64(path, System.Drawing.Imaging.ImageFormat.Png);
string ext = "";
if (!ImageUtil.IsSystemItem(path))
{
ext = System.IO.Path.GetExtension(path).ToLower();
}
if (".lnk".Equals(ext))
{
string targetPath = FileUtil.GetTargetPathByLnk(path);
if (targetPath!=null)
{
path = targetPath;
}
}
BitmapImage bi = ImageUtil.GetBitmapIconByPath(path);
IconInfo iconInfo = new IconInfo
{
Path = path,
BitmapImage = bi
};
iconInfo.DefaultImage = iconInfo.ImageByteArr;
iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(tempPath);
if (StringUtil.IsEmpty(iconInfo.Name))
{
iconInfo.Name = path;
}
MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo); MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
CommonCode.SaveAppData(MainWindow.appData); CommonCode.SaveAppData(MainWindow.appData);
} }
@@ -430,10 +479,25 @@ namespace GeekDesk.Control.UserControls.PannelCard
sb2.Remove(); sb2.Remove();
} }
/// <summary>
/// 添加URL项目
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddUrlIcon(object sender, RoutedEventArgs e) private void AddUrlIcon(object sender, RoutedEventArgs e)
{ {
IconInfoUrlDialog urlDialog = new IconInfoUrlDialog(); IconInfoUrlDialog urlDialog = new IconInfoUrlDialog();
urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog, "IconInfoDialog"); urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog, "IconInfoDialog");
} }
/// <summary>
/// 添加系统项目
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddSystemIcon(object sender, RoutedEventArgs e)
{
SystemItemWindow.Show();
}
} }
} }

View File

@@ -0,0 +1,57 @@
<UserControl x:Class="GeekDesk.Control.UserControls.SystemItem.SystemItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:GeekDesk.Control.UserControls.IconFont"
mc:Ignorable="d"
Background="#00FFFFFF"
>
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Top" Background="Transparent">
<ListBox x:Name="ItemListBox" ItemsSource="{Binding IconInfos}" BorderThickness="0"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsContainerVirtualizable="True"
>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Background="#00FFFFFF"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Background>
<SolidColorBrush Opacity="0"/>
</ListBox.Background>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="80" Height="80" HorizontalAlignment="Center"
Background="#00FFFFFF"
hc:Poptip.IsOpen="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
hc:Poptip.Content="{Binding Content_NoWrite, Mode=OneWay}"
Tag="{Binding}"
MouseLeftButtonDown="Icon_MouseLeftButtonDown"
hc:Poptip.Placement="BottomLeft"
hc:Poptip.HitMode="None"
>
<Image Source="{Binding BitmapImage_NoWrite, Mode=OneWay}" Width="45" Height="45" RenderOptions.BitmapScalingMode="HighQuality" />
<TextBlock TextAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextWrapping="Wrap"
MaxHeight="40"
FontSize="13"
TextTrimming="WordEllipsis"
Width="65" Text="{Binding Name_NoWrite, Mode=OneWay}"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
</UserControl>

View File

@@ -0,0 +1,59 @@
using GeekDesk.Constant;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GeekDesk.Control.UserControls.SystemItem
{
/// <summary>
/// IconPannel.xaml 的交互逻辑
/// </summary>
public partial class SystemItem : UserControl
{
public SystemItem()
{
InitializeComponent();
}
private void Icon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
IconInfo thisInfo = (sender as StackPanel).Tag as IconInfo;
MenuInfo menuInfo = MainWindow.appData.MenuList[MainWindow.appData.AppConfig.SelectedMenuIndex];
string startArg = thisInfo.StartArg;
IconInfo iconInfo;
if (Constants.SYSTEM_ICONS.ContainsKey(startArg))
{
//系统项
iconInfo = new IconInfo
{
Name_NoWrite = thisInfo.Name_NoWrite,
Path_NoWrite = thisInfo.Path_NoWrite,
StartArg_NoWrite = thisInfo.StartArg_NoWrite,
BitmapImage_NoWrite = thisInfo.BitmapImage_NoWrite
};
iconInfo.Content_NoWrite = iconInfo.Name_NoWrite
+ "\n使用次数:" + iconInfo.Count;
} else
{
//startupMenu or Store
iconInfo = CommonCode.GetIconInfoByPath(thisInfo.LnkPath_NoWrite);
}
menuInfo.IconList.Add(iconInfo);
CommonCode.SaveAppData(MainWindow.appData);
}
}
}

View File

@@ -5,7 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GeekDesk.Control.Windows" xmlns:local="clr-namespace:GeekDesk.Control.Windows"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:uc="clr-namespace:GeekDesk.Control.UserControls.IconFont" xmlns:uc="clr-namespace:GeekDesk.Control.UserControls.SystemItem"
xmlns:cvt="clr-namespace:GeekDesk.Converts"
mc:Ignorable="d" mc:Ignorable="d"
Title="Svg" Title="Svg"
Height="520" Width="700" Height="520" Width="700"
@@ -33,6 +34,7 @@
</Setter> </Setter>
</Style.Setters> </Style.Setters>
</Style> </Style>
<cvt:MenuInfoConvert x:Key="MenuInfoConvert"/>
</Window.Resources> </Window.Resources>
<Grid Margin="20"> <Grid Margin="20">
@@ -43,38 +45,52 @@
<Border MouseDown="DragMove" Style="{StaticResource BorderBG}" hc:Dialog.Token="IconUrlDialog"> <Border MouseDown="DragMove" Style="{StaticResource BorderBG}" hc:Dialog.Token="IconUrlDialog">
<hc:DialogContainer> <hc:DialogContainer>
<Grid MouseDown="DragMove"> <Grid MouseDown="DragMove">
<TextBox x:Name="CheckSettingUrl" Visibility="Collapsed" Text="{Binding IsSettingUrl}" TextChanged="CheckSettingUrl_TextChanged"/> <StackPanel HorizontalAlignment="Center" Margin="10">
<Border CornerRadius="8" Height="30" Width="150">
<Border.Background>
<SolidColorBrush Color="White" Opacity="0.7"/>
</Border.Background>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Background="Transparent"
BorderThickness="0"
hc:IconElement.Geometry="{Binding AppConfig.SelectedMenuIndex, Mode=OneWay, Converter={StaticResource MenuInfoConvert}, ConverterParameter=1}"
hc:IconElement.Height="18"
hc:IconElement.Width="18"
IsEnabled="False"
Opacity="1"
>
</Button>
<TextBlock x:Name="MenuName" Text="{Binding AppConfig.SelectedMenuIndex, Mode=OneWay, Converter={StaticResource MenuInfoConvert}, ConverterParameter=2}" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Border>
</StackPanel>
<hc:TabControl x:Name="MyTabControl" <hc:TabControl x:Name="MyTabControl"
IsAnimationEnabled="True" IsAnimationEnabled="True"
SelectionChanged="TabControl_SelectionChanged" SelectionChanged="TabControl_SelectionChanged"
ShowContextMenu="True" ShowContextMenu="True"
IsTabFillEnabled="True" IsTabFillEnabled="True"
Margin="20,30,20,20" Margin="20,60,20,20"
Height="350" Height="350"
VerticalAlignment="Top" VerticalAlignment="Top"
Style="{StaticResource HcTabControl}"> Style="{StaticResource HcTabControl}">
<hc:TabItem Tag="System" IsSelected="True" Header="系统应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}"> <hc:TabItem Tag="System" IsSelected="True" Header="系统应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}">
<hc:SimplePanel> <hc:SimplePanel>
<uc:IconPannel x:Name="SystemItem"/> <uc:SystemItem x:Name="SystemItem"/>
</hc:SimplePanel> </hc:SimplePanel>
</hc:TabItem> </hc:TabItem>
<hc:TabItem Tag="System" IsSelected="True" Header="开始菜单应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}"> <hc:TabItem x:Name="StartMenu" Tag="StartMenu" Header="开始菜单应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" Style="{StaticResource TabTitle}">
<hc:SimplePanel> <hc:SimplePanel>
<uc:IconPannel x:Name="StartMenuItem"/> <uc:SystemItem x:Name="StartMenuItem"/>
<hc:LoadingCircle x:Name="StartMenuLoading"/>
</hc:SimplePanel> </hc:SimplePanel>
</hc:TabItem> </hc:TabItem>
<hc:TabItem Tag="Custom" Header="商店应用" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CustomIcon}" Style="{StaticResource TabTitle}"> <!--<hc:TabItem Tag="Store" Header="商店应用(未开放)" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CustomIcon}" Style="{StaticResource TabTitle}">
<hc:SimplePanel> <hc:SimplePanel>
<uc:IconPannel x:Name="CustomIcon"/> <uc:SystemItem x:Name="StoreItem"/>
<hc:LoadingCircle x:Name="LoadingEle"/>
</hc:SimplePanel> </hc:SimplePanel>
</hc:TabItem> </hc:TabItem>-->
</hc:TabControl> </hc:TabControl>
<Button Content="关闭" Click="Close_Click" Margin="594,420,20,31.5"/>
<Button Content="取消" Click="Close_Click" Margin="391,397.5,163,22.5"/>
<Button Content="自定义设置" Click="CustomButton_Click" IsEnabled="False" Name="CustomButton" Style="{StaticResource Btn1}" Margin="447,397.5,71,22.5"/>
<Button Content="确定" Click="Confirm_Click" Style="{StaticResource Btn1}" Margin="534,397.5,20,22.5" />
</Grid> </Grid>
</hc:DialogContainer> </hc:DialogContainer>
</Border> </Border>

View File

@@ -1,16 +1,22 @@
using GeekDesk.Control.Other; using GeekDesk.Constant;
using GeekDesk.Control.Other;
using GeekDesk.Interface; using GeekDesk.Interface;
using GeekDesk.Util; using GeekDesk.Util;
using GeekDesk.ViewModel; using GeekDesk.ViewModel;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Resources;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Imaging;
using static GeekDesk.Util.ShowWindowFollowMouse; using static GeekDesk.Util.ShowWindowFollowMouse;
namespace GeekDesk.Control.Windows namespace GeekDesk.Control.Windows
@@ -22,27 +28,19 @@ namespace GeekDesk.Control.Windows
public partial class SystemItemWindow : Window, IWindowCommon public partial class SystemItemWindow : Window, IWindowCommon
{ {
private static AppConfig appConfig = MainWindow.appData.AppConfig; private static AppConfig appConfig = MainWindow.appData.AppConfig;
private static MenuInfo menuInfo; private static SystemItemViewModel vm;
private static List<IconfontInfo> systemIcons; private static List<IconInfo> systemIcons;
private static List<IconfontInfo> customIcons; private static List<IconInfo> startMenuIcons;
public static IconfontViewModel vm; private static List<IconInfo> storeIcons;
private SystemItemWindow(List<IconfontInfo> icons, MenuInfo menuInfo)
private SystemItemWindow()
{ {
vm = new SystemItemViewModel();
InitializeComponent();
systemIcons = icons;
this.Topmost = true;
SystemItemWindow.menuInfo = menuInfo;
vm = new IconfontViewModel
{
Iconfonts = systemIcons
};
this.DataContext = vm; this.DataContext = vm;
InitializeComponent();
this.Topmost = true;
} }
/// <summary> /// <summary>
/// 移动窗口 /// 移动窗口
/// </summary> /// </summary>
@@ -61,157 +59,186 @@ namespace GeekDesk.Control.Windows
this.Close(); this.Close();
} }
/// <summary>
/// 切换选项卡
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
TabItem ti = this.MyTabControl.SelectedItem as TabItem; TabItem ti = this.MyTabControl.SelectedItem as TabItem;
List<IconInfo> systemInfos = vm.IconInfos;
if (systemInfos == null)
{
systemInfos = new List<IconInfo>();
}
switch (ti.Tag.ToString()) switch (ti.Tag.ToString())
{ {
case "Custom": case "StartMenu": //开始菜单
CustomButton.IsEnabled = true; if (startMenuIcons == null)
if (StringUtil.IsEmpty(appConfig.CustomIconUrl) || StringUtil.IsEmpty(appConfig.CustomIconJsonUrl))
{ {
LoadingEle.Visibility = Visibility.Visible; vm.IconInfos = null;
CustomIcon.Visibility = Visibility.Collapsed; System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(GetStartMenuInfos))
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig), "IconUrlDialog"); {
IsBackground = true
};
t.Start();
} else } else
{ {
if (customIcons == null) StartMenuLoading.Visibility = Visibility.Collapsed;
vm.IconInfos = startMenuIcons;
}
break;
case "Store": //应用商店
if (storeIcons == null)
{
vm.IconInfos = null;
storeIcons = new List<IconInfo>();
vm.IconInfos = storeIcons;
}
else
{
vm.IconInfos = storeIcons;
}
break;
default: //默认系统项
if (systemIcons == null)
{
vm.IconInfos = null;
systemIcons = GetSysteIconInfos();
vm.IconInfos = systemIcons;
} else
{
vm.IconInfos = systemIcons;
}
break;
}
}
/// <summary>
/// 获取开始菜单路径下项目
/// </summary>
/// <returns></returns>
private void GetStartMenuInfos()
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
StartMenuLoading.Visibility = Visibility.Visible;
}));
List<IconInfo> infos = new List<IconInfo>();
//获取开始菜单路径
string path = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs";
//递归获取信息
GetInfos(path, infos);
App.Current.Dispatcher.Invoke((Action)(() =>
{
if (StartMenu.IsSelected)
{
startMenuIcons = infos;
vm.IconInfos = startMenuIcons;
}
StartMenuLoading.Visibility = Visibility.Collapsed;
}));
}
/// <summary>
/// 递归获取文件信息
/// </summary>
/// <param name="path"></param>
/// <param name="listInfos"></param>
private void GetInfos(string path, List<IconInfo> listInfos)
{
DirectoryInfo di = new DirectoryInfo(path);
FileSystemInfo[] fileInfoArr = di.GetFileSystemInfos();
foreach(FileSystemInfo fi in fileInfoArr)
{
path = fi.FullName;
if (File.Exists(path))
{
string ext = Path.GetExtension(path).ToLower();
if (".exe".Equals(ext) || ".lnk".Equals(ext))
{
try
{ {
vm.Iconfonts = null; IconInfo iconInfo = CommonCode.GetIconInfoByPath_NoWrite(path);
LoadingOnlineIcon(); if (iconInfo.Path_NoWrite != null)
} else {
{ iconInfo.Content_NoWrite = iconInfo.Path_NoWrite + "\n" + iconInfo.Name_NoWrite;
vm.Iconfonts = customIcons; listInfos.Add(iconInfo);
LoadingEle.Visibility = Visibility.Collapsed; }
CustomIcon.Visibility = Visibility.Visible;
} }
catch (Exception) { }
} }
break; }
default: else if (Directory.Exists(path))
if (CustomButton != null) {
{ GetInfos(path, listInfos);
CustomButton.IsEnabled = false; }
}
if (vm != null)
{
vm.Iconfonts = systemIcons;
}
break;
} }
} }
private void Confirm_Click(object sender, RoutedEventArgs e) /// <summary>
/// 获取系统项目
/// </summary>
/// <returns></returns>
private List<IconInfo> GetSysteIconInfos()
{ {
TabItem ti = this.MyTabControl.SelectedItem as TabItem; List<IconInfo> iconInfos = new List<IconInfo>();
int index;
switch (ti.Tag.ToString()) Hashtable systemIcons = Constants.SYSTEM_ICONS;
IconInfo iconInfo;
foreach (object key in systemIcons.Keys)
{ {
case "Custom": string keyStr = key.ToString();
index = this.CustomIcon.IconListBox.SelectedIndex; iconInfo = new IconInfo
if (index != -1) {
{ Name_NoWrite = systemIcons[key].ToString()
menuInfo.MenuGeometry = customIcons[index].Text; };
} iconInfo.BitmapImage_NoWrite = new BitmapImage(
break; new Uri("pack://application:,,,/GeekDesk;component/Resource/Image/SystemIcon/" + keyStr + ".png"
default: , UriKind.RelativeOrAbsolute));
index = this.CustomIcon.IconListBox.SelectedIndex; iconInfo.StartArg = keyStr;
if (index != -1) iconInfo.Content_NoWrite = iconInfo.Name_NoWrite;
{ iconInfos.Add(iconInfo);
menuInfo.MenuGeometry = systemIcons[index].Text;
}
break;
} }
this.Close(); return iconInfos;
} }
public class SystemItemViewModel : INotifyPropertyChanged
private static System.Windows.Window window = null;
public static void Show(List<IconfontInfo> listInfo, MenuInfo menuInfo)
{ {
if (window == null || !window.Activate()) private List<IconInfo> iconInfos;
private AppConfig appConfig;
public SystemItemViewModel()
{ {
window = new SystemItemWindow(listInfo, menuInfo); this.AppConfig = MainWindow.appData.AppConfig;
} }
window.Show();
Keyboard.Focus(window);
ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0, false);
}
private void CustomButton_Click(object sender, RoutedEventArgs e) public AppConfig AppConfig
{
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig));
}
private void CheckSettingUrl_TextChanged(object sender, TextChangedEventArgs e)
{
if (CheckSettingUrl.Text == "true")
{
LoadingOnlineIcon();
} else
{
LoadingEle.IsRunning = true;
CustomIcon.Visibility = Visibility.Collapsed;
}
}
private void LoadingOnlineIcon()
{
try
{
string svgJsStr = HttpUtil.Get(appConfig.CustomIconUrl);
string jsonStr = HttpUtil.Get(appConfig.CustomIconJsonUrl);
List<IconfontInfo> icons = SvgToGeometry.GetIconfonts(svgJsStr, jsonStr);
customIcons = icons;
vm.Iconfonts = customIcons;
LoadingEle.Visibility = Visibility.Collapsed;
CustomIcon.Visibility = Visibility.Visible;
}
catch (Exception e)
{
HandyControl.Controls.Growl.WarningGlobal("加载远程图标异常!");
LogUtil.WriteErrorLog(e, "加载远程图标异常!");
}
}
public void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}
public class IconfontViewModel : INotifyPropertyChanged
{
private List<IconfontInfo> iconfonts;
private string isSettingUrl;
public List<IconfontInfo> Iconfonts
{ {
get get
{ {
return iconfonts; return appConfig;
} }
set set
{ {
iconfonts = value; appConfig = value;
OnPropertyChanged("Iconfonts"); OnPropertyChanged("AppConfig");
} }
} }
public List<IconInfo> IconInfos
public string IsSettingUrl
{ {
get get
{ {
return isSettingUrl; return iconInfos;
} }
set set
{ {
isSettingUrl = value; iconInfos = value;
OnPropertyChanged("IsSettingUrl"); OnPropertyChanged("IconInfos");
} }
} }
@@ -223,5 +250,32 @@ namespace GeekDesk.Control.Windows
} }
} }
private static System.Windows.Window window = null;
public static void Show()
{
if (window == null || !window.Activate())
{
window = new SystemItemWindow();
}
window.Show();
Keyboard.Focus(window);
ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0, false);
}
public void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}
} }
} }

View File

@@ -0,0 +1,45 @@
using GeekDesk.Constant;
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.Converts
{
public class MenuInfoConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int menuIndex = MainWindow.appData.AppConfig.SelectedMenuIndex;
if (menuIndex == -1)
{
return "";
} else
{
string type = parameter.ToString();
if ("1".Equals(type))
{
return MainWindow.appData.MenuList[menuIndex].MenuGeometry;
}
else
{
return MainWindow.appData.MenuList[menuIndex].MenuName;
}
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
//bool isChecked = (bool)value;
//if (!isChecked)
//{
// return null;
//}
//return (AppHideType)int.Parse(parameter.ToString());
}
}
}

View File

@@ -143,6 +143,9 @@
<Compile Include="Control\UserControls\Config\OtherControl.xaml.cs"> <Compile Include="Control\UserControls\Config\OtherControl.xaml.cs">
<DependentUpon>OtherControl.xaml</DependentUpon> <DependentUpon>OtherControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Control\UserControls\SystemItem\SystemItem.xaml.cs">
<DependentUpon>SystemItem.xaml</DependentUpon>
</Compile>
<Compile Include="Control\UserControls\ToDo\TodoControl.xaml.cs"> <Compile Include="Control\UserControls\ToDo\TodoControl.xaml.cs">
<DependentUpon>TodoControl.xaml</DependentUpon> <DependentUpon>TodoControl.xaml</DependentUpon>
</Compile> </Compile>
@@ -186,6 +189,7 @@
<DependentUpon>UpdateWindow.xaml</DependentUpon> <DependentUpon>UpdateWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Converts\DoubleToGridLength.cs" /> <Compile Include="Converts\DoubleToGridLength.cs" />
<Compile Include="Converts\MenuInfoConvert.cs" />
<Compile Include="Converts\TodoTaskExecConvert.cs" /> <Compile Include="Converts\TodoTaskExecConvert.cs" />
<Compile Include="Converts\IntToCornerRadius.cs" /> <Compile Include="Converts\IntToCornerRadius.cs" />
<Compile Include="Converts\OpcityConvert.cs" /> <Compile Include="Converts\OpcityConvert.cs" />
@@ -241,6 +245,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Control\UserControls\SystemItem\SystemItem.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Control\UserControls\ToDo\TodoControl.xaml"> <Page Include="Control\UserControls\ToDo\TodoControl.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@@ -387,5 +395,25 @@
<EmbedInteropTypes>True</EmbedInteropTypes> <EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference> </COMReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="Resource\Image\SystemIcon\Calculator.png" />
<Resource Include="Resource\Image\SystemIcon\Computer.png" />
<Resource Include="Resource\Image\SystemIcon\GroupPolicy.png" />
<Resource Include="Resource\Image\SystemIcon\Network.png" />
<Resource Include="Resource\Image\SystemIcon\RecycleBin.png" />
<Resource Include="Resource\Image\SystemIcon\Registry.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resource\Image\SystemIcon\Notepad.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resource\Image\SystemIcon\Mstsc.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resource\Image\SystemIcon\Control.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resource\Image\SystemIcon\CMD.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@@ -11,7 +11,8 @@
x:Name="window" x:Name="window"
xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:AppData}" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:AppData}"
Title="GeekDesk" Title="GeekDesk"
d:DesignHeight="500" d:DesignWidth="700" MinWidth="600"
MinHeight="400"
WindowStyle="None" WindowStyle="None"
AllowsTransparency="True" AllowsTransparency="True"
Background="Transparent" Background="Transparent"
@@ -129,7 +130,7 @@
<hc:NotifyIcon.ContextMenu> <hc:NotifyIcon.ContextMenu>
<ContextMenu Width="130"> <ContextMenu Width="130">
<MenuItem Header="打开面板" Click="ShowApp"/> <MenuItem Header="打开面板" Click="ShowApp"/>
<MenuItem Header="关闭图标" Click="CloseBarIcon"/> <MenuItem Header="隐藏图标" Click="CloseBarIcon"/>
<MenuItem Header="待办" Click="BacklogMenuClick"/> <MenuItem Header="待办" Click="BacklogMenuClick"/>
<MenuItem Header="程序目录" Click="OpenThisDir"/> <MenuItem Header="程序目录" Click="OpenThisDir"/>
<MenuItem Header="设置" Click="ConfigApp"/> <MenuItem Header="设置" Click="ConfigApp"/>

View File

@@ -62,6 +62,7 @@ namespace GeekDesk
/// </summary> /// </summary>
private void LoadData() private void LoadData()
{ {
GC.KeepAlive(MainWindow.appData); // 持活
this.DataContext = appData; this.DataContext = appData;
if (appData.MenuList.Count == 0) if (appData.MenuList.Count == 0)
{ {
@@ -130,7 +131,7 @@ namespace GeekDesk
{ {
if (MotionControl.hotkeyFinished) if (MotionControl.hotkeyFinished)
{ {
if (mainWindow.Visibility == Visibility.Collapsed || mainWindow.Opacity == 0) if (mainWindow.Visibility == Visibility.Collapsed || mainWindow.Opacity == 0 || MarginHide.isHide)
{ {
ShowApp(); ShowApp();
} }
@@ -187,7 +188,7 @@ namespace GeekDesk
mainWindow.Opacity = 0; mainWindow.Opacity = 0;
} }
}; };
Timeline.SetDesiredFrameRate(opacityAnimation, 30); Timeline.SetDesiredFrameRate(opacityAnimation, 60);
mainWindow.BeginAnimation(OpacityProperty, opacityAnimation); mainWindow.BeginAnimation(OpacityProperty, opacityAnimation);
} else } else
{ {
@@ -335,6 +336,8 @@ namespace GeekDesk
//{ //{
// return; // return;
//} //}
//修改贴边隐藏状态为未隐藏
MarginHide.isHide = false;
if (appData.AppConfig.FollowMouse) if (appData.AppConfig.FollowMouse)
{ {
ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0, false); ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0, false);

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -1,4 +1,5 @@
using GeekDesk.Control.UserControls.Config; using GeekDesk.Control.UserControls.Config;
using GeekDesk.Util;
using GeekDesk.ViewModel; using GeekDesk.ViewModel;
using Gma.System.MouseKeyHook; using Gma.System.MouseKeyHook;
using System; using System;
@@ -51,7 +52,9 @@ namespace GeekDesk.Thread
{ {
MainWindow.mainWindow.Dispatcher.Invoke((Action)(() => MainWindow.mainWindow.Dispatcher.Invoke((Action)(() =>
{ {
if (MainWindow.mainWindow.Visibility == Visibility.Collapsed || MainWindow.mainWindow.Opacity == 0) if (MainWindow.mainWindow.Visibility == Visibility.Collapsed
|| MainWindow.mainWindow.Opacity == 0
|| MarginHide.isHide)
{ {
MainWindow.ShowApp(); MainWindow.ShowApp();
} }

View File

@@ -2,7 +2,7 @@
"title": "GeekDesk版本更新", "title": "GeekDesk版本更新",
"subTitle": "V2.4.10", "subTitle": "V2.4.10",
"msgTitle": "本次更新内容如下", "msgTitle": "本次更新内容如下",
"msg": "['']", "msg": "['各位兄弟去给我点个免费Star呗','增加添加系统和开始菜单应用功能','增加项目启动参数','优化贴边隐藏动画效果','增加双击打开功能','其它已知问题修复']",
"githubUrl": "https://github.com/Demo-Liu/GeekDesk/releases", "githubUrl": "https://github.com/Demo-Liu/GeekDesk/releases",
"giteeUrl": "https://gitee.com/demo_liu/GeekDesk/releases", "giteeUrl": "https://gitee.com/demo_liu/GeekDesk/releases",
"version": "2.4.10" "version": "2.4.10"

View File

@@ -5,6 +5,7 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Windows; using System.Windows;
using System.Windows.Media.Imaging;
/// <summary> /// <summary>
/// 提取一些代码 /// 提取一些代码
@@ -45,7 +46,6 @@ namespace GeekDesk.Util
/// <param name="appData"></param> /// <param name="appData"></param>
public static void SaveAppData(AppData appData) public static void SaveAppData(AppData appData)
{ {
using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Create)) using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Create))
{ {
BinaryFormatter bf = new BinaryFormatter(); BinaryFormatter bf = new BinaryFormatter();
@@ -74,6 +74,100 @@ namespace GeekDesk.Util
return false; return false;
} }
/// <summary>
/// 根据路径获取文件图标等信息
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static IconInfo GetIconInfoByPath(string path)
{
string tempPath = path;
//string base64 = ImageUtil.FileImageToBase64(path, System.Drawing.Imaging.ImageFormat.Png);
//string ext = "";
//if (!ImageUtil.IsSystemItem(path))
//{
// ext = System.IO.Path.GetExtension(path).ToLower();
//}
string iconPath = null;
//if (".lnk".Equals(ext))
//{
string targetPath = FileUtil.GetTargetPathByLnk(path);
iconPath = FileUtil.GetIconPathByLnk(path);
if (targetPath != null)
{
path = targetPath;
}
//}
if (StringUtil.IsEmpty(iconPath))
{
iconPath = path;
}
BitmapImage bi = ImageUtil.GetBitmapIconByPath(iconPath);
IconInfo iconInfo = new IconInfo
{
Path = path,
LnkPath = tempPath,
BitmapImage = bi,
StartArg = FileUtil.GetArgByLnk(tempPath)
};
iconInfo.DefaultImage = iconInfo.ImageByteArr;
iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(tempPath);
if (StringUtil.IsEmpty(iconInfo.Name))
{
iconInfo.Name = path;
}
return iconInfo;
}
public static IconInfo GetIconInfoByPath_NoWrite(string path)
{
string tempPath = path;
//string base64 = ImageUtil.FileImageToBase64(path, System.Drawing.Imaging.ImageFormat.Png);
string ext = "";
if (!ImageUtil.IsSystemItem(path))
{
ext = System.IO.Path.GetExtension(path).ToLower();
}
string iconPath = null;
if (".lnk".Equals(ext))
{
string targetPath = FileUtil.GetTargetPathByLnk(path);
iconPath = FileUtil.GetIconPathByLnk(path);
if (targetPath != null)
{
path = targetPath;
}
}
if (StringUtil.IsEmpty(iconPath))
{
iconPath = path;
}
BitmapImage bi = ImageUtil.GetBitmapIconByPath(iconPath);
IconInfo iconInfo = new IconInfo
{
Path_NoWrite = path,
LnkPath_NoWrite = tempPath,
BitmapImage_NoWrite = bi,
StartArg_NoWrite = FileUtil.GetArgByLnk(tempPath)
};
iconInfo.DefaultImage_NoWrite = iconInfo.ImageByteArr;
iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(tempPath);
if (StringUtil.IsEmpty(iconInfo.Name))
{
iconInfo.Name_NoWrite = path;
}
return iconInfo;
}
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
private struct RECT private struct RECT

View File

@@ -72,23 +72,12 @@ namespace GeekDesk.Util
ico = Icon.FromHandle(ip); ico = Icon.FromHandle(ip);
} }
IntPtr hIcon2 = IntPtr.Zero; return IconToBitmapImage(ico, ip);
//TODO }
for (int i=0; i<=1000; i++)
{
try
{
ico = SystemIcon.MyExtractIcon("%SystemRoot%\\system32\\shell32.dll", i, hIcon2);
Bitmap bmp2 = ico.ToBitmap();
bmp2.Save("d:\\test\\" + i + ".png");
} catch
{
} private static BitmapImage IconToBitmapImage(Icon icon, IntPtr iconIP)
} {
ico = SystemIcon.MyExtractIcon("%SystemRoot%\\system32\\shell32.dll", 16, hIcon2); Bitmap bmp = icon.ToBitmap();
Bitmap bmp = ico.ToBitmap();
MemoryStream strm = new MemoryStream(); MemoryStream strm = new MemoryStream();
ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/png"); ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/png");
@@ -96,16 +85,18 @@ namespace GeekDesk.Util
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 75L); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 75L);
EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameters myEncoderParameters = new EncoderParameters(1);
myEncoderParameters.Param[0] = myEncoderParameter; myEncoderParameters.Param[0] = myEncoderParameter;
bmp.Save("d:\\test.png");
//bmp.Save("d:\\test.png");
bmp.Save(strm, myImageCodecInfo, myEncoderParameters); bmp.Save(strm, myImageCodecInfo, myEncoderParameters);
BitmapImage bmpImage = new BitmapImage(); BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit(); bmpImage.BeginInit();
strm.Seek(0, SeekOrigin.Begin); strm.Seek(0, SeekOrigin.Begin);
bmpImage.StreamSource = strm; bmpImage.StreamSource = strm;
bmpImage.EndInit(); bmpImage.EndInit();
if (ip != IntPtr.Zero) if (iconIP != IntPtr.Zero)
{ {
Shell32.DestroyIcon(ip); Shell32.DestroyIcon(iconIP);
} }
return bmpImage.Clone(); return bmpImage.Clone();
} }

View File

@@ -12,7 +12,9 @@ namespace GeekDesk.Util
public class FileUtil public class FileUtil
{ {
private static readonly string NO_PATH = ".*{.*}.*"; private static readonly string NO_PATH = "{(.*)}";
private static readonly string NO_ICO = "^,(.*)";
private static readonly string HAVE_ICO = "(.*),(.*)";
public static string GetTargetPathByLnk(string filePath) public static string GetTargetPathByLnk(string filePath)
{ {
@@ -20,7 +22,6 @@ namespace GeekDesk.Util
{ {
WshShell shell = new WshShell(); WshShell shell = new WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
if (StringUtil.IsEmpty(shortcut.TargetPath)) if (StringUtil.IsEmpty(shortcut.TargetPath))
{ {
return null; return null;
@@ -32,11 +33,60 @@ namespace GeekDesk.Util
} }
return path; return path;
} }
#pragma warning disable CS0168 // 声明了变量“e”但从未使用过
catch (Exception e) catch (Exception e)
#pragma warning restore CS0168 // 声明了变量“e”但从未使用过
{ {
LogUtil.WriteErrorLog(e, "获取文件图标失败! filePath=" + filePath); LogUtil.WriteErrorLog(e, "获取目标路径失败! filePath=" + filePath);
return null;
}
}
/// <summary>
/// 获取启动参数
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string GetArgByLnk(string filePath)
{
try
{
WshShell shell = new WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
return shortcut.Arguments;
}
catch (Exception e)
{
LogUtil.WriteErrorLog(e, "获取启动参数失败! filePath=" + filePath);
return "";
}
}
/// <summary>
/// 获取iconpath
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string GetIconPathByLnk(string filePath)
{
try
{
WshShell shell = new WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
var iconPath = shortcut.IconLocation;
if (StringUtil.IsEmpty(iconPath)
|| Regex.IsMatch(iconPath, NO_ICO)
|| Regex.IsMatch(iconPath, NO_PATH)
|| !Regex.IsMatch(iconPath, HAVE_ICO))
{
return null;
} else
{
return iconPath.Split(',')[0];
}
}
catch (Exception e)
{
LogUtil.WriteErrorLog(e, "获取图标路径失败! filePath=" + filePath);
return null; return null;
} }
} }

View File

@@ -86,6 +86,11 @@ namespace GeekDesk.Util
/// <returns></returns> /// <returns></returns>
public static BitmapImage GetBitmapIconByPath(string filePath) public static BitmapImage GetBitmapIconByPath(string filePath)
{ {
if (filePath.Contains("%windir%"))
{
filePath = filePath.Replace("%windir%", System.Environment.GetEnvironmentVariable("windir"));
}
if (File.Exists(filePath) || IsSystemItem(filePath)) if (File.Exists(filePath) || IsSystemItem(filePath))
{ {
if (IsImage(filePath)) { if (IsImage(filePath)) {

View File

@@ -27,7 +27,7 @@ namespace GeekDesk.Util
double left = SystemParameters.VirtualScreenLeft; double left = SystemParameters.VirtualScreenLeft;
double top = SystemParameters.VirtualScreenTop; double top = SystemParameters.VirtualScreenTop;
double width = SystemParameters.VirtualScreenWidth; double width = SystemParameters.VirtualScreenWidth;
double height = SystemParameters.WorkArea.Height + 20; double height = SystemParameters.WorkArea.Height + 20; // 不遮挡任务栏
double right = width - Math.Abs(left); double right = width - Math.Abs(left);
double bottom = height - Math.Abs(top); double bottom = height - Math.Abs(top);

View File

@@ -25,10 +25,60 @@ namespace GeekDesk.ViewModel
private string content; //显示信息 private string content; //显示信息
private bool adminStartUp = false; //始终管理员方式启动 默认否 private bool adminStartUp = false; //始终管理员方式启动 默认否
private byte[] defaultImage; //默认图标 private byte[] defaultImage; //默认图标
private string startArg; //启动参数
private string lnkPath;
private IconType iconType = IconType.OTHER; private IconType iconType = IconType.OTHER;
public string LnkPath_NoWrite
{
get
{
return lnkPath;
}
set
{
lnkPath = value;
}
}
public string LnkPath
{
get
{
return lnkPath;
}
set
{
lnkPath = value;
OnPropertyChanged("LnkPath");
}
}
public string StartArg
{
get
{
return startArg;
}
set
{
startArg = value;
OnPropertyChanged("StartArg");
}
}
public string StartArg_NoWrite
{
get
{
return startArg;
}
set
{
startArg = value;
}
}
public IconType IconType public IconType IconType
{ {
get get
@@ -56,6 +106,18 @@ namespace GeekDesk.ViewModel
} }
} }
public byte[] DefaultImage_NoWrite
{
get
{
return defaultImage;
}
set
{
defaultImage = value;
}
}
public bool AdminStartUp public bool AdminStartUp
{ {
get get
@@ -78,7 +140,13 @@ namespace GeekDesk.ViewModel
set set
{ {
count = value; count = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count; if (StringUtil.IsEmpty(Path))
{
Content = Name + "\n使用次数: " + Count;
} else
{
Content = Path + "\n" + Name + "\n使用次数: " + Count;
}
OnPropertyChanged("Count"); OnPropertyChanged("Count");
} }
} }
@@ -92,11 +160,30 @@ namespace GeekDesk.ViewModel
set set
{ {
name = value; name = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count; if (StringUtil.IsEmpty(Path))
{
Content = Name + "\n使用次数: " + Count;
}
else
{
Content = Path + "\n" + Name + "\n使用次数: " + Count;
}
OnPropertyChanged("Name"); OnPropertyChanged("Name");
} }
} }
public string Name_NoWrite
{
get
{
return name;
}
set
{
name = value;
}
}
public string Path public string Path
{ {
get get
@@ -106,11 +193,31 @@ namespace GeekDesk.ViewModel
set set
{ {
path = value; path = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count; if (StringUtil.IsEmpty(Path))
{
Content = Name + "\n使用次数: " + Count;
}
else
{
Content = Path + "\n" + Name + "\n使用次数: " + Count;
}
OnPropertyChanged("Path"); OnPropertyChanged("Path");
} }
} }
public string Path_NoWrite
{
get
{
return path;
}
set
{
path = value;
}
}
public BitmapImage BitmapImage public BitmapImage BitmapImage
{ {
get get
@@ -126,6 +233,20 @@ namespace GeekDesk.ViewModel
} }
} }
public BitmapImage BitmapImage_NoWrite
{
get
{
return ImageUtil.ByteArrToImage(ImageByteArr_NoWrite);
}
set
{
bitmapImage = value;
ImageByteArr_NoWrite = ImageUtil.BitmapImageToByte(bitmapImage);
}
}
public byte[] ImageByteArr public byte[] ImageByteArr
{ {
get get
@@ -140,6 +261,19 @@ namespace GeekDesk.ViewModel
} }
} }
public byte[] ImageByteArr_NoWrite
{
get
{
return imageByteArr;
}
set
{
imageByteArr = value;
}
}
public string Content public string Content
{ {
get get
@@ -153,9 +287,17 @@ namespace GeekDesk.ViewModel
} }
} }
public override String ToString()
public string Content_NoWrite
{ {
return JsonConvert.SerializeObject(this); get
{
return content;
}
set
{
content = value;
}
} }