Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/Files.Launcher/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,28 @@ public class ContextMenuItem : Win32ContextMenuItem, IDisposable
{
public ContextMenuItem()
{
this.SubItems = new List<Win32ContextMenuItem>();
SubItems = new List<Win32ContextMenuItem>();
}

public void Dispose()
{
if (SubItems != null)
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
{
foreach (var si in SubItems)
if (SubItems != null)
{
(si as IDisposable)?.Dispose();
}
foreach (var si in SubItems)
{
(si as IDisposable)?.Dispose();
}

SubItems = null;
SubItems = null;
}
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/Files.Launcher/DeviceWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
namespace FilesFullTrust
{
[SupportedOSPlatform("Windows10.0.10240")]
public class DeviceWatcher : IDisposable
public class DeviceWatcher : Disposable
{
private ManagementEventWatcher insertWatcher, removeWatcher, modifyWatcher;
private PipeStream connection;

private const string WpdGuid = "{6ac27878-a6fa-4155-ba85-f98f491d4f33}";
private readonly PipeStream connection;

public DeviceWatcher(PipeStream connection)
{
Expand Down Expand Up @@ -81,14 +79,17 @@ private async Task SendEvent(string deviceName, string deviceId, DeviceEvent eve
}
}

public void Dispose()
protected override void Dispose(bool disposing)
{
insertWatcher?.Dispose();
removeWatcher?.Dispose();
modifyWatcher?.Dispose();
insertWatcher = null;
removeWatcher = null;
modifyWatcher = null;
if (disposing)
{
insertWatcher?.Dispose();
removeWatcher?.Dispose();
modifyWatcher?.Dispose();
insertWatcher = null;
removeWatcher = null;
modifyWatcher = null;
}
}
}
}
17 changes: 17 additions & 0 deletions src/Files.Launcher/Disposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace FilesFullTrust
{
public abstract class Disposable : IDisposable
{
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
}
}
}
13 changes: 8 additions & 5 deletions src/Files.Launcher/Helpers/DisposableDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace FilesFullTrust.Helpers
{
public class DisposableDictionary : IDisposable
public class DisposableDictionary : Disposable
{
private readonly ConcurrentDictionary<string, object> dict;

Expand Down Expand Up @@ -56,12 +56,15 @@ public void RemoveValue(string key)
(elem as IDisposable)?.Dispose();
}

public void Dispose()
protected override void Dispose(bool disposing)
{
foreach (var elem in dict)
if (disposing)
{
dict.TryRemove(elem.Key, out _);
(elem.Value as IDisposable)?.Dispose();
foreach (var elem in dict)
{
dict.TryRemove(elem.Key, out _);
(elem.Value as IDisposable)?.Dispose();
}
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/Files.Launcher/Helpers/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static extern int RmRegisterResources(uint pSessionHandle,
UInt32 nServices,
string[] rgsServiceNames);

[DllImport("rstrtmgr.dll", CharSet = CharSet.Auto)]
[DllImport("rstrtmgr.dll", CharSet = CharSet.Unicode)]
static extern int RmStartSession(out uint pSessionHandle, int dwSessionFlags, string strSessionKey);

[DllImport("rstrtmgr.dll")]
Expand All @@ -78,23 +78,21 @@ static extern int RmGetList(uint dwSessionHandle,
/// <remarks>See also:
/// http://msdn.microsoft.com/en-us/library/windows/desktop/aa373661(v=vs.85).aspx
/// http://wyupdate.googlecode.com/svn-history/r401/trunk/frmFilesInUse.cs (no copyright in code at time of viewing)
///
///
/// </remarks>
static public List<Process> WhoIsLocking(string path)
{
uint handle;
string key = Guid.NewGuid().ToString();
List<Process> processes = new List<Process>();

int res = RmStartSession(out handle, 0, key);
int res = RmStartSession(out uint handle, 0, key);
if (res != 0) throw new Exception("Could not begin restart session. Unable to determine file locker.");

try
{
const int ERROR_MORE_DATA = 234;
uint pnProcInfoNeeded = 0,
pnProcInfo = 0,
lpdwRebootReasons = RmRebootReasonNone;
uint pnProcInfo = 0;
uint lpdwRebootReasons = RmRebootReasonNone;

string[] resources = new string[] { path }; // Just checking on one resource.

Expand All @@ -105,7 +103,7 @@ static public List<Process> WhoIsLocking(string path)
//Note: there's a race condition here -- the first call to RmGetList() returns
// the total number of process. However, when we call RmGetList() again to get
// the actual processes this number may have increased.
res = RmGetList(handle, out pnProcInfoNeeded, ref pnProcInfo, null, ref lpdwRebootReasons);
res = RmGetList(handle, out uint pnProcInfoNeeded, ref pnProcInfo, null, ref lpdwRebootReasons);

if (res == ERROR_MORE_DATA)
{
Expand All @@ -119,7 +117,7 @@ static public List<Process> WhoIsLocking(string path)
{
processes = new List<Process>((int)pnProcInfo);

// Enumerate all of the results and add them to the
// Enumerate all of the results and add them to the
// list to be returned
for (int i = 0; i < pnProcInfo; i++)
{
Expand All @@ -137,7 +135,7 @@ static public List<Process> WhoIsLocking(string path)
}
finally
{
RmEndSession(handle);
_ = RmEndSession(handle);
}

return processes;
Expand Down
6 changes: 4 additions & 2 deletions src/Files.Launcher/Helpers/ShellLibrary2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ShellItem DefaultSaveFolder

/// <summary>Gets the set of child folders that are contained in the library.</summary>
/// <value>A <see cref="ShellItemArray"/> containing the child folders.</value>
public ShellLibraryFolders Folders => folders ?? (folders = GetFilteredFolders());
public ShellLibraryFolders Folders => folders ??= GetFilteredFolders();

public void Reload()
{
Expand All @@ -85,7 +85,7 @@ public void Reload()
/// <value>The default icon location.</value>
public IconLocation IconLocation
{
get { IconLocation.TryParse(lib.GetIcon(), out var l); return l; }
get { _ = IconLocation.TryParse(lib.GetIcon(), out var l); return l; }
set => lib.SetIcon(value.ToString());
}

Expand Down Expand Up @@ -128,6 +128,7 @@ public override void Dispose()
folders = null;

base.Dispose();
GC.SuppressFinalize(this);
}

/// <summary>Gets the set of child folders that are contained in the library.</summary>
Expand Down Expand Up @@ -194,6 +195,7 @@ public override void Dispose()
{
lib = null;
base.Dispose();
GC.SuppressFinalize(this);
}

/// <summary>Removes the specified location.</summary>
Expand Down
15 changes: 9 additions & 6 deletions src/Files.Launcher/Helpers/ThreadWithMessageQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
namespace FilesFullTrust.Helpers
{
[SupportedOSPlatform("Windows")]
public class ThreadWithMessageQueue<T> : IDisposable
public class ThreadWithMessageQueue<T> : Disposable
{
private readonly BlockingCollection<Internal> messageQueue;
private readonly Thread thread;
private readonly DisposableDictionary state;

public void Dispose()
protected override void Dispose(bool disposing)
{
messageQueue.CompleteAdding();
thread.Join();
state.Dispose();
messageQueue.Dispose();
if (disposing)
{
messageQueue.CompleteAdding();
thread.Join();
state.Dispose();
messageQueue.Dispose();
}
}

public async Task<V> PostMessageAsync<V>(T payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace FilesFullTrust.MessageHandlers
{
[SupportedOSPlatform("Windows10.0.10240")]
public class ApplicationLaunchHandler : IMessageHandler
public class ApplicationLaunchHandler : Disposable, IMessageHandler
{
public void Initialize(PipeStream connection)
{
Expand Down Expand Up @@ -193,9 +193,5 @@ private string GetMtpPath(string executable)
}
return executable;
}

public void Dispose()
{
}
}
}
9 changes: 6 additions & 3 deletions src/Files.Launcher/MessageHandlers/ContextMenuHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace FilesFullTrust.MessageHandlers
{
[SupportedOSPlatform("Windows10.0.10240")]
public class ContextMenuHandler : IMessageHandler
public class ContextMenuHandler : Disposable, IMessageHandler
{
private readonly DisposableDictionary handleTable;

Expand Down Expand Up @@ -164,9 +164,12 @@ bool filterMenuItemsImpl(string menuItem) => !string.IsNullOrEmpty(menuItem)
return filterMenuItemsImpl;
}

public void Dispose()
protected override void Dispose(bool disposing)
{
handleTable?.Dispose();
if (disposing)
{
handleTable?.Dispose();
}
}
}
}
11 changes: 7 additions & 4 deletions src/Files.Launcher/MessageHandlers/FileOperationsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace FilesFullTrust.MessageHandlers
{
[SupportedOSPlatform("Windows10.0.10240")]
public class FileOperationsHandler : IMessageHandler
public class FileOperationsHandler : Disposable, IMessageHandler
{
private FileTagsDb dbInstance;
private ProgressHandler progressHandler;
Expand Down Expand Up @@ -899,10 +899,13 @@ private void UpdateFileTagsDb(ShellFileOperations.ShellFileOpEventArgs e, string
}
}

public void Dispose()
protected override void Dispose(bool disposing)
{
progressHandler?.Dispose();
dbInstance?.Dispose();
if (disposing)
{
progressHandler?.Dispose();
dbInstance?.Dispose();
}
}

private class ProgressHandler : IDisposable
Expand Down
6 changes: 1 addition & 5 deletions src/Files.Launcher/MessageHandlers/FileTagsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace FilesFullTrust.MessageHandlers
{
[SupportedOSPlatform("Windows10.0.10240")]
public class FileTagsHandler : IMessageHandler
public class FileTagsHandler : Disposable, IMessageHandler
{
public static string ReadFileTag(string filePath)
{
Expand Down Expand Up @@ -125,9 +125,5 @@ public Task ParseArgumentsAsync(PipeStream connection, Dictionary<string, object
public void Initialize(PipeStream connection)
{
}

public void Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace FilesFullTrust.MessageHandlers
{
[SupportedOSPlatform("Windows10.0.10240")]
public class InstallOperationsHandler : IMessageHandler
public class InstallOperationsHandler : Disposable, IMessageHandler
{
public void Initialize(PipeStream connection)
{
Expand Down Expand Up @@ -59,9 +59,5 @@ private static void ParseInstallOperation(PipeStream connection, Dictionary<stri
}
}
}

public void Dispose()
{
}
}
}
9 changes: 6 additions & 3 deletions src/Files.Launcher/MessageHandlers/LibrariesHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace FilesFullTrust.MessageHandlers
{
[SupportedOSPlatform("Windows10.0.10240")]
public class LibrariesHandler : IMessageHandler
public class LibrariesHandler : Disposable, IMessageHandler
{
private PipeStream connection;

Expand Down Expand Up @@ -215,9 +215,12 @@ private async Task HandleShellLibraryMessage(Dictionary<string, object> message)
}
}

public void Dispose()
protected override void Dispose(bool disposing)
{
librariesWatcher?.Dispose();
if (disposing)
{
librariesWatcher?.Dispose();
}
}
}
}
Loading