This repository was archived by the owner on Jul 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
206 lines (180 loc) · 7.31 KB
/
app.py
File metadata and controls
206 lines (180 loc) · 7.31 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Creation Date: 02/22/2024
# Creator ID: noEngineer(yesEngineer)
import os
import time
import json
import webbrowser
import subprocess
from colorama import init, Fore, Style
import ctypes
import psutil
# Initialize colorama
init()
# Constants
DATA_FOLDER = os.path.join(os.getenv('APPDATA'), 'XP-Launcher', 'data')
PROFILES_FILE = os.path.join(DATA_FOLDER, 'profiles.json')
PROGRAM_TITLE = "XP-Launcher"
# Windows API constants
SW_SHOWNORMAL = 1
HWND_TOPMOST = 0
SWP_NOMOVE = 0x0002
SWP_NOSIZE = 0x0001
SWP_SHOWWINDOW = 0x0040
class Profile:
def __init__(self, name, paths, update_commands=None, start_gta=False, gta_path=None):
self.name = name
self.paths = paths
self.update_commands = update_commands or []
self.start_gta = start_gta
self.gta_path = gta_path
def open_profile(self):
for path in self.paths:
if path.startswith("http"):
webbrowser.open(path)
else:
subprocess.Popen(path, shell=True) # Start other programs
def update(self):
for command in self.update_commands:
subprocess.run(command, shell=True)
def start_gta_first(self):
if self.start_gta and self.gta_path:
if not self.is_gta_running():
subprocess.Popen(self.gta_path, shell=True) # Start GTA V
print("Starting GTA V...")
while not self.is_gta_running():
time.sleep(1) # Check every 1 second if GTA V is running
print("GTA V started successfully.")
def is_gta_running(self):
process_name = "GTA5.exe"
for proc in psutil.process_iter(['pid', 'name']):
if proc.name() == process_name:
return True
return False
def create_profile():
print_header("Create New Profile")
name = input("Enter profile name: ")
start_gta = input("Start GTA V with this profile? (y/n): ").lower() == 'y'
gta_path = None
if start_gta:
gta_path = input("Enter the path to GTA V shortcut (Grand Theft Auto V.url): ")
paths = input("Enter paths to files separated by commas: ").split(',')
update_commands = input("Enter update commands separated by commas: ").split(',')
profile = Profile(name, paths, update_commands, start_gta, gta_path)
return profile
def load_profiles():
profiles = []
if os.path.isfile(PROFILES_FILE):
with open(PROFILES_FILE, 'r') as f:
for line in f:
if line.strip(): # Check if line is not empty
profile_data = json.loads(line)
profile = Profile(profile_data['name'], profile_data['paths'], profile_data.get('update_commands', []), profile_data.get('start_gta', False), profile_data.get('gta_path'))
profiles.append(profile)
return profiles
def save_profiles(profiles):
with open(PROFILES_FILE, 'w') as f:
for profile in profiles:
profile_data = {'name': profile.name, 'paths': profile.paths, 'update_commands': profile.update_commands, 'start_gta': profile.start_gta, 'gta_path': profile.gta_path}
json.dump(profile_data, f)
f.write('\n')
def print_header(header_text):
print("\n" + Fore.CYAN + Style.BRIGHT + f"== {header_text} ==" + Style.RESET_ALL)
def print_separator():
print("-" * 40)
def center_window(hwnd):
"""Center the window on the screen."""
user32 = ctypes.windll.user32
screensize_x = user32.GetSystemMetrics(0)
screensize_y = user32.GetSystemMetrics(1)
window_rect = ctypes.wintypes.RECT()
user32.GetWindowRect(hwnd, ctypes.byref(window_rect))
window_width = window_rect.right - window_rect.left
window_height = window_rect.bottom - window_rect.top
new_x = screensize_x // 2 - window_width // 2
new_y = screensize_y // 2 - window_height // 2
user32.SetWindowPos(hwnd, HWND_TOPMOST, new_x, new_y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW)
def main():
os.makedirs(DATA_FOLDER, exist_ok=True)
profiles = load_profiles()
# Set console window title
ctypes.windll.kernel32.SetConsoleTitleW(PROGRAM_TITLE)
# Center console window
hwnd = ctypes.windll.kernel32.GetConsoleWindow()
center_window(hwnd)
while True:
os.system("cls")
print_header(PROGRAM_TITLE)
print_separator()
print("Select an option:")
print("1. Profiles")
print("2. Create New Profile")
print("3. Delete Profile")
print("4. Exit")
print_separator()
choice = input("Enter your choice: ")
if choice == "1":
os.system("cls")
if not profiles:
print("No profiles created yet.")
else:
print_header("Profiles")
print_separator() # Added separator here
for i, profile in enumerate(profiles, 1):
print(f"{i}. {profile.name}")
print_separator()
print("0. Go back")
print_separator()
profile_choice = input("Enter profile number: ")
if profile_choice == "0":
continue
try:
profile_index = int(profile_choice)
if 0 < profile_index <= len(profiles):
profile = profiles[profile_index - 1]
profile.start_gta_first() # Start GTA V if necessary
print(f"Updating profile '{profile.name}'...")
profile.update()
print(f"Starting profile '{profile.name}'...")
profile.open_profile()
else:
print("Invalid profile number.")
except ValueError:
print("Invalid input. Please enter a number.")
elif choice == "2":
os.system("cls")
profile = create_profile()
profiles.append(profile)
save_profiles(profiles)
print(f"Profile '{profile.name}' created successfully.")
elif choice == "3":
os.system("cls")
if not profiles:
print("No profiles to delete.")
else:
print_header("Delete Profile")
print_separator() # Added separator here
for i, profile in enumerate(profiles, 1):
print(f"{i}. {profile.name}")
print_separator()
print("0. Go back")
print_separator()
delete_choice = input("Enter profile number to delete: ")
if delete_choice == "0":
continue
try:
delete_index = int(delete_choice)
if 0 < delete_index <= len(profiles):
deleted_profile = profiles.pop(delete_index - 1)
save_profiles(profiles)
print(f"Profile '{deleted_profile.name}' deleted successfully.")
else:
print("Invalid profile number.")
except ValueError:
print("Invalid input. Please enter a number.")
elif choice == "4":
print("Exiting XP-Launcher...")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()