Skip to content

Commit 54121ce

Browse files
committed
Add Basic minimal archive functionallity
Needs documenting and testing May be nice to have a progress report and/or integration with OCIO Logging Signed-off-by: Kevin Wheatley <[email protected]>
1 parent a115736 commit 54121ce

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

include/OpenColorIO/OpenColorIO.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313
#include <fstream>
1414
#include <vector>
15+
#include <set>
1516

1617
#include "OpenColorABI.h"
1718
#include "OpenColorTypes.h"
@@ -1534,6 +1535,9 @@ class OCIOEXPORT Config
15341535
*/
15351536
void archive(std::ostream & ostream, ArchiveFlags flags) const;
15361537

1538+
//TODO: document
1539+
void GetAllFileReferences(std::set<std::string> & files) const;
1540+
15371541
Config(const Config &) = delete;
15381542
Config& operator= (const Config &) = delete;
15391543

src/OpenColorIO/Config.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5547,4 +5547,9 @@ void Config::archive(std::ostream & ostream, ArchiveFlags flags) const
55475547
archiveConfig(ostream, *this, getCurrentContext()->getWorkingDir(), flags);
55485548
}
55495549

5550+
void Config::GetAllFileReferences(std::set<std::string> & files) const
5551+
{
5552+
return getImpl()->GetAllFileReferences(files);
5553+
}
5554+
55505555
} // namespace OCIO_NAMESPACE

src/OpenColorIO/OCIOZArchive.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,34 @@ void addSupportedFiles(void * archiver, const char * path, const char * configWo
200200
mz_os_close_dir(dir);
201201
}
202202
}
203+
204+
void addReferencedFiles(void * archiver, const Config & config)
205+
{
206+
ConstContextRcPtr context = config.getCurrentContext();
207+
ContextRcPtr ctxFilepath = Context::Create();
208+
ctxFilepath->setSearchPath(context->getSearchPath());
209+
ctxFilepath->setWorkingDir(context->getWorkingDir());
210+
ctxFilepath->setConfigIOProxy(context->getConfigIOProxy());
211+
212+
auto prefixLength = std::string(context->getWorkingDir()).length() + 1; // +1 add trailing '/' TODO: improve this
213+
214+
std::set<std::string> files;
215+
config.GetAllFileReferences(files);
216+
for (const auto &file : files)
217+
{
218+
const std::string resolvedPath = context->resolveFileLocation(file.c_str(), ctxFilepath);
219+
const std::string relativePath = resolvedPath.substr(prefixLength);
220+
221+
auto returnCode = mz_zip_writer_add_file(archiver, resolvedPath.c_str(), relativePath.c_str());
222+
if (returnCode != MZ_OK)
223+
{
224+
std::ostringstream os;
225+
os << "Could not write file " << resolvedPath << " to in-memory archive.()" << returnCode << ")";
226+
throw Exception(os.str().c_str());
227+
}
228+
}
229+
}
230+
203231
//////////////////////////////////////////////////////////////////////////////////////
204232

205233
ArchiveFlags EnvironmentOverride(ArchiveFlags oFlags) // TODO: test override
@@ -321,7 +349,7 @@ void archiveConfig(std::ostream & ostream, const Config & config, const char * c
321349
// Add all supported files to in-memory zip from any directories under working directory.
322350
// (recursive)
323351
if (HasFlag(flags, ARCHIVE_FLAGS_MINIMAL))
324-
addSupportedFiles(archiver, configWorkingDirectory, configWorkingDirectory);
352+
addReferencedFiles(archiver, config);
325353
else
326354
addSupportedFiles(archiver, configWorkingDirectory, configWorkingDirectory);
327355

0 commit comments

Comments
 (0)