コード例 #1
0
        private async void Properties_Loaded(object sender, RoutedEventArgs e)
        {
            _tokenSource?.Dispose();
            _tokenSource = new CancellationTokenSource();
            Unloaded    += Properties_Unloaded;
            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, _tokenSource.Token, ItemMD5HashProgress);

                    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;
            }
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: unixcrh/files-uwp
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            Logger.Info("App activated");

            // Window management
            if (!(Window.Current.Content is Frame rootFrame))
            {
                rootFrame = new Frame();
                Window.Current.Content = rootFrame;
            }

            ThemeHelper.Initialize();
            var currentView = SystemNavigationManager.GetForCurrentView();

            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                var eventArgs = args as ProtocolActivatedEventArgs;

                if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
                {
                    rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
                }
                else
                {
                    var trimmedPath = eventArgs.Uri.OriginalString.Split('=')[1];
                    rootFrame.Navigate(typeof(InstanceTabsView), @trimmedPath, new SuppressNavigationTransitionInfo());
                }
                // Ensure the current window is active.
                Window.Current.Activate();
                Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
                currentView.BackRequested += Window_BackRequested;
                return;

            case ActivationKind.CommandLineLaunch:
                var cmdLineArgs    = args as CommandLineActivatedEventArgs;
                var operation      = cmdLineArgs.Operation;
                var cmdLineString  = operation.Arguments;
                var activationPath = operation.CurrentDirectoryPath;

                var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString);

                if (parsedCommands != null && parsedCommands.Count > 0)
                {
                    foreach (var command in parsedCommands)
                    {
                        switch (command.Type)
                        {
                        case ParsedCommandType.OpenDirectory:
                            rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo());

                            // Ensure the current window is active.
                            Window.Current.Activate();
                            Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
                            currentView.BackRequested += Window_BackRequested;
                            return;

                        case ParsedCommandType.OpenPath:

                            try
                            {
                                var det = await StorageFolder.GetFolderFromPathAsync(command.Payload);

                                rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo());

                                // Ensure the current window is active.
                                Window.Current.Activate();
                                Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
                                currentView.BackRequested += Window_BackRequested;

                                return;
                            }
                            catch (System.IO.FileNotFoundException ex)
                            {
                                //Not a folder
                                Debug.WriteLine($"File not found exception App.xaml.cs\\OnActivated with message: {ex.Message}");
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine($"Exception in App.xaml.cs\\OnActivated with message: {ex.Message}");
                            }

                            break;

                        case ParsedCommandType.Unknown:
                            rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
                            // Ensure the current window is active.
                            Window.Current.Activate();
                            Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
                            currentView.BackRequested += Window_BackRequested;
                            return;
                        }
                    }
                }
                break;
            }

            rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());

            // Ensure the current window is active.
            Window.Current.Activate();
            Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
        }
