diff --git a/.bin/Scripts/functions/info.py b/.bin/Scripts/functions/info.py index b81a4922..5f7f3631 100644 --- a/.bin/Scripts/functions/info.py +++ b/.bin/Scripts/functions/info.py @@ -162,7 +162,7 @@ def get_installed_office(): def get_shell_path(folder, user='current'): """Get shell path using SHGetKnownFolderPath via knownpaths, returns str. - + NOTE: Only works for the current user. Code based on https://gist.github.com/mkropat/7550097 """ @@ -175,14 +175,14 @@ def get_shell_path(folder, user='current'): except AttributeError: # Unknown folder ID, ignore and return None pass - + if folderid: try: path = knownpaths.get_path(folderid, getattr(knownpaths.UserHandle, user)) except PathNotFoundError: # Folder not found, ignore and return None pass - + return path def get_user_data_paths(user): @@ -196,7 +196,7 @@ def get_user_data_paths(user): 'Extra Folders': {}, } unload_hive = False - + if user['Name'] == global_vars['Env']['USERNAME']: # We can use SHGetKnownFolderPath for the current user paths['Profile']['Path'] = get_shell_path('Profile') @@ -212,7 +212,7 @@ def get_user_data_paths(user): except Exception: # Profile path not found, leaving as None. pass - + # Shell folders (Prep) if not reg_path_exists(HKU, hive_path) and paths['Profile']['Path']: # User not logged-in, loading hive @@ -226,7 +226,7 @@ def get_user_data_paths(user): except subprocess.CalledProcessError: # Failed to load user hive pass - + # Shell folders shell_folders = r'{}\{}'.format(hive_path, REG_SHELL_FOLDERS) if (reg_path_exists(HKU, hive_path) @@ -252,7 +252,7 @@ def get_user_data_paths(user): if (folder not in paths['Shell Folders'] and os.path.exists(folder_path)): paths['Shell Folders'][folder] = {'Path': folder_path} - + # Extra folders if paths['Profile']['Path']: for folder in EXTRA_FOLDERS: @@ -260,12 +260,12 @@ def get_user_data_paths(user): folder=folder, **paths['Profile']) if os.path.exists(folder_path): paths['Extra Folders'][folder] = {'Path': folder_path} - + # Shell folders (cleanup) if unload_hive: cmd = ['reg', 'unload', r'HKU\{}'.format(TMP_HIVE_PATH)] run_program(cmd, check=False) - + # Done return paths @@ -277,7 +277,7 @@ def get_user_folder_sizes(users): with winreg.OpenKey(HKCU, r'Software\Sysinternals\Du', access=winreg.KEY_WRITE) as key: winreg.SetValueEx(key, 'EulaAccepted', 0, winreg.REG_DWORD, 1) - + for u in users: u.update(get_user_data_paths(u)) if u['Profile']['Path']: @@ -292,7 +292,7 @@ def get_user_folder_sizes(users): def get_user_list(): """Get user list via WMIC, returns list of dicts.""" users = [] - + # Get user info from WMI cmd = ['wmic', 'useraccount', 'get', '/format:csv'] try: @@ -300,10 +300,10 @@ def get_user_list(): except subprocess.CalledProcessError: # Meh, return empty list to avoid a full crash return users - + entries = out.stdout.decode().splitlines() entries = [e.strip().split(',') for e in entries if e.strip()] - + # Add user(s) to dict keys = entries[0] for e in entries[1:]: @@ -314,10 +314,10 @@ def get_user_list(): # Assume SIDs ending with 1000+ are "Standard" and others are "System" e['Type'] = 'Standard' if re.search(r'-1\d+$', e['SID']) else 'System' users.append(e) - + # Sort list users.sort(key=itemgetter('Name')) - + # Done return users @@ -368,23 +368,38 @@ def run_aida64(): '/TEXT', '/SILENT', '/SAFEST'] run_program(cmd, check=False) -def run_bleachbit(): +def run_bleachbit(cleaners=None, preview=True): """Run BleachBit preview and save log. - + This is a preview so no files should be deleted.""" if not os.path.exists(global_vars['LogDir']+r'\BleachBit.log'): + debug_path = r'{}\BleachBit.debug'.format(global_vars['LogDir']) + error_path = debug_path.replace('debug', 'err') + log_path = debug_path.replace('debug', 'log') extract_item('BleachBit', silent=True) - cmd = [global_vars['Tools']['BleachBit'], '--preview', '--preset'] + + # Safety check + if not cleaners: + # Disable cleaning and use preset config + cleaners = ['--preset'] + preview = True + + # Run + cmd = [ + global_vars['Tools']['BleachBit'], + '--preview' if preview else '--clean', + '--debug-log="{}"'.format(debug_path)] + cmd.extend(cleaners) out = run_program(cmd, check=False) + # Save stderr if out.stderr.decode().splitlines(): - with open(global_vars['LogDir']+r'\BleachBit.err', 'a', - encoding='utf-8') as f: + with open(error_path, 'a', encoding='utf-8') as f: for line in out.stderr.decode().splitlines(): f.write(line.strip() + '\n') + # Save stdout - with open(global_vars['LogDir']+r'\BleachBit.log', 'a', - encoding='utf-8') as f: + with open(log_path, 'a', encoding='utf-8') as f: for line in out.stdout.decode().splitlines(): f.write(line.strip() + '\n') diff --git a/.bin/Scripts/system_diagnostics.py b/.bin/Scripts/system_diagnostics.py index 7709c5de..535b14ef 100644 --- a/.bin/Scripts/system_diagnostics.py +++ b/.bin/Scripts/system_diagnostics.py @@ -18,6 +18,65 @@ global_vars['LogFile'] = r'{LogDir}\System Diagnostics.log'.format( D7_MODE = 'd7mode' in sys.argv ERRORS = 0 +# Static Variables +BLEACH_BIT_CLEANERS = { + 'Applications': ( + 'adobe_reader.cache', + 'adobe_reader.tmp', + 'amule.tmp', + 'flash.cache', + 'gimp.tmp', + 'hippo_opensim_viewer.cache', + 'java.cache', + 'libreoffice.cache', + 'liferea.cache', + 'miro.cache', + 'openofficeorg.cache', + 'pidgin.cache', + 'secondlife_viewer.Cache', + 'thunderbird.cache', + 'vuze.backup_files', + 'vuze.cache', + 'vuze.tmp', + 'yahoo_messenger.cache', + ), + 'Browsers': ( + 'chromium.cache', + 'chromium.current_session', + 'chromium.history', + 'firefox.cache', + 'firefox.download_history', + 'firefox.session_restore', + 'firefox.url_history', + 'google_chrome.cache', + 'google_chrome.history', + 'google_chrome.session', + 'google_earth.temporary_files', + 'google_toolbar.search_history', + 'internet_explorer.history', + 'internet_explorer.temporary_files', + 'opera.cache', + 'opera.current_session', + 'opera.download_history', + 'opera.url_history', + 'safari.cache', + 'safari.history', + 'seamonkey.cache', + 'seamonkey.download_history', + 'seamonkey.history', + ), + 'System': ( + 'system.clipboard', + 'system.tmp', + 'winapp2_windows.jump_lists', + 'winapp2_windows.ms_search', + 'windows_explorer.run', + 'windows_explorer.search_history', + 'windows_explorer.thumbnails', + ), +} + + def check_result(result, other_results): """Check result for warnings and errors.""" if not result['CS']: @@ -93,12 +152,18 @@ if __name__ == '__main__': print_info('Scanning for browsers') scan_for_browsers() + # Run BleachBit cleaners + print_info('BleachBit Cleanup') + for k, v in sorted(BLEACH_BIT_CLEANERS.items()): + try_and_print(message=' {}...'.format(k), + function=run_bleachbit, + cs='Done', other_results=other_results, + cleaners=v, preview=bool(not D7_MODE)) + # Export system info print_info('Backup System Information') try_and_print(message='AIDA64 reports...', function=run_aida64, cs='Done', other_results=other_results) - try_and_print(message='BleachBit report...', - function=run_bleachbit, cs='Done', other_results=other_results) if not D7_MODE: backup_browsers() try_and_print(message='File listing...',