Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b5abe39
Improve overall performance and UI responsiveness
hez2010 Jan 15, 2021
291a1aa
Fix incorrect caching and use gradual cache loading
hez2010 Jan 16, 2021
ff56467
Discard cache if refresh manually
hez2010 Jan 16, 2021
04d8534
Scroll history item into view
hez2010 Jan 16, 2021
1d90b3b
Make directory info update real-time
hez2010 Jan 16, 2021
b8de0c7
Fix potential cache massed-up
hez2010 Jan 16, 2021
8bdf9b9
Make cache loading cancellable
hez2010 Jan 16, 2021
37e0402
Update cache if list changed
hez2010 Jan 16, 2021
8a5c9a7
Remove redundant .ToArray()
hez2010 Jan 16, 2021
f25d138
Fix crash if semaphore failed to wait a handle for cancellation
hez2010 Jan 16, 2021
eb68ded
Introduce an interval sampler for list update
hez2010 Jan 16, 2021
f7a904b
Fix empty prompt doesn't show in empty directory
hez2010 Jan 16, 2021
9632c64
Save cache to memory after loading from persistent cache
hez2010 Jan 16, 2021
3197576
Prevent enumerating on a modified collection
hez2010 Jan 16, 2021
fff82b9
Semaphore waiting improvements
hez2010 Jan 16, 2021
34dcdaa
Optimize file monitor to prevent UI lag when lots of file changes occ…
hez2010 Jan 17, 2021
9cad3ac
Make LoadExtendedItemProperties as background task
hez2010 Jan 18, 2021
c85e486
Avoid blocking wait on an async operation
hez2010 Jan 18, 2021
06b47f4
Avoid large persistent cache
hez2010 Jan 18, 2021
77503ed
Remove redundant .ToArray()
hez2010 Jan 18, 2021
c63a9b7
Fix rebase issue
hez2010 Jan 18, 2021
83fcf12
Merge branch 'main' into pr/3045
yaira2 Jan 18, 2021
5acf11f
Fixed code style
yaira2 Jan 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Files/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
ParentShellPageInstance.InstanceViewModel.IsPageTypeSearchResults = true;
if (!navigationArguments.IsLayoutSwitch)
{
ParentShellPageInstance.FilesystemViewModel.AddSearchResultsToCollection(navigationArguments.SearchResults, navigationArguments.SearchPathParam);
await ParentShellPageInstance.FilesystemViewModel.AddSearchResultsToCollection(navigationArguments.SearchResults, navigationArguments.SearchPathParam);
}
}

Expand Down Expand Up @@ -751,12 +751,12 @@ public void RightClickItemContextMenu_Opening(object sender, object e)
ParentShellPageInstance.ContentPage.SelectedItemsPropertiesViewModel.CheckFileExtension();
}

protected virtual void Page_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
protected virtual async void Page_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
{
if (ParentShellPageInstance.IsCurrentInstance)
{
char letterPressed = Convert.ToChar(args.KeyCode);
ParentShellPageInstance.InteractionOperations.PushJumpChar(letterPressed);
await ParentShellPageInstance.InteractionOperations.PushJumpChar(letterPressed);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@
<Compile Include="Dialogs\RestartDialog.xaml.cs">
<DependentUpon>RestartDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Helpers\BitmapHelper.cs" />
<Compile Include="Helpers\FileListCache\CacheEntry.cs" />
<Compile Include="Helpers\FileListCache\FileListCacheController.cs" />
<Compile Include="Helpers\FileListCache\IFileListCache.cs" />
<Compile Include="Helpers\FileListCache\PersistentSQLiteCacheAdapter.cs" />
<Compile Include="Helpers\IntervalSampler.cs" />
<Compile Include="Helpers\RegistryHelper.cs" />
<Compile Include="UserControls\MultitaskingControl\TabItem\TabItemControl.xaml.cs">
<DependentUpon>TabItemControl.xaml</DependentUpon>
Expand Down
20 changes: 11 additions & 9 deletions Files/Filesystem/Cloud/Providers/AmazonDriveProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ public class AmazonDriveProvider : ICloudProviderDetector
{
public async Task DetectAsync(List<CloudProvider> cloudProviders)
{
try
await Task.Run(() =>
{
await Task.Run(() =>
try
{
using var key = Registry.ClassesRoot.OpenSubKey(@"CLSID\{9B57F475-CCB0-4C85-88A9-2AA9A6C0809A}\Instance\InitPropertyBag");
var syncedFolder = (string)key.GetValue("TargetFolderPath");
var syncedFolder = (string)key?.GetValue("TargetFolderPath");

if (syncedFolder == null) return;

cloudProviders.Add(new CloudProvider()
{
ID = CloudProviders.AmazonDrive,
Name = "Amazon Drive",
SyncFolder = syncedFolder
});
});
}
catch
{
// Not detected
}
}
catch
{
// Not detected
}
});
}
}
}
19 changes: 19 additions & 0 deletions Files/Helpers/BitmapHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Windows.UI.Xaml.Media.Imaging;

