About Tree Size 3.1 Source

Project "Tree Size.rbp"
FileTypes
Filetype special/disk
Filetype special/folder
End FileTypes
Class MainWindow Inherits Window
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End ControlInstance
Sub Change() dim b as folder dim id as integer if me.listindex>=0 then id=val(me.cell(me.listindex,4)) if id>0 then b=folders(id) if b<>Nil then lsize.text=bytes(b.lsize) psize.text=bytes(b.psize) ldsize.text=bytes(b.ldsize) pdsize.text=bytes(b.pdsize) lrsize.text=bytes(b.lrsize) prsize.text=bytes(b.prsize) return end if end if end if lsize.text="" psize.text="" ldsize.text="" pdsize.text="" lrsize.text="" prsize.text="" End
Function CompareRows(row1 as Integer, row2 as Integer, column as Integer, ByRef result as Integer) as Boolean if column=1 then dim d1 as Double=me.CellTag(row1,column) dim d2 as Double=me.CellTag(row2,column) if d1>d2 then result=1 elseif d1<d2 then result=-1 else result=0 end if Return true end if End
Sub ExpandRow(row As Integer) dim b as folder dim id as integer if row>=0 then id=val(me.cell(row,4)) if id>0 then b=folders(id) if b<>Nil then addfolder b end if end if end if End
Sub Open() me.columnAlignment(1)=3 me.columnAlignment(2)=3 me.columnAlignment(3)=3 End
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End ControlInstance
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End ControlInstance
End Control
Control lsize Inherits Label
ControlInstance lsize Inherits Label
End ControlInstance
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End ControlInstance
End Control
Control psize Inherits Label
ControlInstance psize Inherits Label
End ControlInstance
End Control
Control ldsize Inherits Label
ControlInstance ldsize Inherits Label
End ControlInstance
End Control
Control StaticText7 Inherits Label
ControlInstance StaticText7 Inherits Label
End ControlInstance
End Control
Control pdsize Inherits Label
ControlInstance pdsize Inherits Label
End ControlInstance
End Control
Control lrsize Inherits Label
ControlInstance lrsize Inherits Label
End ControlInstance
End Control
Control StaticText10 Inherits Label
ControlInstance StaticText10 Inherits Label
End ControlInstance
End Control
Control prsize Inherits Label
ControlInstance prsize Inherits Label
End ControlInstance
End Control
Control ChasingArrows1 Inherits ProgressWheel
ControlInstance ChasingArrows1 Inherits ProgressWheel
End ControlInstance
End Control
Sub EnableMenuItems() FileCloseWindow.Enable End
Function FileCloseWindow() as Boolean close Return true End
Sub addfolder(b as folder) dim f as FolderItem dim g as FolderItem dim i,c as integer dim fo as Folder f=b.f c=f.Count for i=1 to c g=f.TrueItem(i) if g.Directory then fo=readfolder(g) additem fo end if next End
Sub additem(base as folder) dim c,l as integer folders.append base if base.subfoldercount>0 then list.addFolder base.f.displayName else list.addrow base.f.displayName end if l=list.lastIndex list.cell(l,1)=formatsize(base.lsize) list.celltag(l,1)=base.lsize list.cell(l,2)=format(base.foldercount,"0") list.cell(l,3)=format(base.filecount,"0") list.cell(l,4)=format(UBound(folders),"0") End
Function bytes(d as double) as string if d<1024*2 then return format(d,"0")+" Bytes" elseif d<1024*1024*2 then return format(d/1024,"0.0")+" KBytes" else return format(d/1024/1024,"0.0")+" MBytes" end if End
Function formatsize(l as double) as string const kb=1024.0 const mb=1048576.0 const gb=1073741824.0 const tb=1099511627776.0 if l>tb*10.0 then Return Format(l/tb,"0")+" TB" elseif l>tb*0.95 then Return Format(l/tb,"0.0")+" TB" elseif l>gb*10.0 then Return Format(l/gb,"0")+" GB" elseif l>gb*0.95 then Return Format(l/gb,"0.0")+" GB" elseif l>mb*10.0 then Return Format(l/mb,"0")+" MB" elseif l>mb*0.95 then Return Format(l/mb,"0.0")+" MB" elseif l>kb*10.0 then Return Format(l/kb,"0")+" KB" elseif l>kb*0.95 then Return Format(l/kb,"0.0")+" KB" else Return Format(l,"0")+" Byte" end if End
Sub makelist() list.deleteAllRows additem base list.expanded(0)=true End
Function readfolder(f as folderitem) as folder dim fo as folder dim fs as DirectorySizeMBS fo=new folder fo.f=f fs=f.CalculateDirectorySizeMBS(true,30) if fs<>nil then fo.lsize=fs.LogicalTotalSize fo.psize=fs.PhysicalTotalSize fo.lrsize=fs.LogicalResourceForkSize fo.prsize=fs.PhysicalResourceForkSize fo.ldsize=fs.LogicalDataForkSize fo.pdsize=fs.PhysicalDataForkSize fo.filecount=fs.FilesCount fo.foldercount=fs.FolderCount-1 end if fs=f.CalculateDirectorySizeMBS(false,30) if fs<>nil then fo.subfoldercount=fs.FolderCount end if return fo End
Sub start(f as folderitem) startfolder=f w=new workthread w.w=Self w.run End
Sub work() dim fo as folder fo=readfolder(startfolder) redim folders(0) base=fo title=startfolder.displayName makelist list.enabled=true chasingArrows1.visible=false if List.ListIndex=-1 and List.ListCount>0 then List.ListIndex=0 end if End
Property base as folder
Property folders(0) as folder
Property Protected startfolder as folderitem
Property Protected w as workthread
End Class
MenuBar MyMenu
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileSelectFolder = "Select Folder..."
MenuItem UntitledMenu3 = "-"
MenuItem FileCloseWindow = "Close Window"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem AppleAboutthisapplication = "About this application..."
End MenuBar
Class Folder
Property f as folderitem
Property filecount as integer
Property foldercount as integer
Property ldsize as double
Property lrsize as double
Property lsize as double
Property pdsize as double
Property prsize as double
Property psize as double
Property subfoldercount as integer
End Class
Class workthread Inherits Thread
Sub Run() w.work w=nil End
Property w as mainwindow
End Class
Class AboutDialog Inherits Window
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End ControlInstance
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End ControlInstance
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End ControlInstance
Sub Open() dim p as Picture p=NewPicture(128,128,32) p.Graphics.DrawPicture IconPict,0,0 p.mask.Graphics.DrawPicture Iconmask,0,0 me.Backdrop=p End
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End ControlInstance
End Control
Sub EnableMenuItems() FileCloseWindow.Enable End
Function FileCloseWindow() as Boolean close Return TRUE End
End Class
Class App Inherits Application
Sub EnableMenuItems() appleAboutthisapplication.enable fileselectFolder.enable End
Sub NewDocument() dim f as folderitem dim m as MainWindow f=Selectfolder if f<>nil then m=new MainWindow m.start f end if End
Sub Open() // remove the line or define such a function in your own MBSPluginRegistration module registerPlugins End
Sub OpenDocument(item As FolderItem) dim m as MainWindow m=new MainWindow m.start item End
Function AppleAboutthisapplication() as Boolean aboutDialog.show Return true End
Function FileSelectFolder() as Boolean NewDocument Return true End
End Class
Unknown (encrypted)
End Unknown
ExternalFile IconPict
End ExternalFile
ExternalFile IconMask
End ExternalFile
End Project




Links
MBS Xojo tutorial videos