private async void AllView_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e) { var newCellText = (data.SelectedItem as ListedItem)?.FileName; var selectedItem = instanceViewModel.FilesAndFolders[e.Row.GetIndex()]; if (selectedItem.FileType == "Folder") { StorageFolder FolderToRename = await StorageFolder.GetFolderFromPathAsync(selectedItem.FilePath); if (FolderToRename.Name != newCellText) { await FolderToRename.RenameAsync(newCellText); AllView.CommitEdit(); } else { AllView.CancelEdit(); } } else { StorageFile fileToRename = await StorageFile.GetFileFromPathAsync(selectedItem.FilePath); if (fileToRename.Name != newCellText) { await fileToRename.RenameAsync(newCellText); AllView.CommitEdit(); } else { AllView.CancelEdit(); } } //Navigation.NavigationActions.Refresh_Click(null, null); }
public async void PopulateRecentsList() { var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList; BitmapImage ItemImage = new BitmapImage(); string ItemPath = null; string ItemName; StorageItemTypes ItemType; Visibility ItemFolderImgVis; Visibility ItemEmptyImgVis; Visibility ItemFileIconVis; if (mostRecentlyUsed.Entries.Count == 0) { Empty.Visibility = Visibility.Visible; } else { Empty.Visibility = Visibility.Collapsed; } foreach (Windows.Storage.AccessCache.AccessListEntry entry in mostRecentlyUsed.Entries) { string mruToken = entry.Token; try { Windows.Storage.IStorageItem item = await mostRecentlyUsed.GetItemAsync(mruToken); if (item.IsOfType(StorageItemTypes.File)) { ItemName = item.Name; ItemPath = item.Path; ItemType = StorageItemTypes.File; ItemImage = new BitmapImage(); StorageFile file = await StorageFile.GetFileFromPathAsync(ItemPath); var thumbnail = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.ListView, 30, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); if (thumbnail == null) { ItemEmptyImgVis = Visibility.Visible; } else { await ItemImage.SetSourceAsync(thumbnail.CloneStream()); ItemEmptyImgVis = Visibility.Collapsed; } ItemFolderImgVis = Visibility.Collapsed; ItemFileIconVis = Visibility.Visible; recentItemsCollection.Add(new RecentItem() { path = ItemPath, name = ItemName, type = ItemType, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis }); } } catch (System.IO.FileNotFoundException) { mostRecentlyUsed.Remove(mruToken); } catch (UnauthorizedAccessException) { // Skip item until consent is provided } } }
private async void Properties_Loaded(object sender, RoutedEventArgs e) { if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) { // Collect AppWindow-specific info propWindow = Interaction.AppWindows[UIContext]; // Set properties window titleBar style _TitleBar = propWindow.TitleBar; _TitleBar.ButtonBackgroundColor = Colors.Transparent; _TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; App.AppSettings.UpdateThemeElements.Execute(null); } if (App.CurrentInstance.ContentPage.IsItemSelected) { var selectedItem = App.CurrentInstance.ContentPage.SelectedItem; IStorageItem selectedStorageItem = null; if (selectedItem.PrimaryItemAttribute == StorageItemTypes.File) { selectedStorageItem = await StorageFile.GetFileFromPathAsync(selectedItem.ItemPath); ItemProperties.ItemSize = selectedItem.FileSize; } else if (selectedItem.PrimaryItemAttribute == StorageItemTypes.Folder) { var storageFolder = await StorageFolder.GetFolderFromPathAsync(selectedItem.ItemPath); selectedStorageItem = storageFolder; GetFolderSize(storageFolder); } ItemProperties.ItemName = selectedItem.ItemName; ItemProperties.ItemType = selectedItem.ItemType; ItemProperties.ItemPath = selectedItem.ItemPath; ItemProperties.LoadFileIcon = selectedItem.LoadFileIcon; ItemProperties.LoadFolderGlyph = selectedItem.LoadFolderGlyph; ItemProperties.LoadUnknownTypeGlyph = selectedItem.LoadUnknownTypeGlyph; ItemProperties.ItemModifiedTimestamp = selectedItem.ItemDateModified; ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(selectedStorageItem.DateCreated); if (!App.CurrentInstance.ContentPage.SelectedItem.LoadFolderGlyph) { var thumbnail = await(await StorageFile.GetFileFromPathAsync(App.CurrentInstance.ContentPage.SelectedItem.ItemPath)).GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 80, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(thumbnail); ItemProperties.FileIconSource = bitmap; } if (selectedItem.PrimaryItemAttribute == StorageItemTypes.File) { // Get file MD5 hash var hashAlgTypeName = HashAlgorithmNames.Md5; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Visible; ItemProperties.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(selectedItem, hashAlgTypeName); ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashVisibility = Visibility.Visible; } else if (selectedItem.PrimaryItemAttribute == StorageItemTypes.Folder) { ItemProperties.ItemMD5HashVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; } } else { var parentDirectory = App.CurrentInstance.ViewModel.CurrentFolder; if (parentDirectory.ItemPath.StartsWith(App.AppSettings.RecycleBinPath)) { // GetFolderFromPathAsync cannot access recyclebin folder // Currently a fake timestamp is used ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectory.ItemDateModifiedReal); ItemProperties.ItemSize = parentDirectory.FileSize; } else { var parentDirectoryStorageItem = await StorageFolder.GetFolderFromPathAsync(parentDirectory.ItemPath); ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectoryStorageItem.DateCreated); } ItemProperties.ItemName = parentDirectory.ItemName; ItemProperties.ItemType = parentDirectory.ItemType; ItemProperties.ItemPath = parentDirectory.ItemPath; ItemProperties.LoadFileIcon = false; ItemProperties.LoadFolderGlyph = true; ItemProperties.LoadUnknownTypeGlyph = false; ItemProperties.ItemModifiedTimestamp = parentDirectory.ItemDateModified; ItemProperties.ItemMD5HashVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; } }
private async void Properties_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // Collect AppWindow-specific info propWindow = Interaction.AppWindows[this.UIContext]; if (App.CurrentInstance.ContentPage.IsItemSelected) { var selectedItem = App.CurrentInstance.ContentPage.SelectedItem; IStorageItem selectedStorageItem = null; if (selectedItem.PrimaryItemAttribute == StorageItemTypes.File) { selectedStorageItem = await StorageFile.GetFileFromPathAsync(selectedItem.ItemPath); var hashAlgTypeName = HashAlgorithmNames.Md5; // get file hash ItemProperties.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(selectedItem, hashAlgTypeName); ItemProperties.ItemMD5HashVisibility = Visibility.Visible; } else if (selectedItem.PrimaryItemAttribute == StorageItemTypes.Folder) { selectedStorageItem = await StorageFolder.GetFolderFromPathAsync(selectedItem.ItemPath); ItemProperties.ItemMD5HashVisibility = Visibility.Collapsed; } ItemProperties.ItemName = selectedItem.ItemName; ItemProperties.ItemType = selectedItem.ItemType; ItemProperties.ItemPath = selectedItem.ItemPath; ItemProperties.ItemSize = selectedItem.FileSize; ItemProperties.LoadFileIcon = selectedItem.LoadFileIcon; ItemProperties.LoadFolderGlyph = selectedItem.LoadFolderGlyph; ItemProperties.LoadUnknownTypeGlyph = selectedItem.LoadUnknownTypeGlyph; ItemProperties.ItemModifiedTimestamp = selectedItem.ItemDateModified; ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(selectedStorageItem.DateCreated); if (!App.CurrentInstance.ContentPage.SelectedItem.LoadFolderGlyph) { var thumbnail = await(await StorageFile.GetFileFromPathAsync(App.CurrentInstance.ContentPage.SelectedItem.ItemPath)).GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 80, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(thumbnail); ItemProperties.FileIconSource = bitmap; } } else { var parentDirectory = App.CurrentInstance.ViewModel.CurrentFolder; var parentDirectoryStorageItem = await StorageFolder.GetFolderFromPathAsync(parentDirectory.ItemPath); ItemProperties.ItemName = parentDirectory.ItemName; ItemProperties.ItemType = parentDirectory.ItemType; ItemProperties.ItemPath = parentDirectory.ItemPath; ItemProperties.ItemSize = parentDirectory.FileSize; ItemProperties.LoadFileIcon = false; ItemProperties.LoadFolderGlyph = true; ItemProperties.LoadUnknownTypeGlyph = false; ItemProperties.ItemModifiedTimestamp = parentDirectory.ItemDateModified; ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectoryStorageItem.DateCreated); } }
public async void PopulateRecentsList() { recentItemsCollection.Clear(); dataFolder = Windows.Storage.ApplicationData.Current.LocalCacheFolder; RecentsFile = await dataFolder.CreateFileAsync("recents.txt", CreationCollisionOption.OpenIfExists); BitmapImage ItemImage = new BitmapImage(); string ItemPath = null; string ItemName; Visibility ItemFolderImgVis; Visibility ItemEmptyImgVis; Visibility ItemFileIconVis; IList <string> lines = new List <string>(); lines = await FileIO.ReadLinesAsync(RecentsFile); if (lines.Count == 0) { Empty.Visibility = Visibility.Visible; } else if (lines.Count > 10) { try { for (int LineNum = 0; LineNum < 10; LineNum++) { lines.RemoveAt(0); } await FileIO.WriteLinesAsync(RecentsFile, lines); Empty.Visibility = Visibility.Collapsed; lines = await FileIO.ReadLinesAsync(RecentsFile); foreach (string s in lines) { try { var item = await StorageFolder.GetFolderFromPathAsync(s); ItemName = item.DisplayName; ItemPath = item.Path; ItemFolderImgVis = Visibility.Visible; ItemEmptyImgVis = Visibility.Collapsed; ItemFileIconVis = Visibility.Collapsed; if (!recentItemsCollection.Contains(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis })) { recentItemsCollection.Add(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis }); } } catch (System.IO.FileNotFoundException) { IList <string> modifyLines = new List <string>(); modifyLines = lines; modifyLines.Remove(s); await FileIO.WriteLinesAsync(RecentsFile, modifyLines); PopulateRecentsList(); } catch (UnauthorizedAccessException) { Empty.Visibility = Visibility.Visible; } catch (System.ArgumentException) { var item = await StorageFile.GetFileFromPathAsync(s); ItemName = item.DisplayName; ItemPath = item.Path; ItemImage = new BitmapImage(); var thumbnail = await item.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.ListView, 30, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); if (thumbnail == null) { ItemEmptyImgVis = Visibility.Visible; } else { await ItemImage.SetSourceAsync(thumbnail.CloneStream()); ItemEmptyImgVis = Visibility.Collapsed; } ItemFolderImgVis = Visibility.Collapsed; ItemFileIconVis = Visibility.Visible; if (!recentItemsCollection.Contains(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis })) { recentItemsCollection.Add(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis }); } } } } catch (System.IO.FileNotFoundException) { if (ItemPath != null) { RemoveDeletedItemFromList(ItemPath, lines); } else { Debug.WriteLine("Attempted to delete redundant RecentItem from file when ItemPath was never set."); } } } else { try { Empty.Visibility = Visibility.Collapsed; foreach (string s in lines) { try { ItemPath = s; var item = await StorageFolder.GetFolderFromPathAsync(s); ItemName = item.DisplayName; ItemPath = item.Path; ItemFolderImgVis = Visibility.Visible; ItemEmptyImgVis = Visibility.Collapsed; ItemFileIconVis = Visibility.Collapsed; if (!recentItemsCollection.Contains(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis })) { recentItemsCollection.Add(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis }); } } catch (UnauthorizedAccessException) { Empty.Visibility = Visibility.Visible; } catch (System.ArgumentException) { var item = await StorageFile.GetFileFromPathAsync(s); ItemName = item.DisplayName; ItemPath = item.Path; ItemImage = new BitmapImage(); var thumbnail = await item.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.ListView, 30, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); if (thumbnail == null) { ItemEmptyImgVis = Visibility.Visible; } else { await ItemImage.SetSourceAsync(thumbnail.CloneStream()); ItemEmptyImgVis = Visibility.Collapsed; } ItemFolderImgVis = Visibility.Collapsed; ItemFileIconVis = Visibility.Visible; if (!recentItemsCollection.Contains(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis })) { recentItemsCollection.Add(new RecentItem() { path = ItemPath, name = ItemName, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis }); } } } } catch (System.IO.FileNotFoundException) { if (ItemPath != null) { RemoveDeletedItemFromList(ItemPath, lines); } else { Debug.WriteLine("Attempted to delete redundant RecentItem from file when ItemPath was never set."); } } } }
public async void PopulateRecentsList() { var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList; BitmapImage ItemImage; string ItemPath; string ItemName; StorageItemTypes ItemType; Visibility ItemFolderImgVis; Visibility ItemEmptyImgVis; Visibility ItemFileIconVis; bool IsRecentsListEmpty = true; foreach (var entry in mostRecentlyUsed.Entries) { try { var item = await mostRecentlyUsed.GetItemAsync(entry.Token); if (item.IsOfType(StorageItemTypes.File)) { IsRecentsListEmpty = false; } } catch (Exception) { } } if (IsRecentsListEmpty) { Empty.Visibility = Visibility.Visible; } else { Empty.Visibility = Visibility.Collapsed; } foreach (Windows.Storage.AccessCache.AccessListEntry entry in mostRecentlyUsed.Entries) { string mruToken = entry.Token; try { IStorageItem item = await mostRecentlyUsed.GetItemAsync(mruToken); if (item.IsOfType(StorageItemTypes.File)) { ItemName = item.Name; ItemPath = item.Path; ItemType = StorageItemTypes.File; ItemImage = new BitmapImage(); StorageFile file = await StorageFile.GetFileFromPathAsync(ItemPath); var thumbnail = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 30, Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale); if (thumbnail == null) { ItemEmptyImgVis = Visibility.Visible; } else { await ItemImage.SetSourceAsync(thumbnail.CloneStream()); ItemEmptyImgVis = Visibility.Collapsed; } ItemFolderImgVis = Visibility.Collapsed; ItemFileIconVis = Visibility.Visible; recentItemsCollection.Add(new RecentItem() { RecentPath = ItemPath, Name = ItemName, Type = ItemType, FolderImg = ItemFolderImgVis, EmptyImgVis = ItemEmptyImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis }); } } catch (FileNotFoundException) { mostRecentlyUsed.Remove(mruToken); } catch (UnauthorizedAccessException) { // Skip item until consent is provided } catch (COMException ex) { mostRecentlyUsed.Remove(mruToken); System.Diagnostics.Debug.WriteLine(ex); } } if (recentItemsCollection.Count == 0) { Empty.Visibility = Visibility.Visible; } }
private async void VisiblePath_TextChanged(object sender, KeyRoutedEventArgs e) { if (e.Key == VirtualKey.Enter) { var PathBox = (sender as TextBox); var CurrentInput = PathBox.Text; if (CurrentInput != App.ViewModel.Universal.path) { App.ViewModel.CancelLoadAndClearFiles(); if (CurrentInput == "Home" || CurrentInput == "home") { MainPage.accessibleContentFrame.Navigate(typeof(YourHome)); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Recents"; } else if (CurrentInput == "Desktop" || CurrentInput == "desktop") { App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.DesktopPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Desktop"; App.PathText.Text = "Desktop"; } else if (CurrentInput == "Documents" || CurrentInput == "documents") { App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.DocumentsPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Documents"; App.PathText.Text = "Documents"; } else if (CurrentInput == "Downloads" || CurrentInput == "downloads") { App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.DownloadsPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Downloads"; App.PathText.Text = "Downloads"; } else if (CurrentInput == "Pictures" || CurrentInput == "pictures") { App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(PhotoAlbum), MainPage.PicturesPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Pictures"; App.PathText.Text = "Pictures"; } else if (CurrentInput == "Music" || CurrentInput == "music") { App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.MusicPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Music"; App.PathText.Text = "Music"; } else if (CurrentInput == "Videos" || CurrentInput == "videos") { App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.VideosPath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search Videos"; App.PathText.Text = "Videos"; } else if (CurrentInput == "OneDrive" || CurrentInput == "Onedrive" || CurrentInput == "onedrive") { App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), MainPage.OneDrivePath); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search OneDrive"; App.PathText.Text = "OneDrive"; } else { if (CurrentInput.Contains(".")) { if (CurrentInput.Contains(".exe") || CurrentInput.Contains(".EXE")) { if (StorageFile.GetFileFromPathAsync(CurrentInput) != null) { await Interaction.LaunchExe(CurrentInput); PathBox.Text = App.ViewModel.Universal.path; } else { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } } else if (StorageFolder.GetFolderFromPathAsync(CurrentInput) != null) { await StorageFolder.GetFolderFromPathAsync(CurrentInput); App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), CurrentInput); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search"; } else { try { await StorageFile.GetFileFromPathAsync(CurrentInput); StorageFile file = await StorageFile.GetFileFromPathAsync(CurrentInput); var options = new LauncherOptions { DisplayApplicationPicker = false }; await Launcher.LaunchFileAsync(file, options); PathBox.Text = App.ViewModel.Universal.path; } catch (ArgumentException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } catch (FileNotFoundException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } } } else { try { await StorageFolder.GetFolderFromPathAsync(CurrentInput); App.ViewModel.TextState.isVisible = Visibility.Collapsed; MainPage.accessibleContentFrame.Navigate(typeof(GenericFileBrowser), CurrentInput); MainPage.accessibleAutoSuggestBox.PlaceholderText = "Search"; } catch (ArgumentException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } catch (FileNotFoundException) { MessageDialog dialog = new MessageDialog("The path typed was not correct. Please try again.", "Invalid Path"); await dialog.ShowAsync(); } } } } } }