[PATCH] update for file overwrite prompt

Ludwig Nussel ludwig.nussel at gmx.de
Wed Dec 22 10:47:20 EST 2004


Hi,

I think it's better to rename 'nopromptoverwrite' to
'overwritefiles' and have it tri-state instead of boolean. This way
it's possible to specify whether to generally overwrite ("yes"), to
not overwrite ("no") or to prompt the user ("prompt" or any other
value).

cu
Ludwig

-- 
(o_  Ludwig.Nussel at gmx.de
//\
V_/_ PGP Key ID: FF8135CE
-------------- next part --------------
Index: loki_setup/install.c
===================================================================
--- loki_setup.orig/install.c
+++ loki_setup/install.c
@@ -332,21 +332,29 @@ const char *GetProductCDKey(install_info
     return xmlGetProp(info->config->root, "cdkey");
 }
 
-int GetProductPromptOverwrite(install_info *info)
+// 0 = don't overwrite, 1 = overwrite, 2 = ask user
+int GetProductOverwriteFiles(install_info *info)
 {
-	int ret = 1; /* yes */
+	int ret = 2; /* prompt */
 	int needfree = 0;
     char *str = NULL;
-	if(getenv("SETUP_NOPROMPTOVERWRITE")) {
-		str = getenv("SETUP_NOPROMPTOVERWRITE");
+	if(getenv("SETUP_OVERWRITEFILES")) {
+		str = getenv("SETUP_OVERWRITEFILES");
 	}
 	else {
-		str = xmlGetProp(info->config->root, "nopromptoverwrite");
+		str = xmlGetProp(info->config->root, "overwritefiles");
 		needfree = 1;
 	}
-    if ( str && (!strcasecmp(str, "yes") || !strcasecmp(str, "true"))) {
+	if (!str) {
+		ret = 2; /* prompt */
+	}
+	else if ((!strcasecmp(str, "yes") || !strcasecmp(str, "true"))) {
+        ret = 1; /* yes */
+    }
+	else if ((!strcasecmp(str, "no") || !strcasecmp(str, "false"))) {
         ret = 0; /* no */
     }
+
 	if(needfree)
 		xmlFree(str);
     return ret;
Index: loki_setup/install.h
===================================================================
--- loki_setup.orig/install.h
+++ loki_setup/install.h
@@ -267,8 +267,10 @@ extern int         GetProductSplashPosit
 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);
+/** whether to overwrite already existing files
+ * @returns 0 = don't overwrite, 1 = overwrite, 2 = ask user
+ */
+extern int GetProductOverwriteFiles(install_info *info);
 
 /** check if product can be installed. Returns NULL if product can be
  * installed, otherwise reason why not. */
Index: loki_setup/file.c
===================================================================
--- loki_setup.orig/file.c
+++ loki_setup/file.c
@@ -130,16 +130,19 @@ stream *file_fdopen(install_info *info, 
 	return streamp;
 }
 
-static int prompt_overwrite = -1;
+static int 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( overwrite == -1 ) {
+			overwrite = GetProductOverwriteFiles(info);
 		}
 
-		if ( prompt_overwrite ) {
+		if ( overwrite == 0 ) {
+			return NULL;
+		}
+		else if ( overwrite == 2 ) {
 			char msg[128];
 			snprintf(msg, sizeof(msg), _("File '%25s' already exists, overwrite?"), path);
 			if ( UI.prompt(msg, RESPONSE_YES) != RESPONSE_YES ) {
Index: loki_setup/README.xml
===================================================================
--- loki_setup.orig/README.xml
+++ loki_setup/README.xml
@@ -191,8 +191,8 @@ There are several optional attributes of
  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.
  
- nopromptoverwrite  If set to 'yes' existing files will be overwritten without
-                    prompting the user. This was the default before setup 1.6.4
+ overwritefiles  If set to 'yes' existing files will be overwritten without
+                 prompting the user. This was the default before setup 1.6.4
 
 The CDROM element:
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://icculus.org/pipermail/lokisetup/attachments/20041222/6e639bae/attachment.pgp>


More information about the Lokisetup mailing list