Skip to content

Commit b532219

Browse files
authored
Properties: Fix some properties loading on older systems (#1145)
Optimize code
1 parent e0738ba commit b532219

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

Files/View Models/SelectedItemsPropertiesViewModel.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ public Visibility ItemMD5HashProgressVisibility
173173
}
174174
#endregion
175175
#region Properties
176-
public Microsoft.UI.Xaml.Controls.ProgressBar ItemMD5HashProgress
177-
{
178-
get; set;
179-
}
176+
177+
public Microsoft.UI.Xaml.Controls.ProgressBar ItemMD5HashProgress { get; set; }
178+
180179
public ListedItem Item { get; }
181180

182181
public CoreDispatcher Dispatcher { get; set; }
@@ -332,7 +331,6 @@ public async Task GetPropertiesAsync(CancellationTokenSource _tokenSource)
332331
catch (Exception ex)
333332
{
334333
NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message);
335-
ItemMD5HashProgress.Value = ItemMD5HashProgress.Maximum;
336334
ItemMD5HashCalcError = true;
337335
}
338336
}

Files/Views/Pages/Properties.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
xmlns:local1="using:Files.Helpers"
1010
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1111
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
12+
Loaded="Properties_Loaded"
13+
Unloaded="Properties_Unloaded"
1214
d:DesignHeight="475"
1315
d:DesignWidth="400"
1416
RequestedTheme="{x:Bind local1:ThemeHelper.RootTheme}"

Files/Views/Pages/Properties.xaml.cs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,43 @@
22
using Files.Helpers;
33
using Files.Interacts;
44
using Files.View_Models;
5-
using GalaSoft.MvvmLight;
65
using System;
7-
using System.Collections.Generic;
8-
using System.IO;
9-
using System.Linq;
106
using System.Threading;
11-
using System.Threading.Tasks;
127
using Windows.Foundation.Metadata;
13-
using Windows.Security.Cryptography.Core;
14-
using Windows.Storage;
15-
using Windows.Storage.FileProperties;
16-
using Windows.Storage.Search;
178
using Windows.UI;
18-
using Windows.UI.Core;
199
using Windows.UI.WindowManagement;
2010
using Windows.UI.Xaml;
2111
using Windows.UI.Xaml.Controls;
22-
using Windows.UI.Xaml.Media;
23-
using Windows.UI.Xaml.Media.Imaging;
2412
using Windows.UI.Xaml.Navigation;
25-
using static Files.Helpers.NativeFindStorageItemHelper;
26-
using FileAttributes = System.IO.FileAttributes;
2713

2814
namespace Files
2915
{
3016
public sealed partial class Properties : Page
3117
{
3218
private static AppWindowTitleBar _TitleBar;
33-
private CancellationTokenSource _tokenSource;
19+
20+
private CancellationTokenSource _tokenSource = new CancellationTokenSource();
3421

3522
public AppWindow propWindow;
23+
3624
public SelectedItemsPropertiesViewModel ViewModel { get; set; }
3725

3826
public Properties()
3927
{
4028
this.InitializeComponent();
4129
}
30+
4231
protected override void OnNavigatedTo(NavigationEventArgs e)
4332
{
4433
ViewModel = new SelectedItemsPropertiesViewModel(e.Parameter as ListedItem);
45-
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
46-
{
47-
Loaded += Properties_Loaded;
48-
}
49-
else
50-
{
51-
this.OKButton.Visibility = Visibility.Collapsed;
52-
}
5334
ViewModel.ItemMD5HashProgress = ItemMD5HashProgress;
5435
ViewModel.Dispatcher = Dispatcher;
5536
App.AppSettings.ThemeModeChanged += AppSettings_ThemeModeChanged;
5637
base.OnNavigatedTo(e);
5738
}
39+
5840
private async void Properties_Loaded(object sender, RoutedEventArgs e)
5941
{
60-
_tokenSource?.Dispose();
61-
_tokenSource = new CancellationTokenSource();
62-
Unloaded += Properties_Unloaded;
6342
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
6443
{
6544
// Collect AppWindow-specific info
@@ -73,6 +52,7 @@ private async void Properties_Loaded(object sender, RoutedEventArgs e)
7352

7453
await ViewModel.GetPropertiesAsync(_tokenSource);
7554
}
55+
7656
private void Properties_Unloaded(object sender, RoutedEventArgs e)
7757
{
7858
if (_tokenSource != null && !_tokenSource.IsCancellationRequested)
@@ -81,8 +61,8 @@ private void Properties_Unloaded(object sender, RoutedEventArgs e)
8161
_tokenSource.Dispose();
8262
_tokenSource = null;
8363
}
84-
Unloaded -= Properties_Unloaded;
8564
}
65+
8666
private void AppSettings_ThemeModeChanged(object sender, EventArgs e)
8767
{
8868
RequestedTheme = ThemeHelper.RootTheme;
@@ -118,9 +98,6 @@ private async void Button_Click(object sender, RoutedEventArgs e)
11898
else
11999
{
120100
App.PropertiesDialogDisplay.Hide();
121-
_tokenSource.Cancel();
122-
_tokenSource.Dispose();
123-
_tokenSource = new CancellationTokenSource();
124101
}
125102
}
126103
}

0 commit comments

Comments
 (0)