コード例 #3
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            await logWriter.InitializeAsync("debug.log");

            Logger.Info("App activated");

            await EnsureSettingsAndConfigurationAreBootstrapped();

            // Window management
            if (!(Window.Current.Content is Frame rootFrame))
            {
                rootFrame              = new Frame();
                rootFrame.CacheSize    = 1;
                Window.Current.Content = rootFrame;
            }

            var currentView = SystemNavigationManager.GetForCurrentView();

            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                var eventArgs = args as ProtocolActivatedEventArgs;

                if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
                {
                    rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());
                }
                else
                {
                    var parsedArgs     = eventArgs.Uri.Query.TrimStart('?').Split('=');
                    var unescapedValue = Uri.UnescapeDataString(parsedArgs[1]);
                    switch (parsedArgs[0])
                    {
                    case "tab":
                        rootFrame.Navigate(typeof(MainPage), TabItemArguments.Deserialize(unescapedValue), new SuppressNavigationTransitionInfo());
                        break;

                    case "folder":
                        rootFrame.Navigate(typeof(MainPage), unescapedValue, new SuppressNavigationTransitionInfo());
                        break;
                    }
                }

                // Ensure the current window is active.
                Window.Current.Activate();
                Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                return;

            case ActivationKind.CommandLineLaunch:
                var cmdLineArgs    = args as CommandLineActivatedEventArgs;
                var operation      = cmdLineArgs.Operation;
                var cmdLineString  = operation.Arguments;
                var activationPath = operation.CurrentDirectoryPath;

                var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString);

                if (parsedCommands != null && parsedCommands.Count > 0)
                {
                    foreach (var command in parsedCommands)
                    {
                        switch (command.Type)
                        {
                        case ParsedCommandType.OpenDirectory:
                            rootFrame.Navigate(typeof(MainPage), command.Payload, new SuppressNavigationTransitionInfo());

                            // Ensure the current window is active.
                            Window.Current.Activate();
                            Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                            return;

                        case ParsedCommandType.OpenPath:

                            try
                            {
                                var det = await StorageFolder.GetFolderFromPathAsync(command.Payload);

                                rootFrame.Navigate(typeof(MainPage), command.Payload, new SuppressNavigationTransitionInfo());

                                // Ensure the current window is active.
                                Window.Current.Activate();
                                Window.Current.CoreWindow.Activated += CoreWindow_Activated;

                                return;
                            }
                            catch (System.IO.FileNotFoundException ex)
                            {
                                //Not a folder
                                Debug.WriteLine($"File not found exception App.xaml.cs\\OnActivated with message: {ex.Message}");
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine($"Exception in App.xaml.cs\\OnActivated with message: {ex.Message}");
                            }

                            break;

                        case ParsedCommandType.Unknown:
                            if (command.Payload.Equals("."))
                            {
                                rootFrame.Navigate(typeof(MainPage), activationPath, new SuppressNavigationTransitionInfo());
                            }
                            else
                            {
                                var target = Path.GetFullPath(Path.Combine(activationPath, command.Payload));
                                if (!string.IsNullOrEmpty(command.Payload))
                                {
                                    rootFrame.Navigate(typeof(MainPage), target, new SuppressNavigationTransitionInfo());
                                }
                                else
                                {
                                    rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());
                                }
                            }

                            // Ensure the current window is active.
                            Window.Current.Activate();
                            Window.Current.CoreWindow.Activated += CoreWindow_Activated;

                            return;
                        }
                    }
                }
                break;

            case ActivationKind.ToastNotification:
                var eventArgsForNotification = args as ToastNotificationActivatedEventArgs;
                if (eventArgsForNotification.Argument == "report")
                {
                    // Launch the URI and open log files location
                    //SettingsViewModel.OpenLogLocation();
                    SettingsViewModel.ReportIssueOnGitHub();
                }
                break;
            }

            rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

            // Ensure the current window is active.
            Window.Current.Activate();
            Window.Current.CoreWindow.Activated += CoreWindow_Activated;
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: khserg/files-uwp
        private void NavView_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args)
        {
            var item          = args.InvokedItem;
            var itemContainer = args.InvokedItemContainer;

            //var item = Interaction.FindParent<NavigationViewItemBase>(args.InvokedItem as DependencyObject);
            if (args.IsSettingsInvoked == true)
            {
                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(Settings));
            }
            else
            {
                if (item.ToString() == "Home")
                {
                    ContentFrame.Navigate(typeof(YourHome));
                    auto_suggest.PlaceholderText = "Search Recents";
                }
                else if (item.ToString() == "Desktop")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(GenericFileBrowser), DesktopPath);
                    auto_suggest.PlaceholderText = "Search Desktop";
                }
                else if (item.ToString() == "Documents")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(GenericFileBrowser), DocumentsPath);
                    auto_suggest.PlaceholderText = "Search Documents";
                }
                else if (item.ToString() == "Downloads")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(GenericFileBrowser), DownloadsPath);
                    auto_suggest.PlaceholderText = "Search Downloads";
                }
                else if (item.ToString() == "Pictures")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(PhotoAlbum), PicturesPath);
                    auto_suggest.PlaceholderText = "Search Pictures";
                }
                else if (item.ToString() == "Music")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(GenericFileBrowser), MusicPath);
                    auto_suggest.PlaceholderText = "Search Music";
                }
                else if (item.ToString() == "Videos")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(GenericFileBrowser), VideosPath);
                    auto_suggest.PlaceholderText = "Search Videos";
                }
                else if (item.ToString() == "Local Disk (C:\\)")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(GenericFileBrowser), @"C:\");
                    auto_suggest.PlaceholderText = "Search";
                }
                else if (item.ToString() == "OneDrive")
                {
                    ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                    ContentFrame.Navigate(typeof(GenericFileBrowser), OneDrivePath);
                    auto_suggest.PlaceholderText = "Search OneDrive";
                }
                else
                {
                    var tagOfInvokedItem = (nv.MenuItems[nv.MenuItems.IndexOf(itemContainer)] as Microsoft.UI.Xaml.Controls.NavigationViewItem).Tag;

                    if (StorageFolder.GetFolderFromPathAsync(tagOfInvokedItem.ToString()) != null)
                    {
                        ItemViewModel.TextState.isVisible = Visibility.Collapsed;
                        ContentFrame.Navigate(typeof(GenericFileBrowser), tagOfInvokedItem);
                        auto_suggest.PlaceholderText = "Search " + tagOfInvokedItem;
                    }
                    else
                    {
                    }
                }
            }
        }
