DEMO: GLL, Editor Extension: Resource Manager
Aug 12, 2023 21:36:20 GMT 1
scalion and Roger Cabo like this
Post by (X) on Aug 12, 2023 21:36:20 GMT 1
I was pleasantly surprised (OK. I was ecstatic!) while playing around with GFA's GLL Editor Extensions to see what kind of management of the :Files section can be done.
This is just a proof of concept that could be part of some type of automation scheme built into the GFA Editor by you the coder. Feel free to modify and adapt this code to your liking.
One possible use might be to add several embedded text, image or audio resource files to your project. You should be able to automate this process all at the touch of a button.
If you didn't know...
Right from the start, without any of this code, you can already 'right click' on the :File section and Load, Delete, Rename: text, image, audio files and more into your program and they become embedded into the .G32 and .Exe files so they can be accessed as embedded resources (no external files!).
Usage Note:
If you want to manage a resource file with this GLL Editor Extension use the App+R or setup any other available shortcut key combination you prefer and select the Load, Delete or Undelete items in the popup menu.
You can load files and also choose which file to delete. The selected file will be removed from the :Files section and no longer be embedded in the program code.
If you are curious enough to look at the .G32 file with a hex editor you will see the 'embedded' data in compressed form at the end of the file.
As a precaution, a backup copy of the file will be saved in the current project folder with an ".undo" extension.
You can now Undelete the backed up file. The undeleted file should appear in the :Files section and disappear from the drive.
You can load files and also choose which file to delete. The selected file will be removed from the :Files section and no longer be embedded in the program code.
If you are curious enough to look at the .G32 file with a hex editor you will see the 'embedded' data in compressed form at the end of the file.
As a precaution, a backup copy of the file will be saved in the current project folder with an ".undo" extension.
You can now Undelete the backed up file. The undeleted file should appear in the :Files section and disappear from the drive.
The GFA Editor Extension GLL code:
You should be able to download this .G32 file and compile it: "Ctrl+E", the resulting .GLL file should be put into your "GFABASIC32\bin\" subdirectory, then added to the Editor as an Extension "Ctrl+M" gets you there fast, just Add it by selecting it from the "bin" subdir and you are good to go! APP+R while the cursor is in the code area should popup a menu to Load, Delete or Undelete a :File resource.
'#################################################################################
'
' DISCLAIMER: THIS CODE IS OFFERED AS IS FOR EDUCATIONAL PURPOSES.
' YOU ARE FREE TO USE, COPY AND DISTRIBUTE.
' THE USE OF THIS CODE IS AT YOUR OWN RISK.
' I ACCEPT NO LIABILITY NOR MAKE ANY CLAIM OF
' CORRECTNESS OR SUITABILITY IN PART OR IN WHOLE.
'
'#################################################################################
'
' FILENAME GFA_APP_R__ResourceManager.G32
'
' DESCRIPTION A demo of ":File" Resource Management available from the GFA's GLL
' Editor Extension. When editing the code, "App+R" calls up a popup
' menu that offers:{Load, Delete and Undelete} of ":Files" (text,
' image, sound...) which are embedded into the <App.Name>.G32
' GFA-BASIC 32 for Windows file and when compiled, the <App.Name>.EXE
' program file.
'
' AUTHOR (X)
' EMAIL xman.gb32@gmail.com
' WEBSITE https://gfabasic32.blogspot.com/
' FORUM https://gb32.proboards.com/
' STARTED 2023-08-12
' UPDATED <ISO date>
'
'
Sub Gfa_Init
EndSub
Sub Gfa_App_R // R for Resource
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Can you save a file to the :Files section as a resource from GLL?
' Apparently yes.
'
' What if you want to erase a :File? You can do that too!
'
Select PopUp(":File Manager|Load|Delete|UnDelete", 0, 0, -5)
Case 0 // Do Nothing...
Case 1 // Load File...
P_Load_File
Case 2 // Delete :File...
P_Delete_File
Case 3 // Restore :File
P_Undelete_File
EndSelect
EndSub
Proc P_Load_File
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Select :File to load...
'
Dim pfn$ = F_FileSelect("*.*")
If (pfn$ <> "")
°Trace F_FileName(pfn$)
°Trace F_NoExtFileName(F_FileName(pfn$))
Dim inlfn$ = ":" & F_NoExtFileName(F_FileName(pfn$))
°Trace inlfn$
Gfa_CopyFile pfn$, inlfn$
Else
Message "No file was selected."
EndIf
EndProc
Proc P_Delete_File
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Select :File to delete...
'
Dim a%, inlfn$, undofn$
Dim i% = 1 , pum$ = ""
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Populate the file listing of inline files into a Popup menu...
'
Do
°Trace i
°Trace Gfa_InlFileName(i)
If (Gfa_InlFileName(i) == "") Exit Do
pum$ = pum$ & Gfa_InlFileName(i) & "|"
i++
Loop
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Add the last menu entry in case user wants to undelete a file...
'
pum$ = pum$ & "Exit"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Show available resource files to delete in a Popup menu...
'
a% = PopUp(pum$, 0, 0, -5)
Dim fi% = a% + 1
°Trace fi
If (fi => 1) And (fi <= (i - 1))
inlfn$ = Gfa_InlFileName(fi)
If (inlfn$ <> "")
°Trace inlfn$
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Save an undo file; inlfn$ minus the ":" prefix, plus an ".undo" suffix...
' To copy the data from the inline resource section to a normal file use
' CopyFile.
'
undofn$ = App.Path & "\" & F_NoLeadingColon(inlfn$) & ".undo"
°Trace undofn$
CopyFile inlfn$, undofn$
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Delete the file from resource :Files section...
' To delete an entry in the ":Files" tab specify the empty string for src$ and
' its resource name is dest$.
Gfa_CopyFile "", inlfn$
EndIf
EndIf
EndProc
Proc P_Undelete_File
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Select :File to restore...
'
Dim pfn$ = F_FileSelect("*.undo")
°Trace pfn$
If (pfn$ <> "")
Dim inlfn$ = ":" & F_NoExtFileName(F_FileName(pfn$))
°Trace inlfn$
Gfa_CopyFile pfn$, inlfn$
KillFile Silent, pfn$
EndIf
EndProc
Function F_FileSelect(filter$) As String
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Opens a FileSelect dialog for current application path...
'
Dim d$ = App.Path, n$
FileSelect # "Select file", d$ & "\" & filter$, "", n$
If Len(n$)
If Right$(n$) = "\"
'Message "You haven't selected a file."
Return ""
Else
Return n$
EndIf
Else
'Message "The Cancel button was clicked."
Return ""
EndIf
EndFunc
Function F_FileName(pfn$) As String
Return Mid(pfn$, RInStr(pfn$, "\") + 1)
EndFunc
Function F_NoExtFileName(fn$) As String
Return Left(fn$, RInStr(fn$, ".") - 1)
EndFunc
Function F_NoLeadingColon(fn$) As String
If Left(fn$, 1) == ":"
Return SubStr(fn$, 2)
Else
Return fn$
EndIf
EndFunc
You should be able to download this .G32 file and compile it: "Ctrl+E", the resulting .GLL file should be put into your "GFABASIC32\bin\" subdirectory, then added to the Editor as an Extension "Ctrl+M" gets you there fast, just Add it by selecting it from the "bin" subdir and you are good to go! APP+R while the cursor is in the code area should popup a menu to Load, Delete or Undelete a :File resource.