Files
2026-06-25 18:57:43 +02:00

528 lines
17 KiB
Batchfile

@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.
)
:: ============================================================
:: DETECTION DU DOSSIER JAVASCRIPTS APPLICATION (Program Files)
:: ============================================================
:DETECTER_DOSSIER_APP
set "ACROBAT_APP_JS="
:: Chercher Acrobat dans Program Files
if exist "%ProgramFiles%\Adobe\Acrobat DC\Acrobat\Javascripts" (
set "ACROBAT_APP_JS=%ProgramFiles%\Adobe\Acrobat DC\Acrobat\Javascripts"
set "ACROBAT_EXE=%ProgramFiles%\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
)
if exist "%ProgramFiles(x86)%\Adobe\Acrobat DC\Acrobat\Javascripts" (
set "ACROBAT_APP_JS=%ProgramFiles(x86)%\Adobe\Acrobat DC\Acrobat\Javascripts"
set "ACROBAT_EXE=%ProgramFiles(x86)%\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
)
:: Acrobat 2020
if exist "%ProgramFiles%\Adobe\Acrobat 2020\Acrobat\Javascripts" (
set "ACROBAT_APP_JS=%ProgramFiles%\Adobe\Acrobat 2020\Acrobat\Javascripts"
set "ACROBAT_EXE=%ProgramFiles%\Adobe\Acrobat 2020\Acrobat\Acrobat.exe"
)
if exist "%ProgramFiles(x86)%\Adobe\Acrobat 2020\Acrobat\Javascripts" (
set "ACROBAT_APP_JS=%ProgramFiles(x86)%\Adobe\Acrobat 2020\Acrobat\Javascripts"
set "ACROBAT_EXE=%ProgramFiles(x86)%\Adobe\Acrobat 2020\Acrobat\Acrobat.exe"
)
:: ============================================================
:MENU
cls
echo ============================================================
echo %APP_NAME%
echo ============================================================
echo.
if defined ACROBAT_APP_JS (
echo Acrobat detecte : %ACROBAT_APP_JS%
) else (
echo [ATTENTION] Aucune installation d'Acrobat detectee
echo dans Program Files.
)
echo.
echo 1. Installer / Mettre a jour
echo 2. Verifier l'installation
echo 3. Tester le chargement des scripts
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 VERIFIER
if "%CHOIX%"=="3" goto TESTER_SCRIPTS
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
:: ============================================================
:: INSTALLATION / MISE A JOUR
:: ============================================================
:INSTALL
cls
echo ============================================================
echo INSTALLATION de %APP_NAME%
echo ============================================================
echo.
if not defined ACROBAT_APP_JS (
echo [ERREUR] Aucune installation d'Acrobat Pro detectee.
echo Installez d'abord Adobe Acrobat Pro.
echo.
pause
goto MENU
)
:: Verifier les droits admin
net session >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo Droits administrateur requis pour copier dans Program Files.
echo Relancement en tant qu'administrateur...
echo.
powershell -Command "Start-Process cmd -ArgumentList '/k \"%~f0\" __started__ __noupdate__' -Verb RunAs"
exit /b
)
if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%"
echo [1/3] Git...
call :TROUVER_GIT
if %ERRORLEVEL% neq 0 (
pause
goto MENU
)
echo [OK]
echo.
echo [2/3] 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/3] Copie des scripts dans Acrobat...
echo Dossier cible : %ACROBAT_APP_JS%
copy /y "%REPO_DIR%\acrobat-plugin\src\*.js" "%ACROBAT_APP_JS%\" >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo [ERREUR] Impossible de copier dans %ACROBAT_APP_JS%
echo Verifiez les droits administrateur.
pause
goto MENU
)
echo [OK] Scripts copies
:: Aussi copier dans le dossier utilisateur (compatibilite anciennes versions)
if exist "%APPDATA%\Adobe\Acrobat" (
for /d %%D in ("%APPDATA%\Adobe\Acrobat\*") do (
if not exist "%%D\JavaScripts" mkdir "%%D\JavaScripts"
copy /y "%REPO_DIR%\acrobat-plugin\src\*.js" "%%D\JavaScripts\" >nul 2>&1
)
echo [OK] Copie aussi dans AppData pour compatibilite
)
echo.
echo ============================================================
echo VERIFICATION POST-INSTALLATION
echo ============================================================
echo.
if exist "%ACROBAT_APP_JS%\Imposition-00-Core.js" (
echo [OK] Scripts presents dans %ACROBAT_APP_JS%
) else (
echo [ERREUR] Scripts absents de %ACROBAT_APP_JS%
)
echo.
echo ============================================================
echo TERMINE - INSTALLATION OK
echo ============================================================
echo.
echo Fermez et relancez Acrobat Pro.
echo Menu attendu : Edition - Imposition Pro
echo.
echo Conseil : dans Preferences - JavaScript, decochez
echo "Afficher la console en cas d'erreurs et de messages"
echo pour eviter un bug connu d'Acrobat 2025/2026.
echo.
set /p "LAUNCH_NOW=Lancer Acrobat maintenant ? [O/N] : "
if /i "!LAUNCH_NOW!"=="O" (
if defined ACROBAT_EXE (
start "" "%ACROBAT_EXE%"
) else (
echo Lancez Acrobat manuellement.
)
)
pause
goto MENU
:: ============================================================
:: VERIFICATION DE L'INSTALLATION
:: ============================================================
:VERIFIER
cls
set "LOG_FILE=%INSTALL_DIR%\diagnostic.log"
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"
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/4] Depot local...
if exist "%REPO_DIR%\.git" (
echo [OK] %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/4] Fichiers source dans le depot...
set "NB_SRC_MANQ=0"
for %%F in (%FICHIERS_ATTENDUS%) do (
if not exist "%REPO_DIR%\acrobat-plugin\src\%%F" (
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. Scripts dans le dossier app (Program Files) ---
echo.
echo [3/4] Scripts dans Program Files...
if defined ACROBAT_APP_JS (
set "NB_APP_MANQ=0"
for %%F in (%FICHIERS_ATTENDUS%) do (
if not exist "%ACROBAT_APP_JS%\%%F" (
echo [MANQUANT] %%F
echo [MANQUANT] App %%F>> "%LOG_FILE%"
set /a NB_APP_MANQ+=1
)
)
if !NB_APP_MANQ!==0 (
echo [OK] 10/10 scripts dans %ACROBAT_APP_JS%
echo [OK] 10/10 scripts dans app>> "%LOG_FILE%"
set /a NB_OK+=1
) else (
echo [ERREUR] !NB_APP_MANQ! fichier manquant dans %ACROBAT_APP_JS%
echo [ERREUR] Scripts manquants dans app>> "%LOG_FILE%"
set /a NB_ERREURS+=1
)
) else (
echo [ERREUR] Dossier Acrobat non detecte dans Program Files
echo [ERREUR] Pas de dossier app Acrobat>> "%LOG_FILE%"
set /a NB_ERREURS+=1
)
:: --- 4. Scripts dans le dossier utilisateur (AppData) ---
echo.
echo [4/4] Scripts dans AppData...
if exist "%APPDATA%\Adobe\Acrobat" (
set "USER_FOUND=0"
for /d %%D in ("%APPDATA%\Adobe\Acrobat\*") do (
if exist "%%D\JavaScripts\Imposition-00-Core.js" (
echo [OK] %%D\JavaScripts
echo [OK] User scripts : %%D\JavaScripts>> "%LOG_FILE%"
set "USER_FOUND=1"
)
)
if "!USER_FOUND!"=="0" (
echo [INFO] Pas de scripts dans AppData - normal si version recente
echo [INFO] Pas de scripts dans AppData>> "%LOG_FILE%"
)
) else (
echo [INFO] Pas de dossier AppData Adobe
echo [INFO] Pas de dossier AppData Adobe>> "%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 en administrateur
echo - Verifiez qu'Acrobat Pro est installe
echo Des problemes detectes>> "%LOG_FILE%"
) else (
echo.
echo Tout est en ordre.
echo Installation validee>> "%LOG_FILE%"
)
echo.
echo Rapport : %LOG_FILE%
echo.
set /p "OPEN_LOG=Ouvrir le log ? [O/N] : "
if /i "!OPEN_LOG!"=="O" start notepad "%LOG_FILE%"
echo.
pause
goto MENU
:: ============================================================
:: TESTER LE CHARGEMENT DES SCRIPTS
:: ============================================================
:TESTER_SCRIPTS
cls
echo ============================================================
echo TEST DE CHARGEMENT DES SCRIPTS
echo ============================================================
echo.
if not defined ACROBAT_APP_JS (
echo [ERREUR] Aucun dossier Acrobat detecte.
pause
goto MENU
)
:: Verifier les droits admin
net session >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo Droits administrateur requis.
echo Relancement en tant qu'administrateur...
powershell -Command "Start-Process cmd -ArgumentList '/k \"%~f0\" __started__ __noupdate__' -Verb RunAs"
exit /b
)
echo Ce test va :
echo - Placer un script minimal dans %ACROBAT_APP_JS%
echo - Lancer Acrobat
echo - Si une boite "Test OK" apparait, les scripts marchent.
echo.
echo Fermez Acrobat avant de continuer.
echo.
pause
:: Creer le fichier test - contenu simple sans caracteres speciaux
echo app.alert("Test OK - scripts charges depuis Program Files");> "%ACROBAT_APP_JS%\__test_imposing.js"
echo Script de test cree dans %ACROBAT_APP_JS%
echo.
echo Lancement d'Acrobat...
if defined ACROBAT_EXE (
start "" "%ACROBAT_EXE%"
) else (
echo Lancez Acrobat manuellement.
)
echo.
echo Regardez si la boite "Test OK" apparait dans Acrobat.
echo.
set /p "TEST_OK=Le message est apparu ? [O/N] : "
:: Nettoyage
del "%ACROBAT_APP_JS%\__test_imposing.js" 2>nul
if /i "!TEST_OK!"=="O" (
echo.
echo [OK] Les scripts se chargent depuis Program Files.
echo Relancez l'installation pour deployer les vrais scripts.
) else (
echo.
echo [ERREUR] Les scripts ne se chargent pas.
echo.
echo Verifiez dans Acrobat :
echo 1. Preferences - JavaScript - "Activer Acrobat JavaScript"
echo 2. Preferences - JavaScript - Decocher
echo "Afficher la console en cas d'erreurs et de messages"
echo 3. Preferences - Securite avancee -
echo Decocher "Activer le mode protege au demarrage"
echo 4. Redemarrez Acrobat apres ces changements
)
echo.
pause
goto MENU
:: ============================================================
:: LANCER ACROBAT
:: ============================================================
:LAUNCH
cls
echo ============================================================
echo LANCEMENT D'ACROBAT
echo ============================================================
echo.
if defined ACROBAT_EXE (
start "" "%ACROBAT_EXE%"
) else (
echo Executable Acrobat non detecte. Lancez-le manuellement.
)
timeout /t 2 >nul
goto MENU
:: ============================================================
:: DESINSTALLATION
:: ============================================================
:UNINSTALL
cls
echo ============================================================
echo DESINSTALLATION de %APP_NAME%
echo ============================================================
echo.
echo Seront supprimes :
echo - Les scripts Imposition dans Program Files et AppData
echo - %INSTALL_DIR%
echo.
set /p "CONFIRM=Confirmer ? [O/N] : "
if /i "%CONFIRM%" neq "O" goto MENU
:: Verifier les droits admin
net session >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo Droits administrateur requis.
powershell -Command "Start-Process cmd -ArgumentList '/k \"%~f0\" __started__ __noupdate__' -Verb RunAs"
exit /b
)
echo.
:: Supprimer du dossier app (Program Files)
if defined ACROBAT_APP_JS (
del /q "%ACROBAT_APP_JS%\Imposition-*.js" 2>nul
echo [OK] Scripts supprimes de %ACROBAT_APP_JS%
)
:: Supprimer du dossier utilisateur (AppData)
if exist "%APPDATA%\Adobe\Acrobat" (
for /d %%D in ("%APPDATA%\Adobe\Acrobat\*") do (
del /q "%%D\JavaScripts\Imposition-*.js" 2>nul
)
echo [OK] Scripts supprimes de AppData
)
rmdir /s /q "%INSTALL_DIR%" 2>nul
echo [OK] %INSTALL_DIR% supprime
echo.
echo ============================================================
echo DESINSTALLATION TERMINEE
echo ============================================================
echo.
pause
goto MENU
:: ============================================================
:FIN
echo.
echo Au revoir !
echo.
pause
exit /b 0