コード例 #1
0
ファイル: WIN_Native_API.cs プロジェクト: webgzf/RX-Explorer
        public static bool CheckContainsAnyItem(string Path, ItemFilters Filter)
        {
            if (string.IsNullOrWhiteSpace(Path))
            {
                throw new ArgumentException("Argument could not be empty", nameof(Path));
            }

            IntPtr Ptr = FindFirstFileExFromApp(System.IO.Path.Combine(Path, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

            try
            {
                if (Ptr.ToInt64() != -1)
                {
                    do
                    {
                        FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                        if (!Attribute.HasFlag(FileAttributes.System))
                        {
                            if (Attribute.HasFlag(FileAttributes.Directory) && Filter.HasFlag(ItemFilters.Folder))
                            {
                                if (Data.cFileName != "." && Data.cFileName != "..")
                                {
                                    return(true);
                                }
                            }
                            else if (Filter.HasFlag(ItemFilters.File) && !Data.cFileName.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                            {
                                return(true);
                            }
                        }
                    }while (FindNextFile(Ptr, out Data));

                    return(false);
                }
                else
                {
                    LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()));
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
            finally
            {
                FindClose(Ptr);
            }
        }
コード例 #2
0
 public bool IsFolder(string path)
 {
     System.IO.FileAttributes attr = File.GetAttributes(path);
     if (attr.HasFlag(FileAttributes.Directory))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #3
0
ファイル: WIN_Native_API.cs プロジェクト: webgzf/RX-Explorer
        public static List <string> GetStorageItemsPath(string Path, bool IncludeHiddenItem, ItemFilters Filter)
        {
            if (string.IsNullOrWhiteSpace(Path))
            {
                throw new ArgumentNullException(nameof(Path), "Argument could not be null");
            }

            IntPtr Ptr = FindFirstFileExFromApp(System.IO.Path.Combine(Path, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

            try
            {
                if (Ptr.ToInt64() != -1)
                {
                    List <string> Result = new List <string>();

                    do
                    {
                        FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                        if (IncludeHiddenItem || !Attribute.HasFlag(FileAttributes.Hidden))
                        {
                            if (((FileAttributes)Data.dwFileAttributes).HasFlag(FileAttributes.Directory) && Filter.HasFlag(ItemFilters.Folder))
                            {
                                if (Data.cFileName != "." && Data.cFileName != "..")
                                {
                                    Result.Add(System.IO.Path.Combine(Path, Data.cFileName));
                                }
                            }
                            else if (Filter.HasFlag(ItemFilters.File))
                            {
                                Result.Add(System.IO.Path.Combine(Path, Data.cFileName));
                            }
                        }
                    }while (FindNextFile(Ptr, out Data));

                    return(Result);
                }
                else
                {
                    LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()));
                    return(new List <string>());
                }
            }
            catch
            {
                return(new List <string>());
            }
            finally
            {
                FindClose(Ptr);
            }
        }
コード例 #4
0
        public static PhotoBook CreateNew(string projectDirPath)
        {
            if (!Directory.Exists(projectDirPath))
            {
                Directory.CreateDirectory(projectDirPath);
            }
            else
            {
                System.IO.FileAttributes attr = File.GetAttributes(projectDirPath);
                var extension = Path.GetExtension(projectDirPath);

                if (!attr.HasFlag(FileAttributes.Directory))
                {
                    throw new Exception("The given path for photobook location isn't a directory");
                }
                if (extension != string.Empty)
                {
                    throw new Exception("File location provided when creating a new PhotoBook object");
                }
            }

            PhotoBook photoBook = new PhotoBook();

            photoBook.SaveDirectory = Path.GetFullPath(projectDirPath);
            Directory.SetCurrentDirectory(projectDirPath);

            photoBook.FrontCover.Title = "Moja fotoksiążka";

            var(left, right) = photoBook.CreateNewPages();

            left.Layout = photoBook.AvailableLayouts[Layout.Type.TwoPictures];
            left.SetComment(0, "Opis");
            left.SetComment(1, "Opis");

            right.Layout = photoBook.AvailableLayouts[Layout.Type.OnePicture];
            right.SetComment(0, "Opis");

            return(photoBook);
        }
コード例 #5
0
 private static async Task <BitmapImage> GetFileThumbnail(string filepath)
 {
     try
     {
         StorageItemThumbnail thumbnail;
         FileAttributes       attr = File.GetAttributes(@filepath);
         if (attr.HasFlag(FileAttributes.Directory))
         {
             StorageFolder folder = StorageFolder.GetFolderFromPathAsync(@filepath).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
             thumbnail = await folder.GetThumbnailAsync(ThumbnailMode.SingleItem, 150).AsTask().ConfigureAwait(false);
         }
         else
         {
             StorageFile file = StorageFile.GetFileFromPathAsync(@filepath).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
             thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 150).AsTask().ConfigureAwait(false);
         }
         BitmapImage image = new BitmapImage();
         using (Stream stream = thumbnail.AsStreamForRead())
         {
             image.BeginInit();
             image.StreamSource = stream;
             image.CacheOption  = BitmapCacheOption.OnLoad;
             image.EndInit();
             image.Freeze();
         }
         return(image);
     }
     catch (UnauthorizedAccessException)
     {
         Console.WriteLine("invalid permission on " + filepath);
         return(Images.UNAUTHORIZED);
     }
     catch (FileNotFoundException)
     {
         Console.WriteLine("file not found: " + filepath);
         return(Images.MISSING);
     }
 }
コード例 #6
0
ファイル: WIN_Native_API.cs プロジェクト: webgzf/RX-Explorer
        public static List <FileSystemStorageItemBase> GetStorageItems(StorageFolder Folder, bool IncludeHiddenItem, ItemFilters Filter)
        {
            if (Folder == null)
            {
                throw new ArgumentNullException(nameof(Folder), "Argument could not be null");
            }

            IntPtr Ptr = FindFirstFileExFromApp(Path.Combine(Folder.Path, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

            try
            {
                if (Ptr.ToInt64() != -1)
                {
                    List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>();

                    do
                    {
                        FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                        if (IncludeHiddenItem || !Attribute.HasFlag(FileAttributes.Hidden))
                        {
                            if (Attribute.HasFlag(FileAttributes.Directory) && Filter.HasFlag(ItemFilters.Folder))
                            {
                                if (Data.cFileName != "." && Data.cFileName != "..")
                                {
                                    FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                    DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                    if (Attribute.HasFlag(FileAttributes.Hidden))
                                    {
                                        Result.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime));
                                    }
                                    else
                                    {
                                        Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime));
                                    }
                                }
                            }
                            else if (Filter.HasFlag(ItemFilters.File))
                            {
                                FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                if (Attribute.HasFlag(FileAttributes.Hidden))
                                {
                                    Result.Add(new HiddenStorageItem(Data, StorageItemTypes.File, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime));
                                }
                                else
                                {
                                    if (!Data.cFileName.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (Data.cFileName.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
                                        {
                                            Result.Add(new HyperlinkStorageItem(Data, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime));
                                        }
                                        else
                                        {
                                            Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime));
                                        }
                                    }
                                }
                            }
                        }
                    }while (FindNextFile(Ptr, out Data));

                    return(Result);
                }
                else
                {
                    LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()));
                    return(new List <FileSystemStorageItemBase>());
                }
            }
            catch
            {
                return(new List <FileSystemStorageItemBase>());
            }
            finally
            {
                FindClose(Ptr);
            }
        }
