Improve ragephoto-extract, RagePhoto header change

RagePhoto-Extract.c: use fopen_s on Windows
RagePhoto-Extract.cpp: use good() to check if file successfully written
RagePhoto.h: remove LIBRAGEPHOTO_C_API #ifdef to force error if compiled
without C API
This commit is contained in:
Syping 2021-11-13 09:47:03 +01:00
parent 136a6e1fec
commit 44d67fa78f
3 changed files with 12 additions and 2 deletions

View File

@ -27,6 +27,7 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
// Initialise RagePhoto
ragephoto_t ragephoto_in = ragephoto_open(); ragephoto_t ragephoto_in = ragephoto_open();
// Load Photo // Load Photo
@ -44,7 +45,12 @@ int main(int argc, char *argv[])
} }
// Write jpeg // Write jpeg
#ifdef _WIN32
FILE *file = NULL;
fopen_s(&file, argv[2], "wb");
#else
FILE *file = fopen(argv[2], "wb"); FILE *file = fopen(argv[2], "wb");
#endif
if (!file) { if (!file) {
printf("Failed to write file: %s\n", argv[2]); printf("Failed to write file: %s\n", argv[2]);
return 1; return 1;

View File

@ -51,8 +51,14 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
ofs << ragePhoto.photo(); ofs << ragePhoto.photo();
const bool ok = ofs.good();
ofs.close(); ofs.close();
if (!ok) {
std::cout << "Failed to write file: " << argv[2] << std::endl;
return 1;
}
if (ragePhoto.format() == RagePhoto::GTA5) if (ragePhoto.format() == RagePhoto::GTA5)
std::cout << "GTA V Photo successfully exported" << std::endl; std::cout << "GTA V Photo successfully exported" << std::endl;
else else

View File

@ -175,9 +175,7 @@ protected:
RagePhotoData m_data; RagePhotoData m_data;
}; };
#else #else
#ifdef LIBRAGEPHOTO_C_API
#include "RagePhotoC.h" #include "RagePhotoC.h"
#endif // LIBRAGEPHOTO_C_API
#endif // __cplusplus #endif // __cplusplus
#endif // RAGEPHOTO_H #endif // RAGEPHOTO_H