SourecCode Header Generator (by ts-soft) adapted by Zebuddi

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

SourecCode Header Generator (by ts-soft) adapted by Zebuddi

Post by Zebuddi123 »

Thanks to to Thomas (ts-soft) for this handy IDE tool. I have adapted it for my own needs, as i like to use the code from the forum to learn from and most always save the source as there is always something useful therein. But i have to admit i`m lazy when it comes to commenting and detailing where the source came from and the author etc :oops: so when ts dropped this on the forum i rubbed my hands thinking at last i can keep track of the source codes i`ve gotten over time :D so i added some of the things i wanted to be useful to me ( brain like a sieve most of the time :lol: )

added small gui on creating a new file

Image

on new file
Image

on complete
Image

On new file you can fill the author title and version etc you can also add the url by clicking on the active url tab in the browser ( Firefox only at the moment sorry ) which is what i do for the code i download
this give me the link author etc in case i wish to look things up in the future.

Should you just close the gui then a standard details header is written instead

to have the url inserted into the header you must check the download from the internet checkbox

should you fail to click a titlebar and leave the web link blank a requester will pop up to remind you

you can also fill the web link by hand should you want to

; Configure tool as
;
; Commandline: select this tool
; Argument`s: "%TEMPFILE"
; Trigger: "New Sourcecode created"
; [x] Wait until tool quits
; [x] Reload Source after tool has quit
; (x) into current source
; [x] Hide tool from the Main menu
;

Example:

Code: Select all

; COMPILER OPTIONS:
;  [ ] Enable inline ASM support
;  [ ] Create unicode executable
;  [ ] Create threadsafe executable
;  [ ] Enable OnError lines support
;  [x] Enable XP skin support
;  [ ] Request Administrator mode for Windows Vista
;  [ ] Request User mode for Windows Vista (no virtualization)
; Library Subsystem:  
; File Format:        ASCII
; Executable Format:  Windows
;
; Created on:         16/10/2012 18:34
; App/Lib-Name:       PureBasic Source Code Header Generator ( modified by Zebuddi.)
; Author:             ts-soft
; Version:            0.2
; Compiler:           PureBasic 5.00 Beta 4 (Windows - x86)
; Source Code From :           Example Source Code Downloaded From The Internet
; Web Link:  http://forum.purebasic.com/english/viewtopic.php?p=223023
; ==============================================================

Code: Select all

; ==============================================================
; COMPILER OPTIONS:
;  [ ] Enable inline ASM support
;  [ ] Create unicode executable
;  [ ] Create threadsafe executable
;  [ ] Enable OnError lines support
;  [x] Enable XP skin support
;  [ ] Request Administrator mode for Windows Vista
;  [ ] Request User mode for Windows Vista (no virtualization)
; Library Subsystem:  
; File Format:        ASCII
; Executable Format:  Windows
;
; Created on:         16/10/2012 18:34
; App/Lib-Name:       PureBasic Source Code Header Generator ( modified by Zebuddi.)
; Author:             ts-soft
; Version:            0.2
; Compiler:           PureBasic 5.00 Beta 4 (Windows - x86)
; Source Code From :           Example Source Code Downloaded From The Internet
; Web Link:  http://forum.purebasic.com/english/viewtopic.php?p=223023
; ==============================================================

EnableExplicit
EnableExplicit
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#CHILDID_SELF = 0

; #APP_NAME_DEFAULT$ = "Example"
#AUTHOR_DEFAULT$ = "B.S.D Innovative App`s"
; #VERSION_DEFAULT$ = "0.0"

