6 #elif defined(GLib_CYGWIN)
7 TStr TZipIn::SevenZipPath =
"/usr/bin";
8 #elif defined(GLib_MACOSX)
9 TStr TZipIn::SevenZipPath =
"/usr/local/bin";
11 TStr TZipIn::SevenZipPath =
"/usr/bin";
21 PROCESS_INFORMATION piProcInfo;
22 STARTUPINFO siStartInfo;
23 ZeroMemory( &piProcInfo,
sizeof(PROCESS_INFORMATION));
24 ZeroMemory( &siStartInfo,
sizeof(STARTUPINFO));
25 siStartInfo.cb =
sizeof(STARTUPINFO);
27 siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
29 const BOOL FuncRetn = CreateProcess(NULL,
30 (LPSTR) CmdLine.
CStr(),
39 EAssertR(FuncRetn!=0,
TStr::Fmt(
"Can not execute '%s' (Set the TZipIn::SevenZipPath)", CmdLine.
CStr()).CStr());
40 CloseHandle(piProcInfo.hProcess);
41 CloseHandle(piProcInfo.hThread);
43 ZipStdoutRd = popen((TZipIn::SevenZipPath+
"/"+CmdLine).CStr(),
"r");
59 BfL = (int) BytesRead;
61 EAssertR((
BfC!=0)||(
BfL!=0),
"Error reading file '"+
GetSNm()+
"' (Set the TZipIn::SevenZipPath).");
66 FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
73 printf(
"*** Error: file %s, compression format %s not supported\n", FNm.
CStr(), FNm.
GetFExt().
CStr());
78 if (FLen == 0) {
return; }
81 SECURITY_ATTRIBUTES saAttr;
82 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
83 saAttr.bInheritHandle = TRUE;
84 saAttr.lpSecurityDescriptor = NULL;
86 const int PipeBufferSz = 32*1024;
89 SetHandleInformation(
ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
99 FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
105 SECURITY_ATTRIBUTES saAttr;
106 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
107 saAttr.bInheritHandle = TRUE;
108 saAttr.lpSecurityDescriptor = NULL;
112 SetHandleInformation(
ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
140 if (
Bf != NULL) {
delete[]
Bf; }
146 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
148 LBfS+=((
char*)LBf)[LBfC]=
Bf[
BfC++];}
150 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
151 LBfS+=(((
char*)LBf)[LBfC]=
Bf[
BfC++]);}
165 if (
BfC >=
BfL) { BfP = 0; }
170 if (Status == 1) {
return true; }
173 }
while (Status == 0);
175 return !LnChA.
Empty();
186 if (
Eof()) {
return -1; }
191 if (Ch==
'\n') { BfN =
BfC-1;
return 1; }
192 if (Ch==
'\r' &&
Bf[
BfC+1]==
'\n') {
193 BfC++; BfN =
BfC-2;
return 1; }
207 const char* ZipCmd =
"7z.exe e -y -bd -so";
209 const char* ZipCmd =
"7za e -y -bd -so";
234 SECURITY_ATTRIBUTES saAttr;
235 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
236 saAttr.bInheritHandle = TRUE;
237 saAttr.lpSecurityDescriptor = NULL;
239 const int PipeBufferSz = 32*1024;
240 EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz),
"Stdout pipe creation failed");
242 SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
245 PROCESS_INFORMATION piProcInfo;
246 STARTUPINFO siStartInfo;
247 ZeroMemory( &piProcInfo,
sizeof(PROCESS_INFORMATION));
248 ZeroMemory( &siStartInfo,
sizeof(STARTUPINFO));
249 siStartInfo.cb =
sizeof(STARTUPINFO);
251 siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
253 const BOOL FuncRetn = CreateProcess(NULL, (LPSTR) CmdLine.
CStr(),
254 NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo);
255 EAssertR(FuncRetn!=0,
TStr::Fmt(
"Can not execute '%s' (Set the TZipIn::SevenZipPath)", CmdLine.
CStr()).CStr());
256 CloseHandle(piProcInfo.hProcess);
257 CloseHandle(piProcInfo.hThread); }
260 FILE* ZipStdoutRd = popen((TZipIn::SevenZipPath+
"/"+CmdLine).CStr(),
"r");
261 EAssertR(ZipStdoutRd,
TStr::Fmt(
"Can not execute '%s/%s' (Set the TZipIn::SevenZipPath)", TZipIn::SevenZipPath.CStr(), CmdLine.
CStr()).CStr());
264 const int BfSz = 32*1024;
265 char*
Bf =
new char [BfSz];
270 EAssert(ReadFile(ZipStdoutRd, Bf,
MxBfL, &BytesRead, NULL) != 0);
272 size_t BytesRead = fread(Bf, 1,
MxBfL, ZipStdoutRd);
274 EAssert(pclose(ZipStdoutRd) != -1);
277 BfC = 0; Bf[
BfL] = 0;
279 TStr Str(Bf);
delete []
Bf;
281 int n = StrV.
Len()-1;
282 while (n > 0 && ! StrV[n].IsPrefix(
"-----")) { n--; }
288 return StrV[n-7].GetInt64();
310 PROCESS_INFORMATION piProcInfo;
311 STARTUPINFO siStartInfo;
312 ZeroMemory( &piProcInfo,
sizeof(PROCESS_INFORMATION));
313 ZeroMemory( &siStartInfo,
sizeof(STARTUPINFO));
314 siStartInfo.cb =
sizeof(STARTUPINFO);
316 siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
318 const BOOL FuncRetn = CreateProcess(NULL,
319 (LPSTR) CmdLine.
CStr(),
328 EAssertR(FuncRetn!=0,
TStr::Fmt(
"Can not execute '%s' (Set the TZipIn::SevenZipPath)", CmdLine.
CStr()).CStr());
329 CloseHandle(piProcInfo.hProcess);
330 CloseHandle(piProcInfo.hThread);
332 ZipStdinWr = popen((TZipIn::SevenZipPath+
"/"+CmdLine).CStr(),
"r");
341 SECURITY_ATTRIBUTES saAttr;
342 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
343 saAttr.bInheritHandle = TRUE;
344 saAttr.lpSecurityDescriptor = NULL;
348 SetHandleInformation(
ZipStdinWr, HANDLE_FLAG_INHERIT, 0);
368 if (
Bf!=NULL) {
delete[]
Bf; }
379 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
380 LBfS+=
PutCh(((
char*)LBf)[LBfC]);}
382 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
383 LBfS+=(
Bf[
BfL++]=((
char*)LBf)[LBfC]);}
405 const char* ZipCmd =
"7z.exe a -y -bd -si";
407 const char* ZipCmd =
"7za a -y -bd -si";
static TStrStrH FExtToCmdH
static TStr GetCmd(const TStr &ZipFNm)
Return a command-line string that is executed in order to decompress a file to standard output...
static TStr GetCmd(const TStr &ZipFNm)
Return a command-line string that is executed in order to decompress a file to standard output...
static void FillFExtToCmdH()
int PutCh(const char &Ch)
static bool Exists(const TStr &FNm)
static bool IsZipFNm(const TStr &FNm)
Check whether the file extension of FNm is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
TSizeTy Len() const
Returns the number of elements in the vector.
bool GetNextLnBf(TChA &LnChA)
const TDat & GetDat(const TKey &Key) const
static PSIn New(const TStr &FNm)
unsigned long long uint64
void SaveToErrLog(const char *MsgCStr)
static TStrStrH FExtToCmdH
static bool IsZipExt(const TStr &FNmExt)
Check whether the file extension FNmExt is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
static void FillFExtToCmdH()
int PutBf(const void *LBf, const TSize &LBfL)
static PSOut New(const TStr &FNm)
void AddBf(char *NewBf, const int &BfS)
static bool IsZipExt(const TStr &FNmExt)
Check whether the file extension FNmExt is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
static TStr Fmt(const char *FmtStr,...)
#define EAssertR(Cond, MsgStr)
void CreateZipProcess(const TStr &Cmd, const TStr &ZipFNm)
virtual TStr GetSNm() const
void WrNotify(const char *CaptionCStr, const char *NotifyCStr)
void SplitOnWs(TStrV &StrV) const
bool IsKey(const TKey &Key) const
int GetBf(const void *LBf, const TSize &LBfL)
void CreateZipProcess(const TStr &Cmd, const TStr &ZipFNm)
TDat & AddDat(const TKey &Key)