namespace Files.Helpers
{
static class BitmapHelper
{
public static async Task<BitmapImage> ToBitmapAsync(this byte[] data)
{
if (data is null) return null;
using var ms = new MemoryStream(data);
var image = new BitmapImage();
await image.SetSourceAsync(ms.AsRandomAccessStream());
return image;
}
}
}
24 changes: 20 additions & 4 deletions Files/Helpers/FileListCache/FileListCacheController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Caching.Memory;
using System.Threading;
using System.Threading.Tasks;

namespace Files.Helpers.FileListCache
Expand Down Expand Up @@ -27,21 +28,36 @@ private FileListCacheController()
public Task SaveFileListToCache(string path, CacheEntry cacheEntry)
{
if (!App.AppSettings.UseFileListCache) return Task.CompletedTask;
if (cacheEntry == null)
{
filesCache.Remove(path);
return persistentAdapter.SaveFileListToCache(path, cacheEntry);
}
filesCache.Set(path, cacheEntry, new MemoryCacheEntryOptions
{
Size = cacheEntry.FileList.Count
});

// save entry to persistent cache in background
Task.Run(async () => await persistentAdapter.SaveFileListToCache(path, cacheEntry));
return Task.CompletedTask;
return persistentAdapter.SaveFileListToCache(path, cacheEntry);
}

public async Task<CacheEntry> ReadFileListFromCache(string path)
public async Task<CacheEntry> ReadFileListFromCache(string path, CancellationToken cancellationToken)
{
if (!App.AppSettings.UseFileListCache) return null;
var entry = filesCache.Get<CacheEntry>(path);
return entry ?? await persistentAdapter.ReadFileListFromCache(path);
if (entry == null)
{
entry = await persistentAdapter.ReadFileListFromCache(path, cancellationToken);
if (entry?.FileList != null)
{
filesCache.Set(path, entry, new MemoryCacheEntryOptions
{
Size = entry.FileList.Count
});
}
}
return entry;
}
}
}
5 changes: 3 additions & 2 deletions Files/Helpers/FileListCache/IFileListCache.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;

