1999-10-23 04:10:24 +04:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include <Winbase.h>
|
1999-11-03 04:51:54 +03:00
|
|
|
#include <direct.h>
|
1999-10-23 04:10:24 +04:00
|
|
|
#include "globals.h"
|
1999-11-05 03:36:17 +03:00
|
|
|
#include "comp.h"
|
1999-11-03 04:51:54 +03:00
|
|
|
#include "ib.h"
|
1999-10-23 04:10:24 +04:00
|
|
|
|
|
|
|
#define MAX_SIZE 1024
|
|
|
|
|
1999-11-03 04:51:54 +03:00
|
|
|
int interpret(char *cmd);
|
|
|
|
|
|
|
|
CString rootPath;
|
|
|
|
CString configName;
|
|
|
|
CString configPath;
|
|
|
|
CString workspacePath;
|
|
|
|
CString cdPath;
|
|
|
|
CString tempPath;
|
1999-11-06 03:04:08 +03:00
|
|
|
CString iniDstPath;
|
|
|
|
CString iniSrcPath;
|
1999-11-03 04:51:54 +03:00
|
|
|
CString scriptPath;
|
|
|
|
CString nscpxpiPath;
|
|
|
|
|
|
|
|
char buffer[50000];
|
|
|
|
XPI xpiList[100];
|
|
|
|
int xpiLen = -1;
|
|
|
|
|
1999-11-05 22:18:33 +03:00
|
|
|
COMPONENT Components[100];
|
1999-11-05 03:36:17 +03:00
|
|
|
int numComponents;
|
|
|
|
|
1999-11-03 04:51:54 +03:00
|
|
|
int findXPI(CString xpiname, CString filename)
|
|
|
|
{
|
|
|
|
int found = FALSE;
|
|
|
|
|
|
|
|
for (int i=0; !found && i<=xpiLen; i++)
|
|
|
|
if (xpiList[i].xpiname == xpiname &&
|
|
|
|
xpiList[i].filename == filename)
|
|
|
|
found = TRUE;
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
xpiLen++;
|
|
|
|
xpiList[xpiLen].xpiname = xpiname;
|
|
|
|
xpiList[xpiLen].filename = filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ExtractXPIFile(CString xpiname, CString xpifile)
|
|
|
|
{
|
|
|
|
CString command;
|
|
|
|
|
|
|
|
if (findXPI(xpiname, xpifile))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
// Can use -d instead of change CWD???
|
|
|
|
CString xpiArchive = nscpxpiPath + "\\" + xpiname;
|
|
|
|
command = rootPath + "unzip.exe -o" + " " + xpiArchive + " " + xpifile;
|
|
|
|
ExecuteCommand((char *)(LPCTSTR) command, SW_HIDE, INFINITE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReplaceXPIFiles()
|
|
|
|
{
|
|
|
|
CString command;
|
|
|
|
CString xpiArchive;
|
|
|
|
CString xpiArcDest;
|
|
|
|
|
|
|
|
// Go through the whole list putting them into the archives
|
|
|
|
for (int i=0; i<=xpiLen; i++)
|
|
|
|
{
|
|
|
|
// This copy preserves the existing archive if it exists - do we
|
|
|
|
// need to delete it the first time through?
|
|
|
|
xpiArchive = nscpxpiPath + "\\" + xpiList[i].xpiname;
|
|
|
|
xpiArcDest = cdPath + "\\" + xpiList[i].xpiname;
|
|
|
|
if (!CopyFile(xpiArchive, xpiArcDest, TRUE))
|
|
|
|
DWORD e = GetLastError();
|
|
|
|
|
|
|
|
command = rootPath + "zip.exe -m " + xpiArcDest + " " + xpiList[i].filename;
|
|
|
|
ExecuteCommand((char *)(LPCTSTR) command, SW_HIDE, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ReplaceINIFile()
|
|
|
|
{
|
|
|
|
CString command;
|
|
|
|
CString exeName("Seamonkey32e.exe");
|
|
|
|
char olddir[1024];
|
|
|
|
|
|
|
|
GetCurrentDirectory(sizeof(olddir), olddir);
|
|
|
|
|
|
|
|
if(SetCurrentDirectory((char *)(LPCTSTR) cdPath) == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
CString Src = nscpxpiPath + exeName;
|
|
|
|
CString Dst = cdPath + exeName;
|
|
|
|
if (!CopyFile(Src, Dst, TRUE))
|
|
|
|
DWORD e = GetLastError();
|
|
|
|
|
|
|
|
command = rootPath + "nszip.exe " + exeName + " config.ini";
|
|
|
|
ExecuteCommand((char *)(LPCTSTR) command, SW_SHOW, INFINITE);
|
|
|
|
|
|
|
|
SetCurrentDirectory(olddir);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModifyEntity(char *buffer, CString entity, CString newvalue)
|
|
|
|
{
|
|
|
|
CString buf(buffer);
|
|
|
|
entity = entity + " "; // Ensure we don't get false matches
|
|
|
|
|
|
|
|
int i = buf.Find(entity);
|
|
|
|
if (i == -1) return;
|
|
|
|
|
|
|
|
i = buf.Find('"', i+1);
|
|
|
|
if (i == -1) return;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
int j = buf.Find('"', i);
|
|
|
|
if (j == -1) return;
|
|
|
|
j--;
|
|
|
|
|
|
|
|
buf.Delete(i, j-i+1);
|
|
|
|
buf.Insert(i, newvalue);
|
|
|
|
|
|
|
|
strcpy(buffer, (char *)(LPCTSTR) buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ModifyDTD(CString xpifile, CString entity, CString newvalue)
|
|
|
|
{
|
|
|
|
CString newfile = xpifile + ".new";
|
|
|
|
int rv = TRUE;
|
|
|
|
char *fgetsrv;
|
|
|
|
|
|
|
|
// Read in DTD file and make substitutions
|
|
|
|
FILE *srcf = fopen(xpifile, "r");
|
|
|
|
FILE *dstf = fopen(newfile, "w");
|
|
|
|
if (!srcf)
|
|
|
|
rv = FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int done = FALSE;
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
fgetsrv = fgets(buffer, sizeof(buffer), srcf);
|
|
|
|
done = feof(srcf);
|
|
|
|
if (!done)
|
|
|
|
{
|
|
|
|
if (!fgetsrv || ferror(srcf))
|
|
|
|
{
|
|
|
|
rv = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ModifyEntity(buffer, entity, newvalue);
|
|
|
|
fputs(buffer, dstf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(srcf);
|
|
|
|
fclose(dstf);
|
|
|
|
}
|
|
|
|
|
|
|
|
remove(xpifile);
|
|
|
|
rename(newfile, xpifile);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int interpret(char *cmd)
|
|
|
|
{
|
|
|
|
char *cmdname = strtok(cmd, "(");
|
|
|
|
|
|
|
|
if (strcmp(cmdname, "configure") == 0)
|
|
|
|
{
|
|
|
|
char temp[1024];
|
|
|
|
char *section = strtok(NULL, ",)");
|
|
|
|
char *key = strtok(NULL, ",)");
|
|
|
|
char *value = strtok(NULL, ",)");
|
|
|
|
char *newvalue = value;
|
|
|
|
if (value[0] == '%')
|
|
|
|
{
|
|
|
|
value++;
|
|
|
|
char *t = strchr(value, '%');
|
|
|
|
if (!t)
|
|
|
|
return FALSE;
|
|
|
|
*t = '\0';
|
|
|
|
newvalue = (char *)(LPCTSTR) GetGlobal(value);
|
|
|
|
}
|
|
|
|
if (!section || !key || !newvalue)
|
|
|
|
return FALSE;
|
1999-11-06 03:04:08 +03:00
|
|
|
if (!CopyFile(iniSrcPath, iniDstPath, TRUE))
|
1999-11-03 04:51:54 +03:00
|
|
|
DWORD e = GetLastError();
|
|
|
|
if (strcmp(key, "Program Folder Name") == 0)
|
|
|
|
{
|
|
|
|
strcpy(temp, "Netscape by ");
|
|
|
|
strcat(temp, newvalue);
|
|
|
|
newvalue = temp;
|
|
|
|
}
|
1999-11-06 03:04:08 +03:00
|
|
|
WritePrivateProfileString(section, key, newvalue, iniDstPath);
|
1999-11-03 04:51:54 +03:00
|
|
|
}
|
|
|
|
else if (strcmp(cmdname, "replaceXPI") == 0)
|
|
|
|
{
|
|
|
|
char *xpiname = strtok(NULL, ",)");
|
|
|
|
char *xpifile = strtok(NULL, ",)");
|
|
|
|
char *value = strtok(NULL, ",)");
|
|
|
|
char *newvalue = value;
|
|
|
|
if (value[0] == '%')
|
|
|
|
{
|
|
|
|
value++;
|
|
|
|
char *t = strchr(value, '%');
|
|
|
|
if (!t)
|
|
|
|
return FALSE;
|
|
|
|
*t = '\0';
|
|
|
|
newvalue = (char *)(LPCTSTR) GetGlobal(value);
|
|
|
|
}
|
|
|
|
if (!xpiname || !xpifile || !newvalue)
|
|
|
|
return FALSE;
|
|
|
|
ExtractXPIFile(xpiname, xpifile);
|
|
|
|
if (!CopyFile(newvalue, xpifile, FALSE))
|
|
|
|
{
|
|
|
|
DWORD e = GetLastError();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(cmdname, "modifyDTD") == 0)
|
|
|
|
{
|
|
|
|
char *xpiname = strtok(NULL, ",)");
|
|
|
|
char *xpifile = strtok(NULL, ",)");
|
|
|
|
char *entity = strtok(NULL, ",)");
|
|
|
|
char *value = strtok(NULL, ",)");
|
|
|
|
char *newvalue = value;
|
|
|
|
if (value[0] == '%')
|
|
|
|
{
|
|
|
|
value++;
|
|
|
|
char *t = strchr(value, '%');
|
|
|
|
if (!t)
|
|
|
|
return FALSE;
|
|
|
|
*t = '\0';
|
|
|
|
newvalue = (char *)(LPCTSTR) GetGlobal(value);
|
|
|
|
}
|
|
|
|
if (!xpiname || !xpifile || !entity || !newvalue)
|
|
|
|
return FALSE;
|
|
|
|
ExtractXPIFile(xpiname, xpifile);
|
|
|
|
ModifyDTD(xpifile, entity, newvalue);
|
|
|
|
}
|
|
|
|
else if (strcmp(cmdname, "wrapXPI") == 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-11-05 03:36:17 +03:00
|
|
|
|
|
|
|
void init_components()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
WIDGET *w = findWidget("SelectedComponents");
|
1999-11-06 03:04:08 +03:00
|
|
|
BuildComponentList(Components, &numComponents, iniSrcPath);
|
1999-11-05 03:36:17 +03:00
|
|
|
|
|
|
|
// Turn off components that aren't selected
|
|
|
|
for (i=0; i<numComponents; i++)
|
1999-11-06 03:04:08 +03:00
|
|
|
if (strstr(w->value, Components[i].name) == NULL)
|
1999-11-05 22:18:33 +03:00
|
|
|
Components[i].selected = FALSE;
|
1999-11-05 03:36:17 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-10-23 04:10:24 +04:00
|
|
|
extern "C" __declspec(dllexport)
|
1999-11-04 23:19:27 +03:00
|
|
|
int StartIB(CString parms, WIDGET *curWidget)
|
1999-10-23 04:10:24 +04:00
|
|
|
{
|
1999-11-03 04:51:54 +03:00
|
|
|
char *fgetsrv;
|
|
|
|
int rv = TRUE;
|
|
|
|
char olddir[1024];
|
1999-10-23 04:10:24 +04:00
|
|
|
|
1999-11-03 04:51:54 +03:00
|
|
|
rootPath = GetGlobal("Root");
|
|
|
|
configName = GetGlobal("CustomizationList");
|
|
|
|
configPath = rootPath + "Configs\\" + configName;
|
|
|
|
cdPath = configPath + "\\CD";
|
|
|
|
tempPath = configPath + "\\Temp";
|
1999-11-06 03:04:08 +03:00
|
|
|
iniDstPath = cdPath + "\\config.ini";
|
1999-11-03 04:51:54 +03:00
|
|
|
scriptPath = rootPath + "\\script.ib";
|
|
|
|
workspacePath = configPath + "\\Workspace";
|
|
|
|
if (SearchPath(workspacePath, "NSCPXPI", NULL, 0, NULL, NULL))
|
|
|
|
nscpxpiPath = workspacePath + "\\NSCPXPI";
|
|
|
|
else
|
|
|
|
nscpxpiPath = rootPath + "NSCPXPI";
|
1999-11-06 03:04:08 +03:00
|
|
|
iniSrcPath = nscpxpiPath + "\\config.ini";
|
1999-10-23 04:10:24 +04:00
|
|
|
|
1999-11-05 03:36:17 +03:00
|
|
|
init_components();
|
|
|
|
|
1999-11-03 04:51:54 +03:00
|
|
|
_mkdir((char *)(LPCTSTR) cdPath);
|
|
|
|
_mkdir((char *)(LPCTSTR) tempPath);
|
|
|
|
_mkdir((char *)(LPCTSTR) workspacePath);
|
1999-10-23 04:10:24 +04:00
|
|
|
|
1999-11-03 04:51:54 +03:00
|
|
|
GetCurrentDirectory(sizeof(olddir), olddir);
|
1999-10-23 04:10:24 +04:00
|
|
|
|
1999-11-03 04:51:54 +03:00
|
|
|
if(SetCurrentDirectory((char *)(LPCTSTR) tempPath) == FALSE)
|
|
|
|
return FALSE;
|
1999-10-23 04:10:24 +04:00
|
|
|
|
1999-11-03 04:51:54 +03:00
|
|
|
// Read in script file and interpret commands from it
|
|
|
|
FILE *f = fopen(scriptPath, "r");
|
|
|
|
if (!f)
|
|
|
|
rv = FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int done = FALSE;
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
fgetsrv = fgets(buffer, sizeof(buffer), f);
|
|
|
|
done = feof(f);
|
|
|
|
if (!done)
|
|
|
|
{
|
|
|
|
if (!fgetsrv || ferror(f))
|
|
|
|
{
|
|
|
|
rv = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[strlen(buffer)] = '\0'; // Eliminate the trailing newline
|
|
|
|
|
|
|
|
if (!interpret(buffer))
|
|
|
|
{
|
|
|
|
rv = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put all the extracted files back into their new XPI homes
|
|
|
|
ReplaceXPIFiles();
|
|
|
|
|
|
|
|
// Copy remaining default installer files into config
|
|
|
|
// preserving any existing files that we created already
|
|
|
|
// in previous steps
|
1999-11-05 22:18:33 +03:00
|
|
|
/* -- Need to be more selective than this
|
1999-11-03 04:51:54 +03:00
|
|
|
CopyDir(nscpxpiPath, cdPath, NULL, FALSE);
|
1999-11-05 22:18:33 +03:00
|
|
|
*/
|
|
|
|
for (int i=0; i<numComponents; i++)
|
|
|
|
{
|
|
|
|
if (Components[i].selected)
|
1999-11-06 03:04:08 +03:00
|
|
|
CopyFile(nscpxpiPath + "\\" + Components[i].archive,
|
|
|
|
cdPath + "\\" + Components[i].archive, TRUE);
|
1999-11-05 22:18:33 +03:00
|
|
|
}
|
|
|
|
// Didn't work...
|
1999-11-03 04:51:54 +03:00
|
|
|
|
|
|
|
ReplaceINIFile();
|
|
|
|
|
|
|
|
SetCurrentDirectory(olddir);
|
|
|
|
|
|
|
|
|
|
|
|
return rv;
|
1999-10-23 04:10:24 +04:00
|
|
|
}
|
1999-11-03 04:51:54 +03:00
|
|
|
|