@echo off
setlocal enabledelayedexpansion
chcp 1252 >nul

:: ========================================================================
:: USB FORMAT FAT32 MULTILINGUE (FR/EN/DE/IT/ES) - SECURISE
:: Version 1.0
:: PROTEA TECH INFORMATIQUE 1647 CORBIERES
:: ========================================================================

:: Vrification si admin
net session >nul 2>&1
if %errorLevel% NEQ 0 (
    echo Veuillez relancer ce script en tant qu'administrateur !
    pause
    exit
)

:MAINMENU
cls
color 1F
echo ================================================================================================
echo     USB 32GB Max. FORMAT FAT32 MULTILINGUE - V.1.0
echo.
echo          + + ++
echo          +--++--++--+--++----+
echo          ++++      +
echo          +---+ +---+       +--+
echo                          +
echo          +-+     +-+        +-+   +------+
echo.
echo       PROTEA TECH INFORMATIQUE 1647 CORBIERES
echo ================================================================================================
echo.
echo   1. Lancer le programme / Start program / Programm starten / Avvia programma / Iniciar programa
echo   2. Quitter / Exit
echo.
set /p mainchoice="Option 1-2 : "

if "%mainchoice%"=="1" goto LANG
if "%mainchoice%"=="2" exit
echo   Choix invalide !
pause >nul
goto MAINMENU

:LANG
cls
color 1F
echo ========================================================================
echo              USB FORMAT FAT32 MULTILINGUE - V1.0
echo   Choisissez la langue / Choose language / Sprache whlen / Scegli lingua / Seleccione idioma
echo ========================================================================
echo.
echo   1. Franais
echo   2. English
echo   3. Deutsch
echo   4. Italiano
echo   5. Espaol
echo.
set /p lang="Option 1-5 : "

if "%lang%"=="1" set "LANGUE=FR"
if "%lang%"=="2" set "LANGUE=EN"
if "%lang%"=="3" set "LANGUE=DE"
if "%lang%"=="4" set "LANGUE=IT"
if "%lang%"=="5" set "LANGUE=ES"
if not defined LANGUE (
    echo   Choix invalide !
    pause >nul
    goto LANG
)

:: ------------------ Texte selon la langue ------------------
if "!LANGUE!"=="FR" (
    set "TITLE=FORMATAGE USB - FAT32 (Windows 11) - V1.0"
    set "RESET=1. Rinitialiser la cl USB (DiskPart)"
    set "PROMPT=Entrez le NUMERO du disque  formater :"
    set "CONFIRM=ATTENTION^! Toutes les donnes de ce disque seront perdues^! Sauvegardez vos fichiers^! Confirmez-vous ? (O/N) :"
    set "DONE=FORMATAGE TERMINE^! Votre cl est maintenant en FAT32."
    set "BYE=Au revoir^!"
    set "AGAIN=Voulez-vous formater une autre cl ? (O/N) :"
    set "BOOTMSG=Cl bootable dtecte^! Formatage impossible."
) else if "!LANGUE!"=="EN" (
    set "TITLE=USB FORMAT - FAT32 (Windows 11) - V1.0"
    set "RESET=1. Reset USB drive (DiskPart)"
    set "PROMPT=Enter the NUMBER of the disk to format:"
    set "CONFIRM=WARNING^! All data on this disk will be lost^! Backup your files^! Confirm? (Y/N):"
    set "DONE=FORMAT COMPLETE^! Your USB is now FAT32."
    set "BYE=Goodbye^!"
    set "AGAIN=Do you want to format another USB? (Y/N):"
    set "BOOTMSG=Bootable USB detected^! Format not allowed."
) else if "!LANGUE!"=="DE" (
    set "TITLE=USB FORMAT - FAT32 (Windows 11) - V1.0"
    set "RESET=1. USB-Stick zurcksetzen (DiskPart)"
    set "PROMPT=Geben Sie die NUMMER des zu formatierenden Datentrgers ein:"
    set "CONFIRM=WARNUNG^! Alle Daten auf diesem Datentrger gehen verloren^! Sichern Sie Ihre Dateien^! Besttigen? (J/N):"
    set "DONE=FORMATIERUNG ABGESCHLOSSEN^! Ihr USB ist jetzt FAT32."
    set "BYE=Auf Wiedersehen^!"
    set "AGAIN=Mchten Sie einen weiteren USB formatieren? (J/N):"
    set "BOOTMSG=Bootfhiger USB erkannt^! Formatierung nicht erlaubt."
) else if "!LANGUE!"=="IT" (
    set "TITLE=USB FORMAT - FAT32 (Windows 11) - V1.0"
    set "RESET=1. Resetta USB (DiskPart)"
    set "PROMPT=Inserisci il NUMERO del disco da formattare:"
    set "CONFIRM=ATTENZIONE^! Tutti i dati su questo disco saranno persi^! Effettua il backup^! Confermare? (S/N):"
    set "DONE=FORMATTAZIONE COMPLETATA^! La tua USB  ora FAT32."
    set "BYE=Arrivederci^!"
    set "AGAIN=Vuoi formattare un'altra USB? (S/N):"
    set "BOOTMSG=USB avviabile rilevata^! Formattazione non consentita."
) else if "!LANGUE!"=="ES" (
    set "TITLE=FORMATEO USB - FAT32 (Windows 11) - V1.0"
    set "RESET=1. Reiniciar unidad USB (DiskPart)"
    set "PROMPT=Ingrese el NUMERO del disco a formatear:"
    set "CONFIRM=ATENCIN^! Todos los datos en este disco se perdern^! Haga copia de seguridad^! Confirmar? (S/N):"
    set "DONE=FORMATEO COMPLETADO^! Su USB ahora es FAT32."
    set "BYE=Adis^!"
    set "AGAIN=Desea formatear otra USB? (S/N):"
    set "BOOTMSG=USB booteable detectada^! Formateo no permitido."
)

