File: setupwindow.lib

package info (click to toggle)
playonlinux 4.3.4-5
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 8,252 kB
  • sloc: sh: 5,390; python: 5,150; ansic: 72; makefile: 57; xml: 47
file content (879 lines) | stat: -rwxr-xr-x 30,004 bytes parent folder | download | duplicates (4)
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
#!/bin/bash

# Copyright (C) 2007-2011 PlayOnLinux Team
# Copyright (C) 2007-2011 Pâris Quentin

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 

# scripts.lib
# -----------
#
# This lib contains all function to control PlayOnLinux setup windows

export POL_SetupWindow_ID=$$ 
export POL_HOST="127.0.0.1"

POL_Untab()
{
	echo "${1//	/\\t}"
}
ncs()
{
	# Silent netcat
	ncns "$@" > /dev/null 2> /dev/null
}
ncns()
{
	if [ "$POL_OS" = "Mac" -o "$(POL_Config_Read FORCE_LEGACY_NETCAT)" = "TRUE" ]; then
		nc "$@"
	else
		nc -q -1 "$@" 2> /dev/null || nc "$@"
		# Differents possibilities
	fi
}
POL_SetupWindow_Init ()
{
	# Open PlayOnLinux setup window. Should be use only once in a script !
	# Needed for POL_SetupWindow_* functions
	# Usage: POL_SetupWindow_Init
	POL_Debug_Message "Creating new window for pid $$"
	
	local arg1 
	local arg2
	local arg3
	[ "$1" = "--protect" ] && arg3="protect" && shift
	
	[ "$POL_SetupWindow_TopImage" = "" ] && arg1="$1" || arg1="$POL_SetupWindow_TopImage"
	[ "$POL_SetupWindow_LeftImage" = "" ] && arg2="$2" || arg2="$POL_SetupWindow_LeftImage"
	
	[ "$arg1" = "" ] && arg1="None"
	[ "$arg2" = "" ] && arg2="None"
	[ "$arg3" = "" ] && arg3="None"
	
	echo "$POL_COOKIE	POL_SetupWindow_Init	$$	$arg1	$arg2	$arg3" | ncs "$POL_HOST" "$POL_PORT"
	
	export SETUPWINDOW_INIT="true"
}
POL_SetupWindow_Close ()
{
	# Close PlayOnLinux setup window.
	# After this command, POL_SetupWindow_* functions won't work
	# Should be used at the end of the script if POL_SetupWindow_Init has been called
	# Usage: POL_SetupWindow_Close
	POL_Debug_Message "Closing window for pid $$"
	if [ "$POL_SCRIPT_FAILED" = "YES" -a -n "$LOGTITLE" -a -n "$DEBUGGING" -a -z "$NOBUGREPORT" ]
	then
		POL_SetupWindow_question "$(eval_gettext "An error occured during the installation process\n\nDo you want to send the bug to $APPLICATION_TITLE ?")" "$TITLE"
		if [ "$APP_ANSWER" = "TRUE" ]
		then
			export LOGTITLE
			bash "$PLAYONLINUX/bash/bug_report" &
		fi
	fi
	
	echo "$POL_COOKIE	POL_SetupWindow_Close	$$" | ncs "$POL_HOST" "$POL_PORT"
	export SETUPWINDOW_INIT="false"
}

POL_SetupWindow_presentation ()
{
	# Default presentation of a script
	# Usage: POL_SetupWindow_presentation [Program's name] [Program's editor] [Editor's url] [Scriptor's name] [Prefix's name]
	[ "$3" = "" ] || url="($3)" 
	POL_SetupWindow_free_presentation "$(eval_gettext 'Welcome to $APPLICATION_TITLE Installation Wizard.')" "$(eval_gettext 'This wizard will help you install ')$1$(eval_gettext ' on your computer.')\n\n$(eval_gettext 'This program was created by: ')$2\n$url\n\n$(eval_gettext 'This installation program is provided by: ')$4\n\n$1$(eval_gettext ' will be installed in: ')$POL_USER_ROOT/wineprefix/$5$(eval_gettext "\n\n$APPLICATION_TITLE is not responsible for anything that might happen as a result of using these scripts.\n\n")$(eval_gettext 'Click Next to start')"

}
POL_SetupWindow_free_presentation ()
{
	# Free presentation for a script
	# Usage POL_SetupWindow_free_presentation [title] [message]
	
	echo "$POL_COOKIE	POL_SetupWindow_free_presentation	$$	$(POL_Untab "$1")	$(POL_Untab "$2")" | ncs "$POL_HOST" "$POL_PORT"
}
POL_SetupWindow_message ()
{
	# Shows a simple message
	# Usage POL_SetupWindow_message [message] [title]
	
	echo "$POL_COOKIE	POL_SetupWindow_message	$$	$(POL_Untab "$1")	$(POL_Untab "$2")" | ncs "$POL_HOST" "$POL_PORT"
}
POL_SetupWindow_notice ()
{
	# Show an important message, but allows the user to acknowledge it once and for all
	# Usage: POL_SetupWindow_notice [message] [notice id] [title]
	local noticeid="$2"
	[ -z "$noticeid" ] && noticeid="$(POL_MD5 "$1")"
	if ! POL_Notice_IsAck "$noticeid"; then
		local APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_notice	$$	$(POL_Untab "$1")	$(POL_Untab "$3")" | ncns "$POL_HOST" "$POL_PORT")"
		[ "$APP_ANSWER" = "TRUE" ] && POL_Notice_Ack "$noticeid"
	fi
}
POL_SetupWindow_licence ()
{
	# Shows a licence file, and force the user to accept it to continue
	# Usage POL_SetupWindow_licence [message] [title] [licence's file]
	echo "$POL_COOKIE	POL_SetupWindow_licence	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3" | ncs "$POL_HOST" "$POL_PORT"
}

