forked from Log0-git/gdl-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstaller.py
99 lines (78 loc) · 2.65 KB
/
uninstaller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import sys
import winreg
import json
import shutil
import time
import ctypes
import subprocess
import ctypes
ctypes.windll.kernel32.SetConsoleTitleW('GD Localisation Uninstaller')
REG_PATH = 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\GDLoc'
EXPLORER_PATH = os.path.join(os.getenv('WINDIR'), 'explorer.exe')
msg_result = ctypes.windll.user32.MessageBoxW(
0,
'Нажмите ДА, если вы хотите удалить GDL',
'Удаление',
0x000004 | 0x000020 | 0x000100 | 0x040000
)
if not msg_result == 6:
sys.exit(0)
def explore(path):
path = os.path.normpath(path)
if os.path.isdir(path):
subprocess.run([EXPLORER_PATH, path])
elif os.path.isfile(path):
subprocess.run([EXPLORER_PATH, '/select,', path])
def clear_temp():
for j in os.listdir(os.environ['TEMP']):
path = os.path.join(os.environ['TEMP'], j)
if not os.path.isdir(path):
continue
if not j.startswith('_MEI'):
continue
try:
shutil.rmtree(path)
except Exception as er:
print(f'Not fully cleared: {er}')
try:
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
key = winreg.OpenKey(reg, REG_PATH, 0, winreg.KEY_READ)
os.chdir(os.path.dirname(winreg.QueryValueEx(key, 'UninstallString')[0].replace('"', '')))
winreg.DeleteKeyEx(winreg.HKEY_LOCAL_MACHINE, REG_PATH)
except Exception as e:
print(f'Error clearing regedit: {e}')
def try_remove_dir(dir_name):
if os.path.isdir(dir_name):
if os.access(f'{dir_name}/GDLocalisation.dll', os.F_OK):
os.remove(f'{dir_name}/GDLocalisation.dll')
try_remove_dir('adaf-dll')
try_remove_dir('mods')
try_remove_dir('extensions')
try_remove_dir('.GDHM/dll')
temp_file = open('gdl_unins000.txt', 'rb')
backup = json.loads(temp_file.read().decode())
temp_file.close()
for i in backup:
if not os.access(i, os.F_OK) or not os.access(backup[i], os.F_OK):
continue
try:
os.remove(i)
except Exception as e:
print(f'Error removing backup: {e}')
try:
os.rename(backup[i], i)
except Exception as e:
print(f'Error renaming backup: {e}')
try:
os.remove('gdl_unins000.txt')
except Exception as e:
print(f'Error removing file: {e}')
ctypes.windll.user32.MessageBoxW(
0,
'Удаление почти завершено!\nВам осталось удалить файл дезинсталлятора\nНажмите OK, чтобы показать его в проводнике',
'Удаление почти завершено',
0x000000 | 0x000040 | 0x040000
)
explore(sys.executable)
clear_temp()