File: wine.lib

package info (click to toggle)
playonlinux 4.1.1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: wheezy
  • size: 11,208 kB
  • sloc: python: 6,173; sh: 5,358; ansic: 72; makefile: 8
file content (894 lines) | stat: -rwxr-xr-x 26,892 bytes parent folder | download
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
#!/bin/bash

# Copyright (C) 2007-2012 PlayOnLinux Team
# Copyright (C) 2007 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. 

# wine.lib
# --------
#
# This lib contains wine's api

POL_Wine_GetRegValue()
{
	# Get a value in registry
	# Example : POL_Wine_GetReg_Value Multisampling
	#
	# Read http://wiki.winehq.org/UsefulRegistryKeys

	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"
	local value
	[ -e "$WINEPREFIX/user.reg" ] && value="$(grep "$1" "$WINEPREFIX/user.reg" | head -n 1 | tr -d '"' | cut -d= -f2)"
	POL_Debug_Message "Getting registry value $1. Return: $value"
	echo -n "${value:-default}"
}

POL_Wine_UpdateRegistry ()
{
	# Usage: POL_Wine_UpdateRegistry regbasename
	# registry file must be provided thru stdin
	# File signature ("REGEDIT4") in appended automatically

	(echo "REGEDIT4"; echo ""; cat) > "$POL_USER_ROOT/tmp/$1.reg"
	POL_Wine regedit "$POL_USER_ROOT/tmp/$1.reg" &&
	rm "$POL_USER_ROOT/tmp/$1.reg"
}

POL_Wine_UpdateRegistryPair ()
{
	# Usage: POL_Wine_UpdateRegistryPair key name data
	# data="default": remove the name
	# Remark: restarts wineserver

	if [ "$3" = "default" ]; then
		POL_Wine_UpdateRegistry regkey <<- _EOFINI_
		[$1]
		"$2"=-
		_EOFINI_
	else
		POL_Wine_UpdateRegistry regkey <<- _EOFINI_
		[$1]
		"$2"="$3"
		_EOFINI_
	fi
}

POL_Wine_UpdateRegistryWinePair ()
{
	# Usage: POL_Wine_UpdateRegistryPair subkey name data
	# data="default": remove the name
	# Remark: restarts wineserver

	# Put a "\" before $1 if it's not empty
	POL_Wine_UpdateRegistryPair "HKEY_CURRENT_USER\\Software\\Wine${1:+\\$1}" "$2" "$3"
}

# For all functions below, that can be called from the control panel:
# - Kill wineserver before regedit so regedit works even if the user
#   changed Wine version out of our control;
# - Kill wineserver after regedit so change takes effect immediately

POL_Wine_Direct3D ()
{
	# Change a Direct3D value in registry
	# Usage POL_Wine_Direct3D Key Value

	# Example :: POL_Wine_Direct3D UseGLSL [default / enabled / disabled]
	# default: remove the key
	POL_Debug_Message "Setting wine Direct3D $WINEPREFIX $1 $2"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	wineserver -k
	POL_Wine_UpdateRegistryWinePair 'Direct3D' "$1" "$2"
	wineserver -k
}

POL_Wine_X11Drv ()
{
	# Change a X11Drv value in registry
	# Usage POL_Wine_X11Drv Key Value

	# Example :: POL_Wine_X11Drv UseGLSL [default / enabled / disabled]
	# default: remove the key
	POL_Debug_Message "Setting wine X11Drv $WINEPREFIX $1 $2"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	wineserver -k
	POL_Wine_UpdateRegistryWinePair 'X11 Driver' "$1" "$2"
	wineserver -k
}

POL_Wine_DirectSound ()
{
	# Same that POL_Wine_Direct3D, but for DirectSound
	POL_Debug_Message "Setting wine DirectSound $WINEPREFIX $1 $2"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	wineserver -k
	POL_Wine_UpdateRegistryWinePair 'DirectSound' "$1" "$2"
	wineserver -k
}

POL_Wine_DirectInput ()
{
	# Same that POL_Wine_Direct3D, but for DirectInput
	POL_Debug_Message "Setting wine DirectInput $WINEPREFIX $1 $2"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	wineserver -k
	POL_Wine_UpdateRegistryWinePair 'DirectInput' "$1" "$2"
	wineserver -k
}

