Kaydet (Commit) 3d300f1e authored tarafından Zolnai Tamás's avatar Zolnai Tamás

kmz2gltf: Use LO's ZipFileAccess to unzip kmz

Instead of this hacky collada2gltf patch.

Change-Id: I9f15c4ee1c9ea1a1a64116691b12b696c1d63ac5
üst 6904c836
...@@ -15,12 +15,14 @@ ...@@ -15,12 +15,14 @@
#include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/document/XStorageBasedDocument.hpp> #include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
#include <unotools/localfilehelper.hxx> #include <unotools/localfilehelper.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
...@@ -30,7 +32,6 @@ ...@@ -30,7 +32,6 @@
#ifdef ENABLE_COLLADA2GLTF #ifdef ENABLE_COLLADA2GLTF
#include <COLLADA2GLTFWriter.h> #include <COLLADA2GLTFWriter.h>
#include <GLTFAsset.h> #include <GLTFAsset.h>
#include <KMZ2Collada.h>
#endif #endif
#include <string> #include <string>
...@@ -42,6 +43,29 @@ using namespace boost::property_tree; ...@@ -42,6 +43,29 @@ using namespace boost::property_tree;
namespace avmedia { namespace avmedia {
#ifdef ENABLE_COLLADA2GLTF #ifdef ENABLE_COLLADA2GLTF
static void lcl_UnzipKmz(const OUString& rSourceURL, const OUString& rOutputFolderURL, OUString& o_rDaeFileURL)
{
o_rDaeFileURL = OUString();
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess =
packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(), rSourceURL);
uno::Sequence< OUString > aNames = xNameAccess->getElementNames();
for( sal_Int32 i = 0; i < aNames.getLength(); ++i )
{
const OUString sCopy = rOutputFolderURL + "/" + aNames[i];
if( aNames[i].endsWithIgnoreAsciiCase(".dae") )
o_rDaeFileURL = sCopy;
uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(aNames[i]), uno::UNO_QUERY);
::ucbhelper::Content aCopyContent(sCopy,
uno::Reference<ucb::XCommandEnvironment>(),
comphelper::getProcessComponentContext());
aCopyContent.writeStream(xInputStream, true);
}
}
bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput) bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput)
{ {
o_rOutput = OUString(); o_rOutput = OUString();
...@@ -66,7 +90,7 @@ bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput) ...@@ -66,7 +90,7 @@ bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput)
// KMZ covnerter need a temp folder in all case, because it creates temp files next to the source file // KMZ covnerter need a temp folder in all case, because it creates temp files next to the source file
OUString sInput = rSourceURL; OUString sInput = rSourceURL;
const INetURLObject aSourceURLObj(rSourceURL); const INetURLObject aSourceURLObj(rSourceURL);
if( bIsKMZ || aSourceURLObj.GetProtocol() != INET_PROT_FILE ) if( aSourceURLObj.GetProtocol() != INET_PROT_FILE )
{ {
try try
{ {
...@@ -93,20 +117,14 @@ bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput) ...@@ -93,20 +117,14 @@ bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput)
if (bIsKMZ) if (bIsKMZ)
{ {
// KMZ converter needs a system path OUString sDaeFilePath;
const std::string sSourcePath = lcl_UnzipKmz(sInput, sOutput, sDaeFilePath);
OUStringToOString( INetURLObject(sInput).getFSysPath(INetURLObject::FSYS_DETECT), RTL_TEXTENCODING_UTF8 ).getStr(); if ( sDaeFilePath.isEmpty() )
const std::string strDaeFilePath = GLTF::Kmz2Collada()(sSourcePath);
if (strDaeFilePath == "")
{ {
SAL_WARN("avmedia.opengl", "Kmz2Collada converter return with an empty URL\n" << rSourceURL); SAL_WARN("avmedia.opengl", "Cannot find dae file in kmz:\n" << rSourceURL);
return false; return false;
} }
// DAE converter needs URL
OUString sDaeFilePath;
::utl::LocalFileHelper::ConvertPhysicalNameToURL(
OStringToOUString(OString(strDaeFilePath.c_str()), RTL_TEXTENCODING_UTF8 ), sDaeFilePath);
asset->setInputFilePath(OUStringToOString( sDaeFilePath, RTL_TEXTENCODING_UTF8 ).getStr()); asset->setInputFilePath(OUStringToOString( sDaeFilePath, RTL_TEXTENCODING_UTF8 ).getStr());
} }
...@@ -114,7 +132,6 @@ bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput) ...@@ -114,7 +132,6 @@ bool KmzDae2Gltf(const OUString& rSourceURL, OUString& o_rOutput)
writer.write(); writer.write();
// Path to the .json file created by COLLADA2GLTFWriter // Path to the .json file created by COLLADA2GLTFWriter
o_rOutput = sOutput + "/" + GetFilename(sOutput) + ".json"; o_rOutput = sOutput + "/" + GetFilename(sOutput) + ".json";
return true; return true;
} }
#endif #endif
......
...@@ -50,7 +50,6 @@ $(eval $(call gb_StaticLibrary_add_generated_exception_objects,collada2gltf,\ ...@@ -50,7 +50,6 @@ $(eval $(call gb_StaticLibrary_add_generated_exception_objects,collada2gltf,\
UnpackedTarball/collada2gltf/COLLADA2GLTFWriter \ UnpackedTarball/collada2gltf/COLLADA2GLTFWriter \
UnpackedTarball/collada2gltf/GitSHA1 \ UnpackedTarball/collada2gltf/GitSHA1 \
UnpackedTarball/collada2gltf/GLTFOpenCOLLADAUtils \ UnpackedTarball/collada2gltf/GLTFOpenCOLLADAUtils \
UnpackedTarball/collada2gltf/KMZ2Collada \
UnpackedTarball/collada2gltf/assetModifiers/GLTFFlipUVModifier \ UnpackedTarball/collada2gltf/assetModifiers/GLTFFlipUVModifier \
UnpackedTarball/collada2gltf/convert/meshConverter \ UnpackedTarball/collada2gltf/convert/meshConverter \
UnpackedTarball/collada2gltf/convert/animationConverter \ UnpackedTarball/collada2gltf/convert/animationConverter \
...@@ -82,11 +81,6 @@ $(eval $(call gb_StaticLibrary_add_generated_exception_objects,collada2gltf,\ ...@@ -82,11 +81,6 @@ $(eval $(call gb_StaticLibrary_add_generated_exception_objects,collada2gltf,\
UnpackedTarball/collada2gltf/shaders/commonProfileShaders \ UnpackedTarball/collada2gltf/shaders/commonProfileShaders \
)) ))
$(eval $(call gb_StaticLibrary_add_generated_cobjects,collada2gltf,\
UnpackedTarball/collada2gltf/kmz/ioapi \
UnpackedTarball/collada2gltf/kmz/unzip \
))
# o3dgc external library compiled from collada2gltf # o3dgc external library compiled from collada2gltf
$(eval $(call gb_StaticLibrary_set_include,collada2gltf,\ $(eval $(call gb_StaticLibrary_set_include,collada2gltf,\
-I$(call gb_UnpackedTarball_get_dir,collada2gltf)/dependencies/o3dgc/src/o3dgc_common_lib/inc \ -I$(call gb_UnpackedTarball_get_dir,collada2gltf)/dependencies/o3dgc/src/o3dgc_common_lib/inc \
......
...@@ -14,17 +14,7 @@ $(eval $(call gb_UnpackedTarball_set_tarball,collada2gltf,$(COLLADA2GLTF_TARBALL ...@@ -14,17 +14,7 @@ $(eval $(call gb_UnpackedTarball_set_tarball,collada2gltf,$(COLLADA2GLTF_TARBALL
$(eval $(call gb_UnpackedTarball_add_file,collada2gltf,.,external/collada2gltf/GitSHA1.cpp)) $(eval $(call gb_UnpackedTarball_add_file,collada2gltf,.,external/collada2gltf/GitSHA1.cpp))
$(eval $(call gb_UnpackedTarball_add_patches,collada2gltf,\ $(eval $(call gb_UnpackedTarball_add_patches,collada2gltf,\
external/collada2gltf/patches/add-unzip-kmz-files-to-collada-files-module.patch.3 \
external/collada2gltf/patches/wrong_uri_usage.patch.1 \ external/collada2gltf/patches/wrong_uri_usage.patch.1 \
)) ))
ifneq ($(OS),WNT)
$(eval $(call gb_UnpackedTarball_add_patches,collada2gltf,\
external/collada2gltf/patches/write-only-.dae-file-which-we-need.patch.0 \
))
endif
# vim: set noet sw=4 ts=4: # vim: set noet sw=4 ts=4:
diff --git KMZ2Collada.cpp KMZ2Collada.cpp
index d193784..3b5bdfc 100644
--- KMZ2Collada.cpp
+++ KMZ2Collada.cpp
@@ -2,7 +2,7 @@
#include "kmz/unzip.h"
#include "kmz/ioapi.h"
-#include <direct.h>
+#include <string.h>
using namespace std;
@@ -14,39 +14,19 @@ namespace GLTF{
}
- void Kmz2Collada::setFileFolder(std::string& strSrc) {
- std::string strFolderPath = "";
- char *pFolderName = new char[strSrc.size()];
-
- for (unsigned int i = 0; i < strSrc.size(); i++) {
- if (strSrc[i] == '\\' || strSrc[i] == '/') {
- pFolderName[i] = '\0';
- strFolderPath = strKmzPath + pFolderName;
- _mkdir(strFolderPath.c_str());
- }
- pFolderName[i] = strSrc[i];
- }
- strSrc = strKmzPath +strSrc;
-
- delete[] pFolderName;
- }
- void Kmz2Collada::getFilePath(std::string& strSrc) {
+ void Kmz2Collada::getFilePath(const std::string& strSrc) {
char *pTemporaryContent = new char[strSrc.size()+1];
std::string strFilePath;
for (unsigned int ipos = 0; ipos < strSrc.size(); ipos ++) {
+ pTemporaryContent[ipos] = strSrc[ipos];
if (strSrc[ipos] == '\\' || strSrc[ipos] == '/') {
- pTemporaryContent[ipos] = '\0';
+ pTemporaryContent[ipos+1] = '\0';
strFilePath = pTemporaryContent;
- _mkdir(strFilePath.c_str());
}
- pTemporaryContent[ipos] = strSrc[ipos];
}
- if (strFilePath != "")
- strFilePath += '\\';
- strSrc = strFilePath;
- strKmzPath = strSrc;
+ strKmzPath = strFilePath;
delete[] pTemporaryContent;
}
@@ -72,18 +52,24 @@ namespace GLTF{
return "";
}
- for (int i = 0; i < zGlobalInfo.number_entry; i++) {
+ for (int i = 0; i < zGlobalInfo.number_entry; i++, unzGoToNextFile(zFile)) {
if (UNZ_OK != unzGetCurrentFileInfo64(zFile, &zFileInfo,
pFileName, num, NULL, 0, NULL, 0)) {
printf("Read file error\n");
return "";
}
- std::string strFilePath = pFileName;
- setFileFolder(strFilePath);
- if (strstr(strFilePath.c_str(), ".dae"))
- strDaePath = strFilePath;
+ if (!strstr(pFileName, ".dae"))
+ continue;
- FILE *fp = fopen(strFilePath.c_str(),"wb");
+ int pos = strlen(pFileName) - 1;
+ while (pos >= 0) {
+ if (pFileName[pos] == '\\' || pFileName[pos] == '/')
+ break;
+ pos--;
+ }
+ strDaePath = strKmzPath + std::string(&pFileName[pos + 1]);
+
+ FILE *fp = fopen(strDaePath.c_str(),"wb");
if (UNZ_OK != unzOpenCurrentFile(zFile)) {
printf("Open current file error");
@@ -107,8 +93,6 @@ namespace GLTF{
fclose(fp);
delete[] pFileData;
pFileData = NULL;
-
- unzGoToNextFile(zFile);
}
unzCloseCurrentFile(zFile);
@@ -118,4 +102,4 @@ namespace GLTF{
return strDaePath;
}
-}
\ No newline at end of file
+}
diff --git KMZ2Collada.h KMZ2Collada.h
index 5e8bdef..df7e92f 100644
--- KMZ2Collada.h
+++ KMZ2Collada.h
@@ -10,11 +10,8 @@ namespace GLTF{
Kmz2Collada();
~Kmz2Collada();
- /** get the kmz file path and set folder.*/
- void setFileFolder(std::string& strSrc);
-
/** get kmz file path.*/
- void getFilePath(std::string& strSrc);
+ void getFilePath(const std::string& strSrc);
/** copy function.*/
std::string operator()(std::string strInputFile);
@@ -25,4 +22,4 @@ namespace GLTF{
};
}
-#endif
\ No newline at end of file
+#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment