AutoIncluder for PB-IDE [win]

Share your advanced PureBasic knowledge/code with the community.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

AutoIncluder for PB-IDE [win]

Post by ts-soft »

Open automatically all Includes, used by the actuell source, was loaded!

IDE options is set to only one instance!

Is not the fastest, but it works :wink:

Code: Select all

; OpenIncludes
; Autor: Thomas (ts-soft) Schulz
; PB4 erforderlich

EnableExplicit

Global Mutex.l

Procedure FindStringLeft(String.s, StringToFind.s, Startposition.l = 0)

  Protected len, len2, index

  len = Len(String)
  len2 = Len(StringToFind)
  If Startposition = 0
    Startposition = len
  EndIf
  For index = Startposition To 1 Step - 1
    If Mid(String, index, len2) = StringToFind
      ProcedureReturn index
    EndIf
  Next
  ProcedureReturn 0

EndProcedure

Procedure OnlyOne()
  Mutex = CreateMutex_(0, 0, @"{112E4DF0-2388-41B2-87F4-CE683443180E}")
  If GetLastError_() = #ERROR_ALREADY_EXISTS
    ReleaseMutex_(Mutex)
    CloseHandle_(Mutex)
    ProcedureReturn #False
  EndIf
  ProcedureReturn #True
EndProcedure

Define.s Line, Path, Path2, IFile, PBDir, File = ProgramParameter()
Define.l FF, Pos, PosB, PosE, Ft = #PB_Ascii

While Not OnlyOne()
  Delay(10)
Wend

PBDir = GetPathPart(GetEnvironmentVariable("PB_TOOL_IDE"))

