Page 1 of 1

Resident-Maker

Posted: Mon Mar 25, 2013 8:13 pm
by uwekel
Hi,

here is a little tool to make resident files by ease. First you have to create an executable from this code. Afterwards please add an entry in the tools menu which points to the executable and set %FILE as argument. By running this tool, the current source file will be compiled thru the resident maker and a *.res file will be saved in the resident folder. To let the created or changed resident take effect, you have at least to restart the compiler or restart the PB IDE. That's all.

Code: Select all

EnableExplicit

Define.s src, ext, nam, res, path, cmd, arg, out

#Title = "Resident-Creator"

;check if the filename was handed over
If CountProgramParameters() <> 1
  MessageRequester(#Title, "Use %FILE as argument.")
Else
  
  ;get src filename
  src = ProgramParameter()
  
  ;make resident name
  ext = "." + GetExtensionPart(src)
  nam = ReplaceString(GetFilePart(src), ext, ".res")
  
  ;OS relevant stuff
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    #Option = "/RESIDENT"
    #Separator = "\"
    #Residents = "Residents"
  CompilerElse
    #Option = "-r"
    #Separator = "/"
    #Residents = "residents"
    nam = LCase(nam)
  CompilerEndIf
  
  ;delete existing resource name
  res = #PB_Compiler_Home + #Residents + #Separator + nam
  If FileSize(res) >= 0 And Not DeleteFile(res)
    MessageRequester(#Title, "The Resident-File could not be deleted!")
  Else
    
    ;create startup parameters
    path = #PB_Compiler_Home + "compilers" + #Separator
    cmd = path + "pbcompiler"
    arg = #DQUOTE$ + src + #DQUOTE$ + " " + #Option + " " + #DQUOTE$ + res + #DQUOTE$
    
    ;compile
    Define p = RunProgram(cmd, arg, path, #PB_Program_Hide | #PB_Program_Open | #PB_Program_Read)
    If IsProgram(p)
      While ProgramRunning(p)
        If AvailableProgramOutput(p)
          out.s + ReadProgramString(p) + #CRLF$
        EndIf
      Wend
      CloseProgram(p)
    EndIf
    
    ;show output message
    MessageRequester(#Title, out)
    
  EndIf
  
EndIf
Best regards
Uwe

Re: Resident-Maker

Posted: Mon Mar 25, 2013 11:06 pm
by skywalk
Thanks!
Maybe add a few more lines if overwriting an existing residents file?
Help wrote:/IGNORERESIDENT "Filename": Doesn't load the specified resident file when the compiler starts. It's mostly useful when updating a resident which already exists, so it won't load it.

Re: Resident-Maker

Posted: Tue Mar 26, 2013 4:44 pm
by ABBKlaus
mevedia.de wrote:Where is the resulting Resident located? :D It tells me in "C:\Program Files (x86)\PB5\Residents\RES.res", but the File doesn't exist - but all Structures (except the recursive) are available. Can't remove it now anymore. :evil:
You need admin rights to write in these folders, now youve got virtualized :wink:

This link might help to find your residents :

http://support.microsoft.com/kb/927387

Re: Resident-Maker

Posted: Mon Feb 23, 2015 7:33 am
by StarBootics
Hello everyone,

Since I need something to create some resident files I have reworked the original code. Apparently the only way to use custom structure such as Vector2, Vector3, Vector4, Matrix22, Matrix33 and Matrix44 across many modules is to have them compiled as a resident file.

Best regards
StarBootics

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : ResidentCreator
; File Name : ResidentCreator.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : uwekel
; Modified by : StarBootics
; Date : 25-03-2013
; Last Update : 23-02-2015
; PureBasic code : V5.31
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

DeclareModule ResidentCreator
  
  Declare Initialize()
  Declare Run()
  Declare Reset()
  
EndDeclareModule

Module ResidentCreator
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    #Option = "/RESIDENT"
    #Separator = "\"
    #Residents = "Residents"
  CompilerElse
    #Option = "-r"
    #Separator = "/"
    #Residents = "residents"
  CompilerEndIf
  
  #Title = "Resident-Creator"
	
  Structure Instance
    
    Source.s
    Extension.s
    Name.s
    Path.s
    ResidentFile.s
    CompilerFile.s
    Command.s
    Argument.s
    
  EndStructure 
  
  Global Instance.Instance

  Procedure Initialize()

    If CountProgramParameters() <> 1
      MessageRequester(#Title, "Use " + Chr(34) + "%FILE" + Chr(34) + " as argument.")
      Reset()
      End
    Else
      
      ;get src filename
       Instance\Source = ProgramParameter()
      
      ;make resident name
      Instance\Extension = "." + GetExtensionPart(Instance\Source)
       
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        Instance\CompilerFile = "pbcompiler.exe"
        Instance\Name = ReplaceString(GetFilePart(Instance\Source), Instance\Extension, ".res")
      CompilerElse
        Instance\CompilerFile = "pbcompiler"
        Instance\Name = LCase(ReplaceString(GetFilePart(Instance\Source), Instance\Extension, ".res"))
      CompilerEndIf
      
      Instance\ResidentFile = GetEnvironmentVariable("PUREBASIC_HOME") + #Residents + #Separator + Instance\Name
      Instance\Path = GetEnvironmentVariable("PUREBASIC_HOME") + "compilers" + #Separator
      Instance\Command = Instance\Path + Instance\CompilerFile
      Instance\Argument = #DQUOTE$ + Instance\Source + #DQUOTE$ + " " + #Option + " " + #DQUOTE$ + Instance\ResidentFile + #DQUOTE$
      
    EndIf
    
  EndProcedure
  
  
  Procedure Run()
    
    If FileSize(Instance\ResidentFile) >= 0 And Not DeleteFile(Instance\ResidentFile)
      MessageRequester(#Title, "The Resident-File could not be deleted!")
      Reset()
      End
    Else
      
      Define p = RunProgram(Instance\Command, Instance\Argument , Instance\Path, #PB_Program_Hide | #PB_Program_Open | #PB_Program_Read)
      If IsProgram(p)
        While ProgramRunning(p)
          If AvailableProgramOutput(p)
            out.s + ReadProgramString(p) + #CRLF$
          EndIf
        Wend
        CloseProgram(p)
      EndIf
      
      MessageRequester(#Title, out)
      
    EndIf
    
  EndProcedure  
  
  Procedure Reset()
    
    Instance\Source = ""
    Instance\Extension = ""
    Instance\Name = ""
    Instance\Path = ""
    Instance\ResidentFile = ""
    Instance\CompilerFile = ""
    
  EndProcedure
  
EndModule

ResidentCreator::Initialize()
ResidentCreator::Run()
ResidentCreator::Reset()

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<

Re: Resident-Maker

Posted: Mon Feb 23, 2015 8:01 am
by Little John
StarBootics wrote:Apparently the only way to use custom structure [...] across many modules is to have them compiled as a resident file.
No, it isn't.
http://www.purebasic.com/documentation/ ... ludes.html
http://www.purebasic.com/documentation/ ... odule.html

For more information please search the forum, this has been discussed here repeatedly.

Re: Resident-Maker

Posted: Mon Feb 23, 2015 3:06 pm
by StarBootics
Little John wrote:
StarBootics wrote:Apparently the only way to use custom structure [...] across many modules is to have them compiled as a resident file.
No, it isn't.
http://www.purebasic.com/documentation/ ... ludes.html
http://www.purebasic.com/documentation/ ... odule.html

For more information please search the forum, this has been discussed here repeatedly.
I forget to mention that :
  • Without using a common Module
  • Without Including the same file in every module even with XInclude
OK my bad !

Best regards
StarBootics

Re: Resident-Maker

Posted: Sun Jun 09, 2024 10:27 am
by acreis
Great when we have a huge list of constants