Object describing a file
Inheritance: _3PA.MainFeatures.FilteredLists.FilteredItem
Exemple #1
0
        /// <summary>
        /// Event on format cell
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private static void FastOlvOnFormatCell(object sender, FormatCellEventArgs args)
        {
            FileListItem obj = (FileListItem)args.Model;

            if (obj == null)
            {
                return;
            }

            // currently document
            if (obj.FullPath.Equals(Plug.CurrentFilePath))
            {
                RowBorderDecoration rbd = new RowBorderDecoration {
                    FillBrush      = new SolidBrush(Color.FromArgb(50, ThemeManager.Current.MenuFocusedBack)),
                    BorderPen      = new Pen(Color.FromArgb(128, ThemeManager.Current.MenuFocusedBack.IsColorDark() ? ControlPaint.Light(ThemeManager.Current.MenuFocusedBack, 0.10f) : ControlPaint.Dark(ThemeManager.Current.MenuFocusedBack, 0.10f)), 1),
                    BoundsPadding  = new Size(-2, 0),
                    CornerRounding = 6.0f
                };
                args.SubItem.Decoration = rbd;
            }

            // display the flags
            int offset = -5;

            foreach (var name in Enum.GetNames(typeof(FileFlag)))
            {
                FileFlag flag = (FileFlag)Enum.Parse(typeof(FileFlag), name);
                if (flag == 0)
                {
                    continue;
                }
                if (!obj.Flags.HasFlag(flag))
                {
                    continue;
                }
                Image tryImg = (Image)ImageResources.ResourceManager.GetObject(name);
                if (tryImg == null)
                {
                    continue;
                }
                ImageDecoration decoration = new ImageDecoration(tryImg, 100, ContentAlignment.MiddleRight)
                {
                    Offset = new Size(offset, 0)
                };
                if (args.SubItem.Decoration == null)
                {
                    args.SubItem.Decoration = decoration;
                }
                else
                {
                    args.SubItem.Decorations.Add(decoration);
                }
                offset -= 20;
            }

            // display the sub string
            if (offset < -5)
            {
                offset -= 5;
            }
            if (!string.IsNullOrEmpty(obj.SubString))
            {
                TextDecoration decoration = new TextDecoration(obj.SubString, 100)
                {
                    Alignment      = ContentAlignment.MiddleRight,
                    Offset         = new Size(offset, 0),
                    Font           = FontManager.GetFont(FontStyle.Bold, 11),
                    TextColor      = ThemeManager.Current.SubTextFore,
                    CornerRounding = 1f,
                    Rotation       = 0,
                    BorderWidth    = 1,
                    BorderColor    = ThemeManager.Current.SubTextFore
                };
                args.SubItem.Decorations.Add(decoration);
            }
        }
Exemple #2
0
        /// <summary>
        /// Add each files/folders of a given path to the output List of FileObject,
        /// can be set to be recursive,
        /// can be set to not add the subfolders in the results
        /// TODO: Parallelize for max speed
        /// </summary>
        public List <FileListItem> ListFileOjectsInDirectory(string dirPath, bool recursive = true, bool includeFolders = true, bool firstCall = true)
        {
            if (firstCall)
            {
                _startTime = DateTime.Now;
            }

            var output = new List <FileListItem>();

            if (!Directory.Exists(dirPath))
            {
                return(output);
            }

            // get dir info
            var dirInfo = new DirectoryInfo(dirPath);

            // for each file in the dir
            try {
                foreach (var fileInfo in dirInfo.GetFiles())
                {
                    FileExt fileExt;
                    if (!Enum.TryParse(fileInfo.Extension.Replace(".", ""), true, out fileExt))
                    {
                        fileExt = FileExt.Unknow;
                    }
                    output.Add(new FileListItem {
                        DisplayText     = fileInfo.Name,
                        BasePath        = fileInfo.DirectoryName,
                        FullPath        = fileInfo.FullName,
                        Flags           = FileFlag.ReadOnly,
                        Size            = fileInfo.Length,
                        CreateDateTime  = fileInfo.CreationTime,
                        ModifieDateTime = fileInfo.LastWriteTime,
                        Type            = fileExt
                    });
                }
            } catch (Exception e) {
                ErrorHandler.LogError(e);
            }

            // for each folder in dir
            if (includeFolders)
            {
                Regex regex = new Regex(@"\\\.");
                try {
                    foreach (var directoryInfo in dirInfo.GetDirectories())
                    {
                        if (!Config.Instance.FileExplorerIgnoreUnixHiddenFolders || !regex.IsMatch(directoryInfo.FullName))
                        {
                            var folderItem = new FileListItem {
                                DisplayText     = directoryInfo.Name,
                                BasePath        = Path.GetDirectoryName(directoryInfo.FullName),
                                FullPath        = directoryInfo.FullName,
                                CreateDateTime  = directoryInfo.CreationTime,
                                ModifieDateTime = directoryInfo.LastWriteTime,
                                Type            = FileExt.Folder
                            };
                            output.Add(folderItem);
                            // recursive
                            if (recursive && DateTime.Now.Subtract(_startTime).TotalMilliseconds <= Config.Instance.FileExplorerListFilesTimeOutInMs)
                            {
                                folderItem.Children = ListFileOjectsInDirectory(directoryInfo.FullName, true, true, false).Cast <FilteredTypeTreeListItem>().ToList();
                                if (folderItem.Children.Count == 0)
                                {
                                    folderItem.Children = null;
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    ErrorHandler.LogError(e);
                }
            }

            if (firstCall && DateTime.Now.Subtract(_startTime).TotalMilliseconds > Config.Instance.FileExplorerListFilesTimeOutInMs)
            {
                UserCommunication.NotifyUnique("FileExplorerTimeOut", "The file explorer was listing all the files of the requested folder but has been interrupted because it was taking too long.<br><br>You can set a value for this time out in the option page.", MessageImg.MsgInfo, "Listing files", "Time out reached", args => {
                    Appli.Appli.GoToPage(PageNames.OptionsMisc);
                    UserCommunication.CloseUniqueNotif("FileExplorerTimeOut");
                    args.Handled = true;
                });
            }

            return(output);
        }