[lokisetup] Patches

Ludwig Nussel ludwig.nussel at gmx.de
Sat Sep 4 20:03:15 EDT 2004


Stephane Peter wrote:
> I have just merged in all of these patches, to the exception of the  
> promptoverwrite one.
> The reason I didn't merge it is because I'd rather have the default  
> value to be "no" to preserve backwards compatibility with older setup  
> files. If you don't mind sending me an updated patch, I'll merge it,  
> else I'll probably end up doing it myself anyway...

The problem ist that if it's not enabled by default then noone is
going to enable it. Especially since existing setup.xml do not
include it and new installers are probably created by copy&paste.
Patch with reversed logic attached anyways.

The patch loki_setup-lang.diff fixes display of localized tooltips.
Atm only the english text is shown if it comes first in the
setup.xml. Also supports required=false. image/setup.data/setup.xml
should better be UTF-8. Unfortunately gtk1 doesn't automatically
deal properly with encodings so either you have no umlauts (xml
iso-8859-1, locale UTF-8) or garbage instead of umlauts (xml UTF-8,
locale iso-8859-1).

cu
Ludwig

-- 
(o_  Ludwig.Nussel at gmx.de
//\  PGP Key ID: FF8135CE
V_/_ ICQ:        52166811
-------------- next part --------------
Index: loki_setup/README.xml
===================================================================
--- loki_setup.orig/README.xml	2004-09-03 21:01:02.000000000 +0200
+++ loki_setup/README.xml	2004-09-05 01:29:33.132914903 +0200
@@ -188,6 +188,10 @@
 
  manpages   If set to "yes", then the user will be prompted for the install pages installation path.
             Should be used when using the MANPAGE element described below.
+ 
+ promptoverwrite  If set to 'yes' existing files will be overwritten without
+				  prompting the user. It is recommended to enable this option
+				  to not accidently overwrite the user's files.
 
 The CDROM element:
 
Index: loki_setup/copy.c
===================================================================
--- loki_setup.orig/copy.c	2004-08-27 23:34:42.000000000 +0200
+++ loki_setup/copy.c	2004-09-05 01:29:33.133914693 +0200
@@ -305,11 +305,8 @@
 		if ( input == NULL ) {
 			goto copy_file_exit;
 		}
-		/* To avoid problem with busy binary files, remove them first if they exist */
-		if ( binary && file_exists(final) ) {
-			unlink(final);
-		}
-		output = file_open(info, final, (mut && *mut=='y') ? "wm" : "w");
+
+		output = file_open_install(info, final, (mut && *mut=='y') ? "wm" : "w");
 		if ( output == NULL ) {
 			file_close(info, input);
 			goto copy_file_exit;
@@ -898,7 +895,6 @@
 				if ( product ) {
 					if ( GetProductIsMeta(info) ) {
 						extern const char *argv0; // Set in main.c
-                        extern Install_UI UI;
                         if (UI.shutdown) UI.shutdown(info);
 						// We spawn a new setup for this product
 #if defined(darwin)
@@ -1260,3 +1256,4 @@
     return num_binaries;
 }
 
+
Index: loki_setup/file.c
===================================================================
--- loki_setup.orig/file.c	2004-08-27 23:34:42.000000000 +0200
+++ loki_setup/file.c	2004-09-05 01:29:33.134914483 +0200
@@ -18,6 +18,7 @@
 
 #include "file.h"
 #include "install_log.h"
+#include "install_ui.h"
 
 #ifdef HAVE_BZIP2_SUPPORT
 
@@ -128,6 +129,30 @@
 	return streamp;
 }
 
+static int prompt_overwrite = -1;
+
+stream *file_open_install(install_info *info, const char *path, const char *mode)
+{
+	if ( file_exists(path) ) {
+		if( prompt_overwrite == -1 ) {
+			prompt_overwrite = GetProductPromptOverwrite(info);
+		}
+
+		if ( prompt_overwrite ) {
+			char msg[128];
+			snprintf(msg, sizeof(msg), _("File '%25s' already exists, overwrite?"), path);
+			if ( UI.prompt(msg, RESPONSE_YES) != RESPONSE_YES ) {
+				return NULL;
+			}
+		}
+		log_warning(_("File exists: '%s'"), path);
+
+		/* To avoid problem with busy binary files, remove them first if they exist */
+		unlink(path);
+	}
+	return file_open(info, path, mode);
+}
+
 stream *file_open(install_info *info, const char *path, const char *mode)
 {
     stream *streamp;
Index: loki_setup/file.h
===================================================================
--- loki_setup.orig/file.h	2004-03-08 22:43:10.000000000 +0100
+++ loki_setup/file.h	2004-09-05 01:29:33.135914273 +0200
@@ -33,6 +33,8 @@
 } stream;
 
 extern void file_init(void);
+/** wrapper for file_open to prompt user whether to overwrite. Also unlinks file first */
+extern stream *file_open_install(install_info *info, const char *path, const char *mode);
 extern stream *file_open(install_info *info,const char *path,const char *mode);
 extern stream *file_fdopen(install_info *info, const char *path, FILE *fd, gzFile zfd, BZFILE *bzfd, const char *mode);
 extern int file_read(install_info *info, void *buf, int len, stream *streamp);
Index: loki_setup/install.c
===================================================================
--- loki_setup.orig/install.c	2004-09-05 01:29:33.045933198 +0200
+++ loki_setup/install.c	2004-09-05 01:40:09.910432807 +0200
@@ -297,6 +297,7 @@
     if ( str && !strcasecmp(str, "top") ) {
         ret = 0; /* Top */
     }
+	xmlFree(str);
     return ret;
 }
 
@@ -305,6 +306,26 @@
     return xmlGetProp(info->config->root, "cdkey");
 }
 
