]>
Commit | Line | Data |
---|---|---|
6ab5e82f BS |
1 | /* $Id$ */ |
2 | ||
3 | /* | |
4 | * include.c (c) 1998,1999 Brian Smith | |
5 | */ | |
6 | ||
7 | #include <stdlib.h> | |
8 | #include <stdio.h> | |
9 | #include <conio.h> | |
10 | #include <io.h> | |
11 | #include <sys/types.h> | |
12 | #include <sys/stat.h> | |
13 | #include <string.h> | |
14 | ||
15 | extern int files; | |
16 | ||
17 | FILE *cfgfile, *installfile; | |
18 | char *INSTALLER_APPLICATION; | |
19 | char *INSTALLER_VERSION; | |
20 | char *INSTALLER_TITLE; | |
21 | char *INSTALLER_PATH; | |
22 | char *INSTALLER_FOLDER; | |
23 | char *INSTALLER_PROGRAM; | |
24 | char *INSTALLER_SHADOW; | |
25 | char *INSTALLER_OBJECT; | |
26 | char *INSTALLER_SETS; | |
27 | char *INSTALLER_SYSVAR; | |
28 | char *INSTALLER_SYSLINE; | |
29 | char *INSTALLER_PACKAGES[20]; | |
30 | char *INSTALLER_CONFIRM_WPS; | |
31 | char *INSTALLER_CONFIRM_CONFIGSYS; | |
32 | char *INSTALLER_CONFIRM_OVERWRITE; | |
33 | int INSTALLER_BITMAP_WIDTH; | |
34 | int INSTALLER_BITMAP_HEIGHT; | |
35 | int INSTALLER_PACKAGE_COUNT=0; | |
36 | ||
37 | int packagefiles[20]; | |
38 | char *packagefilename[20]; | |
39 | ||
40 | void resetglobals(void); | |
41 | ||
42 | int include_unpack(char *aname); | |
43 | ||
44 | void append_file(char *filename) | |
45 | { | |
95f99113 BS |
46 | FILE *appendfile; |
47 | int amnt; | |
48 | char buffer[512]; | |
49 | ||
50 | if((appendfile = fopen(filename, "rb"))==NULL) | |
51 | { | |
52 | printf("Error opening %s for reading!\n", filename); | |
53 | exit(3); | |
54 | } | |
55 | while(!feof(appendfile)) | |
56 | { | |
57 | amnt = fread(buffer, 1, 512, appendfile); | |
58 | fwrite(buffer, 1, amnt, installfile); | |
59 | } | |
60 | fclose(appendfile); | |
6ab5e82f BS |
61 | } |
62 | ||
63 | void getline(FILE *f, char *entry, char *entrydata) | |
64 | { | |
95f99113 BS |
65 | char in[4096]; |
66 | int z; | |
67 | ||
68 | memset(in, 0, 4096); | |
69 | fgets(in, 4095, f); | |
70 | ||
71 | if(in[strlen(in)-1] == '\n') | |
72 | in[strlen(in)-1] = 0; | |
73 | ||
74 | if(in[0] != '#') | |
75 | { | |
76 | for(z=0;z<strlen(in);z++) | |
77 | { | |
78 | if(in[z] == '=') | |
79 | { | |
80 | in[z] = 0; | |
81 | strcpy(entry, in); | |
82 | strcpy(entrydata, &in[z+1]); | |
83 | return; | |
84 | } | |
85 | } | |
86 | } | |
87 | strcpy(entry, ""); | |
88 | strcpy(entrydata, ""); | |
6ab5e82f BS |
89 | } |
90 | ||
91 | int main(int argc, char *argv[]) | |
92 | { | |
95f99113 BS |
93 | char entry[8096], entrydata[8096]; |
94 | int z; | |
95 | ||
96 | printf("Packinst- version 2.0 (c) 1999-2000 DBSoft\n\n"); | |
97 | if(argc!=2) | |
98 | { | |
99 | printf("Usage: Packinst <filename.cfg>\n"); | |
100 | exit(1); | |
6ab5e82f | 101 | } |
95f99113 BS |
102 | if((cfgfile = fopen(argv[1], "r"))==NULL) |
103 | { | |
104 | printf("Error opening config file \"%s\"!\n", argv[1]); | |
105 | exit(2); | |
106 | } | |
107 | if((installfile = fopen("install.exe", "wb"))==NULL) | |
108 | { | |
109 | printf("Error opening install.exe for writing!\n"); | |
110 | exit(3); | |
111 | } | |
6ab5e82f | 112 | #if 0 |
95f99113 BS |
113 | printf("Adding resources to sfx.exe...\n"); |
114 | system("rc install.rc sfx.exe > NUL"); | |
6ab5e82f | 115 | #endif |
95f99113 BS |
116 | printf("Creating installer...\n"); |
117 | append_file("sfx.exe"); | |
118 | fwrite("DBSOFT-HEADER", 1, 13, installfile); | |
119 | while(!feof(cfgfile)) | |
120 | { | |
121 | getline(cfgfile, entry, entrydata); | |
122 | if(stricmp(entry, "INSTALLER_APPLICATION") == 0) | |
123 | INSTALLER_APPLICATION = (char *)strdup(entrydata); | |
124 | if(stricmp(entry, "INSTALLER_VERSION") == 0) | |
125 | INSTALLER_VERSION = (char *)strdup(entrydata); | |
126 | if(stricmp(entry, "INSTALLER_TITLE") == 0) | |
127 | INSTALLER_TITLE = (char *)strdup(entrydata); | |
128 | if(stricmp(entry, "INSTALLER_PATH") == 0) | |
129 | INSTALLER_PATH = (char *)strdup(entrydata); | |
130 | if(stricmp(entry, "INSTALLER_FOLDER") == 0) | |
131 | INSTALLER_FOLDER = (char *)strdup(entrydata); | |
132 | if(stricmp(entry, "INSTALLER_PROGRAM") == 0) | |
133 | INSTALLER_PROGRAM = (char *)strdup(entrydata); | |
134 | if(stricmp(entry, "INSTALLER_SHADOW") == 0) | |
135 | INSTALLER_SHADOW = (char *)strdup(entrydata); | |
136 | if(stricmp(entry, "INSTALLER_OBJECT") == 0) | |
137 | INSTALLER_OBJECT = (char *)strdup(entrydata); | |
138 | if(stricmp(entry, "INSTALLER_SETS") == 0) | |
139 | INSTALLER_SETS = (char *)strdup(entrydata); | |
140 | if(stricmp(entry, "INSTALLER_SYSVAR") == 0) | |
141 | INSTALLER_SYSVAR = (char *)strdup(entrydata); | |
142 | if(stricmp(entry, "INSTALLER_SYSLINE") == 0) | |
143 | INSTALLER_SYSLINE = (char *)strdup(entrydata); | |
144 | if(stricmp(entry, "INSTALLER_CONFIRM_WPS") == 0) | |
145 | INSTALLER_CONFIRM_WPS = (char *)strdup(entrydata); | |
146 | if(stricmp(entry, "INSTALLER_CONFIRM_CONFIGSYS") == 0) | |
147 | INSTALLER_CONFIRM_CONFIGSYS = (char *)strdup(entrydata); | |
148 | if(stricmp(entry, "INSTALLER_CONFIRM_OVERWRITE") == 0) | |
149 | INSTALLER_CONFIRM_OVERWRITE = (char *)strdup(entrydata); | |
150 | if(stricmp(entry, "INSTALLER_PACKAGE") == 0) | |
151 | { | |
152 | for(z=0;z<strlen(entrydata);z++) | |
153 | { | |
154 | if(entrydata[z] == ',') | |
155 | { | |
156 | entrydata[z] = 0; | |
157 | packagefilename[INSTALLER_PACKAGE_COUNT] = (char *)strdup(entrydata); | |
158 | INSTALLER_PACKAGES[INSTALLER_PACKAGE_COUNT] = (char *)strdup(&entrydata[z+1]); | |
159 | } | |
160 | } | |
161 | resetglobals(); | |
162 | files=0; | |
163 | include_unpack(packagefilename[INSTALLER_PACKAGE_COUNT]); | |
164 | packagefiles[INSTALLER_PACKAGE_COUNT] = files; | |
165 | INSTALLER_PACKAGE_COUNT++; | |
166 | } | |
167 | } | |
168 | fclose(cfgfile); | |
169 | fprintf(installfile, "%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%d", | |
170 | INSTALLER_APPLICATION, INSTALLER_VERSION, INSTALLER_TITLE, | |
171 | INSTALLER_PATH, INSTALLER_FOLDER, INSTALLER_PROGRAM, | |
172 | INSTALLER_SHADOW, INSTALLER_OBJECT, INSTALLER_SETS, INSTALLER_SYSVAR, | |
173 | INSTALLER_SYSLINE, INSTALLER_CONFIRM_WPS, INSTALLER_CONFIRM_CONFIGSYS, | |
174 | INSTALLER_CONFIRM_OVERWRITE, INSTALLER_PACKAGE_COUNT); | |
175 | for(z=0;z<INSTALLER_PACKAGE_COUNT;z++) | |
176 | fprintf(installfile, "-%s", INSTALLER_PACKAGES[z]); | |
177 | fwrite("*", 1, 1, installfile); | |
178 | for(z=0;z<INSTALLER_PACKAGE_COUNT;z++) | |
179 | { | |
180 | struct stat blah; | |
181 | ||
182 | stat(packagefilename[z], &blah); | |
183 | fprintf(installfile, "DBSOFT-ACE%d%d-%lu*", z, packagefiles[z], blah.st_size); | |
184 | append_file(packagefilename[z]); | |
185 | printf("Package: %s - %d files in %s (%lu bytes).\n", INSTALLER_PACKAGES[z], packagefiles[z], packagefilename[z], blah.st_size); | |
186 | } | |
187 | fclose(installfile); | |
188 | fclose(cfgfile); | |
189 | return 0; | |
190 | } |