Set_OS ()
{
	# Set fake windows OS
	# Usage: Set_OS [1] [2]
	#
	# 1: Possible values: win7, win2008, vista, win2003, winxp, win2000, nt40, winnt351, winme, win98, win95, win31, win30, win20
	# 2: Service Pack: sp1, sp2, sp3, sp4, sp5
	POL_Debug_Message "Setting Windows OS to $1 $2"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	if [ -n "$1" ]; then
		POL_Wine_UpdateRegistryWinePair '' 'Version' "$1"
	fi

	if [ -n "$2" ]; then # Need more testing
		local n
		[ "$2" = "sp1" ] && n=1
		[ "$2" = "sp2" ] && n=2
		[ "$2" = "sp3" ] && n=3
		[ "$2" = "sp4" ] && n=4
		[ "$2" = "sp5" ] && n=5

		POL_Wine_UpdateRegistry setos <<- _EOFINI_
		[HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion]
		"CSDVersion"="Service Pack $n"
		[HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Windows]
		"CSDVersion"=dword:00000${n}00
		_EOFINI_
	fi
}

Set_Managed ()
{
	# Let the windows manager to control wine
	# Usage: Set_Managed (On|Off)

	POL_Debug_Message "Setting wine managed: $1"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	local n
	[ "$1" = "On" ] && n="Y"
	[ "$1" = "Off" ] && n="N"
	if [ -n "$n" ]; then
		POL_Wine_UpdateRegistryWinePair 'X11 Driver' "Managed" "$n"
	else
		POL_Debug_Warning "Unrecognized flag '$1'"
	fi
}

Set_SoundDriver ()
{
	# Set the sound driver
	# Usage: Set_SoundDriver [Driver]
	# Disabled in Mac OS
	POL_Debug_Message "Setting wine SoundDriver $@"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	if [ -n "$1" ]; then
		if [ "$POL_OS" = "Linux" ]; then
			POL_Wine_UpdateRegistryWinePair 'Drivers' 'Audio' "$1"
		else
			POL_Debug_Message "Set_SoundDriver disabled on $POL_OS"
		fi
	fi
}

Set_DXGrab ()
{
	# Enable or disable DXGrab
	# Usage: Set_DXGrab (On|Off)
	# On ou Off
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	local n
	[ "$1" = "On" ] && n="Y" && POL_Debug_Message "Setting DXGrab"
	[ "$1" = "Off" ] && n="N" && POL_Debug_Message "Unsetting DXGrab"
	if [ -n "$n" ]; then
		POL_Wine_UpdateRegistryWinePair 'X11 Driver' 'DXGrab' "$n"
	else
		POL_Debug_Warning "Set_DXGrab: unrecognized flag '$1'"
	fi
}

Set_Iexplore ()
{
	# Make a fake IE6 installation
	# Usage: Set_Iexplore
	POL_Debug_Message "Faking ie6 installation"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	POL_Wine_UpdateRegistry ie <<- _EOFINI_
	[HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer]
	"Version"="6.0.2900.2180"
	_EOFINI_
}

Set_Desktop ()
{
	# Set a desktop environement
	# Usage: Set_Desktop (on|off) [width] [height]

	POL_Debug_Message "Setting Desktop : $1 $2 $3"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	local n
	[ "$1" = "On" ] && n="$2x$3"
	[ "$1" = "Off" ] && n="-1"
	if [ -n "$n" ]; then
		POL_Wine_UpdateRegistryWinePair 'X11 Driver' 'Desktop' "$n"
	else
		POL_Debug_Warning "Unrecognized flag '$1'"
	fi
}

Set_SoundSampleRate ()
{
	# Set Sound sample rate
	# Usage: Set_SoundSampleRate [value]
	# values can be: 48000, 44100, 22050, 16000, 11025, 8000
	POL_Debug_Message "Setting SoundSampleRate to $1"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	if [ -n "$1" ]; then
		POL_Wine_UpdateRegistryWinePair 'DirectSound' 'DefaultSampleRate' "$1"
	else
		# FIXME: should we drop the name instead?
		POL_Debug_Warning "Sample rate missing, skipped"
	fi
}

Set_SoundBitsPerSample ()
{
	# Set Sound bits per sample rate
	# Usage: Set_SoundBitsPerSaple [value]
	# values: 8, 16
	POL_Debug_Message "Setting sound DefaultsBitsPerSample to $1"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	if [ -n "$1" ]; then
		POL_Wine_UpdateRegistryWinePair 'DirectSound' 'DefaultBitsPerSample' "$1"
	else
		# FIXME: should we drop the name instead?
		POL_Debug_Warning "BitsPerSample missing, skipped"
	fi
}

