コード例 #1
0
ファイル: FileProperties.cs プロジェクト: CrackerCat/Files-1
        public override void GetBaseProperties()
        {
            base.GetBaseProperties();

            if (Item != null)
            {
                ViewModel.ItemName         = Item.ItemName;
                ViewModel.OriginalItemName = Item.ItemName;
                ViewModel.ItemType         = Item.ItemType;
                ViewModel.ItemPath         = (Item as RecycleBinItem)?.ItemOriginalFolder ??
                                             (Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath);
                ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;
                ViewModel.ItemCreatedTimestamp  = Item.ItemDateCreated;
                ViewModel.LoadFolderGlyph       = Item.LoadFolderGlyph;
                ViewModel.IconData             = Item.CustomIconData;
                ViewModel.LoadUnknownTypeGlyph = Item.LoadUnknownTypeGlyph;
                ViewModel.LoadCustomIcon       = Item.LoadCustomIcon;
                ViewModel.CustomIconSource     = Item.CustomIconSource;
                ViewModel.LoadFileIcon         = Item.LoadFileIcon;

                if (Item.IsShortcutItem)
                {
                    var shortcutItem = (ShortcutItem)Item;

                    var isApplication = !string.IsNullOrWhiteSpace(shortcutItem.TargetPath) &&
                                        (shortcutItem.TargetPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ||
                                         shortcutItem.TargetPath.EndsWith(".msi", StringComparison.OrdinalIgnoreCase) ||
                                         shortcutItem.TargetPath.EndsWith(".bat", StringComparison.OrdinalIgnoreCase));

                    ViewModel.ShortcutItemType = isApplication ? "PropertiesShortcutTypeApplication".GetLocalized() :
                                                 Item.IsLinkItem ? "PropertiesShortcutTypeLink".GetLocalized() : "PropertiesShortcutTypeFile".GetLocalized();
                    ViewModel.ShortcutItemPath                 = shortcutItem.TargetPath;
                    ViewModel.ShortcutItemWorkingDir           = shortcutItem.WorkingDirectory;
                    ViewModel.ShortcutItemWorkingDirVisibility = Item.IsLinkItem ? Visibility.Collapsed : Visibility.Visible;
                    ViewModel.ShortcutItemArguments            = shortcutItem.Arguments;
                    ViewModel.ShortcutItemArgumentsVisibility  = Item.IsLinkItem ? Visibility.Collapsed : Visibility.Visible;
                    ViewModel.IsSelectedItemShortcut           = Item.FileExtension.Equals(".lnk", StringComparison.OrdinalIgnoreCase);
                    ViewModel.ShortcutItemOpenLinkCommand      = new RelayCommand(async() =>
                    {
                        if (Item.IsLinkItem)
                        {
                            var tmpItem = (ShortcutItem)Item;
                            await Win32Helpers.InvokeWin32ComponentAsync(ViewModel.ShortcutItemPath, AppInstance, ViewModel.ShortcutItemArguments, tmpItem.RunAsAdmin, ViewModel.ShortcutItemWorkingDir);
                        }
                        else
                        {
                            var folderUri = new Uri($"files-uwp:?folder={Path.GetDirectoryName(ViewModel.ShortcutItemPath)}");
                            await Windows.System.Launcher.LaunchUriAsync(folderUri);
                        }
                    }, () =>
                    {
                        return(!string.IsNullOrWhiteSpace(ViewModel.ShortcutItemPath));
                    });
                }
            }
        }