POL_SetupWindow_wait_next_signal ()
{
	# Wait for next POL_SetupWindow_ command
	# Shows a pulsebar
	# Usage POL_SetupWindow_wait_next_signal [message] [title]

	echo "$POL_COOKIE	POL_SetupWindow_wait	$$	$(POL_Untab "$1")	$(POL_Untab "$2")" | ncs "$POL_HOST" "$POL_PORT"
}
POL_SetupWindow_wait_button ()
{
	# Wait for next POL_SetupWindow_ command
	# Shows a pulsebar
	# Usage POL_SetupWindow_wait_next_signal [message] [title] [Button text] [Command] [Confirm message (0 = No confirmation needed)]
	
	echo "$POL_COOKIE	POL_SetupWindow_wait_bis	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	export PLAYONLINUX="$PLAYONLINUX" ; export WINEPREFIX="$WINEPREFIX" ; export PATH="$PATH" ; export LD_LIBRARY_PATH="$LD_LIBRARY_PATH" ; $4	$5" | ncs "$POL_HOST" "$POL_PORT"
	
}
POL_SetupWindow_pulsebar ()
{
	# Same than POL_SetupWindow_wait_next_signal, except that you can control the bar
	# Usage POL_SetupWindow_pulsebar [message] [title]
	
	echo "$POL_COOKIE	POL_SetupWindow_pulsebar	$$	$(POL_Untab "$1")	$(POL_Untab "$2")" | ncs "$POL_HOST" "$POL_PORT"
}
POL_SetupWindow_pulse ()
{
	# Change the pulsebar position (0 - 100)
	# Usage POL_SetupWindow_pulse [position]

	echo "$POL_COOKIE	POL_SetupWindow_pulse	$$	$1" | ncs "$POL_HOST" "$POL_PORT"
}
POL_SetupWindow_set_text ()
{
	# Change the pulsebar's text
	# Usage POL_SetupWindow_set_text [message]

	echo "$POL_COOKIE	POL_SetupWindow_set_text	$$	$(POL_Untab "$1")" | ncs "$POL_HOST" "$POL_PORT"
}
POL_SetupWindow_wait ()
{
	# POL_SetupWindow_wait_next_signal in shorter
	POL_SetupWindow_wait_next_signal "$@"
}
POL_SetupWindow_download ()
{
	# Download a file and place it to the current directory
	# Usage: POL_SetupWindow_download [message] [title] [url] [file]
	# /!\ Scriptors should directly use POL_Download
        # If provided, make sure the filename is absolute to avoid any misinterpretation from server

	local FILENAME
	[ -n "$4" ] && FILENAME="$4" || FILENAME="$PWD/"
	Result="$(echo "$POL_COOKIE	POL_SetupWindow_download	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	$(POL_Untab "$FILENAME")" | ncns "$POL_HOST" "$POL_PORT")"
	# FIXME: Result should send 'fail' if the download has failed. Maybe we could catch it
}