POL_Wine_InstallFonts()
{
	# Install microsoft fonts
	# Usage: POL_Wine_InstallFonts
	OLDDIR="$PWD"
	POL_Debug_Message "Installing microsoft fonts"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	# It's a symlink? If yes, remove it
	rm "$WINEPREFIX/drive_c/windows/Fonts" 2> /dev/null
	mkdir -p "$WINEPREFIX/drive_c/windows/Fonts"

	cp "$POL_USER_ROOT/fonts/"* "$WINEPREFIX/drive_c/windows/Fonts/"
}

Set_SoundHardwareAcceleration ()
{
	# Set sound driver hardware acceleration
	# Values : Full, Standard, Basic, Emulation
	POL_Debug_Message "Setting Sound HardwareAcceleration to $1"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	if [ -n "$1" ]; then
		POL_Wine_UpdateRegistryWinePair 'DirectSound' 'HardwareAcceleration' "$1"
	else
		# FIXME: should we drop the name instead?
		POL_Debug_Warning "Hardware acceleration mode missing, skipped"
	fi
}

Set_SoundEmulDriver ()
{
	# Set sound emul driver
	# Usage: Set_SoundEmulDriver(Y|N)
	POL_Debug_Message "Setting Sound EmulDriver to $1"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	if [ -n "$1" ]; then
		POL_Wine_UpdateRegistryWinePair 'DirectSound' 'EmulDriver' "$1"
	else
		# FIXME: should we drop the name instead?
		POL_Debug_Warning "Sound emulation mode missing, skipped"
	fi
}

POL_LoadVar_PROGRAMFILES()
{
	# Get Program Files folder name and store it to PROGRAMFILES variable
	# Usage: POL_LoadVar_PROGRAMFILES
	POL_Debug_Message "Getting Program Files name"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	PROGRAMFILES=`POL_Wine cmd /c echo "%ProgramFiles%" |tr -d '\015\012'`
	if [ "${PROGRAMFILES}" = "%ProgramFiles%" ]
	then # Var is not defined by wine
		export PROGRAMFILES="Program Files"
	else
		export PROGRAMFILES="${PROGRAMFILES:3}"
	fi
}

Set_WineWindowTitle ()
{
	#name of windowed title:$1
	POL_Debug_Message "Setting window title"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	POL_Wine_UpdateRegistryWinePair 'Explorer' 'Desktop' "$1"
}

POL_LoadVar_Device ()
{
	# Get GPU device id and vendor id
	# Results are stored in VendorID and DeviceID variables

	POL_Debug_Message "Gettings GPU informations"
	if [ "$POL_OS" = "Linux" ]; then
		[ -x /usr/sbin/lspci ] && LSPCI=/usr/sbin/lspci || LSPCI=lspci
		VGA_ID1=`$LSPCI | grep -iE "nvidia|ATI|AMD|intel" | grep VGA | awk '{ print $1 }' | head -n 1`
		VGA_ID2=`$LSPCI -n | grep $VGA_ID1 | awk '{ print $3 }'`
		export VendorID=`echo $VGA_ID2 | cut -d: -f1`
		export DeviceID=`echo $VGA_ID2 | cut -d: -f2`
	fi
	if [ "$POL_OS" = "Mac" ]; then
		export DeviceID="$(system_profiler | grep -A 10 "Graphics/Displays:" | grep "Device ID" | awk '{print $3}' | cut -d x -f2)"
		export VendorID="$(system_profiler | grep -A 10 "Graphics/Displays:" | grep "Vendor:" | awk '{print $3}' | tr -d "()" | cut -d x -f2)"
	fi
	POL_Debug_Message "VendorID : $VendorID"
	POL_Debug_Message "DeviceID : $DeviceID"
}

POL_LoadVar_ScreenResolution ()
{
	if [ "$POL_OS" = "Linux" ]; then
		local RESOLUTION="$(xdpyinfo | grep dimensions | awk '{print $2}')"
		export ScreenWidth="$(echo $RESOLUTION | cut -dx -f1)"
		export ScreenHeight="$(echo $RESOLUTION | cut -dx -f2)"
	fi
	if [ "$POL_OS" = "Mac" ]; then
		export ScreenWidth="$(/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution| awk '{print $2}')"
		export ScreenHeight="$(/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution| awk '{print $4}')"
	fi
	POL_Debug_Message "Screen width: $ScreenWidth"
	POL_Debug_Message "Screen height: $ScreenHeight"
}

