RagePhoto-Extract: use RagePhoto::loadFile

This commit is contained in:
Syping 2021-11-02 10:24:22 +01:00
parent a396d014f7
commit 9d9e0c8b05
1 changed files with 23 additions and 34 deletions

View File

@ -28,25 +28,18 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
// Make it crash when RagePhoto have a bug which make the deinitialisation to fail
{
// Initialise RagePhoto // Initialise RagePhoto
RagePhoto ragePhoto; RagePhoto ragePhoto;
// Read file // Load Photo
std::ifstream ifs(argv[1], std::ios::in | std::ios::binary); const bool loaded = ragePhoto.loadFile(argv[1]);
if (!ifs.is_open()) {
if (!loaded) {
if (ragePhoto.error() == RagePhoto::Error::Uninitialised) {
std::cout << "Failed to open file: " << argv[1] << std::endl; std::cout << "Failed to open file: " << argv[1] << std::endl;
return 1; return 1;
} }
std::string data(std::istreambuf_iterator<char>{ifs}, {}); else if (ragePhoto.error() <= RagePhoto::Error::PhotoReadError) {
ifs.close();
// Load Photo
const bool loaded = ragePhoto.load(data);
if (!loaded) {
if (ragePhoto.error() <= RagePhoto::Error::PhotoReadError) {
std::cout << "Failed to load photo" << std::endl; std::cout << "Failed to load photo" << std::endl;
return 1; return 1;
} }
@ -66,9 +59,5 @@ int main(int argc, char *argv[])
else else
std::cout << "RDR 2 Photo successfully exported" << std::endl; std::cout << "RDR 2 Photo successfully exported" << std::endl;
// Clear RagePhoto (provocate crash when pointer leak)
ragePhoto.clear();
}
return 0; return 0;
} }