POL_SetupWindow_textbox ()
{
	# Shows a text box
	# Usage: POL_SetupWindow_textbox [message] [title] [default value] [max length]
	# Result is sent in $APP_ANSWER variable

	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_textbox	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	$(POL_Untab "$4")" | ncns "$POL_HOST" "$POL_PORT")"
        POL_Debug_Message "textbox answer: $APP_ANSWER"
}
POL_SetupWindow_browse ()
{
	# Shows a text box with a browse button
	# Usage: POL_SetupWindow_browse [message] [title] [default value] [Supported file types]
	# Result is sent in $APP_ANSWER variable

	[ "$4" = "" ] && SUPPORTED="All" || SUPPORTED="$4"
	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_browse	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	$PWD	$SUPPORTED" | ncns "$POL_HOST" "$POL_PORT")"
	POL_Debug_Message "browser answer: $APP_ANSWER"
}
POL_SetupWindow_question ()
{
	# Shows a yes/no question
	# Usage: POL_SetupWindow_question [message] [title]
	# Result is sent in $APP_ANSWER variable (TRUE or FALSE)

	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_question	$$	$(POL_Untab "$1")	$(POL_Untab "$2")" | ncns "$POL_HOST" "$POL_PORT")"
	POL_Debug_Message "question answer: $APP_ANSWER"
}
POL_SetupWindow_menu ()
{
	# Shows a menu
	# Usage: POL_SetupWindow_menu [message] [title] [list] [separator]
	# Result is sent in $APP_ANSWER variable

	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_menu	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	$4" | ncns "$POL_HOST" "$POL_PORT")"
	POL_Debug_Message "menu answer: $APP_ANSWER"
}
POL_SetupWindow_icon_menu ()
{
	# Shows a menu with icons
	# Usage: POL_SetupWindow_icon_menu [message] [title] [list] [separator] [icons folder] [icons list]
	# Result is sent in $APP_ANSWER variable

	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_icon_menu	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	$4	$5	$6" | ncns "$POL_HOST" "$POL_PORT")"
	POL_Debug_Message "icon_menu answer: $APP_ANSWER"
}
POL_SetupWindow_checkbox_list ()
{
	# Shows a list of checkbox
	# Usage: POL_SetupWindow_checkbox [message] [title] [list] [separator]
	# Checked boxes are sent in $APP_ANSWER variable, with the same separator

	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_checkbox_list	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	$4" | ncns "$POL_HOST" "$POL_PORT")"
	POL_Debug_Message "checkbox_list answer: $APP_ANSWER"
}
POL_SetupWindow_menu_num ()
{
	# Shows a menu
	# Usage: POL_SetupWindow_menu_num [message] [title] [list] [separator]
	# The number of the result is sent in $APP_ANSWER variable

	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_menu_num	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$3	$4" | ncns "$POL_HOST" "$POL_PORT")"
	POL_Debug_Message "menu_num answer: $APP_ANSWER"
}
POL_SetupWindow_menu_list ()
{
	# Shows a menu (combobox)
	# Usage: POL_SetupWindow_menu [message] [title] [list] [separator]
	# Result is sent in $APP_ANSWER variable
	# Deprecated

	POL_SetupWindow_menu "$@"
}
POL_SetupWindow_shortcuts_list ()
{
	# Shows the shortcut list
	# Usage: POL_SetupWindow_shortcuts_list [message] [title]
	# Result is sent in $APP_ANSWER variable
	
	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_shortcut_list	$$	$(POL_Untab "$1")	$(POL_Untab "$2")" | ncns "$POL_HOST" "$POL_PORT")"
}
POL_SetupWindow_prefix_selector ()
{
	# Shows a prefix selector
	# Usage : POL_SetupWindow_prefix_selector [message]
	# Result is sent in $APP_ANSWER variable
	
	Result="$(echo "$POL_COOKIE	POL_SetupWindow_prefix_selector	$$	$(POL_Untab "$1")	$TITLE" | ncns "$POL_HOST" "$POL_PORT")"

	KINDOF="$(echo $Result | cut -d'~' -f1)" 
	VALUE="$(echo $Result | cut -d'~' -f2)" 
	if [ "$KINDOF" = "2" ]; then
		export APP_ANSWER="$VALUE"
	else
		export APP_ANSWER="$(POL_Shortcut_GetPrefix "$VALUE")"
	fi
}
POL_SetupWindow_login ()
{
	# This function shows a login windows for PlayOnLinux's website
	# Usage: POL_SetupWindow_login "Message" "Title" "Register link"
	
	if [ "$POL_OS" = "Mac" ]; then
		register_link="http://www.playonmac.com/en/register.html"
	else
		register_link="http://www.playonlinux.com/en/register.html"
	fi
	[ "$3" = "" ] || register_link="$3"
	
	Result="$(echo "$POL_COOKIE	POL_SetupWindow_login	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$register_link" | ncns "$POL_HOST" "$POL_PORT")"
	POL_LOGIN="$(echo $Result | cut -d'~' -f1)" 
	POL_PASSWORD="$(echo $Result | cut -d'~' -f2)" 
}
POL_SetupWindow_file ()
{
	# Shows the content of a file
	# Usage: POL_SetupWindow_file [message] [title] [file]
	
	echo "$POL_COOKIE	POL_SetupWindow_file	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$(POL_Untab "$3")" | ncs "$POL_HOST" "$POL_PORT"
}
POL_SetupWindow_textbox_multiline ()
{
	# Same than POL_SetupWindow_textbox, except that it accepts multiline
	# Usage: POL_SetupWindow_textbox_multiline [message] [title] [default value]
	
	APP_ANSWER="$(echo "$POL_COOKIE	POL_SetupWindow_textbox_multiline	$$	$(POL_Untab "$1")	$(POL_Untab "$2")	$(POL_Untab "$3")" | ncns "$POL_HOST" "$POL_PORT")"
	APP_ANSWER="${APP_ANSWER//\\n/
}" # Not the end of POL_SetupWindow_textbox_multiline
	POL_Debug_Message "textbox_multiline answer: $(echo "$APP_ANSWER"|head -n1)[...]"
}



