@@ -16,10 +16,10 @@ ProfileLoader::ProfileLoader( bool autoload )
16
16
loadProfiles ();
17
17
}
18
18
19
- void ProfileLoader::loadProfile ( const std::string& avProfileFile )
19
+ void ProfileLoader::loadProfile ( const std::string& avProfileFileName )
20
20
{
21
21
std::ifstream infile;
22
- infile.open ( avProfileFile .c_str (), std::ifstream::in );
22
+ infile.open ( avProfileFileName .c_str (), std::ifstream::in );
23
23
24
24
ProfileLoader::Profile customProfile;
25
25
@@ -31,18 +31,7 @@ void ProfileLoader::loadProfile( const std::string& avProfileFile )
31
31
if ( keyValue.size () == 2 )
32
32
customProfile[ keyValue.at ( 0 ) ] = keyValue.at ( 1 );
33
33
}
34
- // check if profile contains required values
35
- if (
36
- customProfile.count ( constants::avProfileIdentificator ) &&
37
- customProfile.count ( constants::avProfileIdentificatorHuman ) &&
38
- customProfile.count ( constants::avProfileType ) &&
39
- ( customProfile.find ( constants::avProfileType )->second == constants::avProfileTypeFormat ||
40
- customProfile.find ( constants::avProfileType )->second == constants::avProfileTypeVideo ||
41
- customProfile.find ( constants::avProfileType )->second == constants::avProfileTypeAudio )
42
- )
43
- {
44
- _profiles.push_back ( customProfile );
45
- }
34
+ loadProfile ( customProfile );
46
35
}
47
36
48
37
void ProfileLoader::loadProfiles ( const std::string& avProfilesPath )
@@ -67,28 +56,46 @@ void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
67
56
for ( std::vector< std::string >::iterator fileIt = files.begin (); fileIt != files.end (); ++fileIt )
68
57
{
69
58
const std::string absPath = ( *dirIt ) + " /" + ( *fileIt );
70
- loadProfile ( absPath );
59
+ try
60
+ {
61
+ loadProfile ( absPath );
62
+ }
63
+ catch ( const std::exception& e )
64
+ {
65
+ std::cout << e.what () << std::endl;
66
+ }
71
67
}
72
68
}
73
69
}
74
70
75
- void ProfileLoader::update ( const Profile& profile )
71
+ void ProfileLoader::loadProfile ( const Profile& profile )
76
72
{
77
- Profile::const_iterator profileIt = profile.find ( constants::avProfileIdentificator );
78
- if ( profileIt == profile.end () )
79
- throw std::runtime_error ( " Invalid profile: can't get identificator" );
73
+ // check profile long name
74
+ if ( ! profile.count ( constants::avProfileIdentificator ) )
75
+ {
76
+ throw std::runtime_error ( " Warning: A profile has no name. It will not be loaded." );
77
+ }
80
78
81
- std::string profileId ( profileIt->second );
82
- size_t profileIndex = 0 ;
83
- for ( Profiles::iterator it = _profiles.begin (); it != _profiles.end (); ++it )
79
+ // check profile type
80
+ if ( profile.count ( constants::avProfileType ) == 0 )
84
81
{
85
- // profile already exists
86
- if ( (*it).find ( constants::avProfileIdentificator )->second == profileId )
87
- return ;
88
- ++profileIndex;
82
+ throw std::runtime_error ( " Warning: The profile " + profile.find ( constants::avProfileIdentificator )->second + " has not type. It will not be loaded." );
89
83
}
90
- // profile not found: add the new profile
91
- _profiles.push_back ( profile );
84
+
85
+ // check complete profile
86
+ bool isValid = false ;
87
+ std::string type ( profile.find ( constants::avProfileType )->second );
88
+ if ( type == constants::avProfileTypeFormat )
89
+ isValid = checkFormatProfile ( profile );
90
+ else if ( type == constants::avProfileTypeVideo )
91
+ isValid = checkVideoProfile ( profile );
92
+ else if ( type == constants::avProfileTypeAudio )
93
+ isValid = checkAudioProfile ( profile );
94
+
95
+ if ( isValid )
96
+ _profiles.push_back ( profile );
97
+ else
98
+ throw std::runtime_error ( " Warning: The profile " + profile.find ( constants::avProfileIdentificator )->second + " is invalid. It will not be loaded." );
92
99
}
93
100
94
101
const ProfileLoader::Profiles& ProfileLoader::getProfiles ()
@@ -147,4 +154,51 @@ ProfileLoader::Profile& ProfileLoader::getProfile( const std::string& avProfileI
147
154
throw std::runtime_error ( " unable to find profile: " + avProfileIdentificator );
148
155
}
149
156
157
+
158
+ bool ProfileLoader::checkFormatProfile ( const Profile& profileToCheck )
159
+ {
160
+ bool isValid = true ;
161
+
162
+ if ( ! profileToCheck.count ( constants::avProfileIdentificator ) ||
163
+ ! profileToCheck.count ( constants::avProfileIdentificatorHuman ) ||
164
+ ! profileToCheck.count ( constants::avProfileType ) ||
165
+ ! profileToCheck.count ( constants::avProfileFormat ) )
166
+ {
167
+ isValid = false ;
168
+ }
169
+
170
+ return isValid;
171
+ }
172
+
173
+ bool ProfileLoader::checkVideoProfile ( const Profile& profileToCheck )
174
+ {
175
+ bool isValid = true ;
176
+
177
+ if ( ! profileToCheck.count ( constants::avProfileIdentificator ) ||
178
+ ! profileToCheck.count ( constants::avProfileIdentificatorHuman ) ||
179
+ ! profileToCheck.count ( constants::avProfileType ) ||
180
+ ! profileToCheck.count ( constants::avProfileCodec ) )
181
+ {
182
+ isValid = false ;
183
+ }
184
+
185
+ return isValid;
186
+ }
187
+
188
+ bool ProfileLoader::checkAudioProfile ( const Profile& profileToCheck )
189
+ {
190
+ bool isValid = true ;
191
+
192
+ if ( ! profileToCheck.count ( constants::avProfileIdentificator ) ||
193
+ ! profileToCheck.count ( constants::avProfileIdentificatorHuman ) ||
194
+ ! profileToCheck.count ( constants::avProfileType ) ||
195
+ ! profileToCheck.count ( constants::avProfileCodec ) )
196
+ {
197
+ isValid = false ;
198
+ }
199
+
200
+ return isValid;
201
+ }
202
+
203
+
150
204
}
0 commit comments