diff options
Diffstat (limited to 'hwpfilter/source/htags.cxx')
-rw-r--r-- | hwpfilter/source/htags.cxx | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/hwpfilter/source/htags.cxx b/hwpfilter/source/htags.cxx index b8cafcf38675..69d0398ca952 100644 --- a/hwpfilter/source/htags.cxx +++ b/hwpfilter/source/htags.cxx @@ -19,6 +19,9 @@ #include "precompile.h" +#include <o3tl/char16_t2wchar_t.hxx> +#include <unotools/tempfile.hxx> + #include <string.h> #include "hwplib.h" @@ -49,9 +52,8 @@ bool HyperText::Read(HWPFile& hwpf) EmPicture::EmPicture(size_t tsize) : size(tsize >= 32 ? tsize - 32 : 0) + , data(size, 0) { - if (size != 0) - data.reset( new uchar[size] ); } EmPicture::~EmPicture() @@ -67,7 +69,7 @@ bool EmPicture::Read(HWPFile & hwpf) name[0] = 'H'; name[1] = 'W'; name[2] = 'P'; - return hwpf.ReadBlock(data.get(), size) != 0; + return hwpf.ReadBlock(data.data(), size) != 0; } @@ -82,13 +84,13 @@ OlePicture::OlePicture(int tsize) return; }; +#ifdef _WIN32 OlePicture::~OlePicture() { -#ifdef _WIN32 if( pis ) pis->Release(); -#endif }; +#endif #define FILESTG_SIGNATURE_NORMAL 0xF8995568 @@ -108,27 +110,20 @@ void OlePicture::Read(HWPFile & hwpf) delete [] data; return; } - FILE *fp; - char tname[200]; - wchar_t wtname[200]; - tmpnam(tname); - if (nullptr == (fp = fopen(tname, "wb"))) - { - delete [] data; - return; - } - fwrite(data, size, 1, fp); + + utl::TempFileNamed aTempFile; + aTempFile.EnableKillingFile(); + + SvFileStream aOutputStream(aTempFile.GetURL(), StreamMode::WRITE); + aOutputStream.WriteBytes(data, size); delete [] data; - fclose(fp); - MultiByteToWideChar(CP_ACP, 0, tname, -1, wtname, 200); - if( StgOpenStorage(wtname, nullptr, + aOutputStream.Close(); + if( StgOpenStorage(o3tl::toW(aTempFile.GetFileName().getStr()), nullptr, STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_TRANSACTED, nullptr, 0, &pis) != S_OK ) { pis = nullptr; - unlink(tname); return; } - unlink(tname); #else hwpf.SkipBlock(size); #endif |