# Higher level functions
POL_SetupWindow_cdrom () 
{
	# Shows the cd-rom list to the user
	# Usage: POL_SetupWindow_cdrom
	# Result is sent to CDROM
	
	# 1 = Numéro du CD
	local LIST_DEVICES_=""

	local LNG_WINE_ASKFORCDROM=$(eval_gettext "Where is mounted your CD-ROM?")
	local LNG_OTHER=$(eval_gettext "Other")
	local LNG_REFRESH=$(eval_gettext "Refresh")
	
	local DEVICES
	case "$POL_OS" in
	    Mac)
		DEVICES="/Volumes" ;;

	    Linux|FreeBSD)
		DEVICES="/media"
		# Ubuntu Quantal workaround
		[ -d "/media/$USER" ] && DEVICES="/media/$USER"
		# Fedora/Manjaro workaround
		[ -d "/run/media/$USER" ] && DEVICES="/run/media/$USER" ;;
	esac
	
	if cd "$DEVICES"; then
		shopt -s nullglob
		for device in *
		do
			if [ ! "$device" = "$LNG_OTHER" ]
			then
					LIST_DEVICES_+="$device~"
			fi
		done
		shopt -u nullglob
	fi
	
	POL_SetupWindow_menu "$LNG_WINE_ASKFORCDROM" "$TITLE" "$LIST_DEVICES_$LNG_OTHER~$LNG_REFRESH" "~"		
	CDROM="$APP_ANSWER"
	
	POL_Debug_Message "CD-ROM selected: $CDROM"
	if [ "$CDROM" = "$LNG_OTHER" ]
	then
		POL_SetupWindow_textbox "$LNG_WINE_ASKFORCDROM" "$TITLE" "$DEVICES/cdrom"
		CDROM="$APP_ANSWER"
	elif [ "$CDROM" = "$LNG_REFRESH" ]
	then
		POL_SetupWindow_cdrom
	else
		CDROMc="$CDROM"
		CDROM="$DEVICES/$CDROM"
	fi


	if [ "$CDROM" = "" ]
	then
		CDROM="$DEVICES/cdrom"
	fi
	POL_Debug_Message "cdrom answer: $CDROM"
}
POL_SetupWindow_check_cdrom ()
{
	# Checks if the cdrom is valid
	# If not, callback to POL_SetupWindow_cdrom
	# Usage: POL_SetupWindow_check_cdrom [setup_name.exe]
	original_args="$@"
	cdrom_found="false"
	CDROM_SETUP=""
	POL_SetupWindow_wait "$(eval_gettext 'Reading your device')" "$TITLE"
	while [ ! "$1" = "" ]; do
		if [ ! "$(find "$CDROM" -iwholename "$CDROM/$1")" = "" ]; then
			cdrom_found="true"
			CDROM_SETUP="$CDROM/$1"
			POL_Debug_Message "$CDROM/$1 FOUND!"
			break
		else
			POL_Debug_Message "$CDROM/$1 not found"
		fi
		shift
	done
	
	if [ "$cdrom_found" = "false" ]; then
		POL_Debug_Warning "Unable to find the CD-ROM"
		POL_SetupWindow_message "$(eval_gettext "Error: Unable to find the CD-ROM!")" "$TITLE"
		POL_SetupWindow_cdrom
		POL_SetupWindow_check_cdrom "$original_args"
	fi
}
POL_SetupWindow_cdrom_MountPC()
{
	if [ "$1" ]; then
		if [ ! "$(find "$CDROM" -iwholename "$CDROM/$1")" = "" ]; then
			return 0
		fi
	fi
	
	if [ "$POL_OS" = "Mac" -a "$CDROMc" ]; then
		POL_SetupWindow_question "$(eval_gettext '$TITLE needs to read the PC part of a hybrid CD-Rom.\n\nBy default, MacOS only gives you access to the Mac part of the cd-rom, which may not be compatible with recent versions of Mac OS.\n\nDo you want PlayOnMac to attempt to read the PC-Part of your CD?')" "$TITLE"
		if [ "$APP_ANSWER" = "TRUE" ]; then
			POL_Debug_Message "Trying to mount windows part of $CDROM"
			process()
			{
			        search="$1"
			        read line
			        while [ "$line" ]; do
			                if [ "${line::5}" = "/dev/" ]; then
			                        latest_device="$line";
			                fi
			                #echo $latest_device
			                if [ ! "$(grep "${search::16}" <<< $line)" = "" ]; then
			                        echo $latest_device
			                        break
			                fi 
			                read line;
			        done
			}
			device="$(diskutil list | process "$CDROMc")"
			rdevice="${device}s1"
			POL_Debug_Message "Preparing to mount $rdevice"
			POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE"
			mount_point="/Volumes/${CDROMc}_Windows"
			mkdir "$mount_point"
			if mount -t cd9660 "$rdevice" "$mount_point"; then
				export CDROM="$mount_point"
				export mount_pc_success="true"
				if [ "$1" ]; then
					if [ "$(find "$CDROM" -iwholename "$CDROM/$1")" = "" ]; then
						POL_Debug_Fatal "Unable to find setup file ($1) on the windows part of the cdrom. Umounting"
						POL_SetupWindow_cdrom_UmountPC
					fi
				fi
			else
				POL_Debug_Error "Your CD-ROM does not seem to be a hybrid Mac/PC CD-ROM" "$TITLE"
				rmdir "$mount_point"
			fi
		fi
	fi
}
POL_SetupWindow_cdrom_UmountPC()
{
	if [ "$POL_OS" = "Mac" -a "$CDROMc" -a "$mount_pc_success" ]; then
		POL_Debug_Message "Umounting PC part : $CDROM"
		umount "$CDROM"
		rmdir "$CDROM"
	fi
}
POL_SetupWindow_cdrom_MountMessage ()
{
	if [ "$POL_OS" = "Mac" ]; then
		POL_SetupWindow_message "$(eval_gettext "Don't forget to go to PlayOnMac tools menu -> Read a PC CD-Rom before running your game")" "$TITLE"
	fi
}
POL_SetupWindow_DirectoryProgress ()
{
	# Progressbar, by reading a directory size
	# Usage: POL_SetupWindow_DirectoryProgress [Directory] [Expected Size] [Pid to check] [Current filename]
	# Good for cdrom copy

	local DIRECTORY="$1"
	local EXPECTED_SIZE="$2"
	local PID="$3"
	local cMESSAGE="${4:+\n$4}"
	[ "$PID" ] || return 1
	POL_SetupWindow_pulsebar "$(eval_gettext 'Please wait while $APPLICATION_TITLE is copying files:')$cMESSAGE" "$TITLE"

	POL_SetupWindow_pulse 0
	
	while [ ! "$(ps aux | awk '{print $2}' | grep $PID)" = "" ]; do
		current_size="$(du "$DIRECTORY"| tail -n 1 | awk '{print $1}')"
		current_perc=$(( 100 * $current_size / ${EXPECTED_SIZE} ))
		POL_SetupWindow_pulse "$current_perc"
		sleep 1
	done

	POL_SetupWindow_pulse 100

	return 0
}

