Adds Javascript entry page into wizard (Bugscape #11290)

This commit is contained in:
mitchf%netscape.com 2002-01-11 19:33:33 +00:00
parent 9984cd8b61
commit abc3cffdd1
2 changed files with 290 additions and 2 deletions

View File

@ -357,7 +357,7 @@ BOOL CWizardUI::OnCommand(WPARAM wParam, LPARAM lParam)
WIDGET* curWidget = CurrentNode->pageWidgets[i];
if (curWidget->widgetID != nID)
continue;
if (curWidget->type == "EditBox")
if (curWidget->type == "EditBox" || curWidget->type == "JSEditBox")
{
if (wNotifyCode == EN_KILLFOCUS)
if(((CEdit*)curWidget->control)->GetModify())
@ -573,6 +573,38 @@ void CWizardUI::UpdateScreenWidget(WIDGET *curWidget)
{
}
else if(curWidget->type == "JSEditBox")
{
CEdit *pEditCtl = ((CEdit*)curWidget->control);
pEditCtl->SetSel(0,-1);
pEditCtl->Clear();
CString rootPath = GetGlobal("Root");
CString configName = GetGlobal("CustomizationList");
CString localJavaScriptFile = rootPath + "Configs\\" + configName + "\\" + curWidget->attrib;
if (theApp.FileExists(localJavaScriptFile))
{
CStdioFile sf(localJavaScriptFile,CFile::modeRead | CFile::typeText);
CString strLine;
while (sf.ReadString(strLine))
{
strLine+="\r\n";
int len=pEditCtl->GetWindowTextLength();
pEditCtl->SetSel(len,len);
pEditCtl->ReplaceSel(strLine);
}
sf.Close();
// place cursor at top
pEditCtl->SetSel(-1,-1,FALSE);
} // local JS file exists
} // JSEditBox
}
void CWizardUI::CreateControls()
@ -662,6 +694,20 @@ void CWizardUI::CreateControls()
((CEdit*)curWidget->control)->SetModify(FALSE);
}
}
else if (widgetType == "JSEditBox")
{
curWidget->control = new CEdit;//Added new style parameter ES_AUTOHSCROLL- to allow *GASP* SCROLLING!!
if (rv = ((CEdit*)curWidget->control)->CreateEx(WS_EX_CLIENTEDGE,
_T("EDIT"),
NULL,
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER |ES_AUTOHSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL,
tmpRect,this, ID, 0 ))
{
//Set maximum number of characters allowed per line - limit set to 200
((CEdit*)curWidget->control)->SetWindowText(curWidget->value);
((CEdit*)curWidget->control)->SetModify(FALSE);
}
}
else if (widgetType == "Button") {
curWidget->control = new CButton;
rv = ((CButton*)curWidget->control)->Create(curWidget->value, BS_PUSHBUTTON | WS_TABSTOP, tmpRect, this, ID);
@ -1035,13 +1081,19 @@ CString CWizardUI::GetScreenValue(WIDGET *curWidget)
rv = CString(temp);
}
else if (widgetType == "EditBox") {
else if (widgetType == "EditBox"
{
char myLine[MAX_SIZE];
curWidget->control->GetWindowText(myLine, 250);
CString line = (CString)myLine;
rv = line;
}
else if (widgetType == "JSEditBox")
{
}
else if (widgetType == "ListBox")
{
LPINT choices;
@ -1175,7 +1227,50 @@ void CWizardUI::UpdateGlobals()
((CPrefEditView*)curWidget->control)->DoSavePrefsTree(localPrefsFile);
}
else if (curWidget->type == "JSEditBox")
{
CString rootPath = GetGlobal("Root");
CString configName = GetGlobal("CustomizationList");
CString localJavaScriptFile = rootPath + "Configs\\" + configName + "\\" + curWidget->attrib;
// save it to the file, simple text mode
CEdit *pJSEB = (CEdit *)curWidget->control;
CString strText;
if (pJSEB->GetModify())
{
FILE* fp = fopen(localJavaScriptFile, "wt");
int nLineCount, nLineLength;
if (fp)
{
nLineCount = pJSEB->GetLineCount();
for (i=0;i < nLineCount;i++)
{
nLineLength = pJSEB->GetLine(i, strText.GetBuffer(512),1024);
strText.ReleaseBuffer(nLineLength);
if (nLineLength)
{
if (!fwrite(strText, 1, nLineLength, fp))
break;
fwrite("\n",1,1,fp);
}
} // line loop
fclose(fp);
} // file open okay
} // edit control modified
} // JSEditBox
}
IsNewValue = TRUE;
}

View File

