-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
117 lines (107 loc) · 5.2 KB
/
Copy pathutils.py
File metadata and controls
117 lines (107 loc) · 5.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
import lang
import os
import sys
import subprocess
import webbrowser
from PyQt5.QtWidgets import QMessageBox
def log(msg):
print(f"[LOG] {msg}")
def run_script(script_name, args=None):
if os.path.exists(script_name):
cmd = [sys.executable, script_name]
if args:
cmd.extend(args)
subprocess.Popen(cmd, creationflags=subprocess.CREATE_NO_WINDOW)
log(f"Started: {script_name}")
return True
else:
log(f"Script not found: {script_name}")
return False
def run_console_script(script_name, args=None):
if os.path.exists(script_name):
cmd = [sys.executable, script_name]
if args:
cmd.extend(args)
subprocess.Popen(cmd, creationflags=subprocess.CREATE_NEW_CONSOLE)
log(f"Started console: {script_name}")
return True
else:
log(f"Script not found: {script_name}")
return False
def add_proxy_to_telegram(port):
host = "127.0.0.1"
url = f"tg://socks?server={host}&port={port}"
log(f"Adding proxy with port {port} to Telegram")
try:
result = webbrowser.open(url)
if not result:
raise RuntimeError("webbrowser.open returned False")
except Exception:
try:
import pyperclip
pyperclip.copy(url)
QMessageBox.information(None, "Telegram Proxy",
f"Не удалось открыть Telegram автоматически.\n\n"
f"Ссылка для порта {port} скопирована в буфер обмена:\n{url}")
except:
QMessageBox.information(None, "Telegram Proxy",
f"Ссылка для настройки прокси (порт {port}) в Telegram:\n{url}")
def add_http_proxy_to_telegram(port):
msg_ru = (f"Данный прокси (порт {port}) работает по протоколу HTTP.\n\n"
f"Telegram не поддерживает автоматическое добавление HTTP прокси по ссылке. "
f"Пожалуйста, добавьте его вручную:\n\n"
f"1. Настройки Telegram -> Продвинутые -> Тип соединения\n"
f"2. Использовать собственный прокси -> Добавить\n"
f"3. Выберите 'HTTP' (НЕ SOCKS5)\n"
f"4. Сервер: 127.0.0.1, Порт: {port}\n"
f"5. Сохранить")
msg_en = (f"This proxy (port {port}) uses the HTTP protocol.\n\n"
f"Telegram does not support automatically adding HTTP proxies via deep links. "
f"Please add it manually:\n\n"
f"1. Telegram Settings -> Advanced -> Connection type\n"
f"2. Use custom proxy -> Add proxy\n"
f"3. Select 'HTTP' (NOT SOCKS5)\n"
f"4. Server: 127.0.0.1, Port: {port}\n"
f"5. Save")
QMessageBox.information(None, "Telegram HTTP Proxy", msg_en if lang._is_en else msg_ru)
def add_mtproto_to_telegram(port, secret, fake_tls=None):
host = "127.0.0.1"
if fake_tls:
secret_str = "ee" + secret + fake_tls.encode('ascii').hex()
else:
secret_str = "dd" + secret
url = f"tg://proxy?server={host}&port={port}&secret={secret_str}"
log(f"Adding MTProto proxy with port {port} to Telegram")
try:
result = webbrowser.open(url)
if not result:
raise RuntimeError("webbrowser.open returned False")
except Exception:
try:
import pyperclip
pyperclip.copy(url)
QMessageBox.information(None, "Telegram MTProto Proxy",
f"Не удалось открыть Telegram автоматически.\n\n"
f"Ссылка для порта {port} скопирована в буфер обмена:\n{url}")
except:
QMessageBox.information(None, "Telegram MTProto Proxy",
f"Ссылка для настройки прокси (порт {port}) в Telegram:\n{url}")
def open_project_folder(directory):
log(f"Открытие папки проекта: {directory}")
try:
if os.path.exists(directory):
os.startfile(directory)
log(T("Папка проекта открыта", "Project folder opened"))
return True
else:
log(T("Папка проекта не найдена", "Project folder not found"))
return False
except Exception as e:
log(f"Ошибка открытия папки проекта: {e}")
QMessageBox.critical(None, T("Ошибка", "Error"), f"Не удалось открыть папку проекта:\n{e}")
return False
def open_browser_properties():
try:
subprocess.run(['inetcpl.cpl'], shell=True)
except Exception as e:
QMessageBox.warning(None, T("Ошибка", "Error"), f"Не удалось открыть свойства браузера:\n{e}")