Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
114050c2
Commit
114050c2
authored
Feb 16, 2017
by
ElenaSubbotina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug #33849
parent
7eee0755
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
104 deletions
+124
-104
OfficeUtils/src/OfficeUtils.cpp
OfficeUtils/src/OfficeUtils.cpp
+8
-8
OfficeUtils/src/ZipUtilsCP.cpp
OfficeUtils/src/ZipUtilsCP.cpp
+116
-96
No files found.
OfficeUtils/src/OfficeUtils.cpp
View file @
114050c2
...
...
@@ -41,14 +41,14 @@ COfficeUtils::COfficeUtils(OnProgressCallback* fCallback)
HRESULT
COfficeUtils
::
ExtractToDirectory
(
const
std
::
wstring
&
zipFile
,
const
std
::
wstring
&
unzipDir
,
wchar_t
*
password
,
SHORT
extract_without_path
)
{
if
(
ZLibZipUtils
::
UnzipToDir
(
zipFile
.
c_str
(),
unzipDir
.
c_str
(),
m_fCallback
,
password
,
(
extract_without_path
>
0
)
?
(
true
)
:
(
false
)
)
==
0
)
{
return
S_OK
;
}
else
{
return
S_FALSE
;
}
if
(
ZLibZipUtils
::
UnzipToDir
(
zipFile
.
c_str
(),
unzipDir
.
c_str
(),
m_fCallback
,
password
,
(
extract_without_path
>
0
)
?
(
true
)
:
(
false
)
)
==
0
)
{
return
S_OK
;
}
else
{
return
S_FALSE
;
}
}
...
...
OfficeUtils/src/ZipUtilsCP.cpp
View file @
114050c2
...
...
@@ -477,122 +477,142 @@ namespace ZLibZipUtils
return
false
;
}
/*========================================================================================================*/
int
ZipDir
(
const
WCHAR
*
dir
,
const
WCHAR
*
outputFile
,
const
OnProgressCallback
*
progress
,
int
compressionLevel
)
{
/*========================================================================================================*/
int
oneZipFile
(
zipFile
&
zf
,
zip_fileinfo
&
zi
,
std
::
wstring
&
file_name
,
std
::
wstring
&
zip_file_name
,
int
method
,
int
compressionLevel
)
{
int
err
=
-
1
;
if
(
(
dir
!=
NULL
)
&&
(
outputFile
!=
NULL
)
)
{
deque
<
wstring
>
StringDeque
;
deque
<
wstring
>
zipDeque
;
StringDeque
.
push_back
(
wstring
(
dir
)
);
wstring
zipDir
;
wstring
file
;
wstring
zipFileName
;
wstring
szText
;
NSFile
::
CFileBinary
oFile
;
if
(
oFile
.
OpenFile
(
file_name
))
{
DWORD
dwSizeRead
;
BYTE
*
pData
=
new
BYTE
[
oFile
.
GetFileSize
()];
if
(
oFile
.
ReadFile
(
pData
,
oFile
.
GetFileSize
(),
dwSizeRead
))
{
std
::
string
zipFileNameA
=
codepage_issue_fixToOEM
(
zip_file_name
);
err
=
zipOpenNewFileInZip
(
zf
,
zipFileNameA
.
c_str
(),
&
zi
,
NULL
,
0
,
NULL
,
0
,
NULL
,
method
,
compressionLevel
);
err
=
zipWriteInFileInZip
(
zf
,
pData
,
dwSizeRead
);
err
=
zipCloseFileInZip
(
zf
);
}
RELEASEARRAYOBJECTS
(
pData
);
}
return
0
;
}
int
ZipDir
(
const
WCHAR
*
dir
,
const
WCHAR
*
outputFile
,
const
OnProgressCallback
*
progress
,
int
compressionLevel
)
{
if
(
(
dir
!=
NULL
)
&&
(
outputFile
!=
NULL
)
)
{
deque
<
wstring
>
StringDeque
;
deque
<
wstring
>
zipDeque
;
StringDeque
.
push_back
(
wstring
(
dir
)
);
wstring
zipDir
;
wstring
file
;
wstring
zipFileName
;
wstring
szText
;
zipFile
zf
=
zipOpenHelp
(
outputFile
);
zipFile
zf
=
zipOpenHelp
(
outputFile
);
zip_fileinfo
zi
;
zip_fileinfo
zi
;
zi
.
tmz_date
.
tm_sec
=
zi
.
tmz_date
.
tm_min
=
zi
.
tmz_date
.
tm_hour
=
zi
.
tmz_date
.
tm_mday
=
zi
.
tmz_date
.
tm_mon
=
zi
.
tmz_date
.
tm_year
=
0
;
zi
.
dosDate
=
0
;
zi
.
internal_fa
=
0
;
zi
.
external_fa
=
0
;
zi
.
tmz_date
.
tm_sec
=
zi
.
tmz_date
.
tm_min
=
zi
.
tmz_date
.
tm_hour
=
zi
.
tmz_date
.
tm_mday
=
zi
.
tmz_date
.
tm_mon
=
zi
.
tmz_date
.
tm_year
=
0
;
zi
.
dosDate
=
0
;
zi
.
internal_fa
=
0
;
zi
.
external_fa
=
0
;
#if defined(_WIN32) || defined (_WIN64)
SYSTEMTIME
currTime
;
SYSTEMTIME
currTime
;
GetLocalTime
(
&
currTime
);
GetLocalTime
(
&
currTime
);
zi
.
tmz_date
.
tm_sec
=
currTime
.
wSecond
;
zi
.
tmz_date
.
tm_min
=
currTime
.
wMinute
;
zi
.
tmz_date
.
tm_hour
=
currTime
.
wHour
;
zi
.
tmz_date
.
tm_mday
=
currTime
.
wDay
;
zi
.
tmz_date
.
tm_mon
=
currTime
.
wMonth
;
zi
.
tmz_date
.
tm_year
=
currTime
.
wYear
;
zi
.
tmz_date
.
tm_sec
=
currTime
.
wSecond
;
zi
.
tmz_date
.
tm_min
=
currTime
.
wMinute
;
zi
.
tmz_date
.
tm_hour
=
currTime
.
wHour
;
zi
.
tmz_date
.
tm_mday
=
currTime
.
wDay
;
zi
.
tmz_date
.
tm_mon
=
currTime
.
wMonth
;
zi
.
tmz_date
.
tm_year
=
currTime
.
wYear
;
#endif
unsigned
int
filesCount
=
get_files_count
(
dir
);
unsigned
int
currentFileIndex
=
0
;
while
(
!
StringDeque
.
empty
()
)
{
szText
=
StringDeque
.
front
();
unsigned
int
filesCount
=
get_files_count
(
dir
);
unsigned
int
currentFileIndex
=
0
;
while
(
!
StringDeque
.
empty
()
)
{
szText
=
StringDeque
.
front
();
StringDeque
.
pop_front
();
if
(
zipDeque
.
size
()
>
0
)
{
zipDir
=
zipDeque
.
front
()
+
wstring
(
L"/"
);
zipDeque
.
pop_front
();
}
CArray
<
std
::
wstring
>
aCurFiles
=
NSDirectory
::
GetFiles
(
szText
);
CArray
<
std
::
wstring
>
aCurDirectories
=
NSDirectory
::
GetDirectories
(
szText
);
for
(
int
i
=
0
;
i
<
aCurDirectories
.
GetCount
();
++
i
)
{
std
::
wstring
sCurDirectory
=
aCurDirectories
[
i
];
std
::
wstring
sDirName
=
NSSystemPath
::
GetFileName
(
sCurDirectory
);
StringDeque
.
push_back
(
sCurDirectory
);
zipDeque
.
push_back
(
zipDir
+
sDirName
);
}
for
(
int
i
=
0
;
i
<
aCurFiles
.
GetCount
();
++
i
)
{
std
::
wstring
cFilePath
=
aCurFiles
[
i
];
std
::
wstring
cFileName
=
NSSystemPath
::
GetFileName
(
cFilePath
);
file
=
NSSystemPath
::
Combine
(
szText
,
cFileName
);
zipFileName
=
zipDir
+
cFileName
;
NSFile
::
CFileBinary
oFile
;
if
(
oFile
.
OpenFile
(
file
))
{
DWORD
dwSizeRead
;
BYTE
*
pData
=
new
BYTE
[
oFile
.
GetFileSize
()];
if
(
oFile
.
ReadFile
(
pData
,
oFile
.
GetFileSize
(),
dwSizeRead
))
{
std
::
string
zipFileNameA
=
codepage_issue_fixToOEM
(
zipFileName
);
err
=
zipOpenNewFileInZip
(
zf
,
zipFileNameA
.
c_str
(),
&
zi
,
NULL
,
0
,
NULL
,
0
,
NULL
,
Z_DEFLATED
,
compressionLevel
);
err
=
zipWriteInFileInZip
(
zf
,
pData
,
dwSizeRead
);
err
=
zipCloseFileInZip
(
zf
);
}
RELEASEARRAYOBJECTS
(
pData
);
}
if
(
zipDeque
.
size
()
>
0
)
{
zipDir
=
zipDeque
.
front
()
+
wstring
(
L"/"
);
zipDeque
.
pop_front
();
}
if
(
progress
!=
NULL
)
{
short
cancel
=
0
;
long
progressValue
=
(
1000000
/
filesCount
*
currentFileIndex
);
if
(
NULL
!=
progress
)
(
*
progress
)(
UTILS_ONPROGRESSEVENT_ID
,
progressValue
,
&
cancel
);
CArray
<
std
::
wstring
>
aCurFiles
=
NSDirectory
::
GetFiles
(
szText
);
CArray
<
std
::
wstring
>
aCurDirectories
=
NSDirectory
::
GetDirectories
(
szText
);
for
(
int
i
=
0
;
i
<
aCurDirectories
.
GetCount
();
++
i
)
{
std
::
wstring
sCurDirectory
=
aCurDirectories
[
i
];
std
::
wstring
sDirName
=
NSSystemPath
::
GetFileName
(
sCurDirectory
);
StringDeque
.
push_back
(
sCurDirectory
);
zipDeque
.
push_back
(
zipDir
+
sDirName
);
}
for
(
int
i
=
0
;
i
<
aCurFiles
.
GetCount
();
++
i
)
{
std
::
wstring
cFileName
=
NSSystemPath
::
GetFileName
(
aCurFiles
[
i
]);
if
(
std
::
wstring
::
npos
!=
cFileName
.
find
(
L"mimetype"
))
// возможно и полное соответствие
{
std
::
wstring
cFilePath
=
aCurFiles
[
i
];
file
=
NSSystemPath
::
Combine
(
szText
,
cFileName
);
zipFileName
=
zipDir
+
cFileName
;
oneZipFile
(
zf
,
zi
,
file
,
zipFileName
,
0
,
compressionLevel
);
if
(
cancel
!=
0
)
{
err
=
zipClose
(
zf
,
NULL
);
aCurFiles
.
RemoveAt
(
i
);
break
;
}
}
return
err
;
}
}
for
(
int
i
=
0
;
i
<
aCurFiles
.
GetCount
();
++
i
)
{
std
::
wstring
cFilePath
=
aCurFiles
[
i
];
std
::
wstring
cFileName
=
NSSystemPath
::
GetFileName
(
cFilePath
);
file
=
NSSystemPath
::
Combine
(
szText
,
cFileName
);
zipFileName
=
zipDir
+
cFileName
;
currentFileIndex
++
;
}
}
oneZipFile
(
zf
,
zi
,
file
,
zipFileName
,
Z_DEFLATED
,
compressionLevel
);
err
=
zipClose
(
zf
,
NULL
);
if
(
progress
!=
NULL
)
{
short
cancel
=
0
;
long
progressValue
=
(
1000000
/
filesCount
*
currentFileIndex
);
if
(
NULL
!=
progress
)
(
*
progress
)(
UTILS_ONPROGRESSEVENT_ID
,
progressValue
,
&
cancel
);
if
(
progress
!=
NULL
)
{
short
cancel
=
0
;
long
progressValue
=
1000000
;
if
(
NULL
!=
progress
)
(
*
progress
)(
UTILS_ONPROGRESSEVENT_ID
,
progressValue
,
&
cancel
);
if
(
cancel
!=
0
)
{
zipClose
(
zf
,
NULL
);
}
}
currentFileIndex
++
;
}
}
zipClose
(
zf
,
NULL
);
}
if
(
progress
!=
NULL
)
{
short
cancel
=
0
;
long
progressValue
=
1000000
;
if
(
NULL
!=
progress
)
(
*
progress
)(
UTILS_ONPROGRESSEVENT_ID
,
progressValue
,
&
cancel
);
}
}
return
err
;
}
return
0
;
}
/*========================================================================================================*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment