Fixed Profile to throw exception if an invalid file was provided.

This commit is contained in:
Jonathan Thomas
2014-01-10 17:05:20 -06:00
parent dfe96b638c
commit 0571a95201
2 changed files with 22 additions and 5 deletions

View File

@@ -29,17 +29,13 @@
#define OPENSHOT_PROFILE_H
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>
#include <fstream>
#include <qt5/QtCore/qstring.h>
#include <qt5/QtCore/qstringlist.h>
#include <stdio.h>
#include <stdlib.h>
#include <tr1/memory>
#include <vector>
#include "Exceptions.h"
#include "Fraction.h"
#include "Json.h"

View File

@@ -33,8 +33,24 @@ using namespace openshot;
// @brief Constructor for Profile.
// @param path The folder path / location of a profile file
Profile::Profile(string path) throw(InvalidFile, InvalidJSON) {
bool read_file = false;
try
{
// Initialize info values
info.description = "";
info.height = 0;
info.width = 0;
info.pixel_format = 0;
info.fps.num = 0;
info.fps.den = 0;
info.pixel_ratio.num = 0;
info.pixel_ratio.den = 0;
info.display_ratio.num = 0;
info.display_ratio.den = 0;
info.interlaced_frame = false;
// Read the profile file
ifstream myfile (path.c_str());
if (myfile.is_open())
@@ -43,6 +59,7 @@ Profile::Profile(string path) throw(InvalidFile, InvalidJSON) {
while (myfile.good())
{
// read current line of file
read_file = true;
string line = "";
getline (myfile, line);
@@ -103,13 +120,17 @@ Profile::Profile(string path) throw(InvalidFile, InvalidJSON) {
myfile.close();
}
}
catch (exception e)
{
// Error parsing profile file
throw InvalidFile("Profile could not be found or loaded (or is invalid).", path);
}
// Throw error if file was not read
if (!read_file)
// Error parsing profile file
throw InvalidFile("Profile could not be found or loaded (or is invalid).", path);
}
// Generate JSON string of this object