コード例 #5
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            await logWriter.InitializeAsync("debug.log");

            Logger.Info($"App activated by {args.Kind.ToString()}");

            await EnsureSettingsAndConfigurationAreBootstrapped();

            var rootFrame = EnsureWindowIsInitialized();

            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                var eventArgs = args as ProtocolActivatedEventArgs;

                if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
                {
                    rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());
                }
                else
                {
                    var parsedArgs     = eventArgs.Uri.Query.TrimStart('?').Split('=');
                    var unescapedValue = Uri.UnescapeDataString(parsedArgs[1]);
                    switch (parsedArgs[0])
                    {
                    case "tab":
                        rootFrame.Navigate(typeof(MainPage), TabItemArguments.Deserialize(unescapedValue), new SuppressNavigationTransitionInfo());
                        break;

                    case "folder":
                        rootFrame.Navigate(typeof(MainPage), unescapedValue, new SuppressNavigationTransitionInfo());
                        break;
                    }
                }

                // Ensure the current window is active.
                Window.Current.Activate();
                Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                return;

            case ActivationKind.CommandLineLaunch:
                var cmdLineArgs    = args as CommandLineActivatedEventArgs;
                var operation      = cmdLineArgs.Operation;
                var cmdLineString  = operation.Arguments;
                var activationPath = operation.CurrentDirectoryPath;

                var parsedCommands = CommandLineParser.ParseUntrustedCommands(cmdLineString);

                if (parsedCommands != null && parsedCommands.Count > 0)
                {
                    async Task PerformNavigation(string payload)
                    {
                        if (!string.IsNullOrEmpty(payload))
                        {
                            payload = CommonPaths.ShellPlaces.Get(payload.ToUpperInvariant(), payload);
                            var folder = (StorageFolder)await FilesystemTasks.Wrap(() => StorageFolder.GetFolderFromPathAsync(payload).AsTask());

                            if (folder != null && !string.IsNullOrEmpty(folder.Path))
                            {
                                payload = folder.Path;     // Convert short name to long name (#6190)
                            }
                        }
                        if (rootFrame.Content != null)
                        {
                            await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), payload);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(MainPage), payload, new SuppressNavigationTransitionInfo());
                        }
                    }

                    foreach (var command in parsedCommands)
                    {
                        switch (command.Type)
                        {
                        case ParsedCommandType.OpenDirectory:
                        case ParsedCommandType.OpenPath:
                        case ParsedCommandType.ExplorerShellCommand:
                            await PerformNavigation(command.Payload);

                            break;

                        case ParsedCommandType.Unknown:
                            if (command.Payload.Equals("."))
                            {
                                await PerformNavigation(activationPath);
                            }
                            else
                            {
                                var target = Path.GetFullPath(Path.Combine(activationPath, command.Payload));
                                if (!string.IsNullOrEmpty(command.Payload))
                                {
                                    await PerformNavigation(target);
                                }
                                else
                                {
                                    await PerformNavigation(null);
                                }
                            }
                            break;

                        case ParsedCommandType.OutputPath:
                            OutputPath = command.Payload;
                            break;
                        }
                    }

                    if (rootFrame.Content != null)
                    {
                        // Ensure the current window is active.
                        Window.Current.Activate();
                        Window.Current.CoreWindow.Activated += CoreWindow_Activated;
                        return;
                    }
                }
                break;

            case ActivationKind.ToastNotification:
                var eventArgsForNotification = args as ToastNotificationActivatedEventArgs;
                if (eventArgsForNotification.Argument == "report")
                {
                    // Launch the URI and open log files location
                    //SettingsViewModel.OpenLogLocation();
                    SettingsViewModel.ReportIssueOnGitHub();
                }
                break;
            }

            rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

            // Ensure the current window is active.
            Window.Current.Activate();
            Window.Current.CoreWindow.Activated += CoreWindow_Activated;
        }
