Function SaveBinaryData(FileName, Data)

' adTypeText for binary = 1
Const adTypeText = 1
Const adSaveCreateOverWrite = 2

' Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

' Specify stream type - we want To save Data/string data.
BinaryStream.Type = adTypeText

' Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write Data

' Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite

End Function

Function FileExists(FilePath)
      Set fso = CreateObject("Scripting.FileSystemObject")
      If fso.FileExists(FilePath) Then
        FileExists=CBool(1)
      Else
        FileExists=CBool(0)
      End If
End Function



Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
Set WshShell = WScript.CreateObject("WScript.Shell")
AppDataPath = WshShell.ExpandEnvironmentStrings("%APPDATA%")
Set filesys = CreateObject("Scripting.FileSystemObject") 
Dim exeName 
Dim statusCode
exeName = AppDataPath+"\unzip.exe -o "+AppDataPath+"\mjolnir-w32.zip -d "+AppDataPath+"\"

intAnswer = MsgBox ("This script will install Mjolnir on your machine in '"+AppDataPath+"\mjolnir\'. Do you want to proceed?", _
        vbYesNo,"Mjolnir Installation")

If intAnswer = vbNo Then
   WScript.Quit 0
End If

URL = "http://www.stahlworks.com/dev/unzip.exe"
objWinHttp.open "GET", URL, False
objWinHttp.send ""
SaveBinaryData AppDataPath+"\unzip.exe",objWinHttp.responseBody

If FileExists(AppDataPath+"\mjolnir-w32.zip") Then
      statusCode = WshShell.Run (exeName, 1, true)
Else
	URL = "http://mjolnirscript.net/v3/releases/mjolnir-w32.zip"
	objWinHttp.open "GET", URL, False
	objWinHttp.send ""
	SaveBinaryData AppDataPath+"\mjolnir-w32.zip",objWinHttp.responseBody
	statusCode = WshShell.Run (exeName, 1, true)
End If
filesys.DeleteFile AppDataPath+"\unzip.exe" 


Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\Mjolnir.lnk")
link.Description = "Mjolnir V3 shortcut"
link.IconLocation = AppDataPath+"\mjolnir\32\mjolnir32.exe"
link.TargetPath = AppDataPath+"\mjolnir\32\mjolnir32.exe"
link.WindowStyle = 3
link.WorkingDirectory = AppDataPath+"\mjolnir\32\"
link.Save


MsgBox("Mjolnir installed in '"+AppDataPath+"\mjolnir\', run program from desktop shortcut, if you have antivirus software you probably want to add exclude exception into antivirus software so updates can be retreived")




