From 5c43a39d1322c8cc943758d6173a8a177e76ddd2 Mon Sep 17 00:00:00 2001 From: Syping Date: Sun, 30 Nov 2025 08:13:17 +0100 Subject: [PATCH] libragephoto 0.8.2 release - CMakeLists.txt: update version to 0.8.2 - RagePhoto.cpp: fix memory issue on Windows convertPath function for C+ +11 support - RagePhoto.cs: code style changes for Boolean - RagePhoto.h: update copyright header - RagePhoto.hpp: update copyright header - RagePhotoLibrary.h: update copyright header - src/dotnet: add package tags and update version to 0.8.2 --- CMakeLists.txt | 2 +- src/core/RagePhoto.cpp | 17 ++++++++++------- src/core/RagePhoto.h | 2 +- src/core/RagePhoto.hpp | 2 +- src/core/RagePhotoLibrary.h | 2 +- src/dotnet/RagePhoto.Core.csproj | 9 +++++---- src/dotnet/RagePhoto.cs | 20 ++++++++++---------- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a128bc8..0a7726a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ cmake_minimum_required(VERSION 3.16) cmake_policy(VERSION 3.16...3.28) -project(ragephoto VERSION 0.8.1 LANGUAGES C CXX) +project(ragephoto VERSION 0.8.2 LANGUAGES C CXX) include(GNUInstallDirs) # RagePhoto CMake includes diff --git a/src/core/RagePhoto.cpp b/src/core/RagePhoto.cpp index 7a0b5e7..b76ed75 100644 --- a/src/core/RagePhoto.cpp +++ b/src/core/RagePhoto.cpp @@ -66,13 +66,16 @@ const char* nullchar = ""; /* BEGIN OF STATIC LIBRARY FUNCTIONS */ #if defined(_WIN32) && ((RAGEPHOTO_CXX_STD < 17) || (__cplusplus < 201703L)) -inline std::unique_ptr convertPath(const char *path) +inline std::wstring convertPath(const char *path) { int wideCharSize = MultiByteToWideChar(CP_UTF8, 0, path, -1, nullptr, 0); if (wideCharSize <= 0) - return std::unique_ptr(new wchar_t[1]()); - std::unique_ptr wideCharPath(new wchar_t[wideCharSize]); - MultiByteToWideChar(CP_UTF8, 0, path, -1, wideCharPath.get(), wideCharSize); + return {}; + std::wstring wideCharPath; + wideCharPath.resize(wideCharSize); + if (!MultiByteToWideChar(CP_UTF8, 0, path, -1, &wideCharPath[0], wideCharSize)) + return {}; + wideCharPath.resize(wideCharSize - 1); return wideCharPath; } #endif @@ -292,7 +295,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra rp_data->error = Error::HeaderMallocError; // 4 return false; } - memcpy(rp_data->header, photoHeader_string.c_str(), photoHeader_size); + memcpy(rp_data->header, photoHeader_string.data(), photoHeader_size); #elif defined UNICODE_ICONV iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE"); if (iconv_in == (iconv_t)-1) { @@ -610,7 +613,7 @@ bool RagePhoto::loadFile(const char *filename) #if defined(_WIN32) && (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L) std::ifstream ifs(std::filesystem::u8path(filename), std::ios::in | std::ios::binary); #elif defined(_WIN32) - std::ifstream ifs(convertPath(filename).get(), std::ios::in | std::ios::binary); + std::ifstream ifs(convertPath(filename).data(), std::ios::in | std::ios::binary); #else std::ifstream ifs(filename, std::ios::in | std::ios::binary); #endif @@ -1012,7 +1015,7 @@ bool RagePhoto::saveFile(const char *filename, uint32_t photoFormat) #if defined(_WIN32) && (RAGEPHOTO_CXX_STD >= 17) && (__cplusplus >= 201703L) std::ofstream ofs(std::filesystem::u8path(filename), std::ios::out | std::ios::binary | std::ios::trunc); #elif defined(_WIN32) - std::ofstream ofs(convertPath(filename).get(), std::ios::out | std::ios::binary | std::ios::trunc); + std::ofstream ofs(convertPath(filename).data(), std::ios::out | std::ios::binary | std::ios::trunc); #else std::ofstream ofs(filename, std::ios::out | std::ios::binary | std::ios::trunc); #endif diff --git a/src/core/RagePhoto.h b/src/core/RagePhoto.h index 68429be..4047de9 100644 --- a/src/core/RagePhoto.h +++ b/src/core/RagePhoto.h @@ -1,6 +1,6 @@ /***************************************************************************** * libragephoto RAGE Photo Parser -* Copyright (C) 2021-2024 Syping +* Copyright (C) 2021-2025 Syping * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: diff --git a/src/core/RagePhoto.hpp b/src/core/RagePhoto.hpp index ad1b52d..b36287d 100644 --- a/src/core/RagePhoto.hpp +++ b/src/core/RagePhoto.hpp @@ -1,6 +1,6 @@ /***************************************************************************** * libragephoto RAGE Photo Parser -* Copyright (C) 2023-2024 Syping +* Copyright (C) 2023-2025 Syping * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: diff --git a/src/core/RagePhotoLibrary.h b/src/core/RagePhotoLibrary.h index 66896eb..3058cc7 100644 --- a/src/core/RagePhotoLibrary.h +++ b/src/core/RagePhotoLibrary.h @@ -1,6 +1,6 @@ /***************************************************************************** * libragephoto RAGE Photo Parser -* Copyright (C) 2023 Syping +* Copyright (C) 2023-2025 Syping * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: diff --git a/src/dotnet/RagePhoto.Core.csproj b/src/dotnet/RagePhoto.Core.csproj index c0e2bb5..7e178bd 100644 --- a/src/dotnet/RagePhoto.Core.csproj +++ b/src/dotnet/RagePhoto.Core.csproj @@ -1,17 +1,18 @@  - netstandard2.1;net47;net8.0 + netstandard2.1;net47 RagePhoto.Core RagePhoto - 0.8.1 - 0.8.1 - 0.8.1 + 0.8.2 + 0.8.2 + 0.8.2 Syping Copyright © 2025 Syping Open Source RAGE Photo Parser for GTA V and RDR 2 BSD-2-Clause README.md + libragephoto;gta5;gtav;snapmatic;rdr2;photo https://github.com/Syping/libragephoto disable diff --git a/src/dotnet/RagePhoto.cs b/src/dotnet/RagePhoto.cs index 033db5c..ddb1dd7 100644 --- a/src/dotnet/RagePhoto.cs +++ b/src/dotnet/RagePhoto.cs @@ -6,7 +6,7 @@ namespace RagePhoto { public class Photo : IDisposable { - private bool _disposed; + private Boolean _disposed; private readonly IntPtr _instance; private const String _library = "libragephoto"; @@ -18,10 +18,10 @@ namespace RagePhoto { private static extern void ragephoto_close(IntPtr instance); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_load(IntPtr instance, Byte[] data, UIntPtr size); + private static extern Boolean ragephoto_load(IntPtr instance, Byte[] data, UIntPtr size); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_loadfile(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename); + private static extern Boolean ragephoto_loadfile(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern Int32 ragephoto_error(IntPtr instance); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] @@ -48,30 +48,30 @@ namespace RagePhoto { private static extern UIntPtr ragephoto_getsavesizef(IntPtr instance, UInt32 photoFormat); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_save(IntPtr instance, [Out] Byte[] data); + private static extern Boolean ragephoto_save(IntPtr instance, [Out] Byte[] data); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_savef(IntPtr instance, [Out] Byte[] data, UInt32 photoFormat); + private static extern Boolean ragephoto_savef(IntPtr instance, [Out] Byte[] data, UInt32 photoFormat); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_savefile(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename); + private static extern Boolean ragephoto_savefile(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_savefilef(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename, UInt32 photoFormat); + private static extern Boolean ragephoto_savefilef(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String filename, UInt32 photoFormat); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void ragephoto_setbufferdefault(IntPtr instance); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void ragephoto_setbufferoffsets(IntPtr instance); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_setphotodatac(IntPtr instance, IntPtr data); + private static extern Boolean ragephoto_setphotodatac(IntPtr instance, IntPtr data); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void ragephoto_setphotodesc(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String description, UInt32 bufferSize); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void ragephoto_setphotoformat(IntPtr instance, UInt32 photoFormat); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.I1)] - private static extern bool ragephoto_setphotojpeg(IntPtr instance, Byte[] jpeg, UInt32 size, UInt32 bufferSize); + private static extern Boolean ragephoto_setphotojpeg(IntPtr instance, Byte[] jpeg, UInt32 size, UInt32 bufferSize); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] private static extern void ragephoto_setphotojson(IntPtr instance, [MarshalAs(UnmanagedType.LPUTF8Str)] String json, UInt32 bufferSize); [DllImport(_library, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] @@ -114,7 +114,7 @@ namespace RagePhoto { GC.SuppressFinalize(this); } - protected virtual void Dispose(bool disposing) { + protected virtual void Dispose(Boolean disposing) { if (_disposed) return; ragephoto_close(_instance);