Skip to content

Commit

Permalink
update watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
SplitGemini committed Apr 6, 2020
1 parent 90bced8 commit 73678b7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 24 deletions.
Binary file removed QuickLook-3.6.6.zip
Binary file not shown.
5 changes: 4 additions & 1 deletion QuickLook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ private void RunListener(StartupEventArgs e)
TrayIconManager.ShowNotification("", TranslationHelper.Get("APP_START"));
}
//自己添加的功能,与quick look无关
DesktopWatcher.GetInstance();
if (SettingHelper.Get("Watcher", false))
{
DesktopWatcher.GetInstance().WatcherStart();
}

if (e.Args.Contains("/first"))
{
Expand Down
49 changes: 32 additions & 17 deletions QuickLook/DesktopWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,46 @@ namespace QuickLook
internal class DesktopWatcher
{
private static DesktopWatcher _instance;
private static FileSystemWatcher _watcher = new FileSystemWatcher();
private static string publicDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
private static FileSystemWatcher _watcher = null;
private static readonly string publicDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
private static readonly string userDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
protected DesktopWatcher()
private static readonly FileSystemEventHandler _onProcess = new FileSystemEventHandler(OnProcess);
protected DesktopWatcher() {}

public void WatcherStart()
{
WatcherStart(publicDesktopPath, "*");
if (_watcher != null) return;
MoveFiles();
_watcher = new FileSystemWatcher
{
Path = publicDesktopPath,
Filter = "*",
EnableRaisingEvents = true,
NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName
| NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size,
IncludeSubdirectories = false
};
_watcher.Changed += _onProcess;
_watcher.Created += _onProcess;
}
private static void WatcherStart(string path, string filter)

public void WatcherEnd()
{
_watcher.Path = path;
_watcher.Filter = filter;
_watcher.Changed += new FileSystemEventHandler(OnProcess);
_watcher.Created += new FileSystemEventHandler(OnProcess);
_watcher.EnableRaisingEvents = true;
_watcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName
| NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
_watcher.IncludeSubdirectories = false;
_watcher.Changed -= _onProcess;
_watcher.Created -= _onProcess;
_watcher.Dispose();
_watcher = null;
}

private static void OnProcess(object source, FileSystemEventArgs e)
{
_watcher.Changed -= new FileSystemEventHandler(OnProcess);
_watcher.Created -= new FileSystemEventHandler(OnProcess);
_watcher.Changed -= _onProcess;
_watcher.Created -= _onProcess;
MoveFiles();
_watcher.Changed += new FileSystemEventHandler(OnProcess);
_watcher.Created += new FileSystemEventHandler(OnProcess);
_watcher.Changed += _onProcess;
_watcher.Created += _onProcess;
}

private static void MoveFiles()
{
System.Threading.Thread.Sleep(2000);
Expand Down Expand Up @@ -79,5 +93,6 @@ internal static DesktopWatcher GetInstance()
{
return _instance ?? (_instance = new DesktopWatcher());
}

}
}
Loading

0 comments on commit 73678b7

Please sign in to comment.