' The MIT License (MIT)
'
' Copyright (C) 2026 Scott Duensing
'
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to
' deal in the Software without restriction, including without limitation the
' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
' sell copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
' IN THE SOFTWARE.

' resource.bas -- DVX Resource File Library for DVX BASIC
'
' Provides access to DVX resource blocks appended to binary
' files (.app, .wgt, .lib). Resources are named data entries
' of type icon, text, or binary.
'
' Usage: Add this file to your project.

CONST RES_TYPE_ICON   = 1
CONST RES_TYPE_TEXT   = 2
CONST RES_TYPE_BINARY = 3

DECLARE LIBRARY "basrt"
    ' Open a resource file for reading. Returns a handle (> 0)
    ' or 0 on failure. Close with ResClose when done.
    DECLARE FUNCTION ResOpen(BYVAL path AS STRING) AS LONG

    ' Close a resource handle.
    DECLARE SUB ResClose(BYVAL handle AS LONG)

    ' Return the number of resources in an open handle.
    DECLARE FUNCTION ResCount(BYVAL handle AS LONG) AS LONG

    ' Return the name of a resource by zero-based index.
    DECLARE FUNCTION ResName$(BYVAL handle AS LONG, BYVAL idx AS LONG)

    ' Return the type of a resource by zero-based index.
    ' Returns RES_TYPE_ICON (1), RES_TYPE_TEXT (2), or RES_TYPE_BINARY (3).
    DECLARE FUNCTION ResType(BYVAL handle AS LONG, BYVAL idx AS LONG) AS LONG

    ' Return the size in bytes of a resource by zero-based index.
    DECLARE FUNCTION ResSize(BYVAL handle AS LONG, BYVAL idx AS LONG) AS LONG

    ' Read a text resource by name. Opens and closes the file
    ' internally. Returns "" if not found.
    DECLARE FUNCTION ResGetText$(BYVAL path AS STRING, BYVAL resName AS STRING)

    ' Add or replace a text resource. Returns True on success.
    DECLARE FUNCTION ResAddText(BYVAL path AS STRING, BYVAL resName AS STRING, BYVAL text AS STRING) AS LONG

    ' Add or replace a resource from a file. Type should be
    ' RES_TYPE_ICON or RES_TYPE_BINARY. Returns True on success.
    DECLARE FUNCTION ResAddFile(BYVAL path AS STRING, BYVAL resName AS STRING, BYVAL resType AS LONG, BYVAL srcFile AS STRING) AS LONG

    ' Remove a resource by name. Returns True on success.
    DECLARE FUNCTION ResRemove(BYVAL path AS STRING, BYVAL resName AS STRING) AS LONG

    ' Extract a resource to a file. Returns True on success.
    DECLARE FUNCTION ResExtract(BYVAL path AS STRING, BYVAL resName AS STRING, BYVAL outFile AS STRING) AS LONG
END DECLARE
