Skip to content

Commit 4c19c68

Browse files
authored
Revert "Code Quality: Improved app startup routine 2" (#13526)
1 parent 5fc5d32 commit 4c19c68

File tree

73 files changed

+805
-875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+805
-875
lines changed

src/Files.App.Storage/Files.App.Storage.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<Configurations>Debug;Release;Stable;Preview;Store</Configurations>
1010
<Platforms>x86;x64;arm64</Platforms>
1111
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
12-
<ImplicitUsings>enable</ImplicitUsings>
1312
</PropertyGroup>
1413

1514
<ItemGroup>

src/Files.App.Storage/GlobalUsings.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Files.App.Storage/NativeStorage/NativeFolder.cs

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10,89 +10,94 @@
1010
using Files.Core.Storage.ModifiableStorage;
1111
using Files.Core.Storage.MutableStorage;
1212
using Files.Core.Storage.NestedStorage;
13+
using System;
14+
using System.Collections.Generic;
15+
using System.IO;
1316
using System.Runtime.CompilerServices;
17+
using System.Threading;
18+
using System.Threading.Tasks;
1419

1520
namespace Files.App.Storage.NativeStorage
1621
{
1722
/// <inheritdoc cref="IFolder"/>
1823
public class NativeFolder : NativeStorable<DirectoryInfo>, ILocatableFolder, IModifiableFolder, IMutableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove
19-
{
24+
{
2025
public NativeFolder(DirectoryInfo directoryInfo, string? name = null)
21-
: base(directoryInfo, name)
22-
{
23-
}
24-
25-
public NativeFolder(string path, string? name = null)
26-
: this(new DirectoryInfo(path), name)
27-
{
28-
}
29-
30-
/// <inheritdoc/>
31-
public virtual Task<INestedFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default)
32-
{
33-
var path = SystemIO.Path.Combine(Path, fileName);
34-
35-
if (!File.Exists(path))
36-
throw new FileNotFoundException();
37-
38-
return Task.FromResult<INestedFile>(new NativeFile(path));
39-
}
40-
41-
/// <inheritdoc/>
42-
public virtual Task<INestedFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default)
43-
{
44-
var path = SystemIO.Path.Combine(Path, folderName);
45-
if (!Directory.Exists(path))
46-
throw new FileNotFoundException();
47-
48-
return Task.FromResult<INestedFolder>(new NativeFolder(path));
49-
}
50-
51-
/// <inheritdoc/>
52-
public virtual async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind = StorableKind.All, [EnumeratorCancellation] CancellationToken cancellationToken = default)
53-
{
54-
if (kind == StorableKind.Files)
55-
{
56-
foreach (var item in Directory.EnumerateFiles(Path))
57-
yield return new NativeFile(item);
58-
}
59-
else if (kind == StorableKind.Folders)
60-
{
61-
foreach (var item in Directory.EnumerateDirectories(Path))
62-
yield return new NativeFolder(item);
63-
}
64-
else
65-
{
66-
foreach (var item in Directory.EnumerateFileSystemEntries(Path))
67-
{
68-
if (File.Exists(item))
69-
yield return new NativeFile(item);
70-
else
71-
yield return new NativeFolder(item);
72-
}
73-
}
74-
75-
await Task.CompletedTask;
76-
}
26+
: base(directoryInfo, name)
27+
{
28+
}
29+
30+
public NativeFolder(string path, string? name = null)
31+
: this(new DirectoryInfo(path), name)
32+
{
33+
}
34+
35+
/// <inheritdoc/>
36+
public virtual Task<INestedFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default)
37+
{
38+
var path = System.IO.Path.Combine(Path, fileName);
39+
40+
if (!File.Exists(path))
41+
throw new FileNotFoundException();
42+
43+
return Task.FromResult<INestedFile>(new NativeFile(path));
44+
}
45+
46+
/// <inheritdoc/>
47+
public virtual Task<INestedFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default)
48+
{
49+
var path = System.IO.Path.Combine(Path, folderName);
50+
if (!Directory.Exists(path))
51+
throw new FileNotFoundException();
52+
53+
return Task.FromResult<INestedFolder>(new NativeFolder(path));
54+
}
55+
56+
/// <inheritdoc/>
57+
public virtual async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind = StorableKind.All, [EnumeratorCancellation] CancellationToken cancellationToken = default)
58+
{
59+
if (kind == StorableKind.Files)
60+
{
61+
foreach (var item in Directory.EnumerateFiles(Path))
62+
yield return new NativeFile(item);
63+
}
64+
else if (kind == StorableKind.Folders)
65+
{
66+
foreach (var item in Directory.EnumerateDirectories(Path))
67+
yield return new NativeFolder(item);
68+
}
69+
else
70+
{
71+
foreach (var item in Directory.EnumerateFileSystemEntries(Path))
72+
{
73+
if (File.Exists(item))
74+
yield return new NativeFile(item);
75+
else
76+
yield return new NativeFolder(item);
77+
}
78+
}
79+
80+
await Task.CompletedTask;
81+
}
7782