goto WARNING

:WARNING
cls
color 4F
echo ========================================================================
echo                    !TITLE!
echo.
echo           PROTEA TECH INFORMATIQUE 1647 CORBIERES
echo ========================================================================
echo.
:: Messages d'avertissement dtaills multi-lignes
if "!LANGUE!"=="FR" (
    echo    ATTENTION !
    echo    Cet outil ne prend en charge que les cls USB jusqu' 32GB.
    echo    Pour les cls suprieures, utilisez Guiformat ou Rufus.
    echo    Vous tes seul responsable de vos donnes.
)
if "!LANGUE!"=="EN" (
    echo    WARNING !
    echo    This tool only supports USB drives up to 32GB.
    echo    For larger drives, please use Guiformat or Rufus from official sites.
    echo    You are solely responsible for your data.
)
if "!LANGUE!"=="DE" (
    echo    ACHTUNG !
    echo    Dieses Tool untersttzt nur USB-Sticks bis 32GB.
    echo    Fr grere USBs verwenden Sie bitte Guiformat oder Rufus.
    echo    Sie sind allein verantwortlich fr Ihre Daten.
)
if "!LANGUE!"=="IT" (
    echo    ATTENZIONE !
    echo    Questo strumento supporta solo chiavette USB fino a 32GB.
    echo    Per chiavette pi grandi, utilizzare Guiformat o Rufus dai siti ufficiali.
    echo    Sei l'unico responsabile dei tuoi dati.
)
if "!LANGUE!"=="ES" (
    echo    ATENCIN!
    echo    Esta herramienta solo soporta USB hasta 32GB.
    echo    Para unidades mayores, use Guiformat o Rufus desde los sitios oficiales.
    echo    Usted es el nico responsable de sus datos.
)
echo.
pause
goto MENU

:MENU
cls
color 1F
echo ========================================================================
echo                !TITLE!
echo.
echo           PROTEA TECH INFORMATIQUE 1647 CORBIERES
echo ========================================================================
echo.
echo   !RESET!
echo.
:: Lister les disques amovibles avec numro et lettre
echo   Liste des disques amovibles disponibles :
for /f "skip=1 tokens=1,2,3 delims=," %%A in ('wmic diskdrive where "MediaType='Removable Media'" get Index^,DeviceID^,Model /format:csv') do (
    if not "%%B"=="" echo   Numro=%%A   Lettre du lecteur=%%B   Modle=%%C
)
echo.
set /p disknum="   !PROMPT! "

:: Vrification si le disque existe
wmic diskdrive where "Index=!disknum!" get Index >nul 2>&1
if %errorlevel% NEQ 0 (
    echo Numro de disque invalide !
    pause
    goto MENU
)

:: Avertissement avant formatage
color 4F
echo.
echo !CONFIRM!
set /p confirm="   "

if /I "!confirm!" NEQ "O" if /I "!confirm!" NEQ "Y" if /I "!confirm!" NEQ "J" if /I "!confirm!" NEQ "S" goto MENU

:: --- Cration fichier DiskPart ---
set tmpfile=%temp%\diskcmd.txt
echo select disk !disknum! > "%tmpfile%"
echo attributes disk clear readonly >> "%tmpfile%"
echo clean >> "%tmpfile%"
echo create partition primary >> "%tmpfile%"
echo format fs=fat32 quick label=USB >> "%tmpfile%"
echo assign letter=U >> "%tmpfile%"  :: Force la lettre U pour viter changement automatique
diskpart /s "%tmpfile%"
del "%tmpfile%"

:: Message de succs avec fond rouge
color 4F
echo.
echo !DONE!
echo.
set /p again="   !AGAIN! "
if /I "!again!"=="O" if "!LANGUE!"=="FR" goto MENU
if /I "!again!"=="Y" if "!LANGUE!"=="EN" goto MENU
if /I "!again!"=="J" if "!LANGUE!"=="DE" goto MENU
if /I "!again!"=="S" if "!LANGUE!"=="IT" goto MENU
if /I "!again!"=="S" if "!LANGUE!"=="ES" goto MENU
goto MAINMENU
