ImgMetadataRemover/WindowsApplication/MainWindow.xaml.cs

62 lines
2.3 KiB
C#
Raw Normal View History

2022-02-04 19:21:27 +00:00
using Microsoft.UI.Xaml;
using System;
2022-01-31 19:30:11 +00:00
using System.Collections.Generic;
2022-02-04 19:21:27 +00:00
using System.Runtime.InteropServices;
2022-01-31 19:30:11 +00:00
2022-02-04 19:21:27 +00:00
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
2022-01-31 19:30:11 +00:00
2022-02-04 19:21:27 +00:00
namespace WindowsApplication
2022-01-31 19:30:11 +00:00
{
/// <summary>
2022-02-04 19:21:27 +00:00
/// An empty window that can be used on its own or navigated to within a Frame.
2022-01-31 19:30:11 +00:00
/// </summary>
2022-02-04 19:21:27 +00:00
public sealed partial class MainWindow : Window
2022-01-31 19:30:11 +00:00
{
2022-02-04 19:21:27 +00:00
public MainWindow()
2022-01-31 19:30:11 +00:00
{
this.InitializeComponent();
2022-02-04 19:21:27 +00:00
UpdateNumberOfFilesText(0);
}
2022-02-04 19:21:27 +00:00
private async void PickFilesButton_Click(object sender, RoutedEventArgs e)
{
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
2022-02-04 19:21:27 +00:00
// Get the current window's HWND by passing in the Window object
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
// Associate the HWND with the file picker
WinRT.Interop.InitializeWithWindow.Initialize(folderPicker, hwnd);
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
folderPicker.FileTypeFilter.Add("*");
Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
// Application now has read/write access to all contents in the picked folder
// (including other sub-folder contents)
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
List<string> fileNames = new List<string>();
var folderItems = await folder.GetItemsAsync();
foreach (var item in folderItems)
{
if (item.Attributes == Windows.Storage.FileAttributes.Archive || item.Attributes == Windows.Storage.FileAttributes.Normal)
{
fileNames.Add(item.Name);
}
}
FilesListView.ItemsSource = fileNames;
2022-02-04 19:21:27 +00:00
UpdateNumberOfFilesText(fileNames.Count);
}
2022-01-31 19:30:11 +00:00
}
2022-02-04 19:21:27 +00:00
private void UpdateNumberOfFilesText(int nrOfFiles)
{
NumberOfFiles.Text = $"Total files {nrOfFiles}.";
}
2022-01-31 19:30:11 +00:00
}
}