+int GetProductPromptOverwrite(install_info *info)
+{
+	int ret = 0; /* no */
+	int needfree = 0;
+    char *str = NULL;
+	if(getenv("SETUP_PROMPTOVERWRITE")) {
+		str = getenv("SETUP_PROMPTOVERWRITE");
+	}
+	else {
+		str = xmlGetProp(info->config->root, "promptoverwrite");
+		needfree = 1;
+	}
+    if ( str && (!strcasecmp(str, "yes") || !strcasecmp(str, "true"))) {
+        ret = 1; /* yes */
+    }
+	if(needfree)
+		xmlFree(str);
+    return ret;
+}
+
 /* returns true if any deviant paths are not writable */
 char check_deviant_paths(xmlNodePtr node, install_info *info)
 {
Index: loki_setup/install.h
===================================================================
--- loki_setup.orig/install.h	2004-08-27 23:34:42.000000000 +0200
+++ loki_setup/install.h	2004-09-05 01:39:25.433860160 +0200
@@ -264,6 +264,8 @@
 extern int         GetProductHasManPages(install_info *info);
 extern const char *GetProductCDKey(install_info *info);
 extern const char *GetProductPostInstallMsg(install_info *info);
+/** whether the user should be prompted when files already exist */
+extern int GetProductPromptOverwrite(install_info *info);
 
 extern const char *IsReadyToInstall(install_info *info);
 extern int         CheckRequirements(install_info *info);
Index: loki_setup/install_ui.h
===================================================================
--- loki_setup.orig/install_ui.h	2003-03-29 12:46:22.000000000 +0100
+++ loki_setup/install_ui.h	2004-09-05 01:29:33.137913852 +0200
@@ -33,6 +33,8 @@
     int is_gui; /* Whether an X11 server is available for that UI driver */
 } Install_UI;
 
+extern Install_UI UI;
+
 extern int console_okay(Install_UI *UI, int *argc, char ***argv);
 extern int gtkui_okay(Install_UI *UI, int *argc, char ***argv);
 extern int dialog_okay(Install_UI *UI, int *argc, char ***argv);