コード例 #2
0
ファイル: FileProperties.cs プロジェクト: d2dyno1/Files
        public override void GetBaseProperties()
        {
            if (Item != null)
            {
                ViewModel.ItemName         = Item.ItemName;
                ViewModel.OriginalItemName = Item.ItemName;
                ViewModel.ItemType         = Item.ItemType;
                ViewModel.ItemPath         = (Item as RecycleBinItem)?.ItemOriginalFolder ??
                                             (Path.IsPathRooted(Item.ItemPath) ? Path.GetDirectoryName(Item.ItemPath) : Item.ItemPath);
                ViewModel.ItemModifiedTimestamp = Item.ItemDateModified;
                ViewModel.ItemCreatedTimestamp  = Item.ItemDateCreated;
                ViewModel.LoadCustomIcon        = Item.LoadCustomIcon;
                ViewModel.CustomIconSource      = Item.CustomIconSource;
                ViewModel.LoadFileIcon          = Item.LoadFileIcon;

                if (Item.IsShortcutItem)
                {
                    var shortcutItem = (ShortcutItem)Item;

                    var isApplication = !string.IsNullOrWhiteSpace(shortcutItem.TargetPath) &&
                                        (shortcutItem.TargetPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ||
                                         shortcutItem.TargetPath.EndsWith(".msi", StringComparison.OrdinalIgnoreCase) ||
                                         shortcutItem.TargetPath.EndsWith(".bat", StringComparison.OrdinalIgnoreCase));

                    ViewModel.ShortcutItemType = isApplication ? "Application".GetLocalized() :
                                                 Item.IsLinkItem ? "PropertiesShortcutTypeLink".GetLocalized() : "PropertiesShortcutTypeFile".GetLocalized();
                    ViewModel.ShortcutItemPath                 = shortcutItem.TargetPath;
                    ViewModel.IsShortcutItemPathReadOnly       = shortcutItem.IsSymLink;
                    ViewModel.ShortcutItemWorkingDir           = shortcutItem.WorkingDirectory;
                    ViewModel.ShortcutItemWorkingDirVisibility = Item.IsLinkItem || shortcutItem.IsSymLink ? false : true;
                    ViewModel.ShortcutItemArguments            = shortcutItem.Arguments;
                    ViewModel.ShortcutItemArgumentsVisibility  = Item.IsLinkItem || shortcutItem.IsSymLink ? false : true;
                    ViewModel.IsSelectedItemShortcut           = ".lnk".Equals(Item.FileExtension, StringComparison.OrdinalIgnoreCase);
                    ViewModel.ShortcutItemOpenLinkCommand      = new RelayCommand(async() =>
                    {
                        if (Item.IsLinkItem)
                        {
                            var tmpItem = (ShortcutItem)Item;
                            await Win32Helpers.InvokeWin32ComponentAsync(ViewModel.ShortcutItemPath, AppInstance, ViewModel.ShortcutItemArguments, tmpItem.RunAsAdmin, ViewModel.ShortcutItemWorkingDir);
                        }
                        else
                        {
                            await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(
                                () => NavigationHelpers.OpenPathInNewTab(Path.GetDirectoryName(ViewModel.ShortcutItemPath)));
                        }
                    }, () =>
                    {
                        return(!string.IsNullOrWhiteSpace(ViewModel.ShortcutItemPath));
                    });
                }
            }
        }
コード例 #3
0
 private async void RecentFilesWidget_RecentFileInvoked(object sender, UserControls.PathNavigationEventArgs e)
 {
     try
     {
         var directoryName = Path.GetDirectoryName(e.ItemPath);
         await Win32Helpers.InvokeWin32ComponentAsync(e.ItemPath, AppInstance, workingDirectory : directoryName);
     }
     catch (UnauthorizedAccessException)
     {
         DynamicDialog dialog = DynamicDialogFactory.GetFor_ConsentDialog();
         await dialog.ShowAsync();
     }
     catch (ArgumentException)
     {
         if (new DirectoryInfo(e.ItemPath).Root.ToString().Contains(@"C:\"))
         {
             AppInstance.NavigateWithArguments(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments()
             {
                 NavPathParam = e.ItemPath
             });
         }
         else
         {
             foreach (DriveItem drive in Enumerable.Concat(App.DrivesManager.Drives, AppSettings.CloudDrivesManager.Drives))
             {
                 if (drive.Path.ToString() == new DirectoryInfo(e.ItemPath).Root.ToString())
                 {
                     AppInstance.NavigateWithArguments(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments()
                     {
                         NavPathParam = e.ItemPath
                     });
                     return;
                 }
             }
         }
     }
     catch (COMException)
     {
         await DialogDisplayHelper.ShowDialogAsync(
             "DriveUnpluggedDialog/Title".GetLocalized(),
             "DriveUnpluggedDialog/Text".GetLocalized());
     }
 }