home *** CD-ROM | disk | FTP | other *** search
- /* Startup Selector */
- /* by OLIVERES Jean-Marc */
- /* (c) 1996 Moonchild Prod. */
- /* 01.02.97 */
-
- OPT REG=3
-
- MODULE 'dos/dos','dos/dostags','dos/dosasl','intuition/intuition',
- 'intuition/screens','gadtools','libraries/gadtools','reqtools',
- 'libraries/reqtools','exec/nodes','exec/lists','amigalib/lists'
-
- ENUM ER_NONE,ER_WIN,ER_DIR,ER_NODIR,ER_SCR,ER_MOUSE,ER_EXAM,ER_REQ,ER_GAD,
- ER_FILE,ER_MEM
- ENUM WBS=1,USER,LVID,RMB,WBSP
-
- RAISE ER_WIN IF OpenWindowTagList()=NIL,
- ER_SCR IF LockPubScreen()=NIL,
- ER_MOUSE IF Mouse()<>1,
- ER_MEM IF New()=NIL
-
- CONST BIGGER=-1,SMALLER=1
-
- DEF ptrwin=NIL:PTR TO window,glist=NIL
- DEF scr=NIL:PTR TO screen,visual,menu
- DEF lv_width,lv_heigth,fic_nbr=0,fic_lng=0
- DEF info:fileinfoblock,dirscan,dirlock
- DEF ch[70]:STRING,count1=0,count2=0,count3=0
- DEF choice1,choice2,choice3
- DEF list=NIL:PTR TO lh,node=NIL:PTR TO ln
- DEF f_hdl,nodename,wbsplus,wbsp_path
-
- PROC main() HANDLE
- DEF mes=NIL:PTR TO intuimessage
- DEF id,gad=NIL:PTR TO gadget,i,userdata,idcmp,item
- DEF seconds=0,micros,seconds2,micros2,sel
- init()
- choicerep()
- nodename:=readlog()
- Mouse()
- scr:=LockPubScreen(NIL)
- visual:=GetVisualInfoA(scr,NIL)
- wbsp_path:='SYS:prefs/WBStartup+Prefs'
- wbsplusprefs()
- IF (scanstartupdir()=0) THEN nofile()
- addstartgadget()
- window()
- createmen()
- REPEAT
- IF mes:=Gt_GetIMsg(ptrwin.userport)
- idcmp:=mes.class
- SELECT idcmp
- CASE IDCMP_MENUPICK
- IF (item:=ItemAddress(menu,mes.code))<>NIL
- id:=Long(item+34)
- IF id=1 THEN req('StartupSelector\n\nVersion 1.2a\n\nCopyright © 1996-97\n\n'+
- '03.03.97\n\nMoonchild Prod.')
- IF id=2 THEN SystemTagList('NewCli',NIL)
- IF id=3
- IF ptrwin THEN CloseW(ptrwin)
- Gt_ReplyIMsg(mes)
- quit()
- ENDIF
- ENDIF
- CASE IDCMP_GADGETUP
- gad:=mes.iaddress
- userdata:=gad.userdata
- SELECT userdata
- CASE USER
- count1:=Not(count1)
- CASE WBS
- count2:=Not(count2)
- CASE RMB
- count3:=Not(count3)
- CASE WBSP
- SystemTagList(wbsp_path,NIL)
- CASE LVID
- CurrentTime({seconds2},{micros2})
- node:=list.head
- FOR i:=1 TO mes.code DO node:=node.succ
- IF seconds=0
- CurrentTime({seconds},{micros})
- sel:=i
- ELSEIF DoubleClick(seconds,micros,seconds2,micros2) AND (sel=i)
- setlog(node.name)
- Gt_ReplyIMsg(mes)
- launchstart(node.name)
- ELSE
- seconds:=0
- CurrentTime({seconds},{micros})
- sel:=i
- ENDIF
- ENDSELECT
- ENDSELECT
- Gt_ReplyIMsg(mes)
- ELSE
- WaitPort(ptrwin.userport)
- ENDIF
- UNTIL idcmp=IDCMP_CLOSEWINDOW
- setlog(nodename)
- launchstart(nodename)
- EXCEPT
- SELECT exception
- CASE ER_WIN ; req('Unable to open window !')
- CASE ER_DIR ; req('Can''t find your directory !')
- CASE ER_NODIR ; req('Not a directory !')
- CASE ER_SCR ; req('Unable to lock Workbench screen !')
- CASE ER_GAD ; req('Can''t open the Gadtools.library !')
- CASE ER_MEM ; req('Not enough memory !')
- CASE ER_MOUSE
- IF count3
- launchstart(nodename)
- ELSE
- StrCopy(ch,dirscan,ALL)
- AddPart(ch,'Startup-Sequence',70)
- IF (dirlock:=Lock(ch,ACCESS_READ))=NIL
- req('No Startup-Sequence !\nPress ''OK'' to load the Workbench')
- SystemTagList({lwb},NIL)
- quit()
- ENDIF
- ENDIF
- launchstart('Startup-Sequence')
- ENDSELECT
- quit()
- ENDPROC
-
- PROC setlog(nodename)
- IF count3
- IF count1 THEN choice1:='Y' ELSE choice1:='N'
- IF count2 THEN choice2:='Y' ELSE choice2:='N'
- writelog(choice1,choice2,'Y',nodename)
- ELSE
- writelog('N','N','N',nodename)
- ENDIF
- ENDPROC
-
- PROC init()
- VOID '$VER:Startup Selector 1.2a (02.03.97) Moonchild Prod.'
- AssignPath('ENV','ENVARC:')
- reqtoolsbase:=OpenLibrary('reqtools.library',37)
- IF (gadtoolsbase:=OpenLibrary('gadtools.library',37))=NIL THEN Raise(ER_GAD)
- Rename({wbsold},{wbs})
- Rename({wbsoldinfo},{wbsinfo})
- Rename({userold},{user})
- ENDPROC
-
- PROC writelog(choice1,choice2,choice3,node)
- f_hdl:=Open({sslog},NEWFILE)
- Write(f_hdl,choice1,StrLen(choice1)+1)
- Write(f_hdl,choice2,StrLen(choice2)+1)
- Write(f_hdl,choice3,StrLen(choice3)+1)
- Write(f_hdl,node,StrLen(node)+1)
- Close(f_hdl)
- ENDPROC
-
- PROC readlog()
- DEF log,f_len
- log:={sslog}
- f_len:=FileLength(log)
- IF f_hdl:=Open(log,OLDFILE)
- choice1:=New(f_len)
- Read(f_hdl,choice1,f_len)
- choice2:=choice1+(StrLen(choice1)+1)
- choice3:=choice1+(StrLen(choice1)+1)+(StrLen(choice2)+1)
- nodename:=choice1+(StrLen(choice1)+1)+(StrLen(choice2)+1)+(StrLen(choice3)+1)
- Close(f_hdl)
- IF OstrCmp(choice1,'Y')=0
- count1:=TRUE
- ENDIF
- IF OstrCmp(choice2,'Y')=0
- count2:=TRUE
- ENDIF
- IF OstrCmp(choice3,'Y')=0
- count3:=TRUE
- ENDIF
- ELSE
- req('''S:startupselector_log'' not found !\nCreating default _log ...\n'+
- 'And starting with it ...')
- writelog('N','N','N','Startup-Sequence')
- ENDIF
- ENDPROC nodename
-
- PROC req(msg)
- IF reqtoolsbase
- RtEZRequestA(msg,'OK',0,0,[RTEZ_FLAGS ,EZREQF_CENTERTEXT,
- RT_REQPOS ,REQPOS_CENTERSCR,
- NIL])
- ELSE
- EasyRequestArgs(NIL,[20,0,'Information...',msg,'OK'],0,NIL)
- ENDIF
- ENDPROC
-
- PROC choicerep()
- DEF myargs:PTR TO LONG,rdargs
- myargs:=[0]
- rdargs:=ReadArgs('PATH/O',myargs,NIL)
- IF myargs[]=0
- dirscan:='S:start/'
- ELSE
- dirscan:=String(StrLen(myargs[0]))
- StrCopy(dirscan,myargs[0])
- ENDIF
- IF rdargs THEN FreeArgs(rdargs)
- ENDPROC
-
- PROC scanstartupdir()
-
- /* faire un tri en fonction de *.info et *.bak. Tant qu'aucune de ces
- possibilités n'est trouvée on envoie à la procedure getstartupname()
- sinon on continue à tester */
-
- DEF result,p_anchor:PTR TO anchorpath,olddir
- p_anchor:=New(SIZEOF anchorpath)
- IF (dirlock:=Lock(dirscan,ACCESS_READ))=NIL THEN Raise(ER_NODIR)
- olddir:=CurrentDir(dirlock)
- result:=MatchFirst('~(#?.info|#?.bak)',p_anchor)
- NEW list
- newList(list)
- WHILE result=0
- INC fic_nbr
- info:=p_anchor.info
- getstartupname(info.filename)
- result:=MatchNext(p_anchor)
- ENDWHILE
- MatchEnd(p_anchor)
- CurrentDir(olddir)
- ENDPROC fic_nbr
-
- PROC nofile()
- req('No script in the directory !\nPress ''OK'' to load the Workbench')
- SystemTagList({lwb},NIL)
- quit()
- ENDPROC
-
- PROC getstartupname(infofilename)
- DEF fic_chaine,length
- DEF fic_chaineUp[30]:STRING,fic_preUp[30]:STRING,fic_finUp[30]:STRING
- DEF newnode:PTR TO ln
-
- length:=StrLen(infofilename)
- fic_chaine:=String(length)
- StrCopy(fic_chaine,infofilename)
- IF length>fic_lng THEN fic_lng:=length
-
- NEW newnode
- newnode.name:=fic_chaine
-
- StrCopy(fic_chaineUp,fic_chaine)
- UpperStr(fic_chaineUp)
- IF fic_nbr>1
- StrCopy(fic_preUp,list.head.name)
- UpperStr(fic_preUp)
- ENDIF
- IF fic_nbr>2
- StrCopy(fic_finUp,list.tailpred.name)
- UpperStr(fic_finUp)
- ENDIF
-
- IF fic_nbr=1
- AddHead(list,newnode)
- ELSEIF OstrCmp(fic_preUp,fic_chaineUp)=BIGGER
- AddHead(list,newnode)
- ELSEIF OstrCmp(fic_finUp,fic_chaineUp)=SMALLER
- AddTail(list,newnode)
- ELSE
- node:=list.head
- WHILE (node:=node.succ)<>NIL
- StrCopy(fic_finUp,node.name)
- UpperStr(fic_finUp)
- IF OstrCmp(fic_finUp,fic_chaineUp)=BIGGER
- Insert(list,newnode,node.pred)
- RETURN
- ENDIF
- ENDWHILE
- ENDIF
- ENDPROC
-
- PROC addstartgadget()
- DEF gadget,wbspname,wbsplen
- gadget:=CreateContext({glist})
- wbspname:='Call WBStartup+ ?'
- wbsplen:=StrLen(wbspname)*8+8
- lv_width:=fic_lng*8+28
- IF fic_nbr<8
- lv_heigth:=8*8+4
- ELSEIF fic_nbr>29
- lv_heigth:=29*8+4
- ELSE
- lv_heigth:=fic_nbr*8+4
- ENDIF
- gadget:=CreateGadgetA(LISTVIEW_KIND,gadget,
- [0,0,lv_width,lv_heigth,0,0,0,0,visual,LVID]:newgadget,
- [GTLV_LABELS,list,GTLV_SELECTED,TRUE,NIL])
- gadget:=CreateGadgetA(CHECKBOX_KIND,gadget,
- [lv_width+2,0,12,12,0,0,0,0,visual,USER]:newgadget,
- [GTCB_CHECKED,count1,NIL])
- gadget:=CreateGadgetA(CHECKBOX_KIND,gadget,
- [lv_width+2,12,12,12,0,0,0,0,visual,WBS]:newgadget,
- [GTCB_CHECKED,count2,NIL])
- gadget:=CreateGadgetA(CHECKBOX_KIND,gadget,
- [lv_width+2,24,12,12,0,0,0,0,visual,RMB]:newgadget,
- [GTCB_CHECKED,count3,NIL])
- IF wbsplus
- gadget:=CreateGadgetA(BUTTON_KIND,gadget,
- [((213-wbsplen)/2)+lv_width,lv_heigth-13,wbsplen,12,
- wbspname,0,0,0,visual,WBSP]:newgadget,NIL)
- ENDIF
- ENDPROC
-
- PROC window()
- DEF widcmp,wflags,rport,beveltags
- DEF w_width,w_left,w_top
- DEF nodenamelen
- nodenamelen:=StrLen(nodename)*8+8
- w_width:=lv_width+213
- w_left:=(scr.width-w_width)/2
- w_top:=(scr.height-lv_heigth)/2
- beveltags:=[GT_VISUALINFO,visual,GTBB_FRAMETYPE,BBFT_BUTTON,NIL]
- widcmp:=IDCMP_CLOSEWINDOW OR IDCMP_GADGETUP OR IDCMP_MENUPICK OR LISTVIEWIDCMP
- wflags:=WFLG_CLOSEGADGET+WFLG_DRAGBAR+WFLG_GIMMEZEROZERO+WFLG_NEWLOOKMENUS
- ptrwin:=OpenWindowTagList(NIL,[WA_TITLE ,'Startup-Selector 1.2a',
- WA_GADGETS ,glist,
- WA_LEFT ,w_left,
- WA_TOP ,w_top,
- WA_INNERWIDTH ,w_width,
- WA_INNERHEIGHT ,lv_heigth,
- WA_IDCMP ,widcmp,
- WA_FLAGS ,wflags,
- WA_AUTOADJUST ,-1,
- WA_ACTIVATE ,-1,
- NIL])
- Gt_RefreshWindow(ptrwin,NIL)
- SetStdRast(ptrwin.rport)
- rport:=ptrwin.rport
- SetAPen(rport,2)
- TextF(lv_width+32,8,'Disable User-Startup ?')
- TextF(lv_width+32,20,'Disable WBStartup ?')
- TextF(lv_width+32,32,'Save settings ?')
- DrawBevelBoxA(rport,lv_width+29,0,184,11,beveltags)
- DrawBevelBoxA(rport,lv_width+29,12,160,11,beveltags)
- DrawBevelBoxA(rport,lv_width+29,24,128,11,beveltags)
- IF wbsplus
- TextF((213-nodenamelen)/2+lv_width,(lv_heigth-13-35)/2+35,nodename)
- ELSE
- TextF((213-nodenamelen)/2+lv_width,(lv_heigth-35)/2+35,nodename)
- ENDIF
- ENDPROC
-
- PROC createmen()
- menu:=CreateMenusA([1,0,'Projet',0,0,0,0,
- 2,0,'About',0,0,0,1,
- 2,0,NM_BARLABEL,0,0,0,0,
- 2,0,'NewCli',0,0,0,2,
- 2,0,NM_BARLABEL,0,0,0,0,
- 2,0,'Quit',0,0,0,3,
- 0,0,0,0,0,0,0]:newmenu,[GTMN_FRONTPEN,1,
- GTMN_NEWLOOKMENUS,TRUE,
- NIL])
- LayoutMenusA(menu,visual,NIL)
- SetMenuStrip(ptrwin,menu)
- ENDPROC
-
- PROC launchstart(file)
- DEF launch,ch2[108]:STRING
- IF count1
- IF (Rename({user},{userold}))=NIL
- req('Can''t rename User-Startup !')
- RETURN
- ENDIF
- ENDIF
- IF count2
- IF (Rename({wbs},{wbsold}))=NIL OR (Rename({wbsinfo},{wbsoldinfo}))=NIL
- req('Can''t rename WBStartup or WBStartup.info !')
- ENDIF
- ENDIF
- StrCopy(ch2,'C:EXECUTE ',ALL)
- StrCopy(ch,dirscan,ALL)
- AddPart(ch,file,70)
- StringF(ch,'"\s"',ch)
- StrAdd(ch2,ch,ALL)
- StrCopy(ch,ch2,ALL)
- IF scr THEN UnlockPubScreen(NIL,scr)
- IF ptrwin THEN CloseW(ptrwin)
- IF (launch:=SystemTagList(ch,NIL))=TRUE
- req('Can''t execute this script !\nPlease try another one ...')
- RETURN
- ENDIF
- quit()
- ENDPROC
-
- PROC wbsplusprefs()
- IF dirlock:=Lock(wbsp_path,ACCESS_READ)
- wbsplus:=TRUE
- UnLock(dirlock)
- ENDIF
- ENDPROC
-
- PROC quit()
- IF menu THEN FreeMenus(menu)
- IF dirlock THEN UnLock(dirlock)
- IF scr THEN UnlockPubScreen(NIL,scr)
- IF ptrwin THEN ClearMenuStrip(ptrwin)
- IF visual THEN FreeVisualInfo(visual)
- IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
- IF reqtoolsbase THEN CloseLibrary(reqtoolsbase)
- OpenWorkBench()
- CleanUp(0)
- ENDPROC
-
- wbs: CHAR 'SYS:WBStartup',0
- wbsinfo: CHAR 'SYS:WBStartup.info',0
- wbsold: CHAR 'SYS:WBStartupOld',0
- wbsoldinfo: CHAR 'SYS:WBStartupOld.info',0
- user: CHAR 'S:User-Startup',0
- userold: CHAR 'S:User-StartupOld',0
- lwb: CHAR 'C:LoadWB',0
- sslog: CHAR 'S:startupselector_log',0
-