@@ -129,6 +129,16 @@ public class AliyunDriveMounter : IDokanOperations, IDisposable
129129 /// </summary>
130130 private string _driveParentFileId = "root" ;
131131
132+ /// <summary>
133+ /// 别名
134+ /// </summary>
135+ private string _alias = "" ;
136+
137+ /// <summary>
138+ /// 显示真实大小
139+ /// </summary>
140+ private bool _isRealSize ;
141+
132142 /// <summary>
133143 /// 下载请求
134144 /// </summary>
@@ -137,9 +147,25 @@ public class AliyunDriveMounter : IDokanOperations, IDisposable
137147 Timeout = TimeSpan . FromMinutes ( 45 )
138148 } ;
139149
140- public AliyunDriveMounter ( AliyunDriveConfig driveConfig , AliyunDriveMountConfig driveMountConfig )
150+ /// <summary>
151+ /// 创建挂载
152+ /// </summary>
153+ /// <param name="driveConfig">云盘配置</param>
154+ /// <param name="driveMountConfig">挂载配置</param>
155+ /// <param name="alias">别名</param>
156+ public AliyunDriveMounter (
157+ AliyunDriveConfig driveConfig ,
158+ AliyunDriveMountConfig driveMountConfig ,
159+ string alias = "" )
141160 {
142161 _log = Log . Logger ;
162+ _alias = alias ;
163+
164+ // 如果挂载为目录,则显示真实大小
165+ if ( ! string . IsNullOrWhiteSpace ( driveMountConfig . MountPath ) )
166+ {
167+ _isRealSize = true ;
168+ }
143169
144170 _driveApi = new AliyunDriveApi ( ) ;
145171
@@ -196,7 +222,8 @@ private async Task<byte[]> DownloadFileSegment(string url, int start, int end)
196222 /// <returns></returns>
197223 private string GetPathKey ( string fileName )
198224 {
199- return $ "{ _driveMountConfig . MountPath . TrimPath ( ) } /{ fileName . TrimPath ( ) } ". ToUrlPath ( ) ;
225+ // {_driveMountConfig.MountPath.TrimPath()}/
226+ return $ "{ fileName . TrimPath ( ) } ". ToUrlPath ( ) ;
200227 }
201228
202229 /// <summary>
@@ -1445,7 +1472,7 @@ public IList<FileInformation> FindFilesHelper(string fileName, string searchPatt
14451472 }
14461473
14471474 /// <summary>
1448- /// 创建文件 /文件夹
1475+ /// 创建/打开文件 /文件夹
14491476 /// </summary>
14501477 /// <param name="fileName">文件名</param>
14511478 /// <param name="access">访问权限</param>
@@ -1743,9 +1770,9 @@ public NtStatus ReadFile(string fileName, byte[] buffer, out int bytesRead, long
17431770 partialContent = DownloadFileSegment ( url , ( int ) offset , endOffset ) . GetAwaiter ( ) . GetResult ( ) ;
17441771 }
17451772
1746- if ( fileName . Contains ( "jpg" ) )
1747- {
1748- }
1773+ // if (fileName.Contains("jpg"))
1774+ // {
1775+ // }
17491776
17501777 // 确保不会复制超出 buffer 大小的数据
17511778 int bytesToCopy = Math . Min ( buffer . Length , partialContent . Length ) ;
@@ -1919,8 +1946,21 @@ public NtStatus GetDiskFreeSpace(out long freeBytesAvailable, out long totalNumb
19191946 // diskSpaceInfo.FreeSpace - 云盘的剩余空间
19201947
19211948 totalNumberOfBytes = _driveConfig ? . Metadata ? . TotalSize ?? long . MaxValue ;
1922- totalNumberOfFreeBytes = _driveConfig ? . Metadata ? . UsedSize ?? 0 ;
1923- freeBytesAvailable = totalNumberOfBytes > 0 ? totalNumberOfBytes - totalNumberOfFreeBytes : long . MaxValue ;
1949+
1950+ // 如果显示真实使用量,则根据文件计算
1951+ if ( _isRealSize )
1952+ {
1953+ totalNumberOfFreeBytes = _driveFiles . Sum ( x => x . Value . Size ?? 0 ) ;
1954+ freeBytesAvailable = totalNumberOfBytes > 0 ? totalNumberOfBytes - totalNumberOfFreeBytes : long . MaxValue ;
1955+
1956+ _log . Information ( $ "真实大小 { totalNumberOfFreeBytes } ") ;
1957+ }
1958+ else
1959+ {
1960+ totalNumberOfFreeBytes = _driveConfig ? . Metadata ? . UsedSize ?? 0 ;
1961+ freeBytesAvailable = totalNumberOfBytes > 0 ? totalNumberOfBytes - totalNumberOfFreeBytes : long . MaxValue ;
1962+ }
1963+
19241964
19251965 return NtStatus . Success ;
19261966 }
@@ -1939,6 +1979,11 @@ public NtStatus GetVolumeInformation(out string volumeLabel, out FileSystemFeatu
19391979 // 设置卷标,这个标签可以根据您的需求自定义,例如"我的云盘"
19401980 volumeLabel = _driveConfig ? . Name ?? "我的云盘" ;
19411981
1982+ if ( ! string . IsNullOrWhiteSpace ( _alias ) )
1983+ {
1984+ volumeLabel += $ "({ _alias } )";
1985+ }
1986+
19421987 // 设置文件系统的特性。这些特性描述了文件系统支持的不同功能。
19431988 // 例如,可以设置为支持Unicode文件名、持久ACLs(访问控制列表)、大文件等
19441989 features = FileSystemFeatures . UnicodeOnDisk |
0 commit comments