@@ -77,6 +77,43 @@ internal static Result CreateFolderResult(string title, string subtitle, string
77
77
} ;
78
78
}
79
79
80
+ private static string toReadableSize ( long pDrvSize , int pi )
81
+ {
82
+ int mok = 0 ;
83
+ double drvSize = pDrvSize ;
84
+ string Space = "Byte" ;
85
+ string returnStr = "" ;
86
+
87
+ while ( drvSize > 1024.0 )
88
+ {
89
+ drvSize /= 1024.0 ;
90
+ mok ++ ;
91
+ }
92
+
93
+ if ( mok == 1 )
94
+ Space = "KB" ;
95
+ else if ( mok == 2 )
96
+ Space = " MB" ;
97
+ else if ( mok == 3 )
98
+ Space = " GB" ;
99
+ else if ( mok == 4 )
100
+ Space = " TB" ;
101
+
102
+ if ( mok != 0 )
103
+ if ( pi == 1 )
104
+ returnStr = string . Format ( "{0:F1}{1}" , drvSize , Space ) ;
105
+ else if ( pi == 2 )
106
+ returnStr = string . Format ( "{0:F2}{1}" , drvSize , Space ) ;
107
+ else if ( pi == 3 )
108
+ returnStr = string . Format ( "{0:F3}{1}" , drvSize , Space ) ;
109
+ else
110
+ returnStr = string . Format ( "{0}{1}" , Convert . ToInt32 ( drvSize ) , Space ) ;
111
+ else
112
+ returnStr = string . Format ( "{0}{1}" , Convert . ToInt32 ( drvSize ) , Space ) ;
113
+
114
+ return returnStr ;
115
+ }
116
+
80
117
internal static Result CreateOpenCurrentFolderResult ( string path , bool windowsIndexed = false )
81
118
{
82
119
var retrievedDirectoryPath = FilesFolders . ReturnPreviousDirectoryIfIncompleteString ( path ) ;
@@ -86,19 +123,32 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
86
123
Path . DirectorySeparatorChar
87
124
} , StringSplitOptions . None ) . Last ( ) ;
88
125
89
- if ( retrievedDirectoryPath . EndsWith ( ":\\ " ) )
90
- {
91
- var driveLetter = path . Substring ( 0 , 1 ) . ToUpper ( ) ;
92
- folderName = driveLetter + " drive" ;
93
- }
94
-
95
126
var title = "Open current directory" ;
96
127
97
128
if ( retrievedDirectoryPath != path )
98
129
title = "Open " + folderName ;
99
130
100
-
101
131
var subtitleFolderName = folderName ;
132
+ var subtitle = $ "Use > to search within { subtitleFolderName } , " +
133
+ $ "* to search for file extensions or >* to combine both searches.";
134
+
135
+
136
+
137
+
138
+
139
+ int ? progressBar = null ;
140
+ if ( retrievedDirectoryPath . EndsWith ( ":\\ " ) )
141
+ {
142
+ title = "" ; // hide title when use progress bar,
143
+ var driveLetter = path . Substring ( 0 , 1 ) . ToUpper ( ) ;
144
+ folderName = driveLetter + " drive" ;
145
+ var driveName = driveLetter + ":\\ " ;
146
+ DriveInfo drv = new DriveInfo ( driveLetter ) ;
147
+ subtitle = toReadableSize ( drv . AvailableFreeSpace , 2 ) + " free of " + toReadableSize ( drv . TotalSize , 2 ) ;
148
+ double UsingSize = ( ( Convert . ToDouble ( drv . TotalSize ) - Convert . ToDouble ( drv . AvailableFreeSpace ) ) / Convert . ToDouble ( drv . TotalSize ) * 100 ) ;
149
+ progressBar = Convert . ToInt32 ( UsingSize ) ;
150
+ }
151
+
102
152
103
153
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
104
154
if ( folderName . Length > 19 )
@@ -107,11 +157,11 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
107
157
return new Result
108
158
{
109
159
Title = title ,
110
- SubTitle = $ "Use > to search within { subtitleFolderName } , " +
111
- $ "* to search for file extensions or >* to combine both searches.",
160
+ SubTitle = subtitle ,
112
161
AutoCompleteText = GetPathWithActionKeyword ( retrievedDirectoryPath , ResultType . Folder ) ,
113
162
IcoPath = retrievedDirectoryPath ,
114
163
Score = 500 ,
164
+ ProgressBar = progressBar ,
115
165
Action = c =>
116
166
{
117
167
Context . API . OpenDirectory ( retrievedDirectoryPath ) ;
@@ -208,4 +258,4 @@ public enum ResultType
208
258
Folder ,
209
259
File
210
260
}
211
- }
261
+ }
0 commit comments