Results 1 to 11 of 11

Thread: VB6 SQL-queryable Resources, based on ZipContainer-Files

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    VB6 SQL-queryable Resources, based on ZipContainer-Files

    This Demo has a dependency to RC6 (but would work with RC5 as well).

    The framework-dependency was included, to be able to conveniently "Select" resource-data via SQL -
    (from the ZipFile - InMemory... possible via the SQLite-ZipExtension which maps a Zip-archive to a virtual table).

    The Project contains a modMain.bas Startup-module, which ensures:
    - an AppDB (currently InMemory, but can be easily changed to a FileDB to persist also other AppData)
    - in IDE-mode, the .\Res\-Subfolder is the leading data-source (a Res.zip will be re-created on each App-Startup in the IDE)
    - in compiled mode, the App will instead fill the AppDBs "Res"-table directly from Res.zip
    .. (so the \Res\-Subfolder does not have to be deployed)

    So, whilst your Project is still in development, you simply enhance or update new content behind your \Res\-Subfolder.
    The auto-refreshing of the Res.zip in your ProjectFolder (at each test-run in the IDE) eases a few worries,
    whether the Zip-content matches with the content in your \Res\-Subfolder or not.


    Here the output of the SQL-based resource-readouts on the Test-Form:


    And here the zipped Demo-Code:
    ZipResourceHandling.zip

    Have fun,

    Olaf

  2. #2
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    get filenane list in zip?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Quote Originally Posted by xiaoyao View Post
    get filenane list in zip?
    The output in the upper half of my ScreenShot in #1, is based on:
    - Select * From Res ... ( AppDB.GetTable("Res") under the covers resolves to that "Full-Table-Select" SQL-string)
    So the returned Rs contains the Name-Field (beside all other Fields in table "Res")

    If you want to restrict the FieldList to "just the Name-Column of table Res",
    then of course you can retrieve an Rs with only that single Field in it, via:
    - Set Rs = AppDB.GetRs("Select Name From Res")

    Olaf

  4. #4
    Lively Member
    Join Date
    Oct 2014
    Posts
    93

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Chinese path will be wrong:
    Attached Images Attached Images  

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Quote Originally Posted by smileyoufu View Post
    Chinese path will be wrong:
    The ZipFile-extension (when FilePath's are passed) does not seem to support UTF8-Paths (like the rest of SQLite)...
    Will look into it in the appropriate C-Extension-Module later...

    But it's easy to work-around (for "Resource-Sized ZipFiles", which normally aren't that large) -
    when you load them with a New_c.FSO method into a ByteArray (RC5/RC6.cFSO is completely unicode-aware).

    Just pass the Parameter as a ByteArray directly (instead of the FileName-PathString), like this:
    Code:
    AppDB.ExecCmd "Insert Into Res Select Name, DateTime(mTime,'unixepoch'), Data, sz From ZipFile(?)", _
                   New_c.FSO.ReadByteContent(App.Path & "\Res.zip")
    HTH

    Olaf

  6. #6
    Lively Member
    Join Date
    Oct 2014
    Posts
    93

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Quote Originally Posted by Schmidt View Post
    The ZipFile-extension (when FilePath's are passed) does not seem to support UTF8-Paths (like the rest of SQLite)...
    Will look into it in the appropriate C-Extension-Module later...

    But it's easy to work-around (for "Resource-Sized ZipFiles", which normally aren't that large) -
    when you load them with a New_c.FSO method into a ByteArray (RC5/RC6.cFSO is completely unicode-aware).

    Just pass the Parameter as a ByteArray directly (instead of the FileName-PathString), like this:
    Code:
    AppDB.ExecCmd "Insert Into Res Select Name, DateTime(mTime,'unixepoch'), Data, sz From ZipFile(?)", _
                   New_c.FSO.ReadByteContent(App.Path & "\Res.zip")
    HTH

    Olaf
    Olaf, thank you very much
    ……New_c.FSO.ReadByteContent(App.Path&“ \ Res.zip”) 'It runs normally under the Chinese path

    Please tell me: How to add (.svg .svgz .png .ico ,jpg……) pictures in the Res.zip file to Cairo.ImageList and access them globally through picture keywords

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Quote Originally Posted by smileyoufu View Post
    How to add (.svg .svgz .png .ico ,jpg……) pictures in the Res.zip file to Cairo.ImageList and access them globally through picture keywords
    Generally, you can access the Zip-Contents via appropriate SQL-queries
    (as shown already in the Demo-Source in the opener-post)...

    And a proper SQL-String for your case (to select all image-resources, no matter from what Res\SubFolder), would be:

    Select * From Res Where Right$(Name, 4) In ('.png','.jpg','.svg','svgz','.ico')

    (the blue marked expression being the Left-hand-side, the magenta-colored part the Right-hand-side of the Where-condition).

    After you retrieved the appropriate Rs via the above SQL, you can do a loop over it -
    and then simply add to the Cairo.ImageList (under the "bare short-file-name" as the Key):
    Code:
    Private Sub AddImageResourcesToImageList()
      Dim Rs As cRecordset, Name As String, Key As String
      Set Rs = AppDB.GetTable("Res", "Right$(Name, 4) In ('.png','.jpg','.svg','svgz','.ico')")
      Do Until Rs.EOF
        Name = Replace(Rs!Name, "/", "\") 'make the relative Path-Strings "Win-Compatible"
        Key = New_c.FSO.GetFileNameFromFullPath(Name, True) 'cut-out the short name (without extension)
        Key = IIf(InStr(1, Name, "LowRes\", vbTextCompare), "lr_", "") & Key
        If InStr(1, Name, ".ico", vbTextCompare) Then 'icon-bytes require a different loading-call
           Cairo.ImageList.AddIconFromByteArray Key, Rs!Data.Value
        Else 'all other image-types ('.png','.jpg','.svg','svgz') can use the AddImage-method
           Cairo.ImageList.AddImage Key, Rs!Data.Value
        End If
        Rs.MoveNext
      Loop
    End Sub
    You can test the above routine e.g. by placing the following at the end of Form_Load in the original Demo-Zip:
    Code:
      Call AddImageResourcesToImageList()
      With Cairo.ImageList
        Dim i As Long
        For i = 0 To .Count - 1
          If Len(.KeyByIndex(i)) Then Debug.Print .KeyByIndex(i), " (" & .ItemByIndex(i).Width & "x" & .ItemByIndex(i).Height & ")"
        Next
      End With
    And the above Form_Load-addition should now produce the following Debug-Output:
    Code:
    app_exit       (128x128)
    db_add         (128x128)
    digikam        (128x128)
    fileprint      (128x128)
    lr_app_exit    (22x22)
    lr_db_add      (22x22)
    lr_digikam     (32x32)
    lr_fileprint   (22x22)
    Note, that I've used similar "short-names" for the Demos ImageResources (in a \HighRes\ and in a \LowRes\ SubFolder as well).

    In the routine which does the ImageList-adding above, I've prepared "normal Keys" for all HighRes-images -
    and only for Images which came from the LowRes-Subfolder, I've added an "lr_" prefix on the ImageKey...

    HTH

    Olaf

  8. #8
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Sometimes we need to load some different strings, represented by the value of Key.

    It is very troublesome to write many lines in the code.
    Key names, categories, strings, other languages, basically. More than four fields are required.It would be great if you could gradually add these features.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Quote Originally Posted by xiaoyao View Post
    Sometimes we need to load some different strings, represented by the value of Key.

    It is very troublesome to write many lines in the code.
    Key names, categories, strings, other languages, basically. More than four fields are required.It would be great if you could gradually add these features.
    I don't see where the problem is...

    The FileName of any File in the \Res\ Folder (relative to the App.Path of the Project or Executable),
    is later reflected 1:1 in the Name-Field of the returned Recordset (its relative "FullPath", just with "/" instead of "").

    It is up to you, to write a few convenience-functions around the Recordset-based retrieval of differently named resources.

    If you want additional *Tables* in your AppDB-Object (not only the [Res] Table which hosts the Folder-Content),
    then simply add them in one line of code to your AppDB yourself, as e.g. a Language-Table via:

    AppDB.Exec "Create Table If Not Exists Lang(Key Text Collate NoCase Primary Key, DE Text, EN Text, CN Text)"
    (the above Table already prepared for german, english and chinese Language-Texts, accessable via a Key-Field)

    Note, that AppDB could also be loaded from an existing FileDB, which you place (and ship later) e.g. in your App-Path
    (not each and everything has to be placed as a File in the Res-Folder itself).

    Olaf
    Last edited by Schmidt; May 9th, 2021 at 07:25 AM.

  10. #10
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Sqlite. You can select a local data file to load into the in-memory database. How do I load an in-memory database directly from a resource file without needing a file? Sqlite3.dll, do you still have this function? After the modification is completed in the memory, he can also re-save a new DB file? Or directly into the exe inside?

  11. #11
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: VB6 SQL-queryable Resources, based on ZipContainer-Files

    Is there any function that can add the file directly to exe? You can read it. Modify it, how to write it in before closing the software?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width