-
Notifications
You must be signed in to change notification settings - Fork 1
/
winestarter
executable file
·1493 lines (1474 loc) · 58.9 KB
/
winestarter
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
## License:
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
## You can redistribute it as you wish : GPL v3
## author : wildtruc@noneltd.net
## You can place the script everywhere, but /usr/local/bin is still the best
## You can rename the script as you wish
## usage : winestart CONFIGFILE
## define per game conf files dir
scpt_dir=$HOME/.winestarter
w_tricks=$(find /usr/{bin,local/bin} -name winetricks)
zen_bin=$(find /usr/{bin,local/bin} -name zenity)
convert_bin=$(find /usr/{bin,local/bin} -name convert)
wres_bin=$(find /usr/{bin,local/bin} -name wrestool)
icot_bin=$(find /usr/{bin,local/bin} -name icotool)
strings_bin=$(find /usr/{bin,local/bin} -name strings)
rpm_bin=$(find /usr/{bin,local/bin} -name rpm2cpio)
cab_bin=$(find /usr/{bin,local/bin} -name cabextract)
#yad_bin=$(find /usr/{bin,local/bin} -name yad)
wine_bin='wine'
wineboot_bin='wineboot'
wineserver_bin='wineserver'
conf=$1
## create the user script conf directory if it doesn't exist
[[ -d $scpt_dir ]]|| mkdir -p $scpt_dir
## Is per game specific wine conf file exist ?
[[ -s $scpt_dir/configs/$conf ]]|| exit 0
config_file=$scpt_dir/configs/$conf
. $scpt_dir/configs/$conf
. $scpt_dir/color.conf
[[ $auto_set ]]|| auto_set=0
[[ $set_desktop_env ]]|| set_desktop_env=0
[[ $use_optimus ]]|| use_optimus=0
[[ $use_winepath ]]|| use_winepath=0
[[ $w_install_tricks ]]|| w_install_tricks=0
[[ $w_install_exe ]]|| w_install_exe=0
[[ $w_config ]]|| w_config=0
##define user home desktop directory
if [ -e $HOME/.config/user-dirs.dirs ]; then
. $HOME/.config/user-dirs.dirs
fi
## yad fonts colors
vb='<span color="'$main'" weight="bold" font="'$font0' '$size0'">'
vn='<span color="'$main'" weight="normal" font="'$font0' '$size0'">'
rb='<span color="'$warn'" weight="bold" font="'$font0' '$size0'">'
gb='<span color="'$freeze'" weight="bold" font="'$font0' '$size0'">'
bf='<span color="'$main'" weight="bold" font="'$font1' '$size1'">'
brf='<span color="'$warn'" weight="bold" font="'$font1' '$size1'">'
nf='<span weight="bold" font="'$font0' '$size0'">'
end='</span>'
## yad warning messages
png_stock=$HOME/.winestarter/png/defaults
filesave=$png_stock/'wine-install48.png'
warning=$png_stock/'wine-warn48.png'
inform=$png_stock/'wine-info48.png'
kill_img=$png_stock/'bottle_manager48.png'
#kill_img=$png_stock/'control_panel16.png'
# text=""; dialog_list="$text;gtk-close;$inform"; yad_warnings
#yad_warning(){
## d_txt=$(printf "$dialog_list"|cut -d';' -f1)
# d_btt=$(printf "$dialog_list"|cut -d';' -f1)
# d_img=$(printf "$dialog_list"|cut -d';' -f2)
# w_width=500
# if [ $yad_bin ]; then
# $yad_bin --width=$w_width --height=$(($w_width/3)) --title "" --borders 15 --button="$d_btt":1 \
# --image=$d_img --text="$text" --timeout=3
## $yad_bin --width=400 --height=100 --title "" --button="$d_btt":1 \
## --image=$d_img --timeout=3 --form --field="$text":LBL ''
# else
# [ $zen_bin ]&& zen_warning
# fi
## zenity --height=150 --title='' --warning --window-icon=$d_img --text="$text" --timeout=3
#}
zen_warning(){
## model line: "gtk-close;'info/warn image';'height divider';'window time-out'"
d_btt=$(printf "$dialog_list"|cut -d';' -f1)
d_img=$(printf "$dialog_list"|cut -d';' -f2)
div=$(printf "$dialog_list"|cut -d';' -f3)
time=$(printf "$dialog_list"|cut -d';' -f4)
w_width=400 ; w_height=$(($w_width/$div))
$zen_bin --width=$w_width --height=$w_height --title='' --warning --window-icon="$d_img" \
--timeout=$time --text="$text"
}
zen_question(){
d_btt=$(printf "$dialog_list"|cut -d';' -f1)
d_img=$(printf "$dialog_list"|cut -d';' -f2)
bt_do=$(printf "$dialog_list"|cut -d';' -f3)
bt_undo=$(printf "$dialog_list"|cut -d';' -f4)
d_width=$(printf "$dialog_list"|cut -d';' -f5)
if [[ $d_width != '' ]]; then w_width=$d_width; else w_width=500; fi
# w_width=400
$zen_bin --width=$w_width --title='' --question --window-icon=$d_img --ok-label="$bt_do" \
--cancel-label="$bt_undo" --text="$text"
}
selector_display(){
unset _sel_list
for _sel_key in "${select_list[@]}"; do
_sel_list+=("false")
_sel_list+=("$_sel_key")
_sel_list+=( $(printf "$_sel_key"| \
sed -En "s|^($user_prefix/$bottle_prefix/drive_c/)(.*)$|\2|p" ) )
done
## test lnk correspondance to present application
_sel_path=$($zen_bin --width=600 --height=380 --title "$w_title" --list --radiolist \
--window-icon=$filesave --ok-label='Select a file' --cancel-label='Cancel' \
--text="$sel_text" --column "select" --column='full path' --column "$list_word" \
--hide-column=2 "${_sel_list[@]}")
}
fn_wipe_cache(){
## Control system cache memory. If too high, display an admin window and ask to clear it with warnings.
## use /proc/meminfo MemTotal / Buffers / Cached+Slab (critical avaluate on 60% Buffers+Cached+Slab)
## define critical left free memory
critical='40'
## use 'free' systeù tool to define memory class
m_total=$(free -wm | sed -n "/Mem/p"| awk '{print $2}')
m_used=$(free -wm | sed -n "/Mem/p"| awk '{print $3}')
m_cache=$(free -wm | sed -n "/Mem/p"| awk '{print $7}')
## translate in percentage
_m_used=$(($((100*$m_used))/$m_total))
_m_cache=$(($((100*$m_cache))/$m_total))
_m_free=$(($((100*$(($m_total-$(($m_used+$m_cache))))))/$m_total))
## if total free memory is lower than defined critical then start wipe process
if [ $_m_free -le $critical ]; then
## unless cache memory is higher than real memory used, do not continue.
if [ $_m_cache -gt $_m_used ]; then
_cc_total=$(($m_used+$m_cache))
_cc_used=$(($((100*$m_used))/$_cc_total))
_cc_cache=$(($((100*$m_cache))/$_cc_total))
if [ $_cc_used -le $critical ]; then
echo -e "»»»» Memory cache used over $_cc_cache% (left:$_m_free%)"
text="$vb\\Memory cache is using $_m_cache% of RAM. You can wipe it or leave it as it is. Some apps are known to use a lot of cache memory, so be careful and know what you're doing.$end\\n\\n$brf\\WARNING$end$vb Do not use if your system is a production server, it may wipe all servers cached data.$end"
dialog_list="gtk-close;$warning;Wipe;Cancel;"; zen_question
if [ $? = 0 ]; then
if [[ $EUID -ne 0 ]]; then
# pkexec /usr/local/sbin/winestarter_cache
pkexec bash -c "echo -e \"»»»» Cleaning memory cache.\"; sync; echo 3 > /proc/sys/vm/drop_caches"
fi
fi
fi
fi
else
echo -e "»»»» Memory cache used under critical (left:$_m_free%). Clear"
fi
}
## optimus special sets (1)
fn_optimus(){
export vblank_mode=$opti_VBLK
export PRIMUS_SYNC=$opti_SYNC
if [[ $opti_starter != primusrun ]]; then opti_opt='-b '; fi
opti_run="$opti_starter $opti_opt$opti_accel"
}
## use_winepath sub.
fn_download_ui(){
if [ $dl_installer = 1 ]; then
dl_cmd(){ wget -O $dl_dir/$pack_name $pkgs 2>&1; }
else
dl_cmd(){ wget $pkgs $dl_dir/ 2>&1; }
fi
## This perl regex Analyse and parse wget stdout field, then display it in a yad window
track(){ perl -p -e "$| = 1; s/^.* +([0-9]+%) +([0-9,.]+[GMKB]) +([0-9hms,.]+).*$/\1\n# $pck_dsp [\1] time left: \3\t\2\/s/"; }
pkg_ext=$(printf "$pkgs"| sed -n "s/^.*\.//p")
site=$(printf "$pkgs"| sed -E -n "s/(^.*:\/\/)(\w+)\.(\w+)\.(\w+)\/.*$/\2.\3.\4/p")
pack=$(printf "$pkgs"| sed -n "s/^.*\///p")
pck_dsp=$(printf "$pack"| sed -En "s/.\w*[0-9].rpm//p")
w_text="Downloading from $site server."
## zenity progress bar
dl_cmd | track | $zen_bin --width=550 --title "$w_text" \
--window-icon=filesave --progress --auto-close --no-cancel
}
## wine binary config and use (2).
fn_use_winepath(){
unset dl_list unpack_list os_version
## create tmp dir for package download
dl_dir=$(mktemp --tmpdir -d wine_dl.XXXXXXXX)
pkg_ver=$(printf $wine_ver| cut -d'-' -f1)
pkg_rel=$(printf $wine_ver| cut -d'-' -f2)
download_list(){
if [ $wine_pack -gt 0 ]; then
## check and detect fedora repo version to download from, ex : 22,23,24,etc.
for os_v in ${os_version[@]}; do
dl_ver="wine-$hq_stage$b_elf-$pkg_ver-$pkg_rel.$http_elf.rpm"
http_query=(
"https://download.opensuse.org/repositories/Emulators:/Wine:/Fedora/Fedora_"$os_v"_standard,1"
"https://dl.winehq.org/$dir_ver/fedora/$os_v,0"
)
## look into remote address is package exist, then select then right repo.
for address in ${http_query[@]}; do
_address=$(echo "$address"| cut -d',' -f1)
wget -q --spider $_address/$http_elf/$dl_ver
if [ $? = 0 ]; then
if [ $os_v = $base_dist ]; then
http_src=$(echo "$address"| cut -d',' -f2)
if [ $http_src = 0 ]; then
dl_address_0="$_address/$http_elf"
dl_address_1="$_address/i686"
echo $dl_address_0 >> $file_temp
echo $dl_address_1 >> $file_temp
fi
if [ $http_src = 1 ]; then
dl_address_0="$_address/$http_elf"
dl_address_1="$_address/i686"
fi
fi
fi
done
done
else
wget -O $file_temp $dl_address
## limit PoL Wine version list from 1.4 to 1.8.6
## Since march 2018 WineHQ old-builds has been remove for an unkwonw reason,
## then PoL version has been update accordingly from 1.4 to 1.9.24.
dl_bin_list=( "$(tac "$file_temp"| cut -d';' -f2| sed -n '/1\.9\.24.*$/,/^1\.4$/p')" )
fi
# echo "$dl_final_list"| grep "$wine_ver"| cut -d',' -f2 > $file_temp.[fedostamp]
}
## set Wine binary environment arch.
if [ $wine_elf = 1 ]; then ftp_elf='amd64'; b_elf='64'; else ftp_elf='x86'; b_elf=''; fi
## if system context (distro) is mainly 64bits, prefer to install Wine 64bits pack instead of 32.
sys_arch=$(uname -m)
if [[ $sys_arch =~ ^.*64 ]]; then
ftp_elf='amd64'; b_elf='64'
fi
## control if wine bin dir exist. If not create it from default
if ! [[ -n $wine_path/$ftp_elf/ ]]; then mkdir -p $HOME/.winebin/$ftp_elf; fi
if [[ -d $wine_path/$ftp_elf/$wine_ver ]]; then
_use_winepath_env=1
else
w_title="Winestarter"
## create the download list to fill in the yad loop.
if [ $wine_pack -gt 0 ]; then
if [ $wine_elf = 1 ]; then http_elf='x86_64'; else http_elf='i686'; fi
## Check again system arch.
if [[ $sys_arch =~ ^.*64 ]]; then
http_elf='x86_64'
else
http_elf='i686'
fi
## identify Wine version type
if [[ $wine_ver =~ ^.*staging.*$ ]]; then hq_stage='staging'; hq_short='staging';
elif [[ $wine_ver =~ ^.*stable.*$ ]]; then hq_stage='stable'; hq_short='stable';
else hq_stage='development'; hq_short='devel'; fi
file_temp=$(mktemp --tmpdir ftp.XXXX)
## check glibc os version for corresponding downloadable package list.
glibc=$(ldd --version | sed -n "s/^.* //;1p")
## Fedora glib package version correspond to 'fedora version - 1', lucky we are !
## GLIB Hist : 24 > 2.23, 25 < 2.24, 26 > 2.25, 27 > 2.26, 28 > 2.27, 29 > 2.28, 30 > 2.29
unset os_version
n=0
dist=0
base_dist=$(( $(echo "$glibc"| cut -d'.' -f2)+1 ))
until [ $dist = 24 ]; do
dist=$(( $base_dist-$n ))
os_version+=( $dist )
((n++))
done
## test
# base_dist=29
# os_version=( 29 28 27 26 25 )
## catch witch WineHQ repo class
case $wine_pack in
1) dir_ver='wine-builds';;
2) dir_ver='';;
3) dir_ver='wine-builds.old';;
esac
## catch package class from winestarter_conf resources/list.
case $hq_stage in
'staging')
case $dir_ver in
'wine-builds') hq_ver='hq_stg0';;
'wine-builds.old') hq_ver='hq_stg1';;
'') hq_ver='hq_stg2';;
esac
;;
'stable') hq_ver='hq_stb0' ;;
'development') hq_ver='hq_dev0';;
esac
dl_text="$vb\\Building WineHQ packages repository list.$end"
download_list | $zen_bin --width=550 --title "$w_title" --text="$dl_text" \
--window-icon=filesave --progress --pulsate --auto-close --no-cancel
dl_address_0=$(cat $file_temp| sed -n '1p')
dl_address_1=$(cat $file_temp| sed -n '2p')
dl_list+=( "$dl_address_0/wine-$hq_stage$b_elf-$pkg_ver-$pkg_rel.$http_elf.rpm" )
dl_list+=( "$dl_address_1/wine-$hq_stage-common-$pkg_ver-$pkg_rel.i686.rpm" )
unpack_list+=( "wine-$hq_stage$b_elf-$pkg_ver-$pkg_rel.$http_elf.rpm" )
unpack_list+=( "wine-$hq_stage-common-$pkg_ver-$pkg_rel.i686.rpm" )
else
dl_address_0="http://wine.playonlinux.com/binaries/linux-$ftp_elf"
dl_pkg=PlayOnLinux-wine-$wine_ver-linux-$ftp_elf.pol
dl_list=( "$dl_address_0/$dl_pkg" )
unpack_list=( $dl_pkg )
if [ $b_elf -ne 64 ]; then h_elf='32'; fi
hq_ver='pol'$h_elf
fi
## download packege from web source.
kill $WAIT_UI
cd $dl_dir
for pkgs in ${dl_list[@]}; do
dl_installer=0
pack_name=$wine_ver
fn_download_ui
done
## extract package with rpm cpio.
for dwld in ${unpack_list[@]}; do
if [ $wine_pack = 0 ]; then
un_tar(){ tar -xf $dwld; }
else
un_tar(){ $rpm_bin $dwld | cpio -id; }
fi
if [ $(ls -1 $dl_dir| egrep -c "$pkg_ver") -gt 0 ]; then
e_text="$vb\\Extracting $dwld to $wine_path.$end"
$zen_bin --width=550 --title "$w_title" --window-icon=filesave \
--progress --pulsate --auto-close --no-cancel --text="$e_text" &
WAIT_UI=$(ps -A | grep "zenity" | awk '{print $1}'| sed -n '1p')
un_tar
kill $WAIT_UI
_use_winepath_env=1
else
echo -e "»»»» Downloaded package missing. Using defautl Wine if any."
if [ $zen_bin ]; then
text="$bf\\Downloaded package missing$end$vb.\nUsing system default Wine instead if any.$end"
dialog_list="gtk-close;$warning;4;4"; zen_warning
fi
if [[ -d $wine_path/$ftp_elf/$wine_ver ]]; then
rm -f $wine_path/$ftp_elf/$wine_ver $wine_path/x86/$wine_ver
fi
_use_winepath_env=0
fi
done
## move extracted parckage to winestarter wine's binaries directory.
if [ $_use_winepath_env = 1 ]; then
if [ $wine_pack = 0 ]; then
cp -Rf wineversion/$wine_ver/ $wine_path/$ftp_elf
if [[ -s $HOME/.winestarter/resources/ftp_$hq_ver.\[list\] ]]; then
sed -ni "s/^\($wine_ver\)$/\1*/i;p" \
$HOME/.winestarter/resources/ftp_$hq_ver.[list]
fi
else
mkdir -p $wine_path/$ftp_elf/$wine_ver/
cp -Rf opt/wine-$hq_short/* $wine_path/$ftp_elf/$wine_ver/
if [ $b_elf = 64 ]; then cd $wine_path/x86; ln -sf ../$ftp_elf/$wine_ver ; fi
if [[ -s $HOME/.winestarter/resources/ftp_$hq_ver.\[list\] ]]; then
sed -ni "s/^\($wine_ver\),\(.*\)$/\1*,\2/i;p" \
$HOME/.winestarter/resources/ftp_$hq_ver.[list]
fi
fi
cd $WINEVERPATH/bin
fi
fi
}
## environment settings (3)
fn_wine_binary(){
if [ $_use_winepath_env -gt 0 ]; then
wine_elf_path=$wine_path/$ftp_elf/$wine_ver
export WINEVERPATH=$wine_elf_path
export PATH=$wine_elf_path/bin:$PATH
export WINESERVER=$wine_elf_path/bin/wineserver
export WINELOADER=$wine_elf_path/bin/wine
if [ $wine_elf = 1 ]; then
export WINEDLLPATH=$wine_elf_path/$libs/wine/fakedlls
export LD_LIBRARY_PATH=$wine_elf_path/lib:$wine_elf_path/$libs:$LD_LIBRARY_PATH
#":/lib:/lib64:/usr/lib:/usr/lib64"
else
export WINEDLLPATH=$wine_elf_path/lib/wine
export LD_LIBRARY_PATH="$wine_elf_path/lib:$LD_LIBRARY_PATH"
#":/lib:/lib64:/usr/lib:/usr/lib64"
fi
wine_bin_path=$wine_elf_path/bin/
## sandoxing wine by exec in WINELOADER directory
cd $WINEVERPATH/bin
fi
## in case wine prefix is missing, but it is really and app dir with exe to launch,
## (re-)create prefix.
if ! [[ -d $user_prefix/$bottle_prefix ]]; then
if [[ -d $game_path ]]; then
if [ $(find -L $game_path -wholename "*$game_exe"| grep -c .) -gt 0 ]; then
text="$vb\\Prefix $rb$(echo -e "$bottle_prefix"| sed -n "s/^\.//p")$end doesn't exist.\nDo you really want to create a new one for $rb$game_exe$end ?$end"
dialog_list="gtk-close;$warning;Yes, create;Cancel;400";zen_question
if [ $? -eq 0 ]; then
$wineboot_bin -i
w_install_tricks=1
w_config=1
fi
fi
fi
fi
}
## winetricks dlls install module. (4)
fn_install_tricks(){
unset diff_tricks
w_list_file=$user_prefix/$bottle_prefix/winetricks.log
w_tricks_reserve=$scpt_dir/resources/tricks_workaround.txt
## winestarter has its own wintricks binary, but some weird thibgs happens some time, so
## let's check if it is really in system tree, esle exit.
if [[ -x $w_tricks ]]; then
## set the dlls list to install.
## check winetricks workaround list for winetricks log filtering
if ! [[ -s $w_tricks_reserve ]]; then
$w_tricks settings list|sed -n "/^---/,/---$/d;p"| egrep -v "^Using.*$"|awk '{print $1}' \
>$w_tricks_reserve
fi
## set filters from winetricks settings list command.
w_filters=$(cat $w_tricks_reserve| tr '\n' '|')'w_workaround'
tmp_log=$(mktemp --tmpdir log1.XXXXXXXX)
## set w_tricks_list readable for diff.
_w_tricks_list=$(echo "$w_tricks_list"| tr ',' '\n')
if [[ -s $w_list_file ]]; then
## sort winetricks log alphabetiquely to avoir mistakes, if any.
_w_list_file=$(cat $w_list_file| egrep -v "$w_filters")
echo "$_w_list_file"| sort -bd >$tmp_log
if [ $(echo "$_w_tricks_list"| grep -c .) -gt 0 ]; then
## find diff between w_tricks_list and already installed.
diff_tricks=$(echo "$_w_tricks_list"| grep -vFf "$tmp_log")
if [[ $diff_tricks ]]; then
w_tricks_loop=( $diff_tricks )
if_diff=1
else
w_tricks_loop=''
if_diff=0
fi
fi
else
w_tricks_loop=( $(echo "$w_tricks_list"| tr ',' '\n') )
if [ ${#w_tricks_loop[@]} -gt 0 ]; then if_diff=1; else if_diff=0; fi
fi
## look for cabextract first, mandatory for MS package extraction.
if [[ -x $cab_bin ]]; then
## now, let's do winetricks job
## Check that tricks install process is set to 'on' and take w_install_tricks is not empty.
## else, send error and exit.
if [ $w_install_tricks -gt 0 ]; then
if [ $if_diff = 1 ]; then
if [ ${#w_tricks_loop[@]} -gt 0 ]; then
## take care for all brend new install and already existant ones.
if [[ -s $w_list_file ]]; then new_repo=0; else new_repo=1; fi
e_text="$vb\\Winetricks is working$end"
(for w_list in "${w_tricks_loop[@]}"; do
echo "# Installing $w_list"
$w_tricks $w_tricks_opts $w_list
done
)| $zen_bin --width=250 --title="$w_title" --text="$e_text" \
--window-icon=filesave --progress --pulsate --auto-close --no-cancel
if [[ -s $w_list_file ]]; then
## analyse winetricks log again to get newly installed dlls.
cat $w_list_file| egrep -v "$w_filters"| sort -bd > $tmp_log
## ensure all dlls are installed, else, display error/info message.
diff_logs=$(echo "$_w_tricks_list"| grep -vFf "$tmp_log")
## if diff_logs is not empty, something wrong happened.
if [[ $diff_logs != '' ]]; then
warn_msg=$(echo "$diff_logs"| tr '\n' ','| sed -n "s/,$//g;p")
echo -e "»»»» DLLs install error. $warn_msg are missing or won't install.\n»»»» See config file w_tricks_list field or try to launch winestarter again."
if [ $zen_bin ]; then
text="$bf\\DLLs install error$end$vb.\n$rb$warn_msg$end are missing or won't install.\nLook at $rb$config_file$end or try to launch Winestarter again$end"
dialog_list="gtk-close;$warning;4;4"; zen_warning
fi
else
## if diff_logs is empty, all dlls are installed.
## Make a diff now between all new and added dlls.
if [ $new_repo -eq 0 ]; then
## treat w_list_file for newly install dlls from config.
_new_tricks=$(cat $tmp_log| tr '\n' ','| sed -n "s/,$//p")
sed -ni "s|^\(w_tricks_list\)=\".*\"$|\1=\"$_new_tricks\"|i;p" \
$config_file
fi
sed -ni "s|^\(w_install_tricks\)=.*$|\1=0|i;p" $config_file
fi
fi
fi
else
if [ $w_tricks_list ]; then
echo -e "»»»» No diff between old and new.\n»»»» Passed."
text="$bf\\No diff found between Winetricks log and conf$end$vb.\nFunction passed\n$end"
if [ $zen_bin ]; then dialog_list="gtk-close;$warning;4;4"; zen_warning; fi
sed -ni "s|^\(w_install_tricks\)=.*$|\1=0|i;p" $config_file
else
echo -e "»»»» Winetricks install list is empty.\n»»»» If empty, leave Winetricks dlls install set up to 0 when DLLs list is empty."
text="$bf\\Winetricks install list is empty.$end$vb.\nDon't set up Winetricks dlls install when DLLs list is empty\n$end"
if [ $zen_bin ]; then dialog_list="gtk-close;$warning;4;4"; zen_warning; fi
# exit 0
fi
fi
fi
else
echo -e "»»»» Cabextract binary not found in system tree. Install it first."
text="$bf\\Cabextract binary not found in system tree.$end\n$vb\\Install it first.$end"
if [ $zen_bin ]; then dialog_list="gtk-close;$warning;4;4"; zen_warning; fi
exit 0
fi
else
echo -e "»»»» Winetricks was not found, install it first."
if [ $zen_bin ]; then
text="$bf\\Winetricks was not found$end\n$vb\\Install it first$end"
dialog_list="gtk-close;$warning;4;4"; zen_warning
fi
exit 0
fi
}
## multi format executable installation. (5)
fn_install_exe(){
sub_download(){
if [[ $w_download_dir != '' ]]; then dl_dir=$w_download_dir; else dl_dir=$XDG_DOWNLOAD_DIR; fi
pack_name=$(printf "$pkgs"| sed -n "s/^.*\///p")
if ! [[ -s $dl_dir/$pack_name ]]; then
dl_installer=1
fn_download_ui
fi
}
## in case extra package is compressed, extraction & selection functions are isoleted.
sub_select_dir(){
target_dir=$user_prefix/$bottle_prefix/drive_c/
if [[ $w_install_pck =~ ^.*-.*$ ]]; then
w_install_dir=$(echo "$w_install_pck"| sed -En "s|^(.*)-(.*)$|\1|;s|^.*/||g;p")
target_dir=$target_dir$w_install_dir
else
if [[ -x $zen_bin ]]; then
dir_text="$vb\\Please, select or create the target directory in C: drive.$end"
$zen_bin --width=400 --title "$w_title" --question --window-icon=$filesave \
--ok-label='Select' --cancel-label='Cancel' --text="$dir_text"
abort=$?
if [ $? = 0 ]; then
w_install_dir=$($zen_bin --title "$w_title" --window-icon=$filesave \
--file-selection --filename=$target_dir --directory)
fi
target_dir=$w_install_dir
w_install_dir=$(printf "$target_dir"| sed -n "s/^.*\///g;p")
fi
fi
if [ $extra_pack = 0 ]; then w_install_zip=$w_install_pck; fi
}
sub_extract(){
unset _archive_type
_archive_type=( zip tar rar 7z tar.7z exe )
for _type in ${_archive_type[@]}; do
check_type=$(printf "$w_install_pck"| egrep -oi "$_type$")
case $check_type in
'zip')
auto=0; cd_to=0; cmd='unzip'; _opt_list='-l'
_opt_ex0='-o'; _opt_ex1='-d'; _extra=''
;;
'rar')
auto=0; cd_to=1; cmd='unrar'; _opt_list='lb'
_opt_ex0='x -y -o+ -inul'; _opt_ex1=''; _extra=''
;;
'7z')
auto=0; cd_to=1; cmd='7z'; _opt_list='l'
_opt_ex0='x -y'; _opt_ex1=''; _extra=''
;;
'tar.7z')
auto=0; cd_to=1; cmd='7z'; _opt_list='l'
_opt_ex0='x -y -so'; _opt_ex1='|'; _extra=' tar xf -'
;;
'exe')
auto=1; cd_to=0
cmd="$wine_bin $w_install_pck $wine_opts"
;;
esac
done
## make right selection between w_more_pkgs and zip install type.
if [[ $cmd != '' ]]; then
if [ $cd_to = 1 ]; then
[[ -d $target_dir ]]|| mkdir -p $target_dir
cd $target_dir
cmd_line="$cmd $_opt_ex0 $w_install_pck $_opt_ex1"
else
cmd_line="$cmd $_opt_ex0 $w_install_pck $_opt_ex1 $target_dir"
fi
if [[ $extra_pack = 0 ]]; then
if [ $auto = 0 ]; then
if [ $( $cmd $_opt_list $w_install_pck | egrep -ic "setup.exe") -gt 0 ]; then
warn_msg
target_dir=$XDG_DOWNLOAD_DIR/$w_install_dir
mkdir -p $target_dir
bash -c "$cmd_line"
if [ $go_on = 1 ]; then
setup_bin=$(ls -1 $target_dir/| egrep -i "setup.exe")
if ! [ $setup_bin ]; then
echo -e "»»»» WARNING: Setup.exe not found.\n»»»» You need to set the install executable manually and launch the script again."
if [ $zen_bin ]; then
text="$brf\\Setup.exe not found.$end$vb\nSorry, but you need to set the install executable manually and launch the script again.$end"
dialog_list="gtk-close;$warning;4;4"; zen_warning
fi
exit 0
fi
w_more_pkgs=$target_dir/$setup_bin
w_install_zip=''
fn_install_exe
fi
else
bash -c "$cmd_line"
fi
else
$cmd
fi
else
bash -c "$cmd_line"
chmod 755 *.exe
fi
fi
}
pkgs_log=$user_prefix/$bottle_prefix/packages.log
if_install=1
if [ "$w_exe_path" != '' ]; then
msi=$(printf "$w_exe_path"| grep -c "\.msi")
new_pkg=$(printf "$w_exe_path"| sed -n "s/^.*\///g;p")
if ! [[ -s $pkgs_log ]]||[ $(cat $pkgs_log| grep -wc "$new_pkg") -eq 0 ]; then
if [[ $w_exe_path =~ ^(http*|ftp*) ]]; then
pkgs=$w_exe_path
sub_download
w_exe_path=$dl_dir/$pack_name
fi
if [ $msi = 0 ]; then
$wine_bin $w_exe_path $w_exe_opts
else
$wine_bin msiexec \/i $w_exe_path $w_exe_opts
fi
echo "$new_pkg" >> $pkgs_log
else
echo -e "»»»» $new_pkg already installed, pass."
fi
fn_extract_lnk_file
sleep 1
abort=0
fi
if [ $(printf "$w_more_pkgs"| grep -c .) -gt 0 ]; then
## define pkg is an extra pack.
extra_pack=1
extra_log=$user_prefix/$bottle_prefix/extra_pcks.log
for pkg in ${w_more_pkgs[@]}; do
msi=$(printf "$pkg"| grep -c "\.msi")
prev_pck=$(echo -e "$pkg"| sed -n "s/^.*\///g;p")
if ! [[ -s $extra_log ]]||[ $(cat $extra_log| grep -wc "$prev_pck") -eq 0 ]; then
if [[ $pkg =~ ^(http*|ftp*) ]]; then
pkgs=$pkg
sub_download
pkg=$dl_dir/$pack_name
fi
## check if package is compressed.
if [[ $pkg =~ ^.*\.(zip|tar|rar|7z|tar\.7z)$ ]]; then
w_install_pck=$pkg
sub_select_dir
sub_extract
else
if [ $msi = 0 ]; then
$wine_bin $pkg $w_exe_opts
else
$wine_bin msiexec \/i $pkg $w_exe_opts
fi
fi
echo "$prev_pck" >> $extra_log
else
echo -e "»»»» $prev_pkg already installed, pass."
fi
done
abort=0
fi
## zip file section.
if [ $(printf "$w_install_zip"| grep -c .) -gt 0 ]; then
## set functions used by section first.
## define pkg is not an extra pack.
extra_pack=0
## alert on wrong behaviour.
warn_msg(){
echo -e "»»»» WARNING: Archive looks like an installation dir only.\nExtracting in default download dir.\nThen, set up extra packages install."
if [ $zen_bin ]; then
text="$brf\\Archive seems to be an install dir only.$end$vb\nYou can choose between :\n - Extract and Install as an extra package\n - Cancel, package will be extrated in default downlaod dir under $w_install_dir name, but wont be install.$end"
dialog_list="gtk-close;$warning;Extract & Install;Cancel;"; zen_question
fi
if [ $? = 0 ]; then go_on=1; else go_on=0; fi
}
new_pkg=$(printf "$w_install_zip"| sed -n "s/^.*\///g;p")
if [[ $w_install_dir ]]; then
if [[ $w_install_dir =~ ^.*$USER ]]; then
w_install_dir=$(echo -e "$w_install_dir"| sed -En "s|^.*drive_c/(.*)$|\1|p")
fi
target_dir=$user_prefix/$bottle_prefix/drive_c/$w_install_dir
else
sub_select_dir
fi
if ! [[ -s $pkgs_log ]]||[ $(cat $pkgs_log| grep -wc "$new_pkg") -eq 0 ]; then
mkdir -p $target_dir
game_dir=$w_install_dir
if [[ $w_install_zip =~ ^(http*|ftp*) ]]; then
pkgs=$w_install_zip
sub_download
w_install_zip=$dl_dir/$pack_name
fi
w_install_pck=$w_install_zip
sub_extract
echo "$new_pkg" >> $pkgs_log
if [ $cd_to = 1 ]; then cd $WINEVERPATH/bin; fi
else
echo -e "»»»» $new_pkg already installed, pass."
fi
fn_extract_lnk_file
fi
if [ $(printf "$w_extra_script"| grep -c .) -gt 0 ]; then
chmod 755 $w_extra_script
cp -f $w_extra_script $user_prefix/$bottle_prefix/drive_c/Program\ Files"$w_elf_ext"/$game_dir/
fi
if [ $abort = 1 ]; then
echo -e "»»»» EXE path was not found.\n# Defining the right install executable path is mandatory.\n# EXIT.\n"
if [ $zen_bin ]; then
text="$brf\\EXE path was not found.$end$vb\nDefining the right install executable path is mandatory.\n\nEXIT.$end"
dialog_list="gtk-close;$warning;4;4"; zen_warning
fi
exit 0
else
sed -Eni "s/^(w_install_exe)=[0-9]$/\1=0/i;p" $config_file
# perl -ni - pe "s|(w_install_exe)=[0-9]|\1=0|i" $config_file
fi
}
## target dir existence and desktop file sub process (6)
fn_game_dir_exist(){
fn_root_key
## search if there any app path in "Program Files" or root. If none, link the predifine app dir if any.
if [[ $game_path != '' ]]; then
link=$(printf "$game_path"| sed -n "s/^.*\///g;p")
# _link_target_dir="$user_prefix/$bottle_prefix/drive_c/"$root_key"$link"
# _link_target_path=$user_prefix/$bottle_prefix/drive_c/"$root_key"
_link_target_dir="$user_prefix/$bottle_prefix/drive_c/$root_key$link"
_link_target_path="$user_prefix/$bottle_prefix/drive_c/$root_key"
if ! [[ -d "$_link_target_dir" ]]; then
# if ! [[ -d "p_mon cul" ]]; then
ln -sf $game_path $_link_target_path
fi
## if target app exe path is not find or doesn't exist at this point, search and define.
## and create a desktop file if needed.
## FIXME ?? manage the double link by mistake?
if [[ -h "$_link_target_dir" ]]; then
if_install=0
if [[ "$bin_dir_target" ]]; then
_link_target_exe=$bin_dir_target
else
_link_target_exe="$_link_target_path$game_dir/$game_exe"
fi
if ! [[ -s "$_link_target_exe" ]]; then
fn_extract_lnk_file
else
## control target path and desktop file. If none, create, else, pass.
_target_exe=$(printf "$game_exe"| sed -n "s/^.*\///g;p")
_target_dir=$user_prefix/$bottle_prefix/drive_c/"$root_key"$game_dir
_target_path=$(printf "$_target_dir"| sed -En "s|^(.*)/(drive_c)/(.*)$|\1/dosdevices/c:/\3|p")
_unix_path=$_target_dir/$game_exe
fn_convert_desktop_file
fi
fi
else
## in some cases, game_path and game_exe could not be found and a manually search is needed.
if [[ $game_exe == '' || $game_exe == 'null' ]]; then
unset select_list
exclude_dir='users'
exclude_list='[Ww]indows|Explorer'
bin_dir_target=$(find -L $user_prefix/$bottle_prefix/drive_c/ \
-not \( -path $user_prefix/$bottle_prefix/drive_c/$exclude_dir -prune \) -iname "*.exe" | \
egrep -v "$exclude_list")
select_list=( $bin_dir_target )
list_word='executables'
sel_text="$bf\\Application executable and path not found$end\n
$vb\\Select the appropriate executable file in the list below. Choose wisely, it would define the app
executable and dirrectory for config file, and moreover, allowing to create the dedicate desktop file.$end
\n$nf\\CAUTION:$end$vn Be aware that some apps have their executables in some boot directory,
but have to chroot in the main directory to start (the preivous usualy).
In this case, you have to modify the config file manualy or with Winestarter_conf as needed.$end"
selector_display
if [ $? = 0 ]; then
_dest_path=$_sel_path
_target_exe=$(printf "$_dest_path"| sed -n "s|^.*/||g;p")
_target_dir=$(printf "$_dest_path"| sed -n "s|/$_target_exe||p")
_target_path=$(printf "$_target_dir"| sed -En "s|^(.*)/(drive_c)/(.*)$|\1/dosdevices/c:/\3|p")
_unix_path=$_target_dir/$_target_exe
game_exe=$_target_exe
game_dir=$(printf "$_target_dir"| sed -n "s/^.*\///p")
sed -Eni "s|^(game_exe)=.*$|\1=\"$game_exe\"|g;p" $config_file
sed -Eni "s|^(game_dir)=.*$|\1=\"$game_dir\"|g;p" $config_file
fn_convert_desktop_file
fn_root_key
fi
else
## dedicated winestarter desktop file could be remove by mistake.
## So, control their existance and recreate if needed.
unset _desktop_list
_desktop_list=( $(ls -1 $XDG_DESKTOP_DIR| egrep "(\s*.desktop$)") )
_app_name=$(printf "$game_exe"| sed -n "s/\.exe//g;p")
if [ $(echo "${_desktop_list[*]}"| grep -c "$_app_name") -eq 0 ]; then
for app_dsk in ${_desktop_list[@]}; do
_desk_list_keys+=( $(cat $XDG_DESKTOP_DIR/$app_dsk | egrep "\s*Start.*.exe"| sed -n "s/.*=//p") )
done
if [ $(echo "${_desk_list_keys[*]}"| grep -c "$game_exe") -eq 0 ]; then
_target_exe=$game_exe
_target_dir=$user_prefix/$bottle_prefix/drive_c/"$root_key"$game_dir
_target_path=$(printf "$_target_dir"| sed -En "s|^(.*)/(drive_c)/(.*)$|\1/dosdevices/c:/\3|p")
_unix_path=$_target_dir/$game_exe
fn_convert_desktop_file
fi
fi
fi
fi
}
## pre process step for fn_game_dir_exist (6pre)
fn_root_key(){
## search where is the "Prgram Files" dir and type.
## find where is the exe file to define first application root key.
if [[ $game_exe ]]; then
bin_dir_target=$(find -L \
$user_prefix/$bottle_prefix/drive_c/Program\ {Files,Files\ \(x86\)} -wholename "*$game_exe")
if [[ -e $bin_dir_target ]]; then
bin_elf_type=$(file $bin_dir_target)
if [ $(printf "$bin_elf_type"| egrep -c "80386") -gt 0 ]; then
if [ $wine_elf -gt 0 ]; then
root_key='Program Files (x86)/'; sed_key='Files\ (x86)\/'
else
root_key="Program Files/"; sed_key='Files\/'
fi
else
if [[ "$bin_dir_target" =~ ^.*x86.*$ ]]; then
root_key='Program Files (x86)/'; sed_key='Files\ (x86)\/'
else
root_key="Program Files/"; sed_key='Files\/'
fi
fi
else
## build an exe list with windowws system exclusion list.
exclude_dir='users'
exclude_list='[Ww]indows|Explorer'
## if app data come from fn_game_dir_exist, change app exe seek as appropriate.
## to restrict search, look in where exe could be, not where it could'nt.
bin_dir_target=$(find -L $user_prefix/$bottle_prefix/drive_c/ \
-not \( -path $user_prefix/$bottle_prefix/drive_c/$exclude_dir -prune \) -wholename "*$game_exe" | \
egrep -v "$exclude_list")
# bin_dir_target=$(find -L $user_prefix/$bottle_prefix/drive_c -wholename "*$game_exe")
root_key=''; sed_key=''
fi
else
game_exe='null'
root_key=''; sed_key=''
fi
win_prog_file="$root_key"
}
## sub after fn_game_dir_exist or sub process step after fn_extract_lnk_file. (6bis)
fn_convert_desktop_file(){
_sub_convert_desk(){
## other vars defined for both conditions.
d_emblem=$scpt_dir/emblems/wine_emblem.png
d_png_dir=$scpt_dir/png
l_icon_dir=$HOME/.local/share/icons/hicolor
## check if _desk var is set, no matter it is, it mean that a desktop file was search & found,
## and tell also that a png file exist in default local icons path.
if ! [[ -d "$XDG_DESKTOP_DIR/$_desk" ]]; then
## list all app available icons and convert 256px one to usable format.
_path_icons_list=( $(find $l_icon_dir -iname "$d_icon*") )
for _png in ${_path_icons_list[@]}; do
icon_def=$(printf "$_png"| egrep -o "(\s*[0-9]*x[0-9]*)")
icon_rank=$(printf "$icon_def"| sed -n "s/^.*x//p")
if [ -n $icon_rank ]; then
icon_min=$((256-$icon_rank))
if [ $icon_min -le 208 ]; then
rank_list+=("$icon_rank")
fi
fi
done
if [ ${#rank_list[*]} -gt 0 ]; then
# "0,64 1,48 2,128"
scale_op=$(printf "%s\n" ${rank_list[*]}| sort -n| tail -1)
scale=$scale_op'x'$scale_op
d_icon_src=$l_icon_dir/$scale/apps/$d_icon.png
$convert_bin $d_icon_src $d_emblem -scale $scale -composite $d_png_dir/$d_exec.png
fi
else
## use wrestool with _dest_path to extract png and convert to usable format:
## set the icon type to extract.
ico_type=14
# extract the icon from _dest_path and send it to default winestarter icon path.
$wres_bin -x -t $ico_type -o $scpt_dir/icons $_unix_path
# extract the png from the icon in multi definition format
ico_def_list=('256' '128' '64' '48')
for _def in ${ico_def_list[@]}; do
# look for index for the asked definition
index=$($icot_bin -l $scpt_dir/icons/$d_exec\_$ico_type\_*.ico| \
grep "\(width=$_def\).*\(bit-depth=32\)"| sed -n "s/^.*--index=\([0-9]\).*$/\1/g;p")
if [[ $index > 0 ]]; then
$icot_bin -x -i $index -o $scpt_dir/png $scpt_dir/icons/$d_exec\_$ico_type\_*.ico
png_file=$(ls -1 $scpt_dir/png/$d_exec\_$ico_type*\_$_def\x$_def*.png)
icon_rank=$_def
icon_min=$((256-$icon_rank))
if [ $icon_min -le 208 ]; then
rank_list+=("$icon_rank,$png_file")
fi
fi
done
if [ ${#rank_list[*]} -gt 0 ]; then
# "0,64 1,48 2,128"
upper_def=$(printf "%s\n" ${rank_list[*]}| sort -n| tail -1)
_scale=$(printf "$upper_def"| cut -d',' -f1)
_icon=$(printf "$upper_def"| cut -d',' -f2)
scale=$_scale'x'$_scale
d_icon_src=$_icon.png
$convert_bin $_icon $d_emblem -scale $scale -composite $d_png_dir/$d_exec.png
fi
fi
if [[ -s $d_png_dir/$d_exec.png && ! -s $d_png_dir/.png ]]; then
d_icon=$d_png_dir/$d_exec.png
else
if [[ -s $d_png_dir/.png ]]; then rm -f $d_png_dir/.png; fi
d_icon=$d_png_dir/defaults/wine48w.png
fi
## 'd_name d_exec d_path d_icon dsk_name'
dsk_fields="[Desktop Entry]\nEncoding=UTF-8
Name=$d_name\nComment=$d_name Winestarter managed
Exec=winestarter $_config\nPath=$d_path
StartupWMClass=$game_exe\nType=Application\nStartupNotify=true
Icon=$d_icon\nCategories=Applications;"
echo -e "$dsk_fields" > $XDG_DESKTOP_DIR/$dsk_name
chmod 755 $XDG_DESKTOP_DIR/$dsk_name
}
## modify and backup the desktop file
## then now main app variables are define, check is there is an appropriate desktop file to convert
## or create a new one from scratch.
if [[ -x $convert_bin ]]; then
# if [ -x $_unix_path ]; then
# test -x $_unix_path
if [[ -s $_unix_path ]] ; then
unset _desktop_file_list
_desktop_file_list=( $(ls -1 $XDG_DESKTOP_DIR| egrep "(\s*.desktop$)") )
## catch first word for desktop/exe key seek.
_dsk_key=$(printf "$_target_exe"| sed -En "s|^(\w*.{3,15})(.*).exe|\1|;s|[ ]?$||p")
_config=$(printf "$config_file"| sed -n "s/^.*\///g;p")
## check if _dsk_key match something in desktop files path
## if yes, check if path var is a wine cmdline or a winestarter one.
## if no, check inside desktop file list if executable exist.
## if winestrater's cmd, check that conf file is the good one. If wine's, then convert.
## _dsk_key is place as the first word of the output.
if [[ $(ls $XDG_DESKTOP_DIR/| egrep -c "^$_dsk_key") -gt 0 || \
$(cat $XDG_DESKTOP_DIR/$_desk/$_exe_key*.desktop| egrep -c "^Exec=.*$_dsk_key.*exe.*$") -gt 0 ]]; then
for _desktar in "${_desktop_file_list[@]}"; do
if [ $(echo -e "$_desktar"| egrep -c "$_dsk_key") -gt 0 ] || \
[ $(cat $XDG_DESKTOP_DIR/$_desktar| egrep -c "^Exec=.*$_dsk_key.*exe.*$") -gt 0 ]; then
## check if desktop file is already configured by winestarter or not.
if [[ $(cat $XDG_DESKTOP_DIR/$_desktar| \
egrep -c "^Exec=.*$_dsk_key.*exe.*$") -gt 0 || \
$(cat $XDG_DESKTOP_DIR/$_desktar| egrep -c "^Exec=.*$_config$") -eq 0 ]]; then
## defines appropriiate vars and convert.
## save original desktop file to winestarter conf directory.
cp -f $XDG_DESKTOP_DIR/$_desktar $scpt_dir/desktop/
## look for avialable data from dktop file.
d_name=$(cat $XDG_DESKTOP_DIR/$_desktar| sed -En "s|^(Name=)(.*)$|\2|p")
d_exec=$game_exe
d_path=$(cat $XDG_DESKTOP_DIR/$_desktar| sed -En "s|^(Path=)(.*)$|\2|p")
d_icon=$(cat $XDG_DESKTOP_DIR/$_desktar| sed -En "s|^(Icon=)(.*)$|\2|p")
dsk_name=$_desktar
if ! [[ $d_path ]]; then d_path="$_target_path" ; fi
echo "→→→→→→ convert existing desktop"
_sub_convert_desk
fi
fi
done
else
## if no match create a desktop file from scratch, with a set appropriate vars.
d_name=$(printf "$_target_exe"| sed -En "s/^(.*).(exe|EXE)/\1/p")
d_exec=$_target_exe
d_path="$_target_path"
d_icon=$_target_exe.png
dsk_name=$d_name.desktop
echo "×××××× create desktop from raw"
_sub_convert_desk
fi
fi
fi
# exit 0
}
## sub step process after install or when usage of usage of extract app path. (5bis)
fn_extract_lnk_file(){
# _sub_selector_display(){
# unset _sel_list
# for _sel_key in "${select_list[@]}"; do
# _sel_list+=("false")