Extract ZIP to RAM?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 06:11

teadrinker wrote:
13 Jan 2020, 05:40
This is the solution:

Code: Select all

#MaxMem 4095
SetBatchLines, -1

zipFile := A_ScriptDir . "\test.7z"
pathInsideZip := "Folder\SubFolder\test.txt"
7ZipDLL := "7-zip" . A_PtrSize*8 . ".dll"

7zip := new 7zipToBuff(7ZipDLL, zipFile, pathInsideZip)
7zip.UnzipToBuff(buff)
output := 7zip.output
7zip := ""
MsgBox, % output
MsgBox, % Clipboard := StrGet(&buff, "cp0")

class 7zipToBuff {
   __New(7ZipDLL, zipFile, pathInsideZip) {
      static STD_OUTPUT_HANDLE := -11, DUPLICATE_SAME_ACCESS := 0x2
      
      if !FileExist(7ZipDLL)
         throw 7ZipDLL . " not found"
      if !this.hModule := DllCall("LoadLibrary", "Str", 7ZipDLL, "Ptr")
         throw "LoadLibrary failed"
      
      this.7ZipDLL := 7ZipDLL
      this.zipFile := zipFile
      this.pathInsideZip := pathInsideZip
      
      this.savedStdOut := DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr")
      this.buffSize := this.GetBuffSize()
      
      DllCall("CreatePipe", "PtrP", hReadTemp, "PtrP", hPipeWrite, "Ptr", 0, "UInt", this.buffSize)
      hProc := DllCall("GetCurrentProcess")
      DllCall("DuplicateHandle", "Ptr", hProc, "Ptr", hReadTemp, "Ptr", hProc, "PtrP", hReadPipe, "UInt", 0, "UInt", false, "UInt", DUPLICATE_SAME_ACCESS)
      this.hReadPipe := hReadPipe
      DllCall("CloseHandle", "Ptr", hReadTemp)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr", hPipeWrite)
      this.saved_stdout := DllCall("msvcrt\_dup", "Int", 1)
      this.fd := DllCall("msvcrt\_open_osfhandle", "Ptr", DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr"), "Int", 0)
      DllCall("msvcrt\_dup2", "Int", this.fd, "Int", 1)
   }
   
   __Delete() {
      DllCall("FreeLibrary", "Ptr", this.hModule)
      DllCall("msvcrt\_dup2", "Int", this.saved_stdout, "Int", 1)
      DllCall("msvcrt\_close", "Int", this.fd)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE := -11, "Ptr", this.savedStdOut)
   }
   