Index: loki_setup/plugins/cpio.c
===================================================================
--- loki_setup.orig/plugins/cpio.c	2002-12-07 01:57:32.000000000 +0100
+++ loki_setup/plugins/cpio.c	2004-09-05 01:29:33.138913642 +0200
@@ -149,7 +149,7 @@
 			} else {
 				unsigned long chk = 0;
 				/* Open the file for output */
-				output = file_open(info, file_hdr.c_name, (mut && *mut=='y') ? "wm" : "wb"); /* FIXME: Mmh, is the path expanded??? */
+				output = file_open_install(info, file_hdr.c_name, (mut && *mut=='y') ? "wm" : "wb"); /* FIXME: Mmh, is the path expanded??? */
 				if(output){
 					left = file_hdr.c_filesize;
 					while(left && (nread=file_read(info, buf, (left >= BUFSIZ) ? BUFSIZ : left, input))){
Index: loki_setup/plugins/tar.c
===================================================================
--- loki_setup.orig/plugins/tar.c	2004-03-10 00:30:55.000000000 +0100
+++ loki_setup/plugins/tar.c	2004-09-05 01:29:33.138913642 +0200
@@ -88,7 +88,7 @@
 					file_skip(info, left, input);
 				} else {
 					this_size = 0;
-					output = file_open(info, final, (mut && *mut=='y') ? "wm" : "wb");
+					output = file_open_install(info, final, (mut && *mut=='y') ? "wm" : "wb");
 					if ( output ) {
 						while ( blocks-- > 0 ) {
 							if ( file_read(info, &record, (sizeof record), input)
Index: loki_setup/plugins/uz2.c
===================================================================
--- loki_setup.orig/plugins/uz2.c	2004-03-04 21:16:22.000000000 +0100
+++ loki_setup/plugins/uz2.c	2004-09-05 01:29:33.139913431 +0200
@@ -137,7 +137,7 @@
     if ((in = file_open(info, path, "rb")) == NULL)
         return 0;
 
-    if ((out = file_open(info, final, (mut && *mut=='y') ? "wm" : "wb"))==NULL)
+    if ((out = file_open_install(info, final, (mut && *mut=='y') ? "wm" : "wb"))==NULL)
     {
         file_close(info, in);
         return 0;
Index: loki_setup/plugins/zip.c
===================================================================
--- loki_setup.orig/plugins/zip.c	2004-02-28 20:03:42.000000000 +0100
+++ loki_setup/plugins/zip.c	2004-09-05 01:29:33.140913221 +0200
@@ -737,7 +737,7 @@
 
         if (!symlnk)
         {
-            out = file_open(info, final, (mut && *mut=='y') ? "wm" : "wb");
+            out = file_open_install(info, final, (mut && *mut=='y') ? "wm" : "wb");
             if (!out)
             {
                 log_debug("ZIP: failed to open [%s] for write.", final);
-------------- next part --------------
Index: loki_setup/detect.c
===================================================================
--- loki_setup.orig/detect.c	2004-09-05 01:29:33.074927100 +0200
+++ loki_setup/detect.c	2004-09-05 01:32:16.876437978 +0200
@@ -783,13 +783,12 @@
 
 void DetectLocale(void)
 {
-	current_locale = getenv("LC_ALL");
-	if (!current_locale)
-		current_locale = getenv("LC_MESSAGES");
-	if (!current_locale)
-		current_locale = getenv("LANG");
-	if ( current_locale )
-		log_debug(_("Detected locale is %s"), current_locale);
+	current_locale = setlocale(LC_MESSAGES, NULL);
+	if ( current_locale && (!strcmp(current_locale, "C") || !strcmp(current_locale,"POSIX")) ) {
+		current_locale = NULL;
+	}
+	if ( 0 ) /* log_debug doesn't work here as logging is initialized later */
+		fprintf(stderr, _("Detected locale is %s\n"), current_locale);
 }
 
 /* Matches a locale string against the current one */
@@ -798,10 +797,8 @@
 {
 	if ( ! str )
 		return 1;
-	if ( current_locale && ! (!strcmp(current_locale, "C") || !strcmp(current_locale,"POSIX")) ) {
-		if ( strstr(current_locale, str) == current_locale ) {
-			return 1;
-		}
+	if ( current_locale && !strncmp(current_locale, str, 2)) {
+		return 1;
 	} else if ( !strcmp(str, "none") ) {
 		return 1;
 	}
Index: loki_setup/gtk_ui.c
===================================================================
--- loki_setup.orig/gtk_ui.c	2004-09-03 21:01:02.000000000 +0200
+++ loki_setup/gtk_ui.c	2004-09-05 01:29:33.171906703 +0200
@@ -1229,6 +1229,7 @@
     gchar *name;
     int i;
     GtkWidget *button = NULL;
+	gboolean install = FALSE;
 
 	/* Skip translation nodes */
 	if ( !strcmp(node->name, "lang") )
@@ -1309,15 +1310,15 @@
 	}
 
     /* Check for required option */
-    if ( xmlGetProp(node, "required") ) {
+    if ( xmlNodePropIsTrue(node, "required") ) {
 		xmlSetProp(node, "install", "true");
 		gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
     }
 
     /* If this is a sub-option and parent is not active, then disable option */
-    wanted = xmlGetProp(node, "install");
+    install = xmlNodePropIsTrue(node, "install");
     if( level>0 && GTK_IS_TOGGLE_BUTTON(parent) && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(parent)) ) {
-		wanted = "false";
+		install = FALSE;
 		gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
     }
 	if ( button ) {
@@ -1327,7 +1328,7 @@
 		gtk_widget_show(button);
 	}
 
-	if ( wanted && (strcmp(wanted, "true") == 0) ) {
+	if ( install ) {
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
     } else {
         /* Unmark this option for installation */
Index: loki_setup/image/setup.data/setup.xml
===================================================================
--- loki_setup.orig/image/setup.data/setup.xml	2003-06-15 11:14:28.000000000 +0200
+++ loki_setup/image/setup.data/setup.xml	2004-09-05 01:29:33.172906492 +0200
@@ -8,17 +8,17 @@
    license.txt
   </eula>
   <component name="Default" version="1.54" default="yes">
-   <option install="true" required="true">
+   <option install="true" required="false">
     Base Install
     <lang lang="fr">Installation de base</lang>
-    <lang lang="es">Instalaci?n base</lang>
+    <lang lang="es">Instalaci?n base</lang>
     <lang lang="it">Installazione base</lang>
     <lang lang="de">Minimale Installation</lang>
     <help          >Required for play</help>
     <help lang="fr">Requis pour jouer</help>
     <help lang="es">Se necesita para jugar</help>
-    <help lang="it">? necessaria per giocare</help>
-    <help lang="de">Zum Spielen ben?tigt</help>
+    <help lang="it">? necessaria per giocare</help>
+    <help lang="de">Zum Spielen ben?tigt</help>
 
     <binary arch="any" libc="any" symlink="rt2" icon="icon.xpm" play="yes">
       rt2
Index: loki_setup/install.c
===================================================================
--- loki_setup.orig/install.c	2004-09-05 01:29:33.136914062 +0200
+++ loki_setup/install.c	2004-09-05 01:29:33.174906072 +0200
@@ -1323,6 +1323,7 @@
     const char *text;
 	char *help = xmlGetProp(node, "help");
 	xmlNodePtr n;
+	xmlNodePtr nolang = NULL;
 
 	*line = '\0';
 	if ( help ) {
@@ -1335,7 +1336,9 @@
 	while ( n ) {
 		if( strcmp(n->name, "help") == 0 ) {
 			char *prop = xmlGetProp(n, "lang");
-			if ( match_locale(prop) ) {
+			if(!prop) {
+				nolang = n;
+			} else if ( match_locale(prop) ) {
 				text = xmlNodeListGetString(info->config, n->childs, 1);
 				if(text) {
 					*line = '\0';
@@ -1348,6 +1351,16 @@
 		}
 		n = n->next;
 	}
+
+	/* no matching locale found. use if available */
+	if(!*line && nolang) {
+		text = xmlNodeListGetString(info->config, nolang->childs, 1);
+		if(text) {
+			*line = '\0';
+			while ( (*line == 0) && parse_line(&text, line, sizeof(line)) )
+				;
+		}
+	}
 	return (*line) ? line : NULL;
 }
 
@@ -2743,3 +2756,23 @@
             fprintf(stderr, "chdir(pop: %s): %s\n", curdirs[curdir_index], strerror(errno));
     }
 }
+
+int xmlNodePropIsTrue(xmlNodePtr node, const char* prop)
+{
+    const char* str = xmlGetProp(node, prop);
+
+	if(str && (!strcmp(str, "true") || !strcmp(str, "yes")))
+		return 1;
+
+	return 0;
+}
+
+int xmlNodePropIsFalse(xmlNodePtr node, const char* prop)
+{
+    const char* str = xmlGetProp(node, prop);
+
+	if(str && (!strcmp(str, "false") || !strcmp(str, "no")))
+		return 1;
+
+	return 0;
+}
Index: loki_setup/install.h
===================================================================
--- loki_setup.orig/install.h	2004-09-05 01:29:33.137913852 +0200
+++ loki_setup/install.h	2004-09-05 01:29:33.175905861 +0200
@@ -413,6 +413,8 @@
 extern int restoring_corrupt(void);
 extern void select_corrupt_options(install_info *info);
 
+int xmlNodePropIsTrue(xmlNodePtr node, const char* prop);
+int xmlNodePropIsFalse(xmlNodePtr node, const char* prop);
 
 /*** Global variables ****/
 
@@ -423,3 +425,4 @@
 
 #endif /* _install_h */
 
+


More information about the Lokisetup mailing list