-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler_template.py
More file actions
130 lines (105 loc) · 6.2 KB
/
Copy pathcompiler_template.py
File metadata and controls
130 lines (105 loc) · 6.2 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# compiler_template.py
# --- BAĞIMLILIK İSTEMEYEN SETUP SİHİRBAZI ŞABLONU ---
SETUP_SCRIPT_TEMPLATE = """
import os
import sys
import shutil
import winreg
import ctypes
import tkinter as tk
from tkinter import messagebox
APP_NAME = "__APP_NAME__"
EXE_FILENAME = "__EXE_FILENAME__"
ICON_FILENAME = "__ICON_FILENAME__"
DESCRIPTION = '''__DESCRIPTION__'''
DEFAULT_INSTALL_DIR = os.path.join(os.environ.get("ProgramFiles", "C:\\\\Program Files"), APP_NAME)
def is_admin():
try: return ctypes.windll.shell32.IsUserAnAdmin()
except: return False
if not is_admin():
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
sys.exit()
def resource_path(relative_path):
\"\"\" Exe içinde veya normal çalışma ortamında dosya yolunu bulur \"\"\"
if getattr(sys, 'frozen', False):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.dirname(os.path.abspath(__file__)), relative_path)
class SetupWizard(tk.Tk):
def __init__(self):
super().__init__()
self.title(APP_NAME + " Kurulumu")
self.geometry("480x520")
self.resizable(False, False)
try:
standard_ico = resource_path("ikon2.ico")
if os.path.exists(standard_ico):
self.iconbitmap(standard_ico)
except: pass
self.install_path_var = tk.StringVar(value=DEFAULT_INSTALL_DIR)
self.create_shortcut_var = tk.BooleanVar(value=True)
if ICON_FILENAME:
try:
icon_path = resource_path(ICON_FILENAME)
self.img = tk.PhotoImage(file=icon_path)
tk.Label(self, image=self.img).pack(pady=(15, 5))
except: pass
tk.Label(self, text=APP_NAME + " Kurulumuna Hoş Geldiniz", font=("Arial", 14, "bold")).pack(pady=(5, 10))
if DESCRIPTION.strip():
desc_frame = tk.Frame(self, bg="#f0f0f0", bd=1, relief="sunken")
desc_frame.pack(fill="x", padx=25, pady=5)
scrollbar = tk.Scrollbar(desc_frame)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
desc_text = tk.Text(desc_frame, bg="#f0f0f0", height=6, wrap=tk.WORD, yscrollcommand=scrollbar.set, font=("Arial", 9), bd=0)
desc_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=5, pady=5)
scrollbar.config(command=desc_text.yview)
desc_text.insert(tk.END, DESCRIPTION)
desc_text.config(state=tk.DISABLED)
tk.Label(self, text="Kurulum Konumu:", font=("Arial", 10, "bold")).pack(anchor="w", padx=25, pady=(10, 0))
tk.Entry(self, textvariable=self.install_path_var, width=60).pack(padx=25, pady=5)
tk.Checkbutton(self, text="Masaüstüne Kısayol Oluştur", variable=self.create_shortcut_var, font=("Arial", 10)).pack(anchor="w", padx=25, pady=5)
tk.Button(self, text="Kur", bg="green", fg="white", font=("Arial", 12, "bold"), width=15, command=self.start_installation).pack(pady=15)
def start_installation(self):
install_dir = self.install_path_var.get()
exe_source = resource_path(EXE_FILENAME)
exe_dest = os.path.join(install_dir, EXE_FILENAME)
try:
os.makedirs(install_dir, exist_ok=True)
shutil.copy(exe_source, exe_dest)
uninstaller_path = os.path.join(install_dir, "Uninstall.vbs")
with open(uninstaller_path, "w", encoding="mbcs") as f:
f.write('Set WshShell = CreateObject("WScript.Shell")\\n')
f.write('Set FSO = CreateObject("Scripting.FileSystemObject")\\n')
f.write('On Error Resume Next\\n')
f.write('WshShell.Run "cmd.exe /c reg delete ""HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall\\\\' + APP_NAME + '"" /f", 0, True\\n')
f.write('FSO.DeleteFile WshShell.ExpandEnvironmentStrings("%PUBLIC%") & "\\\\Desktop\\\\' + APP_NAME + '.lnk", True\\n')
f.write('FSO.DeleteFile WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\\\\Desktop\\\\' + APP_NAME + '.lnk", True\\n')
f.write('MsgBox "' + APP_NAME + ' bilgisayarınızdan başarıyla kaldırıldı.", 64, "Kaldırma İşlemi"\\n')
f.write('WshShell.Run "cmd.exe /c ping 127.0.0.1 -n 2 > nul & rmdir /s /q " & Chr(34) & "' + install_dir + '" & Chr(34), 0, False\\n')
if self.create_shortcut_var.get():
public_desktop = os.path.join(os.environ.get("PUBLIC", os.environ.get("USERPROFILE")), "Desktop")
shortcut_path = os.path.join(public_desktop, APP_NAME + ".lnk")
ps_script = (
'$WshShell = New-Object -comObject WScript.Shell\\n'
'$Shortcut = $WshShell.CreateShortcut("' + shortcut_path + '")\\n'
'$Shortcut.TargetPath = "' + exe_dest + '"\\n'
'$Shortcut.WorkingDirectory = "' + install_dir + '"\\n'
'$Shortcut.Save()\\n'
)
import subprocess
subprocess.run(["powershell", "-Command", ps_script], creationflags=0x08000000)
reg_path = "SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall\\\\" + APP_NAME
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, reg_path)
winreg.SetValueEx(key, "DisplayName", 0, winreg.REG_SZ, APP_NAME)
winreg.SetValueEx(key, "UninstallString", 0, winreg.REG_SZ, 'wscript.exe "' + uninstaller_path + '"')
winreg.SetValueEx(key, "DisplayIcon", 0, winreg.REG_SZ, '"' + exe_dest + '"')
winreg.SetValueEx(key, "InstallLocation", 0, winreg.REG_SZ, install_dir)
winreg.CloseKey(key)
messagebox.showinfo("Başarılı", APP_NAME + " başarıyla kuruldu!")
self.destroy()
except Exception as e:
messagebox.showerror("Kurulum Hatası", "Bir hata oluştu:\\n" + str(e))
self.destroy()
if __name__ == "__main__":
app = SetupWizard()
app.mainloop()
"""