2017-06-30 07:15:52 +00:00
|
|
|
if WScript.Arguments.Count < 3 then
|
2017-07-12 10:17:08 +00:00
|
|
|
ShowUsage()
|
2017-06-30 07:15:52 +00:00
|
|
|
ElseIf StrComp("--create",WScript.Arguments(0)) = 0 Then
|
2017-07-12 10:17:08 +00:00
|
|
|
if WScript.Arguments.Count < 4 then
|
|
|
|
ShowUsage()
|
|
|
|
else
|
|
|
|
CreateUploadTarget()
|
|
|
|
end if
|
2017-06-30 07:15:52 +00:00
|
|
|
ElseIf StrComp("--files",WScript.Arguments(0)) = 0 Then
|
2017-07-12 10:17:08 +00:00
|
|
|
if WScript.Arguments.Count < 4 then
|
|
|
|
ShowUsage()
|
|
|
|
else
|
|
|
|
UploadFiles()
|
|
|
|
end if
|
2017-06-30 07:15:52 +00:00
|
|
|
Else
|
2017-07-12 10:17:08 +00:00
|
|
|
ShowUsage()
|
2017-06-30 07:15:52 +00:00
|
|
|
End if
|
|
|
|
|
|
|
|
sub ShowUsage()
|
|
|
|
WScript.StdOut.WriteLine "incorrect parameters"
|
|
|
|
WScript.StdOut.WriteLine "--create [password] [BuildUrl] [BuildName]"
|
|
|
|
WScript.StdOut.WriteLine "--files [password] [dir to upload] [BuildName]"
|
2016-06-07 07:28:14 +00:00
|
|
|
WScript.Quit 1
|
2017-06-30 07:15:52 +00:00
|
|
|
end sub
|
2016-06-07 07:28:14 +00:00
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
function Project64Url()
|
2017-12-12 10:51:24 +00:00
|
|
|
Project64Url = "https://www.pj64-emu.com"
|
2015-09-29 03:45:25 +00:00
|
|
|
End Function
|
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
sub CreateUploadTarget()
|
2017-07-12 10:17:08 +00:00
|
|
|
dim BuildUrl
|
|
|
|
BuildUrl = WScript.Arguments(2)
|
2016-06-07 07:28:14 +00:00
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
Dim objHTTP
|
|
|
|
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
|
|
|
|
objHTTP.open "GET", BuildUrl & "buildTimestamp", False
|
|
|
|
objHTTP.send
|
|
|
|
if (objHTTP.status <> 200) then
|
|
|
|
WScript.StdOut.WriteLine "failed to get job timestamp (" & BuildUrl & "buildTimestamp)"
|
2015-12-01 20:51:59 +00:00
|
|
|
WScript.Quit 1
|
2016-06-07 07:28:14 +00:00
|
|
|
end if
|
2017-07-12 10:17:08 +00:00
|
|
|
dim d
|
2015-09-29 03:45:25 +00:00
|
|
|
|
2017-07-12 10:17:08 +00:00
|
|
|
SetLocale 1033
|
|
|
|
build_date=CDate(objHTTP.responseText)
|
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
|
|
|
|
objHTTP.open "GET", BuildUrl & "api/xml?wrapper=changes", False
|
|
|
|
objHTTP.send
|
2017-07-12 10:17:08 +00:00
|
|
|
|
|
|
|
if (objHTTP.status <> 200) then
|
2015-09-21 23:45:20 +00:00
|
|
|
WScript.StdOut.WriteLine "failed to get job details (" & BuildUrl & "api/xml?wrapper=changes)"
|
2015-12-01 20:51:59 +00:00
|
|
|
WScript.Quit 1
|
2015-09-21 23:45:20 +00:00
|
|
|
end if
|
|
|
|
|
2017-07-12 10:17:08 +00:00
|
|
|
Dim xmlDoc
|
2017-06-30 07:15:52 +00:00
|
|
|
Set xmlDoc = objHTTP.responseXML
|
2015-09-21 23:45:20 +00:00
|
|
|
Set objLst = xmlDoc.getElementsByTagName("freeStyleBuild")
|
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
Dim ProductDescription
|
2015-09-21 23:45:20 +00:00
|
|
|
For each elem in objLst
|
|
|
|
set childNodes = elem.childNodes
|
|
|
|
for each node in childNodes
|
2015-09-30 00:18:37 +00:00
|
|
|
if lcase(node.nodeName)="changeset" then
|
2015-09-21 23:45:20 +00:00
|
|
|
for each item in node.childNodes
|
|
|
|
dim commitId, comment
|
|
|
|
|
|
|
|
commitId = ""
|
|
|
|
comment = ""
|
|
|
|
|
|
|
|
for each itemDetail in item.childNodes
|
|
|
|
if lcase(itemDetail.nodeName)="commitid" then
|
|
|
|
commitId = itemDetail.text
|
|
|
|
end if
|
|
|
|
if lcase(itemDetail.nodeName)="comment" then
|
|
|
|
comment = Replace(Replace(itemDetail.text, vbLf, " "), vbCr, " ")
|
|
|
|
end if
|
|
|
|
next
|
|
|
|
|
|
|
|
if (Len(comment) > 0 and Len(commitId) > 0) then
|
2017-06-30 07:15:52 +00:00
|
|
|
ProductDescription = ProductDescription & "[*]" & comment & " (commit: [URL=""https://github.com/project64/project64/commit/" & commitId & """]"& commitId & "[/URL])" & vbCrLf
|
2015-09-21 23:45:20 +00:00
|
|
|
end if
|
|
|
|
next
|
|
|
|
end if
|
|
|
|
next
|
|
|
|
Next
|
2017-06-30 07:15:52 +00:00
|
|
|
if (Len(ProductDescription) > 0) then
|
|
|
|
ProductDescription = "Changes:"&vbCrLf&"[LIST]" & vbCrLf & ProductDescription & "[/LIST]"
|
2015-09-21 23:45:20 +00:00
|
|
|
else
|
2017-06-30 07:15:52 +00:00
|
|
|
ProductDescription = "No code changes"
|
|
|
|
end if
|
2017-07-12 10:17:08 +00:00
|
|
|
|
|
|
|
Dim url
|
2017-06-30 07:15:52 +00:00
|
|
|
url = Project64Url() + "/index.php"
|
|
|
|
|
2017-07-12 10:17:08 +00:00
|
|
|
dim data
|
|
|
|
data = "option=com_betafile"
|
|
|
|
data = data & "&task=CreateProduct"
|
|
|
|
data = data & "&password="&WScript.Arguments(1)
|
|
|
|
data = data & "&jform[product_name]="&WScript.Arguments(3)
|
|
|
|
data = data & "&jform[product_desc]="&ProductDescription
|
2018-03-27 06:57:29 +00:00
|
|
|
data = data & "&jform[product_date]="&Year(build_date) & "-" & Month(build_date) & "-" & Day(build_date) & " " & Hour(build_date) & ":" & Minute(build_date) & ":" & Second(build_date)
|
2017-07-12 10:17:08 +00:00
|
|
|
|
|
|
|
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
|
|
|
|
objHTTP.open "POST", url, False
|
|
|
|
|
|
|
|
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
|
|
|
|
objHTTP.send data
|
|
|
|
|
|
|
|
if objHTTP.Status <> 200 then
|
|
|
|
WScript.StdOut.WriteLine "Create beta file failed"
|
|
|
|
WScript.StdOut.WriteLine "status: " & objHTTP.Status
|
|
|
|
WScript.StdOut.WriteLine objHTTP.responseText
|
|
|
|
WScript.Quit 1
|
|
|
|
end if
|
|
|
|
|
|
|
|
Set objHTTP = Nothing
|
2015-09-21 23:45:20 +00:00
|
|
|
end sub
|
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
sub UploadFiles()
|
2017-07-12 10:17:08 +00:00
|
|
|
DirToUpload = WScript.Arguments(2)
|
2016-06-07 07:28:14 +00:00
|
|
|
WScript.StdOut.WriteLine "UploadDirectory start - " & DirToUpload
|
|
|
|
Set objFSO = CreateObject("Scripting.FileSystemObject")
|
|
|
|
Set objFolder = objFSO.GetFolder(DirToUpload)
|
|
|
|
Set colFiles = objFolder.Files
|
|
|
|
For Each objFile in colFiles
|
2017-06-30 07:15:52 +00:00
|
|
|
UploadFile DirToUpload & "\" & objFile.Name
|
2017-07-12 10:17:08 +00:00
|
|
|
Next
|
2016-06-07 07:28:14 +00:00
|
|
|
WScript.StdOut.WriteLine "UploadDirectory Finished"
|
|
|
|
end sub
|
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
sub UploadFile(FileToUpload)
|
|
|
|
Const adTypeBinary = 1
|
|
|
|
|
2016-06-07 07:28:14 +00:00
|
|
|
WScript.StdOut.WriteLine "UploadFile start - " & FileToUpload
|
|
|
|
|
|
|
|
dim filePos
|
|
|
|
filePos = InStrRev(FileToUpload, "\")
|
|
|
|
if filePos = 0 then
|
|
|
|
WScript.StdOut.WriteLine "failed to find directory seperator in " & FileToUpload
|
|
|
|
WScript.Quit 1
|
|
|
|
end if
|
|
|
|
|
|
|
|
dim fileName
|
|
|
|
fileName = Mid(FileToUpload, filePos + 1, len(FileToUpload))
|
|
|
|
WScript.StdOut.WriteLine "fileName: " & fileName
|
|
|
|
|
|
|
|
extPos = InStrRev(fileName, ".")
|
|
|
|
if extPos = 0 then
|
|
|
|
WScript.StdOut.WriteLine "failed to find file extension in " & fileName
|
|
|
|
WScript.Quit 1
|
|
|
|
end if
|
|
|
|
extension = Mid(fileName, extPos, len(fileName))
|
2016-07-03 09:41:36 +00:00
|
|
|
if lcase(extension) <> ".zip" And lcase(extension) <> ".exe" And lcase(extension) <> ".apk" then
|
2016-06-07 07:28:14 +00:00
|
|
|
WScript.StdOut.WriteLine "not a valid extension: " & fileName
|
|
|
|
WScript.Quit 1
|
|
|
|
end if
|
|
|
|
|
2017-07-12 10:17:08 +00:00
|
|
|
Dim url
|
2017-06-30 07:15:52 +00:00
|
|
|
url = Project64Url() + "/index.php"
|
2016-06-07 07:28:14 +00:00
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
dim fileContents
|
|
|
|
fileContents = ReadBinaryFile(FileToUpload)
|
2016-06-07 07:28:14 +00:00
|
|
|
|
2017-07-12 10:17:08 +00:00
|
|
|
dim PreFormData, PostFormData
|
|
|
|
PreFormData = PreFormData & "--AaB03x" & vbCrLf & "Content-Disposition: form-data; name=""option""" & vbCrLf & vbCrLf & "com_betafile"& vbCrLf
|
|
|
|
PreFormData = PreFormData & "--AaB03x" & vbCrLf & "Content-Disposition: form-data; name=""task""" & vbCrLf & vbCrLf & "AddFile"& vbCrLf
|
|
|
|
PreFormData = PreFormData & "--AaB03x" & vbCrLf & "Content-Disposition: form-data; name=""password""" & vbCrLf & vbCrLf & WScript.Arguments(1) & vbCrLf
|
|
|
|
PreFormData = PreFormData & "--AaB03x" & vbCrLf & "Content-Disposition: form-data; name=""jform[product_name]""" & vbCrLf & vbCrLf & WScript.Arguments(3) & vbCrLf
|
2017-06-30 07:15:52 +00:00
|
|
|
PreFormData = PreFormData & "--AaB03x" & vbCrLf & "Content-Disposition: form-data; name=""jform[add_file]""; filename=""" & fileName & """" & vbCrLf
|
2016-06-07 07:28:14 +00:00
|
|
|
PreFormData = PreFormData & "Content-Type: application/zip" & vbCrLf & vbCrLf
|
|
|
|
PostFormData = vbCrLf & "--AaB03x" & vbCrLf & "Content-Disposition: form-data; name=""upload""" & vbCrLf & vbCrLf & "Upload" & vbCrLf
|
|
|
|
PostFormData = PostFormData & vbCrLf & vbCrLf & "--AaB03x--"& vbCrLf
|
|
|
|
|
2017-07-12 10:17:08 +00:00
|
|
|
Dim DataToPOSTStream
|
2016-06-07 07:28:14 +00:00
|
|
|
Set DataToPOSTStream = CreateObject("ADODB.Stream")
|
|
|
|
|
|
|
|
DataToPOSTStream.type=adTypeBinary
|
|
|
|
DataToPOSTStream.Open
|
|
|
|
|
|
|
|
DataToPOSTStream.Write = Stream_StringToBinary(PreFormData,"us-ascii")
|
|
|
|
DataToPOSTStream.Write = fileContents
|
|
|
|
DataToPOSTStream.Write = Stream_StringToBinary(PostFormData,"us-ascii")
|
|
|
|
DataToPOSTStream.Position = 0
|
|
|
|
DataToPOSTStream.Type = adTypeBinary
|
2017-06-30 07:15:52 +00:00
|
|
|
|
2016-06-07 07:28:14 +00:00
|
|
|
Dim DataToPOST
|
|
|
|
DataToPOST = DataToPOSTStream.Read
|
|
|
|
|
2017-07-12 10:17:08 +00:00
|
|
|
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
|
|
|
|
objHTTP.open "POST", url, False
|
|
|
|
|
|
|
|
objHTTP.setRequestHeader "Content-Type", "multipart/form-data; boundary=AaB03x"
|
|
|
|
objHTTP.setRequestHeader "Content-Length", Len(fileContents)
|
|
|
|
objHTTP.send DataToPOST
|
|
|
|
|
|
|
|
if objHTTP.Status <> 200 then
|
|
|
|
WScript.StdOut.WriteLine "Failed to upload file"
|
|
|
|
WScript.StdOut.WriteLine "status: " & objHTTP.Status
|
|
|
|
WScript.StdOut.WriteLine objHTTP.responseText
|
|
|
|
WScript.Quit 1
|
|
|
|
end if
|
2016-06-07 07:28:14 +00:00
|
|
|
WScript.StdOut.WriteLine "UploadFile Finished"
|
2015-09-21 23:45:20 +00:00
|
|
|
end sub
|
|
|
|
|
2017-06-30 07:15:52 +00:00
|
|
|
Function ReadBinaryFile(path)
|
|
|
|
Const adTypeBinary = 1
|
|
|
|
Const adTypeText = 2
|
|
|
|
|
|
|
|
dim inStream
|
|
|
|
dim myByte,myByteValue,myCharacter
|
|
|
|
|
|
|
|
set inStream=WScript.CreateObject("ADODB.Stream")
|
|
|
|
|
|
|
|
inStream.Open
|
|
|
|
inStream.type=1
|
|
|
|
|
|
|
|
inStream.LoadFromFile path
|
|
|
|
|
|
|
|
ReadBinaryFile=inStream.Read()
|
|
|
|
inStream.Close
|
|
|
|
End Function
|
|
|
|
|
2015-09-25 02:38:16 +00:00
|
|
|
Function Stream_StringToBinary(Text, CharSet)
|
|
|
|
Const adTypeBinary = 1
|
2017-06-30 07:15:52 +00:00
|
|
|
Const adTypeText = 2
|
2015-09-25 02:38:16 +00:00
|
|
|
|
|
|
|
Dim BinaryStream
|
|
|
|
Set BinaryStream = CreateObject("ADODB.Stream")
|
|
|
|
|
|
|
|
BinaryStream.Type = adTypeText
|
|
|
|
BinaryStream.CharSet = CharSet
|
|
|
|
|
|
|
|
BinaryStream.Open
|
|
|
|
BinaryStream.WriteText Text
|
|
|
|
|
|
|
|
BinaryStream.Position = 0
|
|
|
|
BinaryStream.Type = adTypeBinary
|
|
|
|
Stream_StringToBinary = BinaryStream.Read
|
|
|
|
|
|
|
|
Set BinaryStream = Nothing
|
|
|
|
End Function
|