Skip to content

Commit d20ecff

Browse files
authored
Fixed an issue where external devices cannot be removed while app is opened (#1810)
1 parent 50e9fa0 commit d20ecff

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Files/View Models/ItemViewModel.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,8 @@ private void AddFileOrFolder2(string fileOrFolderPath)
11291129

11301130
IntPtr hFile = FindFirstFileExFromApp(fileOrFolderPath, findInfoLevel, out WIN32_FIND_DATA findData, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero,
11311131
additionalFlags);
1132+
FindClose(hFile);
1133+
11321134
if ((findData.dwFileAttributes & 0x10) > 0) // FILE_ATTRIBUTE_DIRECTORY
11331135
{
11341136
AddFolder(findData, Directory.GetParent(fileOrFolderPath).FullName);
@@ -1556,9 +1558,11 @@ public bool CheckForFilesFolders(string targetPath)
15561558
FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic;
15571559
int additionalFlags = FIND_FIRST_EX_LARGE_FETCH;
15581560

1559-
IntPtr hFile = FindFirstFileExFromApp(targetPath + "\\*.*", findInfoLevel, out WIN32_FIND_DATA findChildData, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, additionalFlags);
1560-
FindNextFile(hFile, out findChildData);
1561-
return FindNextFile(hFile, out findChildData);
1561+
IntPtr hFile = FindFirstFileExFromApp(targetPath + "\\*.*", findInfoLevel, out WIN32_FIND_DATA _, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, additionalFlags);
1562+
FindNextFile(hFile, out _);
1563+
var result = FindNextFile(hFile, out _);
1564+
FindClose(hFile);
1565+
return result;
15621566
}
15631567
}
15641568
}

Files/Views/MainPage.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ public MainPage()
6969
}
7070

7171
AllowDrop = true;
72+
73+
AppInstances.CollectionChanged += AppInstances_CollectionChanged;
74+
}
75+
76+
private void AppInstances_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
77+
{
78+
if (e.OldItems != null)
79+
{
80+
foreach (var removedTab in e.OldItems)
81+
{
82+
// Cleanup resources for the closed tab
83+
((((removedTab as TabItem).Content as Grid).Children[0] as Frame).Content as IShellPage)?.FilesystemViewModel?.Dispose();
84+
}
85+
}
7286
}
7387

7488
protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)

0 commit comments

Comments
 (0)