POL_Wine_SetVideoDriver()
{
	# Set wine video driver
	# Usage POL_Wine_SetVideoDriver
	POL_Debug_Message "Set wine video driver"
	[ -z "$WINEPREFIX" ] && POL_Debug_Fatal "WINEPREFIX not set"

	POL_LoadVar_Device
	DRVID="vga.dll"
	[ "$VendorID" = "10de" ] && DRVID="nv4_disp.dll"
	[ "$VendorID" = "1002" ] && DRVID="ati2dvag.dll"
	[ "$VendorID" = "8086" ] && DRVID="ig4icd32.dll"
	POL_Debug_Message "Detected video driver: $DRVID"

	POL_Wine_UpdateRegistry VGA_ID_fix <<- _EOFINI_
	[HKEY_CURRENT_USER\\Software\\Wine\\Direct3D]
	"VideoPCIVendorID"="dword:0000$VendorID"
	"VideoPCIDeviceID"="dword:0000$DeviceID"
	"VideoDriver"="$DRVID"
	_EOFINI_
}

POL_AutoWine ()
{
	# Detect if the file is a .exe or a .msi file and run it with POL_Wine
	# Same usage than "wine"
	SETUP_PATH="$@"
	# remove everything up to the last dot
	extension="${SETUP_PATH##*.}"
	if [ "$extension" = "msi" ]
	then
		POL_Wine msiexec /i "$SETUP_PATH"
	else
		# FIXME /unix?
		POL_Wine "$SETUP_PATH"
	fi
}

POL_Wine ()
{
	# Run the good wineversion and store the result to a logfile
	# Same usage than "wine"
	mkdir -p "$WINEPREFIX"
	touch "$WINEPREFIX/playonlinux.log"
	local NoErrors
	if [ "$1" = "--ignore-errors" ]; then
		NoErrors="True"
		shift
	fi
	
	if [ ! "$(POL_Config_Read NO_FSCHECK)" = "TRUE" ]; then
		if [ "$1" = "start" ]; then
			if [ "$2" = "/unix" ]; then
				POL_System_CheckFS "$3"
			else
				POL_System_CheckFS "$2"
			fi
		else
			POL_System_CheckFS "$1"
		fi
	fi
	
	POL_Wine_AutoSetVersionEnv
	POL_Debug_Message "Running wine-$POL_WINEVERSION "$@" "
	POL_Debug_LogToPrefix "Running wine-$POL_WINEVERSION "$@""
	if [ ! "$WINEMENUBUILDER_ALERT" ]; then
		POL_Debug_Message "Notice: PlayOnLinux deliberately disables winemenubuilder. See http://www.playonlinux.com/fr/page-26-Winemenubuilder.html"
		WINEMENUBUILDER_ALERT="Done"
	fi
	if [ "$1" = "regedit" ]; then
		POL_Debug_LogToPrefix "Content of $2"
		echo '-----------' >> "$WINEPREFIX/playonlinux.log"
		cat "$2" >> "$WINEPREFIX/playonlinux.log"
		echo '-----------' >> "$WINEPREFIX/playonlinux.log"
	fi


	if [ "$LOGFILE" = "/dev/null" ]; then
		$(POL_Config_Read BEFORE_WINE) wine "$@"  2> >(grep -v menubuilder | tee -a "$WINEPREFIX/playonlinux.log" >&2) > >(tee -a "$WINEPREFIX/playonlinux.log")
		errors=$?
	else
		$(POL_Config_Read BEFORE_WINE) wine "$@" 2> >(grep -v menubuilder | tee -a "$LOGFILE" "$WINEPREFIX/playonlinux.log" >&2) > >(tee -a "$LOGFILE" "$WINEPREFIX/playonlinux.log")
		errors=$?
	fi

	if [ "$errors" != 0 -a "$NoErrors" != "True" -a "$POL_IgnoreWineErrors" != "True" ]; then
		POL_Debug_Error "$(eval_gettext 'Wine seems to have crashed\n\nIf your program is running, just ignore this message')"
	fi
	POL_Debug_Message "Wine return: $errors"
	return $errors
}