7883
/// <inheritdoc/>
7984
public virtual Task DeleteAsync(INestedStorable item, bool permanently = false, CancellationToken cancellationToken = default)
80-
{
81-
_ = permanently;
82-
83-
if (item is ILocatableFile locatableFile)
84-
{
85-
File.Delete(locatableFile.Path);
86-
}
87-
else if (item is ILocatableFolder locatableFolder)
88-
{
89-
Directory.Delete(locatableFolder.Path, true);
90-
}
91-
else
92-
throw new ArgumentException($"Could not delete {item}.");
93-
94-
return Task.CompletedTask;
95-
}
85+
{
86+
_ = permanently;
87+
88+
if (item is ILocatableFile locatableFile)
89+
{
90+
File.Delete(locatableFile.Path);
91+
}
92+
else if (item is ILocatableFolder locatableFolder)
93+
{
94+
Directory.Delete(locatableFolder.Path, true);
95+
}
96+
else
97+
throw new ArgumentException($"Could not delete {item}.");
98+
99+
return Task.CompletedTask;
100+
}
96101

97102
/// <inheritdoc/>
98103
public virtual async Task<INestedStorable> CreateCopyOfAsync(INestedStorable itemToCopy, bool overwrite = default, CancellationToken cancellationToken = default)
@@ -101,7 +106,7 @@ public virtual async Task<INestedStorable> CreateCopyOfAsync(INestedStorable ite
101106
{
102107
if (itemToCopy is ILocatableFile sourceLocatableFile)
103108
{
104-
var newPath = SystemIO.Path.Combine(Path, itemToCopy.Name);
109+
var newPath = System.IO.Path.Combine(Path, itemToCopy.Name);
105110
File.Copy(sourceLocatableFile.Path, newPath, overwrite);
106111

107112
return new NativeFile(newPath);
@@ -129,7 +134,7 @@ public virtual async Task<INestedStorable> MoveFromAsync(INestedStorable itemToM
129134
{
130135
if (itemToMove is ILocatableFile sourceLocatableFile)
131136
{
132-
var newPath = SystemIO.Path.Combine(Path, itemToMove.Name);
137+
var newPath = System.IO.Path.Combine(Path, itemToMove.Name);
133138
File.Move(sourceLocatableFile.Path, newPath, overwrite);
134139

135140
return new NativeFile(newPath);
@@ -154,7 +159,7 @@ public virtual async Task<INestedStorable> MoveFromAsync(INestedStorable itemToM
154159
/// <inheritdoc/>
155160
public virtual async Task<INestedFile> CreateFileAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
156161
{
157-
var path = SystemIO.Path.Combine(Path, desiredName);
162+
var path = System.IO.Path.Combine(Path, desiredName);
158163
if (overwrite || !File.Exists(path))
159164
await File.Create(path).DisposeAsync();
160165

@@ -164,7 +169,7 @@ public virtual async Task<INestedFile> CreateFileAsync(string desiredName, bool
164169
/// <inheritdoc/>
165170
public virtual Task<INestedFolder> CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
166171
{
167-
var path = SystemIO.Path.Combine(Path, desiredName);
172+
var path = System.IO.Path.Combine(Path, desiredName);
168173
if (overwrite)
169174
Directory.Delete(path, true);
170175

@@ -174,8 +179,8 @@ public virtual Task<INestedFolder> CreateFolderAsync(string desiredName, bool ov
174179

175180
/// <inheritdoc/>
176181
public Task<IFolderWatcher> GetFolderWatcherAsync(CancellationToken cancellationToken = default)
177-
{
178-
return Task.FromResult<IFolderWatcher>(new NativeFolderWatcher(this));
179-
}
180-
}
182+
{
183+
return Task.FromResult<IFolderWatcher>(new NativeFolderWatcher(this));
184+
}
185+
}
181186
}

src/Files.App.Storage/NativeStorage/NativeStorable.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ protected static string FormatPath(string path)
5252
{
5353
path = path.Replace("file:///", string.Empty);
5454

55-
if ('/' != SystemIO.Path.DirectorySeparatorChar)
56-
return path.Replace('/', SystemIO.Path.DirectorySeparatorChar);
55+
if ('/' != System.IO.Path.DirectorySeparatorChar)
56+
return path.Replace('/', System.IO.Path.DirectorySeparatorChar);
5757

58-
if ('\\' != SystemIO.Path.DirectorySeparatorChar)
59-
return path.Replace('\\', SystemIO.Path.DirectorySeparatorChar);
58+
if ('\\' != System.IO.Path.DirectorySeparatorChar)
59+
return path.Replace('\\', System.IO.Path.DirectorySeparatorChar);
6060

6161
return path;
6262
}

src/Files.App/Actions/Start/PinToStartAction.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.Core.Storage;
5-
64
namespace Files.App.Actions
75
{
86
internal class PinToStartAction : IAction
97
{
108
public IContentPageContext context;
119

12-
private IStartMenuService SystemPinService { get; } = Ioc.Default.GetRequiredService<IStartMenuService>();
13-
14-
private IStorageService StorageService { get; } = Ioc.Default.GetRequiredService<IStorageService>();
15-
16-
1710
public string Label
1811
=> "PinItemToStart/Text".GetLocalizedResource();
1912

@@ -33,15 +26,11 @@ public async Task ExecuteAsync()
3326
if (context.SelectedItems.Count > 0)
3427
{
3528
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems)
36-
{
37-
var folder = await StorageService.GetFolderAsync(listedItem.ItemPath);
38-
await SystemPinService.PinAsync(folder);
39-
}
29+
await App.SecondaryTileHelper.TryPinFolderAsync(listedItem.ItemPath, listedItem.Name);
4030
}
4131
else
4232
{
43-
var folder = await StorageService.GetFolderAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath);
44-
await SystemPinService.PinAsync(folder);
33+
await App.SecondaryTileHelper.TryPinFolderAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath, context.ShellPage?.FilesystemViewModel.CurrentFolder.Name);
4534
}
4635
}
4736
}

src/Files.App/Actions/Start/UnpinFromStartAction.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
// Copyright (c) 2023 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.Core.Storage;
5-
64
namespace Files.App.Actions
75
{
86
internal class UnpinFromStartAction : IAction
97
{
108
public IContentPageContext context;
119

12-
private IStartMenuService SystemPinService { get; } = Ioc.Default.GetRequiredService<IStartMenuService>();
13-
14-
private IStorageService StorageService { get; } = Ioc.Default.GetRequiredService<IStorageService>();
15-
1610
public string Label
1711
=> "UnpinItemFromStart/Text".GetLocalizedResource();
1812

@@ -32,15 +26,11 @@ public async Task ExecuteAsync()
3226
if (context.SelectedItems.Count > 0)
3327
{
3428
foreach (ListedItem listedItem in context.ShellPage?.SlimContentPage.SelectedItems)
35-
{
36-
var folder = await StorageService.GetFolderAsync(listedItem.ItemPath);
37-
await SystemPinService.UnpinAsync(folder);
38-
}
29+
await App.SecondaryTileHelper.UnpinFromStartAsync(listedItem.ItemPath);
3930
}
4031
else
4132
{
42-
var folder = await StorageService.GetFolderAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath);
43-
await SystemPinService.UnpinAsync(folder);
33+
await App.SecondaryTileHelper.UnpinFromStartAsync(context.ShellPage?.FilesystemViewModel.CurrentFolder.ItemPath);
4434
}
4535
}
4636
}

0 commit comments

Comments
 (0)