File: PackageFormat_Support.cpp

package info (click to toggle)
exempi 2.6.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,780 kB
  • sloc: cpp: 79,791; sh: 4,606; ansic: 538; makefile: 383
file content (124 lines) | stat: -rw-r--r-- 4,619 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// =================================================================================================
// Copyright Adobe
// Copyright 2013 Adobe
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it. 
// =================================================================================================

#include "public/include/XMP_Environment.h"	// ! XMP_Environment.h must be the first included header.

#include "XMPFiles/source/XMPFiles_Impl.hpp"
#include "XMPFiles/source/FormatSupport/PackageFormat_Support.hpp"
#include <algorithm>

// =================================================================================================
/// \file PackageFormat_Support.cpp
///
// =================================================================================================


// =================================================================================================
// PackageFormat_Support::GetPostfixRange
// ================================

#if 0
XMP_Bool PackageFormat_Support::GetPostfixRange ( XMP_FileFormat format , XMP_StringPtr extension, XMP_Uns32 * range )
{
	switch ( format ) {
		case kXMP_XDCAM_EXFile:
			range[0] = 1; range[1] = 99;
			break;
		case kXMP_CanonXFFile:
			range[0] = 1; range[1] = 99;
			break;
		case kXMP_XDCAM_SAMFile:
		case kXMP_XDCAM_FAMFile:
			range[0] = 1; range[1] = 99;
			break;
		case kXMP_P2File:
			range[0] = 0; range[1] = 99;// for voice memo files
			if(strcmp(extension, ".MXF") == 0)
				range[1] = 15;// for audio essence files
			break;
		default:
			return false;
	}
	return true;
}	// PackageFormat_Support::GetPostfixRange
#endif

// =================================================================================================
// PackageFormat_Support::AddResourceIfExists
// ================================

bool PackageFormat_Support::AddResourceIfExists ( XMP_StringVector * resourceList, const XMP_VarString & file )
{
	if ( Host_IO::Exists ( file.c_str() ) ) {
		resourceList->push_back ( file );
		return true;
	}
	return false;
}	// PackageFormat_Support::AddResourceIfExists

#if 0
// =================================================================================================
// PackageFormat_Support::AddResourceIfExists
// ================================

bool PackageFormat_Support::AddResourceIfExists ( XMP_StringVector * resourceList, const XMP_VarString & noExtPath,
	XMP_StringPtr extension, XMP_FileFormat format )
{
	XMP_Uns32 range[2];
	XMP_Bool atLeastOneFileAdded = false, fileAdded = false;
	XMP_VarString iStr, filePath;
	if ( GetPostfixRange ( format, extension, range ) ) {
		for( XMP_Uns32 index = range[0]; index <= range[1] ; ++index )
		{
			SXMPUtils::ConvertFromInt ( index, NULL, &iStr ) ;
			if ( index < LEAST_TWO_DIGIT_INT )
				iStr = '0' + iStr;
			filePath = noExtPath + iStr + extension;
			fileAdded = AddResourceIfExists ( resourceList, filePath );
			atLeastOneFileAdded  |= fileAdded ;
		}
	}
	return atLeastOneFileAdded;
}	// PackageFormat_Support::AddResourceIfExists

#endif
// =================================================================================================
// PackageFormat_Support::AddResourceIfExists
// ================================
bool PackageFormat_Support::AddResourceIfExists ( XMP_StringVector * resourceList, const XMP_VarString & folderPath,
	XMP_StringPtr prefix, XMP_StringPtr postfix )
{
	Host_IO::FolderRef folderHandle = Host_IO::OpenFolder ( folderPath.c_str() );
	if ( folderHandle == Host_IO::noFolderRef || !prefix || !postfix )
		return false;// can't open folder.
	XMP_VarString fileName, filePath;
	size_t fileNameLength;
	size_t prefixLength = strlen ( prefix );
	size_t postfixLength = strlen ( postfix );
	bool atleastOneFileAdded = false;
	while ( Host_IO::GetNextChild ( folderHandle, &fileName ) )
	{
		fileNameLength = fileName.length();
		// Check if the file name starts with prefix and ends with postfix
		if ( fileNameLength >= ( prefixLength + postfixLength ) && 
			fileName.compare ( fileNameLength-postfixLength, postfixLength, postfix ) == 0 && 
			fileName.compare ( 0, prefixLength, prefix ) == 0)
		{
			filePath = folderPath + kDirChar + fileName;
			PackageFormat_Support::AddResourceIfExists ( resourceList, filePath );
			atleastOneFileAdded = true;
		}
	}
	// close folder
	Host_IO::CloseFolder ( folderHandle );
	return atleastOneFileAdded;
}	// PackageFormat_Support::AddResourceIfExists


// =================================================================================================