Page 3 of 3

Re: PureDataConverter

Posted: Mon Nov 19, 2012 5:41 am
by jassing
Damion12 wrote:I was using this in large file data, and am having problems compiling -- reading docs, says that I should be using the .res format - but then how do I add this to my PB project file so I can access it?

Code: Select all

Import "MyFile.res"
endimport
XIncludeFile "UDRes_Include.pbi"

h = LoadLibraryM(UDRes_Get(1))
f = GetProcAddressM(h,"MyFunction")
CallFunctionFast(f)

Re: PureDataConverter

Posted: Wed Jul 24, 2013 7:11 pm
by Thorsten1867
Unter PureBasic 5.1x macht "UDRes_Include.pbi" Probleme.

Für unkomprimierte Resource-Dateien funktioniert es mit folgendem Code:

Code: Select all

;{
; Version 1.1
;
; Copyright (c) 2008 by Thomas Schulz / ts-soft@web.de
; http://www.realsource.de
;
; The contents of this file are subject To the Mozilla Public License Version
; 1.1 (the "License"); you may not use this file except in compliance with
; the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS" basis,
; WITHOUT WARRANTY OF ANY KIND, either express Or implied. See the License
; For the specific language governing rights And limitations under the
; License.
;
; The Original Code is UDRes_Include.pbi
;
; The Initial Developer of the Original Code is Thomas Schulz.
;
; Portions created by Thomas Schulz are Copyright (C) 2008
; Thomas Schulz. All Rights Reserved.
;}

