Portable PB with resource files

Share your advanced PureBasic knowledge/code with the community.
User avatar
Michael Vogel
Addict
Addict
Posts: 2808
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Portable PB with resource files

Post by Michael Vogel »

Using PB on a memory stick is fine because of the /portable option, the only problem is using resources (like multiple program icons etc.) in the compiler options. When doing so, the changing drive letter could be annoying...

I wrote a simple tool which have to be added to the PB IDE, after doing so, a resource file of assigned to the actual source code will be scanned and the drive letters will be changed to the correct value.

Code: Select all

Source.s=ProgramParameter()

Drive.s=UCase(Left(Source,3))
Resource.s
Backup.s

If Mid(Drive,2,2)=":\"

	If ReadFile(#True,Source)

		While Eof(#True)=#False
			Line.s=ReadString(#True)
			If PeekA(@Line)=';'
				If Left(Line,15)="; AddResource ="
					Resource=Trim(Mid(Line,16))
				EndIf
			EndIf
		Wend
		CloseFile(#True)

		If Resource

			If Left(Resource,1)="\" Or Mid(Resource,2,1)=":"
				Debug resource
				MessageRequester("Panik","Illegal resource file definition."+#CR$+"Please use relative path for your resource file definitions.")
			Else
				Resource=GetPathPart(Source)+Resource
				Backup=GetExtensionPart(Resource)
				Backup=Left(Resource,Len(Resource)-Len(GetExtensionPart(Resource)))+"bak"
				DeleteFile(Backup)
				If FileSize(Resource)>#True
					If RenameFile(Resource,Backup)
						If CreateFile(#True,Resource) And ReadFile(#False,Backup)
							While Eof(#False)=#False
								Line.s=ReadString(#False)
								n=FindString(Line," ICON ")
								If n
									n+5
									If PeekA(@Line+n)='"'
										n+1
									EndIf
									If PeekA(@Line+n+1)=':'
										PokeA(@Line+n,PeekA(@Drive))
									EndIf
								EndIf
								Debug Line
								WriteStringN(#True,Line)
							Wend
							CloseFile(#False)
							CloseFile(#True)
							MessageRequester("Ok","Modified resource file.",#MB_ICONINFORMATION|#MB_OK)
						Else
							MessageRequester("Panik","Could not write a new resource file"+#CR$+"'"+Resource+"'.")
						EndIf
					Else
						MessageRequester("Panik","Could not create a backup for the resource file"+#CR$+"'"+Resource+"'.")
					EndIf
				Else
					MessageRequester("Panik","Could not locate the resource file"+#CR$+"'"+Resource+"'.")
				EndIf
			EndIf

		Else
			MessageRequester("Panik","No resource file defined."+#CR$+"Compiler options / Resources")
		EndIf

	EndIf

Else
	MessageRequester("Panik","Wrong tool configuration."+#CR$+"Please use ''%FILE'' as start parameter.",#MB_ICONERROR|#MB_OK)
	
EndIf
User avatar
OldSkoolGamer
Enthusiast
Enthusiast
Posts: 150
Joined: Mon Dec 15, 2008 11:15 pm
Location: Nashville, TN
Contact:

Re: Portable PB with resource files

Post by OldSkoolGamer »

Thanks for this, very handy. Gets tiring having to manually do this every time...
Post Reply