@echo off chcp 65001 >nul 2>&1 setlocal EnableDelayedExpansion title Copydev Imposition Tool - Installation :: Si le script plante ou sort anormalement, la fenetre reste ouverte if "%~1" neq "__started__" ( cmd /k "%~f0" __started__ %* exit /b ) set "APP_NAME=Copydev Imposition Tool" set "INSTALL_DIR=%LOCALAPPDATA%\CopydevImposingAcrobat" set "REPO_DIR=%INSTALL_DIR%\repo" set "GITEA_REPO=https://git.copydev.fr/jules/copydev-imposing-tool.git" set "GIT_URL=https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.2/MinGit-2.47.1.2-64-bit.zip" set "BAT_RAW_URL=https://git.copydev.fr/jules/copydev-imposing-tool/raw/branch/master/acrobat-plugin/install.bat" :: ============================================================ :: AUTO-MISE A JOUR DU SCRIPT :: ============================================================ if "%~2" neq "__noupdate__" ( echo Verification de mise a jour du script... set "BAT_TMP=%TEMP%\install_imposing_new.bat" powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; try { Invoke-WebRequest -Uri '%BAT_RAW_URL%' -OutFile '%TEMP%\install_imposing_new.bat' -UseBasicParsing -TimeoutSec 5 } catch { exit 1 }" >nul 2>&1 if !ERRORLEVEL!==0 ( fc /b "%~f0" "!BAT_TMP!" >nul 2>&1 if !ERRORLEVEL! neq 0 ( echo Nouvelle version detectee, mise a jour... copy /y "!BAT_TMP!" "%~f0" >nul 2>&1 if !ERRORLEVEL!==0 ( del "!BAT_TMP!" 2>nul echo Script mis a jour. Relancement... timeout /t 2 >nul cmd /k "%~f0" __started__ __noupdate__ exit /b ) ) else ( echo Script a jour. ) del "!BAT_TMP!" 2>nul ) else ( echo Impossible de verifier la mise a jour. On continue... ) echo. ) :: ============================================================ :MENU cls echo ============================================================ echo %APP_NAME% echo ============================================================ echo. echo 1. Installer echo 2. Mettre a jour echo 3. Verifier l'installation echo 4. Lancer Acrobat echo 5. Desinstaller echo 6. Quitter echo. set "CHOIX=" set /p "CHOIX=Votre choix [1-6] : " if "%CHOIX%"=="1" goto INSTALL if "%CHOIX%"=="2" goto UPDATE if "%CHOIX%"=="3" goto VERIFIER if "%CHOIX%"=="4" goto LAUNCH if "%CHOIX%"=="5" goto UNINSTALL if "%CHOIX%"=="6" goto FIN echo Choix invalide. timeout /t 2 >nul goto MENU :: ============================================================ :: GIT (portable si absent du systeme) :: ============================================================ :TROUVER_GIT set "GIT_CMD=" where git >nul 2>&1 if %ERRORLEVEL%==0 ( set "GIT_CMD=git" exit /b 0 ) if exist "%INSTALL_DIR%\git\cmd\git.exe" ( set "GIT_CMD=%INSTALL_DIR%\git\cmd\git.exe" exit /b 0 ) echo Telechargement de Git portable... if not exist "%INSTALL_DIR%\temp" mkdir "%INSTALL_DIR%\temp" if not exist "%INSTALL_DIR%\git" mkdir "%INSTALL_DIR%\git" powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GIT_URL%' -OutFile '%INSTALL_DIR%\temp\git.zip' -UseBasicParsing" if not exist "%INSTALL_DIR%\temp\git.zip" ( echo [ERREUR] Echec telechargement Git exit /b 1 ) powershell -Command "Expand-Archive -Force '%INSTALL_DIR%\temp\git.zip' '%INSTALL_DIR%\git'" del "%INSTALL_DIR%\temp\git.zip" 2>nul if not exist "%INSTALL_DIR%\git\cmd\git.exe" ( echo [ERREUR] git.exe introuvable apres extraction exit /b 1 ) set "GIT_CMD=%INSTALL_DIR%\git\cmd\git.exe" exit /b 0 :: ============================================================ :: Detection des dossiers JavaScripts d'Acrobat :: ============================================================ :TROUVER_DOSSIERS_ACROBAT set "NB_DOSSIERS=0" if not exist "%APPDATA%\Adobe\Acrobat" ( exit /b 1 ) for /d %%D in ("%APPDATA%\Adobe\Acrobat\*") do ( if not exist "%%D\JavaScripts" mkdir "%%D\JavaScripts" set /a NB_DOSSIERS+=1 set "DOSSIER_JS_!NB_DOSSIERS!=%%D\JavaScripts" ) if "%NB_DOSSIERS%"=="0" exit /b 1 exit /b 0 :: ============================================================ :: INSTALLATION / MISE A JOUR :: ============================================================ :INSTALL cls echo ============================================================ echo INSTALLATION de %APP_NAME% echo ============================================================ goto DEPLOIEMENT :UPDATE cls echo ============================================================ echo MISE A JOUR de %APP_NAME% echo ============================================================ goto DEPLOIEMENT :DEPLOIEMENT echo. if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%" echo [1/4] Git... call :TROUVER_GIT if %ERRORLEVEL% neq 0 ( pause goto MENU ) echo [OK] echo. echo [2/4] Telechargement du code... if exist "%REPO_DIR%\.git" ( pushd "%REPO_DIR%" "%GIT_CMD%" fetch origin "%GIT_CMD%" pull origin master popd ) else ( if exist "%REPO_DIR%" rmdir /s /q "%REPO_DIR%" "%GIT_CMD%" clone "%GITEA_REPO%" "%REPO_DIR%" ) if not exist "%REPO_DIR%\acrobat-plugin\src\Imposition-00-Core.js" ( echo [ERREUR] Code source introuvable apres clonage/mise a jour pause goto MENU ) echo [OK] echo. echo [3/4] Detection d'Acrobat et copie des scripts... call :TROUVER_DOSSIERS_ACROBAT if %ERRORLEVEL% neq 0 ( echo [ERREUR] Aucune installation d'Acrobat trouvee echo sous %APPDATA%\Adobe\Acrobat echo Verifiez qu'Acrobat Pro est installe. pause goto MENU ) for /l %%i in (1,1,%NB_DOSSIERS%) do ( echo -- !DOSSIER_JS_%%i! copy /y "%REPO_DIR%\acrobat-plugin\src\*.js" "!DOSSIER_JS_%%i!\" >nul ) echo [OK] Scripts copies dans %NB_DOSSIERS% dossier(s) Acrobat echo. echo [4/4] Plugin natif (verification de licence)... if exist "%REPO_DIR%\acrobat-plugin\native\dist\ImposingLicence.api" ( for /d %%D in ("%APPDATA%\Adobe\Acrobat\*") do ( if not exist "%%D\Plug_ins3" mkdir "%%D\Plug_ins3" copy /y "%REPO_DIR%\acrobat-plugin\native\dist\ImposingLicence.api" "%%D\Plug_ins3\" >nul echo -- %%D\Plug_ins3\ImposingLicence.api ) echo [OK] Plugin natif copie ) else ( echo [INFO] Pas de plugin natif precompile. echo La suite fonctionne en JS seul. ) echo. echo ============================================================ echo VERIFICATION POST-INSTALLATION echo ============================================================ echo. set "POST_ERREURS=0" call :TROUVER_DOSSIERS_ACROBAT if %ERRORLEVEL% neq 0 ( echo [ERREUR] Aucun dossier Acrobat detecte set /a POST_ERREURS+=1 ) else ( for /l %%i in (1,1,%NB_DOSSIERS%) do ( if exist "!DOSSIER_JS_%%i!\Imposition-00-Core.js" ( echo [OK] Scripts presents dans !DOSSIER_JS_%%i! ) else ( echo [ERREUR] Scripts absents de !DOSSIER_JS_%%i! set /a POST_ERREURS+=1 ) ) ) echo. if !POST_ERREURS! gtr 0 ( echo ============================================================ echo TERMINE AVEC ERREURS echo ============================================================ echo. echo L'installation a rencontre des problemes. echo Utilisez "Verifier l'installation" pour diagnostiquer. ) else ( echo ============================================================ echo TERMINE - INSTALLATION OK echo ============================================================ echo. echo Redemarrez Acrobat Pro pour charger les scripts. echo Menu attendu : Edition - Imposition Pro ) :: Ouvrir le dossier JavaScripts pour verification visuelle echo. echo Ouverture du dossier JavaScripts d'Acrobat... for /l %%i in (1,1,1) do ( start "" explorer "!DOSSIER_JS_1!" ) echo Verifiez que les fichiers Imposition-*.js sont bien la. echo. set /p "LAUNCH_NOW=Lancer Acrobat maintenant ? [O/N] : " if /i "!LAUNCH_NOW!"=="O" call :LANCER_ACROBAT pause goto MENU :: ============================================================ :: VERIFICATION DE L'INSTALLATION :: ============================================================ :VERIFIER cls set "LOG_FILE=%INSTALL_DIR%\diagnostic.log" echo ============================================================> "%LOG_FILE%" echo DIAGNOSTIC - %APP_NAME%>> "%LOG_FILE%" echo Date : %DATE% %TIME%>> "%LOG_FILE%" echo ============================================================>> "%LOG_FILE%" echo.>> "%LOG_FILE%" echo ============================================================ echo VERIFICATION DE L'INSTALLATION echo ============================================================ echo. set "NB_OK=0" set "NB_ERREURS=0" :: --- 1. Depot local --- echo [1/5] Depot local... if exist "%REPO_DIR%\.git" ( echo [OK] Depot present : %REPO_DIR% echo [OK] Depot local : %REPO_DIR%>> "%LOG_FILE%" set /a NB_OK+=1 ) else ( echo [ERREUR] Depot absent. Lancez d'abord l'installation. echo [ERREUR] Depot local absent>> "%LOG_FILE%" set /a NB_ERREURS+=1 ) :: --- 2. Fichiers source --- echo. echo [2/5] Fichiers source... set "FICHIERS_ATTENDUS=Imposition-00-Core.js Imposition-00b-Licence.js Imposition-01-UI.js Imposition-02-Livret.js Imposition-03-NUp.js Imposition-04-Decoupe.js Imposition-05-Marges.js Imposition-06-Reperes.js Imposition-07-Auto.js Imposition-08-MiseAJour.js" set "NB_SRC_OK=0" set "NB_SRC_MANQ=0" for %%F in (%FICHIERS_ATTENDUS%) do ( if exist "%REPO_DIR%\acrobat-plugin\src\%%F" ( set /a NB_SRC_OK+=1 ) else ( echo [MANQUANT] %%F echo [MANQUANT] Source %%F>> "%LOG_FILE%" set /a NB_SRC_MANQ+=1 ) ) if !NB_SRC_MANQ!==0 ( echo [OK] 10/10 fichiers source presents echo [OK] 10/10 fichiers source presents>> "%LOG_FILE%" set /a NB_OK+=1 ) else ( echo [ERREUR] !NB_SRC_MANQ! fichier manquant echo [ERREUR] !NB_SRC_MANQ! fichier source manquant>> "%LOG_FILE%" set /a NB_ERREURS+=1 ) :: --- 3. Dossiers Acrobat detectes --- echo. echo [3/5] Dossiers Acrobat... call :TROUVER_DOSSIERS_ACROBAT if %ERRORLEVEL% neq 0 ( echo [ERREUR] Aucune installation d'Acrobat trouvee echo [ERREUR] Aucun dossier Acrobat detecte>> "%LOG_FILE%" set /a NB_ERREURS+=1 ) else ( echo [OK] %NB_DOSSIERS% dossier Acrobat detecte echo [OK] %NB_DOSSIERS% dossier Acrobat>> "%LOG_FILE%" set /a NB_OK+=1 for /l %%i in (1,1,%NB_DOSSIERS%) do ( echo !DOSSIER_JS_%%i! echo Dossier : !DOSSIER_JS_%%i!>> "%LOG_FILE%" ) ) :: --- 4. Scripts copies dans Acrobat --- echo. echo [4/5] Scripts dans les dossiers Acrobat... set "DEPLOY_OK=1" for /l %%i in (1,1,%NB_DOSSIERS%) do ( set "DIR_JS=!DOSSIER_JS_%%i!" set "NB_JS_OK=0" set "NB_JS_MANQ=0" for %%F in (%FICHIERS_ATTENDUS%) do ( if exist "!DIR_JS!\%%F" ( set /a NB_JS_OK+=1 ) else ( echo [MANQUANT] %%F dans !DIR_JS! echo [MANQUANT] %%F dans !DIR_JS!>> "%LOG_FILE%" set /a NB_JS_MANQ+=1 set "DEPLOY_OK=0" ) ) if !NB_JS_MANQ!==0 ( echo [OK] !DIR_JS! - 10/10 scripts presents echo [OK] !DIR_JS! - 10/10 scripts>> "%LOG_FILE%" ) ) if "!DEPLOY_OK!"=="1" ( set /a NB_OK+=1 ) else ( echo [ERREUR] Un ou plusieurs scripts manquent dans Acrobat echo [ERREUR] Scripts manquants dans dossier Acrobat>> "%LOG_FILE%" set /a NB_ERREURS+=1 ) :: --- 5. Plugin natif (optionnel) --- echo. echo [5/5] Plugin natif... set "PLUGIN_TROUVE=0" for /l %%i in (1,1,%NB_DOSSIERS%) do ( set "DIR_JS=!DOSSIER_JS_%%i!" set "DIR_PLUG=!DIR_JS:\JavaScripts=\Plug_ins3!" if exist "!DIR_PLUG!\ImposingLicence.api" ( echo [OK] Plugin natif present dans !DIR_PLUG! echo [OK] Plugin natif : !DIR_PLUG!\ImposingLicence.api>> "%LOG_FILE%" set "PLUGIN_TROUVE=1" ) ) if "!PLUGIN_TROUVE!"=="0" ( echo [INFO] Plugin natif non installe - optionnel echo [INFO] Plugin natif non installe>> "%LOG_FILE%" ) :: --- Bilan --- echo. echo ============================================================ echo BILAN : !NB_OK! OK / !NB_ERREURS! erreur echo ============================================================ echo BILAN : !NB_OK! OK / !NB_ERREURS! erreur>> "%LOG_FILE%" echo.>> "%LOG_FILE%" if !NB_ERREURS! gtr 0 ( echo. echo Des problemes ont ete detectes : echo - Relancez l'installation echo - Verifiez qu'Acrobat Pro est installe echo - Verifiez votre connexion reseau echo. echo Des problemes detectes>> "%LOG_FILE%" ) else ( echo. echo Tout est en ordre. Redemarrez Acrobat Pro pour echo voir le menu Edition - Imposition Pro. echo. echo Installation validee>> "%LOG_FILE%" ) echo Rapport enregistre dans : echo %LOG_FILE% echo. set /p "OPEN_LOG=Ouvrir le fichier de log ? [O/N] : " if /i "!OPEN_LOG!"=="O" start notepad "%LOG_FILE%" echo. pause goto MENU :: ============================================================ :: LANCER ACROBAT :: ============================================================ :LAUNCH cls echo ============================================================ echo LANCEMENT D'ACROBAT echo ============================================================ echo. call :LANCER_ACROBAT timeout /t 2 >nul goto MENU :LANCER_ACROBAT where acrobat >nul 2>&1 if %ERRORLEVEL%==0 ( start "" acrobat exit /b 0 ) if exist "%ProgramFiles(x86)%\Adobe\Acrobat DC\Acrobat\Acrobat.exe" ( start "" "%ProgramFiles(x86)%\Adobe\Acrobat DC\Acrobat\Acrobat.exe" exit /b 0 ) if exist "%ProgramFiles%\Adobe\Acrobat DC\Acrobat\Acrobat.exe" ( start "" "%ProgramFiles%\Adobe\Acrobat DC\Acrobat\Acrobat.exe" exit /b 0 ) echo Executable Acrobat introuvable. Lancez-le manuellement. exit /b 1 :: ============================================================ :: DESINSTALLATION :: ============================================================ :UNINSTALL cls echo ============================================================ echo DESINSTALLATION de %APP_NAME% echo ============================================================ echo. echo Seront supprimes : echo - Les scripts Imposition dans chaque dossier Acrobat JavaScripts echo - Le plugin natif ImposingLicence.api si installe echo - %INSTALL_DIR% (code source local, licence registre conservee) echo. set /p "CONFIRM=Confirmer ? [O/N] : " if /i "%CONFIRM%" neq "O" goto MENU echo. if exist "%APPDATA%\Adobe\Acrobat" ( for /d %%D in ("%APPDATA%\Adobe\Acrobat\*") do ( del /q "%%D\JavaScripts\Imposition-*.js" 2>nul del /q "%%D\Plug_ins3\ImposingLicence.api" 2>nul ) ) echo [OK] Scripts et plugin supprimes rmdir /s /q "%INSTALL_DIR%" 2>nul echo [OK] %INSTALL_DIR% supprime echo. echo Pour retirer aussi la cle de licence : echo supprimez HKCU\Software\Copydev\ImposingAcrobat echo. echo ============================================================ echo DESINSTALLATION TERMINEE echo ============================================================ echo. pause goto MENU :: ============================================================ :FIN echo. echo Au revoir ! echo. pause exit /b 0