Skip to content

Commit

Permalink
添加设置,默认不显示隐藏的文件夹和受保护的系统文件,如显示会有半透明的视觉效果
Browse files Browse the repository at this point in the history
  • Loading branch information
DearVa committed Aug 14, 2022
1 parent cefa1e7 commit 3e88aff
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 29 deletions.
5 changes: 5 additions & 0 deletions ExplorerEx/Assets/Settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
</item>
<item header="DoubleClickGoUpperLevel" description="#DoubleClickGoUpperLevelDescription" type="boolean" default="true"/>
</category>

<category header="Advanced">
<item header="ShowHiddenFilesAndFolders" description="#ShowHiddenFilesAndFoldersDescription" type="boolean" default="false"/>
<item header="ShowProtectedSystemFilesAndFolders" description="#ShowProtectedSystemFilesAndFoldersDescription" type="boolean" default="false"/>
</category>
</settings>
1 change: 1 addition & 0 deletions ExplorerEx/ExplorerEx.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=model_005Cfileitem/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=model_005Cfilelistview/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=model_005Cfilelistviewitem/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=view_005Ccontrols_005Cfilepreview/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=view_005Ccontrols_005Cfluentui/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=view_005Ccontrols_005Ctabcontrol/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class DiskDriveItem : FolderItem {

private static readonly Gradient GradientColor = new(Colors.ForestGreen, Colors.Orange, Colors.Red);

public DiskDriveItem(DriveInfo drive) : base(drive.Name) {
public DiskDriveItem(DriveInfo drive) : base(new DirectoryInfo(drive.Name)) {
Drive = drive;
FullPath = drive.Name;
IsFolder = true;
Expand Down Expand Up @@ -66,7 +66,7 @@ public sealed class DiskDriveItem : FolderItem {

public override string GetRenameName() {
if (Drive.IsReady) {
return string.IsNullOrWhiteSpace(Drive.VolumeLabel) ? Type : Drive.VolumeLabel;
return string.IsNullOrWhiteSpace(Drive.VolumeLabel) ? Type ?? string.Empty : Drive.VolumeLabel;
}
MessageBox.Error("DriveIsNotReady".L());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public abstract class FileListViewItem : INotifyPropertyChanged {

protected readonly ImageSource defaultIcon;


[NotMapped]
public double Opacity {
get => opacity;
set {
if (opacity != value) {
opacity = value;
OnPropertyChanged();
}
}
}

private double opacity = 1d;

[Key]
public string FullPath { get; protected init; }

Expand Down Expand Up @@ -123,10 +137,10 @@ public abstract class FileListViewItem : INotifyPropertyChanged {

#region 文件重命名
/// <summary>
/// 获取刚开始重命名时的文件名
/// 获取刚开始重命名时的文件名,如果失败,返回null
/// </summary>
/// <returns></returns>
public abstract string GetRenameName();
public abstract string? GetRenameName();

/// <summary>
/// 重命名
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
namespace ExplorerEx.Model;

public abstract class FileSystemItem : FileListViewItem {
protected FileSystemInfo? FileSystemInfo { get; }

/// <summary>
/// 自动更新UI
/// </summary>
Expand Down Expand Up @@ -77,11 +79,17 @@ public abstract class FileSystemItem : FileListViewItem {
protected FileSystemItem(string fullPath, string name, bool isFolder) : base(fullPath, name, isFolder) { }

protected FileSystemItem(string fullPath, string name, ImageSource defaultIcon) : base(fullPath, name, defaultIcon) { }

protected FileSystemItem(FileSystemInfo fileSystemInfo, bool isFolder) : base(fileSystemInfo.FullName, fileSystemInfo.Name, isFolder) {
FileSystemInfo = fileSystemInfo;
}

protected FileSystemItem(FileSystemInfo fileSystemInfo, ImageSource defaultIcon) : base(fileSystemInfo.FullName, fileSystemInfo.Name, defaultIcon) {
FileSystemInfo = fileSystemInfo;
}
}

public class FileItem : FileSystemItem {
public FileInfo? FileInfo { get; }

/// <summary>
/// 是否是可执行文件
/// </summary>
Expand All @@ -103,25 +111,26 @@ public class FileItem : FileSystemItem {

protected FileItem() : base(null!, null!, false) { }

public FileItem(FileInfo fileInfo) : base(fileInfo.FullName, fileInfo.Name, false) {
FileInfo = fileInfo;
IsFolder = false;
public FileItem(FileInfo fileInfo) : base(fileInfo, false) {
FileSize = -1;
}

public override void LoadAttributes(LoadDetailsOptions options) {
if (FileInfo == null) {
if (FileSystemInfo == null) {
return;
}
var type = FileUtils.GetFileTypeDescription(Path.GetExtension(Name));
var type = FileUtils.GetFileTypeDescription(FileSystemInfo.Extension);
if (string.IsNullOrEmpty(type)) {
Type = "UnknownType".L();
} else {
Type = type;
}
FileSize = FileInfo.Length;
DateModified = FileInfo.LastWriteTime;
DateCreated = FileInfo.CreationTime;
FileSize = ((FileInfo)FileSystemInfo).Length;
DateModified = FileSystemInfo.LastWriteTime;
DateCreated = FileSystemInfo.CreationTime;
if (FileSystemInfo.Attributes.HasFlag(FileAttributes.Hidden)) {
Opacity = 0.5d;
}
}

public override void LoadIcon(LoadDetailsOptions options) {
Expand Down Expand Up @@ -167,7 +176,7 @@ public class FolderItem : FileSystemItem {
var zipIndex = path.IndexOf(@".zip\", StringComparison.CurrentCulture);
if (zipIndex == -1) { // 没找到.zip\,不是zip文件
if (Directory.Exists(path)) {
return (new FolderItem(path.TrimEnd('\\')), PathType.LocalFolder);
return (new FolderItem(new DirectoryInfo(path)), PathType.LocalFolder);
}
if (File.Exists(path)) {
return (null, PathType.LocalFile);
Expand All @@ -188,7 +197,7 @@ public class FolderItem : FileSystemItem {

protected FolderItem() : base(null!, null!, true) { }

public FolderItem(string fullPath): base(fullPath, Path.GetFileName(fullPath), InitializeIsEmptyFolder(fullPath)) {
public FolderItem(DirectoryInfo directoryInfo): base(directoryInfo, InitializeIsEmptyFolder(directoryInfo.FullName)) {
IsFolder = true;
FileSize = -1;
}
Expand All @@ -209,6 +218,9 @@ public class FolderItem : FileSystemItem {
var directoryInfo = new DirectoryInfo(FullPath);
DateModified = directoryInfo.LastWriteTime;
DateCreated = directoryInfo.CreationTime;
if (FileSystemInfo != null && FileSystemInfo.Attributes.HasFlag(FileAttributes.Hidden)) {
Opacity = 0.5d;
}
}

public override void LoadIcon(LoadDetailsOptions options) {
Expand All @@ -228,13 +240,23 @@ public class FolderItem : FileSystemItem {
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public virtual List<FileListViewItem> EnumerateItems(string? selectedPath, out FileListViewItem? selectedItem, CancellationToken token) {
var showHidden = Settings.Current[Settings.CommonSettings.ShowHiddenFilesAndFolders].GetBoolean();
var showSystem = Settings.Current[Settings.CommonSettings.ShowProtectedSystemFilesAndFolders].GetBoolean();

selectedItem = null;
var list = new List<FileListViewItem>();
foreach (var directoryPath in Directory.EnumerateDirectories(FullPath)) {
if (token.IsCancellationRequested) {
return list;
}
var item = new FolderItem(directoryPath);
var di = new DirectoryInfo(directoryPath);
if (di.Attributes.HasFlag(FileAttributes.System) && !showSystem) {
continue;
}
if (di.Attributes.HasFlag(FileAttributes.Hidden) && !showHidden) {
continue;
}
var item = new FolderItem(di);
list.Add(item);
if (directoryPath == selectedPath) {
item.IsSelected = true;
Expand All @@ -245,7 +267,14 @@ public class FolderItem : FileSystemItem {
if (token.IsCancellationRequested) {
return list;
}
var item = new FileItem(new FileInfo(filePath));
var fi = new FileInfo(filePath);
if (fi.Attributes.HasFlag(FileAttributes.System) && !showSystem) {
continue;
}
if (fi.Attributes.HasFlag(FileAttributes.Hidden) && !showHidden) {
continue;
}
var item = new FileItem(fi);
list.Add(item);
if (filePath == selectedPath) {
item.IsSelected = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ internal sealed class FolderOnlyItem : FileListViewItem {
isExpanded = value;
OnPropertyChanged();
if (value) {
// ReSharper disable once PossibleUnintendedReferenceComparison
if (this == Home) {
UpdateDriveChildren();
return;
Expand All @@ -178,6 +179,10 @@ internal sealed class FolderOnlyItem : FileListViewItem {
} else {
actualChildren.Clear();
}

var showHidden = Settings.Current[Settings.CommonSettings.ShowHiddenFilesAndFolders].GetBoolean();
var showSystem = Settings.Current[Settings.CommonSettings.ShowProtectedSystemFilesAndFolders].GetBoolean();

cts = new CancellationTokenSource();
var token = cts.Token;
Task.Run(() => {
Expand All @@ -188,6 +193,13 @@ internal sealed class FolderOnlyItem : FileListViewItem {
if (token.IsCancellationRequested) {
return;
}
var attributes = (FileAttributes)entry.ExternalAttributes;
if (attributes.HasFlag(FileAttributes.System) && !showSystem) {
continue;
}
if (attributes.HasFlag(FileAttributes.Hidden) && !showHidden) {
continue;
}
var entryName = entry.FullName;
var indexOfSlash = entryName.IndexOf('/', relativePath.Length);
if (indexOfSlash != -1) {
Expand All @@ -203,7 +215,14 @@ internal sealed class FolderOnlyItem : FileListViewItem {
return;
}
try {
actualChildren.Add(new FolderOnlyItem(new DirectoryInfo(directoryPath), this));
var di = new DirectoryInfo(directoryPath);
if (di.Attributes.HasFlag(FileAttributes.System) && !showSystem) {
continue;
}
if (di.Attributes.HasFlag(FileAttributes.Hidden) && !showHidden) {
continue;
}
actualChildren.Add(new FolderOnlyItem(di, this));
} catch {
// 忽略错误,不添加
}
Expand All @@ -213,6 +232,13 @@ internal sealed class FolderOnlyItem : FileListViewItem {
return;
}
try {
var fi = new DirectoryInfo(zipPath);
if (fi.Attributes.HasFlag(FileAttributes.System) && !showSystem) {
continue;
}
if (fi.Attributes.HasFlag(FileAttributes.Hidden) && !showHidden) {
continue;
}
actualChildren.Add(new FolderOnlyItem(zipPath, string.Empty, this));
} catch {
// 忽略错误,不添加
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions ExplorerEx/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public static class CommonSettings {
public const string ColorMode = "Appearance.Theme.ColorMode";
public const string WindowBackdrop = "Appearance.Theme.WindowBackdrop";
public const string DoubleClickGoUpperLevel = "Common.DoubleClickGoUpperLevel";
public const string ShowHiddenFilesAndFolders = "Advanced.ShowHiddenFilesAndFolders";
public const string ShowProtectedSystemFilesAndFolders = "Advanced.ShowProtectedSystemFilesAndFolders";
}

public static event Action? ThemeChanged;
Expand Down
27 changes: 27 additions & 0 deletions ExplorerEx/Strings/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions ExplorerEx/Strings/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,13 @@ For the application to run properly, it's recommanded that you first extract all
<data name="...FreeOf..." xml:space="preserve">
<value>{0} free of {1}</value>
</data>
<data name="ShowHiddenFilesAndFolders" xml:space="preserve">
<value>Show hidden files and folders</value>
</data>
<data name="ShowProtectedSystemFilesAndFolders" xml:space="preserve">
<value>Show protected system files and folders</value>
</data>
<data name="Advanced" xml:space="preserve">
<value>Advanced</value>
</data>
</root>
9 changes: 9 additions & 0 deletions ExplorerEx/Strings/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,13 @@ ExplorerEx [-h|--help] [-r|--runInBackground] [-o|--openInNewWindow] [-d|--requi
<data name="...Items" xml:space="preserve">
<value>共{0}个项目</value>
</data>
<data name="ShowHiddenFilesAndFolders" xml:space="preserve">
<value>显示隐藏的文件和文件夹</value>
</data>
<data name="ShowProtectedSystemFilesAndFolders" xml:space="preserve">
<value>显示受保护的系统文件和文件夹</value>
</data>
<data name="Advanced" xml:space="preserve">
<value>高级</value>
</data>
</root>
Loading

0 comments on commit 3e88aff

Please sign in to comment.