POL_GetSetupImages ()
{
	# This function helps you to manage your setup images
	# It will download images only once, except if you use --force
	#
	# ( optional : --force ) 
	# 1 - Top image url
	# 2 - Left image url
	# 3 - Name (only alpha-numerical please)
	# 
	# Path of images are returned in $POL_SetupWindow_LeftImage and $POL_SetupWindow_TopImage

	if [ "$1" == "--force" ]
	then
		left="$3"
		top="$2"
		name="$4"
	else
		left="$2"
		top="$1"
		name="$3"
	fi	
	mkdir -p "$POL_USER_ROOT/configurations/setups/$name"
	cd "$POL_USER_ROOT/configurations/setups/$name"
    
    if [ "$top" == "" ]; then
        export POL_SetupWindow_TopImage="$PLAYONLINUX/etc/setups/default/top.png"
	elif [ "$1" == "--force" ] || [ ! -e "top" ]; then
		$POL_WGET --timeout=10 "$top" -O top 2> /dev/null && POL_SetupWindow_TopImage="$PWD/top" || export POL_SetupWindow_TopImage="$PLAYONLINUX/etc/setups/default/top.png"
		[ "$POL_SetupWindow_TopImage" = "$PLAYONLINUX/etc/setups/default/top.png" ] &&	rm -f top
	else
		POL_SetupWindow_TopImage="$PWD/top"
	fi

    if [ "$left" == "" ]; then
        export POL_SetupWindow_LeftImage="$PLAYONLINUX/etc/setups/default/left.jpg"
	elif [ "$1" == "--force" ] || [ ! -e "left" ]; then
		$POL_WGET --timeout=10 "$left" -O left 2> /dev/null && POL_SetupWindow_LeftImage="$PWD/left" || export POL_SetupWindow_LeftImage="$PLAYONLINUX/etc/setups/default/left.jpg"
		[ "$POL_SetupWindow_LeftImage" = "$PLAYONLINUX/etc/setups/default/left.jpg" ] && rm -f left
	else
		POL_SetupWindow_LeftImage="$PWD/left"
	fi
	cd "$OLDPWD"
}

POL_SetupWindow_InitWithImages ()
{
	# This function is identical than POL_SetupWindow_Init, excepts that it uses images defined in POL_GetSetupImages
	# Usage: POL_SetupWindow_InitWithImages
	POL_SetupWindow_Init "$@"
}

process_POL_SetupWindow_show_exe ()
{
	### Used by POL_SetupWindow_show_exe
	read line
	local first=true
	while [ ! "$line" = "" ]; do
		[ "$first" = "true" ] && first=false || printf "~"
		printf "$(basename "$line")"
		read line
	done
}
POL_SetupWindow_show_exe ()
{
	# Show the list of non-wine .exe file in the current prefix
	# Usage : POL_SetupWindow_show_exe 

	cd "$WINEPREFIX/drive_c"
	POL_SetupWindow_wait_next_signal "$(eval_gettext "Scanning the virtual drive ...")" "$2"
	contents="$(find . -name windows -prune -o -name iexplore.exe -prune -o -iname '*.exe' -a -type f -print | process_POL_SetupWindow_show_exe)"
	POL_SetupWindow_menu "$1" "$2" "$contents" "~"
}

