UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on July 16, 2013, 02:51:29 PM

Title: Scan Folder To Create Resource Bindings
Post by: kevin on July 16, 2013, 02:51:29 PM
 Scan Folder To Create Resource Bindings

   This function runs through a folder (of the your choice) and creates a list of bindings you can then cut'n paste into your program.    The program dumps the list to the debug console so you'll need to run it debug mode (Hot keys are F6 or F7 from the IDE). The function includes basic file extension matching so you can screen out what files are includes and what aren't..  


    Requires PlayBASIC V1.64O (or higher)

[pbcode]


   // Get the path to the Media that's currently in the help files
   // just so we've something to look at.
   Path$=ProgramDir$()+"Help\Commands\Media\"

   // display the path
   print path$

   // scan the folder
   Make_Resource_Binding_from_Path(path$,"PNG,BMP")
   
   Sync
   waitkey
         

   // This Function dumps the resulting into the debugger console

Function Make_Resource_Binding_from_Path(path$,FileTypeList$)

   if FolderExist(Path$)

      ReadDir Path$,"*.*",true,false

      Dim FileTypeList$(0)

      FileTypeList$=upper$(FileTypeList$)         
      FileTypeCount=SplitToArray(FileTypeLIst$,",",FileTypeLIst$())
      
      cr$=chr$(13)+chr$(10)
      Header$ ="// -------------------------------------------------------------"+cr$
      Header$+="// --[ Bound Resources ]-------[ "+ CurrentDate$()+"] -------------------------"+cr$
      Header$+="// -------------------------------------------------------------"+cr$
      Header$+=cr$
      
      
      Tail$=cr$
      Tail$+="// -------------------------------------------------------------"+cr$
      Tail$+="// --[ Bound Resources ]----------------------------------------"+cr$
      Tail$+="// -------------------------------------------------------------"+cr$
      Tail$+=cr$
      
      Indent$=chr$(9)
      Count=0
      For lp =0 to GetDirSize()      
         if GetDirFileType(lp)=1
            name$=GetDirFile$(lp)
            e$=GetFileExt$(Name$)
            if FileTypeCount>0
                  index=FindArrayCell(FileTypeList$(),0,1,FileTypeCount,upper$(e$))
                  if Index>-1

                        name$=GetDirFolder$(lp)+name$

                        if Count=0
                           #print Header$
                        endif
                        #print indent$+"#AddResource "+chr$(34)+trim$(Name$)+chr$(34)
                        
                        Count++
                  endif            
            endif         
         endif
            
      next
      
      
      if Count
            #print Tail$      
      endif
      
   endif
EndFUnction


[/pbcode]


  This code dumps the following source code snippet to the debug console window.  



// -------------------------------------------------------------
// --[ Bound Resources ]-------[ 17 Jul 2013] -------------------------
// -------------------------------------------------------------

