Page 1 of 2

Using 7Zip.dll in UNICODE [Resolved]

Posted: Thu Apr 06, 2017 11:50 am
by Kwai chang caine
Hello at all :D

Before i use a code for use 7Zip.dll with PB
Since PB passing in UNICODE this code not works anymore :|
I have try to translate variable in ASCII but nothing works
If someone know how use it in the new version of PB

Code: Select all

Procedure.s SevenZipDossier(PbIdForm, Path7Zip.s, FolderSource.s, PathDestination.s)
  
 Id7Zip = OpenLibrary(#PB_Any, Path7Zip)
  
 If Id7Zip
    
  If FileSize(FolderSource) = - 2 
       
   PathAddBackslash_(@PathDestination)
   PathAddBackslash_(@FolderSource)
   NameZipFile$ = StringField(FolderSource, CountString(FolderSource, "\"), "\") + ".zip"
   NameZipFile$ = PathDestination + NameZipFile$
   
   *bufFolderSource = AllocateMemory(Len(FolderSource))
   PokeS(*bufFolderSource, FolderSource, -1, #PB_Ascii)

   *bufNameZipFile = AllocateMemory(Len(NameZipFile$))
   PokeS(*bufNameZipFile, NameZipFile$, -1, #PB_Ascii)

   OutputAnsi.s = Space(255)
   CmdLine$ =  "a -tzip -mx7 -ir!" + #DQUOTE$ + PeekS(*bufFolderSource, Len(FolderSource), #PB_Ascii) + "*.*" + #DQUOTE$ + " " + #DQUOTE$ + PeekS(*bufNameZipFile, Len(NameZipFile$), #PB_Ascii) + #DQUOTE$
   CallFunction(Id7Zip, "SevenZip", WindowID(PbIdForm), @CmdLine$, @OutputAnsi, 255)
   
   AnsiLen = Len(OutputAnsi)
   UniLen = MultiByteToWideChar_(#CP_ACP, 0, OutputAnsi, AnsiLen, 0, 0)
   
   If UniLen
    *Unicode = SysAllocStringLen_(0, UniLen)
    MultiByteToWideChar_(#CP_ACP, 0, OutputAnsi, AnsiLen, *Unicode, UniLen)
   EndIf
   
   Output.s = PeekS(*Unicode)
   Debug Output
 
  EndIf
  
  CloseLibrary(Id7Zip)
  
 EndIf

EndProcedure

#Window = 0
OpenWindow(#Window, x, y, 100, 100, "7zip")

SevenZipDossier(#Window, "C:\Temp\7-zip32.dll", "C:\Temp\FolderToZip\", "C:\Temp\")
Have a good day

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 12:27 pm
by Marc56us
Hi KCC,

Sorry, not a reply to your question, but PB support 7z format since 5.10 (uncompress) and 5.40 (compress)
No need 7z DLL
I have not tested with unicode, but it should normally work ?

UseLZMAPacker()

:wink:

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 12:32 pm
by Kwai chang caine
Hello Marc :D

Yes i know that :wink:
But using 7Zip is reall more simple
With the packer you must enumerate all the folder recursively, take name of each file, etc...
With this DLL only the name of the parent folder ....and "rollen my chicken" :mrgreen:

Finally..it was simple...before the arrival of UNICODE :|
But thanks when even for your answer 8)

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 12:38 pm
by Marc56us
Yes, that's a good reason :)

In some case, I use command line version of 7z
(I never figured out how to use the dll version :oops: )

Apart from 7zFM (File Manager), there are two other exe in package
  • 7z.exe: use with runprogram in an hidden windows
  • 7zG.exe same way, for long operation.
    7zG (graphic) work as 7z.exe but diplay a window info with button to stop, pause etc.
    User can seen progress bar, number of files, and can stop. Very usefull.
    7zG does not open console window.

Code: Select all

; Using 7zG.exe (7 zip command line GRAPHIC version)

; Check if exist in standard location
Compressor.s = GetUserDirectory(#PB_Directory_Programs) + "7-zip\7zG.exe"
If FileSize(Compressor) < 0 
     End
EndIf

; Choose a big folder to have time to see 7 zip graphic information window
Source_Dir.s        = PathRequester("Directory to Backup ?", GetTemporaryDirectory())
Destination_File.s  = OpenFileRequester("Destination FileName", GetTemporaryDirectory(), "*.7z", 1)

If Source_Dir <> "" And Destination_File <> ""
     RunProgram(Compressor, "a " + Destination_File + " " + Source_Dir, GetTemporaryDirectory())
EndIf
:wink:

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 1:49 pm
by Kwai chang caine
Thanks a lot, i try your tips in the case of nobody know how solve my problem 8)

It's really magical the numeric, in few seconds we teleport both from france to english land :shock: :lol: :lol:

Image

Have a very good day my friend 8)

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 3:54 pm
by blueb
Maybe you could use the 'lib' files from JHPJHP...

http://www.purebasic.fr/english/viewtop ... 12&t=61534

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 4:54 pm
by normeus
kcc,
I see that you are actually creating the command line request:

Code: Select all

a -tzip -mx7 -ir!"c:\7zip\FolderToZip\*.*" "c:\7zip\FolderToZip.zip"
at that point you should be able to call 7zip.exe instead of calling DLL

I don't know which version of 7zip you are using or your PB version to test but you are not sending ASCII to DLL
once you put together the command request in unicode:

Code: Select all

cmdline$ = "a -tzip -mx7 -ir!" + "c:\temp\ToZIP\*.* "+"c:\temp\out.zip"
then PokeS the command to send:

Code: Select all

   *bufCmdLine  = AllocateMemory(Len(CmdLine$ ))
   PokeS(*bufCmdLine, CmdLine$, -1, #PB_Ascii)
then Disco with *bufCmdLine

Code: Select all

CallFunction(Id7Zip, "SevenZip", WindowID(PbIdForm), *bufCmdLine, @OutputAnsi, 255)

Norm.

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 6:45 pm
by loulou2522
Why not using packer native in Purebasic, i use it and that works perfectly even with zip file ?

exe.

Code: Select all

 UseZipPacker()

  ; Créer le fichier compressé
  If CreatePack(0, "MesFichiersCompresses.zip") 
  
    ; Ajouter vos fichiers 
    AddPackFile(0, "Image1.bmp", "Image1.bmp")  
    AddPackFile(0, "Image2.bmp", "Image2.bmp") 
    AddPackFile(0, "mywave1.wav", "mywave1.wav") 
    AddPackFile(0, "mywave2.wav", "mywave2.wav") 
    ClosePack(0) 
  EndIf

Re: Using 7Zip.dll in UNICODE

Posted: Thu Apr 06, 2017 7:17 pm
by Kwai chang caine
@BlueB
Interesting link (like all jhpjhp do obviously)
I take a look to it
Thanks 8)

@Normeus
What a donkey i am :oops:
You have totately right, i mix ascii and unicode.
And since one hour i have try all i know, so nearly nothing :mrgreen:, without see the nose in the middle of the face :oops:
One thousand of thanks Normeus for your precious help

@loulou2522
I have already answering to this question above :wink:
http://www.purebasic.fr/english/viewtop ... 43#p505543

Re: Using 7Zip.dll in UNICODE

Posted: Fri Apr 07, 2017 10:24 am
by Kwai chang caine
Waaaaoooouuuhhh !!!
You are too strong NORMEUS !!! :shock:


This morning i test your code and exactely what you have say (Because yesterday, i answer you on my smartphone, so no test possible :| )
And that's works perfectly 8)

I have also adding

Code: Select all

AnsiLen = Len(OutputAnsi) * 4
Because i suppose the buffer need to be more big in UNICODE rather ASCII :idea:

I love you 8)
And thanks a lot for your precious help

@All
Have the best very good day of the world 8)

And long life to this splendid tool 7Zip
One of the last tool no programming in OOP :? , so that can be again used with our amazing PB 8)

Re: Using 7Zip.dll in UNICODE [Resolved]

Posted: Fri Apr 07, 2017 11:08 am
by Bisonte
By the way ...

Code: Select all

   *bufFolderSource = AllocateMemory(Len(FolderSource))
   PokeS(*bufFolderSource, FolderSource, -1, #PB_Ascii)
is since PB5.60 shorter with

Code: Select all

*bufFolderSource = Ascii(FolderSource)
and you forget to free the memory at the end of your procedure...

Re: Using 7Zip.dll in UNICODE [Resolved]

Posted: Fri Apr 07, 2017 2:31 pm
by Kwai chang caine
Hello BISONTE :D

Incredible !!! i don't know this function :shock:

It's the kind FRED, who think to all his numerous PB childrens.
Like a hen, watching over her little chicks, for make his life much more easy 8)

Image

This FRED... is really a mother for us !!! :mrgreen:

Thanks a lot BISONTE for this precious tips 8)

PS : I like your dog or wolf, he is really nice :wink:

Re: Using 7Zip.dll in UNICODE

Posted: Thu Feb 01, 2018 12:37 pm
by Taz
loulou2522 wrote:Why not using packer native in Purebasic, i use it and that works perfectly even with zip file ?

exe.

Code: Select all

 UseZipPacker()

  ; Créer le fichier compressé
  If CreatePack(0, "MesFichiersCompresses.zip") 
  
    ; Ajouter vos fichiers 
    AddPackFile(0, "Image1.bmp", "Image1.bmp")  
    AddPackFile(0, "Image2.bmp", "Image2.bmp") 
    AddPackFile(0, "mywave1.wav", "mywave1.wav") 
    AddPackFile(0, "mywave2.wav", "mywave2.wav") 
    ClosePack(0) 
  EndIf
That's great, BUT how can I add a file to an existing archive in PureBasic?

Re: Using 7Zip.dll in UNICODE [Resolved]

Posted: Fri Nov 08, 2019 11:31 pm
by DeanH
Thanks to a bit of help from Kwai chang caine, I have been able to produce a small procedure that takes 7-zip command line instructions. Output is a string containing whatever comes from the dll. It is assumed the dll is in the same directory as the calling program.

Code: Select all

Procedure$ SevenZip(CmdLine$)
  Protected Id7Zip,wn,Output$
  Id7Zip=OpenLibrary(#PB_Any,"7-zip32.dll")
  If Id7Zip
    wn=OpenWindow(#PB_Any, 300, 200, 320, 200, "7zip",#PB_Window_ScreenCentered|#PB_Window_Invisible)
    If wn
      OutputAnsi$ = Space(32767)
      *CmdLine = Ascii(CmdLine$)
      CallFunction(Id7Zip, "SevenZip", WindowID(wn), *CmdLine, @OutputAnsi$, 32767)
      Output$=PeekS(@OutputAnsi$, 32767, #PB_Ascii)
      FreeMemory(*CmdLine)
      CloseLibrary(Id7Zip)
      CloseWindow(wn)
    EndIf
  Else
    Output$="7-zip32.dll not present
  EndIf
  ProcedureReturn Output$
EndProcedure

;The test zips bmd files in the current directory
Debug SevenZip("a Test.zip *.bmd")
Debug ""
;Test lists contents of the zip file
Debug SevenZip("l Test.zip")

The 7-zip32.dll documentation includes a function SevenZipSetUnicodeMode. I tried this but it did not seem to allow the CmdLine$ input without changing it to ascii.

Re: Using 7Zip.dll in UNICODE [Resolved]

Posted: Sat Nov 09, 2019 12:36 pm
by Kwai chang caine
:wink: