forked from XX-net/XX-Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.vbs
200 lines (159 loc) · 5.25 KB
/
start.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
On Error Resume Next
Sub includeFile (fSpec)
dim fileSys, file, fileData
set fileSys = createObject ("Scripting.FileSystemObject")
set file = fileSys.openTextFile (fSpec)
fileData = file.readAll ()
file.close
executeGlobal fileData
set file = nothing
set fileSys = nothing
End Sub
Set fso=CreateObject("Scripting.FileSystemObject")
strCurrentPath = CurrentPath()
strVersion = CurrentVersion()
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = strCurrentPath
python_version = "3.8.2"
pythonDir = "python" & python_version & "\"
If Not DirIsExist(pythonDir) then
includeFile strCurrentPath & "\code\" & strVersion & "\launcher\download.vbs"
includeFile strCurrentPath & "\code\" & strVersion & "\launcher\unzip.vbs"
End If
Sub ChangeCurrentPathToRoot()
strCurrentPath = CurrentPath()
End Sub
Function PreparePython(download_id)
' Check if python have installed.
If DirIsExist(pythonDir) then
PreparePython = True
Exit Function
End If
CreateDir("data")
CreateDir("data\download")
py_fn = "py" & python_version & ".zip"
url = "https://raw.githubusercontent.com/XX-net/XX-Net-dev/master/download/" & py_fn
fp = "data\download\" & py_fn
fsize = 6594715
If download_id = 1 then
call DownloadFile1(url, fp)
Elseif download_id = 2 then
call DownloadFile2(url, fp)
End If
fs = GetFileSize(fp)
if not fs = fsize then
PreparePython = False
Exit Function
end if
call UnzipFiles(fp, "data\download\py" & python_version)
CreateDir("python27")
call MoveDir("data\download\py" & python_version, pythonDir)
call RemoveDir("data\download")
PreparePython = True
End Function
Function DirIsExist(strPath)
Set fso = CreateObject("Scripting.FileSystemObject")
Set shl = CreateObject("WScript.Shell")
exists = fso.FolderExists(strPath)
if (exists) then
DirIsExist = True
Else
DirIsExist = False
end if
End Function
Function CreateDir(strPath)
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(strPath) Then
Set newfolder = filesys.CreateFolder(strPath)
End If
End Function
Function GetFileSize(strPath)
set filesys=CreateObject("Scripting.FileSystemObject")
GetFileSize = filesys.GetFile(strPath).Size
End Function
Function GetAbslutePath(path)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
GetAbslutePath = fso.GetAbsolutePathName(path)
End Function
Sub UnzipFiles(zipFile, targetDir)
'WScript.Echo "unzip " & zipFile
call Unzip(zipFile, targetDir)
End Sub
Sub MoveDir(srcDir, dstDir)
srcDir = GetAbslutePath(srcDir)
dstDir = GetAbslutePath(dstDir)
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(srcDir)
folder.Move dstDir
End Sub
Sub RemoveDir(strFolderPath)
Dim objFSO, objFolder
Set objFSO = CreateObject ("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolderPath) Then
objFSO.DeleteFolder strFolderPath, True
End If
End Sub
python_is_ready = PreparePython(1)
If not python_is_ready then
python_is_ready = PreparePython(2)
End If
If not python_is_ready then
WScript.Echo "XX-Net Download Python Environment fail, Please download Windows version."
Wscript.Quit
End if
Function CurrentPath()
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
CurrentPath = objFSO.GetParentFolderName(objFile)
End Function
Function CurrentVersion()
strCurrentPath = CurrentPath()
strVersionFile = strCurrentPath & "/code/version.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(strVersionFile)) Then
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(strVersionFile,1)
CurrentVersion = objFileToRead.ReadLine()
version_path = strCurrentPath & "/code/" & CurrentVersion & "/launcher/start.py"
If( Not fso.FileExists(version_path) ) Then
CurrentVersion = "default"
End If
objFileToRead.Close
Set objFileToRead = Nothing
Else
CurrentVersion = "default"
End If
End Function
Function isConsole()
Set objArgs = Wscript.Arguments
'WScript.Echo objArgs.Count
'WScript.Echo objArgs(0)
isConsole = 0
If objArgs.Count > 0 Then
if objArgs(0) = "console" Then
isConsole = 1
End If
End If
End Function
Dim strArgs
quo = """"
If isConsole() Then
python_cmd = "python.exe"
Else
python_cmd = "pythonw.exe"
End If
strExecutable = quo & strCurrentPath & "\" & pythonDir & python_cmd & quo
strArgs = strExecutable & " " & quo & strCurrentPath & "\code\" & strVersion & "\launcher\start.py" & quo
RunningLockFn = strCurrentPath & "\data\launcher\Running.Lck"
'WScript.Echo strArgs
Set fso = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject ("Wscript.Shell")
oShell.Environment("Process")("PYTHONPATH")=""
oShell.Environment("Process")("PYTHONHOME")=""
Do
StartTime = Timer
oShell.Run strArgs, isConsole(), true
EndTime = Timer
run_cost = EndTime - StartTime
Loop Until (not fso.FileExists(RunningLockFn)) or run_cost < 20