Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Introduced App.Utils.Storage namespace for storage functionalities #12902

Merged
merged 15 commits into from
Jul 19, 2023
Merged
1 change: 0 additions & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Files.App.Extensions;
using Files.App.Utils;
using Files.App.Utils.Cloud;
using Files.App.Utils.FilesystemHistory;
using Files.App.Helpers;
using Files.App.Services;
using Files.App.Services.DateTimeFormatter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Files.App.Extensions;
using Files.App.Utils.Security;
using System.Collections.Generic;
using System.Collections.ObjectModel;

Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Data/Items/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.Cloud;
using Files.App.Utils.StorageItems;
using Files.App.ViewModels.Properties;
using Files.Core.Helpers;
using Files.Core.ViewModels.FileTags;
Expand Down
6 changes: 4 additions & 2 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Helpers.StorageCache;
using Files.App.Utils.Cloud;
using Files.App.Utils.Shell;
using Files.App.Storage.FtpStorage;
using Files.App.ViewModels.Previews;
using Files.Core.Services.SizeProvider;
using LibGit2Sharp;
Expand Down Expand Up @@ -36,7 +38,7 @@ public sealed class ItemViewModel : ObservableObject, IDisposable
private readonly AsyncManualResetEvent gitChangedEvent;
private readonly DispatcherQueue dispatcherQueue;
private readonly JsonElement defaultJson = JsonSerializer.SerializeToElement("{}");
private readonly IFileListCache fileListCache = FileListCacheController.GetInstance();
private readonly IStorageCacheController fileListCache = StorageCacheController.GetInstance();
private readonly string folderTypeTextLocalized = "Folder".GetLocalizedResource();

private Task? aProcessQueueAction;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Extensions/ShellNewEntryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils;
using Files.App.Utils.StorageItems;
using Files.App.Helpers;
using Files.App.Utils.Shell;
using Files.Shared;
Expand Down
8 changes: 2 additions & 6 deletions src/Files.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@
global using global::CommunityToolkit.Mvvm.Input;
global using global::CommunityToolkit.Mvvm.Messaging;

// Files Front-end
// Files.App
global using global::Files.App.Helpers;
global using global::Files.App.Extensions;
global using global::Files.App.Utils;
global using global::Files.App.Utils.Archives;
global using global::Files.App.Utils.Cloud;
global using global::Files.App.Utils.FilesystemHistory;
global using global::Files.App.Utils.FileTags;
global using global::Files.App.Utils.Git;
global using global::Files.App.Utils.Library;
global using global::Files.App.Utils.RecentItem;
global using global::Files.App.Utils.RecycleBin;
global using global::Files.App.Utils.Search;
global using global::Files.App.Utils.Security;
global using global::Files.App.Utils.Serialization;
global using global::Files.App.Utils.Shell;
global using global::Files.App.Utils.StorageEnumerators;
global using global::Files.App.Utils.StorageItems;
global using global::Files.App.Utils.Storage;
global using global::Files.App.Data.Attributes;
global using global::Files.App.Data.Behaviors;
global using global::Files.App.Data.Commands;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Helpers/BitmapHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.StorageItems;
using Microsoft.UI.Xaml.Media.Imaging;
using System.IO;
using Windows.Graphics.Imaging;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.App.Extensions;
using Files.App.Utils;
using Files.App.Utils.StorageItems;
using Files.App.Utils.Shell;
using Files.App.ViewModels;
using Files.App.Views;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Helpers/ShareItemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Files.App.Extensions;
using Files.App.Utils;
using Files.App.Utils.StorageItems;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Helpers/UI/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using Files.App.Dialogs;
using Files.App.Utils.StorageItems;
using Files.App.Storage.FtpStorage;
using Files.App.ViewModels.Dialogs;
using Microsoft.Extensions.Logging;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Services/QuickAccessService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.StorageItems;
using Files.App.Utils.Shell;
using Files.App.UserControls.Widgets;

