|
4 | 4 | import psutil |
5 | 5 | import qdarktheme |
6 | 6 | import os |
| 7 | +import subprocess |
7 | 8 |
|
8 | 9 |
|
| 10 | +def process_exists(process_name): |
| 11 | + call = 'TASKLIST', '/FI', 'imagename eq %s' % process_name |
| 12 | + # use buildin check_output right away |
| 13 | + output = subprocess.check_output(call).decode() |
| 14 | + # check in last line for process name |
| 15 | + last_line = output.strip().split('\r\n')[-1] |
| 16 | + # because Fail message could be translated |
| 17 | + return last_line.lower().startswith(process_name.lower()) |
9 | 18 |
|
10 | 19 | class MainWindow(QMainWindow): |
11 | 20 | def __init__(self): |
12 | 21 | super().__init__() |
13 | 22 |
|
14 | 23 | self.setWindowTitle("Virtual Desktop Body Tracking Configurator") |
15 | 24 |
|
16 | | - for proc in psutil.process_iter(['name']): |
17 | | - if "vrserver.exe" in proc.info['name'].lower(): |
18 | | - dlg2 = QMessageBox() |
19 | | - dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator") |
20 | | - dlg2.setText("Error!\n\nvrserver.exe running!\n\nPlease close SteamVR and try again") |
21 | | - dlg2.exec() |
22 | | - if QMessageBox.StandardButton.Ok: |
23 | | - exit() |
| 25 | + if process_exists("vrserver.exe"): |
| 26 | + dlg2 = QMessageBox() |
| 27 | + dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator") |
| 28 | + dlg2.setText("Error!\n\nvrserver.exe running!\n\nPlease close SteamVR and try again") |
| 29 | + dlg2.exec() |
| 30 | + if QMessageBox.StandardButton.Ok: |
| 31 | + exit() |
24 | 32 |
|
25 | 33 | self.steam = "" |
26 | 34 | try: |
@@ -309,16 +317,13 @@ def load_settings_clicked(self): |
309 | 317 |
|
310 | 318 | def export_clicked(self): |
311 | 319 |
|
312 | | - for proc in psutil.process_iter(['name']): |
313 | | - if "vrserver.exe" in proc.info['name'].lower(): |
314 | | - dlg2 = QMessageBox() |
315 | | - dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator") |
316 | | - dlg2.setText("Error!\n\nvrserver.exe running!\n\nPlease close SteamVR and try again") |
317 | | - |
318 | | - dlg2.exec() |
319 | | - |
320 | | - if QMessageBox.StandardButton.Ok: |
321 | | - exit() |
| 320 | + if process_exists("vrserver.exe"): |
| 321 | + dlg2 = QMessageBox() |
| 322 | + dlg2.setWindowTitle("Virtual Desktop Body Tracking Configurator") |
| 323 | + dlg2.setText("Error!\n\nvrserver.exe running!\n\nPlease close SteamVR and try again") |
| 324 | + dlg2.exec() |
| 325 | + if QMessageBox.StandardButton.Ok: |
| 326 | + exit() |
322 | 327 |
|
323 | 328 |
|
324 | 329 | #print("Export clicked") |
|
0 commit comments