Skip to content

Commit c59731a

Browse files
committedJul 22, 2021
part 1
1 parent ea7c786 commit c59731a

14 files changed

+68
-177
lines changed
 

‎Files/Files.csproj

+1-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<AppxBundlePlatforms>x86|x64|arm|arm64</AppxBundlePlatforms>
3030
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
3131
<Win32Resource>Resources\MiddleClickScrolling-CursorType.res</Win32Resource>
32+
<LangVersion>9.0</LangVersion>
3233
</PropertyGroup>
3334
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
3435
<DebugSymbols>true</DebugSymbols>
@@ -40,7 +41,6 @@
4041
<UseVSHostingProcess>false</UseVSHostingProcess>
4142
<ErrorReport>prompt</ErrorReport>
4243
<Prefer32Bit>true</Prefer32Bit>
43-
<LangVersion>9.0</LangVersion>
4444
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4545
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
4646
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
@@ -56,7 +56,6 @@
5656
<ErrorReport>prompt</ErrorReport>
5757
<Prefer32Bit>true</Prefer32Bit>
5858
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
59-
<LangVersion>9.0</LangVersion>
6059
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6160
</PropertyGroup>
6261
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
@@ -69,7 +68,6 @@
6968
<UseVSHostingProcess>false</UseVSHostingProcess>
7069
<ErrorReport>prompt</ErrorReport>
7170
<Prefer32Bit>true</Prefer32Bit>
72-
<LangVersion>9.0</LangVersion>
7371
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7472
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
7573
</PropertyGroup>
@@ -84,7 +82,6 @@
8482
<ErrorReport>prompt</ErrorReport>
8583
<Prefer32Bit>true</Prefer32Bit>
8684
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
87-
<LangVersion>9.0</LangVersion>
8885
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8986
</PropertyGroup>
9087
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
@@ -98,7 +95,6 @@
9895
<ErrorReport>prompt</ErrorReport>
9996
<Prefer32Bit>true</Prefer32Bit>
10097
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
101-
<LangVersion>9.0</LangVersion>
10298
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10399
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
104100
</PropertyGroup>
@@ -113,7 +109,6 @@
113109
<ErrorReport>prompt</ErrorReport>
114110
<Prefer32Bit>true</Prefer32Bit>
115111
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
116-
<LangVersion>9.0</LangVersion>
117112
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
118113
</PropertyGroup>
119114
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
@@ -126,7 +121,6 @@
126121
<UseVSHostingProcess>false</UseVSHostingProcess>
127122
<ErrorReport>prompt</ErrorReport>
128123
<Prefer32Bit>true</Prefer32Bit>
129-
<LangVersion>9.0</LangVersion>
130124
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
131125
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
132126
</PropertyGroup>
@@ -141,7 +135,6 @@
141135
<ErrorReport>prompt</ErrorReport>
142136
<Prefer32Bit>true</Prefer32Bit>
143137
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
144-
<LangVersion>9.0</LangVersion>
145138
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
146139
</PropertyGroup>
147140
<PropertyGroup>
@@ -423,9 +416,6 @@
423416
<Compile Include="Filesystem\Search\FolderSearch.cs" />
424417
<Compile Include="Filesystem\StorageFileHelpers\FilesystemResult.cs" />
425418
<Compile Include="Filesystem\StorageFileHelpers\StorageFileExtensions.cs" />
426-
<Compile Include="Filesystem\StorageFileHelpers\IStorageItemWithPath.cs" />
427-
<Compile Include="Filesystem\StorageFileHelpers\StorageFileWithPath.cs" />
428-
<Compile Include="Filesystem\StorageFileHelpers\StorageFolderWithPath.cs" />
429419
<Compile Include="Filesystem\StorageHistory\Helpers\StorageHistoryHelpers.cs" />
430420
<Compile Include="Filesystem\StorageHistory\IStorageHistory.cs" />
431421
<Compile Include="Filesystem\StorageHistory\IStorageHistoryOperations.cs" />

‎Files/Filesystem/Drives.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ private DriveType GetDriveType(DriveInfo drive)
384384
return type;
385385
}
386386

387-
public static async Task<StorageFolderWithPath> GetRootFromPathAsync(string devicePath)
387+
public static async Task<IStorageFolder> GetRootFromPathAsync(string devicePath)
388388
{
389389
if (!Path.IsPathRooted(devicePath))
390390
{
@@ -419,13 +419,13 @@ public static async Task<StorageFolderWithPath> GetRootFromPathAsync(string devi
419419
}
420420
if (matchingDrive != null)
421421
{
422-
return new StorageFolderWithPath(matchingDrive, rootPath);
422+
return matchingDrive;
423423
}
424424
}
425425
else if (devicePath.StartsWith("\\\\")) // Network share
426426
{
427427
rootPath = rootPath.LastIndexOf("\\") > 1 ? rootPath.Substring(0, rootPath.LastIndexOf("\\")) : rootPath; // Remove share name
428-
return new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(rootPath), rootPath);
428+
return await StorageFolder.GetFolderFromPathAsync(rootPath);
429429
}
430430
// It's ok to return null here, on normal drives StorageFolder.GetFolderFromPathAsync works
431431
return null;