Expand Down
5 changes: 2 additions & 3 deletions src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Files.App.Data.Items;
using Files.App.Data.Models;
using Files.App.Extensions;
using Files.App.Utils.StorageItems;
using Files.App.Helpers.ContextFlyouts;
using Files.App.Services;
using Files.App.Utils.Shell;
Expand Down Expand Up @@ -787,7 +786,7 @@ private async void NavigationViewFileTagItem_DragOver(object sender, DragEventAr
var deferral = e.GetDeferral();
e.Handled = true;

var storageItems = await Utils.FilesystemHelpers.GetDraggedStorageItems(e.DataView);
var storageItems = await FilesystemHelpers.GetDraggedStorageItems(e.DataView);

if (!storageItems.Any())
{
Expand Down Expand Up @@ -820,7 +819,7 @@ private async void NavigationViewFileTag_Drop(object sender, DragEventArgs e)

var deferral = e.GetDeferral();

var storageItems = await Utils.FilesystemHelpers.GetDraggedStorageItems(e.DataView);
var storageItems = await FilesystemHelpers.GetDraggedStorageItems(e.DataView);
foreach (var item in storageItems.Where(x => !string.IsNullOrEmpty(x.Path)))
{
var listedItem = new ListedItem(null)
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using CommunityToolkit.WinUI;
using Files.App.Extensions;
using Files.App.Utils;
using Files.App.Utils.StorageEnumerators;
using Files.App.Utils.StorageItems;
using Files.App.Helpers;
using Files.App.Helpers.ContextFlyouts;
using Files.App.ViewModels;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Utils/Archives/ArchiveHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Files.App.Dialogs;
using Files.App.Utils.Archives;
using Files.App.Utils.StorageItems;
using Files.App.ViewModels.Dialogs;
using Microsoft.UI.Xaml.Controls;
using System.IO;
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Utils/Archives/ZipHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.StorageItems;
using Microsoft.Extensions.Logging;
using SevenZip;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/Cloud/CloudDrivesDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Runtime.Versioning;
using System.Threading.Tasks;

namespace Files.App.Helpers
namespace Files.App.Utils.Cloud
{
[SupportedOSPlatform("Windows10.0.10240")]
public class CloudDrivesDetector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Windows.Storage;
using Windows.System.UserProfile;

namespace Files.App.Helpers
namespace Files.App.Utils
{
public static class WallpaperHelpers
{
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Utils/RecentItem/RecentItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.StorageItems;
using Files.App.UserControls.Widgets;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using System.Threading;
using System.Threading.Tasks;

namespace Files.App.Helpers.StorageCache
namespace Files.App.Utils.Storage
{
internal interface IFileListCache
internal interface IStorageCacheController
{
public ValueTask<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken);

public ValueTask SaveFileDisplayNameToCache(string path, string displayName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
// Licensed under the MIT License. See the LICENSE.

using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;

namespace Files.App.Helpers.StorageCache
namespace Files.App.Utils.Storage
{
internal class FileListCacheController : IFileListCache
internal class StorageCacheController : IStorageCacheController
{
private static FileListCacheController instance;
private static StorageCacheController instance;

public static FileListCacheController GetInstance()
private readonly ConcurrentDictionary<string, string> fileNamesCache = new();

private StorageCacheController()
{
return instance ??= new FileListCacheController();
}

private FileListCacheController()
public static StorageCacheController GetInstance()
{
return instance ??= new StorageCacheController();
}

private readonly ConcurrentDictionary<string, string> fileNamesCache = new();

public ValueTask<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken)
{
return fileNamesCache.TryGetValue(path, out var displayName) ? ValueTask.FromResult(displayName) : ValueTask.FromResult(string.Empty);
Expand All @@ -38,4 +36,4 @@ public ValueTask SaveFileDisplayNameToCache(string path, string displayName)
return ValueTask.CompletedTask;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using System.Collections;
using System.Collections.Generic;

namespace Files.App.Helpers
namespace Files.App.Utils.Storage
{
public class BlockingListEnumerator<T> : IEnumerator<T>
{
private readonly IList<T> m_Inner;

private readonly object m_Lock;

private T m_Current;
private int m_Pos;

public BlockingListEnumerator(IList<T> inner, object @lock)
{
m_Inner = inner;
m_Lock = @lock;
m_Pos = -1;
}
private int m_Pos;

public T Current
{
get
{
lock (m_Lock)
{
return m_Current;
}
}
}

object IEnumerator.Current => Current;
object IEnumerator.Current
=> Current;

public BlockingListEnumerator(IList<T> inner, object @lock)
{
m_Inner = inner;
m_Lock = @lock;
m_Pos = -1;
}

public void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.Shared.Extensions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;

namespace Files.App.Helpers
namespace Files.App.Utils.Storage
{
[DebuggerTypeProxy(typeof(CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Files.App.Helpers
public class ConcurrentCollection<T> : ICollection<T>, IList<T>, ICollection, IList
{
private readonly object syncRoot = new object();

private readonly List<T> collection = new List<T>();

public int Count
Expand Down Expand Up @@ -231,6 +232,7 @@ public void Sort(Comparison<T> comparison)
public void Order(Func<List<T>, IEnumerable<T>> func)
{
IEnumerable<T> result;

lock (syncRoot)
{
result = func.Invoke(collection);
Expand All @@ -242,12 +244,14 @@ public void Order(Func<List<T>, IEnumerable<T>> func)
public void OrderOne(Func<List<T>, IEnumerable<T>> func, T item)
{
IList<T> result;

lock (syncRoot)
{
result = func.Invoke(collection).ToList();
}

Remove(item);

var index = result.IndexOf(item);
if (index != -1)
Insert(index, item);
Expand Down
Loading