コード例 #6
0
        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();
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: App.xaml.cs プロジェクト: xJavii8/files-uwp
        public async void PopulatePinnedSidebarItems()
        {
            AddDefaultLocations();

            StorageFile   ListFile;
            StorageFolder cacheFolder = ApplicationData.Current.LocalCacheFolder;

            ListFile = await cacheFolder.CreateFileAsync("PinnedItems.txt", CreationCollisionOption.OpenIfExists);

            if (ListFile != null)
            {
                var ListFileLines = await FileIO.ReadLinesAsync(ListFile);

                foreach (string locationPath in ListFileLines)
                {
                    try
                    {
                        StorageFolder fol = await StorageFolder.GetFolderFromPathAsync(locationPath);

                        var name    = fol.DisplayName;
                        var content = name;
                        var icon    = "\uE8B7";

                        bool isDuplicate = false;
                        foreach (SidebarItem sbi in sideBarItems)
                        {
                            if (!string.IsNullOrWhiteSpace(sbi.Path) && !sbi.isDefaultLocation)
                            {
                                if (sbi.Path.ToString() == locationPath)
                                {
                                    isDuplicate = true;
                                }
                            }
                        }

                        if (!isDuplicate)
                        {
                            sideBarItems.Add(new SidebarItem()
                            {
                                isDefaultLocation = false, Text = name, IconGlyph = icon, Path = locationPath
                            });
                        }
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        Debug.WriteLine(e.Message);
                    }
                    catch (FileNotFoundException e)
                    {
                        Debug.WriteLine("Pinned item was deleted and will be removed from the file lines list soon: " + e.Message);
                        LinesToRemoveFromFile.Add(locationPath);
                    }
                    catch (System.Runtime.InteropServices.COMException e)
                    {
                        Debug.WriteLine("Pinned item's drive was ejected and will be removed from the file lines list soon: " + e.Message);
                        LinesToRemoveFromFile.Add(locationPath);
                    }
                }

                RemoveStaleSidebarItems();
            }
        }
