forked from Rokoko/rokoko-studio-live-blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater_ops.py
502 lines (398 loc) · 16.1 KB
/
updater_ops.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
import bpy
from . import updater
class CheckForUpdateButton(bpy.types.Operator):
bl_idname = 'rsl_updater.check_for_update'
bl_label = 'Check now for Update'
bl_description = 'Checks if a new update is available for Rokoko Studio Live'
bl_options = {'INTERNAL'}
@classmethod
def poll(cls, context):
return not updater.is_checking_for_update
def execute(self, context):
updater.used_updater_panel = True
updater.check_for_update_background()
return {'FINISHED'}
class UpdateToLatestButton(bpy.types.Operator):
bl_idname = 'rsl_updater.update_latest'
bl_label = 'Update Now'
bl_description = 'Updates Rokoko Studio Live to the latest version'
bl_options = {'INTERNAL'}
@classmethod
def poll(cls, context):
return updater.update_needed
def execute(self, context):
updater.confirm_update_to = 'latest'
updater.used_updater_panel = True
bpy.ops.rsl_updater.confirm_update_panel('INVOKE_DEFAULT')
return {'FINISHED'}
class UpdateToSelectedButton(bpy.types.Operator):
bl_idname = 'rsl_updater.update_selected'
bl_label = 'Update to Selected version'
bl_description = 'Updates Rokoko Studio Live to the selected version'
bl_options = {'INTERNAL'}
@classmethod
def poll(cls, context):
if updater.is_checking_for_update or not updater.version_list:
return False
return True
def execute(self, context):
updater.confirm_update_to = context.scene.rsl_updater_version_list
updater.used_updater_panel = True
bpy.ops.rsl_updater.confirm_update_panel('INVOKE_DEFAULT')
return {'FINISHED'}
class UpdateToBetaButton(bpy.types.Operator):
bl_idname = 'rsl_updater.update_beta'
bl_label = 'Update to Beta version'
bl_description = 'Updates Rokoko Studio Live to the Beta version'
bl_options = {'INTERNAL'}
def execute(self, context):
updater.confirm_update_to = 'beta'
updater.used_updater_panel = True
bpy.ops.rsl_updater.confirm_update_panel('INVOKE_DEFAULT')
return {'FINISHED'}
class RemindMeLaterButton(bpy.types.Operator):
bl_idname = 'rsl_updater.remind_me_later'
bl_label = 'Remind me later'
bl_description = 'This hides the update notification til the next Blender restart'
bl_options = {'INTERNAL'}
def execute(self, context):
updater.remind_me_later = True
self.report({'INFO'}, 'You will be reminded later')
return {'FINISHED'}
class IgnoreThisVersionButton(bpy.types.Operator):
bl_idname = 'rsl_updater.ignore_this_version'
bl_label = 'Ignore this version'
bl_description = 'This ignores this version. You will be reminded again when the next version releases'
bl_options = {'INTERNAL'}
def execute(self, context):
updater.set_ignored_version()
self.report({'INFO'}, 'Version ' + updater.latest_version_str + ' will be ignored.')
return {'FINISHED'}
class ShowPatchnotesPanel(bpy.types.Operator):
bl_idname = 'rsl_updater.show_patchnotes'
bl_label = 'Patchnotes'
bl_description = 'Shows the patchnotes of the selected version'
bl_options = {'INTERNAL'}
@classmethod
def poll(cls, context):
if updater.is_checking_for_update or not updater.version_list:
return False
return True
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
updater.used_updater_panel = True
dpi_value = updater.get_user_preferences().system.dpi
return context.window_manager.invoke_props_dialog(self, width=dpi_value * 8.2)
def check(self, context):
# Important for changing options
return True
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
row = col.row(align=True)
row.prop(context.scene, 'rsl_updater_version_list')
if context.scene.rsl_updater_version_list:
version = updater.get_version_by_string(context.scene.rsl_updater_version_list)
col.separator()
row = col.row(align=True)
row.label(text=version.name, icon='SOLO_ON')
col.separator()
for line in version.patch_notes.replace('**', '').split('\r\n'):
row = col.row(align=True)
row.scale_y = 0.75
row.label(text=line)
col.separator()
row = col.row(align=True)
row.label(text='Released: ' + version.release_date)
col.separator()
class ConfirmUpdatePanel(bpy.types.Operator):
bl_idname = 'rsl_updater.confirm_update_panel'
bl_label = 'Confirm Update'
bl_description = 'This shows you a panel in which you have to confirm your update choice'
bl_options = {'INTERNAL'}
show_patchnotes = False
def execute(self, context):
print('UPDATE TO ' + updater.confirm_update_to)
if updater.confirm_update_to == 'beta':
updater.update_now(beta=True)
elif updater.confirm_update_to == 'latest':
updater.update_now(latest=True)
else:
updater.update_now(version=updater.confirm_update_to)
return {'FINISHED'}
def invoke(self, context, event):
dpi_value = updater.get_user_preferences().system.dpi
return context.window_manager.invoke_props_dialog(self, width=dpi_value * 4.1)
def check(self, context):
# Important for changing options
return True
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
version_str = updater.confirm_update_to
if updater.confirm_update_to == 'latest':
version_str = updater.latest_version_str
elif updater.confirm_update_to == 'beta':
version_str = 'Beta'
col.separator()
row = col.row(align=True)
row.label(text='Version: ' + version_str)
if updater.confirm_update_to == 'beta':
col.separator()
col.separator()
row = col.row(align=True)
row.scale_y = 0.75
row.label(text='Warning:')
row = col.row(align=True)
row.scale_y = 0.75
row.label(text=' The beta version might be unstable and some features')
row = col.row(align=True)
row.scale_y = 0.75
row.label(text=' might not work correctly.')
else:
row.operator(ShowPatchnotesPanel.bl_idname, text='Show Patchnotes')
col.separator()
col.separator()
row = col.row(align=True)
row.scale_y = 0.65
row.label(text='Update now:', icon='URL')
class UpdateCompletePanel(bpy.types.Operator):
bl_idname = 'rsl_updater.update_complete_panel'
bl_label = 'Installation Report'
bl_description = 'The update if now complete'
bl_options = {'INTERNAL'}
show_patchnotes = False
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
dpi_value = updater.get_user_preferences().system.dpi
return context.window_manager.invoke_props_dialog(self, width=dpi_value * 4.1)
def check(self, context):
# Important for changing options
return True
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
if updater.update_finished:
row = col.row(align=True)
row.scale_y = 0.9
row.label(text='Rokoko Studio Live was successfully updated.', icon='FILE_TICK')
row = col.row(align=True)
row.scale_y = 0.9
row.label(text='Restart Blender to complete the update.', icon='BLANK1')
else:
row = col.row(align=True)
row.scale_y = 0.9
row.label(text='Update failed.', icon='CANCEL')
row = col.row(align=True)
row.scale_y = 0.9
row.label(text='See Updater Panel for more info.', icon='BLANK1')
class UpdateNotificationPopup(bpy.types.Operator):
bl_idname = 'rsl_updater.update_notification_popup'
bl_label = 'Update available'
bl_description = 'This shows you that an update is available'
bl_options = {'INTERNAL'}
def execute(self, context):
action = context.scene.rsl_update_action
if action == 'UPDATE':
updater.update_now(latest=True)
elif action == 'IGNORE':
updater.set_ignored_version()
else:
# Remind later aka defer
updater.remind_me_later = True
updater.ui_refresh()
return {'FINISHED'}
def invoke(self, context, event):
dpi_value = updater.get_user_preferences().system.dpi
return context.window_manager.invoke_props_dialog(self, width=dpi_value * 4.6)
# def invoke(self, context, event):
# return context.window_manager.invoke_props_dialog(self)
def check(self, context):
# Important for changing options
return True
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
row = col.split(factor=0.55, align=True)
row.scale_y = 1.05
row.label(text='Rokoko Studio Live v' + updater.latest_version_str + ' available!', icon='SOLO_ON')
row.operator(ShowPatchnotesPanel.bl_idname, text='Show Patchnotes')
col.separator()
col.separator()
col.separator()
row = col.row(align=True)
row.prop(context.scene, 'rsl_update_action', expand=True)
def draw_update_notification_panel(layout):
if not updater.update_needed or updater.remind_me_later or updater.is_ignored_version:
return
col = layout.column(align=True)
if updater.update_finished:
col.separator()
row = col.row(align=True)
row.label(text='Restart Blender to complete update!', icon='ERROR')
col.separator()
return
row = col.row(align=True)
row.scale_y = 0.75
row.label(text='Update v' + updater.latest_version_str + ' available!', icon='SOLO_ON')
col.separator()
row = col.row(align=True)
row.scale_y = 1.3
row.operator(UpdateToLatestButton.bl_idname, text='Update Now')
row = col.row(align=True)
row.scale_y = 1
row.operator(RemindMeLaterButton.bl_idname, text='Defer')
row.operator(IgnoreThisVersionButton.bl_idname, text='Ignore')
col.separator()
col.separator()
col.separator()
def draw_updater_panel(context, layout, user_preferences=False):
col = layout.column(align=True)
scale_big = 2
scale_small = 1.2
if user_preferences:
row = col.row(align=True)
row.scale_y = 0.8
row.label(text='Rokoko Studio Live Updater:', icon='URL')
col.separator()
if updater.update_finished:
col.separator()
row = col.row(align=True)
row.scale_y = 0.75
row.label(text='Restart Blender to complete', icon='ERROR')
row = col.row(align=True)
row.scale_y = 0.75
row.label(text='the update!', icon='BLANK1')
col.separator()
return
if updater.show_error:
errors = updater.show_error.split('\n')
for i, error in enumerate(errors):
row = col.row(align=True)
row.scale_y = 0.85
row.label(text=error, icon='ERROR' if i == 0 else 'BLANK1')
col.separator()
if updater.is_checking_for_update:
if not updater.used_updater_panel:
row = col.row(align=True)
row.scale_y = scale_big
row.operator(CheckForUpdateButton.bl_idname, text='Checking..')
else:
split = col.row(align=True)
row = split.row(align=True)
row.scale_y = scale_big
row.operator(CheckForUpdateButton.bl_idname, text='Checking..')
row = split.row(align=True)
row.alignment = 'RIGHT'
row.scale_y = scale_big
row.operator(CheckForUpdateButton.bl_idname, text="", icon='FILE_REFRESH')
elif updater.update_needed:
split = col.row(align=True)
row = split.row(align=True)
row.scale_y = scale_big
row.operator(UpdateToLatestButton.bl_idname, text='Update now to ' + updater.latest_version_str)
row = split.row(align=True)
row.alignment = 'RIGHT'
row.scale_y = scale_big
row.operator(CheckForUpdateButton.bl_idname, text="", icon='FILE_REFRESH')
elif not updater.used_updater_panel or not updater.version_list:
row = col.row(align=True)
row.scale_y = scale_big
row.operator(CheckForUpdateButton.bl_idname, text='Check now for Update')
else:
split = col.row(align=True)
row = split.row(align=True)
row.scale_y = scale_big
row.operator(UpdateToLatestButton.bl_idname, text='Up to Date!')
row = split.row(align=True)
row.alignment = 'RIGHT'
row.scale_y = scale_big
row.operator(CheckForUpdateButton.bl_idname, text="", icon='FILE_REFRESH')
col.separator()
col.separator()
split = col.row(align=True)
row = split.split(factor=0.4, align=True)
row.scale_y = scale_small
row.active = True if not updater.is_checking_for_update and updater.version_list else False
row.label(text='Version:')
row.prop(context.scene, 'rsl_updater_version_list', text='')
row = split.row(align=True)
row.scale_y = scale_small
row.operator(ShowPatchnotesPanel.bl_idname, text="", icon='WORDWRAP_ON')
row = col.row(align=True)
row.scale_y = scale_small
row.active = True if not updater.is_checking_for_update and updater.version_list else False
row.operator(UpdateToSelectedButton.bl_idname, text='Install Selected Version')
row = col.row(align=True)
row.scale_y = scale_small
row.operator(UpdateToBetaButton.bl_idname, text='Install Beta Version')
col.separator()
row = col.row(align=True)
row.scale_y = 0.65
row.label(text='Current version: ' + updater.current_version_str)
# demo bare-bones preferences
class DemoPreferences(bpy.types.AddonPreferences):
bl_idname = updater.package_name
def draw(self, context):
layout = self.layout
draw_updater_panel(context, layout, user_preferences=True)
to_register = [
CheckForUpdateButton,
UpdateToLatestButton,
UpdateToSelectedButton,
UpdateToBetaButton,
RemindMeLaterButton,
IgnoreThisVersionButton,
ShowPatchnotesPanel,
ConfirmUpdatePanel,
UpdateCompletePanel,
UpdateNotificationPopup,
DemoPreferences,
]
def register(bl_info, beta_branch):
# If not beta branch, always disable fake updates and no version checks!
if not beta_branch:
updater.fake_update = False
updater.no_ver_check = False
# Get current version
current_version = []
for i in bl_info['version']:
current_version.append(str(i))
updater.current_version.append(i)
updater.current_version_str = '.'.join(current_version)
bpy.types.Scene.rsl_updater_version_list = bpy.props.EnumProperty(
name='Version',
description='Select the version you want to install\n',
items=updater.get_version_list
)
bpy.types.Scene.rsl_update_action = bpy.props.EnumProperty(
name="Choose action",
description="Action",
items=[
("UPDATE", "Update Now", "Updates now to the latest version"),
("IGNORE", "Ignore this version", "This ignores this version. You will be reminded again when the next version releases"),
("DEFER", "Remind me later", "Hides the update notification til the next Blender restart")
]
)
# Register all Updater classes
count = 0
for cls in to_register:
try:
bpy.utils.register_class(cls)
count += 1
except ValueError:
pass
# print('Registered', count, 'Rokoko Studio Live updater classes.')
if count < len(to_register):
print('Skipped', len(to_register) - count, 'Rokoko Studio Live updater classes.')
def unregister():
# Unregister all Updater classes
for cls in reversed(to_register):
try:
bpy.utils.unregister_class(cls)
except RuntimeError:
pass
if hasattr(bpy.types.Scene, 'rsl_updater_version_list'):
del bpy.types.Scene.rsl_updater_version_list