File size: 9,375 Bytes
dd98494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66caa01
dd98494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66caa01
dd98494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
@echo off
chcp 65001 > nul
color 0A
title Chahuadev Hub - Python Desktop Builder

setlocal enabledelayedexpansion
set PROJECT_DIR=%~dp0
set SCRIPT=chahuadev_hub.py
set ICON=icons\icon.ico
cd /d "%PROJECT_DIR%"

echo.
echo ╔════════════════════════════════════════════════════════════════════════════════╗
echo ║              🚀 Chahuadev Hub  ^|  Python Desktop Builder                      ║
echo ║              สร้าง .exe (Windows) และ Linux Executable ด้วย PyInstaller        ║
echo ╚════════════════════════════════════════════════════════════════════════════════╝
echo.
echo 📂 โครงการ: %PROJECT_DIR%
echo.

:menu
echo ═══════════════════════════════════════
echo  เลือกคำสั่ง:
echo.
echo  [1]  ▶  รันแอป (python)
echo  [2]  🪟  Build Windows .exe
echo  [3]  🐧  Build Linux Executable (ผ่าน WSL)
echo  [4]  🌐  Build ทั้ง Windows + Linux
echo  [5]  🧹  ล้างโฟลเดอร์ build + dist
echo  [6]  📊  ดูสถานะ / ไฟล์ที่สร้าง
echo  [7]  🚪  ออก
echo.
set /p choice= กรุณาเลือก (1-7): 

if "%choice%"=="1" goto run_app
if "%choice%"=="2" goto build_windows
if "%choice%"=="3" goto build_linux
if "%choice%"=="4" goto build_all
if "%choice%"=="5" goto clean_all
if "%choice%"=="6" goto show_status
if "%choice%"=="7" goto exit_prog

echo.
echo [!] ตัวเลือกไม่ถูกต้อง กรุณาลองใหม่
timeout /t 2 >nul
goto menu

REM ─────────────────────────────────────────────────────────────────────────────
:run_app
echo.
echo ▶ กำลังรัน %SCRIPT% ...
echo.
python "%PROJECT_DIR%%SCRIPT%"
echo.
pause
goto menu

REM ─────────────────────────────────────────────────────────────────────────────
:build_windows
echo.
echo 🪟 กำลัง Build Windows .exe ด้วย PyInstaller...
echo.
call :check_pyinstaller
if errorlevel 1 goto menu

if exist "%ICON%" (
    python -m PyInstaller --noconsole --onefile --icon="%ICON%" "%SCRIPT%"
) else (
    python -m PyInstaller --noconsole --onefile "%SCRIPT%"
)

if %errorlevel% neq 0 (
    echo.
    echo [ERROR] Build Windows ล้มเหลว!
    pause
    goto menu
)
echo.
echo ✅ Build Windows สำเร็จ!
goto show_results

REM ─────────────────────────────────────────────────────────────────────────────
:build_linux
echo.
echo 🐧 กำลัง Build Linux Executable ผ่าน WSL...
echo.
call :check_wsl
if errorlevel 1 goto menu

REM แปลง path Windows → WSL
for /f "delims=" %%p in ('wsl wslpath -u "%PROJECT_DIR%"') do set WSL_DIR=%%p

wsl bash -c "cd '%WSL_DIR%' && sudo apt-get install -y python3-tk python3-dev -q && python3 -m pip install pyinstaller requests customtkinter -q && python3 -m PyInstaller --onefile %SCRIPT%"

if %errorlevel% neq 0 (
    echo.
    echo [ERROR] Build Linux ล้มเหลว!
    pause
    goto menu
)
echo.
echo ✅ Build Linux สำเร็จ! (ไฟล์อยู่ใน dist\chahuadev_hub)
goto show_results

REM ─────────────────────────────────────────────────────────────────────────────
:build_all
echo.
echo 🌐 Build ทั้ง Windows และ Linux...
echo.
call :check_pyinstaller
if errorlevel 1 goto menu

