Prompt for AV scan if Fab was recently run

Addresses issue #116
This commit is contained in:
2Shirt 2021-10-14 19:52:57 -06:00
parent 3f2b7e24e6
commit 3f48cc4e46
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
4 changed files with 45 additions and 8 deletions

View file

@ -45,6 +45,15 @@ LAUNCHERS = {
},
},
r'Data Transfers': {
"Fab's Autobackup Pro": {
'L_TYPE': 'Executable',
'L_PATH': 'AutoBackupPro',
'L_ITEM': 'autobackup6pro.exe',
'Extra Code': [
r'call "%bin%\Scripts\init_client_dir.cmd"',
r'reg add HKCU\Software\1201-WizardKit /v FabLastRun /t REG_SZ /d %iso_date% /f >nul 2>&1',
],
},
'FastCopy (as ADMIN)': {
'L_TYPE': 'Executable',
'L_PATH': 'FastCopy',

View file

@ -10,6 +10,7 @@ BROWSER_PATHS = {
'Microsoft Edge': 'Microsoft/Edge/Application/msedge.exe',
'Opera': 'Opera/launcher.exe',
}
FAB_TIMEFRAME = 14 # If it's been at least this many days don't prompt for an AV scan
LIBREOFFICE_XCU_DATA = '''<?xml version="1.0" encoding="UTF-8"?>
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http
<item oor:path="/org.openoffice.Setup/Office/Factories/org.openoffice.Setup:Factory['com.sun.star.presentation.Present

View file

@ -162,7 +162,7 @@ def build_menus(base_menus, title):
return menus
def end_session():
def end_session(menus):
"""End Auto Repairs session."""
# Remove logon task
cmd = [
@ -190,11 +190,14 @@ def end_session():
reg_delete_value('HKCU', AUTO_REPAIR_KEY, 'SessionStarted')
except FileNotFoundError:
LOG.error('Ending repair session but session not started.')
try:
cmd = ['reg', 'delete', fr'HKCU\{AUTO_REPAIR_KEY}', '/f']
run_program(cmd)
except CalledProcessError:
LOG.error('Failed to remote Auto Repairs session settings')
for group in menus:
try:
cmd = ['reg', 'delete', fr'HKCU\{AUTO_REPAIR_KEY}\{group}', '/f']
run_program(cmd)
except CalledProcessError:
LOG.error(
'Failed to remove Auto Repairs session settings for group %s', group,
)
def get_entry_settings(group, name):
@ -362,7 +365,7 @@ def run_auto_repairs(base_menus):
show_main_menu(base_menus, menus)
except SystemExit:
if ask('End session?'):
end_session()
end_session(menus)
raise
# Re-check if a repair session was started
@ -398,7 +401,7 @@ def run_auto_repairs(base_menus):
abort()
# Done
end_session()
end_session(menus)
print_info('Done')
pause('Press Enter to exit...')

View file

@ -3,6 +3,7 @@
# vim: sts=2 sw=2 ts=2
import configparser
from datetime import datetime, timedelta
import logging
import json
import os
@ -12,6 +13,7 @@ import sys
from wk.cfg.main import KIT_NAME_FULL
from wk.cfg.setup import (
BROWSER_PATHS,
FAB_TIMEFRAME,
REG_ESET_NOD32_SETTINGS,
LIBREOFFICE_XCU_DATA,
REG_CHROME_UBLOCK_ORIGIN,
@ -43,6 +45,7 @@ from wk.os.win import (
get_volume_usage,
is_activated,
is_secure_boot_enabled,
reg_read_value,
reg_set_value,
reg_write_settings,
)
@ -157,6 +160,24 @@ def build_menus(base_menus, title, presets):
return menus
def check_if_av_scan_is_needed():
"""Check if an AV scan is needed based on last Fab run."""
try:
last_run = reg_read_value(
'HKCU', fr'Software\{KIT_NAME_FULL}', 'FabLastRun',
)
except FileNotFoundError:
# Assuming it isn't needed
return
# Check date and prompt tech if necessary
last_run_date = datetime.strptime(last_run, '%Y-%m-%d')
if datetime.now() - last_run_date < timedelta(days=FAB_TIMEFRAME):
print_warning('Fab was recently run, an AV scan may be needed.')
if not ask('Continue with setup?'):
abort()
def check_os_and_set_menu_title(title):
"""Check OS version and update title for menus, returns str."""
color = None
@ -246,6 +267,9 @@ def run_auto_setup(base_menus, presets):
# Check OS and update title for menus
title = check_os_and_set_menu_title(title)
# Check if AV scan needs to be run
check_if_av_scan_is_needed()
# Generate menus
menus = build_menus(base_menus, title, presets)