⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 install.c

📁 apache简化版
💻 C
📖 第 1 页 / 共 2 页
字号:
			 "Cannot read file %s", inFile);	return -1;    }    if (! (options & OPT_OVERWRITE)) {	/* Overwrite not allowed if file does not exist */	if ((outfp = fopen(outFile, "r"))) {	    if (! (options & OPT_SILENT)) {		MessageBox_error(hwnd,				 0,				 "File not overwritten",				 MB_OK | MB_ICONWARNING,				 "Preserving existing file %s.\r\r"				 "The new version of this file has been left in %s", 				 outFile, inFile);	    }	    fclose(outfp);	    fclose(infp);	    return 0;	}	/* To get here, output file does not exist */    }    if (!(outfp = fopen(outFile, "w"))) {	MessageBox_error(hwnd, 			 AP_WIN32ERROR,			 "Installation Problem",			 MB_OK | MB_ICONSTOP,			 "Cannot write to file %s", outFile);	fclose(infp);	return -1;    }    while (fgets(inbuf, MAX_INPUT_LINE, infp)) {	char *pos;	char *outbuf;	/* Quickly look to see if this line contains any	 * @@ tokens. If it doesn't, we don't need to bother	 * called expandLine() or taking a copy of the input	 * buffer.	 */	if (options & OPT_EXPAND) {    	    for (pos = inbuf; *pos; ++pos)		if (*pos == '@' && *(pos+1) == '@')		    break;	}	if (options & OPT_EXPAND && *pos) {	    /* The input line contains at least one '@@' sequence, so	     * call expandLine() to expand any sequences we know about.	     */	    outbuf = expandLine(inbuf, replaceTable);	    if (outbuf == NULL) {		fclose(infp);		fclose(outfp);		MessageBox_error(hwnd,				 0,				 "Installation Problem",				 MB_OK|MB_ICONSTOP,				 "An error occurred during installation");		return -1;	    }	}	else {	    outbuf = NULL;	}	/* If outbuf is NULL, we did not need to expand sequences, so	 * just output the contents of the input buffer.	 */	fwrite(outbuf ? outbuf : inbuf, 1, 	       strlen(outbuf ? outbuf : inbuf), outfp);	if (outbuf)	    free(outbuf);    }    fclose(infp);    fclose(outfp);    if (options & OPT_DELETESOURCE) {	unlink(inFile);    }    return 0;}int FillInReplaceTable(HWND hwnd, REPLACETABLE table, char *szInst){    REPLACEITEM *item;    for (item = table; item->tmpl; ++item) {	if (!strcmp(item->tmpl, "@@ServerRoot@@")) {	    char *p;#if NEED_SHORT_PATHS	    int len;	    len = GetShortPathName(szInst, NULL, 0);	    if (len > 0) {		item->value = (char*)malloc(len+1);		GetShortPathName(szInst, item->value, len);	    }#else	    if ((item->value = strdup(szInst)) == NULL)	        return -1;#endif	    for (p = item->value; *p; p++)	        if (*p == '\\') *p = '/';	    continue;	}#if NEED_FQDN	if (!strcmp(item->tmpl, "FQDN")) {	    item->value = GetHostName(hwnd);	    continue;	}#endif    }    return 0;}/* * actionTable[] contains things we do when this DLL is called by InstallShield * during the install. It is like a simple script, without us having to * worry about parsing, error checking, etc. * * Each item in the table is of type ACTIONITEM. The first element is the action  * to perform (e.g. CMD_COPY). The second and third elements are filenames * (e.g. for CMD_COPY, the first filename is the source and the second filename * is the destination). The final element of ACTIONITEM is a set of options * which apply to the current "command". For example, OPT_EXPAND on a CMD_COPY * line, tells the copy function to expand @@ServerRoot@@ tokens found in the * source file. * * The contents of this table are performed in order, top to bottom. This lets * us expand the files to the *.conf.default names, then copy to *.conf only * if the corresponding *.conf file does not already exist. If it does exist, * it is not overwritten. * * Return 1 on success, 0 on error. */typedef enum {    CMD_COPY = 0,    CMD_RMDIR,    CMD_RM,    CMD_END} cmd_t;typedef struct {    cmd_t command;    char *in;    char *out;    options_t options;} ACTIONITEM;typedef ACTIONITEM *ACTIONTABLE;ACTIONITEM actionTable[] = {    /*     * Installation of the configuraton files. These are installed into the ".tmp"     * directory by the installer. We first move them to conf\*.default (overwriting     * any *.default file from a previous install). The *.conf-dist-win files     * are also expanded for any @@...@@ tokens. Then we copy the conf\*.default     * file to corresponding conf\* file, unless that would overwrite an existing file.     */    { CMD_COPY, ".tmp\\mime.types", "conf\\mime.types.default",	OPT_OVERWRITE|OPT_DELETESOURCE },    { CMD_COPY, ".tmp\\magic", "conf\\magic.default",	OPT_OVERWRITE|OPT_DELETESOURCE },    { CMD_COPY, ".tmp\\httpd.conf-dist-win", "conf\\httpd.conf.default", 	OPT_OVERWRITE|OPT_EXPAND|OPT_DELETESOURCE },    { CMD_COPY, ".tmp\\srm.conf-dist-win", "conf\\srm.conf.default", 	OPT_OVERWRITE|OPT_EXPAND|OPT_DELETESOURCE },    { CMD_COPY, ".tmp\\access.conf-dist-win", "conf\\access.conf.default", 	OPT_OVERWRITE|OPT_EXPAND|OPT_DELETESOURCE },    /* Now copy to the 'live' files, unless they already exist */    { CMD_COPY, "conf\\httpd.conf.default", "conf\\httpd.conf", OPT_NONE },    { CMD_COPY, "conf\\srm.conf.default", "conf\\srm.conf", OPT_NONE },    { CMD_COPY, "conf\\access.conf.default", "conf\\access.conf", OPT_NONE },    { CMD_COPY, "conf\\magic.default", "conf\\magic", OPT_NONE },    { CMD_COPY, "conf\\mime.types.default", "conf\\mime.types", OPT_NONE },    { CMD_COPY, ".tmp\\highperformance.conf-dist", "conf\\highperformance.conf-dist", 	OPT_EXPAND|OPT_OVERWRITE|OPT_DELETESOURCE },    /* Move the default htdocs files into place, provided they don't already     * exist.     */    { CMD_COPY, ".tmp\\index.html", "htdocs\\index.html", OPT_DELETESOURCE|OPT_SILENT },    { CMD_RM, ".tmp\\index.html", NULL, OPT_SILENT },    { CMD_COPY, ".tmp\\apache_pb.gif", "htdocs\\apache_pb.gif", OPT_DELETESOURCE|OPT_SILENT },    { CMD_RM, ".tmp\\apache_pb.gif", NULL, OPT_SILENT },    { CMD_RMDIR, ".tmp", NULL },    { CMD_END, NULL, NULL, OPT_NONE }};/* * BeforeExit() is the DLL call from InstallShield. The arguments and * return value as defined by the installer. We are only interested * in the install directory, szInst. Return 0 on error and 1 on * success (!?). */CHAR WINAPI BeforeExit(HWND hwnd, LPSTR szSrcDir, LPSTR szSupport, LPSTR szInst, LPSTR szRes){    ACTIONITEM *pactionItem;    int end = 0;    FillInReplaceTable(hwnd, replaceHttpd, szInst);    pactionItem = actionTable;    while (!end) {	switch(pactionItem->command) {	case CMD_END:	    end = 1;	    break;	case CMD_COPY:	    if (ExpandConfFile(hwnd, szInst, 			       pactionItem->in, 			       pactionItem->out,			       replaceHttpd,			       pactionItem->options) < 0) {		/* Error has already been reported to the user */		return 0;	    }	    break;	case CMD_RM: {	    char inFile[MAX_INPUT_LINE];	    sprintf(inFile, "%s\\%s", szInst, pactionItem->in);	    if (unlink(inFile) < 0 && !(pactionItem->options & OPT_SILENT)) {		MessageBox_error(hwnd, AP_WIN32ERROR, "Error during configuration",		    MB_ICONHAND,		    "Could not remove file %s", 		    inFile);		return 0;	    }	    break;	}	case CMD_RMDIR: {	    char inFile[MAX_INPUT_LINE];	    sprintf(inFile, "%s\\%s", szInst, pactionItem->in);	    if (rmdir(inFile) < 0) {		MessageBox_error(hwnd, AP_WIN32ERROR, "Error during configuration",		    MB_ICONHAND,		    "Could not delete temporary directory %s", 		    inFile);		return 0;	    }	    break;	}	default:	    MessageBox_error(hwnd, 0, "Error during configuration",		    MB_ICONHAND,		    "An error has occurred during configuration\r"		    "(Error: unknown command %d)", (int)pactionItem->command);	    end = 1;	    break;	}	pactionItem++;    }    return 1;}BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved){    if (fdwReason == DLL_PROCESS_ATTACH)	hInstance = hInstDLL;    return TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -