🚑 增加了备份和自动备份功能 端午节快乐 🎉

This commit is contained in:
liufei
2022-06-03 22:04:10 +08:00
parent 0aa7969e4a
commit e42f2c3c73
23 changed files with 311 additions and 54 deletions

View File

@@ -19,13 +19,14 @@
<add key="Services" value="服务" />
</SystemIcons>
<SystemBGs>
<GradientBGParam Color1="#FCCF31" Color2="#F55555" Name="诸神黄昏"/>
<GradientBGParam Color1="#FCCF31" Color2="#F55555" Name="诸神黄昏" />
</SystemBGs>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
<dependentAssembly>
<assemblyIdentity name="CommonServiceLocator" publicKeyToken="489b6accfaf20ef0" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.6.0" newVersion="2.0.6.0" />

View File

@@ -18,9 +18,14 @@ namespace GeekDesk.Constant
/// </summary>
public static string DATA_FILE_PATH = APP_DIR + "Data"; //app数据文件路径
public static string LOG_FILE_PATH = APP_DIR + "Log.log";
/// <summary>
/// 备份文件路径
/// </summary>
public static string DATA_FILE_BAK_PATH = APP_DIR + "bak\\Data.bak"; //app数据文件路径
public static string ERROR_FILE_PATH = APP_DIR + "Error.log";
public static string LOG_FILE_PATH = APP_DIR + "logs\\log.log";
public static string ERROR_FILE_PATH = APP_DIR + "logs\\error.log";
public static int SHADOW_WIDTH = 20;

View File

@@ -62,7 +62,7 @@ namespace GeekDesk.Control.Other
}
ToDoTask.activityBacklog[info].Close(); //关闭桌面通知
ToDoTask.activityBacklog.Remove(info);//激活任务删除
CommonCode.SaveAppData(appData);
CommonCode.SaveAppData(appData, Constants.DATA_FILE_PATH);
}

View File

@@ -0,0 +1,54 @@
<Border x:Class="GeekDesk.Control.Other.GlobalMsgNotification"
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"
BorderThickness="0"
Style="{StaticResource BorderBG}"
Margin="15"
BorderBrush="{DynamicResource BorderBrush}"
Width="320"
Height="400">
<Border.Background>
<SolidColorBrush Color="AliceBlue" Opacity="0.96"/>
</Border.Background>
<Grid>
<StackPanel>
<Image Source="/Resource/Image/BacklogImg.png" Width="260" Margin="0,20,0,0"/>
<hc:Card Width="260" Height="220" BorderThickness="0" Effect="{DynamicResource EffectShadow2}" Margin="0,20,0,0">
<Border CornerRadius="4,4,0,0" Height="160" Padding="10,0,10,0">
<ScrollViewer>
<TextBlock TextOptions.TextFormattingMode="Display"
TextOptions.TextHintingMode="Animated"
UseLayoutRounding="True"
TextWrapping="Wrap"
FontStyle="Normal"
FontSize="15"
LineHeight="22"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="{Binding Msg}"/>
</ScrollViewer>
</Border>
<!--<hc:Card.Footer>
<StackPanel Margin="10" Width="160">
<TextBlock TextWrapping="NoWrap" FontSize="20" Style="{DynamicResource TextBlockLargeBold}" TextTrimming="CharacterEllipsis"
Text="{Binding Title}"
HorizontalAlignment="Left"/>
<TextBlock TextWrapping="NoWrap" Style="{DynamicResource TextBlockDefault}" TextTrimming="CharacterEllipsis"
Margin="0,6,0,0"
HorizontalAlignment="Left"/>
</StackPanel>
</hc:Card.Footer>-->
</hc:Card>
</StackPanel>
<Button Click="Close_Click" Content="朕已阅" Margin="10,0,10,20" Width="298" VerticalAlignment="Bottom"/>
</Grid>
</Border>

View File

@@ -0,0 +1,61 @@
using GeekDesk.Constant;
using GeekDesk.Task;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using HandyControl.Controls;
using Quartz;
using System;
using System.Windows;
using System.Windows.Input;
namespace GeekDesk.Control.Other
{
/// <summary>
/// BacklogNotificatin.xaml 的交互逻辑
/// </summary>
public partial class GlobalMsgNotification
{
public Notification ntf;
public GlobalMsgNotification(DialogMsg msg)
{
InitializeComponent();
this.DataContext = msg;
}
public class DialogMsg
{
public string msg;
public string title;
public string Msg
{
get
{
return msg;
}
set
{
msg = value;
}
}
public string Title
{
get
{
return title;
}
set
{
title = value;
}
}
}
private void Close_Click(object sender, RoutedEventArgs e)
{
ntf.Close();
}
}
}