‎Files/Filesystem/StorageEnumerators/UniversalStorageEnumerator.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class UniversalStorageEnumerator
1919
{
2020
public static async Task<List<ListedItem>> ListEntries(
2121
StorageFolder rootFolder,
22-
StorageFolderWithPath currentStorageFolder,
22+
IStorageFolder currentStorageFolder,
2323
string returnformat,
2424
Type sourcePageType,
2525
CancellationToken cancellationToken,
@@ -138,7 +138,7 @@ ex is UnauthorizedAccessException
138138
return tempList;
139139
}
140140

141-
private static async Task<ListedItem> AddFolderAsync(StorageFolder folder, StorageFolderWithPath currentStorageFolder, string dateReturnFormat, CancellationToken cancellationToken)
141+
private static async Task<ListedItem> AddFolderAsync(StorageFolder folder, IStorageFolder currentStorageFolder, string dateReturnFormat, CancellationToken cancellationToken)
142142
{
143143
var basicProperties = await folder.GetBasicPropertiesAsync();
144144
if (!cancellationToken.IsCancellationRequested)
@@ -166,7 +166,7 @@ private static async Task<ListedItem> AddFolderAsync(StorageFolder folder, Stora
166166

167167
private static async Task<ListedItem> AddFileAsync(
168168
StorageFile file,
169-
StorageFolderWithPath currentStorageFolder,
169+
IStorageFolder currentStorageFolder,
170170
string dateReturnFormat,
171171
bool suppressThumbnailLoading,
172172
Type sourcePageType,

‎Files/Filesystem/StorageFileHelpers/FilesystemResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static FileSystemStatusCode GetErrorCode(Exception ex, Type T = null)
7070
}
7171
else if (ex is ArgumentException) // Item was invalid
7272
{
73-
return (T == typeof(StorageFolder) || T == typeof(StorageFolderWithPath)) ?
73+
return (T == typeof(IStorageFolder) || T.GetInterface("IStorageFolder") is not null) ?
7474
FileSystemStatusCode.NotAFolder : FileSystemStatusCode.NotAFile;
7575
}
7676
else if ((uint)ex.HResult == 0x800700B7)

‎Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs

-12
This file was deleted.

‎Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs

+27-49
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static List<PathBoxItem> GetDirectoryPathComponents(string value)
9292
return pathBoxItems;
9393
}
9494

95-
public async static Task<StorageFolderWithPath> DangerousGetFolderWithPathFromPathAsync(string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null)
95+
public async static Task<IStorageFolder> DangerousGetFolderWithPathFromPathAsync(string value, IStorageFolder rootFolder = null, IStorageFolder parentFolder = null)
9696
{
9797
if (rootFolder != null)
9898
{
@@ -104,123 +104,101 @@ public async static Task<StorageFolderWithPath> DangerousGetFolderWithPathFromPa
104104
}
105105
else if (parentFolder != null && value.IsSubPathOf(parentFolder.Path))
106106
{
107-
var folder = parentFolder.Folder;
107+
var folder = parentFolder;
108108
var prevComponents = GetDirectoryPathComponents(parentFolder.Path);
109-
var path = parentFolder.Path;
110109
foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path))
111110
{
112111
folder = await folder.GetFolderAsync(component.Title);
113-
path = Path.Combine(path, folder.Name);
114112
}
115-
return new StorageFolderWithPath(folder, path);
113+
return folder;
116114
}
117115
else if (value.IsSubPathOf(rootFolder.Path))
118116
{
119-
var folder = rootFolder.Folder;
120-
var path = rootFolder.Path;
117+
var folder = rootFolder;
121118
foreach (var component in currComponents.Skip(1))
122119
{
123120
folder = await folder.GetFolderAsync(component.Title);
124-
path = Path.Combine(path, folder.Name);
125121
}
126-
return new StorageFolderWithPath(folder, path);
122+
return folder;
127123
}
128124
}
129125

130126
if (parentFolder != null && !Path.IsPathRooted(value))
131127
{
132128
// Relative path
133129
var fullPath = Path.GetFullPath(Path.Combine(parentFolder.Path, value));
134-
return new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(fullPath));
130+
return await StorageFolder.GetFolderFromPathAsync(fullPath);
135131
}
136132
else
137133
{
138-
return new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(value));
134+
return await StorageFolder.GetFolderFromPathAsync(value);
139135
}
140136
}
141137

142-
public async static Task<StorageFolder> DangerousGetFolderFromPathAsync(string value,
143-
StorageFolderWithPath rootFolder = null,
144-
StorageFolderWithPath parentFolder = null)
138+
public async static Task<IStorageFolder> DangerousGetFolderFromPathAsync(string value,
139+
IStorageFolder rootFolder = null,
140+
IStorageFolder parentFolder = null)
145141
{
146-
return (await DangerousGetFolderWithPathFromPathAsync(value, rootFolder, parentFolder)).Folder;
142+
return await DangerousGetFolderWithPathFromPathAsync(value, rootFolder, parentFolder);
147143
}
148144

