From 279e74de66bcf8bbfb05968e6fba2d05f61b96dc Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 8 Jun 2005 13:41:02 +0000 Subject: [PATCH] Sync the 13x and 14x trees. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10015 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/Win32/packaging/dtl/.cvsignore | 3 + .../Win32/packaging/installer/download.nsh | 2 +- .../packaging/installer/lyx_installer.nsi | 27 +- .../installer/lyx_languages/english.nsh | 5 +- .../installer/lyx_languages/french.nsh | 15 +- .../installer/lyx_languages/german.nsh | 5 +- .../packaging/installer/lyx_path_prefix.C | 249 +++++++++++++++--- 7 files changed, 251 insertions(+), 55 deletions(-) create mode 100644 development/Win32/packaging/dtl/.cvsignore diff --git a/development/Win32/packaging/dtl/.cvsignore b/development/Win32/packaging/dtl/.cvsignore new file mode 100644 index 0000000000..7ccd885652 --- /dev/null +++ b/development/Win32/packaging/dtl/.cvsignore @@ -0,0 +1,3 @@ +*.dvi +*.dtl +*.log diff --git a/development/Win32/packaging/installer/download.nsh b/development/Win32/packaging/installer/download.nsh index 3cd3a57623..d9641f4a8b 100644 --- a/development/Win32/packaging/installer/download.nsh +++ b/development/Win32/packaging/installer/download.nsh @@ -263,7 +263,7 @@ Abort ; Return to the page go_on: - ${ReadDownloadValues} ${DoNotRequire} ${Download} $0 ${FolderPath} + ${ReadDownloadValues} ${DoNotRequire} ${Download} $0 ${FolderPath} ${if} ${DoNotRequire} == 1 ; diff --git a/development/Win32/packaging/installer/lyx_installer.nsi b/development/Win32/packaging/installer/lyx_installer.nsi index fe60014fd8..db9d9474df 100644 --- a/development/Win32/packaging/installer/lyx_installer.nsi +++ b/development/Win32/packaging/installer/lyx_installer.nsi @@ -209,11 +209,16 @@ Section "-Installation actions" SecInstallation File /r "${PRODUCT_SOURCEDIR}\bin" ${if} "$PathPrefix" != "" - lyx_path_prefix::set "$INSTDIR\Resources\lyx\configure" "$PathPrefix" + lyx_path_prefix::set_path_prefix "$INSTDIR\Resources\lyx\configure" "$PathPrefix" Pop $0 ${if} $0 != 0 MessageBox MB_OK "$(ModifyingConfigureFailed)" ${endif} + lyx_path_prefix::run_configure "$INSTDIR\Resources\lyx\configure" "$PathPrefix" + Pop $0 + ${if} $0 != 0 + MessageBox MB_OK "$(RunConfigureFailed)" + ${endif} ${endif} WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "${PRODUCT_EXE}" @@ -296,6 +301,8 @@ FunctionEnd ;-------------------------------- Function DownloadMinSYS + StrCpy $MinSYSPath "" + StrCpy $DownloadMinSYS "0" ; Search the registry for the MinSYS uninstaller. ; If successful, put its location in $2. @@ -343,6 +350,9 @@ FunctionEnd ;-------------------------------- Function DownloadPython + StrCpy $PythonPath "" + StrCpy $DownloadPython "0" + ${DownloadEnter} \ $PythonPath "Software\Microsoft\Windows\CurrentVersion\App Paths\Python.exe" "" \ "\Python.exe" "" \ @@ -367,6 +377,10 @@ FunctionEnd ;-------------------------------- Function DownloadMiKTeX + StrCpy $DoNotRequireMiKTeX "1" + StrCpy $MiKTeXPath "" + StrCpy $DownloadMiKTeX "0" + ${DownloadEnter} \ $MiKTeXPath "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root" \ "" "\miktex\bin" \ @@ -391,6 +405,10 @@ FunctionEnd ;-------------------------------- Function DownloadPerl + StrCpy $DoNotRequirePerl "1" + StrCpy $PerlPath "" + StrCpy $DownloadPerl "1" + ${DownloadEnter} \ $PerlPath "Software\Perl" BinDir \ "\perl.exe" "" \ @@ -415,6 +433,9 @@ FunctionEnd ;-------------------------------- Function DownloadGhostscript + StrCpy $DoNotRequireGhostscript "1" + StrCpy $GhostscriptPath "" + StrCpy $DownloadGhostscript "0" ; Find which version of ghostscript, if any, is installed. EnumRegKey $1 HKLM "Software\AFPL Ghostscript" 0 @@ -448,6 +469,10 @@ FunctionEnd ;-------------------------------- Function DownloadImageMagick + StrCpy $DoNotRequireImageMagick "1" + StrCpy $ImageMagickPath "" + StrCpy $DownloadImageMagick "0" + ${DownloadEnter} \ $ImageMagickPath "Software\ImageMagick\Current" "BinPath" \ "" "" \ diff --git a/development/Win32/packaging/installer/lyx_languages/english.nsh b/development/Win32/packaging/installer/lyx_languages/english.nsh index 75ee952507..99cbddc753 100644 --- a/development/Win32/packaging/installer/lyx_languages/english.nsh +++ b/development/Win32/packaging/installer/lyx_languages/english.nsh @@ -18,6 +18,7 @@ LangString SecFileAssocDescription "${LYX_LANG}" "Create associations between th LangString SecDesktopDescription "${LYX_LANG}" "A ${PRODUCT_NAME} icon on the desktop." LangString ModifyingConfigureFailed "${LYX_LANG}" "Failed attempting to set 'path_prefix' in the configure script" +LangString RunConfigureFailed "${LYX_LANG}" "Failed attempting to execute the configure script" LangString FinishPageMessage "${LYX_LANG}" "Congratulations! LyX has been installed successfully." LangString FinishPageRun "${LYX_LANG}" "Launch LyX" @@ -26,8 +27,8 @@ LangString DownloadPageField2 "${LYX_LANG}" "&Do not install" LangString MinSYSHeader "${LYX_LANG}" "MinSYS" LangString MinSYSDescription "${LYX_LANG}" "MinSYS is a minimal unix scripting environment (www.mingw.org/msys.shtml) which ${PRODUCT_NAME} needs to run a number of scripts." -LangString EnterMinSYSFolder "${LYX_LANG}" "Please input the path to the folder containing MinSYS.exe" -LangString InvalidMinSYSFolder "${LYX_LANG}" "Unable to find MinSYS.exe" +LangString EnterMinSYSFolder "${LYX_LANG}" "Please input the path to the folder containing sh.exe" +LangString InvalidMinSYSFolder "${LYX_LANG}" "Unable to find sh.exe" LangString MinSYSDownloadLabel "${LYX_LANG}" "&Download MinSYS" LangString MinSYSFolderLabel "${LYX_LANG}" "&Folder containing sh.exe" diff --git a/development/Win32/packaging/installer/lyx_languages/french.nsh b/development/Win32/packaging/installer/lyx_languages/french.nsh index 4718763abe..abd5ce846b 100644 --- a/development/Win32/packaging/installer/lyx_languages/french.nsh +++ b/development/Win32/packaging/installer/lyx_languages/french.nsh @@ -14,11 +14,12 @@ LangString SecFileAssocTitle "${LYX_LANG}" "Associations de fichiers" LangString SecDesktopTitle "${LYX_LANG}" "Icône du bureau" LangString SecCoreDescription "${LYX_LANG}" "Les fichiers ${PRODUCT_NAME}" -LangString SecAllUsersDescription "${LYX_LANG}" "Installer pour tous les utilisateurs, ou seulement pour l'utilisateur courant (nécessite les droits d'administrateur) ?." +LangString SecAllUsersDescription "${LYX_LANG}" "Installer pour tous les utilisateurs (nécessite les droits d'administrateur), ou seulement pour l'utilisateur courant ?." LangString SecFileAssocDescription "${LYX_LANG}" "Crée les associations entre l'exécutable et le suffixe .lyx." LangString SecDesktopDescription "${LYX_LANG}" "Une icône ${PRODUCT_NAME} sur le bureau." -LangString ModifyingConfigureFailed "${LYX_LANG}" "Échec de l'allocation 'path_prefix' dans le script de configuration." +LangString ModifyingConfigureFailed "${LYX_LANG}" "Échec de l'allocation 'path_prefix' lors de la configuration." +LangString RunConfigureFailed "${LYX_LANG}" "Failed attempting to execute the configure script" LangString FinishPageMessage "${LYX_LANG}" "Félicitations ! LyX est installé avec succès." LangString FinishPageRun "${LYX_LANG}" "Démarrer LyX" @@ -26,14 +27,14 @@ LangString FinishPageRun "${LYX_LANG}" "D LangString DownloadPageField2 "${LYX_LANG}" "&Ne pas installer" LangString MinSYSHeader "${LYX_LANG}" "MinSYS" -LangString MinSYSDescription "${LYX_LANG}" "MinSYS est un environnement minimal pour gérer des fichiers de commande (www.mingw.org/msys.shtml) dont ${PRODUCT_NAME} a besoin pour exécuter un certain nombre de commandes." -LangString EnterMinSYSFolder "${LYX_LANG}" "Merci de saisir le chemin conduisant au répertoire où se trouve MinSYS.exe" -LangString InvalidMinSYSFolder "${LYX_LANG}" "MinSYS.exe introuvable" +LangString MinSYSDescription "${LYX_LANG}" "MinSYS est un environnement minimal pour gérer des commandes (www.mingw.org/msys.shtml) dont ${PRODUCT_NAME} a besoin pour ses traitements." +LangString EnterMinSYSFolder "${LYX_LANG}" "Merci de saisir le chemin conduisant au répertoire où se trouve sh.exe" +LangString InvalidMinSYSFolder "${LYX_LANG}" "sh.exe introuvable" LangString MinSYSDownloadLabel "${LYX_LANG}" "&Télécharger MinSYS" LangString MinSYSFolderLabel "${LYX_LANG}" "&Répertoire contenant sh.exe" LangString PythonHeader "${LYX_LANG}" "Python" -LangString PythonDescription "${LYX_LANG}" "Le language de scripting Python (www.python.org) doit être installé ou ${PRODUCT_NAME} ne pourra pas exécuter un certain nombre de commandes." +LangString PythonDescription "${LYX_LANG}" "Le langage de commandes Python (www.python.org) doit être installé ou ${PRODUCT_NAME} ne pourra pas exécuter un certain nombre de commandes." LangString EnterPythonFolder "${LYX_LANG}" "Merci de saisir le chemin conduisant au répertoire où se trouve Python.exe" LangString InvalidPythonFolder "${LYX_LANG}" "Python.exe introuvable" LangString PythonDownloadLabel "${LYX_LANG}" "&Télécharger Python" @@ -47,7 +48,7 @@ LangString MiKTeXDownloadLabel "${LYX_LANG}" "&T LangString MiKTeXFolderLabel "${LYX_LANG}" "&Répertoire contenant latex.exe" LangString PerlHeader "${LYX_LANG}" "Perl" -LangString PerlDescription "${LYX_LANG}" "Si vous avez l'intention d'utilier reLyX pour convertir des documents LaTeX en LyX, vous devez installer Perl (www.perl.com)." +LangString PerlDescription "${LYX_LANG}" "Si vous avez l'intention d'utiliser reLyX pour convertir des documents LaTeX en LyX, vous devez installer Perl (www.perl.com)." LangString EnterPerlFolder "${LYX_LANG}" "Merci de saisir le chemin conduisant au répertoire où se trouve Perl.exe" LangString InvalidPerlFolder "${LYX_LANG}" "Perl.exe introuvable" LangString PerlDownloadLabel "${LYX_LANG}" "&Télécharger Perl" diff --git a/development/Win32/packaging/installer/lyx_languages/german.nsh b/development/Win32/packaging/installer/lyx_languages/german.nsh index 0cb4d8cf1b..7d913f7b83 100644 --- a/development/Win32/packaging/installer/lyx_languages/german.nsh +++ b/development/Win32/packaging/installer/lyx_languages/german.nsh @@ -18,6 +18,7 @@ LangString SecFileAssocDescription "${LYX_LANG}" "Create associations between th LangString SecDesktopDescription "${LYX_LANG}" "A ${PRODUCT_NAME} icon on the desktop." LangString ModifyingConfigureFailed "${LYX_LANG}" "Failed attempting to set 'path_prefix' in the configure script" +LangString RunConfigureFailed "${LYX_LANG}" "Failed attempting to execute the configure script" LangString FinishPageMessage "${LYX_LANG}" "Congratulations! LyX has been installed successfully." LangString FinishPageRun "${LYX_LANG}" "Launch LyX" @@ -26,8 +27,8 @@ LangString DownloadPageField2 "${LYX_LANG}" "&Do not install" LangString MinSYSHeader "${LYX_LANG}" "MinSYS" LangString MinSYSDescription "${LYX_LANG}" "MinSYS is a minimal unix scripting environment (www.mingw.org/msys.shtml) which ${PRODUCT_NAME} needs to run a number of scripts." -LangString EnterMinSYSFolder "${LYX_LANG}" "Please input the path to the folder containing MinSYS.exe" -LangString InvalidMinSYSFolder "${LYX_LANG}" "Unable to find MinSYS.exe" +LangString EnterMinSYSFolder "${LYX_LANG}" "Please input the path to the folder containing sh.exe" +LangString InvalidMinSYSFolder "${LYX_LANG}" "Unable to find sh.exe" LangString MinSYSDownloadLabel "${LYX_LANG}" "&Download MinSYS" LangString MinSYSFolderLabel "${LYX_LANG}" "&Folder containing sh.exe" diff --git a/development/Win32/packaging/installer/lyx_path_prefix.C b/development/Win32/packaging/installer/lyx_path_prefix.C index 305d32a131..601818600b 100644 --- a/development/Win32/packaging/installer/lyx_path_prefix.C +++ b/development/Win32/packaging/installer/lyx_path_prefix.C @@ -18,7 +18,7 @@ * Compile the code with * * g++ -I/c/Program\ Files/NSIS/Contrib -Wall -shared \ - * lyx_path_prefix.c -o lyx_path_prefix.dll + * lyx_path_prefix.C -o lyx_path_prefix.dll * * Move resulting .dll to /c/Program\ Files/NSIS/Plugins */ @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include namespace { @@ -42,12 +44,154 @@ std::string const subst(std::string const & a, std::string::size_type const olen = oldstr.length(); while ((i = lstr.find(oldstr, i)) != std::string::npos) { lstr.replace(i, olen, newstr); - i += newstr.length(); // We need to be sure that we dont - // use the same i over and over again. + i += newstr.length(); } return lstr; } + +std::string const basename(std::string const & path) +{ + std::string::size_type const final_slash = path.find_last_of('\\'); + if (final_slash == std::string::npos) + return path; + return path.substr(final_slash+1); +} + + +std::string const dirname(std::string const & path) +{ + std::string::size_type const final_slash = path.find_last_of('\\'); + if (final_slash == std::string::npos) + return std::string(); + return path.substr(0, final_slash); +} + + +std::string const pop_from_stack() +{ + char data[10*MAX_PATH]; + popstring(data); + return data; +} + + +std::list const tokenize(std::string data, + char const separator) +{ + std::list result; + while (true) { + std::string::size_type const end = data.find(separator); + if (end == std::string::npos) { + result.push_back(data); + break; + } + result.push_back(data.substr(0, end)); + data = data.substr(end+1); + } + return result; +} + + +void remove_duplicates(std::list & data) +{ + typedef std::list::iterator iterator; + for (iterator it = data.begin(); it != data.end(); ++it) { + iterator next = it; + ++next; + if (next == data.end()) + break; + iterator end = std::remove(next, data.end(), *it); + data.erase(end, data.end()); + } +} + + +std::string concatenate(std::list const & data, + char const separator) +{ + typedef std::list::const_iterator iterator; + iterator it = data.begin(); + iterator const end = data.end(); + if (it == end) + return std::string(); + + std::ostringstream result; + result << *it; + ++it; + for (; it != end; ++it) { + result << separator << *it; + } + return result.str(); +} + + +std::string const sanitize_path(std::string const & in) +{ + // Replace multiple, adjacent directory separators. + std::string out = subst(in, "\\\\", "\\"); + std::list out_list = tokenize(out, ';'); + remove_duplicates(out_list); + return concatenate(out_list, ';'); +} + + +bool replace_path_prefix(std::string & data, + std::string::size_type prefix_pos, + std::string const & path_prefix) +{ + std::string::size_type start_prefix = + data.find_first_of('"', prefix_pos); + if (start_prefix == std::string::npos) + return false; + start_prefix += 1; + + std::string::size_type end_line = + data.find_first_of('\n', prefix_pos); + if (end_line == std::string::npos) + return false; + + std::string::size_type end_prefix = + data.find_last_of('"', end_line); + if (end_prefix == std::string::npos || end_prefix == start_prefix) + return false; + + std::string::size_type const count = end_prefix - start_prefix; + std::string const old_prefix = data.substr(start_prefix, count); + std::string const prefix = + subst(sanitize_path(path_prefix + ';' + old_prefix), "\\", "\\\\"); + + data.erase(start_prefix, count); + data.insert(start_prefix, prefix); + + return true; +} + + +bool insert_path_prefix(std::string & data, + std::string::size_type xfonts_pos, + std::string const & path_prefix) +{ + std::string::size_type const xfonts_start = + data.find_last_of('\n', xfonts_pos); + + if (xfonts_start == std::string::npos) + return false; + + std::string const prefix = subst(sanitize_path(path_prefix), "\\", "\\\\"); + std::ostringstream ss; + ss << data.substr(0, xfonts_start) + << "\n" + "cat >>$outfile < const begin(fs); - std::istreambuf_iterator const end; + std::istreambuf_iterator const begin_ifs(ifs); + std::istreambuf_iterator const end_ifs; + std::string configure_data(begin_ifs, end_ifs); + ifs.close(); - std::string configure_data(begin, end); - std::string::size_type const xfonts_pos = configure_data.find("X FONTS"); - if (xfonts_pos == std::string::npos) { + // Does configure already contain a "path_prefix" entry + // or should we insert one? + std::string::size_type const prefix_pos = + configure_data.find("path_prefix"); + if (prefix_pos != std::string::npos) { + if (!replace_path_prefix(configure_data, prefix_pos, path_prefix)) { + pushstring("-1"); + return; + } + } else { + std::string::size_type const xfonts_pos = + configure_data.find("X FONTS"); + + if (xfonts_pos == std::string::npos) { + pushstring("-1"); + return; + } + + if (!insert_path_prefix(configure_data, xfonts_pos, path_prefix)) { + pushstring("-1"); + return; + } + } + + std::ofstream ofs(configure_file.c_str()); + if (!ofs) { pushstring("-1"); return; } - std::string::size_type const xfonts_start = - configure_data.find_last_of('\n', xfonts_pos); - if (xfonts_start == std::string::npos) { + ofs << configure_data; + pushstring("0"); +} + + +// Runs "sh configure" to generate things like lyxrc.defaults. +extern "C" +void __declspec(dllexport) run_configure(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + EXDLL_INIT(); + + std::string configure_file = pop_from_stack(); + std::string const path_prefix = pop_from_stack(); + + std::string const configure_dir = dirname(configure_file); + configure_file = basename(configure_file); + + if (configure_dir.empty()) { pushstring("-1"); return; } - fs.seekg(0); - fs << configure_data.substr(0, xfonts_start) - << "\n" - "cat >>$outfile <