View File

@@ -1,4 +1,5 @@
using GeekDesk.Util;
using GeekDesk.Constant;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Microsoft.Win32;
using System;
@@ -38,7 +39,7 @@ namespace GeekDesk.Control.Other
info.Name = IconName.Text;
info.AdminStartUp = IconIsAdmin.IsChecked.Value;
info.StartArg = StartArg.Text;
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
dialog.Close();
}
@@ -51,7 +52,7 @@ namespace GeekDesk.Control.Other
{
IconInfo info = this.DataContext as IconInfo;
info.BitmapImage = ImageUtil.ByteArrToImage(info.DefaultImage);
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
/// <summary>
@@ -72,7 +73,7 @@ namespace GeekDesk.Control.Other
{
IconInfo info = this.DataContext as IconInfo;
info.BitmapImage = ImageUtil.GetBitmapIconByPath(ofd.FileName);
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
}
catch (Exception e1)

View File

@@ -52,7 +52,7 @@ namespace GeekDesk.Control.Other
{
MainWindow.appData.MenuList[MainWindow.appData.AppConfig.SelectedMenuIndex].IconList.Add(info);
}
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
dialog.Close();
}
@@ -65,7 +65,7 @@ namespace GeekDesk.Control.Other
{
IconInfo info = this.DataContext as IconInfo;
info.BitmapImage = ImageUtil.ByteArrToImage(info.DefaultImage);
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
/// <summary>
@@ -86,7 +86,7 @@ namespace GeekDesk.Control.Other
{
IconInfo info = this.DataContext as IconInfo;
info.BitmapImage = ImageUtil.GetBitmapIconByPath(ofd.FileName);
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
}
catch (Exception ex)

View File

@@ -93,6 +93,16 @@
Foreground="Black"
IsChecked="{Binding UpdateType, Mode=TwoWay, Converter={StaticResource UpdateTypeConvert}, ConverterParameter=2}"/>
</hc:UniformSpacingPanel>
<TextBlock Text="其它" Margin="0,25,0,0"/>
<hc:UniformSpacingPanel Spacing="10" Margin="20,8,0,0">
<Button Content="备份数据"
hc:Poptip.Content="当数据文件损坏时, 以便能够恢复部分数据 (损坏时将有操作提示)"
hc:Poptip.Placement="TopLeft"
hc:Poptip.Offset="10"
Style="{StaticResource Btn1}"
Click="BakDataFile"/>
</hc:UniformSpacingPanel>
</StackPanel>
</hc:SimplePanel>
</Grid>

View File

@@ -107,5 +107,10 @@ namespace GeekDesk.Control.UserControls.Config
CountLowSort.Visibility = Visibility.Visible;
}
}
private void BakDataFile(object sender, RoutedEventArgs e)
{
CommonCode.BakAppData();
}
}
}

View File

@@ -376,7 +376,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
}
CommonCode.SortIconList();
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
/// <summary>

View File

@@ -42,7 +42,7 @@ namespace GeekDesk.Control.UserControls.SystemItem
iconInfo = CommonCode.GetIconInfoByPath(thisInfo.LnkPath_NoWrite);
}
menuInfo.IconList.Add(iconInfo);
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
}
}

View File

@@ -1,4 +1,5 @@
using GeekDesk.Control.Windows;
using GeekDesk.Constant;
using GeekDesk.Control.Windows;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using HandyControl.Controls;
@@ -42,7 +43,7 @@ namespace GeekDesk.Control.UserControls.Backlog
{
MainWindow.appData.HiToDoList.Remove(info);
}
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
return true;
}, "DeleteConfirm");

View File

@@ -178,7 +178,7 @@ namespace GeekDesk.Control.Windows
Growl.SuccessGlobal("设置待办任务成功, 系统将在 " + minutes + " 分钟后提醒您!");
}
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
this.Close();
}

View File