149-
public async static Task<StorageFileWithPath> DangerousGetFileWithPathFromPathAsync(string value,
150-
StorageFolderWithPath rootFolder = null,
151-
StorageFolderWithPath parentFolder = null)
145+
public async static Task<IStorageFile> DangerousGetFileWithPathFromPathAsync(string value,
146+
IStorageFolder rootFolder = null,
147+
IStorageFolder parentFolder = null)
152148
{
153149
if (rootFolder != null)
154150
{
155151
var currComponents = GetDirectoryPathComponents(value);
156152

157153
if (parentFolder != null && value.IsSubPathOf(parentFolder.Path))
158154
{
159-
var folder = parentFolder.Folder;
155+
var folder = parentFolder;
160156
var prevComponents = GetDirectoryPathComponents(parentFolder.Path);
161-
var path = parentFolder.Path;
162157
foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path).SkipLast(1))
163158
{
164159
folder = await folder.GetFolderAsync(component.Title);
165-
path = Path.Combine(path, folder.Name);
166160
}
167161
var file = await folder.GetFileAsync(currComponents.Last().Title);
168-
path = Path.Combine(path, file.Name);
169-
return new StorageFileWithPath(file, path);
162+
return file;
170163
}
171164
else if (value.IsSubPathOf(rootFolder.Path))
172165
{
173-
var folder = rootFolder.Folder;
174-
var path = rootFolder.Path;
166+
var folder = rootFolder;
175167
foreach (var component in currComponents.Skip(1).SkipLast(1))
176168
{
177169
folder = await folder.GetFolderAsync(component.Title);
178-
path = Path.Combine(path, folder.Name);
179170
}
180171
var file = await folder.GetFileAsync(currComponents.Last().Title);
181-
path = Path.Combine(path, file.Name);
182-
return new StorageFileWithPath(file, path);
172+
return file;
183173
}
184174
}
185175

186176
if (parentFolder != null && !Path.IsPathRooted(value))
187177
{
188178
// Relative path
189179
var fullPath = Path.GetFullPath(Path.Combine(parentFolder.Path, value));
190-
return new StorageFileWithPath(await StorageFile.GetFileFromPathAsync(fullPath));
180+
return await StorageFile.GetFileFromPathAsync(fullPath);
191181
}
192182
else
193183
{
194-
return new StorageFileWithPath(await StorageFile.GetFileFromPathAsync(value));
184+
return await StorageFile.GetFileFromPathAsync(value);
195185
}
196186
}
197187

198-
public async static Task<StorageFile> DangerousGetFileFromPathAsync(string value,
199-
StorageFolderWithPath rootFolder = null,
200-
StorageFolderWithPath parentFolder = null)
188+
public async static Task<IStorageFile> DangerousGetFileFromPathAsync(string value,
189+
IStorageFolder rootFolder = null,
190+
IStorageFolder parentFolder = null)
201191
{
202-
return (await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder)).File;
192+
return await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder);
203193
}
204194

205-
public async static Task<IList<StorageFolderWithPath>> GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue)
206-
{
207-
return (await parentFolder.Folder.GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, maxNumberOfItems))
208-
.Select(x => new StorageFolderWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList();
209-
}
210-
211-
public async static Task<IList<StorageFileWithPath>> GetFilesWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue)
212-
{
213-
return (await parentFolder.Folder.GetFilesAsync(CommonFileQuery.DefaultQuery, 0, maxNumberOfItems))
214-
.Select(x => new StorageFileWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList();
215-
}
216-
217-
public async static Task<IList<StorageFolderWithPath>> GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, string nameFilter, uint maxNumberOfItems = uint.MaxValue)
195+
public async static Task<IList<StorageFolder>> GetFoldersWithPathAsync(this StorageFolder parentFolder, string nameFilter, uint maxNumberOfItems = uint.MaxValue)
218196
{
219197
var queryOptions = new QueryOptions();
220198
queryOptions.ApplicationSearchFilter = $"System.FileName:{nameFilter}*";
221-
StorageFolderQueryResult queryResult = parentFolder.Folder.CreateFolderQueryWithOptions(queryOptions);
199+
StorageFolderQueryResult queryResult = parentFolder.CreateFolderQueryWithOptions(queryOptions);
222200

223-
return (await queryResult.GetFoldersAsync(0, maxNumberOfItems)).Select(x => new StorageFolderWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList();
201+
return (await queryResult.GetFoldersAsync(0, maxNumberOfItems)).ToList();
224202
}
225203

226204
public static string GetPathWithoutEnvironmentVariable(string path)

‎Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs

-35
This file was deleted.

‎Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs

-35
This file was deleted.

0 commit comments

Comments
 (0)