by jNizM » 29 Jul 2020, 06:26
Moin,
soweit habe ich das zzt. nur sind die Rüggabewerte noch etwas mau. Muss noch mehr testen.
Code: Select all
...
FindFirstFile(hConnect, ByRef hFind, SearchFile := "*.*", TimeFormat := "system", SizeFormat := "auto", SizeSuffix := false)
{
VarSetCapacity(WIN32_FIND_DATA, (A_IsUnicode ? 592 : 320), 0)
if (hFind := DllCall("wininet\FtpFindFirstFile", "ptr", hConnect, "str", SearchFile, "ptr", &WIN32_FIND_DATA, "uint", 0, "uint*", 0))
return this.FindData(&WIN32_FIND_DATA, TimeFormat, SizeFormat, SizeSuffix)
VarSetCapacity(WIN32_FIND_DATA, 0)
return false
}
FindNextFile(hFind)
{
VarSetCapacity(WIN32_FIND_DATA, (A_IsUnicode ? 592 : 320), 0)
if (DllCall("wininet\InternetFindNextFile", "ptr", hFind, "ptr", &WIN32_FIND_DATA))
return this.FindData(&WIN32_FIND_DATA, TimeFormat, SizeFormat, SizeSuffix)
VarSetCapacity(WIN32_FIND_DATA, 0)
return false
}
FindData(WIN32_FIND_DATA, TimeFormat := "system", SizeFormat := "auto", SizeSuffix := false)
{
static MAX_PATH := 260
static MAXDWORD := 0xffffffff
addr := &WIN32_FIND_DATA
FIND_DATA := []
FIND_DATA["FileAttributes"] := "test"
FIND_DATA["CreationTime"] := this.FileTime( NumGet(addr + 4, "uint") << 32 | NumGet(addr + 8, "uint"), TimeFormat)
FIND_DATA["LastAccessTime"] := this.FileTime( NumGet(addr + 12, "uint") << 32 | NumGet(addr + 16, "uint"), TimeFormat)
FIND_DATA["LastWriteTime"] := this.FileTime( NumGet(addr + 20, "uint") << 32 | NumGet(addr + 24, "uint"), TimeFormat)
FIND_DATA["FileSize"] := this.FormatBytes((NumGet(addr + 28, "uint") * (MAXDWORD + 1)) + NumGet(addr + 32, "uint"), SizeFormat, SizeSuffix)
FIND_DATA["FileName"] := StrGet(addr + 44, "utf-16")
FIND_DATA["AlternateFileName"] := StrGet(addr + 44 + MAX_PATH * (A_IsUnicode ? 2 : 1), "utf-16")
return FIND_DATA
}
FileTime(FileTime, TimeFormat := "system")
{
addr := 0
if (TimeFormat = "system")
addr := this.FileTimeToSystemTime(FileTime)
else if (TimeFormat = "local")
addr := this.FileTimeToLocalFileTime(FileTime)
else
return false
if (addr)
{
return Format("{:04}{:02}{:02}{:02}{:02}{:02}"
, NumGet(addr, 0, "ushort")
, NumGet(addr, 2, "ushort")
, NumGet(addr, 6, "ushort")
, NumGet(addr, 8, "ushort")
, NumGet(addr, 10, "ushort")
, NumGet(addr, 12, "ushort"))
}
return false
}
FileTimeToSystemTime(FileTime)
{
VarSetCapacity(SystemTime, 16, 0)
if (DllCall("FileTimeToSystemTime", "ptr", &FileTime, "ptr", &SystemTime))
return &SystemTime
return false
}
FileTimeToLocalFileTime(FileTime)
{
VarSetCapacity(LocalTime, 16, 0)
if (DllCall("FileTimeToLocalFileTime", "ptr", &FileTime, "ptr", &LocalTime))
return &LocalTime
return false
}
SystemTimeToTzSpecificLocalTime(SystemTime)
{
VarSetCapacity(LocalTime, 16, 0)
if (DllCall("SystemTimeToTzSpecificLocalTime", "ptr", 0, "ptr", &SystemTime, "ptr", &LocalTime))
return &LocalTime
return false
}
FormatBytes(bytes, SizeFormat := "auto", suffix := false)
{
static SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT := 0x0001
static SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS := 0x0002
static S_OK := 0
if (SizeFormat = "auto")
{
size := VarSetCapacity(buf, 1024, 0)
if (DllCall("shlwapi\StrFormatByteSizeEx", "int64", bytes, "int", SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT, "str", buf, "uint", size) = S_OK)
output := buf
}
else if (SizeFormat = "kilobytes" || SizeFormat = "kb")
output := Round(bytes / 1024, 2) . (suffix ? " KB" : "")
else if (SizeFormat = "megabytes" || SizeFormat = "mb")
output := Round(bytes / 1024**2, 2) . (suffix ? " MB" : "")
else if (SizeFormat = "gigabytes" || SizeFormat = "gb")
output := Round(bytes / 1024**3, 2) . (suffix ? " GB" : "")
else if (SizeFormat = "terabytes" || SizeFormat = "tb")
output := Round(bytes / 1024**4, 2) . (suffix ? " TB" : "")
else
output := Round(bytes, 2) . (suffix ? " Bytes" : "")
return output
}
...
Moin,
soweit habe ich das zzt. nur sind die Rüggabewerte noch etwas mau. Muss noch mehr testen.
[code]...
FindFirstFile(hConnect, ByRef hFind, SearchFile := "*.*", TimeFormat := "system", SizeFormat := "auto", SizeSuffix := false)
{
VarSetCapacity(WIN32_FIND_DATA, (A_IsUnicode ? 592 : 320), 0)
if (hFind := DllCall("wininet\FtpFindFirstFile", "ptr", hConnect, "str", SearchFile, "ptr", &WIN32_FIND_DATA, "uint", 0, "uint*", 0))
return this.FindData(&WIN32_FIND_DATA, TimeFormat, SizeFormat, SizeSuffix)
VarSetCapacity(WIN32_FIND_DATA, 0)
return false
}
FindNextFile(hFind)
{
VarSetCapacity(WIN32_FIND_DATA, (A_IsUnicode ? 592 : 320), 0)
if (DllCall("wininet\InternetFindNextFile", "ptr", hFind, "ptr", &WIN32_FIND_DATA))
return this.FindData(&WIN32_FIND_DATA, TimeFormat, SizeFormat, SizeSuffix)
VarSetCapacity(WIN32_FIND_DATA, 0)
return false
}
FindData(WIN32_FIND_DATA, TimeFormat := "system", SizeFormat := "auto", SizeSuffix := false)
{
static MAX_PATH := 260
static MAXDWORD := 0xffffffff
addr := &WIN32_FIND_DATA
FIND_DATA := []
FIND_DATA["FileAttributes"] := "test"
FIND_DATA["CreationTime"] := this.FileTime( NumGet(addr + 4, "uint") << 32 | NumGet(addr + 8, "uint"), TimeFormat)
FIND_DATA["LastAccessTime"] := this.FileTime( NumGet(addr + 12, "uint") << 32 | NumGet(addr + 16, "uint"), TimeFormat)
FIND_DATA["LastWriteTime"] := this.FileTime( NumGet(addr + 20, "uint") << 32 | NumGet(addr + 24, "uint"), TimeFormat)
FIND_DATA["FileSize"] := this.FormatBytes((NumGet(addr + 28, "uint") * (MAXDWORD + 1)) + NumGet(addr + 32, "uint"), SizeFormat, SizeSuffix)
FIND_DATA["FileName"] := StrGet(addr + 44, "utf-16")
FIND_DATA["AlternateFileName"] := StrGet(addr + 44 + MAX_PATH * (A_IsUnicode ? 2 : 1), "utf-16")
return FIND_DATA
}
FileTime(FileTime, TimeFormat := "system")
{
addr := 0
if (TimeFormat = "system")
addr := this.FileTimeToSystemTime(FileTime)
else if (TimeFormat = "local")
addr := this.FileTimeToLocalFileTime(FileTime)
else
return false
if (addr)
{
return Format("{:04}{:02}{:02}{:02}{:02}{:02}"
, NumGet(addr, 0, "ushort")
, NumGet(addr, 2, "ushort")
, NumGet(addr, 6, "ushort")
, NumGet(addr, 8, "ushort")
, NumGet(addr, 10, "ushort")
, NumGet(addr, 12, "ushort"))
}
return false
}
FileTimeToSystemTime(FileTime)
{
VarSetCapacity(SystemTime, 16, 0)
if (DllCall("FileTimeToSystemTime", "ptr", &FileTime, "ptr", &SystemTime))
return &SystemTime
return false
}
FileTimeToLocalFileTime(FileTime)
{
VarSetCapacity(LocalTime, 16, 0)
if (DllCall("FileTimeToLocalFileTime", "ptr", &FileTime, "ptr", &LocalTime))
return &LocalTime
return false
}
SystemTimeToTzSpecificLocalTime(SystemTime)
{
VarSetCapacity(LocalTime, 16, 0)
if (DllCall("SystemTimeToTzSpecificLocalTime", "ptr", 0, "ptr", &SystemTime, "ptr", &LocalTime))
return &LocalTime
return false
}
FormatBytes(bytes, SizeFormat := "auto", suffix := false)
{
static SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT := 0x0001
static SFBS_FLAGS_TRUNCATE_UNDISPLAYED_DECIMAL_DIGITS := 0x0002
static S_OK := 0
if (SizeFormat = "auto")
{
size := VarSetCapacity(buf, 1024, 0)
if (DllCall("shlwapi\StrFormatByteSizeEx", "int64", bytes, "int", SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT, "str", buf, "uint", size) = S_OK)
output := buf
}
else if (SizeFormat = "kilobytes" || SizeFormat = "kb")
output := Round(bytes / 1024, 2) . (suffix ? " KB" : "")
else if (SizeFormat = "megabytes" || SizeFormat = "mb")
output := Round(bytes / 1024**2, 2) . (suffix ? " MB" : "")
else if (SizeFormat = "gigabytes" || SizeFormat = "gb")
output := Round(bytes / 1024**3, 2) . (suffix ? " GB" : "")
else if (SizeFormat = "terabytes" || SizeFormat = "tb")
output := Round(bytes / 1024**4, 2) . (suffix ? " TB" : "")
else
output := Round(bytes, 2) . (suffix ? " Bytes" : "")
return output
}
...[/code]