echo ─── [1/2] Windows .exe ───────────────────────────────
if exist "%ICON%" (
    python -m PyInstaller --noconsole --onefile --icon="%ICON%" "%SCRIPT%"
) else (
    python -m PyInstaller --noconsole --onefile "%SCRIPT%"
)
if %errorlevel% neq 0 (
    echo [ERROR] Build Windows ล้มเหลว!
    pause
    goto menu
)
echo ✅ Windows .exe สำเร็จ

echo.
echo ─── [2/2] Linux Executable (WSL) ────────────────────
call :check_wsl
if errorlevel 1 (
    echo [SKIP] ข้ามขั้นตอน Linux เนื่องจากไม่พบ WSL
) else (
    for /f "delims=" %%p in ('wsl wslpath -u "%PROJECT_DIR%"') do set WSL_DIR=%%p
    wsl bash -c "cd '%WSL_DIR%' && sudo apt-get install -y python3-tk python3-dev -q && python3 -m pip install pyinstaller requests customtkinter -q && python3 -m PyInstaller --onefile %SCRIPT%"
    if !errorlevel! neq 0 (
        echo [ERROR] Build Linux ล้มเหลว!
    ) else (
        echo ✅ Linux Executable สำเร็จ
    )
)
goto show_results

REM ─────────────────────────────────────────────────────────────────────────────
:clean_all
echo.
echo 🧹 กำลังล้างโฟลเดอร์ build และ dist...
if exist "dist"  rmdir /s /q "dist"  && echo   ✅ ลบ dist สำเร็จ
if exist "build" rmdir /s /q "build" && echo   ✅ ลบ build สำเร็จ
if exist "*.spec" del /q "*.spec"    && echo   ✅ ลบ .spec สำเร็จ
echo.
echo ✅ ล้างเสร็จแล้ว
pause
goto menu

REM ─────────────────────────────────────────────────────────────────────────────
:show_status
echo.
echo 📊 สถานะไฟล์ที่สร้าง:
echo.
if exist "dist\chahuadev_hub.exe" (
    for %%f in ("dist\chahuadev_hub.exe") do (
        echo 🪟 Windows .exe  :  dist\chahuadev_hub.exe  ^(%%~zf bytes^)
    )
) else (
    echo 🪟 Windows .exe  :  [ยังไม่ได้ build]
)
if exist "dist\chahuadev_hub" (
    for %%f in ("dist\chahuadev_hub") do (
        echo 🐧 Linux Exec    :  dist\chahuadev_hub       ^(%%~zf bytes^)
    )
) else (
    echo 🐧 Linux Exec    :  [ยังไม่ได้ build]
)
echo.
pause
goto menu

REM ─────────────────────────────────────────────────────────────────────────────
:show_results
echo.
echo ╔════════════════════════════════════════════════════════════════════════════════╗
echo ║                            🎉 Build เสร็จสิ้น!                                  ║
echo ╚════════════════════════════════════════════════════════════════════════════════╝
echo.
if exist "dist\chahuadev_hub.exe" echo 🪟 Windows : dist\chahuadev_hub.exe
if exist "dist\chahuadev_hub"     echo 🐧 Linux   : dist\chahuadev_hub
echo.
set /p open_dist=📂 เปิดโฟลเดอร์ dist? (y/n): 
if /i "%open_dist%"=="y" start "" "%PROJECT_DIR%dist"
echo.
pause
goto menu

REM ─────────────────────────────────────────────────────────────────────────────
:check_pyinstaller
python -m PyInstaller --version >nul 2>&1
if %errorlevel% neq 0 (
    echo [!] ไม่พบ PyInstaller กำลังติดตั้ง...
    python -m pip install pyinstaller requests customtkinter
    if %errorlevel% neq 0 (
        echo [ERROR] ติดตั้ง PyInstaller ล้มเหลว!
        exit /b 1
    )
)
exit /b 0

:check_wsl
wsl --status >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] ไม่พบ WSL บนเครื่องนี้
    echo         ติดตั้ง WSL ด้วยคำสั่ง: wsl --install
    exit /b 1
)
exit /b 0

REM ─────────────────────────────────────────────────────────────────────────────
:exit_prog
echo.
echo 👋 ขอบคุณที่ใช้ Chahuadev Hub Builder!
echo.
timeout /t 2 >nul
endlocal
exit