コード例 #7
0
ファイル: WIN_Native_API.cs プロジェクト: webgzf/RX-Explorer
        public static List <FileSystemStorageItemBase> GetStorageItems(params string[] PathArray)
        {
            if (PathArray.Length == 0 || PathArray.Any((Item) => string.IsNullOrWhiteSpace(Item)))
            {
                throw new ArgumentException("Argument could not be empty", nameof(PathArray));
            }

            if (PathArray.Any((Item) => Path.GetPathRoot(Item) == Item))
            {
                throw new ArgumentException("Unsupport for root directory", nameof(PathArray));
            }

            try
            {
                List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>(PathArray.Length);

                foreach (string Path in PathArray)
                {
                    IntPtr Ptr = FindFirstFileExFromApp(Path, FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

                    try
                    {
                        if (Ptr.ToInt64() != -1)
                        {
                            FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                            if (Attribute.HasFlag(FileAttributes.Directory))
                            {
                                if (Data.cFileName != "." && Data.cFileName != "..")
                                {
                                    FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                    DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                    if (Attribute.HasFlag(FileAttributes.Hidden))
                                    {
                                        Result.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, Path, ModifiedTime));
                                    }
                                    else
                                    {
                                        Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, Path, ModifiedTime));
                                    }
                                }
                            }
                            else
                            {
                                FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                if (Attribute.HasFlag(FileAttributes.Hidden))
                                {
                                    Result.Add(new HiddenStorageItem(Data, StorageItemTypes.File, Path, ModifiedTime));
                                }
                                else
                                {
                                    if (!Data.cFileName.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (Data.cFileName.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
                                        {
                                            Result.Add(new HyperlinkStorageItem(Data, Path, ModifiedTime));
                                        }
                                        else
                                        {
                                            Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, Path, ModifiedTime));
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()));
                        }
                    }
                    finally
                    {
                        FindClose(Ptr);
                    }
                }

                return(Result);
            }
            catch
            {
                return(new List <FileSystemStorageItemBase>());
            }
        }