If File <> ""
  Path = GetPathPart(File)

  FF = ReadFile(#PB_Any, File)
  If FF
    If ReadStringFormat(FF) <> #PB_Ascii : Ft = #PB_UTF8 : EndIf
    
    FileBuffersSize(FF, Lof(FF))
    
    While Not Eof(FF)
      IFile = ""
      Path2 = ""

      Line = ReadString(FF, Ft)

      Pos = FindString(Line, "IncludePath", 1)
      If FindStringLeft(Line, ";", Pos) Or FindStringLeft(Line, #DQUOTE$, Pos)
        Pos = 0
      EndIf
      If Pos
        PosB = FindString(Line, #DQUOTE$, Pos + 12) + 1
        PosE = FindString(Line, #DQUOTE$, PosB)
        If PosB And PosE
          Path = Mid(Line, PosB, PosE - PosB)
        EndIf
      EndIf

      Pos = FindString(Line, "IncludeFile", 1)
      If FindStringLeft(Line, ";", Pos) Or FindStringLeft(Line, #DQUOTE$, Pos)
        Pos = 0
      EndIf
      If Pos
        PosB = FindString(Line, #DQUOTE$, Pos + 12) + 1
        PosE = FindString(Line, #DQUOTE$, PosB)
        If PosB And PosE
          IFile = Mid(Line, PosB, PosE - PosB)
        EndIf
      EndIf

      Pos = FindString(Line, "XIncludeFile", 1)
      If FindStringLeft(Line, ";", Pos) Or FindStringLeft(Line, #DQUOTE$, Pos)
        Pos = 0
      EndIf
      If Pos
        PosB = FindString(Line, #DQUOTE$, Pos + 13) + 1
        PosE = FindString(Line, #DQUOTE$, PosB)
        If PosB And PosE
          IFile = Mid(Line, PosB, PosE - PosB)
        EndIf
      EndIf

      If FindString(Line, "#PB_Compiler_Home", Pos + 12)
        Path2 = PBDir
      EndIf

      If IFile <> ""
        If Path2 <> "" And FileSize(Path2 + IFile) > 0
          RunProgram(Path2 + IFile, "", "", #PB_Program_Wait)
        Else
          If FileSize(IFile) > 0
            RunProgram(IFile, "", "", #PB_Program_Wait)
          Else
            If FileSize(Path + IFile) > 0
              RunProgram(Path + IFile, "", "", #PB_Program_Wait)
            EndIf
          EndIf
        EndIf
      EndIf
    Wend
    CloseFile(FF)
  EndIf
EndIf
CloseHandle_(Mutex)

Config:
Image

download: http://ts-soft.eu/dl/autoincluder.zip
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

Nothing happens when I try to run your EXE. :)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

byo wrote:Nothing happens when I try to run your EXE. :)
This program runs only as plugin of the pb-ide! Correct config is required.
Or your code have no Includes?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Quoted again:

Here is my "AutoOpenIncludes" Tool

My code is shorter than TS-Soft ones! Moreover, I don't need GetPureBasicDirectory(), because the IDE whisperes its path to me! (So I don't need access to the registry => useful for people having PB on an USB-stick!)

The onliest thing that should be noticed is the delay time! If the time is too short, the IDE does react/load too slow and multiple IDE instances will be started. If it is too long, you must wait too long.
//Edit: Now there is a "global mutex", which causes multiple instances to wait until the previous instance is finished.

Code: Select all

; AutoOpenIncludes 
; Autor: André (AND51) Stapf 
; Requires: PB 4.00+ 
; Demo: No (Yes, if you leave out the API) 

EnableExplicit 

Define.s zeile, path=GetPathPart(GetEnvironmentVariable("PB_TOOL_Compiler")), file=ProgramParameter(), mutex="AutoOpenInclude"+GetEnvironmentVariable("PB_Tool_MainWindow") 
CreateMutex_(0, 1, @mutex) 
WaitForSingleObject_(mutex, 12345) 

Procedure runFile(file.s) 
   If FileSize(file) >= 0 
      RunProgram(file) ; There MUST be a delay in order to load all includes correctly! This is, because the IDE is so slow... 
      Delay(IntQ(FileSize(file)/2.3)) ; If this is too slow for you, define your own delay here! 
   EndIf 
EndProcedure 

If ReadFile(0, file) 
   Define format=ReadStringFormat(0), path.s=GetPathPart(file) 
    
   While Not Eof(0) 
      Define zeile.s=ReadString(0, format) 
      Define inc=FindString(zeile, "IncludeFile", 1), incX=FindString(zeile, "XIncludeFile", 1), incP=FindString(zeile, "IncludePath", 1), comment=FindString(zeile, ";", 1) 
      Define quoteL=0, quoteR=0 
       
      If comment <= inc And comment <= incX And comment <= incP And inc|incX|incP 
         If incP 
            quoteL=FindString(zeile, Chr(34), incP) 
            quoteR=FindString(zeile, Chr(34), quoteL+1) 
            path=Mid(zeile, quoteL+1, quoteR-quoteL-1)+"\" 
         EndIf 
         If incX 
            quoteL=FindString(zeile, Chr(34), incX) 
            quoteR=FindString(zeile, Chr(34), quoteL+1) 
            runFile(path+Mid(zeile, quoteL+1, quoteR-quoteL-1)) 
         EndIf 
         If inc And (inc-1 <> incX And Not incX) 
            quoteL=FindString(zeile, Chr(34), inc) 
            quoteR=FindString(zeile, Chr(34), quoteL+1) 
            runFile(path+Mid(zeile, quoteL+1, quoteR-quoteL-1)) 
         EndIf 
      EndIf 
       
      Delay(1) 
   Wend 
    
   CloseFile(0) 
EndIf
Please, configure it the same way as TS-Soft ones! However, here is the image again:
Image

Please, make sure to allow only 1 IDE instance at one (see you preferences).
PB 4.30

Code: Select all

onErrorGoto(?Fred)
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

ts-soft wrote:
byo wrote:Nothing happens when I try to run your EXE. :)
This program runs only as plugin of the pb-ide! Correct config is required.
Or your code have no Includes?
My mistake. I saw your window and missed the word "IDE".
I need some sleep badly. :lol:
Post Reply