• Welcome to Valhalla Legends Archive.
 

[VB6] GetFileTime() help

Started by Ringo, September 21, 2005, 12:06 PM

Previous topic - Next topic

Ringo

Iv got my self stuck on getting file time from a file and checking it with the file time from bnet. (it was ages ago i done anything like this)
I googled up the functions i need (and a few more) and have played around with them for awhile, but i need somone to refresh my memory.


Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
Private Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type
Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const FO_DELETE = &H3


Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _
                         (ByVal lpExistingFileName As String, _
                         ByVal lpNewFileName As String, _
                         ByVal bFailIfExists As Long) As Long
                       
Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" _
                         (ByVal lpPathName As String, _
                         lpSecurityAttributes As Long) As Long
                         
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" _
                         (ByVal lpFileName As String) As Long

Private Declare Function GetFileSize Lib "kernel32" _
                         (ByVal hFile As Long, _
                         lpFileSizeHigh As Long) As Long

Private Declare Function GetFileTime Lib "kernel32" _
                         (ByVal hFile As Long, _
                         lpCreationTime As FILETIME, _
                         lpLastAccessTime As FILETIME, _
                         lpLastWriteTime As FILETIME) As Long
                         
Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" _
                         (ByVal lpExistingFileName As String, _
                         ByVal lpNewFileName As String) As Long

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
                         (ByVal lpFileName As String, _
                         ByVal dwDesiredAccess As Long, _
                         ByVal dwShareMode As Long, _
                         lpSecurityAttributes As Long, _
                         ByVal dwCreationDisposition As Long, _
                         ByVal dwFlagsAndAttributes As Long, _
                         ByVal hTemplateFile As Long) As Long
                         
Private Declare Function CloseHandle Lib "kernel32" _
                         (ByVal hObject As Long) As Long
                         
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _
                         (lpFileOp As SHFILEOPSTRUCT) As Long
                         
Private Declare Function FileTimeToSystemTime Lib "kernel32" _
                         (lpFileTime As FILETIME, _
                         lpSystemTime As SYSTEMTIME) As Long

Private Declare Function FileTimeToLocalFileTime Lib "kernel32" _
                         (lpFileTime As FILETIME, _
                         lpLocalFileTime As FILETIME) As Long

Private Declare Function SystemTimeToFileTime Lib "kernel32.dll" _
                         (lpSystemTime As SYSTEMTIME, _
                         lpFileTime As FILETIME) As Long


Private Sub cmdOpen_Click()
    Dim tmpFT(2) As FILETIME
    Dim SysTime As SYSTEMTIME

    Dim R_Handle As Long, F_Handle As Long
    F_Handle = CreateFile(App.Path & "\IX86Ver3.mpq", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
    If F_Handle = -1 Then
        MsgBox "Open file failed"
        Exit Sub
    End If
   
    R_Handle = GetFileTime(F_Handle, tmpFT(0), tmpFT(1), tmpFT(2))
    If R_Handle = -1 Then
        MsgBox "Unable to get file time"
        Exit Sub
    End If
    Debug.Print "GFT;"
    Debug.Print StrToHex(MakeDWORD(tmpFT(0).dwHighDateTime))
    Debug.Print StrToHex(MakeDWORD(tmpFT(0).dwLowDateTime))
    Debug.Print StrToHex(MakeDWORD(tmpFT(1).dwHighDateTime))
    Debug.Print StrToHex(MakeDWORD(tmpFT(2).dwLowDateTime))
    Debug.Print StrToHex(MakeDWORD(tmpFT(2).dwHighDateTime))
    Debug.Print StrToHex(MakeDWORD(tmpFT(2).dwLowDateTime))
   
    R_Handle = FileTimeToLocalFileTime(tmpFT(0), tmpFT(2))
    If R_Handle = -1 Then
        MsgBox "Unable to convert file time to local file time"
        Exit Sub
    End If
    Debug.Print "FTTLFT;"
    Debug.Print StrToHex(MakeDWORD(tmpFT(2).dwHighDateTime))
    Debug.Print StrToHex(MakeDWORD(tmpFT(2).dwLowDateTime))
    Debug.Print ""
    Debug.Print "00 AC 41 43 25 0B C5 01"
End Sub




and the out put is:

GFT;
B4 BE C5 01
E8 CB 36 17
C4 BE C5 01
9C FC F4 BC
C0 BE C5 01
9C FC F4 BC
FTTLFT;
BC BE C5 01
E8 33 FB 78

00 AC 41 43 25 0B C5 01

I must be doing somthing wrong, or not calling a function i should be.
BnetDocs has been down since yesterday, so i havent been able to check any infomation on it (if there is any)
Any help would be great, thanks in advance!

Ringo

hmm, *bump*
I might have asked wrongly, im having problems getting the correct file time from a file that matchs/is anything like the file time sent by battle.net servers.

00 AC 41 43 25 0B C5 01
Is Battle.net's file time for IX86Ver3.mpq, but im having problems checking it.
Can anyone please explaing to me what steps need to be taken to produce the correct value to check?
I cant really add the FTP protocol to my bnet server project untill i get round this, so any help and i will be mostly greatfull!

Thanks in advance!