@ -380,6 +380,7 @@ void AddPref(CString xpifile, CString entity, CString newvalue, BOOL bUseQuotes,
int ModifyJS(CString xpifile, CString entity, CString newvalue, BOOL bLockPref)
{
int rv = TRUE;
CString newfile = xpifile + ".new";
char *fgetsrv;
@ -858,6 +859,170 @@ BOOL ProcessPrefsTree(CString strPrefsTreeFile, CString strPrefFile, CString str
}
BOOL ModifyUserJS(CString HashedPrefsFile, CString jsSourceFile)
{
// Unhash the prefs file to a plain text file. If there is no hashed file yet,
// create a plaintext file with only a comment.
CString PlainTextPrefsFile = HashedPrefsFile + ".js";
if (FileExists(HashedPrefsFile))
{
if (!UnHash(HashedPrefsFile, PlainTextPrefsFile))
return FALSE;
}
else
{
// Create a plain text prefs with only a comment.
CreateNewFile(PlainTextPrefsFile, "/* protected prefs */\n");
}
// find the block and replace it with the contents of the source file
CString newPrefsFile = PlainTextPrefsFile + ".new";
// Read in all.js file and make substitutions
CStdioFile srcJSC;
FILE* destJSC = fopen(newPrefsFile, "w");
if (srcJSC.Open(PlainTextPrefsFile,CFile::modeRead | CFile::typeText) && destJSC)
{
CString strLine;
bool bInJSBlock = FALSE;
bool bInsertUserJSNow = FALSE;
bool bDroppedPayload = FALSE;
int iBraceLevel = 0; // these are in case cfg file has braces
bool bPastFirstBrace = FALSE;
while (srcJSC.ReadString(strLine))
{
strLine += "\n";
// count braces
/*
char buffer[4096];
strcpy(buffer,strLine);
char *token = strtok( buffer, "{");
while( token != NULL )
{
bPastFirstBrace = TRUE;
iBraceLevel++;
token = strtok(NULL,"{");
}
strcpy(buffer,strLine);
token = strtok( buffer, "}");
while( token != NULL )
{
iBraceLevel--;
token = strtok(NULL,"}");
}
if (bPastFirstBrace && iBraceLevel < 1)
bInsertUserJSNow = TRUE;
*/
// looking for //ADMJS_BEG (ADM JavaScript Begin)
// or //ADMJS_END (ADM JavaScript End) which must be on a line by themselves
int len = strLine.GetLength();
if ( strLine.GetLength() > 10
&& strLine[0] == '/'
&& strLine[1] == '/')
{
CString str = strLine.Left(6);
if (str.CompareNoCase("\n\n//ADMJS_BEG\n") == 0)
{
bInsertUserJSNow = TRUE;
bInJSBlock = TRUE;
}
else if (str.CompareNoCase("//ADMJS_END\n") == 0)
bInJSBlock = FALSE;
}
// drop our payload
//
if (bInsertUserJSNow)
{
CStdioFile srcJS;
CString strJSLine;
fputs(strLine,destJSC); // write out "//ADMJS_BEG"
if (srcJS.Open(jsSourceFile,CFile::modeRead | CFile::typeText))
{
while (srcJS.ReadString(strJSLine))
{
strJSLine += "\n";
fputs(strJSLine, destJSC);
}
srcJS.Close();
}
bInsertUserJSNow = FALSE;
bDroppedPayload = TRUE;
}
else
{
fputs(strLine,destJSC); // drop whatever line we have
}
} // while source lines
if (!bDroppedPayload)
{
CStdioFile srcJS;
CString strJSLine;
strJSLine = "\n\n//ADMJS_BEG\n";
fputs(strJSLine,destJSC);
if (srcJS.Open(jsSourceFile,CFile::modeRead | CFile::typeText))
{
while (srcJS.ReadString(strJSLine))
{
strJSLine += "\n";
fputs(strJSLine, destJSC);
}
srcJS.Close();
}
strJSLine = "//ADMJS_END\n";
fputs(strJSLine,destJSC);
}
srcJSC.Close();
fclose(destJSC);
} // if can open source file
// delete orig and rename new file to correct name
remove(PlainTextPrefsFile);
rename(newPrefsFile, PlainTextPrefsFile);
// And rehash it.
if (!Hash(PlainTextPrefsFile, HashedPrefsFile))
return FALSE;
return TRUE;
}
int interpret(char *cmd)
{
char *cmdname = strtok(cmd, "(");
@ -1106,6 +1271,32 @@ int interpret(char *cmd)
ConvertToRemoteAdmin(url, prefFile, remoteAdminFile);
}
else if (strcmp(cmdname, "modifyUserJS") == 0)
{
// modifyUserJS(XPIname, fileWithinXPI, JSsourcefile) // within XPI
// modifyUserJS(browser.xpi, bin, jsedit.jsc) // example
// modifyUserJS(none, pathAndFilename, JSsourcefile) // normal file
// modifyUserJS(none, \autoadmin\test.jsc, jsedit.jsc) // example
char *xpiname = strtok(NULL, ",)");
char *filename = strtok(NULL, ",)");
char *jssource = strtok(NULL, ",)");
CString jsSourceFile = configPath + "\\" + jssource;
// pull the cfg file out of the XPI
//
ExtractXPIFile(xpiname, filename);
// replace the appropriate block of javascript
//
ModifyUserJS(filename, jsSourceFile);
// cfg file gets repackaged with call to ReplaceXPIFiles in StartIB after all the interpret calls,
// so no need to repacked it ourself.
}
else
return FALSE;//*** We have to handle this condition better.
@ -1658,6 +1849,8 @@ int StartIB(/*CString parms, WIDGET *curWidget*/)
templinuxDir = "tempLinux";
tarfile = "netscape-i686-pc-linux-gnu-sea.tar.gz";
// AfxMessageBox("set breakpoint",MB_OK);
if (SearchPath(workspacePath, "NSCPXPI", NULL, 0, NULL, NULL))
nscpxpiPath = workspacePath + "\\NSCPXPI";
else