6
6
import urllib .request
7
7
from pathlib import Path
8
8
9
+ import gevent
9
10
import steam .protobufs .steammessages_partnerapps_pb2 # don't remove
10
11
from steam .client import SteamClient
11
12
@@ -181,29 +182,6 @@ def handle_drm_file():
181
182
182
183
if drm_proc .returncode != 0 :
183
184
184
- def finish_handling_drm_fail ():
185
- if not drm_output .exists () and drm_download_failed :
186
- input (
187
- f"DRM download failed, download the file from https://partner.steamgames.com/apps/drm/{ drm_app_id } and place it at { drm_output } , then press enter"
188
- )
189
- handled_drm = False
190
- if drm_output .exists ():
191
- handle_drm_file ()
192
- handled_drm = True
193
- if (
194
- drm_proc .returncode != 0
195
- and not drm_download_failed
196
- or drm_download_failed
197
- and not handled_drm
198
- ):
199
- if drm_output .exists ():
200
- pbtools .remove_file (str (drm_output ))
201
- pbtools .error_state (
202
- f"DRM wrapping failed: exit code { drm_proc .returncode } " ,
203
- hush = True ,
204
- term = True ,
205
- )
206
-
207
185
if drm_download_failed and drm_id :
208
186
steamclient = SteamWorker ()
209
187
steamclient .login (
@@ -212,30 +190,47 @@ def finish_handling_drm_fail():
212
190
True ,
213
191
)
214
192
215
- def wait_for_drm_download ():
216
- time .sleep (5 )
217
- resp = steamclient .steam .send_um_and_wait (
218
- "PartnerApps.Download#1" ,
219
- {
220
- "file_id" : f"/{ drm_app_id } /{ drm_id } /{ drm_exe_path .name } _{ drm_id } " ,
221
- "app_id" : int (drm_app_id ),
222
- },
223
- )
224
- url = resp .body .download_url
225
- if url :
226
- with urllib .request .urlopen (url ) as response , open (
227
- str (drm_output ), "wb"
228
- ) as out_file :
229
- shutil .copyfileobj (response , out_file )
230
- steamclient .close ()
231
- finish_handling_drm_fail ()
232
-
233
- if steamclient .logged_on_once :
234
- wait_for_drm_download ()
235
- else :
236
- steamclient .steam .once ("logged_on" , wait_for_drm_download )
237
- else :
238
- finish_handling_drm_fail ()
193
+ while not steamclient .logged_on_once :
194
+ # TODO: doesn't work, "this operation would block forever"
195
+ # steamclient.steam.wait_event("logged_on")
196
+ gevent .sleep (1 )
197
+
198
+ resp = steamclient .steam .send_um_and_wait (
199
+ "PartnerApps.Download#1" ,
200
+ {
201
+ "file_id" : f"/{ drm_app_id } /{ drm_id } /{ drm_exe_path .name } _{ drm_id } " ,
202
+ "app_id" : int (drm_app_id ),
203
+ },
204
+ )
205
+ url = resp .body .download_url
206
+ if url :
207
+ with urllib .request .urlopen (url ) as response , open (
208
+ str (drm_output ), "wb"
209
+ ) as out_file :
210
+ shutil .copyfileobj (response , out_file )
211
+ steamclient .close ()
212
+
213
+ if not drm_output .exists () and drm_download_failed :
214
+ input (
215
+ f"DRM download failed, download the file from https://partner.steamgames.com/apps/drm/{ drm_app_id } and place it at { drm_output } , then press enter"
216
+ )
217
+ handled_drm = False
218
+ if drm_output .exists ():
219
+ handle_drm_file ()
220
+ handled_drm = True
221
+ if (
222
+ drm_proc .returncode != 0
223
+ and not drm_download_failed
224
+ or drm_download_failed
225
+ and not handled_drm
226
+ ):
227
+ if drm_output .exists ():
228
+ pbtools .remove_file (str (drm_output ))
229
+ pbtools .error_state (
230
+ f"DRM wrapping failed: exit code { drm_proc .returncode } " ,
231
+ hush = True ,
232
+ term = True ,
233
+ )
239
234
else :
240
235
handle_drm_file ()
241
236
else :
0 commit comments