cr=Num2Char(13)
lf=Num2char(10)
crlf=StrCat(cr,lf)

info1="                                                           Hi!"
info2="This mini app diddles with the Flying Windows Screensaver."
info3="It modifies the SSFLYWIN.SCR file and inserts the character of your choice from the Wingdings Character Set."
info4="Don't worry, we make a backup of the file, SSFLYWIN.BAK, so you can return to the original at any time."
info5="Do you want to continue?"

;Clear the clipboard
ClipPut("")

a=AskYesNo("Tina's Free Festive Flying Font FunSaver", StrCat(info1, crlf, crlf, info2, crlf, crlf, info3, crlf, crlf, info4, crlf, crlf, info5))
if a==@NO then goto cancel


;Advise the user to select a character, press copy and then close CharMap.
Display(4, "Tina's Free Festive Flying Font FunSaver", "SELECT one character %CRLF%choose COPY %CRLF%CLOSE the Character Map")


:fontselect
;Read the Win.ini MSCharMap section to see what font is there.
orgfont=IniRead("MSCharMap", "Font", "NO DEFAULT")


;Change the font to Wingdings.
newfont=IniWrite("MSCharMap", "Font", "Wingdings")

  
;Run the character map.
RunWait("CHARMAP.EXE", "")


;Change the font back to what it originally was.
if orgfont!="NO DEFAULT" then IniWrite("MSCharMap", "Font", orgfont)


;Get the character/symbol off of the clipboard.
symbol=ClipGet()
If symbol == "" 
     Ask=AskYesNO("Symbol Selection", "No character was found, do you want to choose another?")
     If ask == 1 then goto fontselect
endif

          
;Convert the character to a number.
magicnum=Char2Num(symbol)
;message("", magicnum)


;Build the path to the Windows directory and SSFLYWIN.SCR.
wherewin=DirWindows(0)
flywin=StrCat(wherewin, "SSFlyWin.SCR")


;Check to see if they have a back up file, if not create it.
flywinbak=StrCat(wherewin, "SSFlyWin.bak")
If FileExist(flywinbak)==@NO then FileCopy(flywin, flywinbak, @False)


;Check file size of SSFLYWIN.SCR.  If it is not equal to 16160 it is not the correct version.
size=FileSize(flywin)
If size != 16160 
     Message("Whoops %size%", "This Script doesn't work with your version of Flying Windows. %CRLF% SORRY")
     goto cancel
endif


;Set the memory buffer.
binbuf=BinaryAlloc(size)
if binbuf ==0 
     Message("ERROR", "BinaryAlloc Failed")
else
     ;read into the buffer
     BinaryRead(binbuf, flywin)
     ;insert the new number into the correct offset.
     BinaryPoke(binbuf, 11762, magicnum)
     ;write the file out.
     BinaryWrite(binbuf, flywin)
     ;free the buffer
     BinaryFree(binbuf)
endif


:dlg                         
;Display a dialog box for the user to test the new selection.
FlyWinFormat=`WWWDLGED,5.0`

FlyWinCaption=`Tina's Free Festive Flying Font FunSaver`
FlyWinX=74
FlyWinY=80
FlyWinWidth=243
FlyWinHeight=154
FlyWinNumControls=10

FlyWin01=`16,38,80,DEFAULT,PUSHBUTTON,DEFAULT,"TEST",1`
FlyWin02=`80,118,80,DEFAULT,PUSHBUTTON,DEFAULT,"EXIT",0`
FlyWin03=`33,8,184,DEFAULT,STATICTEXT,DEFAULT,"The new symbol has been entered into your screensaver. "`
FlyWin04=`104,38,88,DEFAULT,STATICTEXT,DEFAULT,"Test fly your new font."`
FlyWin05=`16,56,80,DEFAULT,PUSHBUTTON,DEFAULT,"SET SCREENSAVER",2`
FlyWin06=`104,56,120,DEFAULT,STATICTEXT,DEFAULT,"Set Flying Font as your Screensaver."`
FlyWin07=`104,91,104,DEFAULT,STATICTEXT,DEFAULT,"Choose another font character."`
FlyWin08=`16,91,80,DEFAULT,PUSHBUTTON,DEFAULT,"SET FONT",3`
FlyWin09=`16,73,80,DEFAULT,PUSHBUTTON,DEFAULT,"SET OPTIONS",4`
FlyWin10=`104,73,97,DEFAULT,STATICTEXT,DEFAULT,"Set Flying Font setup options"`

ButtonPushed=Dialog("FlyWin")


;Run the screensaver.
delay(2)
;return value 1 tests the funsaver.
If ButtonPushed == 1 then goto test   

;return value 2 sets the funsaver in the win.ini and system.ini 
If ButtonPushed == 2 then goto setsaver

;return value 3 sends user back to the character map to select another font.
If ButtonPushed == 3 then goto fontselect

If ButtonPushed == 4 then goto options


:Cancel
Exit 

:test
RunWait("SSFlywin*scr", "/s")
goto dlg

  
:setsaver
;turn the screensaver on and set the timeout.
a=WinParmGet(7)
b=WinParmGet(8)

WinParmSet(7, "480", 1)
WinParmSet(8, "1", 1)

;Read the Win.ini and replace the screensaver with SSflywin.scr 
IniWritePvt("boot", "SCRNSAVE.EXE", Flywin, "System.ini")
 
Display(3,"Tina's Free Festive Flying Font FunSaver", "%crlf% The new font is set. %crlf% %crlf% Please adjust the following settings.") 

delay(2)
:options
RunWait("SSFlywin*scr", "")

Display(3,"Tina's Free Festive Flying Font FunSaver", "Launching Festive Flying Font FunSaver") 

RunWait("SSFlywin*scr", "/s") 

goto dlg
