From a419d4e80884b7beb2e46c13b47a513d4ccc99de Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 10 Jan 2019 20:55:50 -0700 Subject: [PATCH] Added find_user_wallpapers.py * Fixes issue #16 --- .bin/Scripts/find_user_wallpapers.py | 81 ++++++++++++++++++++++++++++ .bin/Scripts/settings/launchers.py | 5 ++ 2 files changed, 86 insertions(+) create mode 100644 .bin/Scripts/find_user_wallpapers.py diff --git a/.bin/Scripts/find_user_wallpapers.py b/.bin/Scripts/find_user_wallpapers.py new file mode 100644 index 00000000..3ea182f5 --- /dev/null +++ b/.bin/Scripts/find_user_wallpapers.py @@ -0,0 +1,81 @@ +# Wizard Kit: Find user wallpaper(s) + +import os +import sys + +# STATIC VARIABLES +EXPLORER_LOCATIONS = [ + r'{APPDATA}\Microsoft\Internet Explorer\Internet Explorer Wallpaper.bmp', + r'{APPDATA}\Microsoft\Windows\Themes\TranscodedWallpaper.jpg', + r'{APPDATA}\Mozilla\Firefox\Desktop Background.bmp', + ] +REG_HKCU_LOCATIONS = { + r'Control Panel\Desktop': 'Wallpaper', + r'Software\Microsoft\Internet Explorer\Desktop\General': 'WallpaperSource', + } + +# Init +os.chdir(os.path.dirname(os.path.realpath(__file__))) +sys.path.append(os.getcwd()) +from functions.cleanup import * +init_global_vars() +os.system('title {}: Find user wallpaper(s)'.format(KIT_NAME_FULL)) + +if __name__ == '__main__': + try: + stay_awake() + clear_screen() + + # Build list of wallpaper paths + wall_paths = [s.format(**global_vars['Env']) for s in EXPLORER_LOCATIONS] + for k, v in REG_HKCU_LOCATIONS.items(): + with winreg.OpenKey(HKCU, k) as key: + try: + _path = winreg.QueryValueEx(key, v)[0] + except Exception: + # Meh, ignore + pass + else: + wall_paths.append(_path) + + # Copy files into ClientDir + dest_folder = r'{}\{}\Wallpapers'.format( + global_vars['BackupDir'], + global_vars['Env']['USERNAME'], + ) + os.makedirs(dest_folder, exist_ok=True) + for source_path in wall_paths: + if os.path.exists(source_path): + dest_path = '{}\{}'.format( + dest_folder, + re.sub(r'^.*\\', '', source_path), + ) + dest_path = non_clobber_rename(dest_path) + try: + shutil.copy(source_path, dest_path) + except Exception: + # Meh, ignore + pass + + # Open folder if wallpapers were copied or report error + delete_empty_folders(dest_folder.replace(r'\Wallpaper', '')) + if os.path.exists(dest_folder): + popen_program(['explorer', dest_folder]) + else: + print_warning('No wallpapers found.') + pause('Press Enter to exit...') + + # TODO: DELETEME + print('Wall paths:') + for p in wall_paths: + print(' ', p) + pause('Meh?') + + # Done + exit_script() + except SystemExit: + pass + except: + major_exception() + +# vim: sts=2 sw=2 ts=2 diff --git a/.bin/Scripts/settings/launchers.py b/.bin/Scripts/settings/launchers.py index 80b199c2..ae78c3f5 100644 --- a/.bin/Scripts/settings/launchers.py +++ b/.bin/Scripts/settings/launchers.py @@ -215,6 +215,11 @@ LAUNCHERS = { r'call "%bin%\Scripts\init_client_dir.cmd" /Logs /Transfer', ], }, + 'Find User Wallpapers': { + 'L_TYPE': 'PyScript', + 'L_PATH': 'Scripts', + 'L_ITEM': 'find_user_wallpapers.py', + }, 'KVRT': { 'L_TYPE': 'Executable', 'L_PATH': 'KVRT',