Skip to content

Commit

Permalink
updated FileWatcherEx 1.3, used SynchronizingObject; Magick.NET 7.6.0.1
Browse files Browse the repository at this point in the history
#405: Error reading the C:\Users\User\Application Data directory
  • Loading branch information
d2phap committed Aug 29, 2018
1 parent 9ff0962 commit 9df9316
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Source/Components/ImageGlass.Core/ImageGlass.Core.csproj
Expand Up @@ -81,8 +81,8 @@
<Reference Include="IconLib, Version=0.73.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IconLib.Unofficial.0.73.0\lib\net20\IconLib.dll</HintPath>
</Reference>
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.5.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
<HintPath>..\..\packages\Magick.NET-Q16-AnyCPU.7.5.0.1\lib\net40\Magick.NET-Q16-AnyCPU.dll</HintPath>
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.6.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
<HintPath>..\..\packages\Magick.NET-Q16-AnyCPU.7.6.0.1\lib\net40\Magick.NET-Q16-AnyCPU.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down
2 changes: 1 addition & 1 deletion Source/Components/ImageGlass.Core/packages.config
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IconLib.Unofficial" version="0.73.0" targetFramework="net471" />
<package id="Magick.NET-Q16-AnyCPU" version="7.5.0.1" targetFramework="net471" />
<package id="Magick.NET-Q16-AnyCPU" version="7.6.0.1" targetFramework="net471" />
</packages>
4 changes: 2 additions & 2 deletions Source/ImageGlass/ImageGlass.csproj
Expand Up @@ -131,8 +131,8 @@
<Reference Include="DotNetZip, Version=1.11.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.11.0\lib\net20\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="FileWatcherEx, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\FileWatcherEx.1.0.0\lib\net45\FileWatcherEx.dll</HintPath>
<Reference Include="FileWatcherEx, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\FileWatcherEx.1.3.0\lib\net45\FileWatcherEx.dll</HintPath>
</Reference>
<Reference Include="IconLib, Version=0.73.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IconLib.Unofficial.0.73.0\lib\net20\IconLib.dll</HintPath>
Expand Down
53 changes: 18 additions & 35 deletions Source/ImageGlass/frmMain.cs
Expand Up @@ -255,7 +255,10 @@ public void Prepare(string path)
this._fileWatcher = new FileWatcherEx.FileWatcherEx()
{
FolderPath = dirPath,
IncludeSubdirectories = GlobalSetting.IsRecursiveLoading
IncludeSubdirectories = GlobalSetting.IsRecursiveLoading,

// auto Invoke the form if required, no need to invidiually invoke in each event
SynchronizingObject = this
};

this._fileWatcher.OnCreated += FileWatcher_OnCreated;
Expand Down Expand Up @@ -2482,12 +2485,6 @@ private void timSlideShow_Tick(object sender, EventArgs e)

private void FileWatcher_OnRenamed(object sender, FileChangedEvent e)
{
if (this.InvokeRequired)
{
this.Invoke(new Action<object, FileChangedEvent>(FileWatcher_OnRenamed), sender, e);
return;
}

string newFilename = e.FullPath;
string oldFilename = e.OldFullPath;

Expand Down Expand Up @@ -2584,13 +2581,7 @@ private void FileWatcher_OnChanged(object sender, FileChangedEvent e)
{
return;
}

if (this.InvokeRequired)
{
this.Invoke(new Action<object, FileChangedEvent>(FileWatcher_OnChanged), sender, e);
return;
}


// update the viewing image
var imgIndex = GlobalSetting.ImageList.IndexOf(e.FullPath);

Expand Down Expand Up @@ -2629,19 +2620,24 @@ private void FileWatcher_OnCreated(object sender, FileChangedEvent e)
FileWatcher_AddNewFileAction(e.FullPath);
}
}



private void FileWatcher_AddNewFileAction(string newFilename)
private void FileWatcher_OnDeleted(object sender, FileChangedEvent e)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.InvokeRequired)
// Only watch the supported file types
var ext = Path.GetExtension(e.FullPath).ToLower();
if (!GlobalSetting.ImageFormatHashSet.Contains(ext))
{
this.Invoke(new Action<string>(FileWatcher_AddNewFileAction), newFilename);
return;
}

// add to queue list for deleting
this._queueListForDeleting.Add(e.FullPath);
}


private void FileWatcher_AddNewFileAction(string newFilename)
{
//Add the new image to the list
GlobalSetting.ImageList.AddItem(newFilename);

Expand All @@ -2650,25 +2646,12 @@ private void FileWatcher_AddNewFileAction(string newFilename)
{
Tag = newFilename
};

thumbnailBar.Items.Add(lvi);
thumbnailBar.Refresh();
}


private void FileWatcher_OnDeleted(object sender, FileChangedEvent e)
{
// Only watch the supported file types
var ext = Path.GetExtension(e.FullPath).ToLower();
if (!GlobalSetting.ImageFormatHashSet.Contains(ext))
{
return;
}

// add to queue list for deleting
this._queueListForDeleting.Add(e.FullPath);
}


/// <summary>
/// The queue thread to check the files needed to be deleted.
Expand Down
2 changes: 1 addition & 1 deletion Source/ImageGlass/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.11.0" targetFramework="net471" />
<package id="FileWatcherEx" version="1.0.0" targetFramework="net471" />
<package id="FileWatcherEx" version="1.3.0" targetFramework="net471" />
<package id="IconLib.Unofficial" version="0.73.0" targetFramework="net471" />
</packages>

0 comments on commit 9df9316

Please sign in to comment.