Index: Makefile.am =================================================================== RCS file: /cvs/cygwin-apps/setup/Makefile.am,v retrieving revision 2.27 diff -u -3 -p -B -r2.27 Makefile.am --- Makefile.am 10 Mar 2003 15:47:53 -0000 2.27 +++ Makefile.am 7 Apr 2003 08:41:49 -0000 @@ -36,6 +36,7 @@ INCLUDES = -I$(srcdir)/bz2lib -I$(srcdir noinst_PROGRAMS = \ setup \ + setup-config \ @INILINT@ EXTRA_PROGRAMS = inilint @@ -286,6 +287,9 @@ setup_version.c : $(srcdir)/ChangeLog Ma echo 'static const char version_store[] = VERSION_PREFIX " '$$V'";';\ echo 'const char *version = version_store + sizeof (VERSION_PREFIX);') > version.tmp;\ mv version.tmp setup_version.c + +setup_config_SOURCES = customconfig.cc +setup_config_CXXFLAGS = -DTEST %.o: %.rc $(WINDRES) --preprocessor "$(CC) -E -xc-header -DRC_INVOKED" --include-dir $(srcdir) -o $@ $< Index: main.cc =================================================================== RCS file: /cvs/cygwin-apps/setup/main.cc,v retrieving revision 2.25 diff -u -3 -p -B -r2.25 main.cc --- main.cc 28 Feb 2003 23:42:09 -0000 2.25 +++ main.cc 7 Apr 2003 08:41:49 -0000 @@ -46,6 +46,8 @@ static const char *cvsid = #include "proppage.h" #include "propsheet.h" +#include "customconfig.h" + // Page class headers #include "splash.h" #include "AntiVirus.h" @@ -61,6 +63,10 @@ static const char *cvsid = #include "getopt++/GetOption.h" #include "getopt++/BoolOption.h" +#ifdef CUSTOM_CONFIG_SUPPORT +CUSTOM_CONFIG_PARAMS(ccParams); +#endif + int next_dialog; HINSTANCE hinstance; @@ -343,7 +349,10 @@ main (int argc, char **argv) Window::SetAppInstance (hinstance); // Create pages - Splash.Create (); +#ifdef CUSTOM_CONFIG_SUPPORT + if (ccParams.show_splash_screen) +#endif + Splash.Create (); AntiVirus.Create (); Source.Create (); Root.Create (); @@ -355,13 +364,19 @@ main (int argc, char **argv) Desktop.Create (); // Add pages to sheet - MainWindow.AddPage (&Splash); +#ifdef CUSTOM_CONFIG_SUPPORT + if (ccParams.show_splash_screen) +#endif + MainWindow.AddPage (&Splash); MainWindow.AddPage (&AntiVirus); MainWindow.AddPage (&Source); MainWindow.AddPage (&Root); MainWindow.AddPage (&LocalDir); MainWindow.AddPage (&Net); MainWindow.AddPage (&Site); +#ifdef CUSTOM_CONFIG_SUPPORT + if (ccParams.show_chooser_screen) +#endif MainWindow.AddPage (&Chooser); MainWindow.AddPage (&Progress); MainWindow.AddPage (&Desktop); Index: site.cc =================================================================== RCS file: /cvs/cygwin-apps/setup/site.cc,v retrieving revision 2.25 diff -u -3 -p -B -r2.25 site.cc --- site.cc 10 Mar 2003 08:50:16 -0000 2.25 +++ site.cc 7 Apr 2003 08:41:49 -0000 @@ -37,6 +37,7 @@ static const char *cvsid = #include "LogSingleton.h" #include "io_stream.h" #include "site.h" +#include "customconfig.h" #include "port.h" @@ -173,8 +174,13 @@ get_site_list (HINSTANCE h, HWND owner) { char mirror_url[1000]; +#if CUSTOM_CONFIG_SUPPORT + extern CustomConfigParams ccParams; + strcpy(mirror_url,ccParams.mirror_url); +#else if (LoadString (h, IDS_MIRROR_LST, mirror_url, sizeof (mirror_url)) <= 0) return 1; +#endif char *bol, *eol, *nl, *theString; { String mirrors = get_url_to_string (mirror_url, owner); Index: mount.cc =================================================================== RCS file: /cvs/cygwin-apps/setup/mount.cc,v retrieving revision 2.15 diff -u -3 -p -B -r2.15 mount.cc --- mount.cc 15 Jan 2003 22:06:22 -0000 2.15 +++ mount.cc 7 Apr 2003 08:41:49 -0000 @@ -22,7 +22,7 @@ static const char *cvsid = "\n%%% $Id: m #endif #include "win32.h" - +#include "customconfig.h" #include #include @@ -440,7 +440,12 @@ read_mounts () root_scope = (is_admin ())? IDC_ROOT_SYSTEM : IDC_ROOT_USER; GetWindowsDirectory (windir, sizeof (windir)); windir[2] = 0; +#ifdef CUSTOM_CONFIG_SUPPORT + extern CustomConfigParams ccParams; + set_root_dir (String (windir) + ccParams.root_dir); +#else set_root_dir (String (windir) + "\\cygwin"); +#endif m++; } } --- /dev/null 2003-04-07 10:09:56.000000000 +0200 +++ customconfig.h 2003-04-07 10:00:37.000000000 +0200 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2003, Ralf Habacker. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Ralf Habacker + * + */ + +/* + setup customisation support allows generating a partially customized version of + setup.exe through a special helper application named 'setup-config.exe', which + reads the activated customizable parameters or patches the setup.exe binary to + change the customizable parameters. + + Customizable parameters could be added to an application through the + CUSTOM_CONFIG_PARAMS(instance_name) macro, which defines an instance named + 'instance_name' of the CustomConfigParams object. + + + */ + +#ifndef _CUSTOMCONFIG_H_ +#define _CUSTOMCONFIG_H_ + +// enable custom configuration support +#define CUSTOM_CONFIG_SUPPORT 1 + +// +// structure definitions +// +// + +typedef struct { + long magic1,magic2; + long version; + char mirror_url[512]; + char root_dir[512]; + bool show_splash_screen; + bool show_chooser_screen; + // --- add lines ---- +} CustomConfigParams; + + + +// +// default value definitions +// +#define CCP_MAGIC1 0x12345678 +#define CCP_MAGIC2 0x87654321 +#define CCP_VERSION 2 + +// +// use this macro for defining a CustomConfigParams instance +// +#define CUSTOM_CONFIG_PARAMS(name) \ +CustomConfigParams name = { \ + CCP_MAGIC1,CCP_MAGIC2, \ + CCP_VERSION, \ + "http://sources.redhat.com/cygwin/mirrors.lst", /* mirror_url[512] */ \ + "\\cygwin", /* root_dir[512] */ \ + true, /* show_splash_screen */ \ + true, /* show_chooser_screen */ \ +}; + +// +// fragment for printing item list +// +#define CUSTOM_CONFIG_PRINT_ITEMS(f,name) \ + fprintf(f,"CustomConfig (Structure version: %d) {\n",name->version); \ + fprintf(f,"mirror_url=%s\n",name->mirror_url); \ + fprintf(f,"root_dir=%s\n",name->root_dir); \ + fprintf(f,"show_splash_screen=%d\n",name->show_splash_screen ); \ + fprintf(f,"show_chooser_screen=%d\n",name->show_chooser_screen ); \ + fprintf(f,"}\n"); + +// +// fragement for parsing the items from input stream +// +#define CUSTOM_CONFIG_SCAN_ITEMS(f,name) \ + ret = fscanf(f,"CustomConfig (Structure version: %d) {\n",&(name)->version); \ + ret = fscanf(f,"mirror_url=%s\n",&(name)->mirror_url); \ + ret = fscanf(f,"root_dir=%s\n",&(name)->root_dir); \ + ret = fscanf(f,"show_splash_screen=%d\n",&(name)->show_splash_screen ); \ + ret = fscanf(f,"show_chooser_screen=%d\n",&(name)->show_chooser_screen ); + +#endif /* _CUSTOMCONFIG_H_ */ --- /dev/null 2003-04-07 10:10:00.000000000 +0200 +++ customconfig.cc 2003-04-06 21:27:58.000000000 +0200 @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2003, Ralf Habacker. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Ralf Habacker + * + */ +#if 0 +static const char *cvsid = + "\n%%% $Id:$\n"; +#endif + +#include +#include + +#include "customconfig.h" + + + +class CustomConfig { + public: + CustomConfig(char *s,bool verboseMode = false); +// ~CustomConfig(); + bool Print(FILE *f); + bool Set(FILE *f); + bool Set(CustomConfigParams &Params); + protected: + void *mapFile(bool writable); + void unmapFile(); + CustomConfigParams *searchParams(void *lpFileBase); + int Error; + private: + char filename[1024]; + HANDLE hfile; + HANDLE hfilemapping; + bool verbose; +}; + + +CustomConfig::CustomConfig(char *s,bool verboseMode) +{ + strcpy(filename,s); + verbose = verboseMode; +} + +/* +CustomConfig::~CustomConfig() +{ +} +*/ +void *CustomConfig::mapFile(bool writeable) +{ + // open image + hfile = CreateFile(filename, writeable ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0); + if (hfile == INVALID_HANDLE_VALUE) { + Error = 1; + return 0; + } + + HANDLE hfilemapping = CreateFileMapping(hfile, NULL, writeable ? PAGE_READWRITE : PAGE_READONLY , 0, 0, NULL); + if (hfilemapping == 0) + { + CloseHandle(hfile); + Error = 2; + return 0; + } + + void *lpFileBase = MapViewOfFile(hfilemapping, writeable ? FILE_MAP_WRITE : FILE_MAP_READ,0, 0, 0); + if (lpFileBase == 0) + { + CloseHandle(hfilemapping); + CloseHandle(hfile); + Error = 3; + return 0; + } + return lpFileBase; +} + +void CustomConfig::unmapFile() +{ + // FIXME: check valid handles + CloseHandle(hfilemapping); + CloseHandle(hfile); +} + +CustomConfigParams *CustomConfig::searchParams(void *lpFileBase) +{ + if (lpFileBase == 0) + return (CustomConfigParams *)0; + + PIMAGE_DOS_HEADER dosheader = (PIMAGE_DOS_HEADER)lpFileBase; + PIMAGE_NT_HEADERS ntheader = (PIMAGE_NT_HEADERS) ((char *)dosheader + dosheader->e_lfanew); + int lpFileSize = ntheader->OptionalHeader.SizeOfImage; + + // search structure and write params if found in image + for (long *p = (long *)lpFileBase ; p < (long *)((int)lpFileBase+lpFileSize); p++) { + if (*p == CCP_MAGIC1) { + if (*(p+1) == CCP_MAGIC2) + return (CustomConfigParams *)p; + } + } + return (CustomConfigParams *)0; +} + + +bool CustomConfig::Print(FILE *f) +{ + CustomConfigParams *curParams = searchParams(mapFile(false)); + if (curParams) { + CUSTOM_CONFIG_PRINT_ITEMS(f,curParams); + unmapFile(); + return true; + } + else { + fprintf(stderr,"setup-config: could not find config structure in '%s'\n",filename); + return false; + } +} + +bool CustomConfig::Set(CustomConfigParams &Params) +{ + char temp[1024]; + + CustomConfigParams *curParams = searchParams(mapFile(true)); + if (curParams) { + *curParams = Params; + unmapFile(); + return true; + } + else { + fprintf(stderr,"setup-config: could not find config structure in '%s'\n",filename); + return false; + } +} + +bool CustomConfig::Set(FILE *f) +{ + // default values + CUSTOM_CONFIG_PARAMS(ccParams); + int version; + char buf[1024]; + int ret; + CustomConfigParams newParams = ccParams; + + // scan input + if (verbose) { + fprintf(stderr,"parsing input data\n"); + fflush(stderr); + } + + // read the config file + CUSTOM_CONFIG_SCAN_ITEMS(f,&newParams); + + // check version matching for the readed input file + if (ccParams.version != newParams.version ) { + fprintf(stderr,"setup-config: version mismatch error (setup-config=%d input-file=%d)\n",ccParams.version,newParams.version); + exit(1); + } + + if (verbose) { + fprintf(stderr,"reading binary '%s'\n",filename); + fflush(stderr); + } + + // read setup configuration from binary + CustomConfigParams *curParams = searchParams(mapFile(true)); + if (!curParams) { + fprintf(stderr,"setup-config: could not find config structure in '%s'\n",filename); + exit(1); + } + + // check version matching between our application and the targeted binary + if (curParams->version != ccParams.version) { + fprintf(stderr,"setup-config: version mismatch error (setup=%d setup-config=%d)\n",curParams->version,ccParams.version); + exit(1); + } + + + if (verbose) { + fprintf(stderr,"setup new configuration\n"); + fflush(stderr); + } + // set new configuration + *curParams = newParams; + + if (verbose) { + fprintf(stderr,"write back configuration in binary\n"); + fflush(stderr); + } + unmapFile(); + return true; +} + +#ifdef TEST +int main(int argc,char **argv) +{ + char *name; + bool verbose = true; + + if (argc == 3) + name = argv[2]; + else + name = "setup.exe"; + if (argc > 1) { + CustomConfig test(name,verbose); + if (strcmp(argv[1],"-r") == 0) + test.Print(stdout); + if (strcmp(argv[1],"-w") == 0) { + test.Set(stdin); + if (verbose) + test.Print(stdout); + } + } +} +#endif