|
2 | 2 | #Copyright (C) 2009 - 2019 David CM, released under the GPL.
|
3 | 3 | # Author: David CM <[email protected]> and others.
|
4 | 4 | # note: this file doesn't get settings from the base profile to avoid issues when updating from older versions.
|
5 |
| - |
6 |
| -from synthDrivers._settingsDB import appConfig |
7 |
| -import gui, os, wx, addonHandler |
| 5 | +from logHandler import log |
| 6 | +from synthDrivers._settingsDB import appConfig, DEFAULT_LIB_FOLDER |
| 7 | +import globalVars, gui, os, shutil, wx, addonHandler |
8 | 8 | addonHandler.initTranslation()
|
9 | 9 |
|
| 10 | + |
| 11 | +def preserveFiles(addonName, folder): |
| 12 | + """ |
| 13 | + addonName: the name (identifier) of the addon |
| 14 | + folder: a path for a folder inside the addonName directory. |
| 15 | + """ |
| 16 | + absFolderPath = os.path.abspath(os.path.join(globalVars.appArgs.configPath, "addons", addonName, folder)) |
| 17 | + tempFolder = os.path.abspath(os.path.join(globalVars.appArgs.configPath, "addons", addonName + addonHandler.ADDON_PENDINGINSTALL_SUFFIX, folder)) |
| 18 | + if os.path.isdir(absFolderPath): |
| 19 | + if os.path.isdir(tempFolder): |
| 20 | + shutil.rmtree(tempFolder) |
| 21 | + os.rename(absFolderPath, tempFolder) |
| 22 | + |
10 | 23 | msg=""
|
11 | 24 | if not os.path.exists(os.path.join(os.path.dirname(__file__), 'synthDrivers', appConfig.TTSPath, appConfig.dllName)):
|
12 | 25 | # Translators: the message shown if the driver can't find libraries during installation.
|
13 | 26 | msg = _("""The synthesizer won't be available until you set IBMTTS files. NVDA won't show this synthesizer in teh synthesizers lists because you need to set the IBMTTS files location first.
|
14 | 27 | To do it open the NVDA settings dialog, select IBMTTS category and use the "Browse for IBMTTS library" button to select the IBMTTS files folder.\n""")
|
15 | 28 |
|
16 |
| -# Translators: message box when user is installing the addon in NVDA. |
17 |
| -#msg += _("""if you are using another copy of IBMTTS or similar with a different name, you should not load this driver in the same NVDA session. If you do it, NVDA will fail. |
18 |
| -#To resolve it switch to another synthesizer (E.G espeak) then restart NVDA. Afther that, you can use this new driver.""") |
19 | 29 |
|
20 | 30 | def onInstall():
|
21 |
| - if msg!="": |
| 31 | + try: |
| 32 | + preserveFiles("IBMTTS", fr"synthDrivers\{DEFAULT_LIB_FOLDER}") |
| 33 | + except: |
| 34 | + log.warning("error backing data", exc_info=True) |
| 35 | + if msg != "": |
22 | 36 | gui.messageBox(msg,
|
23 | 37 | # Translators: title of message box when user is installing NVDA
|
24 | 38 | _("IBMTTS driver for NVDA"), wx.OK)
|
0 commit comments