05-17-2023, 11:20 PM
(05-17-2023, 08:11 PM)thesolarcode Wrote: Trying to implement version string per library.
I don't want to have for each library a separate CONST or SUB/FUNCTION with different name just to get it's version string.
I also don't want to hardcode the library names and versions in a single place.
DATA / READ / RESTORE doesn't work, because RESTORE doesn't accept a variable.
Any ideas how I could implement this?
Here's a prototype how I'd do it, it's certainly not bulletproof, but should work as an example to build your own.
Save as "Versions.bas"
Code: (Select All)
'Example for multiple embedded version strings.
_TITLE "Versions"
'The idea is to embed clearly identifyable strings into the compiled EXE.
'Each library defines its version string either globally in the .bi file or
'locally in any of the library's functions in the .bm file.
'Don't use CONSTs here, as CONSTed strings will not be embedded into the
'EXE per define, but only if the CONST would be actually assigned to a variable.
MY$ = "$VER: my.library 1.0 (17.05.23) Copyright (c) 2023 by Me :END$"
YOUR$ = "$VER: your.library 1.0 (17.05.23) Copyright (c) 2023 by You :END$"
OTHER$ = "$VER: other.library 1.0 (17.05.23) Copyright (c) 2023 by Whoever :END$"
COLOR 12: PRINT "This program makes use of the following modules/libraries:"
COLOR 15: PrintEmbeddedVersions "" 'empty or "ALL" to print all
PRINT
COLOR 12: PRINT "your.lib version is:"
COLOR 15: PrintEmbeddedVersions "your.lib" 'any unique part string will do
COLOR 7
END
'This SUB loads the programs own EXE into a string and searches for
'the embedded strings.
SUB PrintEmbeddedVersions (which$) 'empty = "ALL"
OPEN "Versions.exe" FOR BINARY AS #1
exe$ = SPACE$(LOF(1))
GET #1, , exe$
CLOSE #1
IF which$ = "" THEN wch$ = "ALL": ELSE wch$ = which$ 'check and avoid side effect on argument
vPos& = 0: vEnd& = 0
DO
vPos& = INSTR(vEnd& + 1, exe$, UCASE$("$ver: ")) 'see notes below
IF vPos& > 0 THEN
vEnd& = INSTR(vPos& + 1, exe$, UCASE$(" :end$")) 'see notes below
IF vEnd& > 0 THEN
vStr$ = MID$(exe$, vPos& + 6, vEnd& - vPos& - 6)
IF UCASE$(wch$) = "ALL" OR INSTR(vStr$, wch$) > 0 THEN PRINT vStr$
END IF
END IF
LOOP UNTIL vPos& = 0
END SUB
'You may wonder about the UCASE$ usage, when we could simply write the search
'string in uppercase as we use it in the actual version strings. Well, these
'search strings are also embedded in the EXE and would be misinterpreted as
'another version string with random (binary) content in between. With the use
'of UCASE$ and the lowercase writing we avoid this, as the lowercase text is
'actually embedded in the EXE, but the SUB searches only for the uppercase
'appearances of the strings.
GuiTools, Blankers & other Projects:
https://staging.qb64phoenix.com/forumdisplay.php?fid=32
Libraries & useful Functions:
https://staging.qb64phoenix.com/forumdisplay.php?fid=23
https://staging.qb64phoenix.com/forumdisplay.php?fid=32
Libraries & useful Functions:
https://staging.qb64phoenix.com/forumdisplay.php?fid=23