@@ -167,6 +167,9 @@
<Compile Include="Constant\TodoTaskExecType.cs" />
<Compile Include="Constant\BGStyle.cs" />
<Compile Include="Constant\UpdateType.cs" />
<Compile Include="Control\Other\GlobalMsgNotification.xaml.cs">
<DependentUpon>GlobalMsgNotification.xaml</DependentUpon>
</Compile>
<Compile Include="Control\Other\BacklogNotificatin.xaml.cs">
<DependentUpon>BacklogNotificatin.xaml</DependentUpon>
</Compile>
@@ -290,6 +293,10 @@
<Compile Include="ViewModel\IconfontInfo.cs" />
<Compile Include="ViewModel\IconInfo.cs" />
<Compile Include="ViewModel\MenuInfo.cs" />
<Page Include="Control\Other\GlobalMsgNotification.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Control\Other\BacklogNotificatin.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -515,4 +522,13 @@
<Import Project="packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets" Condition="Exists('packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets')" />
<Import Project="packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets" Condition="Exists('packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets')" />
<Import Project="packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets" Condition="Exists('packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets')" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>; Move all assemblies and related files to lib folder
ROBOCOPY "$(TargetDir) " "$(TargetDir)lib\ " /XF Data *.exe *.config *.manifest /XD lib logs bak /E /IS /MOVE
if %25errorlevel%25 leq 4 exit 0 else exit %25errorlevel%25</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -6,6 +6,7 @@
xmlns:uc="clr-namespace:GeekDesk.Control.UserControls.PannelCard"
xmlns:cn="clr-namespace:GeekDesk.Constant"
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"
xmlns:local="clr-namespace:GeekDesk"
mc:Ignorable="d"
xmlns:cvt="clr-namespace:GeekDesk.Converts"
x:Name="AppWindow"
@@ -26,6 +27,7 @@
MouseDown="MainWindow_MouseDown"
MouseEnter="MainWindow_MouseEnter"
GotFocus="Window_GotFocus"
Loaded="Window_Loaded"
>
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="15"/>
@@ -124,7 +126,6 @@
FocusVisualStyle="{x:Null}"
/>
</hc:UniformSpacingPanel>
</DockPanel>
@@ -151,6 +152,7 @@
<ContextMenu Width="130" x:Name="TaskbarContextMenu">
<MenuItem Header="打开面板" Click="ShowApp"/>
<MenuItem Header="拾色器" Click="ColorPicker"/>
<MenuItem Header="备份" Click="BakDataFile"/>
<MenuItem Header="隐藏图标" Click="CloseBarIcon"/>
<MenuItem Header="待办" Click="BacklogMenuClick"/>
<MenuItem Header="程序目录" Click="OpenThisDir"/>

View File

@@ -8,6 +8,7 @@ using GeekDesk.Task;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using GeekDesk.ViewModel.Temp;
using Microsoft.Win32;
using NPinyin;
using System;
using System.Collections.ObjectModel;
@@ -38,14 +39,19 @@ namespace GeekDesk
public static MainWindow mainWindow;
public MainWindow()
{
//加载数据
LoadData();
InitializeComponent();
mainWindow = this;
this.Topmost = true;
this.Loaded += Window_Loaded;
this.SizeChanged += MainWindow_Resize;
ToDoTask.BackLogCheck();
InitializeComponent();
//用于其他类访问
mainWindow = this;
//置于顶层
this.Topmost = true;
//执行待办提醒
ToDoTask.BackLogCheck();
////实例化隐藏 Hide类进行时间timer设置
MarginHide.ReadyHide(this);
@@ -60,7 +66,7 @@ namespace GeekDesk
/// <summary>
/// 显示搜索框
/// 搜索快捷键按下
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
@@ -72,6 +78,9 @@ namespace GeekDesk
}
}
/// <summary>
/// 显示搜索框
/// </summary>
private void ShowSearchBox()
{
RunTimeStatus.SEARCH_BOX_SHOW = true;
@@ -128,6 +137,9 @@ namespace GeekDesk
RightCard.VerticalUFG.Visibility = Visibility.Visible;
}
/// <summary>
/// 隐藏搜索框
/// </summary>
public void HidedSearchBox()
{
RunTimeStatus.SEARCH_BOX_SHOW = false;
@@ -214,6 +226,10 @@ namespace GeekDesk
//更新线程开启 检测更新
UpdateThread.Update();
//自动备份一次数据
appData.AppConfig.SysBakTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
CommonCode.SaveAppData(appData, Constants.DATA_FILE_BAK_PATH);
}
/// <summary>
@@ -338,21 +354,6 @@ namespace GeekDesk
}
/// <summary>
/// 重置窗体大小 写入缓存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MainWindow_Resize(object sender, System.EventArgs e)
{
if (this.DataContext != null)
{
AppData appData = this.DataContext as AppData;
appData.AppConfig.WindowWidth = this.Width;
appData.AppConfig.WindowHeight = this.Height;
}
}
/// <summary>
@@ -754,5 +755,21 @@ namespace GeekDesk
AppWindowLostFocus();
}
/// <summary>
/// 备份数据文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[Obsolete]
private void BakDataFile(object sender, RoutedEventArgs e)
{
Thread t = new Thread(() =>
{
CommonCode.BakAppData();
});
t.ApartmentState = ApartmentState.STA;
t.Start();
}
}
}

