MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / addSupportedFiles

Function addSupportedFiles

src/OpenColorIO/OCIOZArchive.cpp:149–202  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////////// Utility functions section ///////////////////////////////////////////////////////////////////////////////// * Utility function for archived Configs. * * \param archiver Minizip-ng handle object. * \param path Path of the file or the folder to add inside the OCIOZ archive. * \param configWorkingDirectory Working

Source from the content-addressed store, hash-verified

147 * \param configWorkingDirectory Working directory of the current config.
148 */
149void addSupportedFiles(void * archiver, const char * path, const char * configWorkingDirectory)
150{
151 DIR *dir = mz_os_open_dir(path);
152 if (dir != NULL)
153 {
154 struct dirent *entry = NULL;
155 while ((entry = mz_os_read_dir(dir)) != NULL)
156 {
157 // Join the current path and the directory/file name to get the absolute path.
158 std::string absPath = pystring::os::path::join(path, entry->d_name);
159 // Check if the absolute path is a directory.
160 if (mz_os_is_dir(absPath.c_str()) == MZ_OK)
161 {
162 // Since mz_os_read_dir is listing the whole directory, "." and ".." must be
163 // ignored.
164 if (!StringUtils::Compare(".", entry->d_name) &&
165 !StringUtils::Compare("..", entry->d_name))
166 {
167 // Add the current directory.
168 addSupportedFiles(archiver, absPath.c_str(), configWorkingDirectory);
169 }
170 }
171 else
172 {
173 // Absolute path is a file.
174 std::string root, ext;
175 pystring::os::path::splitext(root, ext, std::string(entry->d_name));
176 // Strip leading dot character in order to get the extension name only.
177 ext = pystring::lstrip(ext, ".");
178
179 // Check if the extension is supported. Using logic from LoadFileUncached().
180 FormatRegistry & formatRegistry = FormatRegistry::GetInstance();
181 FileFormatVector possibleFormats;
182 formatRegistry.getFileFormatForExtension(ext, possibleFormats);
183 if (!possibleFormats.empty())
184 {
185 // The extension is supported. Add the current file to the OCIOZ archive.
186 if (mz_zip_writer_add_path(
187 archiver, absPath.c_str(),
188 configWorkingDirectory, 0, 1) != MZ_OK)
189 {
190 // Close DIR object before throwing.
191 mz_os_close_dir(dir);
192
193 std::ostringstream os;
194 os << "Could not write LUT file " << absPath << " to in-memory archive.";
195 throw Exception(os.str().c_str());
196 }
197 }
198 }
199 }
200 mz_os_close_dir(dir);
201 }
202}
203//////////////////////////////////////////////////////////////////////////////////////
204
205void archiveConfig(std::ostream & ostream, const Config & config, const char * configWorkingDirectory)

Callers 1

archiveConfigFunction · 0.85

Calls 3

CompareFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected