commit 237b0404ff45af46d2815d65b3590d309ce4e2bf
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sat Apr 20 14:57:12 2024 +0200

    Handle the case of outdated chkconfig.ltx in user directory
    
    (cherry picked from commit b8ff824a4f4ab4d3e213b55bf8117fd95b7b9657)
---
 src/LaTeXPackages.cpp | 39 ++++++++++++++++++++++++++++++++++++---
 src/LaTeXPackages.h   |  2 +-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/LaTeXPackages.cpp b/src/LaTeXPackages.cpp
index e708df1dfe..0f4129eabe 100644
--- a/src/LaTeXPackages.cpp
+++ b/src/LaTeXPackages.cpp
@@ -22,9 +22,12 @@
 #include "support/debug.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 #include "support/Package.h"
 
+#include "frontends/alert.h"
+
 
 using namespace std;
 using namespace lyx::support;
@@ -35,7 +38,7 @@ namespace lyx {
 LaTeXPackages::Packages LaTeXPackages::packages_;
 
 
-void LaTeXPackages::getAvailable()
+void LaTeXPackages::getAvailable(bool retry)
 {
        Lexer lex;
        support::FileName const real_file = libFileSearch("", "packages.lst");
@@ -73,10 +76,40 @@ void LaTeXPackages::getAvailable()
                }
        }
        // Check if the pkglist has current format.
-       // Reconfigure and re-parse if not.
+       // Reconfigure once and re-parse if not.
        if (lstformat != "2") {
+               // If we have already reconfigured, check if there is an 
outdated config file
+               // which produces the outdated lstformat
+               if (retry) {
+                       // check if we have an outdated chkconfig.ltx file in 
user dir
+                       support::FileName chkconfig = 
fileSearch(addPath(package().user_support().absFileName(), ""),
+                                                                
"chkconfig.ltx", string(), must_exist);
+                       if (chkconfig.empty()) {
+                               // nothing found. So we can only warn
+                               frontend::Alert::warning(_("Invalid package 
list format!"),
+                                       _("The format of your LaTeX packages 
list is wrong. Please file a bug report."));
+                               return;
+                       }
+                       // Found. Try to rename and warn.
+                       support::FileName chkconfig_bak;
+                       chkconfig_bak.set(chkconfig.absFileName() + ".bak");
+                       if (chkconfig.renameTo(chkconfig_bak))
+                               // renaming succeeded
+                               frontend::Alert::warning(_("Outdated 
configuration script detected!"),
+                                       _("We have detected an outdated script 
'chkconfig.ltx' in your user directory.\n"
+                                         "The script has been renamed to 
'chkconfig.ltx.bak'.\n"
+                                         "If you did not copy the script there 
by purpose, you can safely delete it."));
+                       else {
+                               // renaming failed
+                               frontend::Alert::warning(_("Outdated 
configuration script detected!"),
+                                       bformat(_("We have detected an outdated 
script 'chkconfig.ltx' in your user directory\n"
+                                         "(%1$s).\n"
+                                         "Please delete or update this 
file!"), from_utf8(chkconfig.absFileName())));
+                               return;
+                       }
+               }
                package().reconfigureUserLyXDir("");
-               getAvailable();
+               getAvailable(true);
        }
 }
 
diff --git a/src/LaTeXPackages.h b/src/LaTeXPackages.h
index dba6d039f6..12f3e4ec0b 100644
--- a/src/LaTeXPackages.h
+++ b/src/LaTeXPackages.h
@@ -25,7 +25,7 @@ namespace lyx {
 class LaTeXPackages {
 public:
        /// Which of the required packages are installed?
-       static void getAvailable();
+       static void getAvailable(bool retry = false);
        /// Is the (required) package available?
        static bool isAvailable(std::string const & name);
        /// Is the (required) package available at least as of
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to