namespace Files.Helpers.FileListCache
{
internal interface IFileListCache
{
public Task<CacheEntry> ReadFileListFromCache(string path);
public Task<CacheEntry> ReadFileListFromCache(string path, CancellationToken cancellationToken);

public Task SaveFileListToCache(string path, CacheEntry cacheEntry);
}
Expand Down
30 changes: 23 additions & 7 deletions Files/Helpers/FileListCache/PersistentSQLiteCacheAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;

Expand Down Expand Up @@ -43,19 +45,33 @@ PRIMARY KEY(""Id"")

public async Task SaveFileListToCache(string path, CacheEntry cacheEntry)
{
const int maxCachedEntries = 128;
try
{
if (cacheEntry == null)
{
using var deleteCommand = new SqliteCommand("DELETE FROM FileListCache WHERE Id = @Id", connection);
deleteCommand.Parameters.Add("@Id", SqliteType.Text).Value = path;
await deleteCommand.ExecuteNonQueryAsync();
return;
}

if (cacheEntry.FileList.Count > maxCachedEntries)
{
cacheEntry.FileList = cacheEntry.FileList.Take(maxCachedEntries).ToList();
}

using var cmd = new SqliteCommand("SELECT Id FROM FileListCache WHERE Id = @Id", connection);
cmd.Parameters.Add("@Id", SqliteType.Text).Value = path;
using var reader = await cmd.ExecuteReaderAsync();
if (reader.HasRows)
{
// need to update entry
using var insertCommand = new SqliteCommand("UPDATE FileListCache SET Timestamp = @Timestamp, Entry = @Entry WHERE Id = @Id", connection);
insertCommand.Parameters.Add("@Id", SqliteType.Text).Value = path;
insertCommand.Parameters.Add("@Timestamp", SqliteType.Integer).Value = GetTimestamp(DateTime.UtcNow);
insertCommand.Parameters.Add("@Entry", SqliteType.Text).Value = JsonConvert.SerializeObject(cacheEntry);
await insertCommand.ExecuteNonQueryAsync();
using var updateCommand = new SqliteCommand("UPDATE FileListCache SET Timestamp = @Timestamp, Entry = @Entry WHERE Id = @Id", connection);
updateCommand.Parameters.Add("@Id", SqliteType.Text).Value = path;
updateCommand.Parameters.Add("@Timestamp", SqliteType.Integer).Value = GetTimestamp(DateTime.UtcNow);
updateCommand.Parameters.Add("@Entry", SqliteType.Text).Value = JsonConvert.SerializeObject(cacheEntry);
await updateCommand.ExecuteNonQueryAsync();
}
else
{
Expand All @@ -73,14 +89,14 @@ public async Task SaveFileListToCache(string path, CacheEntry cacheEntry)
}
}

public async Task<CacheEntry> ReadFileListFromCache(string path)
public async Task<CacheEntry> ReadFileListFromCache(string path, CancellationToken cancellationToken)
{
try
{
using var cmd = new SqliteCommand("SELECT Timestamp, Entry FROM FileListCache WHERE Id = @Id", connection);
cmd.Parameters.Add("@Id", SqliteType.Text).Value = path;

using var reader = await cmd.ExecuteReaderAsync();
using var reader = await cmd.ExecuteReaderAsync(cancellationToken);
if (!await reader.ReadAsync())
{
return null;
Expand Down
38 changes: 38 additions & 0 deletions Files/Helpers/IntervalSampler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;

namespace Files.Helpers
{
class IntervalSampler
{
private DateTime recordPoint;
private TimeSpan sampleInterval;

public IntervalSampler(int millisecondsInterval)
{
sampleInterval = TimeSpan.FromMilliseconds(millisecondsInterval);
recordPoint = DateTime.Now;
}

public IntervalSampler(TimeSpan interval)
{
sampleInterval = interval;
recordPoint = DateTime.Now;
}

public void Reset()
{
recordPoint = DateTime.Now;
}

public bool CheckNow()
{
var now = DateTime.Now;
if (now - sampleInterval >= recordPoint)
{
recordPoint = now;
return true;
}
return false;
}
}
}
4 changes: 2 additions & 2 deletions Files/Interacts/Interaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,9 +1227,9 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
}
}

public void PushJumpChar(char letter)
public Task PushJumpChar(char letter)
{
AssociatedInstance.FilesystemViewModel.JumpString += letter.ToString().ToLower();
return AssociatedInstance.FilesystemViewModel.SetJumpStringAsync(AssociatedInstance.FilesystemViewModel.JumpString + letter.ToString().ToLower());
}

public async Task<string> GetHashForFileAsync(ListedItem fileItem, string nameOfAlg, CancellationToken token, Microsoft.UI.Xaml.Controls.ProgressBar progress)
Expand Down
2 changes: 1 addition & 1 deletion Files/MultilingualResources/Files.hu-HU.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2060,4 +2060,4 @@
</group>
</body>
</file>
</xliff>
</xliff>
5 changes: 3 additions & 2 deletions Files/MultilingualResources/Files.tr-TR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,9 @@
<target state="translated">Yeni isim oluştur</target>
</trans-unit>
<trans-unit id="ItemAlreadyExistsDialogTitle" translate="yes" xml:space="preserve">
<source>Öğe zaten mevcut</source>
<source>Item already exists</source>
<target state="needs-review-translation" state-qualifier="tm-suggestion">Öğe zaten mevcut</target>
<note from="MultilingualUpdate" annotates="source" priority="2">Please verify the translation’s accuracy as the source string was updated after it was translated.</note>
</trans-unit>
<trans-unit id="ItemAlreadyExistsDialogSecondaryButtonText" translate="yes" xml:space="preserve">
<source>Replace existing item</source>
Expand Down Expand Up @@ -2062,4 +2063,4 @@
</group>
</body>
</file>
</xliff>
</xliff>
4 changes: 2 additions & 2 deletions Files/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Files
{
internal class Program
{
private static void Main()
private static async Task Main()
{
var args = Environment.GetCommandLineArgs();
var proc = System.Diagnostics.Process.GetCurrentProcess();
Expand All @@ -27,7 +27,7 @@ private static void Main()
switch (command.Type)
{
case ParsedCommandType.ExplorerShellCommand:
OpenShellCommandInExplorerAsync(command.Payload, proc.Id).GetAwaiter().GetResult();
await OpenShellCommandInExplorerAsync(command.Payload, proc.Id);
//Exit..

return;
Expand Down
6 changes: 6 additions & 0 deletions Files/Strings/hu-HU/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1518,4 +1518,10 @@
<data name="StatusBarControlDetailsView.AutomationProperties.Name" xml:space="preserve">
<value>Részletek</value>
</data>
<data name="BaseLayoutContextFlyoutSortByDateDeleted.Text" xml:space="preserve">
<value>Törlés dátuma</value>
</data>
<data name="dateDeletedColumn.Header" xml:space="preserve">
<value>Törlés dátuma</value>
</data>
</root>
26 changes: 25 additions & 1 deletion Files/Strings/ru-RU/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<value>Отправить отчет о проблеме, чтобы предоставить разработчикам больше информации о ней</value>
</data>
<data name="SettingsAboutThirdPartyLicenses.Text" xml:space="preserve">
<value>Third Party Licenses</value>
<value>Сторонние лицензии</value>
</data>
<data name="SettingsAboutTitle.Text" xml:space="preserve">
<value>О приложении</value>
Expand Down Expand Up @@ -1413,4 +1413,28 @@
<data name="SettingsDualPane.Text" xml:space="preserve">
<value>Двойная панель</value>
</data>
<data name="SettingsCopyLocationSwitch.Header" xml:space="preserve">
<value>Отображать пункт "Копировать местоположение"</value>
</data>
<data name="SettingsContextMenuOverflowSwitch.Header" xml:space="preserve">
<value>Переносить непомещающиеся пункты в подменю</value>
</data>
<data name="SettingsContextMenu.Text" xml:space="preserve">
<value>Настройки контекстного меню</value>
</data>
<data name="SettingsOpenInNewTabSwitch.Header" xml:space="preserve">
<value>Отображать пункт "Открыть в новой вкладке"</value>
</data>
<data name="LibraryWidgetDescription.Text" xml:space="preserve">
<value>Папки</value>
</data>
<data name="SettingsContextMenuAnimationsSwitch.Header" xml:space="preserve">
<value>Использовать анимации при открытии и закрытии контекстного меню</value>
</data>
<data name="StatusBarControlShowFileExtensions.Header" xml:space="preserve">
<value>Отображать расширения файлов</value>
</data>
<data name="StatusBarControlShowHiddenItems.Header" xml:space="preserve">
<value>Отображать скрытые файлы</value>
</data>
</root>
Loading