Share your advanced PureBasic knowledge/code with the community.
uwekel
Enthusiast
Posts: 740 Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)
Post
by uwekel » Mon Mar 25, 2013 8:13 pm
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
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
skywalk
Addict
Posts: 4210 Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA
Post
by skywalk » Mon Mar 25, 2013 11:06 pm
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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
ABBKlaus
Addict
Posts: 1143 Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany
Post
by ABBKlaus » Tue Mar 26, 2013 4:44 pm
mevedia.de wrote: Where is the resulting Resident located?
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.
You need admin rights to write in these folders, now youve got virtualized
This link might help to find your residents :
http://support.microsoft.com/kb/927387
StarBootics
Addict
Posts: 1006 Joined: Sun Jul 07, 2013 11:35 am
Location: Canada
Post
by StarBootics » Mon Feb 23, 2015 7:33 am
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 <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
The Stone Age did not end due to a shortage of stones !
StarBootics
Addict
Posts: 1006 Joined: Sun Jul 07, 2013 11:35 am
Location: Canada
Post
by StarBootics » Mon Feb 23, 2015 3:06 pm
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
The Stone Age did not end due to a shortage of stones !
acreis
Enthusiast
Posts: 204 Joined: Fri Jun 01, 2012 12:20 am
Post
by acreis » Sun Jun 09, 2024 10:27 am
Great when we have a huge list of constants