~sebikul/mundus/mundus-git

« back to all changes in this revision

Viewing changes to .src/PathHelper.module

  • Committer: Sebi
  • Date: 2015-12-01 23:14:32 UTC
  • Revision ID: git-v1:bc907761723b955cad8a13c3c3cafd4cfe78dcb7
Tags: v3.0.1
Fixed path parsing and a spacing issue in the Backups form

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
' Gambas module file
 
2
 
 
3
Public Function CheckProgram(sProg As String) As Boolean
 
4
 
 
5
  Dim iPos As Integer
 
6
 
 
7
  iPos = InStr(sProg, " ")
 
8
  If iPos Then sProg = Left(sProg, iPos - 1)
 
9
 
 
10
  Shell "which " & sProg & " >/dev/null 2>&1" Wait
 
11
 
 
12
  Return (Process.LastValue = 0)
 
13
 
 
14
End
 
15
 
 
16
Public Function GetDirectorySize(sPath As String) As Long
 
17
 
 
18
  Dim sSize, sCommand As String
 
19
 
 
20
  If Not Exist(sPath) Then Return 0
 
21
 
 
22
  sCommand = "du -bs " & Shell$(PathHelper.ResolvePath(sPath))
 
23
 
 
24
  Shell sCommand To sSize
 
25
 
 
26
  Return CLong(Split(sSize, "\t")[0])
 
27
 
 
28
End
 
29
 
 
30
Public Function ResolvePath(sPath As String) As String
 
31
 
 
32
  Dim sFullPath As String
 
33
 
 
34
  If sPath Begins "~/" Then
 
35
 
 
36
    sPath = Mid(sPath, 3)
 
37
 
 
38
    sFullPath = User.Home &/ sPath
 
39
  Else
 
40
    sFullPath = sPath
 
41
  Endif
 
42
 
 
43
  Return sFullPath
 
44
 
 
45
End
 
46
 
 
47
Public Function ScaleSize(Size As Long) As String
 
48
 
 
49
  Dim RetVal As Float
 
50
 
 
51
  Dim sPower As String
 
52
 
 
53
  Dim iKB As Integer = 1024
 
54
  Dim iMB As Integer = iKB * iKB
 
55
  Dim iGB As Integer = iMB * iKB
 
56
 
 
57
  If Size >= 0 And Size < iKB Then
 
58
 
 
59
    sPower = "B"
 
60
    RetVal = Size
 
61
 
 
62
  Else If Size >= iKB And Size < iMB Then
 
63
 
 
64
    sPower = "KB"
 
65
    RetVal = Round(Size / iKB, -2)
 
66
 
 
67
  Else If Size >= iMB And Size < iGB Then
 
68
 
 
69
    sPower = "MB"
 
70
    RetVal = Round(Size / iMB, -2)
 
71
 
 
72
  Else If Size >= iGB Then
 
73
 
 
74
    sPower = "GB"
 
75
    RetVal = Round(Size / iGB, -2)
 
76
 
 
77
  Else
 
78
 
 
79
    sPower = "B"
 
80
    RetVal = Size
 
81
 
 
82
  Endif
 
83
 
 
84
  Return Subst("&1 &2", RetVal, sPower)
 
85
 
 
86
End
 
 
b'\\ No newline at end of file'