forked from ApolloFoundation/Apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.vbs
executable file
·106 lines (93 loc) · 3.73 KB
/
update.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Set fso = CreateObject("Scripting.FileSystemObject")
const ReadOnly = 1
If Wscript.Arguments.Count > 1 Then
For i = 0 To Wscript.Arguments.Count - 1
prgArgs = prgArgs & " " & chr(34) & Wscript.Arguments.Item(i) & chr(34)
Next
End If
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, chr(34) & WScript.ScriptFullName & chr(34) & " " & prgArgs & " " & chr(34) & "/elevate" & chr(34), "", "runas", 1
WScript.Quit
End If
WScript.Echo "Got: " & WScript.Arguments.Count & " params"
If ( (fso.FolderExists(WScript.Arguments(0))) AND (fso.FolderExists( WScript.Arguments(1) )) AND (("false" = LCase(WScript.Arguments(2)) ) Or ( "true" = LCase(WScript.Arguments(2)) ))) Then
WScript.Echo "Starting Platform Dependent Updater"
WScript.Echo "Waiting 3 sec"
WScript.Sleep 3000
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.Run "taskkill /f /im ""java.exe""", , True
WScript.Echo "Copy update files"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(WScript.Arguments(1))
Wscript.Echo objFolder.Path
Set colFiles = objFolder.Files
Wscript.Echo "Copy root files"
For Each objFile in colFiles
targetFilePath = Wscript.Arguments(0) & "\" & objFile.Name
isReadonly = MakeReadWrite(targetFilePath)
fso.CopyFile objFile.Path, Wscript.Arguments(0) & "\", True
if (isReadonly) then
MakeReadonly(targetFilePath)
End If
Next
Wscript.Echo "Root files were copied. Copy subfolders..."
CopySubfolders fso.GetFolder(objFolder)
Wscript.Echo "Subfolders were copied"
Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.CurrentDirectory = WScript.Arguments(0)
objShell.Run "make_transport_shortcut.vbs" & " " & chr(34) & WScript.Arguments(0) & chr(34) & "\.."
objShell.Run chr(34) & WScript.Arguments(0) & "\replace_apl_db.bat" & chr(34)
if ("true" = LCase(WScript.Arguments(2))) Then
WScript.Echo "Start desktop application"
objShell.Run chr(34) & WScript.Arguments(0) & "\start-desktop.vbs" & chr(34)
else
WScript.Echo "Start command line application"
objShell.Run chr(34) & WScript.Arguments(0) & "\start.vbs" & chr(34)
End If
WScript.Echo "Exit"
Else
WScript.Echo "Invalid input parameters:" & WScript.Arguments(0) & " " & WScript.Arguments(1) & " " & WScript.Arguments(2)
End If
Sub CopySubFolders(Folder)
For Each Subfolder in Folder.SubFolders
targetFolderPath = Replace(LCase(SubFolder.Path), LCase(WScript.Arguments(1)), WScript.Arguments(0))
WScript.Echo targetFolderPath
if (Not fso.FolderExists(targetFolderPath)) then
fso.CreateFolder targetFolderPath
End If
Set objFolder = fso.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
targetFilePath = targetFolderPath & "\" & objFile.Name
Wscript.Echo targetFilePath
isReadonly = MakeReadWrite(targetFilePath)
fso.CopyFile objFile.Path, targetFolderPath & "\", True
if (isReadonly) then
MakeReadonly(targetFilePath)
End If
Next
CopySubFolders Subfolder
Next
End Sub
Function MakeReadWrite(File)
MakeReadWrite = false
if (fso.FileExists(File)) then
Set f = fso.GetFile(File)
If f.Attributes AND ReadOnly Then
f.Attributes = f.Attributes XOR ReadOnly
MakeReadWrite = true
End If
End If
End Function
Function MakeReadonly(File)
MakeReadonly = false
if (fso.FileExists(File)) then
Set f = fso.GetFile(File)
If Not(f.Attributes AND ReadOnly) Then
f.Attributes = f.Attributes XOR ReadOnly
MakeReadonly = true
End If
End If
End Function