示例#1
0
        private static async void ShowInExplorer(string path, StorageItemTypes type)
        {
            var           options = new Windows.System.FolderLauncherOptions();
            StorageFolder folder;

            switch (type)
            {
            case StorageItemTypes.File:
                var file = await StorageFile.GetFileFromPathAsync(path);

                options.ItemsToSelect.Add(file);
                folder = await file.GetParentAsync();

                break;

            case StorageItemTypes.Folder:
                folder = await StorageFolder.GetFolderFromPathAsync(path);

                options.ItemsToSelect.Add(folder);
                break;

            case StorageItemTypes.None:
            default:
                return;
            }
            await Windows.System.Launcher.LaunchFolderAsync(folder, options);
        }
示例#2
0
        private static async Task <string> GenerateUniquePath(string ItemPath, StorageItemTypes Type, IEnumerable <string> ExceptPath)
        {
            string UniquePath = ItemPath;

            switch (Type)
            {
            case StorageItemTypes.File:
            {
                string NameWithoutExt = Path.GetFileNameWithoutExtension(ItemPath);
                string Extension      = Path.GetExtension(ItemPath);
                string Directory      = Path.GetDirectoryName(ItemPath);

                for (ushort Count = 1; await FileSystemStorageItemBase.CheckExistAsync(UniquePath) || ExceptPath.Contains(UniquePath); Count++)
                {
                    if (Regex.IsMatch(NameWithoutExt, @".*\(\d+\)"))
                    {
                        UniquePath = Path.Combine(Directory, $"{NameWithoutExt.Substring(0, NameWithoutExt.LastIndexOf("(", StringComparison.InvariantCultureIgnoreCase))}({Count}){Extension}");
                    }
                    else
                    {
                        UniquePath = Path.Combine(Directory, $"{NameWithoutExt} ({Count}){Extension}");
                    }
                }

                break;
            }

            case StorageItemTypes.Folder:
            {
                string Directory = Path.GetDirectoryName(ItemPath);
                string Name      = Path.GetFileName(ItemPath);

                for (ushort Count = 1; await FileSystemStorageItemBase.CheckExistAsync(UniquePath) || ExceptPath.Contains(UniquePath); Count++)
                {
                    if (Regex.IsMatch(Name, @".*\(\d+\)"))
                    {
                        UniquePath = Path.Combine(Directory, $"{Name.Substring(0, Name.LastIndexOf("(", StringComparison.InvariantCultureIgnoreCase))}({Count})");
                    }
                    else
                    {
                        UniquePath = Path.Combine(Directory, $"{Name} ({Count})");
                    }
                }

                break;
            }

            default:
            {
                break;
            }
            }

            return(UniquePath);
        }
        /// <summary>
        /// 初始化FileSystemStorageItem对象
        /// </summary>
        /// <param name="Data">WIN_Native_API所提供的数据</param>
        /// <param name="StorageType">指示存储类型</param>
        /// <param name="Path">路径</param>
        /// <param name="ModifiedTime">修改时间</param>
        public FileSystemStorageItem(WIN_Native_API.WIN32_FIND_DATA Data, StorageItemTypes StorageType, string Path, DateTimeOffset ModifiedTime)
        {
            InternalPathString = Path;
            ModifiedTimeRaw    = ModifiedTime;
            this.StorageType   = StorageType;

            if (StorageType != StorageItemTypes.Folder)
            {
                SizeRaw = ((ulong)Data.nFileSizeHigh << 32) + Data.nFileSizeLow;
            }
        }
示例#4
0
 public static void ShowInExplorerWithLoader(string path, StorageItemTypes type)
 {
     if (MainPage.Instance == null)
     {
         ShowInExplorer(path, type);
     }
     else
     {
         MainPage.Instance.Loader.ShowIndeterminant("ProcessRequest", false, () => ShowInExplorer(path, type));
     }
 }
        public RecycleStorageItem(string ActualPath, string OriginPath, StorageItemTypes StorageType, DateTimeOffset CreateTime)
        {
            this.OriginPath  = OriginPath;
            this.StorageType = StorageType;

            ModifiedTimeRaw = CreateTime.ToLocalTime();

            if (StorageType == StorageItemTypes.File)
            {
                SizeRaw = WIN_Native_API.CalculateFileSize(ActualPath);
            }

            InternalPathString = ActualPath;
        }
示例#6
0
        private async void RenameDialog_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            DesireNameMap.Clear();

            if (RenameItems.Count() > 1)
            {
                FileSystemStorageItemBase BaseItem = RenameItems.First();

                StorageItemTypes BaseTypes = BaseItem switch
                {
                    FileSystemStorageFile => StorageItemTypes.File,
                    FileSystemStorageFolder => StorageItemTypes.Folder,
                    _ => StorageItemTypes.None
                };

                HashSet <string> ExceptPath  = new HashSet <string>();
                List <string>    StringArray = new List <string>();

                foreach (string Name in RenameItems.Select((Item) => Item.Name))
                {
                    string UniquePath = await GenerateUniquePath(BaseItem.Path, BaseTypes, ExceptPath);

                    ExceptPath.Add(UniquePath);
                    StringArray.Add($"{Name}\r⋙⋙   ⋙⋙   ⋙⋙\r{Path.GetFileName(UniquePath)}");
                    DesireNameMap.Add(Name, Path.GetFileName(UniquePath));
                }

                Preview.Text = string.Join(Environment.NewLine + Environment.NewLine, StringArray);
            }
            else
            {
                string OriginName = RenameItems.First().Name;

                DesireNameMap.Add(OriginName, OriginName);
                Preview.Text = $"{OriginName}\r⋙⋙   ⋙⋙   ⋙⋙\r{OriginName}";
            }

            if (RenameItems.First() is FileSystemStorageFile File)
            {
                if (File.Name != Path.GetExtension(File.Name))
                {
                    RenameText.Select(0, File.Name.Length - Path.GetExtension(File.Name).Length);
                }
            }
            else
            {
                RenameText.SelectAll();
            }
        }
示例#7
0
        /// <summary>
        ///  Determines whether the current IStorageItem matches the specified StorageItemTypes value.
        /// </summary>
        /// <param name="type">The value to match against.</param>
        /// <returns>True if the IStorageItem matches the specified value; otherwise false.</returns>
        public bool IsOfType(StorageItemTypes type)
        {
            if (IsFolder() && type == StorageItemTypes.Folder)
            {
                return(true);
            }

            if (IsFile() && type == StorageItemTypes.File)
            {
                return(true);
            }

            if (IsOneNote() && type == StorageItemTypes.None)
            {
                return(true);
            }

            return(false);
        }
        private bool IsOfTypeInternal(StorageItemTypes type)
        {
            if (_oneDriveStorageItem.IsFolder() && type == StorageItemTypes.Folder)
            {
                return(true);
            }

            if (_oneDriveStorageItem.IsFile() && type == StorageItemTypes.File)
            {
                return(true);
            }

            if (_oneDriveStorageItem.IsOneNote() && type == StorageItemTypes.None)
            {
                return(true);
            }

            return(false);
        }
示例#9
0
        public static MenuFlyoutItem GetShowInExplorerItem(string path, StorageItemTypes type)
        {
            var item = new MenuFlyoutItem()
            {
                Icon = new FontIcon()
                {
                    Glyph = "\uE838"
                },
                Text = Helper.Localize("Show In Explorer")
            };

            item.Click += async(s, args) =>
            {
                if (await Helper.FileNotExist(path))
                {
                    Helper.ShowMusicNotFoundNotification(Music.GetFilename(path));
                    return;
                }
                ShowInExplorerWithLoader(path, type);
            };
            return(item);
        }
示例#10
0
        private async void RenameText_TextChanged(object sender, TextChangedEventArgs e)
        {
            DesireNameMap.Clear();

            if (RenameItems.Count() > 1)
            {
                FileSystemStorageItemBase BaseItem = RenameItems.First();

                StorageItemTypes BaseTypes = BaseItem switch
                {
                    FileSystemStorageFile => StorageItemTypes.File,
                    FileSystemStorageFolder => StorageItemTypes.Folder,
                    _ => StorageItemTypes.None
                };

                HashSet <string> ExceptPath  = new HashSet <string>();
                List <string>    StringArray = new List <string>();

                foreach (string Name in RenameItems.Select((Item) => Item.Name))
                {
                    string UniquePath = await GenerateUniquePath(Path.Combine(Path.GetDirectoryName(BaseItem.Path), RenameText.Text), BaseTypes, ExceptPath);

                    ExceptPath.Add(UniquePath);
                    StringArray.Add($"{Name}\r⋙⋙   ⋙⋙   ⋙⋙\r{Path.GetFileName(UniquePath)}");
                    DesireNameMap.Add(Name, Path.GetFileName(UniquePath));
                }

                Preview.Text = string.Join(Environment.NewLine + Environment.NewLine, StringArray);
            }
            else
            {
                string OriginName = RenameItems.First().Name;

                DesireNameMap.Add(OriginName, RenameText.Text);
                Preview.Text = $"{OriginName}\r⋙⋙   ⋙⋙   ⋙⋙\r{RenameText.Text}";
            }
        }
示例#11
0
 public override bool IsOfType(StorageItemTypes type) => type is StorageItemTypes.File;
 public bool IsOfType(StorageItemTypes type)
 {
     return true;
 }
示例#13
0
 public override bool IsOfType(StorageItemTypes type)
 {
     return(File.IsOfType(type));
 }
示例#14
0
 public abstract bool IsOfType(StorageItemTypes type);
示例#15
0
 public bool IsOfType(StorageItemTypes type) => throw new NotImplementedException();
示例#16
0
 /// <summary>
 /// Indicates whether the current <see cref="StorageFolder"/> matches the specified <see cref="StorageItemTypes"/> value.
 /// </summary>
 /// <param name="type">The enum value that determines the object type to match against.</param>
 /// <returns>True if the <see cref="StorageFolder"/> matches the specified <see cref="StorageItemTypes"/> value; otherwise false.</returns>
 /// <seealso cref="StorageItemTypes"/>
 public bool IsOfType(StorageItemTypes type)
 {
     return type == StorageItemTypes.Folder;
 }
示例#17
0
 /// <inheritdoc />
 public bool IsOfType(StorageItemTypes type)
 {
     return(type == StorageItemTypes.File);
 }
示例#18
0
 public RecycleStorageItem(WIN_Native_API.WIN32_FIND_DATA Data, StorageItemTypes StorageType, string Path, DateTimeOffset ModifiedTime) : base(Data, StorageType, Path, ModifiedTime)
 {
 }
示例#19
0
 public virtual bool IsOfType(StorageItemTypes type)
 => type == StorageItemTypes.None;
示例#20
0
 public bool IsOfType(StorageItemTypes type)
 => type == StorageItemTypes.File;
 public bool IsOfType(StorageItemTypes type)
 {
     return(true);
 }
示例#22
0
        public static async Task <FileSystemStorageItemBase> CreateAsync(string Path, StorageItemTypes ItemTypes, CreateOption Option)
        {
            switch (ItemTypes)
            {
            case StorageItemTypes.File:
            {
                if (WIN_Native_API.CreateFileFromPath(Path, Option, out string NewPath))
                {
                    return(await OpenAsync(NewPath));
                }
                else
                {
                    LogTracer.Log($"Native API could not create file: \"{Path}\", fall back to UWP storage API");

                    try
                    {
                        StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(Path));

                        switch (Option)
                        {
                        case CreateOption.GenerateUniqueName:
                        {
                            StorageFile NewFile = await Folder.CreateFileAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.GenerateUniqueName);

                            return(await CreateFromStorageItemAsync(NewFile));
                        }

                        case CreateOption.OpenIfExist:
                        {
                            StorageFile NewFile = await Folder.CreateFileAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.OpenIfExists);

                            return(await CreateFromStorageItemAsync(NewFile));
                        }

                        case CreateOption.ReplaceExisting:
                        {
                            StorageFile NewFile = await Folder.CreateFileAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.ReplaceExisting);

                            return(await CreateFromStorageItemAsync(NewFile));
                        }

                        default:
                        {
                            return(null);
                        }
                        }
                    }
                    catch
                    {
                        LogTracer.Log($"UWP storage API could not create file: \"{Path}\"");
                        return(null);
                    }
                }
            }

            case StorageItemTypes.Folder:
            {
                if (WIN_Native_API.CreateDirectoryFromPath(Path, Option, out string NewPath))
                {
                    return(await OpenAsync(NewPath));
                }
                else
                {
                    LogTracer.Log($"Native API could not create file: \"{Path}\", fall back to UWP storage API");

                    try
                    {
                        StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(Path));

                        switch (Option)
                        {
                        case CreateOption.GenerateUniqueName:
                        {
                            StorageFolder NewFolder = await Folder.CreateFolderAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.GenerateUniqueName);

                            return(await CreateFromStorageItemAsync(NewFolder));
                        }

                        case CreateOption.OpenIfExist:
                        {
                            StorageFolder NewFolder = await Folder.CreateFolderAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.OpenIfExists);

                            return(await CreateFromStorageItemAsync(NewFolder));
                        }

                        case CreateOption.ReplaceExisting:
                        {
                            StorageFolder NewFolder = await Folder.CreateFolderAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.ReplaceExisting);

                            return(await CreateFromStorageItemAsync(NewFolder));
                        }

                        default:
                        {
                            return(null);
                        }
                        }
                    }
                    catch
                    {
                        LogTracer.Log($"UWP storage API could not create folder: \"{Path}\"");
                        return(null);
                    }
                }
            }

            default:
            {
                return(null);
            }
            }
        }