POL_SetupWindow_VMS ()
{
	# Ask the user how much memory does his graphic board have, and store it to POL config file
	# Usage: POL_SetupWindow_VMS [minimum memory]
	
	[ "$WINEPREFIX" = "" ] && POL_Debug_Fatal "WINEPREFIX is not set !"
	VMS="$(POL_Config_Read VMS)"
	if [ "$VMS" = "" ]
	then
		POL_SetupWindow_menu "$(eval_gettext "How much memory (in MB) does your graphics board have?")" "$TITLE" "64-128-256-320-384-512-640-768-896-1024-1536-1792-2048-3072-4096" "-"
		VMS="$APP_ANSWER"
		POL_Config_Write VMS $APP_ANSWER
	fi
	POL_Wine_Direct3D "VideoMemorySize" "$VMS"
	if [ ! "$1" = "" ]
	then
		if [ $VMS -lt $1 ]
		then
			POL_Debug_Warning "$(eval_gettext "Video card does not have enough memory")" "$TITLE"
			POL_SetupWindow_message "$(eval_gettext "Your video card does not have enough memory!\nIt might prevent the game from working")" "$TITLE"
		fi
	fi
}

POL_SetupWindow_InstallMethod()
{
	# Shows a list of install methods
	# Usage: POL_SetupWindow_InstallMethod [List]
	# Elements in list are separated by a coma
	# Accepted methods are STEAM, STEAM_DEMO, LOCAL, CD, DVDROM, DOWNLOAD, ORIGIN, ORIGIN_DEMO, DESURA, DESURA_DEMO

	[ "$1" = "" ] && POL_Debug_Fatal "No method in list"
	STR=""
	ICO=""
	LNG_STEAM="$(eval_gettext "Use Steam Store version")"
	LNG_STEAM_DEMO="$(eval_gettext "Use Steam Store demo version")"
	LNG_DESURA="$(eval_gettext "Use Desura Store version")"
	LNG_DESURA_DEMO="$(eval_gettext "Use Desura Store demo version")"
	LNG_ORIGIN="$(eval_gettext "Use Origin Store version")"
	LNG_ORIGIN_DEMO="$(eval_gettext "Use Origin Store demo version")"
	
	LNG_LOCAL="$(eval_gettext "Use a setup file in my computer")"
	LNG_CDROM="$(eval_gettext "Use CD-ROM(s)")"
	LNG_DVD="$(eval_gettext "Use DVD-ROM(s)")"
	LNG_DOWNLOAD="$(eval_gettext "Download the program")"
	
	if [ ! "$(printf "$1" | grep LOCAL)" = "" ] 
	then 
		STR="$STR~$LNG_LOCAL"
		ICO="$ICO~browse.png"
	fi
	if [ ! "$(printf "$1" | grep CD)" = "" ] 
	then 
		STR="$STR~$LNG_CDROM"
		ICO="$ICO~cdrom.png"
	fi
	if [ ! "$(printf "$1" | grep DVD)" = "" ] 
	then 
		STR="$STR~$LNG_DVD"
		ICO="$ICO~cdrom.png"
	fi
	if [ ! "$(printf "$1" | grep STEAM)" = "" ] 
	then 
		STR="$STR~$LNG_STEAM"
		ICO="$ICO~download.png"
	fi
	if [ ! "$(printf "$1" | grep STEAM_DEMO)" = "" ] 
	then 
		STR="$STR~$LNG_STEAM_DEMO"
		ICO="$ICO~download.png"
	fi
	
	if [ ! "$(printf "$1" | grep DESURA)" = "" ] 
	then 
		STR="$STR~$LNG_DESURA"
		ICO="$ICO~download.png"
	fi
	if [ ! "$(printf "$1" | grep DESURA_DEMO)" = "" ] 
	then 
		STR="$STR~$LNG_DESURA_DEMO"
		ICO="$ICO~download.png"
	fi
	
	if [ ! "$(printf "$1" | grep ORIGIN)" = "" ] 
	then 
		STR="$STR~$LNG_ORIGIN"
		ICO="$ICO~download.png"
	fi
	if [ ! "$(printf "$1" | grep ORIGIN_DEMO)" = "" ] 
	then 
		STR="$STR~$LNG_ORIGIN_DEMO"
		ICO="$ICO~download.png"
	fi
	
	
	if [ ! "$(printf "$1" | grep DOWNLOAD)" = "" ] 
	then 
		STR="$STR~$LNG_DOWNLOAD"
		ICO="$ICO~download.png"
	fi
	
	STR="${STR:1}"
	ICO="${ICO:1}"
	
	mkdir -p "$POL_USER_ROOT/tmp/cache/icons/InstallMethod"
	cp "$PLAYONLINUX/resources/images/icones/browse.png" "$POL_USER_ROOT/tmp/cache/icons/InstallMethod"
	cp "$PLAYONLINUX/resources/images/icones/cdrom.png" "$POL_USER_ROOT/tmp/cache/icons/InstallMethod"
	cp "$PLAYONLINUX/resources/images/icones/download.png" "$POL_USER_ROOT/tmp/cache/icons/InstallMethod"
	
	POL_SetupWindow_icon_menu "$(eval_gettext "Please choose an installation method")" "$TITLE"  "$STR" "~" "$POL_USER_ROOT/tmp/cache/icons/InstallMethod" "$ICO"
	
	# Si l'utilisateur n'a rien choisi
	if [ "$APP_ANSWER" = "" ]
	then
		POL_SetupWindow_InstallMethod "$@"
		return
	fi
	
	[ "$APP_ANSWER" = "$LNG_LOCAL" ] && INSTALL_METHOD="LOCAL"
	[ "$APP_ANSWER" = "$LNG_STEAM" ] && INSTALL_METHOD="STEAM"
	[ "$APP_ANSWER" = "$LNG_STEAM_DEMO" ] && INSTALL_METHOD="STEAM_DEMO"
	[ "$APP_ANSWER" = "$LNG_DESURA" ] && INSTALL_METHOD="DESURA"
	[ "$APP_ANSWER" = "$LNG_DESURA_DEMO" ] && INSTALL_METHOD="DESURA_DEMO"
	[ "$APP_ANSWER" = "$LNG_ORIGIN" ] && INSTALL_METHOD="ORIGIN"
	[ "$APP_ANSWER" = "$LNG_ORIGIN_DEMO" ] && INSTALL_METHOD="ORIGIN_DEMO"
	[ "$APP_ANSWER" = "$LNG_DOWNLOAD" ] && INSTALL_METHOD="DOWNLOAD"
	[ "$APP_ANSWER" = "$LNG_DVD" ] && INSTALL_METHOD="DVD"
	[ "$APP_ANSWER" = "$LNG_CDROM" ] && INSTALL_METHOD="CD"
	
	
	POL_Debug_Message "Install method: $INSTALL_METHOD"
}
POL_SetupWindow_shortcut_creator()
{
	# Shows a shortcut creator
	# Usage: POL_SetupWindow_shortcut_creator
	# No argument, this function uses WINEPREFIX
	[ "$WINEPREFIX" = "" ] && POL_Debug_Fatal "POL_SetupWindow_shortcut_creator : wineprefix not set"
	
	local LNG_FINISH="$(eval_gettext "I don't want to make another shortcut")"
	local LNG_BROWSE="$(eval_gettext "Browse")"
	local CODENAME="$(POL_MD5 "$WINEPREFIX")"
	mkdir -p "$POL_USER_ROOT/tmp/cache/icons/$CODENAME"
	cp "$PLAYONLINUX/resources/images/icones/browse.png" "$POL_USER_ROOT/tmp/cache/icons/$CODENAME"
	cp "$PLAYONLINUX/resources/images/icones/finish.png" "$POL_USER_ROOT/tmp/cache/icons/$CODENAME"
	while true; do
		POL_SetupWindow_wait_next_signal "$(eval_gettext "Scanning the virtual drive ...")" "$TITLE"
		local existing="$(get_existing_POL_SetupWindow_shortcut_creator)"
		cd "$WINEPREFIX/drive_c" || POL_Debug_Fatal "Prefix : $WINEPREFIX does not exist"
		local contents="$(find . -name windows -prune -o -name iexplore.exe -prune -o \( -iname '*.exe' -o -iname '*.lnk' -o -iname '*.bat' -o -iname '*.cmd' \) -a -type f -print | process_POL_SetupWindow_shortcut_creator)"
		local CONTENTS2=""
		[ -z "$contents" ] || CONTENTS2="~$contents"
		POL_SetupWindow_icon_menu "$(eval_gettext "Please choose a file for $APPLICATION_TITLE to make a shortcut")" "$TITLE"  "$LNG_FINISH~$LNG_BROWSE$CONTENTS2" "~" "$POL_USER_ROOT/tmp/cache/icons/$CODENAME" "finish.png~browse.png$CONTENTS2"
		[ "$APP_ANSWER" = "$LNG_FINISH" ] && break

		local EXE_FILE
		local EXE_PATH
		if [ "$APP_ANSWER" = "$LNG_BROWSE" ]
		then
			cd $WINEPREFIX/drive_c
			POL_SetupWindow_browse "$(eval_gettext "Please choose a file for $APPLICATION_TITLE to make a shortcut")" "$TITLE"
			EXE_FILE="$(basename "$APP_ANSWER")"
			EXE_PATH="$(dirname "$APP_ANSWER")"
		else
			EXE_FILE="$APP_ANSWER"
		fi

		if [ -n "$EXE_FILE" ]
		then
			local SUGGEST="${EXE_FILE%.*}"
			if [ -e "$POL_USER_ROOT/shortcuts/$SUGGEST" ]; then
				local ALTSUGGEST=""
				local wineprefix="$WINEPREFIX"
				wineprefix=${wineprefix//"//"/"/"}
				if [ "$(detect_wineprefix "$SUGGEST")" != "$wineprefix" ]; then
					local PREFIX="$(POL_Wine_GetPrefixFromPath "$WINEPREFIX")"
					ALTSUGGEST="$SUGGEST ($PREFIX)"
				fi
				if [ -n "$ALTSUGGEST" ] && [ ! -e "$POL_USER_ROOT/shortcuts/$ALTSUGGEST" ]; then
					SUGGEST="$ALTSUGGEST"
				else
					let SUGGEST_VERSION=2
					while [ -e "$POL_USER_ROOT/shortcuts/$SUGGEST ($SUGGEST_VERSION)" ]; do
						let SUGGEST_VERSION++
					done
					SUGGEST="$SUGGEST ($SUGGEST_VERSION)"
				fi
			fi
			while true; do
				POL_SetupWindow_textbox "$(eval_gettext "Please choose a shortcut name for $EXE_FILE")" "$TITLE" "$SUGGEST"
				SUGGEST="$APP_ANSWER"
				[ ! -e "$POL_USER_ROOT/shortcuts/$SUGGEST" ] && break
				POL_SetupWindow_question "$(eval_gettext "A shortcut by that name already exists, overwrite?")" "$TITLE"
				if [ "$APP_ANSWER" = "TRUE" ]; then
					rm "$POL_USER_ROOT/shortcuts/$SUGGEST"
					break
				fi
			done
			POL_Shortcut "$EXE_FILE" "$SUGGEST" "" "" "" "$EXE_PATH"
			echo "POL_Shortcut \"$EXE_FILE\" \"$SUGGEST\"" >> "$POL_USER_ROOT/tmp/shortcuts"
		fi
	done
}

process_POL_SetupWindow_shortcut_creator ()
{
	### Used by POL_SetupWindow_shortcut_creator
	local sep=""
	while read runnable; do
		local filename="$(basename "$runnable")"
		if [ -z "$(grep "$filename" <<<"$existing")" ]; then
			local target="$WINEPREFIX/drive_c/$runnable"
			[[ "$runnable" =~ \.lnk$ ]] && target="$(winepath -u "$(strings "$target"|tail -n 1)")"
			#echo "$runnable: Trying to extract icon off $target" >&2
			POL_ExtractIcon "$target" "$POL_USER_ROOT/tmp/cache/icons/$CODENAME/$filename" > /dev/null 2>&1
			# Prefix with priority
			case "$filename" in
			   *.exe) echo "1$filename" ;;
			   *.lnk) echo "2$filename" ;;
			   *) echo "9$filename"
			esac
		else
			POL_Debug_Message "Skipped $filename (shortcut already exists)"
		fi
	done |\
	# Sort by priority, remove duplicates
	sort -u |\
	while read filename; do
		# Strip priority
		printf "$sep${filename:1}"
		sep="~"
	done
}
get_existing_POL_SetupWindow_shortcut_creator()
{
	### Used by POL_SetupWindow_shortcut_creator
	local wineprefix="$WINEPREFIX"
	wineprefix=${wineprefix//"//"/"/"}
	local OLDIFS="$IFS"
	local IFS=$'\n'
	pushd "$POL_USER_ROOT/shortcuts/" &&
	for shortcut in *
	do
		IFS="$OLDIFS"
		if [ "$(detect_wineprefix "$shortcut")" = "$wineprefix" ]; then
			detect_appexec "$shortcut"
		fi
	done
	popd
}

POL_SetupWindow_RequiredCard()
{
	# Forcing usage of one kind of video card
	
	# Usage : POL_Wine_RequiredCard "NVIDIA,INTEL" (-v = blacklist) (for exemple)
	MyCard="$(POL_Wine_DetectCard)"
	
	if [ ! "$(printf "$1" | grep "$MyCard" $2)" = "" ]; then
		NOBUGREPORT="TRUE"
		POL_Debug_Fatal "Sorry, your video card ($MyCard) is not supported to run $TITLE"
	fi
}
POL_SetupWindow_AdvisedCard()
{
	# Advising usage of one kind of video card
	
	# Usage : POL_Wine_RequiredCard "NVIDIA,INTEL" (-v = blacklist) (for exemple)
	MyCard="$(POL_Wine_DetectCard)"
	
	if [ ! "$(printf "$1" | grep "$MyCard" $2)" = "" ]; then
		NOBUGREPORT="TRUE"
		POL_Debug_Error "Your video card ($MyCard) might cause problems to run $TITLE"
	fi
}

POL_SetupWindow_TestedCard()
{
	# Suggesting usage of one kind of video card
	
	# Usage : POL_Wine_TestCard "NVIDIA,INTEL" (-v = blacklist) (for exemple)
	MyCard="$(POL_Wine_DetectCard)"
	
	if [ ! "$(printf "$1" | grep "$MyCard" $2)" = "" ]; then
		POL_SetupWindow_message "Your video card ($MyCard) has not been tested with $TITLE. Don't hesitate to send us feedbacks, so we can improve $APPLICATION_TITLE" "$TITLE"
	fi
}

POL_SimpleMessage ()
{
	# Shows a text box
	# Usage: POL_SetupWindow_textbox [message] [title] [default value]
	# Result is sent in $APP_ANSWER variable

	echo "$POL_COOKIE	SimpleMessage	$(POL_Untab "$1")" | ncs "$POL_HOST" "$POL_PORT"
}

POL_SetupWindow_SetID()
{
	echo "$POL_COOKIE	POL_SetupWindow_SetID	$$	$1" | ncs "$POL_HOST" "$POL_PORT"	
}

POL_SetupWindow_UnsetID()
{
	echo "$POL_COOKIE	POL_SetupWindow_UnsetID	$$" | ncs "$POL_HOST" "$POL_PORT"	
}