Skip to content

Commit e329de0

Browse files
committed
part 1
1 parent dd12008 commit e329de0

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>8.0</LangVersion>
4444
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4545
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
4646
</PropertyGroup>
@@ -55,7 +55,6 @@
5555
<ErrorReport>prompt</ErrorReport>
5656
<Prefer32Bit>true</Prefer32Bit>
5757
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
58-
<LangVersion>8.0</LangVersion>
5958
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6059
</PropertyGroup>
6160
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
@@ -68,7 +67,6 @@
6867
<UseVSHostingProcess>false</UseVSHostingProcess>
6968
<ErrorReport>prompt</ErrorReport>
7069
<Prefer32Bit>true</Prefer32Bit>
71-
<LangVersion>8.0</LangVersion>
7270
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7371
</PropertyGroup>
7472
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
@@ -82,7 +80,6 @@
8280
<ErrorReport>prompt</ErrorReport>
8381
<Prefer32Bit>true</Prefer32Bit>
8482
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
85-
<LangVersion>8.0</LangVersion>
8683
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8784
</PropertyGroup>
8885
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
@@ -96,7 +93,6 @@
9693
<ErrorReport>prompt</ErrorReport>
9794
<Prefer32Bit>true</Prefer32Bit>
9895
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
99-
<LangVersion>8.0</LangVersion>
10096
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10197
</PropertyGroup>
10298
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM64'">
@@ -110,7 +106,6 @@
110106
<ErrorReport>prompt</ErrorReport>
111107
<Prefer32Bit>true</Prefer32Bit>
112108
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
113-
<LangVersion>8.0</LangVersion>
114109
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
115110
</PropertyGroup>
116111
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
@@ -123,7 +118,6 @@
123118
<UseVSHostingProcess>false</UseVSHostingProcess>
124119
<ErrorReport>prompt</ErrorReport>
125120
<Prefer32Bit>true</Prefer32Bit>
126-
<LangVersion>8.0</LangVersion>
127121
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
128122
</PropertyGroup>
129123
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
@@ -137,7 +131,6 @@
137131
<ErrorReport>prompt</ErrorReport>
138132
<Prefer32Bit>true</Prefer32Bit>
139133
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
140-
<LangVersion>8.0</LangVersion>
141134
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
142135
</PropertyGroup>
143136
<PropertyGroup>
@@ -406,9 +399,6 @@
406399
<Compile Include="Filesystem\Search\FolderSearch.cs" />
407400
<Compile Include="Filesystem\StorageFileHelpers\FilesystemResult.cs" />
408401
<Compile Include="Filesystem\StorageFileHelpers\StorageFileExtensions.cs" />
409-
<Compile Include="Filesystem\StorageFileHelpers\IStorageItemWithPath.cs" />
410-
<Compile Include="Filesystem\StorageFileHelpers\StorageFileWithPath.cs" />
411-
<Compile Include="Filesystem\StorageFileHelpers\StorageFolderWithPath.cs" />
412402
<Compile Include="Filesystem\StorageHistory\Helpers\StorageHistoryHelpers.cs" />
413403
<Compile Include="Filesystem\StorageHistory\IStorageHistory.cs" />
414404
<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
var extraProps = await basicProperties.RetrievePropertiesAsync(new[] { "System.DateCreated" });
@@ -168,7 +168,7 @@ private static async Task<ListedItem> AddFolderAsync(StorageFolder folder, Stora
168168

169169
private static async Task<ListedItem> AddFileAsync(
170170
StorageFile file,
171-
StorageFolderWithPath currentStorageFolder,
171+
IStorageFolder currentStorageFolder,
172172
string dateReturnFormat,
173173
bool suppressThumbnailLoading,
174174
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)