示例#23
0
 public NetworkItemGroup(StorageItemTypes type)
 {
     this.Type  = type;
     this.Items = new ObservableCollection <NetworkItemInfo>();
 }
示例#24
0
 public bool IsOfType(StorageItemTypes type)
 {
     throw new NotImplementedException();
 }
示例#25
0
 public StorageItemGroup(StorageItemTypes type)
 {
     this.Type  = type;
     this.Items = new ObservableCollection <StorageItemInfo>();
     //this.Name = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView().GetString(type == StorageItemTypes.File ? "List/File/Text" : "List/Folder/Text");
 }
示例#26
0
 /// <summary>
 /// Tokenで取得されたファイルやフォルダ
 /// </summary>
 /// <param name="storageItem"></param>
 /// <param name="thumbnailManager"></param>
 public StorageItemImageSource(IStorageItem storageItem, ThumbnailManager thumbnailManager)
 {
     StorageItem       = storageItem;
     _thumbnailManager = thumbnailManager;
     ItemTypes         = SupportedFileTypesHelper.StorageItemToStorageItemTypes(StorageItem);
 }
示例#27
0
 public StorageItemGroup(StorageItemTypes type, string name)
 {
     this.Type  = type;
     this.Items = new ObservableCollection <StorageItemInfo>();
     this.Name  = name;
 }
示例#28
0
 public override bool IsOfType(StorageItemTypes type) => type == StorageItemTypes.Folder;
 public HiddenStorageItem(WIN_Native_API.WIN32_FIND_DATA Data, StorageItemTypes StorageType, string Path, DateTimeOffset ModifiedTime) : base(Data, StorageType, Path, ModifiedTime)
 {
     SetThumbnailOpacity(ThumbnailStatus.ReduceOpacity);
 }
 public bool IsOfType(StorageItemTypes type)
 {
     throw new System.NotImplementedException();
 }
示例#31
0
        public static async Task <bool?> IsOfType(this string path, StorageItemTypes type)
        {
            IStorageItem item = await path.ToStorageItem() is IStorageItem storageItem ? storageItem : null;

            return(item?.IsOfType(type));
        }