forked from JackD83/PyMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunner.py
156 lines (113 loc) · 4.61 KB
/
Runner.py
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
import subprocess, ResumeHandler
import platform
import sys, os, stat, Overclock
def runEmu(config, rom):
ResumeHandler.storeResume()
name = config["name"]
workdir = config["workingDir"] if "workingDir" in config else None
cmd = config["cmd"] if "workingDir" in config else None
if(cmd == None or not os.path.isfile(cmd)):
print("cmd needs to be set to an existing executable")
return
print("Platform is: " + platform.processor())
if(workdir == None and not cmd == None):
workdir = os.path.abspath(os.path.join(cmd, os.pardir))
if(platform.processor() == ""):
runEmuMIPS(name, cmd, workdir, config, rom)
else:
runEmuHost(name, cmd, workdir, config, rom)
def runEmuMIPS(name, cmd, workdir, config, rom):
name = config["name"]
cmd = config["cmd"] if "cmd" in config else None
workdir = config["workingDir"] if "workingDir" in config else None
screen = config["screen"] if "screen" in config else None
legacy = config["legacy"] if "legacy" in config else None
overclock = config["overclock"] if "overclock" in config else None
if(workdir == None and not cmd == None):
workdir = os.path.abspath(os.path.join(cmd, os.pardir))
if(overclock != None):
try:
Overclock.setClock(overclock)
except Exception as ex:
pass
fileName = "run"
if(legacy == "True"):
fileName ="legacyRun"
file = open("/tmp/" + fileName,"w")
file.write("#!/bin/sh\n")
if(legacy == "True"):
file.write("export HOME=/mnt/ext_sd/home/\n")
file.write("echo 0 > /proc/jz/lcd_a320\n")
file.write("cd \"" + workdir + "\"\n")
file.write(cmd + " \"" + rom + "\"\n")
file.close()
st = os.stat('/tmp/' + fileName)
os.chmod('/tmp/' + fileName, st.st_mode | stat.S_IEXEC)
if(legacy == "True"):
file = open("/tmp/run","w")
file.write("#!/bin/sh\n")
file.write("mount --bind /mnt/ext_sd/ /opt/legacy/mnt/ext_sd/\n")
file.write("mount --bind /mnt/int_sd/ /opt/legacy/mnt/int_sd/\n")
file.write("chroot /opt/legacy /tmp/legacyRun\n")
file.close()
st = os.stat('/tmp/run')
os.chmod('/tmp/run', st.st_mode | stat.S_IEXEC)
sys.exit()
def runEmuHost(name, cmd, workdir, config, rom):
print("run emu " + cmd + " " + name + " with file " + rom + " cwd " +workdir)
try:
subprocess.Popen([cmd, rom ], cwd=workdir)
except Exception as ex:
print(str(ex))
def runNative(config):
ResumeHandler.storeResume()
cmd = config["cmd"] if "cmd" in config else None
if(cmd == None or not os.path.isfile(cmd)):
print("cmd needs to be set to an existing executable")
return
print("Platform is: " + platform.processor())
if(platform.processor() == ""):
runNativeMIPS(cmd, config)
else:
runNativeHost(cmd, config)
def runNativeMIPS(cmd, config):
cmd = config["cmd"] if "cmd" in config else None
screen = config["screen"] if "screen" in config else None
legacy = config["legacy"] if "legacy" in config else None
overclock = config["overclock"] if "overclock" in config else None
selection = config["selection"] if "selection" in config else ""
if(overclock != None):
try:
Overclock.setClock(overclock)
except Exception as ex:
pass
fileName = "run"
if(legacy == "True"):
fileName ="legacyRun"
file = open("/tmp/" + fileName,"w")
file.write("#!/bin/sh\n")
if(legacy == "True"):
file.write("export HOME=/mnt/ext_sd/home/\n")
file.write("echo 0 > /proc/jz/lcd_a320\n")
parent = os.path.abspath(os.path.join(cmd, os.pardir))
file.write("cd \"" + parent + "\"\n")
file.write("\"" + cmd + "\" \"" + selection + "\"\n")
file.close()
st = os.stat('/tmp/' + fileName)
os.chmod('/tmp/' + fileName, st.st_mode | stat.S_IEXEC)
if(legacy == "True"):
file = open("/tmp/run","w")
file.write("#!/bin/sh\n")
file.write("mount --bind /mnt/ext_sd/ /opt/legacy/mnt/ext_sd/\n")
file.write("mount --bind /mnt/int_sd/ /opt/legacy/mnt/int_sd/\n")
file.write("chroot /opt/legacy /tmp/legacyRun\n")
file.close()
st = os.stat('/tmp/run')
os.chmod('/tmp/run', st.st_mode | stat.S_IEXEC)
sys.exit()
def runNativeHost(cmd, config):
selection = overclock = config["selection"] if "selection" in config else ""
try:
subprocess.Popen([cmd, selection])
except Exception as ex:
print(str(ex))