-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
180 lines (142 loc) · 5.04 KB
/
main.py
File metadata and controls
180 lines (142 loc) · 5.04 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
import os.path
import os
import time
import subprocess
import argparse
import sys
import shutil
import pyuac
import questionary
from questions import *
from constants import *
import constants
from src_computer_name.menu_computer_name import menu_change_computer_name
from src_network.menu_network import menu_change_network
from src_network.change_ip import reset_network_adapters
from src_software.menu_software import menu_manage_software
from src_optimize_windows.menu_optimize_windows import menu_optimize_windows
from src_restart.menu_restart import menu_restart_computer
from src_automations.menu_automations import menu_custom_automations
# ---------------------------------------------------------------------------- #
def utility_folder_init():
if not os.path.exists(UTILITY_FOLDER_PATH):
# print_error("CREATING TCBatch FOLDER IN C DRIVE")
os.makedirs(UTILITY_FOLDER_PATH)
# print_error("CREATING SETTINGS.JSON IN C DRIVE")
save_settings()
elif not os.path.exists(UTILITY_FOLDER_PATH + SETTINGS_FOLDER):
# print_error("CREATING SETTINGS.JSON IN C DRIVE")
save_settings()
elif os.path.exists(UTILITY_FOLDER_PATH) and os.path.exists(UTILITY_FOLDER_PATH + SETTINGS_FOLDER):
# print_error("READING SETTINGS.JSON IN C DRIVE")
with open(UTILITY_FOLDER_PATH + SETTINGS_FOLDER, "r") as json_file:
json_data = json.load(json_file)
download_path = json_data["download path"]
try:
if os.access(download_path, os.W_OK):
constants.DOWNLOAD_FOLDER_PATH = download_path
else:
# print_error("COULD NOT REACH DOWNLOAD FOLDER")
save_settings()
except Exception as e:
print(e)
save_settings()
print(f"CURRENT DOWNLOAD FOLDER {constants.DOWNLOAD_FOLDER_PATH}")
# ----------------- create a copy of the exe for command line prompts ---------------- #
try:
if getattr(sys, 'frozen', False):
# Copy the .exe file to UTILITY_FOLDER_PATH
current_exe_path = sys.executable # Path of the running .exe file
destination_path = os.path.join(UTILITY_FOLDER_PATH, os.path.basename(current_exe_path))
# Copy the file only if it doesn't already exist in the destination
if not os.path.exists(destination_path):
shutil.copy(current_exe_path, destination_path)
except:
pass
# ---------------------------------------------------------------------------- #
# MAIN MENU #
# ---------------------------------------------------------------------------- #
def menu_main():
choices = [
"Manage Windows Settings", #0
"Download / Install Software", #1
"Automations", #2
"Restart Computer"] #3
# WINDOWS BACKUP?
match ask_select(APP_NAME,choices,True):
case 0:
menu_manage_windows()
case 1:
menu_manage_software()
case 2:
menu_custom_automations()
case 3:
menu_restart_computer()
menu_main()
def menu_manage_windows():
choices = [
"Change Computer Name",
"Change Network Settings",
"Optimize Windows",
"Create Startup Shortcut Folder"
]
choices.append("[return]")
cancel = choices[-1]
match ask_select(ASCII_MANAGE_WINDOWS,choices,True):
case 0:
menu_change_computer_name()
case 1:
menu_change_network()
case 2:
# print_hint("-----credit to Andy Babin-----")
menu_optimize_windows()
case 3:
menu_startup_symlink()
case cancel:
return
menu_manage_windows()
# ---------------------------------------------------------------------------- #
# SET STARTUP SYMLINK #
# ---------------------------------------------------------------------------- #
def menu_startup_symlink():
questionary.print("CREATING STARTUP SYMLINK FOLDER", style="bold")
winshell.CreateShortcut(
Path=os.path.join(winshell.desktop(), "Startup_Shortcut.lnk"),
Target=PATH_STARTUP_FOLDER,
Icon=(PATH_STARTUP_FOLDER, 0),
Description="Shortcut to Startup"
)
time.sleep(1)
# print_return()
menu_manage_windows()
def handle_starting_arguments():
parser = argparse.ArgumentParser(description=f'TCBatch {APP_VERSION}')
parser.add_argument('-hello', action='store_true', help='returns "world" for testing')
parser.add_argument('-v', action='store_true', help='returns version')
parser.add_argument('-ip-reset', action='store_true', help='resets all ip addresses sequentially starting at 192.168.8.100 - requires admin')
args, unknown = parser.parse_known_args()
# args = parser.parse_args()
if args.hello:
print("world.")
return False
if args.v:
print(APP_VERSION)
return False
if args.ip_reset:
reset_network_adapters()
return False
return True
# ---------------------------------------------------------------------------- #
# MAIN #
# ---------------------------------------------------------------------------- #
def main():
utility_folder_init()
menu_main()
if __name__ == "__main__":
if handle_starting_arguments():
if not pyuac.isUserAdmin():
print("RE-LAUNCHING AS ADMIN!")
time.sleep(1)
pyuac.runAsAdmin()
else:
main() # Already an admin here.