From 423cd343fbcd375e661327409c1d92f67ddc1e0d Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 28 Sep 2021 23:23:05 -0600 Subject: [PATCH] Add show_os_name() with support status checks --- scripts/auto_setup.py | 3 +-- scripts/wk/cfg/__init__.py | 1 + scripts/wk/cfg/windows_builds.py | 36 ++++++++++++++++++++++++++++++++ scripts/wk/os/win.py | 33 +++++++++++++++++++++++++++++ scripts/wk/repairs/win.py | 5 ++--- scripts/wk/setup/win.py | 12 ++++++++--- 6 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 scripts/wk/cfg/windows_builds.py diff --git a/scripts/auto_setup.py b/scripts/auto_setup.py index 79f23de5..e30b39e7 100644 --- a/scripts/auto_setup.py +++ b/scripts/auto_setup.py @@ -135,10 +135,9 @@ BASE_MENUS = { 'System Information': ( MenuEntry('AIDA64 Report', 'auto_export_aida64_report'), MenuEntry('Backup Registry', 'auto_backup_registry'), - MenuEntry('Everything (File List)', no_op), ), 'System Summary': ( - MenuEntry('Operating System', no_op), + MenuEntry('Operating System', 'auto_show_os_name'), MenuEntry('Windows Activation', no_op), MenuEntry('Secure Boot', no_op), MenuEntry('Installed RAM', no_op), diff --git a/scripts/wk/cfg/__init__.py b/scripts/wk/cfg/__init__.py index bb77be75..f79d77ef 100644 --- a/scripts/wk/cfg/__init__.py +++ b/scripts/wk/cfg/__init__.py @@ -7,3 +7,4 @@ from . import main from . import net from . import sources from . import ufd +from . import windows_builds diff --git a/scripts/wk/cfg/windows_builds.py b/scripts/wk/cfg/windows_builds.py new file mode 100644 index 00000000..580564b4 --- /dev/null +++ b/scripts/wk/cfg/windows_builds.py @@ -0,0 +1,36 @@ +"""WizardKit: Config - Windows Builds""" +# vim: sts=2 sw=2 ts=2 + + +OLDEST_SUPPORTED_BUILD = 19041 # Windows 10 20H1 +OUTDATED_BUILD_NUMBERS = ( + 9600, # Windows 8.1 Update + 18363, # Windows 10 19H2 + ) +WINDOWS_BUILDS = { + # Windows 7 + '6.1.7600': 'RTM "Vienna"', + '6.1.7601': 'SP1 "Vienna"', + + # Windows 8 + '6.2.9200': 'RTM', + + # Widnows 8.1 + '6.3.9200': '"Blue"', + '6.3.9600': '"Update"', + + # Windows 10 + '10.0.10240': '1507 "Threshold 1"', + '10.0.10586': '1511 "Threshold 2"', + '10.0.14393': '1607 "Redstone 1"', + '10.0.15063': '1703 "Redstone 2"', + '10.0.16299': '1709 "Redstone 3"', + '10.0.17134': '1803 "Redstone 4"', + '10.0.17763': '1809 "Redstone 5"', + '10.0.18362': '1903 / 19H1', + '10.0.18363': '1909 / 19H2', + '10.0.19041': '2004 / 20H1', + '10.0.19042': '20H2', + '10.0.19043': '21H1', + '10.0.19044': '21H2', +} diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index b32866ca..4fa96574 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -16,12 +16,18 @@ except ImportError as err: raise err from wk.borrowed import acpi +from wk.cfg.windows_builds import ( + OLDEST_SUPPORTED_BUILD, + OUTDATED_BUILD_NUMBERS, + WINDOWS_BUILDS, + ) from wk.exe import run_program from wk.std import GenericError, GenericWarning, sleep # STATIC VARIABLES LOG = logging.getLogger(__name__) +ARCH = '64' if platform.architecture()[0] == '64bit' else '32' CONEMU = 'ConEmuPID' in os.environ KNOWN_DATA_TYPES = { 'BINARY': winreg.REG_BINARY, @@ -120,6 +126,33 @@ def is_activated(): return act_str and 'permanent' in act_str +# System Info Functions +def show_os_name(check=True): + """Build OS display name and print it to screen. + + NOTE: If check=True then an exception is raised if the OS version is + outdated or unsupported. + """ + key = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion' + build_version = int(reg_read_value("HKLM", key, "CurrentBuild")) + build_version_full = platform.win32_ver()[1] + details = WINDOWS_BUILDS.get(build_version_full, f'Build {build_version}') + display_name = ( + f'{reg_read_value("HKLM", key, "ProductName")} {ARCH}-bit {details}' + ) + + # Check for support issues + if check: + if build_version in OUTDATED_BUILD_NUMBERS: + raise GenericWarning(f'{display_name} (outdated)') + + if build_version < OLDEST_SUPPORTED_BUILD: + raise GenericError(f'{display_name} (unsupported)') + + # Done + print(display_name) + + # Registry Functions def reg_delete_key(hive, key, recurse=False): # pylint: disable=raise-missing-from diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index 910768c1..07f87bb9 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -52,6 +52,7 @@ from wk.std import ( ) if platform.system() == 'Windows': from wk.os.win import ( + OS_VERSION, get_timezone, set_timezone, reg_delete_value, @@ -64,6 +65,7 @@ if platform.system() == 'Windows': ) else: # Workaround to allow basic testing under non-Windows environments + OS_VERSION = -1 def no_op(*args, **kwargs): # pylint: disable=unused-argument """No-op function.""" # wk.os.win @@ -133,9 +135,6 @@ PROGRAMFILES_32 = os.environ.get( 'PROGRAMFILES', r'C:\Program Files (x86)', ), ) -OS_VERSION = -1 -if platform.system() == 'Windows': - OS_VERSION = float(platform.win32_ver()[0]) POWER_PLANS = { 'Balanced': '381b4222-f694-41f0-9685-ff5bb260df2e', 'Custom': '01189998-8199-9119-725c-ccccccccccc3', diff --git a/scripts/wk/setup/win.py b/scripts/wk/setup/win.py index 786d4371..c5621a3c 100644 --- a/scripts/wk/setup/win.py +++ b/scripts/wk/setup/win.py @@ -42,10 +42,12 @@ from wk.std import ( ) if platform.system() == 'Windows': from wk.os.win import ( + OS_VERSION, activate_with_bios, reg_read_value, reg_set_value, reg_write_settings, + show_os_name, ) from wk.repairs.win import ( backup_all_browser_profiles, @@ -59,6 +61,7 @@ if platform.system() == 'Windows': ) else: # Workaround to allow basic testing under non-Windows environments + OS_VERSION = -1 def no_op(*args, **kwargs): # pylint: disable=unused-argument """No-op function.""" # wk.os.win @@ -66,6 +69,7 @@ else: reg_read_value = no_op reg_set_value = no_op reg_write_settings = no_op + show_os_name = no_op # wk.repairs.win backup_all_browser_profiles = no_op backup_registry = no_op @@ -97,9 +101,6 @@ LIBREOFFICE_XCU_DATA = ''' ''' MENU_PRESETS = Menu() -OS_VERSION = -1 -if platform.system() == 'Windows': - OS_VERSION = float(platform.win32_ver()[0]) PROGRAMFILES_32 = os.environ.get( 'PROGRAMFILES(X86)', os.environ.get( 'PROGRAMFILES', r'C:\Program Files (x86)', @@ -558,6 +559,11 @@ def auto_restore_default_uac(): TRY_PRINT.run('User Account Control...', restore_default_uac) +def auto_show_os_name(): + """Display OS Name.""" + TRY_PRINT.run('Operating System...', show_os_name) + + def auto_windows_temp_fix(): """Restore default ACLs for Windows\\Temp.""" TRY_PRINT.run(r'Windows\Temp fix...', fix_windows_temp)