Procedure.s GetPBCompilerVersion()
	Protected Compiler, result.s
	CompilerSelect #PB_Compiler_OS
		CompilerCase #PB_OS_Windows
			Compiler = RunProgram(GetEnvironmentVariable("PB_TOOL_Compiler"), "/STANDBY", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Hide)
		CompilerDefault
			Compiler = RunProgram(GetEnvironmentVariable("PB_TOOL_Compiler"), "--standby", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Hide)
	CompilerEndSelect
	If Compiler
		result = StringField(ReadProgramString(Compiler), 3, #TAB$)
		WriteProgramStringN(Compiler, "END")
		CloseProgram(Compiler)
	EndIf
	ProcedureReturn result
EndProcedure

Procedure.s ReadPBPrefs(group.s, key.s)
	Protected result.s, prefs.s = GetEnvironmentVariable("PB_TOOL_Preferences")
	
	If OpenPreferences(prefs)
		PreferenceGroup(group)
		result = ReadPreferenceString(key, "")
		ClosePreferences()
	EndIf
	ProcedureReturn result
EndProcedure


;{ /////////////////////////////////////////////////////////
;{ ------------------------------------------------------
Enumeration
	#Window_0
EndEnumeration

Enumeration
	#Window_0_Text0_Title
	#Window_0_Text1_Version
	#Window_0_Text5_Author
	#Window_0_String6_6
	#Window_0_String2_2
	#Window_0_String3_3
	#Window_0_Text8_WebAddress
	#Window_0_String_WebAddress
	#Window_0_CheckBox8_ExampleCodeDownloadedFromInternet
	#Window_0_Button6_Done
	
EndEnumeration
;}

Procedure WinEventFunc(HookHandle.l, LEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
	Static oldurl$,Uni$,url$,Asc$,bstr.l,len.l
	Protected oba.IAccessible
	Define v.VARIANT
	If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @oba, @v.VARIANT) = #S_OK
		v\vt = #VT_I4
		v\lVal = #CHILDID_SELF
		; ...Prepare a spot for the bstr
		Asc$ = Space(#MAX_PATH)
		Uni$ = Space(#MAX_PATH*2+2)
		MultiByteToWideChar_(#CP_ACP, 0, @Asc$, -1, @Uni$, Len(Asc$)*2+2)
		bstr = SysAllocString_(@Uni$)
		; ...Put the returned value in it
		If oba\get_accValue(v, @bstr) = #S_OK
			; ...Convert the bstr into an ascii string
			len = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0)
			url$ = Space(len)
			WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, @url$, len, 0, 0)
			; ...See if it contains a URL
			If Left(url$,4) = "http"
				If url$<>oldurl$
					oldurl$ = url$
					SetGadgetText(#Window_0_String_WebAddress,url$)
					;AddGadgetItem(1, -1, url$)
				EndIf
			EndIf
		EndIf
		SysFreeString_(bstr)
	EndIf
	
EndProcedure


Procedure OpenWindow_Window_0()
	If OpenWindow(#Window_0,  854, 395, 400, 139, "Pure Source File Setup", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_WindowCentered|#PB_Window_ScreenCentered)		 
		StringGadget(#Window_0_String6_6, 50, 10, 335, 20, "", #ES_CENTER)
		StringGadget(#Window_0_String2_2, 50, 40, 335, 20, "", #ES_CENTER)
		StringGadget(#Window_0_String3_3, 50, 65, 50, 20, "", #ES_CENTER)
		CheckBoxGadget(#Window_0_CheckBox8_ExampleCodeDownloadedFromInternet, 115, 70, 220, 15, "Example Code Downloaded From Internet")
		StringGadget(#Window_0_String_WebAddress, 10, 110, 377, 20, "", #ES_CENTER)
		ButtonGadget(#Window_0_Button6_Done, 345, 70, 40, 20, "Done")
		
		TextGadget(#Window_0_Text0_Title, 5, 40, 40, 15, "Title", #PB_Text_Center)
		TextGadget(#Window_0_Text1_Version, 10, 70, 40, 15, "Version", #PB_Text_Center)
		TextGadget(#Window_0_Text5_Author, 5, 10, 40, 15, "Author", #PB_Text_Center)
		TextGadget(#Window_0_Text8_WebAddress, 165, 90, 70, 15, "Web Address", #PB_Text_Center)
	EndIf
EndProcedure

;{------------------------------------------------------
Global gettitle$, getversion$, getaurthor$, geturl$,  xx, dfi$
OpenWindow_Window_0()
Define hdll.l, eHook.l,result.b
hdll = OpenLibrary(0, "Oleacc.dll")
SetActiveGadget(#Window_0_String6_6)
eHook = SetWinEventHook_(1, #MAXWORD, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT | #WINEVENT_SKIPOWNPROCESS)
Repeat
	Select WaitWindowEvent()
			; ///////////////////
		Case #PB_Event_Gadget
			Select EventGadget()
				Case #Window_0_Button6_Done
					
					getaurthor$=GetGadgetText(#Window_0_String6_6)
					If getaurthor$="": getaurthor$=#AUTHOR_DEFAULT$: EndIf
					
					gettitle$=GetGadgetText(#Window_0_String2_2)
					If gettitle$="" :  gettitle$="Example" : EndIf
					
					getversion$=GetGadgetText(#Window_0_String3_3)
					If getversion$="": getversion$="0.0": EndIf
					
					xx=GetGadgetState(#Window_0_CheckBox8_ExampleCodeDownloadedFromInternet)
					CallDebugger
					If xx=1 
						dfi$="Example Source Code Downloaded From The Internet"
						geturl$=GetGadgetText(#Window_0_String_WebAddress)
						If xx = 1 And Len(geturl$)=0
							result=MessageRequester("Get Web Link","Click On The WebLink To Grab Url",#MB_ICONINFORMATION| #PB_MessageRequester_YesNo)
							If    result = #PB_MessageRequester_No
								geturl$="Web Link Not Specified"
								CloseWindow(#Window_0)
								Break
							EndIf
						EndIf
						If Len(geturl$)>0
							CloseWindow(#Window_0)
							Break
						EndIf
					Else
						CloseWindow(#Window_0)
						Break
					EndIf
					
					
					
			EndSelect
			; ////////////////////////
		Case #PB_Event_CloseWindow
			Select EventWindow()
				Case #Window_0
					CloseWindow(#Window_0)
					If eHook
						UnhookWinEvent_(eHook)
					EndIf
					If hdll
						CloseLibrary(0)
					EndIf
					Break
			EndSelect
	EndSelect
ForEver
;}----------------------------------------------------------------------------
;}//////////////////////////////////////////////



;{
Define.s File = ProgramParameter()
Define FF, Format
FF = CreateFile(#PB_Any, File)
If FF
	Select ReadPBPrefs("CompilerDefaults", "TextEncoding")
		Case "1"
			Format = #PB_UTF8
		Default
			Format = #PB_Ascii
	EndSelect
	WriteStringFormat(FF, Format)
	WriteStringN(FF, "; ==============================================================", Format)
	WriteStringN(FF, "; COMPILER OPTIONS:", Format)
	Select ReadPBPrefs("CompilerDefaults", "InlineASM")
		Case "0"
			WriteStringN(FF, ";  [ ] Enable inline ASM support", Format)
		Default
			WriteStringN(FF, ";  [x] Enable inline ASM support", Format)
	EndSelect
	Select ReadPBPrefs("CompilerDefaults", "Unicode")
		Case "0"
			WriteStringN(FF, ";  [ ] Create unicode executable", Format)
		Default
			WriteStringN(FF, ";  [x] Create unicode executable", Format)
	EndSelect
	Select ReadPBPrefs("CompilerDefaults", "Thread")
		Case "0"
			WriteStringN(FF, ";  [ ] Create threadsafe executable", Format)
		Default
			WriteStringN(FF, ";  [x] Create threadsafe executable", Format)
	EndSelect
	Select ReadPBPrefs("CompilerDefaults", "OnError")
		Case "0"
			WriteStringN(FF, ";  [ ] Enable OnError lines support", Format)
		Default
			WriteStringN(FF, ";  [x] Enable OnError lines support", Format)
	EndSelect
	CompilerIf #PB_Compiler_OS = #PB_OS_Windows
		Select ReadPBPrefs("CompilerDefaults", "XPSkin")
			Case "0"
				WriteStringN(FF, ";  [ ] Enable XP skin support", Format)
			Default
				WriteStringN(FF, ";  [x] Enable XP skin support", Format)
		EndSelect
		Select ReadPBPrefs("CompilerDefaults", "VistaAdmin")
			Case "0"
				WriteStringN(FF, ";  [ ] Request Administrator mode for Windows Vista", Format)
			Default
				WriteStringN(FF, ";  [x] Request Administrator mode for Windows Vista", Format)
		EndSelect
		Select ReadPBPrefs("CompilerDefaults", "VistaUser")
			Case "0"
				WriteStringN(FF, ";  [ ] Request User mode for Windows Vista (no virtualization)", Format)
			Default
				WriteStringN(FF, ";  [x] Request User mode for Windows Vista (no virtualization)", Format)
		EndSelect
	CompilerEndIf
	WriteStringN(FF, "; Library Subsystem:  " + ReadPBPrefs("CompilerDefaults", "SubSystem"), Format)
	Select ReadPBPrefs("CompilerDefaults", "TextEncoding")
		Case "1"
			WriteStringN(FF, "; File Format:        UTF-8", Format)
		Default
			WriteStringN(FF, "; File Format:        ASCII", Format)
	EndSelect
	CompilerIf #PB_Compiler_OS = #PB_OS_Windows
		Select ReadPBPrefs("CompilerDefaults", "ExeFormat")
			Case "1"
				WriteStringN(FF, "; Executable Format:  Console", Format)
			Case "2"
				WriteStringN(FF, "; Executable Format:  Shared DLL", Format)
			Default
				WriteStringN(FF, "; Executable Format:  Windows", Format)
		EndSelect
	CompilerElse
		Select ReadPBPrefs("CompilerDefaults", "ExeFormat")
			Case "1"
				WriteStringN(FF, "; Executable Format:  Console", Format)
			Case "2"
				WriteStringN(FF, "; Executable Format:  Shared .so", Format)
			Default
				WriteStringN(FF, "; Executable Format:  Linux", Format)
		EndSelect
	CompilerEndIf
	WriteStringN(FF, ";", Format)
	WriteStringN(FF, "; Created on:         " + FormatDate("%dd/%mm/%yyyy %hh:%ii", Date()), Format)
	WriteStringN(FF, "; App/Lib-Name:       " + gettitle$, Format)
	WriteStringN(FF, "; Author:             " + getaurthor$, Format)
	WriteStringN(FF, "; Version:            " + getversion$, Format)
	WriteStringN(FF, "; Compiler:           " + GetPBCompilerVersion(), Format)
	If xx=1
		WriteStringN(FF, "; Source Code From :           " + dfi$, Format)
		WriteStringN(FF,"; Web Link:  "+geturl$, Format)
		WriteStringN(FF, "; ==============================================================", Format)
	Else
		WriteStringN(FF, "; ==============================================================", Format)
	EndIf
	
	WriteStringN(FF, "", Format)
	WriteStringN(FF, "EnableExplicit", Format)
	WriteStringN(FF, "", Format)
	CloseFile(FF)
EndIf 
;}
Zebuddi. :D
Last edited by Zebuddi123 on Wed Feb 04, 2015 1:12 am, edited 1 time in total.
malleo, caput, bang. Ego, comprehendunt in tempore
Jeromyal
Enthusiast
Enthusiast
Posts: 216
Joined: Wed Jul 17, 2013 8:49 am

Re: SourecCode Header Generator (by ts-soft) adapted by Zebu

Post by Jeromyal »

Is there an updated version of this tool that works with PB5.20?
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: SourecCode Header Generator (by ts-soft) adapted by Zebu

Post by Bisonte »

this work with all pb versions since 5.0
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Post Reply