From ea2928aac64f2094196af64919a31e14d79c8158 Mon Sep 17 00:00:00 2001 From: Pierre Cosson Date: Wed, 28 Oct 2026 08:50:55 +0000 Subject: [PATCH] Ajouter setup.py --- setup.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7656a91 --- /dev/null +++ b/setup.py @@ -0,0 +1,78 @@ + +# -*- coding: utf-8 -*- +from setuphelpers import * +import winreg + +uninstallkey = [] + +PROFILE = 100 +REG_PATH = ( + r'SOFTWARE\Microsoft\Windows\CurrentVersion' + r'\Explorer\VolumeCaches' +) + +CATEGORIES = { + 'Temporary Files', + 'Thumbnail Cache', + 'Delivery Optimization Files', +} + +FLAG = 'StateFlags{:04d}'.format(PROFILE) + + +def get_categories(): + with reg_openkey_noredir( + winreg.HKEY_LOCAL_MACHINE, REG_PATH + ) as root: + categories = [] + index = 0 + while True: + try: + categories.append(winreg.EnumKey(root, index)) + index += 1 + except OSError: + break + return categories + + +def install(): + available = get_categories() + + for category in available: + path = REG_PATH + '\\' + category + + with reg_openkey_noredir( + winreg.HKEY_LOCAL_MACHINE, + path, + sam=winreg.KEY_SET_VALUE + ) as key: + value = 2 if category in CATEGORIES else 0 + reg_setvalue( + key, FLAG, value, type=winreg.REG_DWORD + ) + + if category in CATEGORIES: + print('Enabled: {}'.format(category)) + + missing = CATEGORIES - set(available) + if missing: + print('Unavailable categories: {}'.format(missing)) + + # Execution silencieuse du profil + run('cleanmgr.exe /sagerun:{}'.format(PROFILE), + timeout=3600) + + +def uninstall(): + for category in get_categories(): + path = REG_PATH + '\\' + category + + with reg_openkey_noredir( + winreg.HKEY_LOCAL_MACHINE, + path, + sam=winreg.KEY_SET_VALUE + ) as key: + try: + winreg.DeleteValue(key, FLAG) + except FileNotFoundError: + pass