-
Notifications
You must be signed in to change notification settings - Fork 2
/
launcherm.gd
1394 lines (1176 loc) · 36.3 KB
/
launcherm.gd
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# tool
# class_name
# extends
extends Control
## A brief description of your script.
##
## A more detailed description of the script.
##
## @tutorial: http://the/tutorial1/url.com
## @tutorial(Tutorial2): http://the/tutorial2/url.com
# ----- signals
# ----- enums
enum STATUS_LOCAL {
WAIT = 0,
START_REQUESTED,
CHECK_INFO_SW_UPDATES_REQUESTED,
SW_UPDATES_REQUESTED,
SW_UPDATER_REQUEST_INIT,
SW_LAUNCHER_REQUEST_INIT,
SW_CORE_REQUEST_INIT,
SW_INFO_REQUESTED,
SW_INFO_UPDATER_REQUESTED,
SW_INFO_LAUNCHER_REQUESTED,
SW_INFO_CORE_REQUESTED,
SW_INFO_WAIT,
SW_INFO_UPDATER_WAIT,
SW_INFO_LAUNCHER_WAIT,
SW_INFO_CORE_WAIT,
SW_DW_INFO_REQUESTED,
SW_DW_INFO_WAIT,
SW_CHECK_ULC,
SW_DW_BRICKS,
SW_DW_BRICK_WAIT,
SW_DW_COMPLETED,
MT_DW_INFO_REQUESTED,
MT_DW_COMPLETED,
MERGE_AND_MOVE,
MERGE_AND_MOVE_ALL_BRICKS,
MERGE_AND_MOVE_SINGLE_BRICK,
READ_AND_SAVE,
READ_AND_SAVE_ALL_CHUNKS,
READ_AND_SAVE_GROUP_OF_CHUNKS,
SW_DW_RENAME
}
enum OP_TYPE_LOCAL {
NONE = 0,
SW_DW,
MT_DW,
}
# ----- constants
const M4DVERSION = {
'v1': 2,
'v2': 0,
'v3': 0,
'v4': 1,
'p': "a",
'godot': {
'v1': 4,
'v2': 2,
'v3': 1,
'v4': 2, # dev = 0, rc = 1, stable = 2
'p': "stable"
}
}
const M4DNAME = "mapod4d"
# default 0 version of M4D
const M4D0VERSION = {
'v1': 0,
'v2': 0,
'v3': 0,
'v4': 0,
'p': "a",
'godot': {
'v1': 4,
'v2': 2,
'v3': 1,
'v4': 2, # dev = 0, rc = 1, stable = 2
'p': "stable"
}
}
const WK_PATH = 'wk'
const UPDATES_DIR = "updates"
const TMP_DIR = "tmp"
## storage name for data info of current download
const DW_INFO = "download_info"
## name of software updater on the update server
const UPDATER_NAME = "updater"
## name of software updater
const UPDATER_EXE_NAME = "updater"
## storage name for data info of software updater
const UPDATER_INFO = "updater_info"
## name of software launcher on the update server
const LAUNCHER_NAME = "launcherm"
## name of software launcher
const LAUNCHER_EXE_NAME = "mapod4d"
## storage name for data info of software launcher
const LAUNCHER_INFO = "launcherm_info"
## name of software core on the update server
const CORE_NAME = "core"
## name of software core
const CORE_EXE_NAME = "core"
const MULTIVSVR = "https://sv001.mapod4d.it"
const MULTIVSVR_PORT = 80
const BUF_NAME = "buf_"
const CHUNKSIZE = 550000
const CHUNKSIZE_MULTI = 1000
const BLOCK_ISTANCE_PORT = 2000
const EDITOR_DBG_BASE_PATH = "res://test"
# ----- exported variables
# ----- public variables
# ----- private variables
## enable debug messages
var _mapod4d_debug_flag: bool = false
## enable debug status flux messages
var _mapod4d_debug_status_flag: bool = true
## this application codified version
var _m4dsversion = null
## internal configuration
var _settings = {
"insicure": false,
"autoupdate": false,
}
var _tls_opt = TLSOptions.client_unsafe()
# status machine
# current status
var _status = STATUS_LOCAL.WAIT
# status of request
var _entry_0_status = STATUS_LOCAL.WAIT
## dinamic paths
var _build_updater_path = null
var _build_launcher_path = null
var _build_core_path = null
var _build_wk_path = null
var _build_updates_path = null
var _build_tmp_dir = null
var _build_dest_dw_path = null
## general
var _server = null
var _base_path = null
var _local_lock = false # future mutitread
var _op_type:OP_TYPE_LOCAL = OP_TYPE_LOCAL.NONE
var _os_info = {
"os": null,
"exe_ext": ""
}
var _base_dir = null
## local support
var _mapod4d_debug_line: int = 0
var _is_ready = false
## if true the module needs to be updated
var _update_updater = false
var _update_core = false
var _update_launcher = false
var _current_brick = 0
var _dw_name = null
var _download_file = null
var _info = null
var _url = null
var _dir = null
var _dest_file = null
var _input_file_data = null
var _input_file_data_read = false
var _brick_name = null
var _current_merging_brick = 0
var _current_chunk = 0
var _software_name = null
var _tmp_dir = null
var _sysop = null
var _destination = null
var _which = null
## _info data saved after info download
var _info_saved = {}
## sofware download vars
var _ext = null
## metaverse download vars
var _mapod4d_ver = null
# ----- onready variables
@onready var http_sw_info_rq = $HTTPSWRequestInfo
@onready var http_sw_dw_rq = $HTTPSWRequestDownload
@onready var http_mt_info_rq = $HTTPSWRequestInfo
@onready var http_mt_dw_rq = $HTTPSWRequestDownload
@onready var tab_container = $TabContainer
@onready var software = $TabContainer/Software
@onready var multiverse = $TabContainer/Multiverse
# ----- optional built-in virtual _init method
# ----- built-in virtual _ready method
# Called when the node enters the scene tree for the first time.
func _ready():
_block_istance()
## encode application version
_m4dsversion = _sversion(
M4DVERSION.v1, M4DVERSION.v2, M4DVERSION.v3, M4DVERSION.v4)
## check OS
match OS.get_name():
"Windows", "UWP":
_os_info.os = "W00"
_os_info.exe_ext = ".exe"
"macOS":
_os_info.os = "M00"
_os_info.exe_ext = ""
"Linux", "FreeBSD", "NetBSD", "OpenBSD", "BSD":
_os_info.os = "L00"
_os_info.exe_ext = ""
"Android":
_os_info.os = "A00"
_os_info.exe_ext = ""
"iOS":
_os_info.os = "I00"
_os_info.exe_ext = ""
"Web":
_os_info.os = "H00"
_os_info.exe_ext = ""
## get base path
_base_path = OS.get_executable_path().get_base_dir()
if OS.has_feature('editor'):
_base_path = EDITOR_DBG_BASE_PATH
#tab_container.set_tab_disabled(1, true)
else:
tab_container.set_tab_disabled(1, true)
tab_container.set_tab_title(0, tr("TABSOFTWARE"))
tab_container.set_tab_title(1, tr("TABMULTIVERSE"))
tab_container.set_tab_title(2, tr("TABSETTINGS"))
_build_paths()
_build_dirs()
_write_version()
_load_setting()
http_sw_info_rq.request_completed.connect(
_on_sw_dw_info_completed)
http_sw_dw_rq.request_completed.connect(
_on_sw_dw_brick_completed)
software.check_info_sw_updates_requested.connect(
_on_check_info_sw_updates_requested)
software.sw_search_updates_requested.connect(
_on_sw_search_updates_requested)
software.sw_updates_requested.connect(
_on_sw_updates_requested)
software.download_software_requested.connect(
_on_software_dw_info_requested)
software.info_software_requested.connect(
_on_info_software_requested)
multiverse.download_metaverse_requested.connect(
_on_download_metaverse_requested)
if _settings.autoupdate == true:
# current status
_set_status(STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED)
# starting flow status
_set_entry_0_status(STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED)
else:
# current status
_set_status(STATUS_LOCAL.START_REQUESTED)
# starting flow status
_set_entry_0_status(STATUS_LOCAL.START_REQUESTED)
# DEBUG
# _set_status(STATUS_LOCAL.WAIT)
# _set_entry_0_status(STATUS_LOCAL.WAIT)
_is_ready = true
# ----- remaining built-in virtual methods
## write version file concerning this application
func _enter_tree():
var args = OS.get_cmdline_user_args()
if "-m4dver" in args:
_write_version()
get_tree().quit()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
# status MACHINE
if _is_ready and _local_lock != true:
if _status != STATUS_LOCAL.WAIT:
match _status:
STATUS_LOCAL.START_REQUESTED:
_start_requested()
STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED:
_check_info_sw_updates_requested(software)
STATUS_LOCAL.SW_UPDATES_REQUESTED:
_sw_updates_requested(software)
STATUS_LOCAL.SW_UPDATER_REQUEST_INIT, \
STATUS_LOCAL.SW_LAUNCHER_REQUEST_INIT, \
STATUS_LOCAL.SW_CORE_REQUEST_INIT:
_sw_request_init()
## simple file updater info request
STATUS_LOCAL.SW_INFO_REQUESTED, \
## updater file info request
STATUS_LOCAL.SW_INFO_UPDATER_REQUESTED, \
## launcher file info request
STATUS_LOCAL.SW_INFO_LAUNCHER_REQUESTED, \
## core file info request
STATUS_LOCAL.SW_INFO_CORE_REQUESTED, \
## file info request to download
STATUS_LOCAL.SW_DW_INFO_REQUESTED:
_sw_dw_info_requested()
## file info request wait
STATUS_LOCAL.SW_INFO_WAIT, \
## updater file info request wait
STATUS_LOCAL.SW_INFO_UPDATER_WAIT, \
## launcher file info request wait
STATUS_LOCAL.SW_INFO_LAUNCHER_WAIT, \
## core file info request wait
STATUS_LOCAL.SW_INFO_CORE_WAIT, \
## file info request to download wait
STATUS_LOCAL.SW_DW_INFO_WAIT:
_update_info_wait()
STATUS_LOCAL.SW_CHECK_ULC:
_sw_check_ulc()
STATUS_LOCAL.SW_DW_BRICKS:
_sw_dw_bricks()
STATUS_LOCAL.SW_DW_BRICK_WAIT:
_update_info_wait()
STATUS_LOCAL.SW_DW_COMPLETED:
_sw_dw_completed()
STATUS_LOCAL.MT_DW_INFO_REQUESTED:
mt_dw_info_requested()
STATUS_LOCAL.MT_DW_COMPLETED:
_mt_dw_completed()
STATUS_LOCAL.MERGE_AND_MOVE:
_merge_and_move()
STATUS_LOCAL.MERGE_AND_MOVE_ALL_BRICKS:
_merge_and_move_all_bricks()
STATUS_LOCAL.MERGE_AND_MOVE_SINGLE_BRICK:
_merge_and_move_single_brick()
STATUS_LOCAL.READ_AND_SAVE:
_read_and_save()
STATUS_LOCAL.READ_AND_SAVE_ALL_CHUNKS:
_read_and_save_all_chunks()
STATUS_LOCAL.READ_AND_SAVE_GROUP_OF_CHUNKS:
_read_and_save_group_of_chunks()
STATUS_LOCAL.SW_DW_RENAME:
_sw_dw_rename()
# ----- public methods
# ----- private methods
## write version file
func _write_version():
var json_data = JSON.stringify(M4DVERSION)
var base_dir = OS.get_executable_path().get_base_dir()
if OS.has_feature('editor'):
base_dir = EDITOR_DBG_BASE_PATH
var file_name = base_dir + "/" + M4DNAME + ".json"
var file = FileAccess.open(file_name, FileAccess.WRITE)
if file != null:
file.store_string(json_data)
file.flush()
## load and update settings
func _load_setting():
var base_dir = OS.get_executable_path().get_base_dir()
if OS.has_feature('editor'):
base_dir = EDITOR_DBG_BASE_PATH
var file_name = base_dir + "/" + M4DNAME + "_conf.json"
if FileAccess.file_exists(file_name):
## TODO load settings
var file = FileAccess.open(file_name, FileAccess.READ)
if file != null:
var settings = file.get_as_text()
settings = JSON.parse_string(settings)
if settings != null:
_set_settings(settings)
file.close()
else:
## create default settings
var settings = JSON.stringify(_settings)
var file = FileAccess.open(file_name, FileAccess.WRITE)
if file != null:
file.store_string(settings)
file.flush()
file.close()
if _settings.insicure:
http_sw_info_rq.set_tls_options(_tls_opt)
http_sw_dw_rq.set_tls_options(_tls_opt)
http_mt_info_rq.set_tls_options(_tls_opt)
http_mt_dw_rq.set_tls_options(_tls_opt)
## create default settings
## update settings
var settings = JSON.stringify(_settings)
var file = FileAccess.open(file_name, FileAccess.WRITE)
if file != null:
file.store_string(settings)
file.flush()
file.close()
## check and config internal settings
func _set_settings(settings):
if "insicure" in settings:
if typeof(_settings.insicure) == TYPE_BOOL:
_settings.insicure = bool(settings.insicure)
## build dinamic paths
func _build_paths():
_build_wk_path = "%s/%s" % [_base_path, WK_PATH]
_build_updater_path = "%s/%s" % [_build_wk_path , UPDATER_EXE_NAME]
_build_launcher_path = "%s/%s" % [_base_path , LAUNCHER_EXE_NAME]
_build_core_path = "%s/%s" % [_build_wk_path , CORE_EXE_NAME]
_build_updates_path = "%s/%s" % [_build_wk_path , UPDATES_DIR]
_build_tmp_dir = "%s/%s" % [_build_wk_path , TMP_DIR]
_build_dest_dw_path = "%s/dw_" % [_build_updates_path]
_mapod4d_debug(_build_wk_path)
## make directory
func _make_dir(path):
if _base_dir != null:
if _base_dir.dir_exists(path) == false:
# var error = _base_dir.make_dir(path)
pass
## build base directory structure or get it
func _build_dirs():
if _base_path != null:
_base_dir = DirAccess.open(_base_path)
_make_dir(_build_wk_path)
_make_dir(_build_updates_path)
_make_dir(_build_tmp_dir)
func _sversion(v1, v2, v3, v4):
return "{v1}{v2}{v3}{v4}".format({
"v1": "%03d" % v1,
"v2": "%03d" % v2,
"v3": "%03d" % v3,
"v4": "%03d" % v4,
})
func _read_version(file_name):
var ret_val = {
"result": false,
"version" : {},
"sversion": "",
}
var file = FileAccess.open(file_name, FileAccess.READ)
if file != null:
var data = file.get_as_text()
var data_json = JSON.parse_string(data)
if data_json != null:
if "v1" in data_json and \
"v2" in data_json and \
"v3" in data_json and \
"v4" in data_json:
ret_val.result = true
ret_val.version = {
"v1": data_json.v1,
"v2": data_json.v2,
"v3": data_json.v3,
"v4": data_json.v4,
}
ret_val.encoded_version = _sversion(
data_json.v1, data_json.v2, data_json.v3, data_json.v4)
return ret_val
## write updater version json
func _write_updater_version():
if _base_dir != null:
if _base_dir.file_exists(_build_updater_path):
var updater_exe = "%s%s" % [_build_updater_path, _os_info.exe_ext]
var _exit_code = OS.execute(updater_exe, ["++", "-m4dver"])
else:
var version_file = "%s%s" % [_build_updater_path, ".json"]
var json_data = JSON.stringify(M4D0VERSION)
var file = FileAccess.open(version_file, FileAccess.WRITE)
if file != null:
file.store_string(json_data)
file.flush()
## write core version json
func _write_core_version():
if _base_dir != null:
if _base_dir.file_exists(_build_core_path):
var core_exe = "%s%s" % [_build_core_path, _os_info.exe_ext]
var _exit_code = OS.execute(core_exe, ["++", "-m4dver"])
else:
var version_file = "%s%s" % [_build_core_path, ".json"]
var json_data = JSON.stringify(M4D0VERSION)
var file = FileAccess.open(version_file, FileAccess.WRITE)
if file != null:
file.store_string(json_data)
file.flush()
## prevent multiple instance
func _block_istance():
## create server and prevent multiple instance
#_server = TCPServer.new()
#var error = _server.listen(BLOCK_ISTANCE_PORT, "127.0.0.1")
#if error != OK:
#get_tree().quit()
#var output = []
#OS.execute("tasklist", [], output )
#for line in output[0].split("\n"):
#if line.begins_with("chrome"):
#get_tree().quit()
#https://github.com/godotengine/godot/issues/18150
pass
## utility status to string
func _status_to_str():
var status = _get_status()
var ret_val = "undefined"
match status:
STATUS_LOCAL.WAIT:
ret_val = "WAIT"
STATUS_LOCAL.START_REQUESTED:
ret_val = "START_REQUESTED"
STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED:
ret_val = "CHECK_INFO_SW_UPDATES_REQUESTED"
STATUS_LOCAL.SW_UPDATES_REQUESTED:
ret_val = "SW_UPDATES_REQUESTED"
STATUS_LOCAL.SW_UPDATER_REQUEST_INIT:
ret_val = "SW_UPDATER_REQUEST_INIT"
STATUS_LOCAL.SW_LAUNCHER_REQUEST_INIT:
ret_val = "SW_LAUNCHER_REQUEST_INIT"
STATUS_LOCAL.SW_CORE_REQUEST_INIT:
ret_val = "SW_CORE_REQUEST_INIT"
STATUS_LOCAL.SW_INFO_REQUESTED:
ret_val = "SW_INFO_REQUESTED"
STATUS_LOCAL.SW_INFO_UPDATER_REQUESTED:
ret_val = "SW_INFO_UPDATER_REQUESTED"
STATUS_LOCAL.SW_INFO_LAUNCHER_REQUESTED:
ret_val = "SW_INFO_LAUNCHER_REQUESTED"
STATUS_LOCAL.SW_INFO_CORE_REQUESTED:
ret_val = "SW_INFO_CORE_REQUESTED"
STATUS_LOCAL.SW_INFO_WAIT:
ret_val = "SW_INFO_WAIT"
STATUS_LOCAL.SW_INFO_UPDATER_WAIT:
ret_val = "SW_INFO_UPDATER_WAIT"
STATUS_LOCAL.SW_INFO_LAUNCHER_WAIT:
ret_val = "SW_INFO_LAUNCHER_WAIT"
STATUS_LOCAL.SW_INFO_CORE_WAIT:
ret_val = "SW_INFO_CORE_WAIT"
STATUS_LOCAL.SW_DW_INFO_REQUESTED:
ret_val = "SW_DW_INFO_REQUESTED"
STATUS_LOCAL.SW_DW_INFO_WAIT:
ret_val = "SW_DW_INFO_WAIT"
STATUS_LOCAL.SW_CHECK_ULC:
ret_val = "SW_CHECK_ULC"
STATUS_LOCAL.SW_DW_BRICKS:
ret_val = "SW_DW_BRICKS"
STATUS_LOCAL.SW_DW_BRICK_WAIT:
ret_val = "SW_DW_BRICK_WAIT"
STATUS_LOCAL.SW_DW_COMPLETED:
ret_val = "SW_DW_COMPLETED"
STATUS_LOCAL.MT_DW_INFO_REQUESTED:
ret_val = "MT_DW_INFO_REQUESTED"
STATUS_LOCAL.MT_DW_COMPLETED:
ret_val = "MT_DW_COMPLETED"
STATUS_LOCAL.MERGE_AND_MOVE:
ret_val = "MERGE_AND_MOVE"
STATUS_LOCAL.MERGE_AND_MOVE_ALL_BRICKS:
ret_val = "MERGE_AND_MOVE_ALL_BRICKS"
STATUS_LOCAL.MERGE_AND_MOVE_SINGLE_BRICK:
ret_val = "MERGE_AND_MOVE_SINGLE_BRICK"
STATUS_LOCAL.READ_AND_SAVE:
ret_val = "READ_AND_SAVE"
STATUS_LOCAL.READ_AND_SAVE_ALL_CHUNKS:
ret_val = "READ_AND_SAVE_ALL_CHUNKS"
STATUS_LOCAL.READ_AND_SAVE_GROUP_OF_CHUNKS:
ret_val = "READ_AND_SAVE_GROUP_OF_CHUNKS"
STATUS_LOCAL.SW_DW_RENAME:
ret_val = "SW_DW_RENAME"
ret_val = ">>status " + ret_val
return ret_val
## console output status iternal
func _mapod4d_debug_status():
if _mapod4d_debug_status_flag:
var stack = get_stack()
if len(stack) > 1:
stack = str(stack[1])
else:
stack = ""
print("##_##{prog} {status}".format({
"prog": _mapod4d_debug_line,
"status": _status_to_str(),
}))
print("##_##{prog} +++ {stack}".format({
"prog": _mapod4d_debug_line,
"stack": str(stack),
}))
_mapod4d_debug_line += 1
if _mapod4d_debug_line > 10000:
_mapod4d_debug_line = 0
## console output iternal
func _mapod4d_debug(data):
if _mapod4d_debug_flag:
_mapod4d_debug_status()
var stack = get_stack()
if len(stack) > 1:
stack = str(stack[1])
else:
stack = ""
print("##_##{prog} {data}".format({
"prog": _mapod4d_debug_line,
"data": str(data),
}))
print("##_##{prog} +++ {stack}".format({
"prog": _mapod4d_debug_line,
"stack": str(stack),
}))
if _mapod4d_debug_status_flag == false:
_mapod4d_debug_line += 1
if _mapod4d_debug_line > 10000:
_mapod4d_debug_line = 0
## reset info status
func _reset_info_and_wait(error=null):
_mapod4d_debug_status()
_end_of_flow(error)
# reset
_op_type = OP_TYPE_LOCAL.NONE
_current_brick = 0
_dw_name = null
_download_file = null
_info = null
_url = null
_dir = null
if _dest_file != null:
_dest_file.close()
_dest_file = null
if _input_file_data != null:
_input_file_data.close()
_input_file_data = null
_input_file_data_read = false
_brick_name = null
_current_merging_brick = 0
_current_chunk = 0
_software_name = null
_tmp_dir = null
_sysop = null
_destination = null
_which = null
## sofware download vars
_ext = null
## metaverse download vars
_mapod4d_ver = null
_set_entry_0_status(STATUS_LOCAL.WAIT)
_set_status(STATUS_LOCAL.WAIT)
_mapod4d_debug_status()
## end of flow
func _end_of_flow(error):
var entry_0_status = _get_entry_0_status()
var status = _get_status()
match entry_0_status:
STATUS_LOCAL.WAIT:
pass
STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED:
if error == null:
if status == STATUS_LOCAL.SW_CHECK_ULC:
if _update_core or _update_launcher or _update_updater:
_child_update_msg(tr("UPDFOUND"))
software.enable_update_button()
software.disable_src_button()
else:
software.disable_update_button()
software.enable_src_button()
_child_update_msg(tr("NOUPDFOUND"))
else:
_child_update_msg(tr(error))
## set new status
func _set_status(status:STATUS_LOCAL):
_status = status
## return current status
func _get_status():
return _status
## set new status
func _set_entry_0_status(status:STATUS_LOCAL):
_entry_0_status = status
## return current status
func _get_entry_0_status():
return _entry_0_status
## send info to child
func _child_update_msg(msg):
if _which != null:
_which.update_msg(msg)
## send info to child
func _child_update_merge_info(data):
if _which != null:
_which.update_merge_info(data)
## update child info general download
func _update_info_wait():
if http_sw_dw_rq.get_http_client_status() == 7:
var bs = http_sw_dw_rq.get_downloaded_bytes()
var db = http_sw_dw_rq.get_body_size()
var perc = "%.2f" % 0
if db > 0:
perc = "%.2f" % ((float(bs) / float(db)) * 100.0)
var data = {
"bs": str(bs),
"db": str(db),
"perc": str(perc),
"info": str(_info),
"bricks": str(_info.bricks),
"brick": _current_brick + 1,
}
if _which != null:
_which.update_download_info(data)
## SOFTWARES SECTION
## DA NON FARE ENTRY 0 start software simple info request
func _on_info_software_requested(
software_name, ext, sysop, tmp_dir, destination, which):
_reset_info_and_wait()
_mapod4d_debug_status()
_op_type = OP_TYPE_LOCAL.SW_DW
_software_name = software_name
_ext = ext
_sysop = sysop
_tmp_dir = tmp_dir
_destination = destination
_which = which
_set_status(STATUS_LOCAL.SW_INFO_REQUESTED)
## ENTRY 0 start software download
func _on_software_dw_info_requested(
software_name, ext, sysop, tmp_dir, destination, which):
_reset_info_and_wait()
_set_entry_0_status(STATUS_LOCAL.SW_DW_INFO_REQUESTED)
_mapod4d_debug_status()
_op_type = OP_TYPE_LOCAL.SW_DW
_software_name = software_name
_ext = ext
_sysop = sysop
_tmp_dir = tmp_dir
_destination = destination
_which = which
_set_status(STATUS_LOCAL.SW_DW_INFO_REQUESTED)
## -------------------------------------- REORDER
## event request start software check updates
func _on_check_info_sw_updates_requested(which):
_check_info_sw_updates_requested(which)
## event request start searchsoftware updates
func _on_sw_search_updates_requested(which):
_sw_search_updates_requested(which)
## event request start software updates
func _on_sw_updates_requested(which):
_sw_updates_requested(which)
## ENTRY 0 base start (no actions)
func _start_requested():
_reset_info_and_wait()
software.enable_src_button()
# starting status
#_set_entry_0_status(STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED)
#_mapod4d_debug_status()
#_which = which
#_child_update_msg(tr("LOOKFORUPD"))
#_set_status(STATUS_LOCAL.SW_UPDATER_REQUEST_INIT)
## ENTRY 0 start software check updates
func _check_info_sw_updates_requested(which):
_reset_info_and_wait()
# starting status
_set_entry_0_status(STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED)
_mapod4d_debug_status()
_which = which
_child_update_msg(tr("LOOKFORUPD"))
_set_status(STATUS_LOCAL.SW_UPDATER_REQUEST_INIT)
## ENTRY 0 start search software updates
func _sw_search_updates_requested(which):
_reset_info_and_wait()
_set_entry_0_status(STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED)
_mapod4d_debug_status()
_which = which
_child_update_msg(tr("LOOKFORUPD"))
_set_status(STATUS_LOCAL.CHECK_INFO_SW_UPDATES_REQUESTED)
## ENTRY 0 start software updates
func _sw_updates_requested(which):
_reset_info_and_wait()
_set_entry_0_status(STATUS_LOCAL.SW_UPDATES_REQUESTED)
_mapod4d_debug_status()
_which = which
_child_update_msg(tr("LOOKFORUPD"))
if _update_updater == true:
_set_status(STATUS_LOCAL.SW_UPDATER_REQUEST_INIT)
elif _update_launcher == true:
_set_status(STATUS_LOCAL.SW_LAUNCHER_REQUEST_INIT)
elif _update_core == true:
_set_status(STATUS_LOCAL.SW_CORE_REQUEST_INIT)
else:
## no updates found
pass
## init software requested
func _sw_request_init():
_mapod4d_debug_status()
_op_type = OP_TYPE_LOCAL.SW_DW
_tmp_dir = _build_tmp_dir
var status = _get_status()
match status:
STATUS_LOCAL.SW_UPDATER_REQUEST_INIT:
_software_name = UPDATER_NAME
_ext = _os_info.exe_ext
_sysop = _os_info.os
# TODO prima era cosi'
#_destination = _build_updater_path
## used only for download
_destination = "%s%s.bin" % [_build_dest_dw_path, _software_name]
var entry_0_status = _get_entry_0_status()
if entry_0_status == STATUS_LOCAL.SW_UPDATES_REQUESTED:
_set_status(STATUS_LOCAL.SW_DW_INFO_REQUESTED)
else:
_set_status(STATUS_LOCAL.SW_INFO_UPDATER_REQUESTED)
STATUS_LOCAL.SW_LAUNCHER_REQUEST_INIT:
_software_name = LAUNCHER_NAME
_ext = _os_info.exe_ext
_sysop = _os_info.os
#_destination = "files/launcher"
## used only for download
_destination = "%s%s.bin" % [_build_dest_dw_path, _software_name]
var entry_0_status = _get_entry_0_status()
if entry_0_status == STATUS_LOCAL.SW_UPDATES_REQUESTED:
_set_status(STATUS_LOCAL.SW_DW_INFO_REQUESTED)
else:
_set_status(STATUS_LOCAL.SW_INFO_LAUNCHER_REQUESTED)
STATUS_LOCAL.SW_CORE_REQUEST_INIT:
_software_name = CORE_NAME
_ext = _os_info.exe_ext
_sysop = _os_info.os
#_destination = "files/core"
## used only for download
_destination = "%s%s.bin" % [_build_dest_dw_path, _software_name]
var entry_0_status = _get_entry_0_status()
if entry_0_status == STATUS_LOCAL.SW_UPDATES_REQUESTED:
_set_status(STATUS_LOCAL.SW_DW_INFO_REQUESTED)
else:
_set_status(STATUS_LOCAL.SW_INFO_CORE_REQUESTED)
## download software requested
func _sw_dw_info_requested():
_mapod4d_debug_status()
_url = MULTIVSVR + "/api/software/"
_url += _software_name + "/" + _sysop + "?format=json"
_mapod4d_debug(_url)
var headers = ["Content-Type: application/json"]
_download_file = _tmp_dir + "/" + BUF_NAME
http_sw_info_rq.request(_url, headers, HTTPClient.METHOD_GET)
var status = _get_status()
if status == STATUS_LOCAL.SW_INFO_REQUESTED:
_set_status(STATUS_LOCAL.SW_INFO_WAIT)
elif status == STATUS_LOCAL.SW_INFO_UPDATER_REQUESTED:
_set_status(STATUS_LOCAL.SW_INFO_UPDATER_WAIT)
elif status == STATUS_LOCAL.SW_INFO_LAUNCHER_REQUESTED:
_set_status(STATUS_LOCAL.SW_INFO_LAUNCHER_WAIT)
elif status == STATUS_LOCAL.SW_INFO_CORE_REQUESTED:
_set_status(STATUS_LOCAL.SW_INFO_CORE_WAIT)
else:
_set_status(STATUS_LOCAL.SW_DW_INFO_WAIT)
## info software download ended
func _on_sw_dw_info_completed(result, _response_code, _headers, body):
_mapod4d_debug_status()
_mapod4d_debug("progress")
if result == HTTPRequest.RESULT_SUCCESS:
var json = JSON.new()
json.parse(body.get_string_from_utf8())
_mapod4d_debug("BODY" + str(body.get_string_from_utf8()))
_mapod4d_debug("JSON" + str(json.get_data()))
_info = json.get_data()
if _info != null:
if 'detail' in _info:
_child_update_msg("ERROR " + _info.detail)
_reset_info_and_wait()
else:
var status = _get_status()
if status == STATUS_LOCAL.SW_DW_INFO_WAIT:
_mapod4d_debug(_info.bricks)
_dw_name = _info.link + "_"
_current_brick = 0
# SOLO DEBUG
#_info.bricks = 1
#_info.compressed = false
# SOLO DEBUG FINE
#if _info.bricks == 0: