libragephoto/src/RagePhoto-Extract.cpp

75 lines
2.4 KiB
C++
Raw Normal View History

2021-08-25 00:30:10 +02:00
/*****************************************************************************
* libragephoto RAGE Photo Parser
* Copyright (C) 2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "RagePhoto.h"
2021-09-17 08:17:25 +02:00
#include <fstream>
2021-08-25 00:30:10 +02:00
#include <iostream>
2021-09-17 08:17:25 +02:00
#include <iterator>
2021-08-25 00:30:10 +02:00
int main(int argc, char *argv[])
{
if (argc != 3) {
2021-08-26 00:22:11 +02:00
std::cout << "Usage: " << argv[0] << " [photo] [jpegout]" << std::endl;
2021-08-25 00:30:10 +02:00
return 0;
}
2021-08-26 00:22:11 +02:00
// Make it crash when RagePhoto have a bug which make the deinitialisation to fail
{
// Initialise RagePhoto
RagePhoto ragePhoto;
2021-08-25 00:30:10 +02:00
2021-08-26 00:22:11 +02:00
// Read file
2021-09-17 08:17:25 +02:00
std::ifstream ifs(argv[1], std::ios::in | std::ios::binary);
if (!ifs.is_open()) {
std::cout << "Failed to open file: " << argv[1] << std::endl;
return 1;
2021-08-26 00:22:11 +02:00
}
2021-09-17 08:17:25 +02:00
std::string data(std::istreambuf_iterator<char>{ifs}, {});
ifs.close();
2021-08-26 00:22:11 +02:00
// Load Photo
2021-09-17 08:17:25 +02:00
const bool loaded = ragePhoto.load(data);
2021-08-26 00:22:11 +02:00
if (!loaded) {
2021-09-17 08:17:25 +02:00
if (ragePhoto.error() <= RagePhoto::Error::PhotoReadError) {
2021-08-26 00:22:11 +02:00
std::cout << "Failed to load photo" << std::endl;
return 1;
}
}
// Write jpeg
2021-09-17 08:17:25 +02:00
std::ofstream ofs(argv[2], std::ios::out | std::ios::binary | std::ios::trunc);
if (!ofs.is_open()) {
std::cout << "Failed to write file: " << argv[2] << std::endl;
return 1;
2021-08-26 00:22:11 +02:00
}
2021-09-17 08:17:25 +02:00
ofs << ragePhoto.photo();
ofs.close();
2021-08-26 00:22:11 +02:00
if (ragePhoto.format() == RagePhoto::GTA5)
2021-09-03 18:36:00 +02:00
std::cout << "GTA V Photo successfully exported" << std::endl;
else
std::cout << "RDR 2 Photo successfully exported" << std::endl;
2021-08-25 00:30:10 +02:00
2021-08-26 00:22:11 +02:00
// Clear RagePhoto (provocate crash when pointer leak)
ragePhoto.clear();
}
2021-08-25 00:30:10 +02:00
return 0;
}