CompilerIf Defined(UDResPack, #PB_Structure) = #False
Structure UDResPack
  Size.q
  CRC.q
  Packer.b
  Magic.b[6]
EndStructure
CompilerEndIf

Procedure UDRes_Get(ResNumber, hModule = 0)
  Protected ResName.s, ResType.s = "PBDATA"
  Protected hFind, hLoad, hLock, hSize, Size, CRC, Packer
  Protected *Mem.UDResPack, *DestMem

  If ResNumber < 0 : ProcedureReturn #False : EndIf
  ResNumber + 1

  ResName = "#" + Str(ResNumber)

  If Not hModule : hModule = GetModuleHandle_(#Null) : EndIf

  hFind = FindResource_(hModule, ResName, @ResType)
  If hFind
    hLoad = LoadResource_(hModule, hFind)
    hSize = SizeofResource_(hModule, hFind)
    hLock = LockResource_(hLoad)
    
    *Mem = AllocateMemory(hSize)
    
    If *Mem
      CopyMemory(hLock, *Mem, hSize)
      FreeResource_(hLock)
      ProcedureReturn *Mem 
    EndIf
    
  EndIf
EndProcedure

Procedure UDRes_GetResNumber(FileName.s, start = 1, hModule = 0)
  Protected *Mem = UDRes_Get(0, hModule)
  Protected FileNames.s
  Protected i, j

  If *Mem
    FileNames = PeekS(*Mem, -1, #PB_UTF8)
    FreeMemory(*Mem)
    If start < 1 : start = 1 : EndIf
    
    j = CountString(FileNames, ",")
    
    For i = start To j
      If UCase(StringField(FileNames, i + 1, ",")) = UCase(FileName)
        ProcedureReturn i
      EndIf
    Next
    
  EndIf

EndProcedure

Procedure UDRes_CatchImage(Image, ResNumber, hModule = 0)
  Protected *Mem = UDRes_Get(ResNumber, hModule)
  Protected result

  If *Mem
    result = CatchImage(Image, *Mem, MemorySize(*Mem))
    FreeMemory(*Mem)
    ProcedureReturn result
  EndIf

EndProcedure
Eine komplette Umstellung auf die internen Packroutinen ist mir leider nicht gelungen. Ich vermute mal, dass das erzeugte ZIP nicht ganz kompatible mit der internen ZIP-PackerLib ist.

Es wäre super, wenn man das Programm zum Erstellen der Resource und die Include an PB 5.1 anpassen könnte.

Re: PureDataConverter

Posted: Wed Jul 24, 2013 7:59 pm
by ts-soft

Code: Select all

;{
; Version 1.2
;
; Copyright (c) 2008 by Thomas Schulz / ts-soft@web.de
; http://www.realsource.de
;
; The contents of this file are subject To the Mozilla Public License Version
; 1.2 (the "License"); you may not use this file except in compliance with
; the License. You may obtain a copy of the License at
; http://www.mozilla.org/MPL/
;
; Software distributed under the License is distributed on an "AS IS" basis,
; WITHOUT WARRANTY OF ANY KIND, either express Or implied. See the License
; For the specific language governing rights And limitations under the
; License.
;
; The Original Code is UDRes_Include.pbi
;
; The Initial Developer of the Original Code is Thomas Schulz.
;
; Portions created by Thomas Schulz are Copyright (C) 2008
; Thomas Schulz. All Rights Reserved.
;}

CompilerIf Defined(uncompress, #PB_Procedure) = #False
ImportC "zlib.lib"
  uncompress(*dest, *destLen, *source, sourceLen)
EndImport
CompilerEndIf

Enumeration
  #UDRes_Packer_None
  #UDRes_Packer_jCalg1
  #UDRes_Packer_zip
EndEnumeration

CompilerIf Defined(UDResPack, #PB_Structure) = #False
Structure UDResPack
  Size.q
  CRC.q
  Packer.b
  Magic.b[6]
EndStructure
CompilerEndIf

CompilerIf Defined(_UnpackMemory, #PB_Procedure) = #False
Procedure _UnpackMemory(*SourceMemoryID, SourceLength, *DestionationMemoryID, DestLength, Packer = #UDRes_Packer_jCalg1)
  Select Packer
;     Case #UDRes_Packer_jCalg1
;       ProcedureReturn UnpackMemory(*SourceMemoryID, *DestionationMemoryID)
    Case #UDRes_Packer_zip
      If Not uncompress(*DestionationMemoryID, @DestLength, *SourceMemoryID, SourceLength)
        ProcedureReturn #True
      EndIf
  EndSelect
EndProcedure
CompilerEndIf

Procedure UDRes_Get(ResNumber, hModule = 0)
  Protected ResName.s, ResType.s = "PBDATA"
  Protected hFind, hLoad, hLock, hSize, Size, CRC, Packer
  Protected *Mem.UDResPack, *DestMem

  If ResNumber < 0 : ProcedureReturn #False : EndIf
  ResNumber + 1

  ResName = "#" + Str(ResNumber)

  If Not hModule : hModule = GetModuleHandle_(#Null) : EndIf

  hFind = FindResource_(hModule, ResName, @ResType)
  If hFind
    hLoad = LoadResource_(hModule, hFind)
    hSize = SizeofResource_(hModule, hFind)
    hLock = LockResource_(hLoad)

    *Mem = AllocateMemory(hSize)

    If *Mem
      CopyMemory(hLock, *Mem, hSize)
      FreeResource_(hLock)

      If PeekS(@*Mem\Magic[0], 6, #PB_Ascii) <> "PBDATA"

        ProcedureReturn *Mem
      EndIf

      Size    = *Mem\Size
      CRC     = *Mem\CRC
      Packer  = *Mem\Packer

      If Size > 0
        *DestMEM = AllocateMemory(Size)
        If *DestMEM
          If _UnpackMemory(*Mem + SizeOf(UDResPack), MemorySize(*Mem), *DestMEM, Size, Packer) > 0
            FreeMemory(*Mem)
            If CRC32Fingerprint(*DestMEM, Size) = CRC

              ProcedureReturn *DestMEM
            Else
              FreeMemory(*DestMEM)
            EndIf
          Else
            FreeMemory(*DestMEM)
          EndIf
        EndIf
      Else
        FreeMemory(*Mem)
      EndIf
    EndIf
  EndIf
EndProcedure

Procedure.s UDRes_GetFileName(ResNumber, hModule = 0)
  Protected *Mem = UDRes_Get(0, hModule)
  Protected FileNames.s
  If *Mem
    FileNames  = PeekS(*Mem, -1, #PB_UTF8)
    FreeMemory(*Mem)
    ProcedureReturn StringField(FileNames, ResNumber + 1, ",")
  EndIf
EndProcedure

Procedure UDRes_GetResNumber(FileName.s, start = 1, hModule = 0)
  Protected *Mem = UDRes_Get(0, hModule)
  Protected FileNames.s
  Protected I, J

  If *Mem
    FileNames = PeekS(*Mem, -1, #PB_UTF8)
    FreeMemory(*Mem)
    If start < 1 : start = 1 : EndIf

    J = CountString(FileNames, ",")

    For I = start To J
      If UCase(StringField(FileNames, I + 1, ",")) = UCase(FileName)
        ProcedureReturn I
      EndIf
    Next
    
  EndIf

EndProcedure

Procedure UDRes_Save(FileName.s, ResNumber, hModule = 0)
  Protected FileID
  Protected *Mem

  FileID = CreateFile(#PB_Any, FileName)

  If FileID
    *Mem = UDRes_Get(ResNumber, hModule)

    If *Mem
      WriteData(FileID, *Mem, MemorySize(*Mem))
      CloseFile(FileID)
      FreeMemory(*Mem)

      ProcedureReturn #True
    EndIf

    CloseFile(FileID)
    DeleteFile(FileName)
  EndIf
EndProcedure

Procedure UDRes_CatchSound(Sound, ResNumber, hModule = 0)
  Protected *Mem = UDRes_Get(ResNumber, hModule)
  Protected Result

  If *Mem
    Result = CatchSound(Sound, *Mem, MemorySize(*Mem))
    FreeMemory(*Mem)

    ProcedureReturn Result
  EndIf

EndProcedure

Procedure UDRes_CatchImage(Image, ResNumber, Flag = 0, hModule = 0)
  Protected *Mem = UDRes_Get(ResNumber, hModule)
  Protected Result

  If *Mem
    Result = CatchImage(Image, *Mem, MemorySize(*Mem), Flag)
    FreeMemory(*Mem)

    ProcedureReturn Result
  EndIf

EndProcedure

Procedure UDRes_CatchSprite(Sprite, ResNumber, Modus = 0, hModule = 0)
  Protected *Mem = UDRes_Get(ResNumber, hModule)
  Protected Result

  If *Mem
    Result = CatchSprite(Sprite, *Mem, Modus)
    FreeMemory(*Mem)

    ProcedureReturn Result
  EndIf

EndProcedure

CompilerIf #PB_Compiler_Version >= 520
Procedure UDRes_CatchMusic(Music, ResNumber, hModule = 0)
  Protected *Mem = UDRes_Get(ResNumber, hModule)
  Protected Result

  If *Mem
    Result = CatchMusic(Music, *Mem, MemorySize(*Mem))
    FreeMemory(*Mem)

    ProcedureReturn Result
  EndIf

EndProcedure
CompilerEndIf

Re: PureDataConverter

Posted: Wed Jul 24, 2013 8:04 pm
by Thorsten1867
Great! Thanks!
[German]Auf die Idee bin ich nicht gekommen, sondern habe nur versucht auf die neue PackerLib umzustellen. ;-) [/German]

Re: PureDataConverter

Posted: Thu Sep 19, 2013 9:01 am
by Rbender
Hi There,

after updating PB from 5.11 to 5.20 LTS I got a compiling error while using a pbi file from PureDataConverter 1.6.007.

The error: _UnpackMemory() is not a function, array, makro or linkedlist

Must I change something?

Re: PureDataConverter

Posted: Thu Sep 19, 2013 4:43 pm
by ts-soft
After 5 Years, this tool is outdated! The new packerformat in pb is not compatible to the old ones.
If you use the zip-format and the include v1.2 posted 2 posting over this post, it should work.