コード例 #8
0
ファイル: App.xaml.cs プロジェクト: xJavii8/files-uwp
        private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
        {
            try
            {
                var devices = (await KnownFolders.RemovableDevices.GetFoldersAsync()).OrderBy(x => x.Path);
                foreach (StorageFolder device in devices)
                {
                    var letter = device.Path;
                    if (!foundDrives.Any(x => x.tag == letter))
                    {
                        var    content = device.DisplayName;
                        string icon    = null;
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low,
                                                                                      async() =>
                        {
                            if (content.Contains("DVD"))
                            {
                                icon = "\uE958";
                            }
                            else
                            {
                                icon = "\uE88E";
                            }

                            ulong totalSpaceProg      = 0;
                            ulong freeSpaceProg       = 0;
                            string free_space_text    = "Unknown";
                            string total_space_text   = "Unknown";
                            Visibility capacityBarVis = Visibility.Visible;
                            try
                            {
                                StorageFolder drive    = await StorageFolder.GetFolderFromPathAsync(letter);
                                var retrivedProperties = await drive.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });

                                var sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).GigaBytes;
                                freeSpaceProg      = Convert.ToUInt64(sizeAsGBString);

                                sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).GigaBytes;
                                totalSpaceProg = Convert.ToUInt64(sizeAsGBString);

                                free_space_text  = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).ToString();
                                total_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).ToString();
                            }
                            catch (UnauthorizedAccessException)
                            {
                                capacityBarVis = Visibility.Collapsed;
                            }
                            catch (NullReferenceException)
                            {
                                capacityBarVis = Visibility.Collapsed;
                            }

                            if (!foundDrives.Any(x => x.tag == letter))
                            {
                                foundDrives.Add(new DriveItem()
                                {
                                    driveText             = content,
                                    glyph                 = icon,
                                    maxSpace              = totalSpaceProg,
                                    spaceUsed             = totalSpaceProg - freeSpaceProg,
                                    tag                   = letter,
                                    progressBarVisibility = capacityBarVis,
                                    spaceText             = free_space_text + " free of " + total_space_text,
                                });
                            }
                        });
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                await consentDialog.ShowAsync();
            }
        }
コード例 #9
0
ファイル: App.xaml.cs プロジェクト: xJavii8/files-uwp
        public void PopulateDrivesListWithLocalDisks()
        {
            var driveLetters = DriveInfo.GetDrives().Select(x => x.RootDirectory.Root).ToList().OrderBy(x => x.Root.FullName).ToList();

            driveLetters.ForEach(async roots =>
            {
                try
                {
                    var content = string.Empty;
                    string icon = null;
                    if (!(await KnownFolders.RemovableDevices.GetFoldersAsync()).Select(x => x.Path).ToList().Contains(roots.Name))
                    {
                        // TODO: Display Custom Names for Local Disks as well
                        if (InstanceTabsView.NormalizePath(roots.Name) != InstanceTabsView.NormalizePath("A:") &&
                            InstanceTabsView.NormalizePath(roots.Name) != InstanceTabsView.NormalizePath("B:"))
                        {
                            content = $"Local Disk ({roots.Name.TrimEnd('\\')})";
                            icon    = "\uEDA2";
                        }
                        else
                        {
                            content = $"Floppy Disk ({roots.Name.TrimEnd('\\')})";
                            icon    = "\uE74E";
                        }


                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low,
                                                                                      async() =>
                        {
                            Visibility capacityBarVis = Visibility.Visible;
                            ulong totalSpaceProg      = 0;
                            ulong freeSpaceProg       = 0;
                            string free_space_text    = "Unknown";
                            string total_space_text   = "Unknown";

                            try
                            {
                                StorageFolder drive    = await StorageFolder.GetFolderFromPathAsync(roots.Name);
                                var retrivedProperties = await drive.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });

                                var sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).GigaBytes;
                                freeSpaceProg      = Convert.ToUInt64(sizeAsGBString);

                                sizeAsGBString = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).GigaBytes;
                                totalSpaceProg = Convert.ToUInt64(sizeAsGBString);

                                free_space_text  = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.FreeSpace"]).ToString();
                                total_space_text = ByteSizeLib.ByteSize.FromBytes((ulong)retrivedProperties["System.Capacity"]).ToString();
                            }
                            catch (UnauthorizedAccessException)
                            {
                                capacityBarVis = Visibility.Collapsed;
                            }
                            catch (NullReferenceException)
                            {
                                capacityBarVis = Visibility.Collapsed;
                            }

                            App.foundDrives.Add(new DriveItem()
                            {
                                driveText             = content,
                                glyph                 = icon,
                                maxSpace              = totalSpaceProg,
                                spaceUsed             = totalSpaceProg - freeSpaceProg,
                                tag                   = roots.Name,
                                progressBarVisibility = capacityBarVis,
                                spaceText             = free_space_text + " free of " + total_space_text,
                            });
                        });
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    Debug.WriteLine(e.Message);
                }
            });
        }