#AddResource "AddResource-Example1-400by300.png"
#AddResource "AddResource-Example2-Hello-World.png"
#AddResource "bubble_64x64.bmp"
#AddResource "Camera-Tutorial-V001.png"
#AddResource "Fonts-Create-Bitmap-Font-Custom-Font-Example.png"
#AddResource "Fonts-Create-Bitmap-Font-Example.png"
#AddResource "Fonts-Save-Font-Example.png"
#AddResource "FRESH.png"
#AddResource "Heart-Frames-Screen-Shot.png"
#AddResource "ImageLayout.png"
#AddResource "Linear-Rotation-Scaling-Example.png"
#AddResource "Mapping-Blocks-Example.png"
#AddResource "Mapping-Level-Array-Example.png"
#AddResource "Mapping-Level-Example.png"
#AddResource "Mapping-Level-With-Indexes-And-Blocks.png"
#AddResource "PlayBASIC-Hello-World-Debug-Console-Example.png"
#AddResource "PlayBASIC-Screen-Layout-400-by-300-On-Windows-XP.png"
#AddResource "PlayBasicSig.png"
#AddResource "SceneBuffer-Draw-Order-Example-Cropped.png"
#AddResource "Shape-MergeShape-Example.png"
#AddResource "Shape-Picture.png"
#AddResource "Shapes-BoxHitShape-Example.png"
#AddResource "Shapes-CircleHitShape-Example.png"
#AddResource "Shapes-DrawShape-Example.png"
#AddResource "Shapes-LineHitShape-Example.png"
#AddResource "Shapes-PointHitShape-Example.png"
#AddResource "Shapes-RefreshShape-Example.png"
#AddResource "Shapes-ResizeShape-Example.png"
#AddResource "Shapes-RotateShape-Example.png"
#AddResource "Shapes-ShapeHitShape-Example.png"
#AddResource "Shapes-ShiftShape-Example.png"
#AddResource "ship.bmp"
#AddResource "Sprite-Alpha-50-Mode-8-Example.png"
#AddResource "Sprite-Alpha-50-Picture.png"
#AddResource "Sprite-Alpha-Addition-Mode-16-Example.png"
#AddResource "Sprite-Alpha-Addition.png"
#AddResource "Sprite-Alpha-Subtraction-Mode-32-Example.png"
#AddResource "Sprite-Collision-Circle-Close-Up.png"
#AddResource "Sprite-Collision-Pixel-Perfect-Close-Up.png"
#AddResource "Sprite-Collision-Rectangle-Close-Up.png"
#AddResource "Sprite-Collision-Rotated-Rectangle-Close-Up.png"
#AddResource "Sprite-Collision-Shape-Collision-Close-Up.png"
#AddResource "Sprite-Collision-Shapes-Ship-With-Shape-Mask.png"
#AddResource "Sprite-Filtering-Example.png"
#AddResource "Sprite-Gouraud-Mode-128-Example.png"
#AddResource "Sprite-Gouraud-Mode-256-Example.png"
#AddResource "Sprite-Rotation-Frame-Example.png"
#AddResource "Sprite-Tint-Examples.png"
#AddResource "Sprite-Tutorial-5-Sprites-On-Screen.png"
#AddResource "Sprite-Tutorial-Blank-Screen.png"
#AddResource "AnimationsExplosion-Frame-Sheet.png"
#AddResource "Animationsexplosions.png"
#AddResource "CollisionCircles-Hit.png"
#AddResource "CollisionLine-Intersect-Circle.png"
#AddResource "CollisionRay-Intersect-World-Picture-400by300.png"
#AddResource "PlayWriteIDE-Perferences-Window.png"
#AddResource "PlayWriteIDE-Source-Inspector-Parsing-Functions.png"
#AddResource "Animations\ClownRunrun0001.Bmp"
#AddResource "Animations\ClownRunrun0002.Bmp"
#AddResource "Animations\ClownRunrun0003.Bmp"
#AddResource "Animations\ClownRunrun0004.Bmp"
#AddResource "Animations\ClownRunrun0005.Bmp"
#AddResource "Animations\ClownRunrun0006.Bmp"
#AddResource "Animations\ClownRunrun0007.Bmp"
#AddResource "Animations\ClownRunrun0008.Bmp"
#AddResource "Animations\ClownRunrun0009.Bmp"
#AddResource "Animations\ClownRunrun0010.Bmp"
#AddResource "Animations\ClownRunrun0011.Bmp"
#AddResource "Animations\ClownRunrun0012.Bmp"
#AddResource "Animations\Explodeex10001.Bmp"
#AddResource "Animations\Explodeex10002.Bmp"
#AddResource "Animations\Explodeex10003.Bmp"
#AddResource "Animations\Explodeex10004.Bmp"
#AddResource "Animations\Explodeex10005.Bmp"
#AddResource "Animations\Explodeex10006.Bmp"
#AddResource "Animations\Explodeex10007.Bmp"
#AddResource "Animations\Explodeex10008.Bmp"
#AddResource "Animations\Explodeex10009.Bmp"
#AddResource "Animations\Explodeex10010.Bmp"
#AddResource "Animations\Heartheart0001.Bmp"
#AddResource "Animations\Heartheart0002.Bmp"
#AddResource "Animations\Heartheart0003.Bmp"
#AddResource "Animations\Heartheart0004.Bmp"
#AddResource "Animations\Heartheart0005.Bmp"
#AddResource "Animations\Heartheart0006.Bmp"
#AddResource "Animations\Heartheart0007.Bmp"
#AddResource "Animations\Heartheart0008.Bmp"
#AddResource "Animations\Starstar0001.bmp"
#AddResource "Animations\Starstar0002.bmp"
#AddResource "Animations\Starstar0003.bmp"
#AddResource "Animations\Starstar0004.bmp"
#AddResource "Animations\Starstar0005.bmp"
#AddResource "Animations\Starstar0006.bmp"
#AddResource "Animations\Starstar0007.bmp"
#AddResource "Animations\Starstar0008.bmp"
#AddResource "Animations\Starstar0009.bmp"

// -------------------------------------------------------------
// --[ Bound Resources ]----------------------------------------
// -------------------------------------------------------------