Disk functions
Posted: Sat Apr 17, 2021 9:35 am
Hi Chris & Robert
VFP has also a - slightly different working - DiskSpace() function. How should it be implemented ? I'm thinking about to enhance the current XSharp.core code. The currently available overloads are
the required VFP overloads are
My idea is to do the main work inside the new DiskSpace( cDrive AS STRING , nType AS INT ) overload. The required changes would be:
the additional overload looks like:
What do you think ?
regards
Karl-Heinz
VFP has also a - slightly different working - DiskSpace() function. How should it be implemented ? I'm thinking about to enhance the current XSharp.core code. The currently available overloads are
Code: Select all
FUNCTION DiskSpace() AS INT64
FUNCTION DiskSpace(nDrive AS INT) AS INT64
FUNCTION DiskSpace(cDrive AS STRING) AS INT64
Code: Select all
FUNCTION DiskSpace() AS INT64
FUNCTION DiskSpace( cDrive AS STRING ) AS INT64
FUNCTION DiskSpace( cDrive AS STRING , nType AS INT ) AS INT64
Code: Select all
FUNCTION DiskSpace() AS INT64
// replacement for the existing core code
IF Runtimestate.Dialect == XSharpDialect.FoxPro
RETURN DiskSpace ( CurDrive(), 2 ) // 2 is the VFP <nType> default
ELSE
RETURN DiskSpace ( CurDrive(), 1 ) // VO returns always oDrive:TotalSize
ENDIF
FUNCTION DiskSpace(cDrive AS STRING) AS INT64
// replacement for the existing core code
IF Runtimestate.Dialect == XSharpDialect.FoxPro
RETURN DiskSpace ( cDrive , 2 ) // 2 is the VFP <nType> default
ELSE
RETURN DiskSpace ( cDrive , 1 ) // VO returns always oDrive:TotalSize
ENDIF
FUNCTION DiskSpace(nDrive AS INT) AS INT64
LOCAL cDisk AS STRING
cDisk := DiskNo2DiskName(nDrive)
RETURN DiskSpace(cDisk, 1 ) <---- // VO returns always oDrive:TotalSize
:
Code: Select all
FUNCTION DiskSpace( cDrive AS STRING , nType AS INT ) AS INT64
LOCAL result AS INT64
IF String.IsNullOrEmpty(cDrive)
cDrive := CurDrive()
ELSEIF cDrive:Length > 1
cDrive := cDrive:Substring(0,1)+":"
ENDIF
// todo: verify the nType param
TRY
// XSharp.IO.File.ClearErrorState()
VAR oDrive := System.IO.DriveInfo{cDrive}
// todo: verify the results
SWITCH nType
CASE 1
result := oDrive:TotalSize
CASE 2
result := oDrive:TotalFreeSpace
CASE 3
result := oDrive:AvailableFreeSpace
END SWITCH
CATCH e AS Exception
// XSharp.IO.File.SetErrorState(e)
IF Runtimestate.Dialect == XSharpDialect.FoxPro
result := -1
ELSE
result := 0
ENDIF
END TRY
RETURN result
regards
Karl-Heinz