From 42f6bac3db462a041d0bec29112ce35bc732a6e3 Mon Sep 17 00:00:00 2001 From: "sgehani%netscape.com" Date: Thu, 10 Feb 2000 10:04:18 +0000 Subject: [PATCH] Added random install feature to deteremine component pre-selection at parse time. b = 24299 r = ssu --- xpinstall/wizard/mac/src/MacInstallWizard.h | 3 ++ xpinstall/wizard/mac/src/Parser.c | 57 +++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/xpinstall/wizard/mac/src/MacInstallWizard.h b/xpinstall/wizard/mac/src/MacInstallWizard.h index 804d350630cd..7bec1837fd89 100644 --- a/xpinstall/wizard/mac/src/MacInstallWizard.h +++ b/xpinstall/wizard/mac/src/MacInstallWizard.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -257,6 +258,7 @@ if (err) \ #define sAttributes 25 #define sURL 26 #define sDependency 31 +#define sRandomInstall 34 #define sTermDlg 27 @@ -460,6 +462,7 @@ OSErr PopulateCompWinKeys(char *); OSErr PopulateTermWinKeys(char *); OSErr PopulateIDIKeys(char *); OSErr MapDependencies(void); +Boolean RandomSelect(long); short GetComponentIndex(Handle); Boolean FillKeyValueForIDIKey(short, Handle, char *); Boolean FillKeyValueUsingResID(short, short, Handle, char *); diff --git a/xpinstall/wizard/mac/src/Parser.c b/xpinstall/wizard/mac/src/Parser.c index 8406c79afee6..fff5b3fc1412 100644 --- a/xpinstall/wizard/mac/src/Parser.c +++ b/xpinstall/wizard/mac/src/Parser.c @@ -233,6 +233,8 @@ PopulateCompWinKeys(char *cfgText) Str255 pSName, pkey, pidx; char eof[1]; char *currDepNum; + long randomPercent; + Boolean bRandomSet; eof[0] = 0; @@ -313,6 +315,34 @@ PopulateCompWinKeys(char *cfgText) DisposeHandle(sizeH); DisposePtr(currKey); + /* random install percentage */ + GetIndString(pkey, rParseKeys, sRandomInstall); + currKey = PascalToC(pkey); + Handle randomH = NewHandleClear(4); + if (FillKeyValueUsingName(currSName, currKey, randomH, cfgText)) + { + bRandomSet = true; + HLock(randomH); + randomPercent = atol(*randomH); + HUnlock(randomH); + + if (randomPercent != 0) /* idiot proof for those giving 0 as the rand percent */ + { + if (RandomSelect(randomPercent)) + gControls->cfg->comp[i].selected = true; + else + gControls->cfg->comp[i].selected = false; + } + else + bRandomSet = false; + } + else + bRandomSet = false; + if (randomH) + DisposeHandle(randomH); + if (currKey) + DisposePtr(currKey); + /* attributes (SELECTED|INVISIBLE|LAUNCHAPP) */ GetIndString(pkey, rParseKeys, sAttributes); currKey = PascalToC(pkey); @@ -324,10 +354,13 @@ PopulateCompWinKeys(char *cfgText) char *attrType = NULL; GetIndString(pkey, rParseKeys, sSELECTED); attrType = PascalToC(pkey); - if (NULL != strstr(*attrValH, attrType)) - gControls->cfg->comp[i].selected = true; - else - gControls->cfg->comp[i].selected = false; + if (!bRandomSet) /* when random key specified then selected attr is overriden */ + { + if (NULL != strstr(*attrValH, attrType)) + gControls->cfg->comp[i].selected = true; + else + gControls->cfg->comp[i].selected = false; + } if (attrType) DisposePtr(attrType); @@ -610,6 +643,22 @@ MapDependencies() return err; } +Boolean +RandomSelect(long percent) +{ + Boolean bSelect = false; + int arbitrary = 0; + + srand(time(NULL)); + arbitrary = rand(); + arbitrary %= 100; + + if (arbitrary <= percent) + bSelect = true; + + return bSelect; +} + short GetComponentIndex(Handle compName) {