コード例 #8
0
ファイル: WIN_Native_API.cs プロジェクト: webgzf/RX-Explorer
        public static List <FileSystemStorageItemBase> Search(string FolderPath, string TargetName, bool SearchInSubFolders = false, bool IncludeHiddenItem = false, CancellationToken CancelToken = default)
        {
            if (string.IsNullOrWhiteSpace(FolderPath))
            {
                throw new ArgumentException("Argument could not be empty", nameof(FolderPath));
            }

            if (string.IsNullOrEmpty(TargetName))
            {
                throw new ArgumentException("Argument could not be empty", nameof(TargetName));
            }

            IntPtr Ptr = FindFirstFileExFromApp(Path.Combine(FolderPath, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH);

            List <FileSystemStorageItemBase> SearchResult = new List <FileSystemStorageItemBase>();

            try
            {
                if (Ptr.ToInt64() != -1)
                {
                    do
                    {
                        FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes;

                        if (IncludeHiddenItem || !Attribute.HasFlag(FileAttributes.Hidden))
                        {
                            if (Attribute.HasFlag(FileAttributes.Directory))
                            {
                                if (Data.cFileName != "." && Data.cFileName != "..")
                                {
                                    string CurrentDataPath = Path.Combine(FolderPath, Data.cFileName);

                                    if (Regex.IsMatch(Data.cFileName, @$ ".*{TargetName}.*", RegexOptions.IgnoreCase))
                                    {
                                        FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                        DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                        if (Attribute.HasFlag(FileAttributes.Hidden))
                                        {
                                            SearchResult.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, CurrentDataPath, ModifiedTime));
                                        }
                                        else
                                        {
                                            SearchResult.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, CurrentDataPath, ModifiedTime));
                                        }
                                    }

                                    if (SearchInSubFolders)
                                    {
                                        SearchResult.AddRange(Search(CurrentDataPath, TargetName, true, IncludeHiddenItem, CancelToken));
                                    }
                                }
                            }
                            else
                            {
                                if (Regex.IsMatch(Data.cFileName, @$ ".*{TargetName}.*", RegexOptions.IgnoreCase))
                                {
                                    string CurrentDataPath = Path.Combine(FolderPath, Data.cFileName);

                                    FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime);
                                    DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc);

                                    if (Attribute.HasFlag(FileAttributes.Hidden))
                                    {
                                        SearchResult.Add(new HiddenStorageItem(Data, StorageItemTypes.File, CurrentDataPath, ModifiedTime));
                                    }
                                    else
                                    {
                                        if (!Data.cFileName.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                                        {
                                            if (Data.cFileName.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
                                            {
                                                SearchResult.Add(new HyperlinkStorageItem(Data, CurrentDataPath, ModifiedTime));
                                            }
                                            else
                                            {
                                                SearchResult.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, CurrentDataPath, ModifiedTime));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }while (FindNextFile(Ptr, out Data) && !CancelToken.IsCancellationRequested);

                    return(SearchResult);
                }
                else
                {
                    return(SearchResult);
                }
            }
            catch
            {
                return(SearchResult);
            }
            finally
            {
                FindClose(Ptr);
            }
        }