View File

@@ -1,5 +1,9 @@
using GeekDesk.Constant;
using GeekDesk.Control.Other;
using GeekDesk.ViewModel;
using HandyControl.Data;
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -8,6 +12,7 @@ using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows;
using System.Windows.Media.Imaging;
using static GeekDesk.Control.Other.GlobalMsgNotification;
/// <summary>
/// 提取一些代码
@@ -28,15 +33,56 @@ namespace GeekDesk.Util
{
using (FileStream fs = File.Create(Constants.DATA_FILE_PATH)) { }
appData = new AppData();
SaveAppData(appData);
SaveAppData(appData, Constants.DATA_FILE_PATH);
}
else
{
using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Open))
try
{
BinaryFormatter bf = new BinaryFormatter();
appData = bf.Deserialize(fs) as AppData;
using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
appData = bf.Deserialize(fs) as AppData;
}
}
catch
{
if (File.Exists(Constants.DATA_FILE_BAK_PATH))
{
try
{
using (FileStream fs = new FileStream(Constants.DATA_FILE_BAK_PATH, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
appData = bf.Deserialize(fs) as AppData;
}
DialogMsg msg = new DialogMsg();
msg.msg = "不幸的是, GeekDesk当前的数据文件已经损坏, " +
"现在已经启用系统自动备份的数据\n\n" +
"如果你有较新的备份, " +
"请退出GeekDesk, " +
"将备份文件重命名为:Data, " +
"然后将Data覆盖到GeekDesk的根目录即可\n\n" +
"系统上次备份时间: \n" + appData.AppConfig.SysBakTime +
"\n\n如果当前数据就是你想要的数据, 那么请不用管它";
GlobalMsgNotification gm = new GlobalMsgNotification(msg);
HandyControl.Controls.Notification ntf = HandyControl.Controls.Notification.Show(gm, ShowAnimation.Fade, true);
gm.ntf = ntf;
} catch
{
MessageBox.Show("不幸的是, GeekDesk当前的数据文件已经损坏\n如果你有备份, 请将备份文件重命名为:Data 然后将Data覆盖到GeekDesk的根目录即可!");
Application.Current.Shutdown();
return null;
}
} else
{
MessageBox.Show("不幸的是, GeekDesk当前的数据文件已经损坏\n如果你有备份, 请将备份文件重命名为:Data 然后将Data覆盖到GeekDesk的根目录即可!");
Application.Current.Shutdown();
return null;
}
}
}
return appData;
@@ -46,15 +92,38 @@ namespace GeekDesk.Util
/// 保存app 数据
/// </summary>
/// <param name="appData"></param>
public static void SaveAppData(AppData appData)
public static void SaveAppData(AppData appData, string filePath)
{
using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Create))
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()
{
SaveFileDialog sfd = new SaveFileDialog
{
Title = "备份文件",
Filter = "bak文件(*.bak)|*.bak",
FileName = "Data-GD-" + DateTime.Now.ToString("yyMMdd") + ".bak",
};
if (sfd.ShowDialog() == true)
{
using (FileStream fs = new FileStream(sfd.FileName, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, MainWindow.appData);
}
}
}
/// <summary>

View File

@@ -93,8 +93,21 @@ namespace GeekDesk.ViewModel
private SearchType searchType;
private string sysBakTime; //系统自动备份时间
#region GetSet
public string SysBakTime
{
get
{
return sysBakTime;
}
set
{
sysBakTime = value;
}
}
public SearchType SearchType
{
@@ -898,7 +911,7 @@ namespace GeekDesk.ViewModel
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
#endregion

View File

@@ -1,4 +1,5 @@
using GeekDesk.Util;
using GeekDesk.Constant;
using GeekDesk.Util;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -88,7 +89,7 @@ namespace GeekDesk.ViewModel
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
}

View File

@@ -1,4 +1,5 @@
using GeekDesk.Util;
using GeekDesk.Constant;
using GeekDesk.Util;
using System;
using System.ComponentModel;
@@ -69,7 +70,7 @@ namespace GeekDesk.ViewModel
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
}

View File

@@ -303,7 +303,7 @@ namespace GeekDesk.ViewModel
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}

View File

@@ -134,7 +134,7 @@ namespace GeekDesk.ViewModel
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
}
}

View File

@@ -133,7 +133,7 @@ namespace GeekDesk.ViewModel
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
CommonCode.SaveAppData(MainWindow.appData);
CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
}
}
}