-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUnitron TrueFit Checker.py
118 lines (98 loc) · 5.68 KB
/
Unitron TrueFit Checker.py
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
#############################################################
# #
# Copyright Bluebotlabz #
# #
#############################################################
import requests
from pathlib import Path
from colorama import just_fix_windows_console
from colorama import Fore, Back, Style
import libhearingdownloader
import xml.etree.ElementTree as xml
just_fix_windows_console()
print("\n\n")
print("==================================================")
print("= " + Style.BRIGHT + Fore.CYAN + "Unitron" + Style.RESET_ALL + " TrueFit Update Checker =")
print("="*(47-len(libhearingdownloader.downloaderVersion)) + " " + Fore.GREEN + libhearingdownloader.downloaderVersion + Style.RESET_ALL + " =")
turboFile = Path("turbo.txt")
if not turboFile.is_file():
libhearingdownloader.printWaranty()
disclaimer = [
"DISCLAIMER",
"",
"The contributors of the Hearing Aids Fitting Software Update Checkers (\"The Checker\")",
"do not take any responsability for what you do with The Checker.",
"",
"Unitron is a trademark of Sonova AG",
"Sonova is a trademark of Sonova AG",
"Unitron is a subsidiary of Sonova AG",
"Unitron TrueFit is created by Unitron",
"All rights and credit go to their rightful owners. No copyright infringement intended.",
"",
"The contributors of The Checker, and The Checker itself are not affiliated with or endorsed by",
"Unitron or Sonova AG",
"Depending on how The Checker is used, it may violate the EULA and/or Terms and Conditions of the associated software.",
"The Checker is an UNOFFICIAL project and the use of associated software may be limited."
]
# Display disclaimer
if not turboFile.is_file():
libhearingdownloader.printDisclaimer(disclaimer)
print("\n\nFetching Data...")
# Yh that's right, Phonak namespace...
xmlns = "{http://cocoon.phonak.com}" # Define the xmlns
updaterRetries = libhearingdownloader.updaterRetries
while updaterRetries > 0:
try:
xmlData = requests.get("https://svc.myunitron.com/1/ObjectLocationService.svc/FittingApplicationInstaller/index?appName=Unitron%20TrueFit&appVer=5.1.0.25391&dist=Unitron&country=GB&subKeys=").text # Request the updater API (spoof older version to get whole installer files rather than "patch" installers)
data = xml.fromstring(xmlData)
break
except:
pass
updaterRetries -= 1
if (updaterRetries == 0):
print("\n" + Fore.RED + "Error" + Style.RESET_ALL + ": Update server could not be reached")
exit(1)
# Get latest version number (Gets full version from xml and removes the fourth version number as that is not used in files)
latestVersion = '.'.join((data[0].find(xmlns + "UpdateVersion").find(xmlns + "Version").text).split(".")[:-1])
print("\n\nThe latest available Unitron TrueFit version is " + Fore.GREEN + "v" + latestVersion + Style.RESET_ALL + "\n\n")
# List of versions
validVersions = [
(latestVersion, 'The latest available Unitron TrueFit verion'),
('manual', 'Manually specify a version (' + Fore.RED + 'WARNING' + Style.RESET_ALL + ': ADVANCED USERS ONLY)')
]
# Select outputDir and targetVersion
outputDir = libhearingdownloader.selectOutputFolder()
targetVersion = validVersions[libhearingdownloader.selectFromList(validVersions)][0]
print("\n\n")
# Logic for "special" versions
if (targetVersion == 'latest'):
targetVersion = latestVersion
elif (targetVersion == 'manual'):
targetVersion = ''
while not targetVersion:
targetVersion = input("\nPlease enter " + Fore.GREEN + "manual TrueFit version" + Style.RESET_ALL + ": ")
if (len(targetVersion.split('.')) > 3 or not targetVersion.replace('.', '').isdecimal()):
print("\nThe version you have selected is " + Fore.RED + "invalid" + Style.RESET_ALL + ".\nPlease try again. (" + Fore.YELLOW + "hint" + Style.RESET_ALL + ": it should be in a similar format to " + Fore.GREEN + "a.b.c" + Style.RESET_ALL + " where " + Fore.GREEN + "a" + Style.RESET_ALL + ", " + Fore.GREEN + "b" + Style.RESET_ALL + ", and " + Fore.GREEN + "c" + Style.RESET_ALL + " are integers)")
targetVersion = ''
elif (input("\nYou have selected version (" + Fore.YELLOW + targetVersion + Style.RESET_ALL + ") are you sure you want to download it? [" + Style.DIM + "(" + Style.BRIGHT + Fore.GREEN + "Y" + Style.RESET_ALL + Style.DIM + ")" + Style.RESET_ALL + "/n] ") == "n"):
targetVersion = ''
# Create download folder
outputDir += "Unitron TrueFit " + targetVersion + "/"
# Get CDN/Download location
unitronCDNPath = data[0].find(xmlns + "Location").text
# Get list of files to download for a specified version from the XML data
print ("Downloading directory index")
filesToDownload = {}
for child in data[0].find(xmlns + "ContentInfos"):
# Construct paths
filesToDownload[(outputDir + child.find(xmlns + "Key").text).replace(latestVersion, targetVersion)] = (libhearingdownloader.normalizePath(unitronCDNPath, False) + libhearingdownloader.normalizePath(child.find(xmlns + "RemotePath").text, False) + child.find(xmlns + "Key").text).replace(latestVersion, targetVersion)
# Download and save the files
print("Downloading " + str(len(filesToDownload.keys())) + " files\n")
currentFile = 1
for fileToDownload in filesToDownload.keys():
if (libhearingdownloader.verboseDebug):
print(filesToDownload[fileToDownload])
# Download file
libhearingdownloader.downloadFile(filesToDownload[fileToDownload], fileToDownload, "Downloading " + fileToDownload.split("/")[-1] + " (" + str(currentFile) + "/" + str(len(filesToDownload.keys())) + ")")
currentFile += 1
print("\n\nDownload Complete!")