@@ -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,35 +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
-
35
- // check profile long name
36
- if ( ! customProfile.count ( constants::avProfileIdentificator ) )
37
- {
38
- std::cout << " Warning: A profile has no name. It will not be loaded." << std::endl;
39
- return ;
40
- }
41
-
42
- // check profile type
43
- if ( customProfile.count ( constants::avProfileType ) == 0 )
44
- {
45
- std::cout << " Warning: The profile " << customProfile.find ( constants::avProfileIdentificator )->second << " has not type. It will not be loaded." << std::endl;
46
- return ;
47
- }
48
-
49
- // check complete profile
50
- bool isValid = false ;
51
- std::string type ( customProfile.find ( constants::avProfileType )->second );
52
- if ( type == constants::avProfileTypeFormat )
53
- isValid = checkFormatProfile ( customProfile );
54
- else if ( type == constants::avProfileTypeVideo )
55
- isValid = checkVideoProfile ( customProfile );
56
- else if ( type == constants::avProfileTypeAudio )
57
- isValid = checkAudioProfile ( customProfile );
58
-
59
- if ( isValid )
60
- _profiles.push_back ( customProfile );
61
- else
62
- std::cout << " Warning: The profile " << customProfile.find ( constants::avProfileIdentificator )->second << " is invalid. It will not be loaded." << std::endl;
34
+ loadProfile ( customProfile );
63
35
}
64
36
65
37
void ProfileLoader::loadProfiles ( const std::string& avProfilesPath )
@@ -84,28 +56,46 @@ void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
84
56
for ( std::vector< std::string >::iterator fileIt = files.begin (); fileIt != files.end (); ++fileIt )
85
57
{
86
58
const std::string absPath = ( *dirIt ) + " /" + ( *fileIt );
87
- loadProfile ( absPath );
59
+ try
60
+ {
61
+ loadProfile ( absPath );
62
+ }
63
+ catch ( const std::exception& e )
64
+ {
65
+ std::cout << e.what () << std::endl;
66
+ }
88
67
}
89
68
}
90
69
}
91
70
92
- void ProfileLoader::update ( const Profile& profile )
71
+ void ProfileLoader::loadProfile ( const Profile& profile )
93
72
{
94
- Profile::const_iterator profileIt = profile.find ( constants::avProfileIdentificator );
95
- if ( profileIt == profile.end () )
96
- 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
+ }
97
78
98
- std::string profileId ( profileIt->second );
99
- size_t profileIndex = 0 ;
100
- for ( Profiles::iterator it = _profiles.begin (); it != _profiles.end (); ++it )
79
+ // check profile type
80
+ if ( profile.count ( constants::avProfileType ) == 0 )
101
81
{
102
- // profile already exists
103
- if ( (*it).find ( constants::avProfileIdentificator )->second == profileId )
104
- return ;
105
- ++profileIndex;
82
+ throw std::runtime_error ( " Warning: The profile " + profile.find ( constants::avProfileIdentificator )->second + " has not type. It will not be loaded." );
106
83
}
107
- // profile not found: add the new profile
108
- _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." );
109
99
}
110
100
111
101
const ProfileLoader::Profiles& ProfileLoader::getProfiles ()
0 commit comments