mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 14:25:52 +00:00
Added random install feature to deteremine component pre-selection at parse time.
This commit is contained in:
parent
4d45292f58
commit
42f6bac3db
@ -27,6 +27,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <Navigation.h>
|
||||
#include <MacTypes.h>
|
||||
#include <PLStringFuncs.h>
|
||||
@ -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 *);
|
||||
|
@ -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 (!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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user