-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRunner.py
157 lines (107 loc) · 4.32 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
157
import subprocess, ResumeHandler
import platform,copy, json, Common, InfoOverlay
import sys, os, stat, Overclock
import TaskHandler
import Configuration
import Theme
def setMainMenu(MainMenu):
global main
main = MainMenu
def showLaunchImage():
launchImage = Theme.getValue("launchImage","theme/launch.png")
main.setOverlay(InfoOverlay.InfoOverlay(launchImage, None))
def runEmu(config, rom):
ResumeHandler.storeResume()
Common.addToCustomList(config, rom, "lastPlayedData")
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
overclock = config["overclock"] if "overclock" in config else None
params = config["params"] if "params" in config else None
if(workdir == None and not cmd == None):
workdir = os.path.abspath(os.path.join(cmd, os.pardir))
fileName = "run"
file = open("/tmp/" + fileName,"w")
file.write("#!/bin/sh\n")
file.write("cd \"" + workdir + "\"\n")
if(params != None):
file.write(cmd + " " + params.replace("$f","\""+ rom + "\"") + "\n")
else:
file.write(cmd + " \"" + rom + "\"\n")
file.close()
st = os.stat('/tmp/' + fileName)
os.chmod('/tmp/' + fileName, st.st_mode | stat.S_IEXEC)
showLaunchImage()
if(overclock != None and not Configuration.isOpenDinguX()):
try:
Overclock.setClock(overclock)
except Exception as ex:
pass
TaskHandler.addPeriodicTask(0, sys.exit , delay=100)
def runEmuHost(name, cmd, workdir, config, rom):
print("run emu " + cmd + " " + name + " with file " + rom + " cwd " +workdir)
showLaunchImage()
try:
subprocess.Popen([cmd, rom ], cwd=workdir)
except Exception as ex:
print(str(ex))
main.setOverlay(None)
def runNative(config):
ResumeHandler.storeResume()
Common.addToCustomList(config, None, "lastPlayedData")
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
overclock = config["overclock"] if "overclock" in config else None
selection = config["selection"] if "selection" in config else ""
params = config["params"] if "params" in config else None
fileName = "run"
file = open("/tmp/" + fileName,"w")
file.write("#!/bin/sh\n")
parent = os.path.abspath(os.path.join(cmd, os.pardir))
file.write("cd \"" + parent + "\"\n")
if(params != None):
file.write(cmd + " " + params.replace("$f","\""+ selection + "\"") + "\n")
else:
file.write("\"" + cmd + "\" \"" + selection + "\"\n")
file.close()
st = os.stat('/tmp/' + fileName)
os.chmod('/tmp/' + fileName, st.st_mode | stat.S_IEXEC)
showLaunchImage()
if(overclock != None):
try:
Overclock.setClock(overclock)
except Exception as ex:
pass
TaskHandler.addPeriodicTask(0, sys.exit , delay=100)
def runNativeHost(cmd, config):
selection = overclock = config["selection"] if "selection" in config else ""
showLaunchImage()
try:
subprocess.Popen([cmd, selection])
except Exception as ex:
print(str(ex))
main.setOverlay(None)