POL_Wine_SelectPrefix()
{
	# Select a wineprefix and remove unexpected chars
	# Usage: POL_Wine_SelectPrefix [prefixname]
	PREFNAME=`printf "$1"| tr -c [[a-zA-Z0-9]\.] '_'`
	POL_Debug_Message "Selecting prefix: $PREFNAME"
	export WINEPREFIX="$POL_USER_ROOT/wineprefix/$PREFNAME"
	export DOSPREFIX="$WINEPREFIX"
	if [ -e "$WINEPREFIX/playonlinux.cfg" ]; then
		export POL_WINEVERSION="$(POL_Config_PrefixRead VERSION)"
	else
		touch "$WINEPREFIX/playonlinux.cfg" 2> /dev/null
	fi
	
	## In fact it's a bad idea
	#if [ "$(POL_Config_PrefixRead ARCH)" = "x86" ]; then ## Comme ca, pas de conflits
	#	export WINEARCH=win32
	#fi
}
POL_Wine_PrefixExists()
{
	# Checks if a prefix exists
	# Usage: POL_Wine_PrefixExists
	# Return True or False
	PREFNAME=`printf "$1"| tr -c [[a-zA-Z0-9]\.] '_'`
	[ -d "$POL_USER_ROOT/wineprefix/$PREFNAME/drive_c" ] && echo "True" || echo "False"
}
POL_Wine_InstallVersion()
{
	# Install a wineverison
	# Usage: POL_Wine_InstallVersion [VERSION]
	[ ! "$1" = "" ] && export POL_WINEVERSION="$1"
	[ "$POL_WINEVERSION" = "" ] && POL_Debug_Fatal "No POL_WINEVERSION set"
	[ "$POL_ARCH" = "" ] && POL_System_SetArch "auto"
	POL_Debug_Message "Installing wine version path: $POL_WINEVERSION, $POL_ARCH"
	[ "$POL_OS" = "Mac" ] && ARCH_PREFIX="darwin"
	[ "$POL_OS" = "Linux" ] && ARCH_PREFIX="linux"
	OLDPATH="$PWD"
	WINE_SECTION="$ARCH_PREFIX-$POL_ARCH"
	WINEDIR="$REPERTOIRE/wine/$WINE_SECTION"
	touch "$WINEDIR/installing"
	if [ ! -e "$WINEDIR/$POL_WINEVERSION" ]
	then
		
		WINE_ADDRESS=$($POL_WGET "$WINE_SITE/$WINE_SECTION.lst" -O- | grep ";$POL_WINEVERSION;" | tail -n 1 | cut -d ";" -f1)
		if [ "$WINE_ADDRESS" = "" ] && [ "$POL_ARCH" = "amd64" ]
		then
			POL_Debug_Warning "Wine $1 amd64 does not exist. Switching to x86"
			POL_System_SetArch "x86"
			POL_Wine_InstallVersion "$1"
		else
			if [ "$WINE_ADDRESS" = "" ]
			then
				POL_Debug_Error "$(eval_gettext "Unable to find version: ")$POL_WINEVERSION"
				POL_SetupWindow_Close
				exit
			fi

			cd "$REPERTOIRE/tmp"
			POL_SetupWindow_download "$(eval_gettext "Downloading Wine: ")$POL_WINEVERSION" "$TITLE" "$WINE_SITE/$WINE_SECTION/$WINE_ADDRESS"
			POL_SetupWindow_wait_next_signal "$(eval_gettext "Downloading Wine: ")$POL_WINEVERSION" "$TITLE"
			sleep 1
			sha1=$($POL_WGET "$WINE_SITE/$WINE_SECTION/$WINE_ADDRESS.sha1" -O- | awk '{print $1}')
			sha1_file=$(shasum "./$WINE_ADDRESS" | awk '{print $1}')
			echo "Server sha1 : $sha1"
			echo "Client sha1 : $sha1_file"

			if [ ! "$sha1" = "$sha1_file" ]
			then
				POL_SetupWindow_message "$(eval_gettext 'The download seems to have failed.')" "$TITLE"
			else
				POL_SetupWindow_wait "$(eval_gettext 'Extracting Wine...')" "$TITLE"
				"$PLAYONLINUX/playonlinux-pkg" -i "$PWD/$WINE_ADDRESS"
			fi
			rm "$WINE_ADDRESS"
			POL_Wine_Install_gecko "$POL_WINEVERSION" "$POL_ARCH"
		fi
	fi
	rm "$WINEDIR/installing"
	
}
POL_Wine_InstallCDROM()
{
	POL_Wine_InstallCDROMCustom "$1" "$CDROM"
}
POL_Wine_InstallCDROMCustom()
{
	if [ "$1" ]; then
		letter="$1:"
	else
		letter="p:"
	fi
	if [ "$CDROM" ]; then
		cd "$WINEPREFIX/dosdevices"
		rm "$letter" 2> /dev/null
		ln -s "$2" "$letter"
	fi
}
POL_Wine_Install_gecko()
{
	# Install gecko for selected wine version
	# Usage : POL_Wine_Install_gecko [ Version ] ( Arch )
	[ -z "$1" ] && return 1
        wine_version="$1"
        unpatched_version=`POL_Wine_GetBaseName "$1"`
	[ "$2" = "amd64" ] && arch="$2" || arch="x86"

	POL_Debug_Message "Installing gecko for wine $unpatched_version $arch"
	gecko_dir="$REPERTOIRE/wine/gecko"
	gecko_file="$REPERTOIRE/configurations/listes/gecko.lst"
	found="$(grep "^${unpatched_version//./\.};" "$gecko_file")"
	[ "$POL_OS" = "Linux" ] && wos="linux"
	[ "$POL_OS" = "Mac" ] && wos="darwin"

	if [ ! -L "$POL_USER_ROOT/wine/$wos-$arch/$wine_version/share/wine/gecko" ]
	then
		POL_Debug_Message "Linking gecko"
		ln -s "$POL_USER_ROOT/wine/gecko/" "$POL_USER_ROOT/wine/$wos-$arch/$wine_version/share/wine/gecko"
	fi
	if [ "$found" ]; then
		gecko1="$(cut -d ';' -f2 <<< $found)"
		gecko2="$(cut -d ';' -f3 <<< $found)"
		md5_1="$(cut -d ';' -f4 <<< $found)"
		md5_2="$(cut -d ';' -f5 <<< $found)"
		
		cd "$gecko_dir"
		if [ "$gecko1" ]; then
			if [ -e "$gecko1" ]; then
				POL_Debug_Message "$gecko1 already installed. Skipping"
			else
				POL_Debug_Message "Installing $gecko1"
				POL_Download "$GECKO_SITE/x86/$gecko1" "$md5_1"
			fi
		fi
		
		if [ "$arch" = "amd64" ]; then
			if [ "$gecko2" ]; then
				if [ -e "$gecko2" ]; then
					POL_Debug_Message "$gecko2 already installed. Skipping"
				else
					POL_Debug_Message "Installing $gecko2"
					POL_Download "$GECKO_SITE/amd64/$gecko2" "$md5_2"
				fi
			fi
		fi
	fi
}
POL_Wine_AutoSetVersionEnv()
{
	# Get the current prefix's version and set PATH environement variable
	# Usage: POL_Wine_AutoSetVersionEnv
	[ "$WINEPREFIX" = "" ] && POL_Debug_Fatal "WINEPREFIX is not set!"
	POL_WINEVERSION="$(POL_Config_PrefixRead "VERSION")"
	POL_ARCH="$(POL_Config_PrefixRead "ARCH")"
	[ "$POL_WINEVERSION" = "" ] || POL_Wine_SetVersionEnv
}
POL_Wine_SetVersionEnv()
{
	# Usage: POL_Wine_SetWineVersion [VERSION]
	# Get first argument's wine version and set PATH environement variable
	[ ! "$1" = "" ] && export POL_WINEVERSION="$1"
	[ "$POL_WINEVERSION" = "" ] && POL_Debug_Warning "No POL_WINEVERSION set, assuming it is reset"
	[ "$POL_WINEVERSION" = "" ] && export POL_WINEVERSION="--reset"
	if [ ! "$POL_WINEVERSION" = "" ]
	then
		[ "$POL_ARCH" = "" ] && POL_System_SetArch "auto"
		POL_Debug_Message "Setting wine version path: $POL_WINEVERSION, $POL_ARCH"
		[ "$POL_OS" = "Mac" ] && ARCH_PREFIX="darwin"
		[ "$POL_OS" = "Linux" ] && ARCH_PREFIX="linux"
		OLDPATH="$PWD"
		WINEDIR="$REPERTOIRE/wine/$ARCH_PREFIX-$POL_ARCH"
		mkdir -p "$WINEDIR"
		cd "$WINEDIR"

		if [ "$POL_WINEVERSION" = "--reset" ]
		then
			export PATH="$PATH_ORIGIN"
			export LD_LIBRARY_PATH="$LD_PATH_ORIGIN"
			export POL_WINEVERSION=""
		else
			if [ ! -e "$WINEDIR/$POL_WINEVERSION" ]
			then
				POL_Debug_Message "Wine $POL_WINEVERSION not installed"
		 		POL_Wine_InstallVersion "$POL_WINEVERSION"
			else
				POL_Debug_Message "\"$WINEDIR/$POL_WINEVERSION\" exists"
			fi
			export PATH="$WINEDIR/$POL_WINEVERSION/bin/:$PATH"
			export LD_LIBRARY_PATH="$WINEDIR/$POL_WINEVERSION/lib/:$LD_LIBRARY_PATH"
		
		fi
	fi
	cd "$OLDPATH"
}
POL_Wine_SetVersionPrefix()
{
	# Usage: POL_Wine_SetVersionPrefix [VERSION]
	# Change a prefix wine version
	[ ! "$1" = "" ] && export POL_WINEVERSION="$1"
	[ "$WINEPREFIX" = "" ] && POL_Debug_Fatal "WINEPREFIX is not set!"

	POL_Config_PrefixWrite "VERSION" "$POL_WINEVERSION"	
}
POL_Wine_PrefixCreate()
{
	# Create a wineprefix
	# Usage: POL_Wine_PrefixCreate [VERSION]
	if [ ! "$1" = "" ]; then
		POL_Debug_Message "Setting POL_WINEVERSION to $1"
		export POL_WINEVERSION="$1"
	elif [ "$POL_WINEVERSION" ]; then
		POL_Debug_Message "POL_WINEVERSION is already set to $POL_WINEVERSION. Using it"
	else
		POL_Debug_Message "No version specified. Using system version ($(wine --version))"
	fi
	
	POL_Debug_Message "Creating prefix ($POL_WINEVERSION)..."
	POL_SetupWindow_wait "$(eval_gettext 'Please wait while the virtual drive is being created...')" "$TITLE"
	[ "$POL_ARCH" = "" ] && POL_System_SetArch "auto"
	[ "$WINEPREFIX" = "" ] && POL_Debug_Fatal "WINEPREFIX is not set!"
	
	if [ -e "$WINEPREFIX" ]; then
		POL_Debug_Message "Prefix already exists"
		touch "$WINEPREFIX/playonlinux.cfg"
		if [ ! "$POL_WINEVERSION" = "" ]; then
			POL_Debug_Message "Setting version to $POL_WINEVERSION"
			POL_Wine_SetVersionPrefix "$POL_WINEVERSION"
			POL_Wine_SetVersionEnv
		fi
	else	# Prefix does not exit, let's create it
		if [ "$POL_WINEVERSION" = "" ]; then
			# System wineversion
			## Really bad idea
			## export WINEARCH=win32
			POL_Debug_InitPrefix
			wine wineboot
			if [ -e "$WINEPREFIX/drive_c/windows/syswow64" ] # It is a 64 bits prefix
			then
				POL_Config_PrefixWrite "ARCH" "amd64"
				POL_Debug_LogToPrefix "This is a 64bits prefix!"
				POL_Config_Write WINE_SYSTEM_ARCH amd64
			else
				POL_Config_PrefixWrite "ARCH" "x86"
				POL_Debug_LogToPrefix "This is a 32bits prefix!"
				POL_Config_Write WINE_SYSTEM_ARCH x86
			fi
			POL_LoadVar_PROGRAMFILES
		else
			mkdir -p "$WINEPREFIX"
			POL_Debug_Message "Using wine $POL_WINEVERSION"
			POL_Wine_InstallVersion "$POL_WINEVERSION"
			POL_Config_PrefixWrite "ARCH" "$POL_ARCH"
			POL_Config_PrefixWrite "VERSION" "$POL_WINEVERSION"
			POL_Wine_AutoSetVersionEnv
			
			POL_Debug_InitPrefix
			
			which wineprefixcreate && [ "$(POL_MD5_file "$(which wineprefixcreate)")" != "5c0ee90682746e811698a53415b4765d" ] && [ ! "$(which wineprefixcreate | grep $APPLICATION_TITLE)" = "" ] && wine wineprefixcreate
			wine wineboot
			POL_LoadVar_PROGRAMFILES
		fi
	fi
	sleep 3 # We wait 3 seconds, so that we are sure that .reg file are created
	POL_LoadVar_PROGRAMFILES
}
POL_Wine_OverrideDLL()
{
	# Override DLLs
	mode=$1
	[ "$mode" = "disabled" ] && unset mode
	shift
 
	cat << EOF > "$POL_USER_ROOT/tmp/override-dll.reg"
REGEDIT4
 
[HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides]
EOF
 
	while test "$1" != ""
	do
		echo "\"*$1\"=\"$mode\"" >> "$POL_USER_ROOT/tmp/override-dll.reg"
		shift
	done
 
	POL_Debug_Message "Overriting DLLs"
	POL_SetupWindow_wait_next_signal "Please wait" "$TITLE"
	POL_Wine regedit "$POL_USER_ROOT/tmp/override-dll.reg"
}

POL_Wine_OverrideDLL_App()
{
	APP="$1"
	MODE="$2"
	DLL="$3"

	cd "$POL_USER_ROOT/ressources"
	[ -e "$POL_USER_ROOT/ressources/app_dll_override.reg" ] && rm app_dll_override.reg

	echo "REGEDIT4" > app_dll_override.reg
	echo "" >> app_dll_override.reg
	echo "[HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\$APP\\DllOverrides]" >> app_dll_override.reg
	until [ "$DLL" == "" ]; do
		if [ "$DLL" = "comctl32" ]; then
			rm -rf "$WINEPREFIX/winsxs/manifests/x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2982_none_deadbeef.manifest"
		fi
		echo "\"$DLL\"=\"$MODE\"" >> app_dll_override.reg
		shift
		DLL="$3"
	done
	POL_Wine regedit app_dll_override.reg
	rm app_dll_override.reg
}
POL_Wine_WaitBefore ()
{
	# Lock bash commands until wine is exited
	# Usage : POL_Wine_WaitExit [Program title] (--allow-kill)
	SOFTNAME="$1"
	if [ "$2" = "--allow-kill" ] 
	then
		allowKill="true"
	else
		allowKill="false"
	fi
	
	[ "$1" = "" ] && message="$(eval_gettext "Please wait...")" || message="$(eval_gettext 'Please wait while $SOFTNAME is installed...')"
	
	if [ "$allowKill" = "true" ]
	then
		POL_SetupWindow_wait_button "$message" "$TITLE" "$(eval_gettext 'Install is done')" "wineserver -k" "$(eval_gettext 'Be careful! This will kill install process. If it is not finished, you will have to reinstall $SOFTNAME')"
	else
		POL_SetupWindow_wait "$message" "$TITLE"
	fi
	
}
POL_Wine_WaitExit ()
{
	# Lock bash commands until wine is exited
	# Usage : POL_Wine_WaitExit (--force-input) [Program title] (--allow-kill)
	if [ "$1" = "--force-input" ] 
	then
		forceInput="true"
		shift
	else
		forceInput="false"
	fi

	SOFTNAME="$1"
	if [ "$2" = "--allow-kill" ] 
	then
		allowKill="true"
	else
		allowKill="false"
	fi
	
	[ "$1" = "" ] && message="$(eval_gettext "Please wait...")" || message="$(eval_gettext 'Please wait while $SOFTNAME is installed...')"
	if [ "$allowKill" = "true" ]
	then
		POL_SetupWindow_wait_button "$message" "$TITLE" "$(eval_gettext 'Install is done')" "wineserver -k" "$(eval_gettext 'Be careful! This will kill install process. If it is not finished, you will have to reinstall $SOFTNAME')"
	else
		POL_SetupWindow_wait "$message" "$TITLE"
	fi
	wineserver -w || POL_SetupWindow_message "$(eval_gettext 'Press next only when the installation process is finished')" "$TITLE"
	[ "$forceInput" = "true" ] && POL_SetupWindow_message "$(eval_gettext 'Press next only when the installation process is finished')" "$TITLE"
}



POL_Wine_reboot ()
{
	# Simulate windows reboot
	POL_SetupWindow_wait_next_signal "$(eval_gettext 'Please wait while $APPLICATION_TITLE is simulating a Windows reboot')" "Wine"
	POL_Wine wineboot
}
POL_Wine_GetPrefixFromPath ()
{
	# Return wineprefix from path
	# Usage POL_Wine_GetPrefixFromPath [Exe file]
	local p="$1"
	p="${p#*/wineprefix/}"
	p="${p%%/*}"
	echo "$p"
}
POL_Wine_GetBaseName()
{
	perl -e '$release=$ARGV[0]; $release =~ s/^([0-9]+\.[0-9]+(\.[0-9]+)?(-rc[0-9]+)?)-?.*$/$1/; print "$release\n"' "$1"	
}
POL_Wine_GetPatchName()
{
	perl -e '$release=$ARGV[0]; $release =~ s/^[0-9]+\.[0-9]+(\.[0-9]+)?(-rc[0-9]+)?-?//; print "$release\n"' "$1"	
}
POL_Lnk_Read()
{
	drive_c_found="false"
	export ANSWER_PATH=""
	export ANSWER_PREFIX=""
	export ANSWER_NAME="$1"
	ANSWER_NAME="${ANSWER_NAME/.lnk/}"
	while read line; do
		if [ "$drive_c_found" = "true" ]; then
			if [ "${line:1:1}" = ":" ]; then
				break
			fi
			if [ "$ANSWER_PATH" = "" ]; then
				ANSWER_PATH="$line"
			else
				ANSWER_PATH="$ANSWER_PATH/$line"
			fi
		fi
		if [ "$line" = "drive_c" ]; then
			drive_c_found="true"
			ANSWER_PREFIX="$lastline"
		fi
		lastline="$line"
	done < <(strings "$1")
}