|
Takilara Apprentice
Joined: 31 Jan 2002 Posts: 129 Location: Norway
|
Posted: Mon Dec 05, 2005 1:43 pm
Checking the date/time of a file using zMUD commands |
I was wondering if it is possble to check the timestamp of last modified using zmud commands, or using the #SCRIPT command with a vbscript?
What im trying to achieve:
Comparing timestamp of my settings file with a settingsfile on a webserver
if webserver file is newer, grab this file, reload settings
if local file is newer, POST the local settings file to a form on the server
Ie, basic version control system, without using FTP, and hopefully without having to create standalone software. (i realize i have to make the serverside of this, but thats no problem) |
|
_________________
|
|
|
|
TonDiening GURU
Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Mon Dec 05, 2005 2:18 pm |
I'm going to put something like that together for collaborative mud mapping/deciphering over the holidays. I was considering using #FTP as you could grab the time stamp from it.
Quote: |
Syntax: #FTP [command] [arguments]
dir or list
display a directory listing of the current remote server files
|
Then use the #LOAD
Quote: |
Syntax: #LOA filename
Load the specified settings file into the current window. Note the the current settings file is not saved! Any variables in filename are expanded.
|
Probably a better solution with SQL or something but that seemed to be the easiest to my headspace.
I'd be coupling that with flat text files with %tab for a knowledge base so not to bload the .mud file with variables. Also allows for Excel parsing later on.
As for POST there was an example of a Scandanavian (A*?) guy who had a script that posted his regional code to a weather site which he grabbed the result but I no longer find it. |
|
|
|
Takilara Apprentice
Joined: 31 Jan 2002 Posts: 129 Location: Norway
|
Posted: Mon Dec 05, 2005 2:26 pm |
well i cannot use FTP, as the server im gonna use does not supprot regular ftp, so to get the timestamp of the remote file id have to open a socket to a webpage on hte server, on that webpage id run a php script to echo out the timestamp. And since the server is php enabled i wont have any problems dooing the serverside bit.
however the first obstacle is to find the timestamp of the local files. Im considering though to use EXEC to launch a batchfile, that will dir or attrib the local file and pipe the output to a textfile. then use #file , and #read to read this timestamp (triggers to capture it)
However that will cause a blink on the taskbar wich i was hoping to avoid.
Next obstacle is going to be how to open a socket to the webpage without launching a browser.
But i would assume this would be possible using vbscript
Last obstacle would be to POST or download the most recent file.
I could pretty easily create such software in .net, but i would prefer to do it all within zmud, and i have a feeling that vbscript ought to be powerful enough to do what cant be done in zmud. (also i currently dont have VS installed..) |
|
_________________
|
|
|
|
TonDiening GURU
Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Mon Dec 05, 2005 6:30 pm |
Looks like kind of thing is somewhat standard in VB courses from a quick google scan. If anyone has them skills sets I'm sure they can drop a 10 line code for this.
Searching I find thigns you can use as base examples:
For page retrieval (doesn't work on my comp, probably dont have some vbscript loaded or something)
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=12115
For date stamps:
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=21370
[quote=Full Throttle]
#log log.txt
#log
#mss {Set fso = CreateObject~(~"Scripting.FileSystemObject~"~): If ~(fso.FileExists~(~"log.txt~"~)~) Then: Set objLog = fso.GetFile~(~"log.txt~"~): intLog = objLog.Size: Else: intLog = 0: End If: If ~(intLog > 10000000~) Then: objLog.Copy~(~"medievia.log.%time(yyyymmdd).txt~"~): objLog.Delete: End If} {VBScript}
[/quote]
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=19752
[quote=Full Throttle]
This will download the file from the server each time I call the alias.
[/quote] |
|
|
|
Takilara Apprentice
Joined: 31 Jan 2002 Posts: 129 Location: Norway
|
Posted: Tue Dec 06, 2005 7:43 am |
Brilliant, i'm gonna try this out asap:)
thanks |
|
_________________
|
|
|
|
Takilara Apprentice
Joined: 31 Jan 2002 Posts: 129 Location: Norway
|
Posted: Tue Dec 06, 2005 10:27 pm |
Finally got it,, damn gotta say VBScript aint my strongest language..
Adapted in part from: http://www.motobit.com/tips/detpg_uploadvbsie/
(Seems to have been written by Antonin Foller)
first a comparison alias, i call it compareSettings
Code: |
#mss {}
#mss {URL=~"http:~/~/someurl.com~/somefolder~/somescript~"}
#mss {localFileName=~"c:\zmud\medieva\medieva.mud~"}
#mss {boundary=~"%random( 100000000)~"}
getLocalFileTime
getRemoteFileTime
#if @remoteFileStamp>@localFileStamp {downloadSettings}
#if @remoteFileStamp<@localFileStamp {uploadSettings}
#if @remoteFileStamp=@localFileStamp {#echo Settings are syncronised}
|
getLocalFileTime
Code: |
#mss {Set fso = CreateObject~(~"Scripting.FileSystemObject~"~): If ~(fso.FileExists~(localFileName~)~) Then: Set objLog = fso.GetFile~(localFileName~): intLog = objLog.Size: End If: stamp = objLog.DateLastModified:UDate = DateDiff~(~"s~", ~"01/01/1970 00:00:00~", stamp~)} {VBScript}
#var localFileStamp {%mss( UDate)}
|
getRemoteFileTime
Code: |
#script {strHTML = ~"~"}
#script {Sub getHTML:Set objHTTP = CreateObject~(~"MSXML2.XMLHTTP~"):objHTTP.Open ~"GET~", URL+~"?filename=~"+localFileName+~"~&seed=%time( )~", ~"FALSE~":objHTTP.Send:strHTML = objHTTP.ResponseText:Set objHTTP = Nothing:End Sub}
#mss {getHTML}
#var remoteFileStamp {%mss( strHTML)}
|
(NOTE! ive built it so that the serverside script requires a filename, then it returns only the timestamp)
Now that we know what version of the file we want we can either download or upload,, lets do upload first:
uploadSettings
Code: |
#echo UPLOAD LOCAL FILE TO INTERNET
uploadSettingsVB
#echo %mss( myResult)
|
uploadSettingsVB // NOTE. this is in VBScript mode!
Code: |
Option Explicit
dim myResult
myResult = uploadFile
Function uploadFile
Dim binData
Dim FormData
binData = readFile()
FormData = BuildFormData(binData,boundary,localFileName,"myFile")
Dim myResult
uploadFile = postFile(FormData)
end function
function postFile(someData)
Dim http
Set http = CreateObject("MSXML2.XMLHTTP")
' NOTE timestamp so server can set correct stamp
http.Open "POST", URL+"?timestamp="+CStr(UDate), False
http.setRequestHeader "Content-Type", "multipart/form-data;boundary="+boundary
' http.setRequestHeader "Content-Length",CStr(localFileSize)
http.send someData
postFile = http.responseText
end function
Function readFile
' Get timestamp
Set fso = CreateObject("Scripting.FileSystemObject")
Set objLog = fso.GetFile(localFileName)
Dim intLog
intLog = objLog.Size
Dim stamp
stamp = objLog.DateLastModified
UDate = DateDiff("s", "01/01/1970 00:00:00", stamp)
dim objStream
set objStream = CreateObject("ADODB.Stream")
objStream.Type=1
objStream.Open
objStream.LoadFromFile localFileName
'localFileSize=objStream.Size
Dim tempBinData
tempBinData=objStream.Read
objStream.Close
Set objStream=Nothing
readFile = tempBinData
End Function
Function BuildFormData(FileContents, Boundary, FileName, FieldName)
dim Pre, Po
dim PreOut, PoOut
Const ContentType = "application/upload"
Pre = "--" + Boundary + vbCrLf + mpFields(FieldName, FileName, ContentType)
Po = vbCrLf + "--" + Boundary + "--" + vbCrLf
Const adLongVarBinary = 205
Dim RS: Set RS = CreateObject("ADODB.Recordset")
RS.Fields.Append "b", adLongVarBinary, Len(Pre) + LenB(FileContents) + Len(Po)
RS.Open
RS.AddNew
Dim LenData
'Convert Pre string value To a binary data
LenData = Len(Pre)
RS("b").AppendChunk (StringToMB(Pre) & ChrB(0))
PreOut = RS("b").GetChunk(LenData)
RS("b") = ""
LenData = Len(Po)
RS("b").AppendChunk (StringToMB(Po) & ChrB(0))
PoOut = RS("b").GetChunk(LenData)
RS("b") = ""
RS("b").AppendChunk (PreOut)
RS("b").AppendChunk (FileContents)
RS("b").AppendChunk (PoOut)
RS.Update
Dim tempFormData
tempFormData = RS("b")
BuildFormData = tempFormData
RS.Close
End Function
Function mpFields(FieldName, FileName, ContentType)
Dim MPTemplate 'template For multipart header
MPTemplate = "Content-Disposition: form-data; name=""{field}"";" + _
" filename=""{file}""" + vbCrLf + _
"Content-Type: {ct}" + vbCrLf + vbCrLf
Dim Out
Out = Replace(MPTemplate, "{field}", FieldName)
Out = Replace(Out, "{file}", FileName)
mpFields = Replace(Out, "{ct}", ContentType)
End Function
Function StringToMB(S)
Dim I, B
For I = 1 To Len(S)
B = B & ChrB(Asc(Mid(S, I, 1)))
Next
StringToMB = B
End Function
|
(Make your serverside script binary read the file "myFile", in php its something like $_FILES["myFile"])
(NOTE!! make sure you add a lot of validation of the files here, as its easily abused if not)
Then maybe we want to download instead:
downloadSettings
Code: |
#echo {DOWNLOAD NEW FILE FROM INTERNET}
#echo {Download settings. Please wait!}
#var tempname someoldtempfile
#save @tempname
downloadFileVB
#load %mss( localFileName)
#save
|
downloadFileVB // VBScript mode again
Code: |
Option Explicit
strHTML = ""
Dim newSettingsFile
Dim tempFile
tempFile = localFileName
'Lose the old file
removeoldfile
'Get the new file
Dim someContent
someContent = getnewfile
'Write the new file
writeFile (someContent)
sub removeoldfile
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(tempFile)) Then
fso.DeleteFile(tempFile)
end if
End Sub
Function getnewfile
Dim objHTTP
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.Open "GET", URL+"?getfile=true&filename="+localFileName+"&seed="+CStr(Rnd), "FALSE"
objHTTP.Send
strHTML = objHTTP.ResponseText
getnewfile=objHTTP.ResponseBody
Set objHTTP = Nothing
End Function
Function writeFile (fileContents)
dim objStream
set objStream = CreateObject("ADODB.Stream")
objStream.Mode=3
objStream.Type=1
objStream.Open
objStream.Write=fileContents
' objStream.SaveToFile localFileName
objStream.SaveToFile tempFile
objStream.Close
Set objStream=Nothing
End Function
|
(this bit requires the server to listen for the getfile parameter, and echo out the actual file.. also here validation is critical)
Hope it may be of use to someone
(I am aware that it is kinda messy, but my knowledge and experience of VBScript and general M$ stuff is not too good, so if anyone manages to clean this up more, that would be nice :) |
|
_________________
|
|
|
|
Takilara Apprentice
Joined: 31 Jan 2002 Posts: 129 Location: Norway
|
Posted: Wed Dec 07, 2005 11:17 am |
Update: Just tested this method for syncing the map databse also, however that turns out not to work so good because of the size. So i dont see any good way of syncing the map without using some sort of compression on the map before sending it, and that is suddenly alot more complex
|
|
_________________
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|