   UnzipToBuff(ByRef buff) {
      VarSetCapacity(buff, this.buffSize)
      this.output := this.SevenZip("e -hide """ . this.zipFile . """ """ . this.pathInsideZip . """ -so")
      Loop {
         Sleep, 10
         DllCall("PeekNamedPipe", "Ptr", this.hReadPipe, "Ptr", 0, "UInt", 0, "Ptr", 0, "UIntP", avail, "Ptr", 0)
      } until avail = this.buffSize || A_Index = 100

      fullSize := 0
      Loop {
         res := DllCall("ReadFile", "Ptr", this.hReadPipe, "Ptr", &buff + fullSize, "UInt", this.buffSize, "UIntP", nSize, "UInt", 0)
         fullSize += nSize
      } until !res || fullSize = this.buffSize
   }
   
   GetBuffSize() {
      hArc := DllCall(this.7ZipDLL . "\SevenZipOpenArchive", "Ptr", 0, "AStr", this.zipFile, "Int", 0)
      VarSetCapacity(INDIVIDUALINFO, 558, 0)
      DllCall(this.7ZipDLL . "\SevenZipFindFirst", "Ptr", hArc, "AStr", this.pathInsideZip, "Ptr", &INDIVIDUALINFO)
      DllCall(this.7ZipDLL . "\SevenZipCloseArchive", "Ptr", hArc)
      Return NumGet(INDIVIDUALINFO, "UInt")
   }
   
   SevenZip(sCommand) {
      VarSetCapacity(output, size := 1024)
      res := DllCall(this.7ZipDLL . "\SevenZip", "Ptr", 0, "AStr", sCommand, "Ptr", &output, "Int", size)
      return StrGet(&output, nSize, "CP0")
   }
}
Thanks. Much better in class form.

But I tested and failed. He never reacts. Ahk is freezing.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 06:51

teadrinker wrote:
13 Jan 2020, 06:06
Ha-ha, also freezes on double click :lol:
I just saw this message.
I like winrar anyway. I hate 7z. :)
Nye such misfortune?

:roll:
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

13 Jan 2020, 07:05

So far I've found such a workaround:

Code: Select all

#MaxMem 4095
#SingleInstance, Force
SetBatchLines, -1
if !A_Args[1] {
   Run, % """" . A_ScriptFullPath . """ 1"
   ExitApp
}

zipFile := A_ScriptDir . "\test.7z"
pathInsideZip := "Folder\SubFolder\test.txt"
7ZipDLL := "7-zip" . A_PtrSize*8 . ".dll"

7zip := new 7zipToBuff(7ZipDLL, zipFile, pathInsideZip)
7zip.UnzipToBuff(buff)
output := 7zip.output
7zip := ""
MsgBox, % output
MsgBox, % Clipboard := StrGet(&buff, "cp0")

class 7zipToBuff {
   __New(7ZipDLL, zipFile, pathInsideZip) {
      static STD_OUTPUT_HANDLE := -11, DUPLICATE_SAME_ACCESS := 0x2
      
      if !FileExist(7ZipDLL)
         throw 7ZipDLL . " not found"
      if !this.hModule := DllCall("LoadLibrary", "Str", 7ZipDLL, "Ptr")
         throw "LoadLibrary failed"
      
      this.7ZipDLL := 7ZipDLL
      this.zipFile := zipFile
      this.pathInsideZip := pathInsideZip
      
      this.savedStdOut := DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr")
      this.buffSize := this.GetBuffSize()
      
      DllCall("CreatePipe", "PtrP", hReadTemp, "PtrP", hPipeWrite, "Ptr", 0, "UInt", this.buffSize)
      hProc := DllCall("GetCurrentProcess")
      DllCall("DuplicateHandle", "Ptr", hProc, "Ptr", hReadTemp, "Ptr", hProc, "PtrP", hReadPipe, "UInt", 0, "UInt", false, "UInt", DUPLICATE_SAME_ACCESS)
      this.hReadPipe := hReadPipe
      DllCall("CloseHandle", "Ptr", hReadTemp)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr", hPipeWrite)
      this.saved_stdout := DllCall("msvcrt\_dup", "Int", 1)
      this.fd := DllCall("msvcrt\_open_osfhandle", "Ptr", DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr"), "Int", 0)
      DllCall("msvcrt\_dup2", "Int", this.fd, "Int", 1)
   }
   
   __Delete() {
      DllCall("FreeLibrary", "Ptr", this.hModule)
      DllCall("msvcrt\_dup2", "Int", this.saved_stdout, "Int", 1)
      DllCall("msvcrt\_close", "Int", this.fd)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE := -11, "Ptr", this.savedStdOut)
   }
   
   UnzipToBuff(ByRef buff) {
      VarSetCapacity(buff, this.buffSize)
      this.output := this.SevenZip("e -hide """ . this.zipFile . """ """ . this.pathInsideZip . """ -so")
      Loop {
         Sleep, 10
         DllCall("PeekNamedPipe", "Ptr", this.hReadPipe, "Ptr", 0, "UInt", 0, "Ptr", 0, "UIntP", avail, "Ptr", 0)
      } until avail = this.buffSize || A_Index = 100

      fullSize := 0
      Loop {
         res := DllCall("ReadFile", "Ptr", this.hReadPipe, "Ptr", &buff + fullSize, "UInt", this.buffSize, "UIntP", nSize, "UInt", 0)
         fullSize += nSize
      } until !res || fullSize = this.buffSize
   }
   
   GetBuffSize() {
      hArc := DllCall(this.7ZipDLL . "\SevenZipOpenArchive", "Ptr", 0, "AStr", this.zipFile, "Int", 0)
      VarSetCapacity(INDIVIDUALINFO, 558, 0)
      DllCall(this.7ZipDLL . "\SevenZipFindFirst", "Ptr", hArc, "AStr", this.pathInsideZip, "Ptr", &INDIVIDUALINFO)
      DllCall(this.7ZipDLL . "\SevenZipCloseArchive", "Ptr", hArc)
      Return NumGet(INDIVIDUALINFO, "UInt")
   }
   
   SevenZip(sCommand) {
      VarSetCapacity(output, size := 1024)
      res := DllCall(this.7ZipDLL . "\SevenZip", "Ptr", 0, "AStr", sCommand, "Ptr", &output, "Int", size)
      return StrGet(&output, nSize, "CP0")
   }
}
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 07:17

teadrinker wrote:
13 Jan 2020, 07:05
So far I've found such a workaround:

Code: Select all

#MaxMem 4095
#SingleInstance, Force
SetBatchLines, -1
if !A_Args[1] {
   Run, % """" . A_ScriptFullPath . """ 1"
   ExitApp
}

zipFile := A_ScriptDir . "\test.7z"
pathInsideZip := "Folder\SubFolder\test.txt"
7ZipDLL := "7-zip" . A_PtrSize*8 . ".dll"

7zip := new 7zipToBuff(7ZipDLL, zipFile, pathInsideZip)
7zip.UnzipToBuff(buff)
output := 7zip.output
7zip := ""
MsgBox, % output
MsgBox, % Clipboard := StrGet(&buff, "cp0")

class 7zipToBuff {
   __New(7ZipDLL, zipFile, pathInsideZip) {
      static STD_OUTPUT_HANDLE := -11, DUPLICATE_SAME_ACCESS := 0x2
      
      if !FileExist(7ZipDLL)
         throw 7ZipDLL . " not found"
      if !this.hModule := DllCall("LoadLibrary", "Str", 7ZipDLL, "Ptr")
         throw "LoadLibrary failed"
      
      this.7ZipDLL := 7ZipDLL
      this.zipFile := zipFile
      this.pathInsideZip := pathInsideZip
      
      this.savedStdOut := DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr")
      this.buffSize := this.GetBuffSize()
      
      DllCall("CreatePipe", "PtrP", hReadTemp, "PtrP", hPipeWrite, "Ptr", 0, "UInt", this.buffSize)
      hProc := DllCall("GetCurrentProcess")
      DllCall("DuplicateHandle", "Ptr", hProc, "Ptr", hReadTemp, "Ptr", hProc, "PtrP", hReadPipe, "UInt", 0, "UInt", false, "UInt", DUPLICATE_SAME_ACCESS)
      this.hReadPipe := hReadPipe
      DllCall("CloseHandle", "Ptr", hReadTemp)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr", hPipeWrite)
      this.saved_stdout := DllCall("msvcrt\_dup", "Int", 1)
      this.fd := DllCall("msvcrt\_open_osfhandle", "Ptr", DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr"), "Int", 0)
      DllCall("msvcrt\_dup2", "Int", this.fd, "Int", 1)
   }
   
   __Delete() {
      DllCall("FreeLibrary", "Ptr", this.hModule)
      DllCall("msvcrt\_dup2", "Int", this.saved_stdout, "Int", 1)
      DllCall("msvcrt\_close", "Int", this.fd)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE := -11, "Ptr", this.savedStdOut)
   }
   
   UnzipToBuff(ByRef buff) {
      VarSetCapacity(buff, this.buffSize)
      this.output := this.SevenZip("e -hide """ . this.zipFile . """ """ . this.pathInsideZip . """ -so")
      Loop {
         Sleep, 10
         DllCall("PeekNamedPipe", "Ptr", this.hReadPipe, "Ptr", 0, "UInt", 0, "Ptr", 0, "UIntP", avail, "Ptr", 0)
      } until avail = this.buffSize || A_Index = 100

      fullSize := 0
      Loop {
         res := DllCall("ReadFile", "Ptr", this.hReadPipe, "Ptr", &buff + fullSize, "UInt", this.buffSize, "UIntP", nSize, "UInt", 0)
         fullSize += nSize
      } until !res || fullSize = this.buffSize
   }
   
   GetBuffSize() {
      hArc := DllCall(this.7ZipDLL . "\SevenZipOpenArchive", "Ptr", 0, "AStr", this.zipFile, "Int", 0)
      VarSetCapacity(INDIVIDUALINFO, 558, 0)
      DllCall(this.7ZipDLL . "\SevenZipFindFirst", "Ptr", hArc, "AStr", this.pathInsideZip, "Ptr", &INDIVIDUALINFO)
      DllCall(this.7ZipDLL . "\SevenZipCloseArchive", "Ptr", hArc)
      Return NumGet(INDIVIDUALINFO, "UInt")
   }
   
   SevenZip(sCommand) {
      VarSetCapacity(output, size := 1024)
      res := DllCall(this.7ZipDLL . "\SevenZip", "Ptr", 0, "AStr", sCommand, "Ptr", &output, "Int", size)
      return StrGet(&output, nSize, "CP0")
   }
}
It didn't work in my system. :(
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

13 Jan 2020, 07:30

What happens when you launch it?
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 07:39

teadrinker wrote:
13 Jan 2020, 07:30
What happens when you launch it?
Never. It just freezes over.
Windows7 x64

x86 autohotkey.
Same problem with X64.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

13 Jan 2020, 07:47

This is weird. For me it works on Windows 7 and 10 for both bitness.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 08:03

When I get home I'll try with Windows 10.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

13 Jan 2020, 08:57

Make sure you specify pathInsideZip correctly.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

13 Jan 2020, 09:18

This version will check if all files exist.

Code: Select all

#MaxMem 4095
#SingleInstance, Force
SetBatchLines, -1
if !A_Args[1] {
   Run, % """" . A_ScriptFullPath . """ 1"
   ExitApp
}

zipFile := A_ScriptDir . "\test.7z"
pathInsideZip := "Folder\SubFolder\test.txt"
7ZipDLL := "7-zip" . A_PtrSize*8 . ".dll"

7zip := new 7zipToBuff(7ZipDLL, zipFile, pathInsideZip)
7zip.UnzipToBuff(buff)
output := 7zip.output
7zip := ""
MsgBox, % output
MsgBox, % Clipboard := StrGet(&buff, "UTF-8")

class 7zipToBuff {
   __New(7ZipDLL, zipFile, pathInsideZip) {
      static STD_OUTPUT_HANDLE := -11, DUPLICATE_SAME_ACCESS := 0x2
      
      if !FileExist(7ZipDLL)
         throw 7ZipDLL . " not found"
      if !FileExist(zipFile)
         throw "The file """ . zipFile . """ not found"
      if !this.hModule := DllCall("LoadLibrary", "Str", 7ZipDLL, "Ptr")
         throw "LoadLibrary failed"
      
      this.7ZipDLL := 7ZipDLL
      this.zipFile := zipFile
      this.pathInsideZip := pathInsideZip
      
      this.savedStdOut := DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr")
      buffSize := this.GetBuffSize()
      if (buffSize = -1)
         throw "The file """ . pathInsideZip . """ not found in archive"
      this.buffSize := buffSize
      
      DllCall("CreatePipe", "PtrP", hReadTemp, "PtrP", hPipeWrite, "Ptr", 0, "UInt", this.buffSize)
      hProc := DllCall("GetCurrentProcess")
      DllCall("DuplicateHandle", "Ptr", hProc, "Ptr", hReadTemp, "Ptr", hProc, "PtrP", hReadPipe, "UInt", 0, "UInt", false, "UInt", DUPLICATE_SAME_ACCESS)
      this.hReadPipe := hReadPipe
      DllCall("CloseHandle", "Ptr", hReadTemp)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr", hPipeWrite)
      this.saved_stdout := DllCall("msvcrt\_dup", "Int", 1)
      this.fd := DllCall("msvcrt\_open_osfhandle", "Ptr", DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr"), "Int", 0)
      DllCall("msvcrt\_dup2", "Int", this.fd, "Int", 1)
   }
   
   __Delete() {
      DllCall("FreeLibrary", "Ptr", this.hModule)
      DllCall("msvcrt\_dup2", "Int", this.saved_stdout, "Int", 1)
      DllCall("msvcrt\_close", "Int", this.fd)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE := -11, "Ptr", this.savedStdOut)
   }
   
   UnzipToBuff(ByRef buff) {
      VarSetCapacity(buff, this.buffSize + 2)
      this.output := this.SevenZip("e -hide """ . this.zipFile . """ """ . this.pathInsideZip . """ -so")
      Loop {
         Sleep, 10
         DllCall("PeekNamedPipe", "Ptr", this.hReadPipe, "Ptr", 0, "UInt", 0, "Ptr", 0, "UIntP", avail, "Ptr", 0)
      } until avail = this.buffSize || A_Index = 100

      fullSize := 0
      Loop {
         res := DllCall("ReadFile", "Ptr", this.hReadPipe, "Ptr", &buff + fullSize, "UInt", this.buffSize, "UIntP", nSize, "UInt", 0)
         fullSize += nSize
      } until !res || fullSize = this.buffSize
      NumPut(0, &buff + this.buffSize, "UShort")
   }
   
   GetBuffSize() {
      hArc := DllCall(this.7ZipDLL . "\SevenZipOpenArchive", "Ptr", 0, "AStr", this.zipFile, "Int", 0)
      VarSetCapacity(INDIVIDUALINFO, 558, 0)
      res := DllCall(this.7ZipDLL . "\SevenZipFindFirst", "Ptr", hArc, "AStr", this.pathInsideZip, "Ptr", &INDIVIDUALINFO)
      DllCall(this.7ZipDLL . "\SevenZipCloseArchive", "Ptr", hArc)
      Return res = 0 ? NumGet(INDIVIDUALINFO, "UInt") : -1
   }
   
   SevenZip(sCommand) {
      VarSetCapacity(output, size := 1024)
      res := DllCall(this.7ZipDLL . "\SevenZip", "Ptr", 0, "AStr", sCommand, "Ptr", &output, "Int", size)
      return StrGet(&output, nSize, "CP0")
   }
}
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 12:28

teadrinker wrote:
13 Jan 2020, 08:57
Make sure you specify pathInsideZip correctly.
https://drive.google.com/file/d/1YM_lpe3L-TEG__5JQGOt43EXVCJTs7gI/view

It still doesn't work. I'm using these dll files.

Oh yes it's my fault. Sub folder. :(

I'm so sorry.
Last edited by hasantr on 13 Jan 2020, 12:50, edited 1 time in total.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 12:39

It's all great. So we have another important library, thanks to you. Thank you very much.

Maybe one last problem.
If zip can't find a file in it, it crashes again.
Is there a way to start again before the whole exe crashes.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

13 Jan 2020, 13:07

hasantr wrote: If zip can't find a file in it, it crashes again.
Did you try latest version? It should not crash, but throw an exception if the file not found.

Image
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

13 Jan 2020, 13:48

teadrinker wrote:
13 Jan 2020, 13:07
hasantr wrote: If zip can't find a file in it, it crashes again.
Did you try latest version? It should not crash, but throw an exception if the file not found.

Image
Yes, no more collapse. On my first attempt, this version crashed with double clicks. I turned everything off completely and now it's not collapsing.
It's all done then. :bravo: :thumbup:

Thank you.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

02 Feb 2020, 16:07

teadrinker wrote:
13 Jan 2020, 09:18
This version will check if all files exist.

Code: Select all

#MaxMem 4095
#SingleInstance, Force
SetBatchLines, -1
if !A_Args[1] {
   Run, % """" . A_ScriptFullPath . """ 1"
   ExitApp
}

zipFile := A_ScriptDir . "\test.7z"
pathInsideZip := "Folder\SubFolder\test.txt"
7ZipDLL := "7-zip" . A_PtrSize*8 . ".dll"

7zip := new 7zipToBuff(7ZipDLL, zipFile, pathInsideZip)
7zip.UnzipToBuff(buff)
output := 7zip.output
7zip := ""
MsgBox, % output
MsgBox, % Clipboard := StrGet(&buff, "UTF-8")

class 7zipToBuff {
   __New(7ZipDLL, zipFile, pathInsideZip) {
      static STD_OUTPUT_HANDLE := -11, DUPLICATE_SAME_ACCESS := 0x2
      
      if !FileExist(7ZipDLL)
         throw 7ZipDLL . " not found"
      if !FileExist(zipFile)
         throw "The file """ . zipFile . """ not found"
      if !this.hModule := DllCall("LoadLibrary", "Str", 7ZipDLL, "Ptr")
         throw "LoadLibrary failed"
      
      this.7ZipDLL := 7ZipDLL
      this.zipFile := zipFile
      this.pathInsideZip := pathInsideZip
      
      this.savedStdOut := DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr")
      buffSize := this.GetBuffSize()
      if (buffSize = -1)
         throw "The file """ . pathInsideZip . """ not found in archive"
      this.buffSize := buffSize
      
      DllCall("CreatePipe", "PtrP", hReadTemp, "PtrP", hPipeWrite, "Ptr", 0, "UInt", this.buffSize)
      hProc := DllCall("GetCurrentProcess")
      DllCall("DuplicateHandle", "Ptr", hProc, "Ptr", hReadTemp, "Ptr", hProc, "PtrP", hReadPipe, "UInt", 0, "UInt", false, "UInt", DUPLICATE_SAME_ACCESS)
      this.hReadPipe := hReadPipe
      DllCall("CloseHandle", "Ptr", hReadTemp)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr", hPipeWrite)
      this.saved_stdout := DllCall("msvcrt\_dup", "Int", 1)
      this.fd := DllCall("msvcrt\_open_osfhandle", "Ptr", DllCall("GetStdHandle", "UInt", STD_OUTPUT_HANDLE, "Ptr"), "Int", 0)
      DllCall("msvcrt\_dup2", "Int", this.fd, "Int", 1)
   }
   
   __Delete() {
      DllCall("FreeLibrary", "Ptr", this.hModule)
      DllCall("msvcrt\_dup2", "Int", this.saved_stdout, "Int", 1)
      DllCall("msvcrt\_close", "Int", this.fd)
      DllCall("SetStdHandle", "UInt", STD_OUTPUT_HANDLE := -11, "Ptr", this.savedStdOut)
   }
   
   UnzipToBuff(ByRef buff) {
      VarSetCapacity(buff, this.buffSize + 2)
      this.output := this.SevenZip("e -hide """ . this.zipFile . """ """ . this.pathInsideZip . """ -so")
      Loop {
         Sleep, 10
         DllCall("PeekNamedPipe", "Ptr", this.hReadPipe, "Ptr", 0, "UInt", 0, "Ptr", 0, "UIntP", avail, "Ptr", 0)
      } until avail = this.buffSize || A_Index = 100

      fullSize := 0
      Loop {
         res := DllCall("ReadFile", "Ptr", this.hReadPipe, "Ptr", &buff + fullSize, "UInt", this.buffSize, "UIntP", nSize, "UInt", 0)
         fullSize += nSize
      } until !res || fullSize = this.buffSize
      NumPut(0, &buff + this.buffSize, "UShort")
   }
   
   GetBuffSize() {
      hArc := DllCall(this.7ZipDLL . "\SevenZipOpenArchive", "Ptr", 0, "AStr", this.zipFile, "Int", 0)
      VarSetCapacity(INDIVIDUALINFO, 558, 0)
      res := DllCall(this.7ZipDLL . "\SevenZipFindFirst", "Ptr", hArc, "AStr", this.pathInsideZip, "Ptr", &INDIVIDUALINFO)
      DllCall(this.7ZipDLL . "\SevenZipCloseArchive", "Ptr", hArc)
      Return res = 0 ? NumGet(INDIVIDUALINFO, "UInt") : -1
   }
   
   SevenZip(sCommand) {
      VarSetCapacity(output, size := 1024)
      res := DllCall(this.7ZipDLL . "\SevenZip", "Ptr", 0, "AStr", sCommand, "Ptr", &output, "Int", size)
      return StrGet(&output, nSize, "CP0")
   }
}
I want to read a lot of zip files. How to do it for the best performance. I would be very happy if you give an example.
Thank you.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

03 Feb 2020, 13:38

hasantr wrote: I would be very happy if you give an example.
An example depends on what info you need to get from those files and what you want to do with this info.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Extract ZIP to RAM?

03 Feb 2020, 14:08

teadrinker wrote:
03 Feb 2020, 13:38
hasantr wrote: I would be very happy if you give an example.
An example depends on what info you need to get from those files and what you want to do with this info.
#Include %A_ScriptDir%\Lib\SevenZip_ExtractMem2.ahk

Loop, files, % dizinler "*.udf", FR
{
zipFile := A_LoopFileFullPath
pathInsideZip := "content.xml"
7ZipDLL := "7-zip" . A_PtrSize*8 . ".dll"

7zip := new 7zipToBuff(7ZipDLL, zipFile, pathInsideZip)
7zip.UnzipToBuff(buff)
msgbox % A_LoopFileFullPath
output := 7zip.output
7zip := ""
;MsgBox, % output
data := StrGet(&buff, "UTF-8")
}
In the example above, ahk collapses.

It is part of a very large work. I take the context.xml text inside the zip files into the variable and then save it in the sqlite database.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

04 Feb 2020, 07:29

Don't you forget to start the script with

Code: Select all

if !A_Args[1] {
	Run, % """" . A_ScriptFullPath . """ 1"
	ExitApp
}
?
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Extract ZIP to RAM?

07 Mar 2020, 12:56

Just try to use this API and the resulting zip archive does not opened by WinZip or WinRar.
https://docs.microsoft.com/en-us/windows/win32/cmpapi/-compression-portal

Code: Select all

inputFile := "1.mp4"
Compressed := "1.zip"
Uncompressed := "2.mp4"

; compress
FileGetSize, size, % inputFile
fileread, file, *c %inputFile%
DllCall("LoadLibrary", "str", "Cabinet.dll", "ptr") 
DllCall("Cabinet.dll\CreateCompressor", "uint", COMPRESS_ALGORITHM_MSZIP := 2, "ptr", 0, "ptr*", cHandle)
DllCall("Cabinet.dll\Compress", "ptr", cHandle, "ptr", &file, "uint", size, "ptr", &cBuffer, "uint", 0, "uint*", maxsize)
VarSetCapacity(cBuffer, maxsize, 0)
DllCall("Cabinet.dll\Compress","ptr", cHandle, "ptr", &file, "uint", size, "ptr", &cBuffer, "uint", maxsize, "uint*", realsize)
DllCall("Cabinet.dll\CloseCompressor", "Ptr", cHandle)
fileobj := fileOpen(Compressed, "rw")
fileobj.RawWrite(cBuffer, realsize)
fileobj.Close()

; decompress
FileGetSize, size, % Compressed
fileread, file, *c %Compressed%
DllCall("Cabinet.dll\CreateDecompressor", "uint", COMPRESS_ALGORITHM_MSZIP := 2, "ptr", 0, "ptr*", cHandle)
DllCall("Cabinet.dll\Decompress", "ptr", cHandle, "ptr", &file, "uint", size, "ptr", &cBuffer, "uint", 0, "uint*", maxsize)
VarSetCapacity(cBuffer, maxsize, 0)
DllCall("Cabinet.dll\Decompress","ptr", cHandle, "ptr", &file, "uint", size, "ptr", &cBuffer, "uint", maxsize, "uint*", realsize)
DllCall("Cabinet.dll\CloseDecompressor", "Ptr", cHandle)
fileobj := fileOpen(Uncompressed, "rw")
fileobj.RawWrite(cBuffer, realsize)
fileobj.Close()
msgbox done
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Extract ZIP to RAM?

07 Mar 2020, 16:35

This api is available beginning with Windows 8, for me it is a disadvantage.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 227 guests