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
|
#!/usr/bin/python
# -*- coding: UTF-8 -*-
###########################################################################
# winewrite.py - description #
# ------------------------------ #
# begin : Fri Mar 26 2004 #
# copyright : (C) 2006 by Yuriy Kozlov #
# email : yuriy.kozlov@gmail.com #
# #
###########################################################################
# #
# 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. #
# #
###########################################################################
import os
import wineread
import random
""" Provides functions for changings settings in wine """
def SetDriveMappings(drives):
""" Sets wine's drive settings """
driveletters = os.listdir(wineread.winepath + "/dosdevices")
set(driveletters)
for drive in drives[:26]:
letter = drive[1].lower()
defineDrive = False
if letter in driveletters: # The drive exists
if drive[2]: # The drive is in use
# Compare for changes
changed = False
# Check if the mapping changed
if drive[2] != os.readlink(wineread.winepath + "/dosdevices/" + letter):
changed = True
# If it's changed, it will be recreated
if changed:
os.unlink(wineread.winepath + "/dosdevices/" + letter)
defineDrive = True
else:
# Remove the drive
os.unlink(wineread.winepath + "/dosdevices/" + letter)
else: # The drive doesn't exist
if drive[2]: # The drive is in use
# Create it
defineDrive = True
else:
# Do nothing
continue
if defineDrive:
os.symlink(drive[2], wineread.winepath + "/dosdevices/" + letter)
SetDriveTypes(drives[:26])
SetShellLinks(drives[26:])
def SetShellLinks(shelllinks):
existingshelllinks = os.listdir(wineread.winepath + "/dosdevices/c:/windows/profiles/" + os.environ['USER'])
set(existingshelllinks)
shellregistry = wineread.GetShellRegistry()
for link in shelllinks:
createLink = False
if link[1] in existingshelllinks: # The link exists
linkpath = wineread.winepath + "/dosdevices/c:/windows/profiles/" + os.environ['USER'] + "/" + link[1]
if link[2]: # The folder is mapped
# Compare for changes
changed = False
# Check if the mapping changed
if os.path.islink(linkpath) and link[2] != os.readlink(linkpath):
changed = True
elif not os.path.islink(linkpath) and link[2] != linkpath:
changed = True
elif link[5] != shellregistry.get(link[1], wineread.defaultwinfolderspath + "\\" + link[1]):
changed = True
# If it's changed, it will be recreated
if changed:
if os.path.islink(linkpath):
os.unlink(linkpath)
else:
os.rename(linkpath,linkpath + "-backup" + str(random.randint(1,1000000)))
createLink = True
else:
# Remove the link
os.unlink(linkpath)
else: # The link doesn't exist
if link[2]: # The folder is mapped
# Create it
createLink = True
else:
# Do nothing
continue
if createLink:
os.symlink(link[2], wineread.winepath + "/dosdevices/c:/windows/profiles/" + os.environ['USER'] + "/" + link[1])
if shellregistry.has_key(link[1]):
SetShellRegistry(link)
def SetShellRegistry(link):
shellfile=open('.registryshellw.reg','w')
shellfile.write("REGEDIT4\n\n[HKEY_USERS\\.Default\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders]\n")
link[5] = link[5].replace("\\","\\\\")
shellfile.write('"' + link[1] + '"="' + link[5] + '"\n')
shellfile.write("\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders]\n")
link[5] = link[5].replace("\\","\\\\")
shellfile.write('"' + link[1] + '"="' + link[5] + '"\n')
shellfile.write("\n[HKEY_USERS\\.Default\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders]\n")
shellfile.write('"' + link[1] + '"="' + "%USERPROFILE%\\\\" + link[1] + '"')
shellfile.write("\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders]\n")
shellfile.write('"' + link[1] + '"="' + "%USERPROFILE%\\\\" + link[1] + '"')
shellfile.close()
os.system("wine regedit .registryshellw.reg")
os.remove(".registryshellw.reg")
def SetKeyValues(key,settings):
""" Sets all the values in key to those from the dictionary settings """
file=open('.registrykey.reg','w')
file.write("REGEDIT4\n\n[" + key + "]\n")
for setting in settings:
# Casting to a python string is necessary for older versions of pyQT
if str(settings[setting])[:4] == 'hex:':
file.write('"'+str(setting)+'"='+str(settings[setting])+'\n')
else:
file.write('"'+str(setting)+'"="'+str(settings[setting])+'"\n')
file.close()
os.system("wine regedit .registrykey.reg")
os.remove(".registrykey.reg")
def SetValue(key,value,data):
""" Sets the value in key to data """
file=open('.registryvalue.reg','w')
file.write("REGEDIT4\n\n[" + key + "]\n")
file.write('"' + value + '"="' + data + '"')
file.close()
os.system("wine regedit .registryvalue.reg")
os.remove(".registryvalue.reg")
def SetDriveTypes(drives):
""" Sets the type for the drives in the registry """
drivesfile=open('.registrydrives.reg','w')
drivesfile.write("REGEDIT4\n\n[HKEY_LOCAL_MACHINE\\Software\\Wine\\Drives]\n")
for drive in drives:
mapping = drive[2]
if mapping:
drivesfile.write('"' + drive[1] + '"="' + drive[3] + '"\n')
drivesfile.close()
os.system("wine regedit .registrydrives.reg")
os.remove(".registrydrives.reg")
def SetAudioDriver(driver):
""" Sets the audio driver in the registry """
SetValue("HKEY_CURRENT_USER\\Software\\Wine\\Drivers","Audio",driver)
def SetDSoundSettings(settings, app = None):
""" Sets the settings for Direct Sound in the registry """
if not app:
SetKeyValues("HKEY_CURRENT_USER\\Software\\Wine\\DirectSound", settings)
else:
SetKeyValues("HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\" +\
app + "\\DirectSound", settings)
def SetWindowSettings(settings, app = None):
""" Sets the window settings in the registry """
windowsfile=open('.registrywindows.reg','w')
if not app:
windowsfile.write("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Wine\\X11 Driver]\n")
else:
windowsfile.write("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\" +\
app + "\\X11 Driver]\n")
# There is a bug in wine that doesn't allow removing of registry entries from
# a reg file, so unchecking emulate desktop can't be implemented this way yet.
for setting in settings:
if settings[setting]:
windowsfile.write('"'+str(setting)+'"="'+str(settings[setting])+'"\n')
else:
# winecfg removes the value when the emulate desktop checkbox is unchecked
windowsfile.write('"'+str(setting)+'"=-\n')
windowsfile.close()
os.system("wine regedit .registrywindows.reg")
os.remove(".registrywindows.reg")
def SetD3DSettings(settings, app = None):
""" Sets the settings for Direct3D in the registry """
if not app:
SetKeyValues("HKEY_CURRENT_USER\\Software\\Wine\\Direct3D", settings)
else:
SetKeyValues("HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\" +\
app + "\\Direct3D", settings)
def SetDesktopSettings(settings):
""" Sets the control panel \ Desktop settings in the registry """
SetKeyValues("HKEY_CURRENT_USER\\Control Panel\\Desktop", settings)
def SetWinVersion(version, app = None):
"""
Sets the windows version in the registry
Sample format for version:
( "winxp", "Windows XP", 5, 1, 0xA28, "VER_PLATFORM_WIN32_NT", "Service Pack 2", 2, 0, "WinNT")
"""
winverfile=open('.registrywinver.reg','w')
if not app:
winverfile.write("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Wine]\n")
winverfile.write('"Version"="' + version[0] + '"\n')
Key9x = "\n[HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion]\n"
KeyNT = "\n[HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion]\n"
KeyProdNT = "\n[HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\ProductOptions]\n"
KeyWindNT = "\n[HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Windows\n"
KeyEnvNT = "\n[HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment]\n"
versionnumber9x = str(version[2]) + '.' + str(version[3]) + '.' + str(version[4])
versionnumberNT = str(version[2]) + '.' + str(version[3])
if version[5] == "VER_PLATFORM_WIN32_WINDOWS":
winverfile.write(Key9x + '"VersionNumber"="' + versionnumber9x + '"\n')
winverfile.write(Key9x + '"SubVersionNumber"="' + str(version[6]) + '"\n')
winverfile.write(KeyNT + '"CSDVersion"=-\n')
winverfile.write(KeyNT + '"CurrentVersion"=-\n')
winverfile.write(KeyNT + '"CurrentBuildNumber"=-\n')
winverfile.write(KeyProdNT + '"ProductType"=-\n')
winverfile.write(KeyWindNT + '"CSDVersion"=-\n')
winverfile.write(KeyEnvNT + '"OS"=-\n')
elif version[5] == "VER_PLATFORM_WIN32_NT":
winverfile.write(KeyNT + '"CurrentVersion"="' + versionnumberNT + '"\n')
winverfile.write(KeyNT + '"CSDVersion"="' + str(version[6]) + '"\n')
winverfile.write(KeyNT + '"CurrentBuildNumber"="' + str(version[4]) + '"\n')
winverfile.write(KeyProdNT + '"ProductType"="' + str(version[9]) + '"\n')
winverfile.write(KeyWindNT + '"CSDVersion"=dword:00000' + str(version[7]) + '00\n')
winverfile.write(KeyEnvNT + '"OS"="Windows_NT"\n')
winverfile.write(Key9x + '"VersionNumber"=-\n')
winverfile.write(Key9x + '"SubVersionNumber"=-\n')
elif version[5] == "VER_PLATFORM_WIN32s":
winverfile.write(Key9x + '"VersionNumber"=-\n')
winverfile.write(Key9x + '"SubVersionNumber"=-\n')
winverfile.write(KeyNT + '"CSDVersion"=-\n')
winverfile.write(KeyNT + '"CurrentVersion"=-\n')
winverfile.write(KeyNT + '"CurrentBuildNumber"=-\n')
winverfile.write(KeyProdNT + '"ProductType"=-\n')
winverfile.write(KeyWindNT + '"CSDVersion"=-\n')
winverfile.write(KeyEnvNT + '"OS"=-\n')
else:
winverfile.write("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\" +\
app + "]\n")
if version[0] == "global":
winverfile.write('"Version"=-\n')
else:
winverfile.write('"Version"="' + version[0] + '"\n')
winverfile.close()
os.system("wine regedit .registrywinver.reg")
os.remove(".registrywinver.reg")
def SetApps(apps):
""" Adds and removes keys for app specific settings for apps """
oldapps = wineread.GetApps()
newapps = []
# Add new app keys
for app in apps:
if app not in oldapps:
newapps.append(app)
AddApps(newapps)
# Remove removed app keys
for app in oldapps:
if app not in apps:
RemoveApp(app)
def RemoveApp(app):
""" Removes the key for settings for app """
os.system("wine regedit /D HKEY_USERS\\\\S-1-5-4\\\\Software\\\\Wine\\\\AppDefaults\\\\" +\
app)
def AddApps(apps):
""" Adds a key for app """
appsfile=open('.registryapps.reg','w')
appsfile.write("REGEDIT4\n\n")
for app in apps:
appsfile.write('[HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\' +\
app + ']\n')
appsfile.close()
os.system("wine regedit .registryapps.reg")
os.remove(".registryapps.reg")
def SetDllOverrides(overrides, app = None):
""" Sets the dll override settings in the registry """
dllfile=open('.registrydll.reg','w')
if not app:
dllfile.write("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides]\n")
else:
dllfile.write("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Wine\\AppDefaults\\" +\
app + "\\DllOverrides]\n")
origoverrides = wineread.GetDllOverrides(app)
for dll in overrides.keys():
dllfile.write('"'+str(dll)+'"="'+str(overrides[dll])+'"\n')
for dll in origoverrides.keys():
if dll not in overrides:
dllfile.write('"'+str(dll)+'"=-\n')
dllfile.close()
os.system("wine regedit .registrydll.reg")
os.remove(".registrydll.reg")
def SetDefaultBrowser(browser):
"""
Sets the default browser to browser
Doesn't set windows browsers, leaves it for the program to do.
"""
file=open('.registrybrowser.reg','w')
file.write("REGEDIT4\n")
if browser[1] == ':':
for format in wineread.default_browser_formats:
file.write("\n[HKEY_LOCAL_MACHINE\\Software\\Classes\\" +\
format + "\\shell\\open\\command]\n")
file.write('@="' + browser + '"\n')
file.close()
os.system("wine regedit .registrybrowser.reg")
os.remove(".registrybrowser.reg")
else: # winebrowser
for format in wineread.default_browser_formats:
file.write("\n[HKEY_LOCAL_MACHINE\\Software\\Classes\\" +\
format + "\\shell\\open\\command]\n")
file.write('@="winebrowser"\n')
file.close()
os.system("wine regedit .registrybrowser.reg")
os.remove(".registrybrowser.reg")
SetFirstBrowser(browser)
def SetDefaultMailer(mailer):
"""
Sets the default mailer to mailer
Doesn't set windows mailers, leaves it for the program to do.
"""
file=open('.registrymailer.reg','w')
file.write("REGEDIT4\n")
if mailer[1] == ':':
for format in wineread.default_mailer_formats:
file.write("\n[HKEY_LOCAL_MACHINE\\Software\\Classes\\" +\
format + "\\shell\\open\\command]\n")
file.write('@="' + mailer + '"\n')
file.close()
os.system("wine regedit .registrymailer.reg")
os.remove(".registrymailer.reg")
else: # winebrowser
for format in wineread.default_mailer_formats:
file.write("\n[HKEY_LOCAL_MACHINE\\Software\\Classes\\" +\
format + "\\shell\\open\\command]\n")
file.write('@="winebrowser %1"\n')
file.close()
os.system("wine regedit .registrymailer.reg")
os.remove(".registrymailer.reg")
SetFirstMailer(mailer)
def SetFirstBrowser(browser):
""" Sets the first in the list of browsers for winebrowser to use to browser """
originalbrowserlist = wineread.GetNativeBrowserList()
if browser in originalbrowserlist:
originalbrowserlist.remove(browser)
browserlist = [browser] + originalbrowserlist
browserlist = str(browserlist).strip('[]')
browserlist = browserlist.replace("'","")
browserlist = browserlist.replace(", ",",")
SetValue("HKEY_CURRENT_USER\\Software\\Wine\\WineBrowser","Browsers",browserlist)
def SetFirstMailer(mailer):
""" Sets the first in the list of mailers for winebrowser to use to mailer """
originalmailerlist = wineread.GetNativeMailerList()
if mailer in originalmailerlist:
originalmailerlist.remove(mailer)
mailerlist = [mailer] + originalmailerlist
mailerlist = str(mailerlist).strip('[]')
mailerlist = mailerlist.replace("'","")
mailerlist = mailerlist.replace(", ",",")
SetValue("HKEY_CURRENT_USER\\Software\\Wine\\WineBrowser","Mailers",mailerlist)
def CreateWineDrive(path = None):
"""
Creates a fake windows installation in path
"""
if not path:
path = wineread.default_winepath
os.system("WINEPREFIX=" + path + " wineprefixcreate --wait")
# ----- Theming -----
def SetCurrentTheme(theme):
"""
Sets the current theme
theme = (theme,color,size), None if none is set
"""
if not theme:
theme = ("", "", "")
themesettings = {"ColorName":theme[1],
"SizeName":theme[2],
"ThemeActive":"1"}
if not theme[0]:
themesettings["DllName"] = ""
themesettings["ThemeActive"] = "0"
else:
themesettings["DllName"] = "C:\\\\windows\\\\Resources\\\\Themes\\\\" +\
theme[0] + "\\\\" + theme[0] +".msstyles"
themefile=open('.registrytheme.reg','w')
themefile.write("REGEDIT4\n\n[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\ThemeManager]\n")
for setting in themesettings:
if themesettings[setting]:
themefile.write('"'+str(setting)+'"="'+str(themesettings[setting])+'"\n')
else:
themefile.write('"'+str(setting)+'"=-\n')
themefile.close()
os.system("wine regedit .registrytheme.reg")
os.remove(".registrytheme.reg")
def SetColorSettings(colors):
""" Takes a dictionary of color settings and sets them in the registry """
SetKeyValues("HKEY_CURRENT_USER\\Control Panel\\Colors",colors)
SetKeyValues("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\ThemeManager\\Control Panel\\Colors",colors)
def SetWindowMetrics(metrics):
"""
Takes a dictionary of WindowMetrics settings and sets them in the registry
"""
SetKeyValues("HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics",metrics)
ports_translation = {"lp":"lpt","ttyS":"com"}
def CreatePorts(ports = None):
"""
Creates links to ports in dosdevices
"""
if not ports:
# Find ports in /dev
ports = ["lp0"]
for port in ports:
winport = ports_translation[port.rstrip("012345678")] +\
str(int(port.lstrip("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")) + 1)
os.symlink("/dev/" + port, wineread.winepath + "/dosdevices/" + winport)
|