Skip to content

Commit

Permalink
修复某些拖入文件操作导致桌面文件丢失的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Sep 30, 2024
1 parent 0cda042 commit 9dd5017
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
43 changes: 0 additions & 43 deletions ZongziTEK_Blackboard_Sticker/Helpers/FileUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,5 @@ public static void CopyFolder(string sourceFolder, string destFolder)
throw new Exception($"copy file Error:{ex.Message}\r\n source:{ex.StackTrace}");
}
}


/// <summary>
/// 移动文件
/// </summary>
/// <param name="sourceFolder">源文件夹</param>
/// <param name="destFolder">目标文件呢</param>
public static void MoveFolder(string sourceFolder, string destFolder)
{
try
{
//如果目标路径不存在,则创建目标路径
if (!Directory.Exists(destFolder))
{
Directory.CreateDirectory(destFolder);
}
//得到原文件根目录下的所有文件
string[] files = Directory.GetFiles(sourceFolder);
foreach (string file in files)
{
string name = Path.GetFileName(file);
string dest = Path.Combine(destFolder, name);
// 移动文件
File.Move(file, dest);
}
//得到原文件根目录下的所有文件夹
string[] folders = Directory.GetDirectories(sourceFolder);
foreach (string folder in folders)
{
string dirName = folder.Split('\\')[folder.Split('\\').Length - 1];
string destfolder = Path.Combine(destFolder, dirName);
// 递归调用
MoveFolder(folder, destfolder);
}

// 删除源文件夹
Directory.Delete(sourceFolder);
}
catch (Exception ex)
{
throw new Exception($"move file Error:{ex.Message}\r\n source:{ex.StackTrace}");
}
}
}
}
2 changes: 1 addition & 1 deletion ZongziTEK_Blackboard_Sticker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Background="#00000000"
ResizeMode="NoResize" ShowInTaskbar="False"
Icon="/黑板贴.png" WindowStyle="None" AllowsTransparency="True" Closing="window_Closing" AllowDrop="True" Loaded="window_Loaded"
DragEnter="window_DragEnter" DragLeave="window_DragLeave" Drop="window_Drop" Activated="window_Activated" StateChanged="window_StateChanged"
Drop="window_Drop" Activated="window_Activated" StateChanged="window_StateChanged"
ui:ThemeManager.RequestedTheme="Light">

<Grid>
Expand Down
12 changes: 11 additions & 1 deletion ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ public static void SaveSettings()
#region Utility
#region FileDrag

private bool isCopying = false;
/*private bool isCopying = false;
private void window_DragEnter(object sender, System.Windows.DragEventArgs e)
{
TextBlockDragHint.Text = "松手以将文件添加到桌面";
Expand Down Expand Up @@ -1817,6 +1817,16 @@ await Task.Run(() =>
ProgressBarDragEnter.Visibility = Visibility.Collapsed;
isCopying = false;
}*/
private void window_Drop(object sender, System.Windows.DragEventArgs e)
{
Task.Run(() =>
{
Dispatcher.Invoke(() =>
{
System.Windows.MessageBox.Show("请将此文件拖到桌面空白处", null, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
});
});
}
#endregion
#endregion
Expand Down

0 comments on commit 9dd5017

Please sign in to comment.