@@ -18,6 +18,7 @@ var totalFilesInFolder = 0 // How many images in the folder that we can show
18
18
// Infobar vars
19
19
var InfoBar_Name = " (Filename goes here) "
20
20
var InfoBar_Format = " (Resolution etc goes here) "
21
+ var InfoBar_FileSize = " (Filesize goes here) "
21
22
var InfoBar_Misc = " (Misc stuff goes here) "
22
23
23
24
@@ -243,7 +244,7 @@ func set_new_url(in_url: String) { // This is the main thing. It gets called whe
243
244
InfoBar_Format = String ( current_image_width) + " x " + String( current_image_height) // TODO show color depth etc too
244
245
let TitlebarImageIndex = currentImageIndex + 1 // because 0/x looks weird
245
246
InfoBar_Misc = String ( TitlebarImageIndex) + " / " + String( totalFilesInFolder)
246
-
247
+ InfoBar_FileSize = get_human_size ( bytes : get_file_size ( urlString : current_url ) )
247
248
248
249
249
250
// Enable menu items since we now should have a image loaded
@@ -287,6 +288,28 @@ func get_filename() -> String { /* picture.jpg */
287
288
return fn
288
289
}
289
290
291
+ func get_file_size( urlString: String ) -> Int {
292
+ let local_url = URL ( string: urlString)
293
+ do {
294
+ let resources = try local_url!. resourceValues ( forKeys: [ . fileSizeKey] )
295
+ let fileSize = resources. fileSize!
296
+ return fileSize
297
+ } catch {
298
+ return 0
299
+ }
300
+ }
301
+
302
+ func get_human_size( bytes: Int ) -> String {
303
+ // https://stackoverflow.com/a/42723243
304
+ // get_human_size(bytes: get_file_size(urlString: current_url))
305
+ let bcf = ByteCountFormatter ( )
306
+ //bcf.allowedUnits = [.useMB, .useKB] // optional: restricts the units to MB and KB only
307
+ bcf. countStyle = . file
308
+ bcf. isAdaptive = true
309
+ let string = bcf. string ( fromByteCount: Int64 ( bytes) )
310
+ return string
311
+ }
312
+
290
313
func get_folder( ) -> String { /* /path/to/ */
291
314
let NSs = ( get_URL_String ( ) as NSString )
292
315
let folderpath = NSs . deletingLastPathComponent
0 commit comments