From 244d549cf8d420cdd4152d0c41a8af9a52fef6f8 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Tue, 3 Oct 2017 11:07:01 +0300 Subject: [PATCH] --save-use-only-names mode --- DesktopEditor/doctrenderer/docbuilder_p.h | 79 ++++++++++++++++++++- DesktopEditor/doctrenderer/doctrenderer.pro | 24 +++++++ 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/doctrenderer/docbuilder_p.h b/DesktopEditor/doctrenderer/docbuilder_p.h index 438fd423c8..6a65cc17ae 100644 --- a/DesktopEditor/doctrenderer/docbuilder_p.h +++ b/DesktopEditor/doctrenderer/docbuilder_p.h @@ -56,6 +56,10 @@ #include #endif +#ifdef BUIDLER_OPEN_DOWNLOAD_ENABLED +#include "../../Common/FileDownloader/FileDownloader.h" +#endif + template class CScopeWrapper { @@ -558,6 +562,8 @@ namespace NSDoctRenderer bool m_bIsCacheScript; + std::wstring m_sFolderForSaveOnlyUseNames; + std::string m_sGlobalVariable; bool m_bIsGlobalVariableUse; public: @@ -851,6 +857,64 @@ namespace NSDoctRenderer #endif } + void MoveFileOpen(const std::wstring& from, const std::wstring& to) + { +#ifdef BUIDLER_OPEN_DOWNLOAD_ENABLED + int n1 = (int)from.find (L"www"); + int n2 = (int)from.find (L"http"); + int n3 = (int)from.find (L"ftp"); + int n4 = (int)from.find (L"https"); + + //если nI сранивать не с 0, то будут проблемы + //потому что в инсталяции мы кладем файлы в /var/www... + if (0 == n1 || 0 == n2 || 0 == n3 || 0 == n4) + { + CFileDownloader oDownloader(from, false); + oDownloader.SetFilePath(to); + if (oDownloader.DownloadSync()) + return; + } +#endif + +#ifdef BUIDLER_OPEN_BASE64_ENABLED + if (0 == from.find(L"data:")) + { + std::wstring::size_type findBase64 = from.find(L"base64,"); + if (std::wstring::npos != findBase64) + { + int nStartBase64 = (int)findBase64; + if (50 > nStartBase64) + { + nStartBase64 += 7; + const wchar_t* pStart = from.c_str() + nStartBase64; + int nDataLen = (int)from.length() - nStartBase64; + + std::string sBase64 = NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(pStart, (LONG)nDataLen, false); + + BYTE* pDataDst = NULL; + int nDataDstLen = 0; + if (NSFile::CBase64Converter::Decode(sBase64.c_str(), (int)sBase64.length(), pDataDst, nDataLen)) + { + NSFile::CFileBinary oFileDst; + if (oFileDst.CreateFileW(to)) + { + oFileDst.WriteFile(pDataDst, (DWORD)nDataDstLen); + oFileDst.CloseFile(); + + RELEASEARRAYOBJECTS(pDataDst); + return; + } + + RELEASEARRAYOBJECTS(pDataDst); + } + } + } + } +#endif + + NSFile::CFileBinary::Copy(from, to); + } + int OpenFile(const std::wstring& path, const std::wstring& params) { Init(); @@ -861,7 +925,7 @@ namespace NSDoctRenderer NSDirectory::CreateDirectory(m_sFileDir + L"/changes"); std::wstring sFileCopy = m_sFileDir + L"/origin." + NSCommon::GetFileExtention(path); - NSFile::CFileBinary::Copy(path, sFileCopy); + MoveFileOpen(path, sFileCopy); COfficeFileFormatChecker oChecker; if (!oChecker.isOfficeFile(path)) @@ -1054,7 +1118,16 @@ namespace NSDoctRenderer NSStringUtils::CStringBuilder oBuilder; std::wstring _path = path; - std::wstring sDstFileDir = NSCommon::GetDirectoryName(_path); + if (!m_sFolderForSaveOnlyUseNames.empty()) + { + _path = m_sFolderForSaveOnlyUseNames; + wchar_t last = m_sFolderForSaveOnlyUseNames.c_str()[m_sFolderForSaveOnlyUseNames.length() - 1]; + if (last != '/' && last != '\\') + _path += L"/"; + _path += NSCommon::GetFileName(path); + } + + std::wstring sDstFileDir = NSCommon::GetDirectoryName(_path); if ((sDstFileDir != _path) && !NSDirectory::Exists(sDstFileDir)) NSDirectory::CreateDirectories(sDstFileDir); @@ -1642,6 +1715,8 @@ namespace NSDoctRenderer m_pInternal->m_oParams.m_sWorkDir = std::wstring(value); else if (sParam == "--cache-scripts") m_pInternal->m_bIsCacheScript = (std::wstring(value) == L"true"); + else if (sParam == "--save-use-only-names") + m_pInternal->m_sFolderForSaveOnlyUseNames = std::wstring(value); else if (sParam == "--argument") { std::wstring sArg(value); diff --git a/DesktopEditor/doctrenderer/doctrenderer.pro b/DesktopEditor/doctrenderer/doctrenderer.pro index 330a02d2d4..ec01261c60 100644 --- a/DesktopEditor/doctrenderer/doctrenderer.pro +++ b/DesktopEditor/doctrenderer/doctrenderer.pro @@ -44,3 +44,27 @@ unix { target.path = /usr/lib INSTALLS += target } + +# downloader +DEFINES += BUIDLER_OPEN_DOWNLOAD_ENABLED +DEFINES += BUIDLER_OPEN_BASE64_ENABLED + +HEADERS += ../../Common/FileDownloader/FileDownloader.h +core_windows { + SOURCES += \ + ../../Common/FileDownloader/FileDownloader_win.cpp + + LIBS += -lurlmon +} +core_linux { + SOURCES += \ + ../../Common/FileDownloader/FileDownloader_curl.cpp + + LIBS += -lcurl +} +core_mac { + OBJECTIVE_SOURCES += \ + ../../Common/FileDownloader/FileDownloader_mac.mm + + LIBS += -framework AppKit +}