Академический Документы
Профессиональный Документы
Культура Документы
Introduction
YouwouldliketocreateyourownscriptsforPlayOnLinuxbutyoudon'tknowsquataboutprogramming?Thistutorial willexplainthebasicsandyou'llsoonbeaproinplayonlinuxianbash
Bash?
BashisacommandinterpretorinGNU/Linux.It'stheoneappearingwhenyoulaunchaterminal.Italsoallowsyouto makescripts.Ascriptisalistofcommandsthatyourconsolewillopenoneaftertheother PlayOnLinuxhasadvancedfunctionsinbashtomakethescriptingprocesseasier.Let'sgetacquaintedwiththem
Yourfirstscript
IrecommendthatyouuseZoloom'sprogramtoscript:PlayOnLinuxScriptCreator.Otherwise,asimpletexteditor isfine. WesaidpreviouslythatPlayOnLinuxwasmadeinbash.Openyourtesteditorandtypeinthefollowingline:
#!/bin/bash
Then,youneedtoaddthecodethatwillloadPlayOnLinux'sfunctions
if [ "$PLAYONLINUX" = "" ] then exit 0 fi source "$PLAYONLINUX/lib/sources"
Thiscodemightnotseemveryclearonfirstlook.You'llunderstanditbetterinthenextchapter Thiscodemaybeshortenedthatway:
[ "$PLAYONLINUX" = "" ] && exit source "$PLAYONLINUX/lib/sources"
Duringthistutorial,Iwillnotputthiscodeeachtimeduringtheexamplesseeingasitisnecessary.Rememberto includeitotherwiseyourscriptwon'twork.
Executingyourscript
Note:Istronglyadvisethatyouworkwithaconsole.Itisveryusefulincasethereisaproblem.Allyouhavetodois launch"playonlinux"or"playonlinuxscriptcreator"inaconsole.Theerrorsyoumaygetwillbewrittenintheconsole. Onatexteditor,saveyoufileandusethe"Execute"functionofPlayOnLinux's"Tool"menu WithPlayOnLinuxScriptCreator,usethe"Run"button Nothing'shappening?That'snormal,youhaven'taskedPlayOnlinuxanythingyet.
CreateascriptforPlayOnLinuxChapter2:Basic functions
InitializingandclosingaPlayOnLinuxwindow
Sincetheversion3ofPlayOnLinux,youneedtoinitializeawindowatthebeginningofyourscriptandcloseitatthe end. Toinitializeawindow,usethefollowingline:
POL_SetupWindow_Init
Tocloseit:
POL_SetupWindow_Close
Intheend,yourscriptshouldlooklikethis:
if [ "$PLAYONLINUX" = "" ] then exit 0 fi source "$PLAYONLINUX/lib/sources" POL_SetupWindow_Init
Displayingamessage
Addthefollowingcodetoyourscript:
POL_SetupWindow_message "Hello World !" "My first message"
Thisiswhatyouwillget
Youcannowdisplayamessage.Happy?
Displayingamessageintheconsole
IfyoulaunchPlayonlinuxfromaterminal,youcanhaveamessagedisplayedinitwhichisveryconvinientfor debugging.Enterthefollowingcode:
echo "Hello World"
Commentingyourcode
Thissymbole"#"basicallytellsbashtoignorethefollowingtext.Hereisanexample:
echo "Hello World" # a nice comment echo "Goodbye World"
Weadviseyoutocommentyourcodeasmuchaspossibletomakeiteasiertoreadandfacilitatethevalidationprocess bythescriptors
Atextzone
Youwanttoasksomethingtotheuser?ThefunctionPOL_SetupWindow_textboxwascreatedforthatpurpose.Add thefollowingcodetoyourscript:
POL_SetupWindow_textbox "What is your name?" "Text zone"
Andhere'swhatthewindowlookslike
Nothing'shappening?That'snormal,we'llseeinthenextchapterhowtoretrievethedatethattheuserentered
Aquestion?
Youwanttheusertheanswerbyyesorno?ThenusethisfunctionPOL_SetupWindow_question Here'showitworks:
POL_SetupWindow_question "Do you like PlayOnLinux ?" "A question"
Theresultwilllooklike:
Inthenextchapterwewillseehowtoretrievetheanswertothequestion
Alittlemenu
Justlikeforthetwopreviousfunctions,youcancreateamenuforPlayOnLinux.
POL_SetupWindow_menu "What would you like to eat tonight ?" "Tonight's menu" "Carrots Potatoes French-Fries" " "
Introducingyourapplication
Thiscommandisveryimportant.Itallowsyoutointroducetheapplicationtotheuserbeforeheinstallsit
POL_SetupWindow_presentation "Name of the program" "Editor of the program" "Editor's site" "your pseudo" "Program's prefix (cf chapter 5)"
Example:
POL_SetupWindow_presentation "The Quest of the platypus" "PlayOnLinux" "http://www.playonlinux.com" "Tinou" "quest_of_the_platypus"
CreateascriptforPlayOnLinuxChapter3:the variables
Variable?Isthatanewinsult?
No,it'snotaninsult.Thevariableisaveryimportantelementinprogramming.Itisdefinedbyanameandavalue. Thisvaluecanvaryalongthescript. Ifyoudon'tunderstand,keeponreadingandyou'llfindoutwhatit'sallabout.
Declaringavariable
Therearetooptionstodeclareavariableinbash: 1stcase:
MY_VARIABLE="My value"
2ndcase:
export MY_VARIABLE="My value"
Readingavariable
Youhavetoputthissign"$"infrontofthevariable. Here'sanexampleofcode:
PSEUDO="Tinou" POL_SetupWindow_message "$PSEUDO is the strongest" "Name of the strongest"
Rsult:
Youcanusevariablesinanyfunction,echo,message,question,menu,...
PlayOnLinuxandvariables
Doyourememberthiscode?
POL_SetupWindow_menu "What do you want to eat tonight ?" "Tonight's menu" "Carrots Potatoes French-fries" " "
Theresultisactuallysentinthevariable$APP_ANSWER.Thisisthewaytoretrieveyourvariable:
POL_SetupWindow_menu "What do you want to eat tonight ?" "Tonight's menu" "Carrots Potatoes French-fries" " " MY_MEAL=$APP_ANSWER POL_SetupWindow_message "Tonight we'll be eating $MY_MEAL" "Tonight's menu"
Thevariable$APP_ANSWERiscreatedwitheachPlayOnLinuxfunctionsthatinvolvesachoicefromtheuser. ForPOL_SetupWindow_question,$APP_ANSWERiseitherTRUEorFALSEdependingontheanswer.
CreateascriptforPlayOnLinuxChapter4: Conditions
Conditions?CanIeatit?
You'dhavetobeveryhungrybutwhynot.Moreseriously,aconditionwillallowyoutoorderyouscripttododifferent thingsaccordingtoatest.Forexample,thevalueofavariable
Anexamplealwaysmakesunderstandingeasier
We'llbeusingthecommandif
POL_SetupWindow_menu "What's for dinner ?" "Tonight's menu" "Carrots Potatoes French-fries" " " MY_MEAL=$APP_ANSWER if [ "$MY_MEAL" = "Carrots" ] then POL_SetupWindow_message "Let's eat" "Tonight's menu" fi
Themessage"let'seat"willonlyappearsiftheuserchoosescarrots
POL_SetupWindow_menu "What's for dinner ?" "Tonight's menu" "Carrots Potatoes French-fries" " " MY_MEAL=$APP_ANSWER if [ "$MON_REPAS" = "Carottes" ] POL_SetupWindow_message "I'm on a hunger strike" "Tonight's menu" else POL_SetupWindow_message "Can I have a second helping ?" "Tonight's menu" fi
Themessage"I'monahungerstrike"willonlybedisplayediftheuserchoosescarrots.Otherwisethemessage"CanI haveasecondhelping?"willbedisplayed
CreateascriptforPlayOnLinuxChapter5:Wine
Who'sthat?
ThisisPlayOnLinux'smotor.ThissoftwaredeveloppedbyWineHQpermitstorunonLinuxsoftwaresthatwere createdforWindows. Inthischapter,IwillshowyousomeimportantPlayOnLinuxfunctionsinregardtoWinebutnotallofthem.Forthe moretechnicalfunctions,youshouldreadMulX'sdocumentation.
TheStoryofthePrefix
PlayOnLinuxmanageswinesprefixes.Nothingbetterthananillustrationtoexplainthis. Withwine,theinstallationofagamelookslikethis:
WithPlayOnLinux,itcanbesummedupthisway:
Thepointbeing:Itallowstohaveaspecificconfigurationpergameandtheuninstallationofagameissimplified(you justhavetoremoveafolder)
ManagingprefixeswithPlayOnLinux
Twocommands:
select_prefix
Aprefixshouldonlycontainalphanumericalcharacters
Selectsaprefix.Allcommandsstartingwith"wine"or"regedit"willactinthisprefix
select_prefix "$HOME/.PlayOnLinux/wineprefix/Steam/"
WillselectSteam'sprefix
POL_SetupWindow_prefixcreate
POL_SetupWindow_prefixcreate
Willeithercreateorupdateaprefix.Itisnecessarybeforeeachinstallation
AskfortheCDROM
Onecommand:POL_SetupWindow_cdromtheresultisstoredinthe$CDROMvariable
POL_SetupWindow_cdrom
CheckingthatthereisaCDROM
Verifiesifthefileexists,otherwiselaunchesPOL_SetupWindow_cdrom
POL_SetupWindow_check_cdrom "/path/to/the/file/in/CD"
Usingwinetoexecutea.exe
Executesa.exefileintheselectedprefix Examples:
wine $CDROM/setup.exe wine d:\setup.exe wine /home/splash/my_filer.exe
CreatingalauncherinPlayOnLinux
Usethefollowingsyntax:
POL_SetupWindow_make_shortcut "Name_of_the_prefix" "Directory" "Executable" "" "Name of the launcher"
Example:
POL_SetupWindow_make_shortcut "JediKnightII" "Program Files/LucarsArt" "JediKnightII.exe" "" "Star Wars : Jedi Knight II"
CreateascriptforPlayOnLinuxChapter6:Thefile system
Introduction
Thereareacoupleofgoodwaystomanipulateyourfilesinbash.We'llgiveyouthemostimportantcommands
PlayOnLinuxhasatemporarydirectory
It's$HOME/.PlayOnLinux/tmp/ Youcanstockandmodifyanyfileyouwantinit. Itisrecommandedthatyouremovethefilesfromthisfolderonceyou'redonewiththem
Switchingdirectory
Youmustusethecommandcd. Note:Thenewdirectoryisstoredinthe$PWDvariable Example:
cd $HOME/.PlayOnLinux/tmp/
Afewcorrespondences
./referstothecurrentfile ../referstotheparentdirectory
Removingafileordirectory
Warning,thiscommandisverydangerous.Itcoulddestroyallyourfilesifyoudon'thandleitproperly.Forexample,if youdecidetoremove/home/tinou/.PlayOnLinux/tmp/andthatyouinadvertentlyinsertablankbetween/tinou/and .PlayOnLinux,youcansayfarewelltoyoudocuments.PlayOnLinuxwillnotbeheldresponsibleforanymishandling onyourpart. Thisbeingsaid,herearethecodes
rm ./file.extension
Willremovefile.extensioninthecurrentdirectory($PWD)
rm ./dossier -r
Removesadirectoryandeverythinginit.
Copyingafilefromadirectoryfromanother
cp source_file target_directory
Copyingadirectory
cp source_directory target_directory/ -r
Movingorrenamingafileordirectory
mv source_directory target_directory mv source_file target_file
CreateascriptforPlayOnLinuxChapter7:Afew moreexampleswithPlayOnLinuxversion3
Afewcommands
Freerpresentation:
POL_SetupWindow_free_presentation "Titre" "Message"
Downloadingafile
POL_SetupWindow_download "message" "Title" "URL"
Atextezonewiththe"browse"button
POL_SetupWindow_browse "message" "Title" "Default Value"
Waitingforaprocesstoend
Thisisnew.ThereisawaytohavePlayOnLinuxwaitduringtheexecutionofaprocess. Basically,you'retellingPlayOnLinux:"displaya"wait"windowwithawaitingbaruntilItellyouotherwise." Hereisthesyntax:
POL_SetupWindow_wait_next_signal "message" "title" command1... command2... POL_SetupWindow_detect_exit POL_SetupWindow_...
Anexample:
POL_SetupWindow_wait_next_signal "Installation of Steam" "Steam" wine "steam.exe" POL_SetupWindow_detect_exit POL_SetupWindow_message "Steam installed"