'Copyright (c) 2009, Greg Sweitzer, All rights reserved. 'Permission is hereby granted, free of charge, to any person obtaining a copy of this software, to modify 'and redistribute it and use its source and binary forms, with or without modification, provided that the following conditions are met: '1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. '2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 'This software is provided by the copyright holders and contributors "as is" with no express or implied warranties. '====================== 'LaunchPad - Liberty BASIC source code 'this program requires additional files installed using the .exe installer 'also, the Hot Key Plus program is configured during installation to 1) run when computer starts, and 2) respond to the key combination Ctrl-j '====================== 'DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT 'DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT 'DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT 'DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT - DEFINE ENVIRONMENT nomainwin on error goto [ErrorHandler] tries = 2 'how many more lines to read after 1st command fails. This value changes under [ErrorHandler] below. 'FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE 'FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE 'FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE 'FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE - FIND DATA FILE filename$ = "launch.lpf" dim info$(10, 10) files "", filename$, info$( qtyFiles = val(info$(0, 0)) if qtyFiles = 0 then notice$ = "launch.lpf - File not found!" calldll #user32, "MessageBeep", _MB_ICONSTOP as long, beepResult as boolean mbflags = _MB_ICONSTOP OR _MB_OK calldll #user32, "MessageBoxA", _ 0 as long, _ notice$ as ptr, _ "LaunchPad Notice" as ptr, _ mbflags as long, _ mbResult as long end 'if ini file does not exist - do not attempt to open it end if 'OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW 'OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW 'OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW 'OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW - OPEN WINDOW WindowWidth = 164 WindowHeight = 56 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) button #window.default, "Go!", [GO], UL, 115, 3, 40, 22 'button in down width height TextboxColor$ = "white" textbox #window.textbox, 2, 2, 110, 22 'textbox in down length height 'the following stylebits are mutually exclusive 'stylebits #window, 0, 0, _WS_EX_TOOLWINDOW, 0 'make window & titlebar small & remove icon stylebits #window, 0, 0, _WS_EX_TOPMOST, 0 'place window always on top open "LaunchPad" for dialog as #window windowStatus = 1 #window "trapclose [quit]" #window.default, "!font ms_sans_serif 6" 'button font #window "font arial 11" 'text font #window.textbox, "!setfocus" 'place cursor in first box 'READ INI open filename$ for input as #Ini DIM var$(5000) 'dimension array for number of lines i = 5 while blankLines = 0 'Read data until encounter multiple blank lines - requires data to be on one of first three lines Line Input #Ini, var$(i) if i > 3 and var$(i) = "" and var$(i-1) = "" and var$(i-2) = "" then blankLines = 1 i = i + 1 wend close #Ini wait 'GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - 'GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - 'GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - 'GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - GET REQUEST - [GO] #window.textbox "!contents? request$" 'transform window contents to string if request$ = "" then goto [quit] request$ = lower$(request$) 'convert any upper case text to lower case 'RESERVED REQUESTS if request$ = "list" then openData = 1 if request$ = "edit" then openData = 1 if request$ = "l" then openData = 1 if openData = 1 then run "notepad.exe launch.lpf", SHOWMAXIMIZED goto [quit] end if if right$(request$,3) = ".ca" then goto [internetAddressEntered] 'If user types a string ending if right$(request$,4) = ".biz" then goto [internetAddressEntered] 'in one of these domains but does if right$(request$,4) = ".com" then goto [internetAddressEntered] 'not specify a transfer protocol, if right$(request$,4) = ".edu" then goto [internetAddressEntered] 'it is treated as a URL and if right$(request$,4) = ".gov" then goto [internetAddressEntered] '"http://" is appended to the if right$(request$,5) = ".info" then goto [internetAddressEntered] 'beginning (below). There are a few if right$(request$,4) = ".mil" then goto [internetAddressEntered] 'more here than later because if right$(request$,5) = ".name" then goto [internetAddressEntered] 'the user can always choose another if right$(request$,4) = ".net" then goto [internetAddressEntered] 'request to enter here. if right$(request$,4) = ".org" then goto [internetAddressEntered] if right$(request$,4) = ".pro" then goto [internetAddressEntered] if right$(request$,4) = ".htm" then goto [internetAddressEntered] 'This works on the Internet and if right$(request$,5) = ".html" then goto [internetAddressEntered] 'also local pages. if left$(request$,2) = "a " then goto [referenceEntered] if left$(request$,2) = "b " then goto [referenceEntered] if left$(request$,2) = "d " then goto [referenceEntered] if left$(request$,2) = "g " then goto [referenceEntered] if left$(request$,2) = "i " then goto [referenceEntered] if left$(request$,2) = "t " then goto [referenceEntered] if left$(request$,2) = "w " then goto [referenceEntered] if left$(request$,2) = "y " then goto [referenceEntered] if request$ = "exit" or request$ = "quit" or request$ = "end" then goto [quit] if request$ = "help" or request$ = "options" or request$ = "preferences" then URLFile$ = "http://pasoft.ca/quickstart.htm" goto [loadURL] end if if request$ = "about" then URLFile$ = "http://pasoft.ca/about_1.3.htm" goto [loadURL] end if if request$ = "version" then close #window : windowStatus = 0 calldll #user32, "MessageBeep", _MB_ICONINFORMATION as long, beepResult as boolean : mbflags = _MB_ICONINFORMATION OR _MB_OK calldll #user32, "MessageBoxA", 0 as long, "LaunchPad v1.3 HotKeyPlus v1.01" as ptr, "LaunchPad" as ptr, mbflags as long, mbResult as long goto [quit] end if 'READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA 'READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA 'READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA 'READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA - READ DATA for j = 1 to i+5 var$(j) = lower$(var$(j)) 'convert any upper case text (in launch.lpf) to lower case if request$ = var$(j) then requestFound = 1 lineRequestLocated = j string2Run$ = var$(j+1) 'if string contains both leading and trailing quotation marks, run that string if left$(string2Run$,1) = chr$(34) then qMarks = 1 if right$(string2Run$,1) = chr$(34) then qMarks = qMarks + 1 if qMarks = 2 then run string2Run$ goto [quit] end if [readNextLine] if windowStatus = 1 then close #window windowStatus = 0 end if if instr(string2Run$,"#") > 0 then goto [executeWithparameters] gosub [getFileExtension] if extensionIdentified = 1 then if spaceDetected <> 1 then run associatedFile$ + " " + var$(j+1), SHOWMAXIMIZED goto [quit] else 'wrap string in quotes if execute contains spaces run associatedFile$ + " " + chr$(34) + var$(j+1) + chr$(34), SHOWMAXIMIZED goto [quit] end if else run string2Run$ end if if windowStatus = 1 then close #window windowStatus = 0 end if end end if next j if requestFound = 0 then confirm string2Run$ + " - Sorry, no such request. Open launch.lpf?"; openIni$ if openIni$="yes" then run "notepad.exe launch.lpf", SHOWMAXIMIZED [quit] if windowStatus = 1 then close #window windowStatus = 0 end if end 'PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE 'PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE 'PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE 'PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE - PROCESS EXECUTE [getFileExtension] string2Run$ = lower$(string2Run$) explorerTest$ = left$(string2Run$, 8) 'do this here bc otherwise treaats execute as a data file and tries to find associated extension if instr(string2Run$,"/") > 0 then forwardSlashDetected = 1 'detect forward slash to improve error reporting if explorerTest$ = "explorer" then run string2Run$ goto [quit] end if if left$(string2Run$, 3) = "www" or left$(string2Run$, 4) = "http" then URLFile$=string2Run$ goto [loadURL] end if if instr(string2Run$,".") = 0 then 'if no period in command line, run it as is run string2Run$ goto [quit] end if fileindex=len(string2Run$) filelength=len(string2Run$) while mid$(string2Run$, fileindex,1)<>"." fileindex=fileindex-1 wend ext$=right$(string2Run$,filelength-fileindex) 'print ext$ 2222 if ext$ = "msc" then return if ext$ = "cpl" then return extensionIdentified = 1 if ext$ = "exe" then run string2Run$ goto [quit] end if if ext$ = "bat" then run string2Run$ goto [quit] end if loadWebSite = 0 if ext$ = "biz" then loadWebSite = 1 'If execute does not begin with "http://" but ends with if ext$ = "com" then 'one of these domains, then treat it as a URL. dotComExtensionDetected = 1 'This section allows users to use e.g. "business.com" loadWebSite = 1 'and have it correctly interpreted. Ideally, the user would end if 'always preface a URL with the transfer protocol. Ideally. if ext$ = "edu" then loadWebSite = 1 if ext$ = "gov" then loadWebSite = 1 if ext$ = "info" then loadWebSite = 1 if ext$ = "int" then loadWebSite = 1 if ext$ = "mil" then loadWebSite = 1 if ext$ = "name" then loadWebSite = 1 if ext$ = "net" then loadWebSite = 1 if ext$ = "org" then loadWebSite = 1 if ext$ = "pro" then loadWebSite = 1 if dotComExtensionDetected = 1 then if instr(string2Run$,"c:\") > 0 then 'string starts with c:\ and ends with .com therefor is an executable run string2Run$ goto [quit] end if end if if loadWebSite = 1 and left$(string2Run$,4) <> "http" then URLFile$ = "http://"+string2Run$'2222 goto [loadURL] end if [determineFileAssociation] 'see "FindExecutable" in LB companion p 438 of combined AND ShellExecute p 443 extensionIdentified = 1 'determine if space exists within string a$ = string2Run$ b$ = string2Run$ LET s=LEN(a$) [LOOP] num$ = " " IF LEN(num$) = 0 THEN END n = INSTR(a$,num$) IF n=0 THEN GOTO [stripped] a$= LEFT$(a$,n-1) + RIGHT$(a$, s-n) LET s=LEN(a$) GOTO [LOOP] 'SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN 'SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN 'SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN 'SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN - SUBS & FUN [loadURL] lpOperation$ = "open" lpParameters$ = parameters$ lpDirectory$ = DefaultDir$ nShowCmd = _SW_SHOWNORMAL calldll #shell32, "ShellExecuteA", _ hWindow as long, _ 'parent window lpOperation$ as ptr, _ 'open or print URLFile$ as ptr, _ 'file name lpParameters$ as ptr, _ 'null lpDirectory$ as ptr, _ 'default directory nShowCmd as long, _ 'show window flag result as long if result <= 32 then 'see if next line works if var$(lineRequestLocated+tries) <> "" then string2Run$ = var$(lineRequestLocated+tries) tries = tries + 1 goto [readNextLine] end if if result <= 32 then print "Error, Address Failure!" end if goto [quit] [executeWithparameters] if instr(string2Run$,"/") > 0 then forwardSlashDetected = 1 'parse string2Rin$ into path, file name, and paramaters length = len(string2Run$) position = instr(string2Run$,"#") pathAndFile$ = left$(string2Run$, position-1) shortFile$=SeparateFile$(pathAndFile$) paramaters$ = right$(string2Run$, length-position) pathOnlyLength = len(pathAndFile$)-len(shortFile$) pathOnly$=left$(pathAndFile$,pathOnlyLength) 'feed variables to dll URLFile$=shortFile$ lpOperation$ = "open" lpParameters$ = paramaters$ lpDirectory$ = pathOnly$ nShowCmd = _SW_SHOWNORMAL calldll #shell32, "ShellExecuteA", _ hWindow as long, _ 'parent window lpOperation$ as ptr, _ 'open or print URLFile$ as ptr, _ 'file name lpParameters$ as ptr, _ 'null lpDirectory$ as ptr, _ 'default directory nShowCmd as long, _ 'show window flag result as long if result <= 32 then 'see if next line works if var$(lineRequestLocated+tries) <> "" then string2Run$ = var$(lineRequestLocated+tries) tries = tries + 1 goto [readNextLine] end if if result <= 32 then print "Error, Address Failure!" goto [quit] end if [referenceEntered] length = len(request$) word$=right$(request$,length-2) if left$(request$,2) = "a " then URLFile$="http://www.amazon.com/s/ref=nb_ss?url=search-alias%3Daps&field-keywords="+word$+"&x=0&y=0" if left$(request$,2) = "b " then URLFile$="http://search.about.com/fullsearch.htm?terms="+word$+"&SUName=search" if left$(request$,2) = "d " then URLFile$="http://www.google.com/dictionary?aq=f&langpair=en|en&q=" + word$ + "&hl=en" if left$(request$,2) = "g " then URLFile$="http://www.google.com/#hl=en&source=hp&q=" + word$ + "&fp=1&cad=b" if left$(request$,2) = "i " then URLFile$="http://www.imdb.com/find?s=all&q="+word$ if left$(request$,2) = "t " then URLFile$="http://thesaurus.reference.com/browse/"+word$ if left$(request$,2) = "w " then URLFile$="http://en.wikipedia.org/wiki/"+word$ if left$(request$,2) = "y " then URLFile$="http://www.youtube.com/results?search_query=" + word$ + "&search_type=&aq=f" goto [loadURL] [internetAddressEntered] if left$(request$,4) <> "http" then URLFile$="http://"+request$ goto [loadURL] end if [stripped] if a$ <> b$ then spaceDetected=1 'determine file association string2Run$ = var$(j+1) index=len(string2Run$) : length=len(string2Run$) if instr(string2Run$,"\") > 0 then 'only run while if string contains "\", otherwise loops and crashes while mid$(string2Run$, index,1)<>"\" index=index-1 wend end if lpszFile$=right$(string2Run$,length-index) lpszDirectory$ = left$(string2Run$,index) lpszResult$ = space$(255) + chr$(0) calldll #shell32, "FindExecutableA", lpszFile$ as ptr,lpszDirectory$ as ptr,lpszResult$ as ptr, result as long associatedFile$ = trim$(lpszResult$) return [ErrorHandler] cursor normal 'if error 0 (file not found), then read second line after command and try that if Err = 0 and var$(lineRequestLocated+tries) <> "" then string2Run$ = var$(lineRequestLocated+tries) tries = tries + 1 goto [readNextLine] end if notice$ = "Error "+str$(Err)+" - "+Err$+" " 'file not found error can be triggered by use of forward slashes on Windows systems if forwardSlashDetected = 1 then notice$ = notice$ + chr$(13) + chr$(13) + "Try using backward slashes instead." calldll #user32, "MessageBeep", _MB_ICONSTOP as long, beepResult as boolean mbflags = _MB_ICONSTOP OR _MB_OK calldll #user32, "MessageBoxA", _ 0 as long, _ notice$ as ptr, _ "LaunchPad Notice" as ptr, _ mbflags as long, _ mbResult as long call Pause 1000 goto [quit] end 'if you don't end here launchpad stays in memory sub Pause milliseconds 'Pause using sleep calldll #kernel32, "Sleep",_ milliseconds as ulong,_ result as void end sub function SeparateFile$(f$) 'strip file name from path fileindex=len(f$) filelength=len(f$) while mid$(f$, fileindex,1)<>"\" fileindex=fileindex-1 wend SeparateFile$=right$(f$,filelength-fileindex) end function