-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAson.sh
executable file
·1231 lines (1065 loc) · 42.2 KB
/
Ason.sh
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
#!/bin/bash
##############################################################################################################################################################
# AUTOR: Paco Guerrero <[email protected]>
# PROJECT: ASON (Amazon on SteamOS Over Nile)
# ABOUT: script with the objective of displaying an interface, i.e. a frontend for the unofficial Amazon Games linux client called 'nile'.
#
# PARAMS: Nope.
# DEBUG MODE: run 'DEBUG=Y path-to-Ason/Ason.sh'
#
# REQUERIMENTS: NILE, YAD, JQ, SHORTCUTSNAMEID, WGET, SHUF, FILE, FIND, ... gnu utils :D
#
# EXITs:
# 0 --> OK!!!.
# 1 --> Missing required component.
# 99 -> No login...
##############################################################################################################################################################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#! GLOBAL VARIABLES
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Basic
NOMBRE="ASON - [Amazon Games on Steam OS over Nile]"
VERSION=2.1
# Config files of nile
NILEUSER="$HOME/.config/nile/user.json"
NILELIBR="$HOME/.config/nile/library.json"
NILEINSTALLED="$HOME/.config/nile/installed.json"
# Where is the app and binaries
ASONPATH=$(readlink -f "$(dirname "$0")")
ASONBIN="$ASONPATH/bin"
ASONCACHE="$HOME/.cache/ason/"
YAD="$ASONBIN/yad"
NILE="$ASONBIN/nile"
JQ="$ASONBIN/jq"
NAMEID="$ASONBIN/shortcutsNameID"
GRIDER="$ASONBIN/grider"
# Locations
DIRINSTALL="$HOME/Games"
DEBUGFILE="$ASONPATH/debug.log"
# Config files of Ason
ASONOPTIONFILE="$HOME/.config/nile/ason.config"
# Queue for download
QASON="$ASONCACHE""/ason.donwload"
# Pid of downloader
PID_DOWNLOADER=
# IMG dir
ASONIMAGES="$ASONPATH/img/"
ASONSIMGPLASH="$ASONIMAGES/splash/"
ASONIMGMAIN="$ASONIMAGES/main/"
ASONLOGO="$ASONIMAGES/Ason_64.jpeg"
ASONWARNING="$ASONIMAGES/Ason_warning.png"
ASONCOMPATING="$ASONIMAGES/Ason_compatibility.png"
#* Tittle and share Window components
TITTLE="--title=$NOMBRE - $VERSION"
ICON="--window-icon=$ASONLOGO"
# Set language
case "$LANG" in
es_ES.UTF-8)
lNOLOGIN="\n\nAson no ha podido encontrar la informacion necesaria para poder inicar en Amazon Games.\n\n\nPor favor, <b>haz login correctamente</b>."
lLIBRARY=Biblioteca
lINSTALLED=Instalado
lOPTIONS=Opciones
lEXIT=Salir
lEXITMSG='Espero que hayas disfrutado de ASON. Hasta pronto.'
lDOWNLOADSM='Descargas'
lNODOWLOADS='No hay descargas en curso.'
lGAME='Juego'
lTITTLE='Titulo'
lGENRE='Genero'
lDETAILS='Detalles'
lBACK='Volver'
lINSTALL='Instalar'
lUNINSTALL='Desinstalar'
lDELETE='Borrar'
lNOINSTALLED='No hay juegos instalados'
lPATH='Ruta'
lUNINSTALLED='Desinstalado'
lUNINSTALLING='Desinstalando'
lADDDOWNLOAD='Añadido a la cola de descargas'
lSEARCH='Buscar'
lSYNC='Sincronizar'
lADDMENU='Add Steam...'
lUPDATE='Actualizar'
lUPDATING='Actualizando'
lSYNCHRONIZING='Sincronizando'
lREFRESH='Refrescar'
lWAIT='Esperar'
lASKWAIT='Hay descargas en curso.\n\n¿Quieres esperar a que terminen antes de salir?'
lALLSTOPED='Todos los procesos han sido detenidos'
lALLNOSTOPED='Cerrando Ason pero continuando las descargas en segundo plano.\n\nAparecera un mensaje al finalizar'
lOLWHERE='Donde quieres guardar los juegos descargados?'
lOLGRID='Clave para descargar grids desde Steamgriddb'
lODGAMESPATH='Ruta de descarga'
lSAVE='Guardar'
lABOUT='Acerca de'
lADREBOOT='Es necesario reiniciar Ason para iniciar con los nuevos cambios'
lREMEMBERADDSTEAM='Ya tienes tu juego en Steam.\n\n<b>MUY IMPORTANTE</b>, debes de configurar su compatibilidad de Proton desde Steam.\
Si no haces este cambio, probablemente <b>el juego no va a funcionar</b>.\n\nRecuerda, los juegos son gestionados y configurados desde Steam.'
lSUREADDSTEAM='Estas <b>SEGURO</b> de que tu quieres add to Steam este juego?\n\nEs posible que el juego sea duplicado si ya lo instalaste anteriormente.\
\n\n<b>RECUERDA</b>:\n\n\tGestiona tus juegos desde Steam.'
lSCREENSHOTS='Screenshots'
lSUREUNINSTALL='¿Estas <b>SEGURO</b> de que tu quieres desinstalar este juego y borrar su carpeta de instalación?\
\n\n<b>RECUERDA</b>: podría contener información valiosa del juego como saves.'
lURL='<b>Pega aquí</b> la url tras iniciar sesión'
lTEXTLOGIN1='A continuación se abrirá en tu navegador por defecto una web de inicio de sesión en Amazon.\n\nPor favor, <b>inicia sesión</b> en Amazon en esa ventana.'
lTEXTLOGIN2="Por último, tras acabar el login de forma correcta, <b>copia</b> la url a la que te redirigió Amazon (generalmente la tienda)."
;;
*)
lNOLOGIN="\n\nAson could not find the information needed to login to Amazon Games.\n\n\nPlease, <b>login correctly</b>."
lLIBRARY=Library
lINSTALLED=Installed
lOPTIONS=Options
lEXIT=Exit
lEXITMSG='Thanks for use ASON. Bye Bye...'
lDOWNLOADSM='Downloads'
lNODOWLOADS='There are no downloads in progress.'
lGAME='Game'
lTITTLE='Tittle'
lGENRE='Genre'
lDETAILS='Details'
lBACK='Back'
lINSTALL='Install'
lUNINSTALL='Uninstall'
lDELETE='Delete'
lNOINSTALLED='There are no installed games.'
lPATH='Path'
lUNINSTALLED='Uninstalled'
lUNINSTALLING='Uninstalling'
lADDDOWNLOAD='Add to download'
lSEARCH='Search'
lSYNC='Sync'
lADDMENU='Add Steam...'
lUPDATE='Update'
lUPDATING='Updating'
lSYNCHRONIZING='Synchronizing'
lREFRESH='Refresh'
lWAIT='Wait'
lASKWAIT='There are downloads in progress.\n\nDo you want to wait for them to finish before exiting?'
lALLSTOPED='All processes have been stopped.'
lALLNOSTOPED='Closing Ason but continuing downloads in the background.\n\nA message will appear when finished.'
lOLWHERE='Where do you want to save the downloaded games?'
lOLGRID='Key for download grids from steamgriddb'
lODGAMESPATH='Download path'
lSAVE='Save'
lABOUT='About'
lADREBOOT='You have to close Ason to load the new configuration.'
lREMEMBERADDSTEAM='You just have the game add to Steam.Now, <b>VERY IMPORTANT</b>, you must configure its Proton compatibility in the game.\
\n\nIf you do not change the compatibility option on the Steam Game, you can not run the game.\n\n\nGames are managed and configured directly from Steam.'
lSUREADDSTEAM='Are you <b>SURE</b> you want to add to Steam this game?\n\nIt is possible that the game will be duplicated if you have already installed it.\
\n\n<b>REMEMBER</b>:\n\n\tManage the game from Steam directly.'
lSCREENSHOTS='Screenshots'
lSUREUNINSTALL='Are you <b>SURE</b> you want to uninstall this game and delete its installation folder?\
\n\n<b>REMEMBER</b>: it might contain valuable game information such as saves'.
lURL='<b>Paste here</b> the url after logging in to Amazon'
lTEXTLOGIN1='An Amazon login website will then open in your browser by default.\n\nPlease <b>login</b> to Amazon in that tab.'
lTEXTLOGIN2="Finally, after finishing the login correctly, <b>copy</b> the url to which Amazon redirected you (usually the web store)."
;;
esac
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#! FUNCTIONS
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
##
# Should be updated? - check the last stable version on The Internet
#
should_be_updated(){
local __file=__OLDVERSION=
__OLDVERSION="$ASONPATH/$(basename "$0").old"
local __URL_UPDATER="https://raw.githubusercontent.com/FranjeGueje/Ason/master/Updating/updating"
__file=$(basename "$0").lastversion && [ -f "$__file" ] && rm "$__file"
if ! wget -O "$__file" -q "$__URL_UPDATER" ;then
[ -n "$DEBUG" ] && to_debug_file "[WARNING] UPDATER: Cannot download the latest script version from Internet."
echo "[WARNING] Cannot download the latest script version."
else
local __BIG_VERSION=__SMALL_VERSION=__ACTUAL_BIG_VERSION=__ACTUAL_SMALL_VERSION=__VERSION_UPDATE=__UPDATE_DATA=
__VERSION_UPDATE=$(grep 'VERSION=' "$__file" | head -n 1 | cut -d '=' -f 2)
__BIG_VERSION=$(echo "$__VERSION_UPDATE" | cut -d '.' -f 1)
__SMALL_VERSION=$(echo "$__VERSION_UPDATE" | cut -d '.' -f 2)
__ACTUAL_BIG_VERSION=$(echo "$VERSION" | cut -d '.' -f 1)
__ACTUAL_SMALL_VERSION=$(echo "$VERSION" | cut -d '.' -f 2)
__UPDATE_DATA=$(grep 'UPDATE_DATA=' "$__file" | head -n 1 | cut -d '=' -f 2)
if [[ $__BIG_VERSION -gt $__ACTUAL_BIG_VERSION || ($__BIG_VERSION -eq $__ACTUAL_BIG_VERSION && $__SMALL_VERSION -gt $__ACTUAL_SMALL_VERSION) ]];then
[ -n "$DEBUG" ] && to_debug_file "[INFO] UPDATER: It's necesary updating to version $__VERSION_UPDATE"
local __extract_folder=/tmp/Ason_update
[ -d "$__extract_folder" ] && rm -Rf "$__extract_folder"
mkdir -p "$__extract_folder"
show_msg "Ason is updating" &
if wget -O "$__file".zip -q "$__UPDATE_DATA" ;then
unzip "$__file".zip -d "$__extract_folder" >/dev/null 2>&1
rm -rf "${ASONPATH:?}/"* && mv "$__extract_folder"/*/* "$ASONPATH"/.
rm -Rf "$__file".zip "$__file"
fi
[ -d "$__extract_folder" ] && rm -Rf "$__extract_folder"
echo "[WARNING] $NOMBRE is updated. Please, rerun this tool!"
show_msg "Ason is updated. Please, rerun Ason."
exit 0
else
[ -n "$DEBUG" ] && to_debug_file "[INFO] UPDATER: Not necesary updating. The actual version is $VERSION and the web is $__VERSION_UPDATE"
fi
fi
[ -f "$__file" ] && rm "$__file"
}
##
# get_nile_title
# Show a message on screen
# return The title of game.
#
# $1 = source varname ( id of Amazon Game )
# return The title of game.
#
function get_nile_title() {
local __id=$1
# Requisite of jq
# shellcheck disable=SC2016
iconv -c "$NILELIBR" | "$JQ" -r --arg v "$__id" '.[] | select (.product.id == $v ) | .product.title '
}
##
# get_nile_logo
# Show a message on screen
# return The logo file of game.
#
# $1 = source varname ( id of Amazon Game )
# return The logo file of game.
#
function get_nile_logo() {
local __id=$1
# Requisite of jq
# shellcheck disable=SC2016
iconv -c "$NILELIBR" | "$JQ" -r --arg v "$__id" '.[] | select (.product.id == $v ) | .product.productDetail.details.logoUrl ' | sed "s|https://m.media-amazon.com/images/I/|$ASONCACHE|g"
}
##
# get_nile_image
# Show a message on screen
# return The image file of game.
#
# $1 = source varname ( id of Amazon Game )
# return The image file of game.
#
function get_nile_image() {
local __id=$1
# Requisite of jq
# shellcheck disable=SC2016
iconv -c "$NILELIBR" | "$JQ" -r --arg v "$__id" '.[] | select (.product.id == $v ) | .product.productDetail.details.pgCrownImageUrl ' | sed "s|https://m.media-amazon.com/images/I/|$ASONCACHE|g"
}
##
# get_nile_screenshots
# Show a message on screen
# return All screenshots files of game.
#
# $1 = source varname ( id of Amazon Game )
# return All screenshots files of game.
#
function get_nile_screenshots() {
local __id=$1
# Requisite of jq
# shellcheck disable=SC2016
iconv -c "$NILELIBR" | "$JQ" -r --arg v "$__id" '.[] | select (.product.id == $v ) | .product.productDetail.details.screenshots[] '
}
##
# get_nile_detail
# Show a message on screen
# return The details of game.
#
# $1 = source varname ( id of Amazon Game )
# return The details of game.
#
function get_nile_detail() {
local __id=$1
# Requisite of jq
# shellcheck disable=SC2016
iconv -c "$NILELIBR" | "$JQ" -r --arg v "$__id" '.[] | select (.product.id == $v ) | "\(.product.productDetail.details.releaseDate)|\(.product.productDetail.details.developer)|\(.product.productDetail.details.publisher)|\(.product.productDetail.details.esrbRating)|\(.product.productDetail.details.genres)|\(.product.productDetail.details.gameModes)|\(.product.productDetail.details.shortDescription)|\(.product.productDetail.details.screenshots)"'
}
##
# get_nile_path_installed_game
# Show a message on screen
# return path of a installed game.
#
# $1 = source varname ( id of Amazon Game )
# return path of a installed game.
#
function get_nile_path_installed_game() {
local __id=$1
# Requisite of jq
# shellcheck disable=SC2016
iconv -c "$NILEINSTALLED" | "$JQ" -r --arg v "$__id" '.[] | select (.id == $v ) | .path'
}
##
# to_debug_file
# Save a msg to debug
#
# $1 = Text to Debub file
#
function to_debug_file() {
echo -e "$1" >>"$DEBUGFILE"
}
##
# requisites
# Show the detail of a game
#
function requisites() {
local __other_requisites=("wget" "iconv" "shuf")
local __test=
if [ ! -f "$YAD" ]; then
if __test=$(which "yad" 2>/dev/null); then
[ -n "$DEBUG" ] && to_debug_file "DBG: Using yad from $__test"
YAD=$__test
else
[ -n "$DEBUG" ] && to_debug_file "DBG: Missing required component yad"
echo "Missing required component yad" && exit 1
fi
fi
if [ ! -f "$NILE" ]; then
if __test=$(which "nile" 2>/dev/null); then
[ -n "$DEBUG" ] && to_debug_file "DBG: Using nile from $__test"
NILE=$__test
else
[ -n "$DEBUG" ] && to_debug_file "DBG: Missing required component nile"
echo "Missing required component nile" && exit 1
fi
fi
if [ ! -f "$JQ" ]; then
if __test=$(which "jq" 2>/dev/null); then
[ -n "$DEBUG" ] && to_debug_file "DBG: Using jq from $__test"
JQ=$__test
else
[ -n "$DEBUG" ] && to_debug_file "DBG: Missing required component jq"
echo "Missing required component jq" && exit 1
fi
fi
for i in "${__other_requisites[@]}"; do
if ! __test=$(which "$i" 2>/dev/null); then
[ -n "$DEBUG" ] && to_debug_file "DBG: Missing required component jq"
echo "Missing required component $i" && exit 1
fi
done
# Magick is optional
if [ -f "$ASONBIN/magick" ]; then
MAGICK="$ASONBIN/magick"
fi
[ -d "$QASON" ] || mkdir -p "$QASON"
}
##
# fileRandomInDir
# Return a random file from dir.
#
# $1 = source varname ( dir )
# return The random file in dir.
#
function fileRandomInDir() {
local __dir=$1
find "$__dir" -mindepth 0 -maxdepth 1 -type f | shuf -n 1
}
##
# download_grid
# Download the grids for a game
#
# $1 = Name of game
#
function download_grid() {
local __NOMBRE=$1
local __ANAMEID="/tmp/ason.nameID"
local __ANAMES="/tmp/ason.names"
local __AGRIDS="/tmp/ason.grid"
[ -n "$GRIDKEY" ] || GRIDKEY=0
mkdir -p "$__AGRIDS"
rm -f "$__ANAMEID"
sleep 3
find "$HOME/.local/share/Steam/userdata/" -name "shortcuts.vdf" -type f -exec "$NAMEID" {} \; >> "$__ANAMEID"
cut -f1 -d $'\t' "$__ANAMEID" > "$__ANAMES"
if grep -w "$__NOMBRE".bat < "$__ANAMES" >/dev/null ; then
local __id=
__id=$(grep -m 1 "$__NOMBRE".bat$'\t' < "$__ANAMEID" | cut -f2 -d $'\t')
"$GRIDER" -dest "$__AGRIDS" "$GRIDKEY" "$__NOMBRE" "$__id"
for dir in "$HOME"/.local/share/Steam/userdata/*/; do
cp "$__AGRIDS"/* "$dir/config/grid/"
done
rm -f $__AGRIDS/*
fi
}
##
# get_cache
# Download the cache images from internet.
#
# $1 = source varname ( url to download )
# $2 = target filename ( file to save the download )
# $3 = size limit (in format widthxheight)
#
function get_cache() {
local __url=$1
local __file=$2
local __limit=$3
local __w=
__w=$(echo "$__limit" | cut -d 'x' -f1)
wget "$__url" -O "$__file" >/dev/null 2>/dev/null && file "$__file" | grep -v "$__w" && [ -n "$MAGICK" ] && "$MAGICK" convert "$__file" -resize "$__limit"'>' "$__file"
[ -n "$DEBUG" ] && to_debug_file "DBG: Download image $__url to $__file"
}
##
# cache
# Check or generate the cache of ASON
#
function cache() {
local __ACACHED=/tmp/ason.cached
local __ACACHING=/tmp/ason.to_caching
local __ACACH_REQ=/tmp/ason.required_cache
local __ASONCACHEVER="$ASONCACHE""cache/ason.versioncache"
#***This new version, does it need recaching??
local __need_recaching=Y
[ "$__need_recaching" == 'Y' ] && if [ ! -f "$__ASONCACHEVER" ] || [ "$(cat "$__ASONCACHEVER")" != "$VERSION" ]; then
# Remove old cache because change of ver
find "$ASONCACHE" -mindepth 0 -maxdepth 1 -type f -exec rm -f {} \;
fi
# All necessary cache
local __A= ; __A=$("$JQ" -r -c '.[].product.productDetail.details | "\(.logoUrl)\n\(.pgCrownImageUrl)"' "$NILELIBR" | grep -w -v null | sed "s|https://m.media-amazon.com/images/I/||g" | sort | uniq)
# Get local cache
find "$ASONCACHE" -mindepth 0 -maxdepth 1 -type f | sed "s|$ASONCACHE||g" | sort | uniq >"$__ACACHED"
[ "$__A" == "$(cat "$__ACACHED")" ] && echo 100 && return
[ -n "$DEBUG" ] && to_debug_file "DBG: Necessary caching!!"
# Get necesary cache (LOGO)
"$JQ" -r -c .[].product.productDetail.details.logoUrl "$NILELIBR" | grep -w -v null | sed "s|https://m.media-amazon.com/images/I/||g" >"$__ACACHING"
if grep -vFf "$__ACACHED" <"$__ACACHING" >"$__ACACH_REQ"; then
local __num=
__num=$(wc -l <"$__ACACH_REQ")
local __counter=0
local __file=
# Get the logo image
while read -r __url; do
__file=$ASONCACHE/$(basename "$__url")
[ ! -f "$__file" ] && get_cache "$__url" "$__file" "400x225" &
echo $((__counter * 50 / __num))
((__counter++))
done < <("$JQ" -r -c .[].product.productDetail.details.logoUrl "$NILELIBR" | grep -w -v null | grep -Ff "$__ACACH_REQ")
fi
# Get necesary cache (IMAGE DETAIL)
"$JQ" -r -c .[].product.productDetail.details.pgCrownImageUrl "$NILELIBR" | grep -w -v null | sed "s|https://m.media-amazon.com/images/I/||g" >"$__ACACHING"
if grep -vFf "$__ACACHED" <"$__ACACHING" >"$__ACACH_REQ"; then
local __num=
__num=$(wc -l <"$__ACACH_REQ")
local __counter=0
local __file=
# Get the detail image
while read -r __url; do
__file=$ASONCACHE/$(basename "$__url")
[ ! -f "$__file" ] && get_cache "$__url" "$__file" "512x288" &
echo $((50 + __counter * 50 / __num))
((__counter++))
done < <("$JQ" -r -c .[].product.productDetail.details.pgCrownImageUrl "$NILELIBR" | grep -w -v null | grep -Ff "$__ACACH_REQ")
fi
rm "$__ACACHED" "$__ACACHING" "$__ACACH_REQ"
# Save the cache version
mkdir -p "$ASONCACHE"cache ; echo "$VERSION" > "$__ASONCACHEVER"
}
##
# delete_old_cache
# Delete all old cache of Ason
#
function delete_old_cache() {
#Old files for cache purposes
local ASONTITFILE="$ASONCACHE""/ason.tit"
local ASONIDNAME="$ASONCACHE""/ason.id-name"
local ASONIMGFILE="$ASONCACHE""/ason.img"
local ASONIMGDFILE="$ASONCACHE""/ason.img_detail"
local ASONGENFILE="$ASONCACHE""/ason.gen"
local ASONNULL="$ASONCACHE""/null"
rm "$ASONTITFILE" "$ASONIMGFILE" "$ASONIMGDFILE" "$ASONGENFILE" "$ASONCACHE/ason.versioncache" "$ASONIDNAME" "$ASONNULL" 2>/dev/null
}
##
# reload_library
# Load in memory the Library of ASON
#
# $1 = source varname ( [OPTIONAL] text to search)
#
function reload_library() {
#! REMEMBER: ID + Logo + Title + Genre
__search=$1
# Requisite of jq
# shellcheck disable=SC2016
readarray -t -d '|' \
ALIB < <("$JQ" -r -j --arg v "$__search" '.[] | select(.product.title | ascii_downcase | contains ($v)) | "\(.product.id)|\(.product.productDetail.details.logoUrl)|\(.product.title)|\(.product.productDetail.details.genres[0])|"' "$NILELIBR" | sed "s|https://m.media-amazon.com/images/I/|$ASONCACHE|g" | iconv -c)
[ -n "$DEBUG" ] && to_debug_file "DBG: RELOAD LIBRARY:\n ${ALIB[*]}"
}
##
# downloader_daemon
# Downloader main daemon
#
# $1 = source varname ( contains pid of father process )
#
function downloader_daemon() {
# PID of father
local __fpid=$1
# File that is downloading
local __file_downloading=
# Name of downloading file
local __downloading=
# Queue of files to download
local __files=
# Name of game
local __name=
# Image of game
local __image=
[ -d "$QASON" ] || mkdir -p "$QASON"
find "$QASON" -type f -exec rm -Rf {} \;
[ -n "$DEBUG" ] && to_debug_file "Downloader: Starting the Descargador."
while kill -0 "$__fpid" 2>/dev/null || [ "$(ls -A "$QASON")" ]; do
if [ "$(ls -A "$QASON")" ]; then
__files=("$QASON"/*)
__file_downloading="${__files[0]}"
__downloading=$(basename "$__file_downloading")
__name=$(cut -d '|' -f1 <"$__file_downloading")
__image=$(cut -d '|' -f2 <"$__file_downloading")
{
echo "Downloader: Downloading a game with ID: $__downloading and name $__name"
[ ! -d "$DIRINSTALL" ] && mkdir -p "$DIRINSTALL"
"$NILE" install --base-path "$DIRINSTALL" "$__downloading"
echo "Downloader: Finish the game with ID: $__downloading and name $__name"
} >>"$DEBUGFILE" 2>>"$DEBUGFILE"
sleep 0.5
if [ -f "$__file_downloading" ]; then
rm "$__file_downloading"
show_msg "$lINSTALLED" "$__image"
[ -n "$DEBUG" ] && to_debug_file "Downloader: Installed $lINSTALLED $__image"
else
[ -n "$DEBUG" ] && to_debug_file "Downloader: Uninstalling $__downloading because the user deleted it from the queue"
"$NILE" uninstall "$__downloading" >>"$DEBUGFILE" 2>>"$DEBUGFILE"
[ -n "$DEBUG" ] && to_debug_file "Downloader: Uninstalled $__downloading because the user deleted it from the queue"
fi
else
sleep 5
fi
done
[ -n "$DEBUG" ] && to_debug_file "Downloader: Exiting of descargador."
}
##
# add_download
# Add a game to download
#
# $1 = source varname ( contains the ID (of game) )
#
function add_download() {
local __id=$1
local __name=
__name=$(get_nile_title "$__id")
local __image=
__image=$(get_nile_logo "$__id")
echo -ne "$__name|$__image" | iconv -c >"$QASON/$__id"
[ -n "$DEBUG" ] && to_debug_file "Downloader: Add to download queue the $(echo -ne "$__name|$__image" | iconv -c)"
}
##
# add_steam_game
# Add a game to Steam
#
# $1 = source varname ( The executable of game )
#
function add_steam_game() {
if ! grep -i "x-scheme-handler/steam=" <"$HOME"/.config/mimeapps.list >/dev/null 2>/dev/null; then
echo "x-scheme-handler/steam=steam.desktop;" >>"$HOME"/.config/mimeapps.list
fi
#x-scheme-handler/steam=steam.desktop;
local __encodedUrl=
__encodedUrl="steam://addnonsteamgame/$(python3 -c "import urllib.parse;print(urllib.parse.quote(\"$1\", safe=''))")"
touch /tmp/addnonsteamgamefile
xdg-open "$__encodedUrl" >>"$DEBUGFILE"
[ -n "$DEBUG" ] && to_debug_file "DBG: Add to steam the url:\n$__encodedUrl\n"
}
##
# create_bat_file
# Create the bat file for windows. Create a bat script (for Windows). This script 1st install dependencies, then run the game
#
# $1 = source varname ( The tittle of game )
# S2 = source varname ( The path of game )
#
function create_bat_file() {
local __name=$1
local __path=$2
local __F=$__path/fuel.json
local __exec=
local __dep=
__exec="$("$JQ" .Main.Command "$__F") $("$JQ" -r '.Main.Args | @sh' "$__F")"
local __dep=
local __num=
local __args=
local ARG=()
__num=$("$JQ" ".PostInstall | length" "$__F")
for ((i = 0; i < __num; i++)); do
__args=$("$JQ" ".PostInstall[$i].Args | length" "$__F")
ARG=()
for ((j = 0; j < __args; j++)); do
ARG+=("$("$JQ" -r ".PostInstall[$i].Args[$j]" "$__F")")
done
__dep+="\n$("$JQ" ".PostInstall[$i].Command" "$__F") ${ARG[*]}"
done
local __ason_bat="@echo off\n\n\
IF EXIST c:\\\\ason.dependencies (\n\
REM Dependencies are installed\n\
)ELSE (\n\
REM To install the dependencies\n\
echo Intalling dependencies\n\
$__dep \n\
echo Installed > c:\\\\ason.dependencies \n\
)\n\
REM Run the app\n\
echo Run Game...\n\
START \"\" $__exec \n\
\n\
exit 0"
[ -n "$DEBUG" ] && to_debug_file "DBG: Generated the bat file with content:\n $__ason_bat \n"
echo -ne "$__ason_bat" >"$__path/$__name".bat
[ -n "$DEBUG" ] && to_debug_file "DBG: Created the bat file in $__path/$__name.bat"
echo -ne "$__ason_bat" >"$__path/ason.bat"
[ -n "$DEBUG" ] && to_debug_file "DBG: Created the bat file in $__path/ason.bat"
echo -ne "$__dep" >"$__path/ason.dependencies.bat"
[ -n "$DEBUG" ] && to_debug_file "DBG: Created the DEPENDENCIES bat file in $__path/ason.dependencies.bat"
}
##
# show_msg
# Show a message on screen
#
# $1 = source varname ( Text to show )
# $2 = source varname ( [OPTIONAL] image to show )
#
function show_msg() {
if [ -n "$2" ]; then
"$YAD" "$TITTLE" "$ICON" --center --no-buttons --on-top --align=center --timeout=2 --undecorated --text="$1" --image="$2" --no-markup
else
"$YAD" "$TITTLE" "$ICON" --center --no-buttons --on-top --align=center --timeout=2 --undecorated --text="$1" --no-markup
fi
}
##
# dologin
# Login on Amazon Games over Nile.
#
function dologin() {
[ -n "$DEBUG" ] && to_debug_file "DBG: Doing login"
#"$NILE" auth --login --no-sandbox
local __token=__client_id=__code_verifier=__serial=__url=__code=__auth_code=
__token=$("$NILE" auth -l --non-interactive)
__client_id=$(echo "$__token" | $JQ -r ."client_id")
__code_verifier=$(echo "$__token" | $JQ -r ."code_verifier")
__serial=$(echo "$__token" | $JQ -r ."serial")
__url=$(echo "$__token" | $JQ -r ."url")
"$YAD" "$TITTLE" "$ICON" --center --on-top --align=center --undecorated --text="$lTEXTLOGIN1" --button="ok":0 --width=400 --height=20
xdg-open "$__url" >/dev/null 2>&1
local __salida=
__salida=$("$YAD" "$TITTLE" "$ICON" --text="$lTEXTLOGIN2" \
--columns=1 --form --button="$lEXIT":1 --button="Enter":0 --buttons-layout=edge --align=center --field="$lURL":)
local __boton=$?
if [ "$__boton" -eq 0 ];then
__auth_code=$(echo "$__salida" | cut -d '|' -f1)
__code=${__auth_code##*openid.oa2.authorization_code=}
__code=${__code%%&*}
"$NILE" register --code "$__code" --client-id "$__client_id" --code-verifier "$__code_verifier" --serial "$__serial"
else
[ -n "$DEBUG" ] && to_debug_file "DBG: The user cancelled the login form."
show_msg "Exiting from Ason"
exit 99
fi
[ -n "$DEBUG" ] && to_debug_file "DBG: Login exit"
}
##
# dologout
# Logout on Amazon Games over Nile.
#
function dologout() {
[ -n "$DEBUG" ] && to_debug_file "DBG: Doing Logout"
"$NILE" auth --logout
[ -n "$DEBUG" ] && to_debug_file "DBG: Logout exit"
}
##
# load_options
# Load the options from the file
#
function load_options() {
if [ -f "$ASONOPTIONFILE" ]; then
[ -n "$DEBUG" ] && to_debug_file "DBG: using the options of file $ASONOPTIONFILE"
DIRINSTALL=$(cut -d '|' -f1 <"$ASONOPTIONFILE")
GRIDKEY=$(cut -d '|' -f2 <"$ASONOPTIONFILE")
else
[ -n "$DEBUG" ] && to_debug_file "DBG: Using the default options"
fi
}
##
# loadingW
# The global process to caching
#
function loadingW() {
# PID of the new dialog
local __pid=
# splash Window
"$YAD" "$TITTLE" --center --splash --on-top --image="$(fileRandomInDir "$ASONSIMGPLASH")" --no-buttons &
__pid=$!
[ -d "$ASONCACHE" ] || mkdir -p "$ASONCACHE"
[ -n "$DEBUG" ] && to_debug_file "DBG: Generating the cache"
delete_old_cache
cache | "$YAD" "$ICON" --on-top --text="Caching..." --progress --auto-close --no-buttons --undecorated --no-escape --no-markup
[ -n "$DEBUG" ] && to_debug_file "DBG: Cache generated"
[ -n "$DEBUG" ] && to_debug_file "DBG: Load options"
load_options
[ -n "$DEBUG" ] && to_debug_file "DBG: Reload Library"
# Kill the splash windows
kill $__pid
}
##
# mainW
# Show the MAIN Window
#
function mainW() {
"$YAD" "$TITTLE" --center --image="$(fileRandomInDir "$ASONIMGMAIN")" --sticky --buttons-layout=spread --no-markup \
--button=$lLIBRARY:0 --button=$lINSTALLED:1 --button=$lOPTIONS:2 --button="$lDOWNLOADSM":3 --button="$lEXIT":100 "$ICON" --fixed --on-top
MENU=$?
}
##
# libraryW
# Show the LIBRARY Window
#
# $1 = source varname ( [OPTIONAL] text to search)
#
function libraryW() {
local __search=$1
if [ -n "$__search" ]; then
reload_library "$__search"
else
reload_library
fi
# Result of YAD dialog
local __salida=
local __boton=0
[ -n "$DEBUG" ] && to_debug_file "DBG: Showing the library list:\n${ALIB[*]}"
while [ $__boton -ne 1 ] && [ $__boton -ne 252 ]; do
__salida=$("$YAD" "$TITTLE" "$ICON" --center --on-top --list --width=1280 --height=800 --hide-column=1 --sticky --no-markup --buttons-layout=spread \
--button="$lBACK":1 --button="$lSEARCH":3 --button="$lDETAILS":0 --button="$lSYNC":4 --button="$lINSTALL":2 \
--column=ID --column="$lGAME":IMG --column="$lTITTLE" --column="$lGENRE" "${ALIB[@]}")
local __boton=$?
local __id=
__id=$(echo "$__salida" | cut -d'|' -f1)
case $__boton in
0) # Details
[ -n "$DEBUG" ] && to_debug_file "DBG: Get game detail of $__id ID"
gameDetailW "$__id"
;;
2) # Install
local __name=
__name=$(echo "$__salida" | cut -d'|' -f3)
show_msg "$lADDDOWNLOAD" "$(get_nile_logo "$__id")"
add_download "$__id"
;;
3) # Buscar
__salida=$("$YAD" "$TITTLE" "$ICON" --center --on-top --no-escape --button="OK":0 --form --field="$lSEARCH:")
__salida=${__salida::-1}
__salida=$(echo "$__salida" | tr '[:upper:]' '[:lower:]')
[ -n "$DEBUG" ] && to_debug_file "DBG: Searching the title:\n$__salida\n"
libraryW "$__salida"
break
;;
4) # Sincronizar
show_msg "$lSYNCHRONIZING..." &
local __num= && local __num_new=
__num=$($JQ ". | length" "$NILELIBR")
"$NILE" library sync 2>"$DEBUGFILE"
__num_new=$($JQ ". | length" "$NILELIBR")
if [ "$__num" -ne "$__num_new" ]; then
[ -n "$DEBUG" ] && to_debug_file "DBG: The library is changed"
loadingW
break
fi
;;
*) ;;
esac
done
}
##
# download_managerW
# Show the downloads queue
#
function download_managerW() {
# Result of YAD dialog
local __salida=
local __boton=0
while [ $__boton -ne 1 ] && [ $__boton -ne 252 ]; do
if [ "$(ls -A "$QASON")" ]; then
# List of downloads
local __descargas=
# Name of game
local __name=
# Image of game
local __image=
# List of Ason's download
local __ADOWN=()
__descargas=("$QASON"/*)
[ "${#__descargas[@]}" -eq 0 ] || for i in "${__descargas[@]}"; do
__name=$(cut -d '|' -f1 <"$i")
__image=$(cut -d '|' -f2 <"$i")
__ADOWN+=("$i" "$__image" "$__name")
done
local __salida=
__salida=$("$YAD" "$TITTLE" "$ICON" --center --list --width=1280 --height=800 --hide-column=1 --sticky --no-markup --buttons-layout=spread \
--column=File --column="$lGAME":IMG --column="$lTITTLE" --button="$lBACK":1 --button="$lREFRESH":2 --button="$lDELETE":0 "${__ADOWN[@]}")
local __boton=$?
if [ "$__boton" -eq 0 ]; then
[ -n "$DEBUG" ] && to_debug_file "DBG: Deleting the download $(echo "$__salida" | cut -d'|' -f1)"
rm "$(echo "$__salida" | cut -d'|' -f1)"
fi
else
show_msg "$lNODOWLOADS"
__boton=1
fi
done
}
##
# gameDetailW
# Show the detail of a game
#
# $1 = source varname ( contains the ID of game in Amazon Games)
#
function gameDetailW() {
local __id=$1
local __fecha=
local __developer=
local __publicador=
local __esrb=
local __generos=
local __modos=
local __desc=
local __info=
__info=$(get_nile_detail "$__id")
__fecha=$(echo "$__info" | cut -d '|' -f1 | iconv -c)
__fecha="${__fecha:0:10}"
__developer=$(echo "$__info" | cut -d '|' -f2 | iconv -c)
__publicador=$(echo "$__info" | cut -d '|' -f3 | iconv -c)
__esrb=$(echo "$__info" | cut -d '|' -f4 | iconv -c)
__generos=$(echo "$__info" | cut -d '|' -f5 | iconv -c)
__modos=$(echo "$__info" | cut -d '|' -f6 | iconv -c)
__desc=$(echo "$__info" | cut -d '|' -f7 | iconv -c)
local __text=
__text="Rel. Date: $__fecha\tDeveloper: $__developer\tPublisher: $__publicador\n\nESRB: $__esrb\tGenre: $__generos\tModes: $__modos\n\nDescription: $__desc"
local __image=
__image="$(get_nile_image "$__id")"
[ "$__image" == 'null' ] && __image="$(get_nile_logo "$__id")"
[ -n "$DEBUG" ] && to_debug_file "DBG: Detail of game:\n$__text\nAnd image: $__image"
while [ $__boton -ne 1 ] && [ $__boton -ne 252 ]; do
"$YAD" "$TITTLE" "$ICON" --center --image="$__image" --sticky --buttons-layout=spread --width=512 --no-markup --no-markup --form \
--item-separator="#@#" --field="$__text":LBL --button="$lBACK":1 --button="$lSCREENSHOTS":4 --button="$lINSTALL":8 >/dev/null
local __boton=$?
case "$__boton" in
0) ;;
4)
[ -n "$DEBUG" ] && to_debug_file "DBG: View screenshot of $__id OD"
screnshotsW "$__id"
;;
8)
local __name=
__name=$(get_nile_title "$__id")
show_msg "$lADDDOWNLOAD" "$(get_nile_logo "$__id")"
add_download "$__id"
;;
*) ;;
esac
done
}
##
# screnshotsW
# Show the SCREENSHOTS Window
#
# $1 = source varname ( contains the index of game in JSON)
#
function screnshotsW() {
local __id=$1
local __tempS=/tmp/ason.screenshots/
[ ! -d "$__tempS" ] && mkdir "$__tempS"
get_nile_screenshots "$__id" >"$__tempS/urls"
wget -i "$__tempS/urls" -P "$__tempS/." >/dev/null 2>/dev/null
rm "$__tempS/urls"
for i in "$__tempS"/*; do