Skip to content

Commit a115736

Browse files
committed
Add global comment to archives to record OCIO version used to create them
Signed-off-by: Kevin Wheatley <[email protected]>
1 parent 4869a87 commit a115736

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/OpenColorIO/OCIOZArchive.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ void archiveConfig(std::ostream & ostream, const Config & config, const char * c
325325
else
326326
addSupportedFiles(archiver, configWorkingDirectory, configWorkingDirectory);
327327

328+
std::ostringstream comment;
329+
comment << "Configuration written by archiveConfig() OCIO: " << GetVersion();
330+
mz_zip_writer_set_comment(archiver, comment.str().c_str());
331+
328332
// Close in-memory zip.
329333
mz_zip_writer_close(archiver);
330334
}

src/apps/ocioarchive/main.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int main(int argc, const char **argv)
123123
std::cerr << "ERROR: Could not load config: " << configFilename << std::endl;
124124
exit(1);
125125
}
126-
126+
127127
}
128128
else if (ocioEnv && *ocioEnv)
129129
{
@@ -136,7 +136,7 @@ int main(int argc, const char **argv)
136136
catch (...)
137137
{
138138
// Capture any errors and display a custom message.
139-
std::cerr << "ERROR: Could not load config from $OCIO variable: "
139+
std::cerr << "ERROR: Could not load config from $OCIO variable: "
140140
<< ocioEnv << std::endl;
141141
exit(1);
142142
}
@@ -147,11 +147,11 @@ int main(int argc, const char **argv)
147147
exit(1);
148148
}
149149

150-
try
150+
try
151151
{
152152
// The ocioz extension is added by the archive method. The assumption is that
153153
// archiveName is the filename without extension.
154-
154+
155155
// Do not add ocioz extension if already present.
156156
if (!StringUtils::EndsWith(archiveName, ".ocioz"))
157157
{
@@ -163,14 +163,14 @@ int main(int argc, const char **argv)
163163
{
164164
OCIO::ArchiveFlags flags = OCIO::ARCHIVE_FLAGS_DEFAULT;
165165
if (minimal)
166-
flags = OCIO::ArchiveFlags(flags | OCIO::ARCHIVE_FLAGS_MINIMAL);
166+
flags = OCIO::ArchiveFlags(flags | OCIO::ARCHIVE_FLAGS_MINIMAL);
167167

168168
config->archive(ofstream, flags);
169169
ofstream.close();
170170
}
171171
else
172172
{
173-
std::cerr << "Could not open output stream for: "
173+
std::cerr << "Could not open output stream for: "
174174
<< archiveName + std::string(OCIO::OCIO_CONFIG_ARCHIVE_FILE_EXT)
175175
<< std::endl;
176176
exit(1);
@@ -180,13 +180,13 @@ int main(int argc, const char **argv)
180180
{
181181
std::cerr << e.what() << std::endl;
182182
exit(1);
183-
}
183+
}
184184
}
185185
catch (OCIO::Exception & exception)
186186
{
187187
std::cerr << "ERROR: " << exception.what() << std::endl;
188188
exit(1);
189-
}
189+
}
190190
catch (std::exception& exception)
191191
{
192192
std::cerr << "ERROR: " << exception.what() << std::endl;
@@ -210,7 +210,7 @@ int main(int argc, const char **argv)
210210
}
211211

212212
archiveName = args[0].c_str();
213-
try
213+
try
214214
{
215215
if (extractDestination.empty())
216216
{
@@ -250,7 +250,7 @@ int main(int argc, const char **argv)
250250
mz_zip_reader_create(&reader);
251251
#endif
252252
struct tm tmu_date;
253-
253+
254254
err = mz_zip_reader_open_file(reader, path.c_str());
255255
if (err != MZ_OK)
256256
{
@@ -273,7 +273,7 @@ int main(int argc, const char **argv)
273273
err = mz_zip_reader_entry_get_info(reader, &file_info);
274274
if (err != MZ_OK)
275275
{
276-
std::cerr << "ERROR: Could not get information from entry: " << file_info->filename
276+
std::cerr << "ERROR: Could not get information from entry: " << file_info->filename
277277
<< std::endl;
278278
exit(1);
279279
}
@@ -290,6 +290,13 @@ int main(int argc, const char **argv)
290290

291291
err = mz_zip_reader_goto_next_entry(reader);
292292
} while (err == MZ_OK);
293+
294+
const char *global_comment = nullptr;
295+
if (mz_zip_reader_get_comment(reader, &global_comment) == MZ_OK)
296+
{
297+
if (global_comment)
298+
std::cout << "\n" << global_comment << "\n";
299+
}
293300
}
294301

295302
// Generic error handling.

0 commit comments

Comments
 (0)