From 9f9ac4b696cba2bdbb1747e288d00f984f2ce188 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Wed, 11 Sep 2019 09:55:43 +0200 Subject: [PATCH] Auto-updater --- .gitignore | 2 + 3rdparty/7z/7zlib/7zlib.vcxproj | 242 ++++++++++ 3rdparty/7z/7zlib/7zlib.vcxproj.filters | 264 +++++++++++ 3rdparty/CMakeLists.txt | 48 +- Utilities/File.cpp | 2 +- Utilities/Log.cpp | 39 +- rpcs3.sln | 19 +- rpcs3/Crypto/sha256.cpp | 449 +++++++++++++++++++ rpcs3/Crypto/sha256.h | 281 ++++++++++++ rpcs3/Emu/CMakeLists.txt | 1 + rpcs3/Emu/System.h | 4 +- rpcs3/Json/tooltips.json | 1 + rpcs3/emucore.vcxproj | 4 + rpcs3/emucore.vcxproj.filters | 6 + rpcs3/rpcs3.vcxproj | 45 +- rpcs3/rpcs3.vcxproj.filters | 21 + rpcs3/rpcs3_version.cpp | 10 + rpcs3/rpcs3_version.h | 1 + rpcs3/rpcs3qt/CMakeLists.txt | 1 + rpcs3/rpcs3qt/game_compatibility.cpp | 5 +- rpcs3/rpcs3qt/game_list_frame.cpp | 18 +- rpcs3/rpcs3qt/gui_settings.h | 1 + rpcs3/rpcs3qt/main_window.cpp | 27 +- rpcs3/rpcs3qt/main_window.h | 3 + rpcs3/rpcs3qt/main_window.ui | 9 +- rpcs3/rpcs3qt/progress_dialog.cpp | 4 +- rpcs3/rpcs3qt/progress_dialog.h | 2 +- rpcs3/rpcs3qt/settings_dialog.cpp | 8 + rpcs3/rpcs3qt/settings_dialog.ui | 7 + rpcs3/rpcs3qt/update_manager.cpp | 560 ++++++++++++++++++++++++ rpcs3/rpcs3qt/update_manager.h | 36 ++ 31 files changed, 2068 insertions(+), 52 deletions(-) create mode 100644 3rdparty/7z/7zlib/7zlib.vcxproj create mode 100644 3rdparty/7z/7zlib/7zlib.vcxproj.filters create mode 100644 rpcs3/Crypto/sha256.cpp create mode 100644 rpcs3/Crypto/sha256.h create mode 100644 rpcs3/rpcs3qt/update_manager.cpp create mode 100644 rpcs3/rpcs3qt/update_manager.h diff --git a/.gitignore b/.gitignore index 3542589944..9b3d9b057d 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,5 @@ CMakeLists.txt.user # macOS .DS_Store +# 7zlib +/3rdparty/7z/**/*.lib diff --git a/3rdparty/7z/7zlib/7zlib.vcxproj b/3rdparty/7z/7zlib/7zlib.vcxproj new file mode 100644 index 0000000000..f7cf99f68e --- /dev/null +++ b/3rdparty/7z/7zlib/7zlib.vcxproj @@ -0,0 +1,242 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 16.0 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C} + Win32Proj + My7zlib + 10.0 + + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + $(ProjectDir)$(Platform)\$(Configuration)\ + + + true + + + true + + + false + + + + NotUsing + Level3 + MaxSpeed + true + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + + + + + Use + Level3 + Disabled + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + true + + + + + + \ No newline at end of file diff --git a/3rdparty/7z/7zlib/7zlib.vcxproj.filters b/3rdparty/7z/7zlib/7zlib.vcxproj.filters new file mode 100644 index 0000000000..9b6cdbfaaa --- /dev/null +++ b/3rdparty/7z/7zlib/7zlib.vcxproj.filters @@ -0,0 +1,264 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 98d75940be..f3d72796eb 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -31,9 +31,55 @@ target_link_libraries(3rdparty_zlib INTERFACE ${ZLIB_LIBRARY}) target_include_directories(3rdparty_zlib INTERFACE ${ZLIB_INCLUDE_DIR}) # 7z sdk -add_library(3rdparty_7z INTERFACE) if(WIN32) + add_library(3rdparty_7z STATIC EXCLUDE_FROM_ALL + 7z/Sha256.c + 7z/Ppmd7Dec.c + 7z/XzDec.c + 7z/XzEnc.c + 7z/Lzma2Dec.c + 7z/XzCrc64.c + 7z/DllSecur.c + 7z/Lzma2DecMt.c + 7z/BraIA64.c + 7z/7zFile.c + 7z/7zStream.c + 7z/Lzma86Enc.c + 7z/Threads.c + 7z/7zAlloc.c + 7z/LzmaEnc.c + 7z/MtCoder.c + 7z/Lzma86Dec.c + 7z/Sort.c + 7z/LzFindMt.c + 7z/7zDec.c + 7z/Bcj2.c + 7z/Ppmd7.c + 7z/Bra86.c + 7z/Bcj2Enc.c + 7z/7zBuf.c + 7z/Aes.c + 7z/AesOpt.c + 7z/XzCrc64Opt.c + 7z/7zArcIn.c + 7z/Lzma2Enc.c + 7z/Bra.c + 7z/7zCrcOpt.c + 7z/7zBuf2.c + 7z/LzFind.c + 7z/Ppmd7Enc.c + 7z/CpuArch.c + 7z/Delta.c + 7z/XzIn.c + 7z/Alloc.c + 7z/Xz.c + 7z/LzmaDec.c + 7z/LzmaLib.c + 7z/7zCrc.c + 7z/MtDec.c) target_include_directories(3rdparty_7z INTERFACE 7z) +else() + add_library(3rdparty_7z INTERFACE) endif() # libPNG diff --git a/Utilities/File.cpp b/Utilities/File.cpp index d8626ea25b..fcf3ed12ac 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1067,7 +1067,7 @@ fs::file::file(const std::string& path, bs_t mode) m_file = std::make_unique(handle); #else - int flags = 0; + int flags = O_CLOEXEC; // Ensures all files are closed on execl for auto updater if (mode & fs::read && mode & fs::write) flags |= O_RDWR; else if (mode & fs::read) flags |= O_RDONLY; diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 789a1fe371..8059518141 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -329,25 +329,34 @@ logs::file_writer::file_writer(const std::string& name) { if (!m_file.open(buf_name, fs::read + fs::rewrite + fs::lock)) { - if (fs::g_tls_error == fs::error::acces) - { - if (fs::exists(buf_name)) - { - fmt::throw_exception("Another instance of %s is running. Close it or kill its process, if necessary.", name); - } - else - { - fmt::throw_exception("Cannot create %s.log (access denied)." #ifdef _WIN32 - "\nNote that %s cannot be installed in Program Files or similar directory with limited permissions." -#else - "\nPlease, check %s permissions in '~/.config/'." + // Windows does not close all handles before starting a new process with execl + // We delay another check for rpcs3 restart after an update + // TODO: cleaner solution? + std::this_thread::sleep_for(500ms); + if (!m_file.open(buf_name, fs::read + fs::rewrite + fs::lock)) #endif - , name, name); + { + if (fs::g_tls_error == fs::error::acces) + { + if (fs::exists(buf_name)) + { + fmt::throw_exception("Another instance of %s is running. Close it or kill its process, if necessary.", name); + } + else + { + fmt::throw_exception("Cannot create %s.log (access denied)." +#ifdef _WIN32 + "\nNote that %s cannot be installed in Program Files or similar directory with limited permissions." +#else + "\nPlease, check %s permissions in '~/.config/'." +#endif + , name, name); + } } - } - fmt::throw_exception("Cannot create %s.log (error %s)", name, fs::g_tls_error); + fmt::throw_exception("Cannot create %s.log (error %s)", name, fs::g_tls_error); + } } // Check free space diff --git a/rpcs3.sln b/rpcs3.sln index ccc39005e9..a3f3e3fead 100644 --- a/rpcs3.sln +++ b/rpcs3.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2027 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29306.81 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asmjit", "asmjitsrc\asmjit.vcxproj", "{AC40FF01-426E-4838-A317-66354CEFAE88}" EndProject @@ -79,6 +79,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libusb", "libusb", "{6D8E86 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libusb-1.0 (static)", "3rdparty\libusb_static.vcxproj", "{349EE8F9-7D25-4909-AAF5-FF3FADE72187}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "7z", "7z", "{CB3DD03E-074E-4FA5-B253-51A3372D1768}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "7zlib", "3rdparty\7z\7zlib\7zlib.vcxproj", "{5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug - LLVM|x64 = Debug - LLVM|x64 @@ -247,6 +251,16 @@ Global {349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Release - LLVM|x64.Build.0 = Release|x64 {349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Release|x64.ActiveCfg = Release|x64 {349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Release|x64.Build.0 = Release|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Debug - LLVM|x64.ActiveCfg = Debug|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Debug - LLVM|x64.Build.0 = Debug|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Debug - MemLeak|x64.ActiveCfg = Debug|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Debug - MemLeak|x64.Build.0 = Debug|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Debug|x64.ActiveCfg = Debug|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Debug|x64.Build.0 = Debug|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Release - LLVM|x64.ActiveCfg = Release|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Release - LLVM|x64.Build.0 = Release|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Release|x64.ActiveCfg = Release|x64 + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -268,6 +282,7 @@ Global {A107C21C-418A-4697-BB10-20C3AA60E2E4} = {FA1E6C16-CA63-45F8-8D52-E21DF396BE36} {939FE206-1182-ABC3-1234-FEAB88E98404} = {D16E245C-CC5A-4B9A-8BAB-1176F02C1631} {349EE8F9-7D25-4909-AAF5-FF3FADE72187} = {6D8E86F7-84A0-45BA-ACC3-F02FC5545B3B} + {5B146DEA-9ACE-4D32-A7FD-3F42464DD69C} = {CB3DD03E-074E-4FA5-B253-51A3372D1768} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {06CC7920-E085-4B81-9582-8DE8AAD42510} diff --git a/rpcs3/Crypto/sha256.cpp b/rpcs3/Crypto/sha256.cpp new file mode 100644 index 0000000000..2b67fe9ef8 --- /dev/null +++ b/rpcs3/Crypto/sha256.cpp @@ -0,0 +1,449 @@ +/* + * FIPS-180-2 compliant SHA-256 implementation + * + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: GPL-2.0 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ +/* + * The SHA-256 Secure Hash Standard was published by NIST in 2002. + * + * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf + */ + +#include "sha256.h" + +#include + +#if defined(MBEDTLS_SELF_TEST) +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#include +#include +#define mbedtls_printf printf +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ + +#define SHA256_VALIDATE_RET(cond) +#define SHA256_VALIDATE(cond) + +#if !defined(MBEDTLS_SHA256_ALT) + +/* + * 32-bit integer manipulation macros (big endian) + */ +#ifndef GET_UINT32_BE +#define GET_UINT32_BE(n,b,i) \ +do { \ + (n) = ( (uint32_t) (b)[(i) ] << 24 ) \ + | ( (uint32_t) (b)[(i) + 1] << 16 ) \ + | ( (uint32_t) (b)[(i) + 2] << 8 ) \ + | ( (uint32_t) (b)[(i) + 3] ); \ +} while( 0 ) +#endif + +#ifndef PUT_UINT32_BE +#define PUT_UINT32_BE(n,b,i) \ +do { \ + (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ + (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ + (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ + (b)[(i) + 3] = (unsigned char) ( (n) ); \ +} while( 0 ) +#endif + +/* Implementation that should never be optimized out by the compiler */ +static void mbedtls_zeroize_sha256(void* v, size_t n) +{ + volatile unsigned char* p = (volatile unsigned char*)v; + while (n--) + *p++ = 0; +} + +void mbedtls_sha256_init( mbedtls_sha256_context *ctx ) +{ + SHA256_VALIDATE( ctx != NULL ); + + memset( ctx, 0, sizeof( mbedtls_sha256_context ) ); +} + +void mbedtls_sha256_free( mbedtls_sha256_context *ctx ) +{ + if( ctx == NULL ) + return; + + mbedtls_zeroize_sha256(ctx, sizeof(mbedtls_sha256_context)); +} + +void mbedtls_sha256_clone( mbedtls_sha256_context *dst, + const mbedtls_sha256_context *src ) +{ + SHA256_VALIDATE( dst != NULL ); + SHA256_VALIDATE( src != NULL ); + + *dst = *src; +} + +/* + * SHA-256 context setup + */ +int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ) +{ + SHA256_VALIDATE_RET( ctx != NULL ); + SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); + + ctx->total[0] = 0; + ctx->total[1] = 0; + + if( is224 == 0 ) + { + /* SHA-256 */ + ctx->state[0] = 0x6A09E667; + ctx->state[1] = 0xBB67AE85; + ctx->state[2] = 0x3C6EF372; + ctx->state[3] = 0xA54FF53A; + ctx->state[4] = 0x510E527F; + ctx->state[5] = 0x9B05688C; + ctx->state[6] = 0x1F83D9AB; + ctx->state[7] = 0x5BE0CD19; + } + else + { + /* SHA-224 */ + ctx->state[0] = 0xC1059ED8; + ctx->state[1] = 0x367CD507; + ctx->state[2] = 0x3070DD17; + ctx->state[3] = 0xF70E5939; + ctx->state[4] = 0xFFC00B31; + ctx->state[5] = 0x68581511; + ctx->state[6] = 0x64F98FA7; + ctx->state[7] = 0xBEFA4FA4; + } + + ctx->is224 = is224; + + return( 0 ); +} + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, + int is224 ) +{ + mbedtls_sha256_starts_ret( ctx, is224 ); +} +#endif + +#if !defined(MBEDTLS_SHA256_PROCESS_ALT) +static const uint32_t K[] = +{ + 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, + 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, + 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, + 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, + 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, + 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, + 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, + 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, + 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, + 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, + 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, + 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, + 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, + 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, + 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, + 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2, +}; + +#define SHR(x,n) (((x) & 0xFFFFFFFF) >> (n)) +#define ROTR(x,n) (SHR(x,n) | ((x) << (32 - (n)))) + +#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) +#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) + +#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22)) +#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25)) + +#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) + +#define R(t) \ + ( \ + W[t] = S1(W[(t) - 2]) + W[(t) - 7] + \ + S0(W[(t) - 15]) + W[(t) - 16] \ + ) + +#define P(a,b,c,d,e,f,g,h,x,K) \ + do \ + { \ + temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \ + temp2 = S2(a) + F0((a),(b),(c)); \ + (d) += temp1; (h) = temp1 + temp2; \ + } while( 0 ) + +int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, + const unsigned char data[64] ) +{ + uint32_t temp1, temp2, W[64]; + uint32_t A[8]; + unsigned int i; + + SHA256_VALIDATE_RET( ctx != NULL ); + SHA256_VALIDATE_RET( (const unsigned char *)data != NULL ); + + for( i = 0; i < 8; i++ ) + A[i] = ctx->state[i]; + +#if defined(MBEDTLS_SHA256_SMALLER) + for( i = 0; i < 64; i++ ) + { + if( i < 16 ) + GET_UINT32_BE( W[i], data, 4 * i ); + else + R( i ); + + P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i], K[i] ); + + temp1 = A[7]; A[7] = A[6]; A[6] = A[5]; A[5] = A[4]; A[4] = A[3]; + A[3] = A[2]; A[2] = A[1]; A[1] = A[0]; A[0] = temp1; + } +#else /* MBEDTLS_SHA256_SMALLER */ + for( i = 0; i < 16; i++ ) + GET_UINT32_BE( W[i], data, 4 * i ); + + for( i = 0; i < 16; i += 8 ) + { + P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i+0], K[i+0] ); + P( A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], W[i+1], K[i+1] ); + P( A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], W[i+2], K[i+2] ); + P( A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], W[i+3], K[i+3] ); + P( A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], W[i+4], K[i+4] ); + P( A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], W[i+5], K[i+5] ); + P( A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], W[i+6], K[i+6] ); + P( A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], W[i+7], K[i+7] ); + } + + for( i = 16; i < 64; i += 8 ) + { + P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], R(i+0), K[i+0] ); + P( A[7], A[0], A[1], A[2], A[3], A[4], A[5], A[6], R(i+1), K[i+1] ); + P( A[6], A[7], A[0], A[1], A[2], A[3], A[4], A[5], R(i+2), K[i+2] ); + P( A[5], A[6], A[7], A[0], A[1], A[2], A[3], A[4], R(i+3), K[i+3] ); + P( A[4], A[5], A[6], A[7], A[0], A[1], A[2], A[3], R(i+4), K[i+4] ); + P( A[3], A[4], A[5], A[6], A[7], A[0], A[1], A[2], R(i+5), K[i+5] ); + P( A[2], A[3], A[4], A[5], A[6], A[7], A[0], A[1], R(i+6), K[i+6] ); + P( A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[0], R(i+7), K[i+7] ); + } +#endif /* MBEDTLS_SHA256_SMALLER */ + + for( i = 0; i < 8; i++ ) + ctx->state[i] += A[i]; + + return( 0 ); +} + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +void mbedtls_sha256_process( mbedtls_sha256_context *ctx, + const unsigned char data[64] ) +{ + mbedtls_internal_sha256_process( ctx, data ); +} +#endif +#endif /* !MBEDTLS_SHA256_PROCESS_ALT */ + +/* + * SHA-256 process buffer + */ +int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, + const unsigned char *input, + size_t ilen ) +{ + int ret; + size_t fill; + uint32_t left; + + SHA256_VALIDATE_RET( ctx != NULL ); + SHA256_VALIDATE_RET( ilen == 0 || input != NULL ); + + if( ilen == 0 ) + return( 0 ); + + left = ctx->total[0] & 0x3F; + fill = 64 - left; + + ctx->total[0] += (uint32_t) ilen; + ctx->total[0] &= 0xFFFFFFFF; + + if( ctx->total[0] < (uint32_t) ilen ) + ctx->total[1]++; + + if( left && ilen >= fill ) + { + memcpy( (void *) (ctx->buffer + left), input, fill ); + + if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); + + input += fill; + ilen -= fill; + left = 0; + } + + while( ilen >= 64 ) + { + if( ( ret = mbedtls_internal_sha256_process( ctx, input ) ) != 0 ) + return( ret ); + + input += 64; + ilen -= 64; + } + + if( ilen > 0 ) + memcpy( (void *) (ctx->buffer + left), input, ilen ); + + return( 0 ); +} + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +void mbedtls_sha256_update( mbedtls_sha256_context *ctx, + const unsigned char *input, + size_t ilen ) +{ + mbedtls_sha256_update_ret( ctx, input, ilen ); +} +#endif + +/* + * SHA-256 final digest + */ +int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, + unsigned char output[32] ) +{ + int ret; + uint32_t used; + uint32_t high, low; + + SHA256_VALIDATE_RET( ctx != NULL ); + SHA256_VALIDATE_RET( (unsigned char *)output != NULL ); + + /* + * Add padding: 0x80 then 0x00 until 8 bytes remain for the length + */ + used = ctx->total[0] & 0x3F; + + ctx->buffer[used++] = 0x80; + + if( used <= 56 ) + { + /* Enough room for padding + length in current block */ + memset( ctx->buffer + used, 0, 56 - used ); + } + else + { + /* We'll need an extra block */ + memset( ctx->buffer + used, 0, 64 - used ); + + if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); + + memset( ctx->buffer, 0, 56 ); + } + + /* + * Add message length + */ + high = ( ctx->total[0] >> 29 ) + | ( ctx->total[1] << 3 ); + low = ( ctx->total[0] << 3 ); + + PUT_UINT32_BE( high, ctx->buffer, 56 ); + PUT_UINT32_BE( low, ctx->buffer, 60 ); + + if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); + + /* + * Output final state + */ + PUT_UINT32_BE( ctx->state[0], output, 0 ); + PUT_UINT32_BE( ctx->state[1], output, 4 ); + PUT_UINT32_BE( ctx->state[2], output, 8 ); + PUT_UINT32_BE( ctx->state[3], output, 12 ); + PUT_UINT32_BE( ctx->state[4], output, 16 ); + PUT_UINT32_BE( ctx->state[5], output, 20 ); + PUT_UINT32_BE( ctx->state[6], output, 24 ); + + if( ctx->is224 == 0 ) + PUT_UINT32_BE( ctx->state[7], output, 28 ); + + return( 0 ); +} + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, + unsigned char output[32] ) +{ + mbedtls_sha256_finish_ret( ctx, output ); +} +#endif + +#endif /* !MBEDTLS_SHA256_ALT */ + +/* + * output = SHA-256( input buffer ) + */ +int mbedtls_sha256_ret( const unsigned char *input, + size_t ilen, + unsigned char output[32], + int is224 ) +{ + int ret; + mbedtls_sha256_context ctx; + + SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); + SHA256_VALIDATE_RET( ilen == 0 || input != NULL ); + SHA256_VALIDATE_RET( (unsigned char *)output != NULL ); + + mbedtls_sha256_init( &ctx ); + + if( ( ret = mbedtls_sha256_starts_ret( &ctx, is224 ) ) != 0 ) + goto exit; + + if( ( ret = mbedtls_sha256_update_ret( &ctx, input, ilen ) ) != 0 ) + goto exit; + + if( ( ret = mbedtls_sha256_finish_ret( &ctx, output ) ) != 0 ) + goto exit; + +exit: + mbedtls_sha256_free( &ctx ); + + return( ret ); +} + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +void mbedtls_sha256( const unsigned char *input, + size_t ilen, + unsigned char output[32], + int is224 ) +{ + mbedtls_sha256_ret( input, ilen, output, is224 ); +} +#endif diff --git a/rpcs3/Crypto/sha256.h b/rpcs3/Crypto/sha256.h new file mode 100644 index 0000000000..6dbf0babb0 --- /dev/null +++ b/rpcs3/Crypto/sha256.h @@ -0,0 +1,281 @@ +/** + * \file sha256.h + * + * \brief This file contains SHA-224 and SHA-256 definitions and functions. + * + * The Secure Hash Algorithms 224 and 256 (SHA-224 and SHA-256) cryptographic + * hash functions are defined in FIPS 180-4: Secure Hash Standard (SHS). + */ +/* + * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved + * SPDX-License-Identifier: GPL-2.0 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * This file is part of Mbed TLS (https://tls.mbed.org) + */ +#ifndef MBEDTLS_SHA256_H +#define MBEDTLS_SHA256_H + +#include +#include + +/* MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED is deprecated and should not be used. */ +#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 /**< SHA-256 hardware accelerator failed */ +#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 /**< SHA-256 input data was malformed. */ + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(MBEDTLS_SHA256_ALT) +// Regular implementation +// + +/** + * \brief The SHA-256 context structure. + * + * The structure is used both for SHA-256 and for SHA-224 + * checksum calculations. The choice between these two is + * made in the call to mbedtls_sha256_starts_ret(). + */ +typedef struct mbedtls_sha256_context +{ + uint32_t total[2]; /*!< The number of Bytes processed. */ + uint32_t state[8]; /*!< The intermediate digest state. */ + unsigned char buffer[64]; /*!< The data block being processed. */ + int is224; /*!< Determines which function to use: + 0: Use SHA-256, or 1: Use SHA-224. */ +} +mbedtls_sha256_context; + +#else /* MBEDTLS_SHA256_ALT */ +#include "sha256_alt.h" +#endif /* MBEDTLS_SHA256_ALT */ + +/** + * \brief This function initializes a SHA-256 context. + * + * \param ctx The SHA-256 context to initialize. This must not be \c NULL. + */ +void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); + +/** + * \brief This function clears a SHA-256 context. + * + * \param ctx The SHA-256 context to clear. This may be \c NULL, in which + * case this function returns immediately. If it is not \c NULL, + * it must point to an initialized SHA-256 context. + */ +void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); + +/** + * \brief This function clones the state of a SHA-256 context. + * + * \param dst The destination context. This must be initialized. + * \param src The context to clone. This must be initialized. + */ +void mbedtls_sha256_clone( mbedtls_sha256_context *dst, + const mbedtls_sha256_context *src ); + +/** + * \brief This function starts a SHA-224 or SHA-256 checksum + * calculation. + * + * \param ctx The context to use. This must be initialized. + * \param is224 This determines which function to use. This must be + * either \c 0 for SHA-256, or \c 1 for SHA-224. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ); + +/** + * \brief This function feeds an input buffer into an ongoing + * SHA-256 checksum calculation. + * + * \param ctx The SHA-256 context. This must be initialized + * and have a hash operation started. + * \param input The buffer holding the data. This must be a readable + * buffer of length \p ilen Bytes. + * \param ilen The length of the input data in Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, + const unsigned char *input, + size_t ilen ); + +/** + * \brief This function finishes the SHA-256 operation, and writes + * the result to the output buffer. + * + * \param ctx The SHA-256 context. This must be initialized + * and have a hash operation started. + * \param output The SHA-224 or SHA-256 checksum result. + * This must be a writable buffer of length \c 32 Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, + unsigned char output[32] ); + +/** + * \brief This function processes a single data block within + * the ongoing SHA-256 computation. This function is for + * internal use only. + * + * \param ctx The SHA-256 context. This must be initialized. + * \param data The buffer holding one block of data. This must + * be a readable buffer of length \c 64 Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, + const unsigned char data[64] ); + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif +/** + * \brief This function starts a SHA-224 or SHA-256 checksum + * calculation. + * + * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0. + * + * \param ctx The context to use. This must be initialized. + * \param is224 Determines which function to use. This must be + * either \c 0 for SHA-256, or \c 1 for SHA-224. + */ +MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, + int is224 ); + +/** + * \brief This function feeds an input buffer into an ongoing + * SHA-256 checksum calculation. + * + * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0. + * + * \param ctx The SHA-256 context to use. This must be + * initialized and have a hash operation started. + * \param input The buffer holding the data. This must be a readable + * buffer of length \p ilen Bytes. + * \param ilen The length of the input data in Bytes. + */ +MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx, + const unsigned char *input, + size_t ilen ); + +/** + * \brief This function finishes the SHA-256 operation, and writes + * the result to the output buffer. + * + * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0. + * + * \param ctx The SHA-256 context. This must be initialized and + * have a hash operation started. + * \param output The SHA-224 or SHA-256 checksum result. This must be + * a writable buffer of length \c 32 Bytes. + */ +MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, + unsigned char output[32] ); + +/** + * \brief This function processes a single data block within + * the ongoing SHA-256 computation. This function is for + * internal use only. + * + * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0. + * + * \param ctx The SHA-256 context. This must be initialized. + * \param data The buffer holding one block of data. This must be + * a readable buffer of size \c 64 Bytes. + */ +MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx, + const unsigned char data[64] ); + +#undef MBEDTLS_DEPRECATED +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ + +/** + * \brief This function calculates the SHA-224 or SHA-256 + * checksum of a buffer. + * + * The function allocates the context, performs the + * calculation, and frees the context. + * + * The SHA-256 result is calculated as + * output = SHA-256(input buffer). + * + * \param input The buffer holding the data. This must be a readable + * buffer of length \p ilen Bytes. + * \param ilen The length of the input data in Bytes. + * \param output The SHA-224 or SHA-256 checksum result. This must + * be a writable buffer of length \c 32 Bytes. + * \param is224 Determines which function to use. This must be + * either \c 0 for SHA-256, or \c 1 for SHA-224. + */ +int mbedtls_sha256_ret( const unsigned char *input, + size_t ilen, + unsigned char output[32], + int is224 ); + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif + +/** + * \brief This function calculates the SHA-224 or SHA-256 checksum + * of a buffer. + * + * The function allocates the context, performs the + * calculation, and frees the context. + * + * The SHA-256 result is calculated as + * output = SHA-256(input buffer). + * + * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0. + * + * \param input The buffer holding the data. This must be a readable + * buffer of length \p ilen Bytes. + * \param ilen The length of the input data in Bytes. + * \param output The SHA-224 or SHA-256 checksum result. This must be + * a writable buffer of length \c 32 Bytes. + * \param is224 Determines which function to use. This must be either + * \c 0 for SHA-256, or \c 1 for SHA-224. + */ +MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input, + size_t ilen, + unsigned char output[32], + int is224 ); + +#undef MBEDTLS_DEPRECATED +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ + +#ifdef __cplusplus +} +#endif + +#endif /* mbedtls_sha256.h */ diff --git a/rpcs3/Emu/CMakeLists.txt b/rpcs3/Emu/CMakeLists.txt index a7c5d7c555..23d5677da7 100644 --- a/rpcs3/Emu/CMakeLists.txt +++ b/rpcs3/Emu/CMakeLists.txt @@ -61,6 +61,7 @@ target_sources(rpcs3_emu PRIVATE ../Crypto/lz.cpp ../Crypto/md5.cpp ../Crypto/sha1.cpp + ../Crypto/sha256.cpp ../Crypto/unedat.cpp ../Crypto/unpkg.cpp ../Crypto/unself.cpp diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 88498b75f8..7ef4b95015 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -344,10 +344,10 @@ public: bool InstallPkg(const std::string& path); private: - static std::string GetEmuDir(); - void LimitCacheSize(); + public: + static std::string GetEmuDir(); static std::string GetHddDir(); static std::string GetHdd1Dir(); static std::string GetSfoDirFromGamePath(const std::string& game_path, const std::string& user, const std::string& title_id = ""); diff --git a/rpcs3/Json/tooltips.json b/rpcs3/Json/tooltips.json index 3288fc94c1..e78d90caf7 100644 --- a/rpcs3/Json/tooltips.json +++ b/rpcs3/Json/tooltips.json @@ -141,6 +141,7 @@ "show_boot_game": "Shows a confirmation dialog when a game was booted while another game is running.", "show_pkg_install": "Shows a dialog when packages were installed successfully.", "show_pup_install": "Shows a dialog when firmware was installed successfully.", + "check_update_start": "Check if an update is available on startup.", "useRichPresence": "Enables use of Discord Rich Presence to show what game you are playing on Discord.\nRequires a restart of RPCS3 to completely close the connection.", "discordState": "Tell your friends what you are doing.", "custom_colors": "Prioritize custom user interface colors over properties set in stylesheet." diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 32628d265f..9345092ede 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -347,6 +347,9 @@ NotUsing + + NotUsing + @@ -424,6 +427,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index f3f66f034b..064c9998f4 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -83,6 +83,9 @@ Crypto + + Crypto + Crypto @@ -844,6 +847,9 @@ Crypto + + Crypto + Crypto diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index 1375ffb6e1..34a828fc9d 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -117,7 +117,7 @@ $(SolutionDir)lib\Release-x64;$(SolutionDir)lib\$(Configuration)-$(Platform)\;$(UniversalCRT_LibraryPath_x64);$(LibraryPath) - ..\3rdparty\hidapi\hidapi;.\;..\;..\asmjit\src;..\3rdparty\yaml-cpp\include;..\3rdparty\ffmpeg\WindowsInclude;..\3rdparty\cereal\include;..\3rdparty\ffmpeg\Windows\x86_64\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);..\3rdparty\minidx12\Include;..\3rdparty\GSL\include;..\3rdparty\libpng;..\3rdparty\GL;..\3rdparty\stblib;..\3rdparty\OpenAL\include;..\3rdparty\pugixml\src;..\3rdparty\Optional;..\3rdparty\discord-rpc\include;..\3rdparty\zlib + ..\3rdparty\7z;..\3rdparty\hidapi\hidapi;.\;..\;..\asmjit\src;..\3rdparty\yaml-cpp\include;..\3rdparty\ffmpeg\WindowsInclude;..\3rdparty\cereal\include;..\3rdparty\ffmpeg\Windows\x86_64\Include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(UniversalCRT_IncludePath);..\3rdparty\minidx12\Include;..\3rdparty\GSL\include;..\3rdparty\libpng;..\3rdparty\GL;..\3rdparty\stblib;..\3rdparty\OpenAL\include;..\3rdparty\pugixml\src;..\3rdparty\Optional;..\3rdparty\discord-rpc\include;..\3rdparty\zlib @@ -192,8 +192,8 @@ Level3 - gdi32.lib;..\hidapi.lib;..\libusb-1.0.lib;winmm.lib;OpenAL.lib;XAudio.lib;D3D12GSRender.lib;GLGSRender.lib;shlwapi.lib;VKGSRender.lib;vulkan-1.lib;glslang.lib;OSDependent.lib;OGLCompiler.lib;SPIRV.lib;HLSL.lib;Advapi32.lib;user32.lib;zlib.lib;..\libpng16.lib;asmjit.lib;yaml-cpp.lib;discord-rpc.lib;emucore.lib;dxgi.lib;$(QTDIR)\lib\qtmain.lib;shell32.lib;opengl32.lib;$(QTDIR)\lib\Qt5OpenGL.lib;$(QTDIR)\lib\Qt5Widgets.lib;$(QTDIR)\lib\Qt5Gui.lib;$(QTDIR)\lib\Qt5Qml.lib;$(QTDIR)\lib\Qt5Network.lib;$(QTDIR)\lib\Qt5Core.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5WinExtras.lib;%(AdditionalDependencies) - $(VULKAN_SDK)\Lib;..\3rdparty\OpenAL\libs\Win64;..\Vulkan\glslang-build\hlsl\Release;..\Vulkan\glslang-build\SPIRV\Release;..\Vulkan\glslang-build\OGLCompilersDLL\Release;..\Vulkan\glslang-build\glslang\OSDependent\Windows\Release;..\Vulkan\glslang-build\glslang\Release;..\lib\$(CONFIGURATION)-$(PLATFORM);..\3rdparty\minidx12\Lib;..\3rdparty\discord-rpc\lib;$(QTDIR)\lib;%(AdditionalLibraryDirectories) + gdi32.lib;..\hidapi.lib;..\libusb-1.0.lib;winmm.lib;OpenAL.lib;XAudio.lib;D3D12GSRender.lib;GLGSRender.lib;shlwapi.lib;VKGSRender.lib;vulkan-1.lib;glslang.lib;OSDependent.lib;OGLCompiler.lib;SPIRV.lib;HLSL.lib;Advapi32.lib;user32.lib;zlib.lib;..\libpng16.lib;asmjit.lib;yaml-cpp.lib;discord-rpc.lib;emucore.lib;dxgi.lib;$(QTDIR)\lib\qtmain.lib;shell32.lib;opengl32.lib;$(QTDIR)\lib\Qt5OpenGL.lib;$(QTDIR)\lib\Qt5Widgets.lib;$(QTDIR)\lib\Qt5Gui.lib;$(QTDIR)\lib\Qt5Qml.lib;$(QTDIR)\lib\Qt5Network.lib;$(QTDIR)\lib\Qt5Core.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5WinExtras.lib;7zlib.lib;%(AdditionalDependencies) + ..\3rdparty\7z\7zlib\x64\Release\;$(VULKAN_SDK)\Lib;..\3rdparty\OpenAL\libs\Win64;..\Vulkan\glslang-build\hlsl\Release;..\Vulkan\glslang-build\SPIRV\Release;..\Vulkan\glslang-build\OGLCompilersDLL\Release;..\Vulkan\glslang-build\glslang\OSDependent\Windows\Release;..\Vulkan\glslang-build\glslang\Release;..\lib\$(CONFIGURATION)-$(PLATFORM);..\3rdparty\minidx12\Lib;..\3rdparty\discord-rpc\lib;$(QTDIR)\lib;%(AdditionalLibraryDirectories) "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions) true Debug @@ -506,6 +506,11 @@ true true + + true + true + true + true true @@ -691,6 +696,11 @@ true true + + true + true + true + true true @@ -896,6 +906,11 @@ true true + + true + true + true + true true @@ -1081,6 +1096,11 @@ true true + + true + true + true + true true @@ -1110,6 +1130,7 @@ + @@ -1653,6 +1674,24 @@ + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DWITH_DISCORD_RPC -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DNDEBUG -DQT_WINEXTRAS_LIB "-DBRANCH=$(BRANCH)" -D%(PreprocessorDefinitions) "-I.\..\3rdparty\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\minidx12\Include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtOpenGL" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtQml" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtCore" "-I.\release" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_WINEXTRAS_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\minidx12\Include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtOpenGL" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtQml" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DWITH_DISCORD_RPC -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DNDEBUG -DQT_WINEXTRAS_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\minidx12\Include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtOpenGL" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtQml" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtCore" "-I.\release" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing %(Identity)... + .\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_WINEXTRAS_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\minidx12\Include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtOpenGL" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtQml" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index 5cc0e4b75f..e7a4578453 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -114,6 +114,9 @@ {c25f8f80-cc74-4760-8488-a291b3026b1d} + + {ccb05d09-d394-493b-8b08-bde054969da0} + @@ -749,6 +752,21 @@ Gui\skylanders + + Gui\update manager + + + Generated Files\Release - LLVM + + + Generated Files\Debug + + + Generated Files\Release + + + Generated Files\Debug - LLVM + @@ -993,6 +1011,9 @@ rpcs3 + + Gui\update manager + diff --git a/rpcs3/rpcs3_version.cpp b/rpcs3/rpcs3_version.cpp index 045cd4b304..98e1f21fb3 100644 --- a/rpcs3/rpcs3_version.cpp +++ b/rpcs3/rpcs3_version.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "rpcs3_version.h" #include "git-version.h" +#include "Utilities/StrUtil.h" namespace rpcs3 { @@ -9,6 +10,15 @@ namespace rpcs3 return RPCS3_GIT_BRANCH; } + std::pair get_commit_and_hash() + { + const auto commit_and_hash = fmt::split(RPCS3_GIT_BRANCH, {"-"}); + if (commit_and_hash.size() != 2) + return std::make_pair("0", "00000000"); + + return std::make_pair(commit_and_hash[0], commit_and_hash[1]); + } + // TODO: Make this accessible from cmake and keep in sync with MACOSX_BUNDLE_BUNDLE_VERSION. // Currently accessible by Windows and Linux build scripts, see implementations when doing MACOSX const extern utils::version version{ 0, 0, 7, utils::version_type::alpha, 1, RPCS3_GIT_VERSION }; diff --git a/rpcs3/rpcs3_version.h b/rpcs3/rpcs3_version.h index 14bfe3d32e..a95f145d5b 100644 --- a/rpcs3/rpcs3_version.h +++ b/rpcs3/rpcs3_version.h @@ -6,6 +6,7 @@ namespace rpcs3 { std::string get_branch(); + std::pair get_commit_and_hash(); extern const utils::version version; } diff --git a/rpcs3/rpcs3qt/CMakeLists.txt b/rpcs3/rpcs3qt/CMakeLists.txt index 8ca2e28663..cdb7f6f1d9 100644 --- a/rpcs3/rpcs3qt/CMakeLists.txt +++ b/rpcs3/rpcs3qt/CMakeLists.txt @@ -42,6 +42,7 @@ trophy_manager_dialog.cpp trophy_notification_frame.cpp trophy_notification_helper.cpp + update_manager.cpp user_account.cpp user_manager_dialog.cpp vfs_dialog.cpp diff --git a/rpcs3/rpcs3qt/game_compatibility.cpp b/rpcs3/rpcs3qt/game_compatibility.cpp index b5db854dd6..fc57c73781 100644 --- a/rpcs3/rpcs3qt/game_compatibility.cpp +++ b/rpcs3/rpcs3qt/game_compatibility.cpp @@ -127,10 +127,7 @@ void game_compatibility::RequestCompatibility(bool online) QNetworkReply* network_reply = m_network_access_manager->get(m_network_request); // Show Progress - m_progress_dialog = new progress_dialog(tr(".Please wait."), tr("Abort"), 0, 100); - m_progress_dialog->setWindowTitle(tr("Downloading Database")); - m_progress_dialog->setFixedWidth(QLabel("This is the very length of the progressbar due to hidpi reasons.").sizeHint().width()); - m_progress_dialog->setValue(0); + m_progress_dialog = new progress_dialog(tr("Downloading Database"), tr(".Please wait."), tr("Abort"), 0, 100); m_progress_dialog->show(); // Animate progress dialog a bit more diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index d938b2bfa1..286b6f34bb 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -1252,8 +1252,7 @@ void game_list_frame::BatchCreatePPUCaches() return; } - progress_dialog* pdlg = new progress_dialog(tr("Creating all PPU caches"), tr("Cancel"), 0, total, this); - pdlg->setWindowTitle(tr("PPU Cache Batch Creation")); + progress_dialog* pdlg = new progress_dialog(tr("PPU Cache Batch Creation"), tr("Creating all PPU caches"), tr("Cancel"), 0, total, this); pdlg->setAutoClose(false); pdlg->setAutoReset(false); pdlg->show(); @@ -1298,8 +1297,7 @@ void game_list_frame::BatchRemovePPUCaches() return; } - progress_dialog* pdlg = new progress_dialog(tr("Removing all PPU caches"), tr("Cancel"), 0, total, this); - pdlg->setWindowTitle(tr("PPU Cache Batch Removal")); + progress_dialog* pdlg = new progress_dialog(tr("PPU Cache Batch Removal"), tr("Removing all PPU caches"), tr("Cancel"), 0, total, this); pdlg->setAutoClose(false); pdlg->setAutoReset(false); pdlg->show(); @@ -1340,8 +1338,7 @@ void game_list_frame::BatchRemoveSPUCaches() return; } - progress_dialog* pdlg = new progress_dialog(tr("Removing all SPU caches"), tr("Cancel"), 0, total, this); - pdlg->setWindowTitle(tr("SPU Cache Batch Removal")); + progress_dialog* pdlg = new progress_dialog(tr("SPU Cache Batch Removal"), tr("Removing all SPU caches"), tr("Cancel"), 0, total, this); pdlg->setAutoClose(false); pdlg->setAutoReset(false); pdlg->show(); @@ -1385,8 +1382,7 @@ void game_list_frame::BatchRemoveCustomConfigurations() return; } - progress_dialog* pdlg = new progress_dialog(tr("Removing all custom configurations"), tr("Cancel"), 0, total, this); - pdlg->setWindowTitle(tr("Custom Configuration Batch Removal")); + progress_dialog* pdlg = new progress_dialog(tr("Custom Configuration Batch Removal"), tr("Removing all custom configurations"), tr("Cancel"), 0, total, this); pdlg->setAutoClose(false); pdlg->setAutoReset(false); pdlg->show(); @@ -1431,8 +1427,7 @@ void game_list_frame::BatchRemoveCustomPadConfigurations() return; } - progress_dialog* pdlg = new progress_dialog(tr("Removing all custom pad configurations"), tr("Cancel"), 0, total, this); - pdlg->setWindowTitle(tr("Custom Pad Configuration Batch Removal")); + progress_dialog* pdlg = new progress_dialog(tr("Custom Pad Configuration Batch Removal"), tr("Removing all custom pad configurations"), tr("Cancel"), 0, total, this); pdlg->setAutoClose(false); pdlg->setAutoReset(false); pdlg->show(); @@ -1474,8 +1469,7 @@ void game_list_frame::BatchRemoveShaderCaches() return; } - progress_dialog* pdlg = new progress_dialog(tr("Removing all shader caches"), tr("Cancel"), 0, total, this); - pdlg->setWindowTitle(tr("Shader Cache Batch Removal")); + progress_dialog* pdlg = new progress_dialog(tr("Shader Cache Batch Removal"), tr("Removing all shader caches"), tr("Cancel"), 0, total, this); pdlg->setAutoClose(false); pdlg->setAutoReset(false); pdlg->show(); diff --git a/rpcs3/rpcs3qt/gui_settings.h b/rpcs3/rpcs3qt/gui_settings.h index acb75c4fc7..b3855f284c 100644 --- a/rpcs3/rpcs3qt/gui_settings.h +++ b/rpcs3/rpcs3qt/gui_settings.h @@ -207,6 +207,7 @@ namespace gui const gui_save m_enableUIColors = gui_save(meta, "enableUIColors", false); const gui_save m_richPresence = gui_save(meta, "useRichPresence", true); const gui_save m_discordState = gui_save(meta, "discordState", ""); + const gui_save m_check_upd_start = gui_save(meta, "checkUpdateStart", true); const gui_save gs_disableMouse = gui_save(gs_frame, "disableMouse", false); const gui_save gs_resize = gui_save(gs_frame, "resize", false); diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 0a05bd47d4..79c0ec36bc 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -172,6 +172,13 @@ void main_window::Init() // Fix possible hidden game list columns. The game list has to be visible already. Use this after show() m_gameListFrame->FixNarrowColumns(); + +#if defined(_WIN32) || defined(__linux__) + if (guiSettings->GetValue(gui::m_check_upd_start).toBool()) + { + m_updater.check_for_updates(true, this); + } +#endif } // returns appIcon @@ -423,8 +430,7 @@ void main_window::InstallPkg(const QString& dropPath, bool is_bulk) const std::string fileName = sstr(QFileInfo(filePath).fileName()); const std::string path = sstr(filePath); - progress_dialog pdlg(tr("Installing package ... please wait ..."), tr("Cancel"), 0, 1000, this); - pdlg.setWindowTitle(tr("RPCS3 Package Installer")); + progress_dialog pdlg(tr("RPCS3 Package Installer"), tr("Installing package ... please wait ..."), tr("Cancel"), 0, 1000, this); pdlg.show(); // Synchronization variable @@ -563,8 +569,7 @@ void main_window::InstallPup(const QString& dropPath) return; } - progress_dialog pdlg(tr("Installing firmware version %1\nPlease wait...").arg(qstr(version_string)), tr("Cancel"), 0, static_cast(updatefilenames.size()), this); - pdlg.setWindowTitle(tr("RPCS3 Firmware Installer")); + progress_dialog pdlg(tr("RPCS3 Firmware Installer"), tr("Installing firmware version %1\nPlease wait...").arg(qstr(version_string)), tr("Cancel"), 0, static_cast(updatefilenames.size()), this); pdlg.show(); // Synchronization variable @@ -1411,6 +1416,20 @@ void main_window::CreateConnects() } }); + connect(ui->updateAct, &QAction::triggered, [=]() + { +#if !defined(_WIN32) && !defined(__linux__) + QMessageBox::warning(this, tr("Auto-updater"), tr("The auto-updater currently isn't available for your os.")); + return; +#endif + if(!Emu.IsStopped()) + { + QMessageBox::warning(this, tr("Auto-updater"), tr("Please stop the emulation before trying to update.")); + return; + } + m_updater.check_for_updates(false, this); + }); + connect(ui->aboutAct, &QAction::triggered, [this] { about_dialog dlg(this); diff --git a/rpcs3/rpcs3qt/main_window.h b/rpcs3/rpcs3qt/main_window.h index d433be2aea..6b4d971bf6 100644 --- a/rpcs3/rpcs3qt/main_window.h +++ b/rpcs3/rpcs3qt/main_window.h @@ -15,6 +15,7 @@ #include "debugger_frame.h" #include "game_list_frame.h" #include "gui_settings.h" +#include "update_manager.h" #include @@ -144,4 +145,6 @@ private: game_list_frame* m_gameListFrame = nullptr; std::shared_ptr guiSettings; std::shared_ptr emuSettings; + + update_manager m_updater; }; diff --git a/rpcs3/rpcs3qt/main_window.ui b/rpcs3/rpcs3qt/main_window.ui index f2b52b2817..25d5fbdef4 100644 --- a/rpcs3/rpcs3qt/main_window.ui +++ b/rpcs3/rpcs3qt/main_window.ui @@ -141,7 +141,7 @@ 0 0 1058 - 22 + 20 @@ -298,7 +298,7 @@ Help - + @@ -638,10 +638,7 @@ RAP Files - - - false - + Check for Updates diff --git a/rpcs3/rpcs3qt/progress_dialog.cpp b/rpcs3/rpcs3qt/progress_dialog.cpp index d093643340..d88a9fc239 100644 --- a/rpcs3/rpcs3qt/progress_dialog.cpp +++ b/rpcs3/rpcs3qt/progress_dialog.cpp @@ -2,10 +2,12 @@ #include -progress_dialog::progress_dialog(const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent, Qt::WindowFlags flags) +progress_dialog::progress_dialog(const QString &windowTitle, const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent, Qt::WindowFlags flags) : QProgressDialog(labelText, cancelButtonText, minimum, maximum, parent, flags) { + setWindowTitle(windowTitle); setFixedWidth(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width()); + setValue(0); setWindowModality(Qt::WindowModal); connect(this, &QProgressDialog::canceled, this, &QProgressDialog::deleteLater); diff --git a/rpcs3/rpcs3qt/progress_dialog.h b/rpcs3/rpcs3qt/progress_dialog.h index 0e92a8bd2d..e11e8f55bb 100644 --- a/rpcs3/rpcs3qt/progress_dialog.h +++ b/rpcs3/rpcs3qt/progress_dialog.h @@ -17,7 +17,7 @@ class progress_dialog : public QProgressDialog { public: - progress_dialog(const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); + progress_dialog(const QString &windowTitle, const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); ~progress_dialog(); void SetValue(int progress); diff --git a/rpcs3/rpcs3qt/settings_dialog.cpp b/rpcs3/rpcs3qt/settings_dialog.cpp index 7f2e2f95f8..4e8f6f4f53 100644 --- a/rpcs3/rpcs3qt/settings_dialog.cpp +++ b/rpcs3/rpcs3qt/settings_dialog.cpp @@ -1311,6 +1311,8 @@ settings_dialog::settings_dialog(std::shared_ptr guiSettings, std: SubscribeTooltip(ui->cb_show_pup_install, json_gui["show_pup_install"].toString()); + SubscribeTooltip(ui->cb_check_update_start, json_gui["check_update_start"].toString()); + SubscribeTooltip(ui->useRichPresence, json_gui["useRichPresence"].toString()); SubscribeTooltip(ui->discordState, json_gui["discordState"].toString()); @@ -1372,6 +1374,8 @@ settings_dialog::settings_dialog(std::shared_ptr guiSettings, std: ui->cb_show_pkg_install->setChecked(xgui_settings->GetValue(gui::ib_pkg_success).toBool()); ui->cb_show_pup_install->setChecked(xgui_settings->GetValue(gui::ib_pup_success).toBool()); + ui->cb_check_update_start->setChecked(xgui_settings->GetValue(gui::m_check_upd_start).toBool()); + bool enableUIColors = xgui_settings->GetValue(gui::m_enableUIColors).toBool(); ui->cb_custom_colors->setChecked(enableUIColors); ui->pb_gl_icon_color->setEnabled(enableUIColors); @@ -1447,6 +1451,10 @@ settings_dialog::settings_dialog(std::shared_ptr guiSettings, std: { xgui_settings->SetValue(gui::ib_pup_success, val); }); + connect(ui->cb_check_update_start, &QCheckBox::clicked, [=](bool val) + { + xgui_settings->SetValue(gui::m_check_upd_start, val); + }); connect(ui->cb_custom_colors, &QCheckBox::clicked, [=](bool val) { diff --git a/rpcs3/rpcs3qt/settings_dialog.ui b/rpcs3/rpcs3qt/settings_dialog.ui index 1067dbf4ee..599e9c82a0 100644 --- a/rpcs3/rpcs3qt/settings_dialog.ui +++ b/rpcs3/rpcs3qt/settings_dialog.ui @@ -2514,6 +2514,13 @@ + + + + Check for updates on startup + + + diff --git a/rpcs3/rpcs3qt/update_manager.cpp b/rpcs3/rpcs3qt/update_manager.cpp new file mode 100644 index 0000000000..2f9d254b8d --- /dev/null +++ b/rpcs3/rpcs3qt/update_manager.cpp @@ -0,0 +1,560 @@ +#include "stdafx.h" +#include "update_manager.h" +#include "rpcs3_version.h" +#include "Utilities/StrUtil.h" +#include "Crypto/sha256.h" +#include "Emu/System.h" + +#include +#include +#include + +#if defined(_WIN32) +#include +#include +#include <7z.h> +#include <7zAlloc.h> +#include <7zBuf.h> +#include <7zCrc.h> +#include <7zFile.h> +#include <7zVersion.h> + +#define PATH_MAX MAX_PATH + +#else +#include +#include +#endif + +update_manager::update_manager() +{ + m_manager.setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy); +} + +void update_manager::check_for_updates(bool automatic, QWidget* parent) +{ + if (QSslSocket::supportsSsl() == false) + { + LOG_ERROR(GENERAL, "Can't update! Please make sure your system supports SSL."); + if (!automatic) + QMessageBox::warning(parent, tr("Auto-updater"), tr("Can't update! Please make sure your system supports SSL.")); + return; + } + + m_parent = parent; + + const std::string request_url = m_update_url + rpcs3::get_commit_and_hash().second; + QNetworkReply* reply_json = m_manager.get(QNetworkRequest(QUrl(QString::fromStdString(request_url)))); + + m_progress_dialog = new progress_dialog(tr("Checking For Updates"), tr("Please wait..."), tr("Abort"), 0, 100, parent); + m_progress_dialog->setAutoClose(false); + m_progress_dialog->setAutoReset(false); + m_progress_dialog->show(); + + connect(m_progress_dialog, &QProgressDialog::canceled, reply_json, &QNetworkReply::abort); + connect(m_progress_dialog, &QProgressDialog::finished, m_progress_dialog, &QProgressDialog::deleteLater); + + // clang-format off + connect(reply_json, &QNetworkReply::downloadProgress, [&](qint64 bytesReceived, qint64 bytesTotal) + { + m_progress_dialog->setMaximum(bytesTotal); + m_progress_dialog->setValue(bytesReceived); + }); + + connect(reply_json, QOverload::of(&QNetworkReply::error), this, &update_manager::handle_error); + connect(reply_json, &QNetworkReply::finished, [=]() + { + handle_reply(reply_json, &update_manager::handle_json, automatic, "Retrieved Json Info"); + }); + // clang-format on +} + +void update_manager::handle_error(QNetworkReply::NetworkError error) +{ + if (error != QNetworkReply::NoError) + { + QNetworkReply* reply = qobject_cast(sender()); + if(!reply) + return; + + m_progress_dialog->close(); + + reply->deleteLater(); + if (error != QNetworkReply::OperationCanceledError) + { + QString error = reply->errorString(); + LOG_ERROR(GENERAL, "[Auto-updater] Network Error: %s", error.toStdString()); + } + } +} + +bool update_manager::handle_reply(QNetworkReply* reply, std::function func, bool automatic, const std::string& message) +{ + if (auto error = reply->error(); error != QNetworkReply::NoError) + return false; + + // Read data from network reply + const QByteArray data = reply->readAll(); + reply->deleteLater(); + + LOG_NOTICE(GENERAL, "[Auto-updater] %s", message); + if (!func(*this, data, automatic)) + { + m_progress_dialog->close(); + + if (!automatic) + QMessageBox::warning(m_parent, tr("Auto-updater"), tr("An error occured during the auto-updating process.\nCheck the log for more information.")); + } + + return true; +} + +bool update_manager::handle_json(const QByteArray& data, bool automatic) +{ + const QJsonObject json_data = QJsonDocument::fromJson(data).object(); + int return_code = json_data["return_code"].toInt(-255); + + bool hash_found = true; + + if (return_code < 0) + { + std::string error_message; + switch (return_code) + { + case -1: error_message = "Hash not found(Custom/PR build)"; break; + case -2: error_message = "Server Error - Maintenance Mode"; break; + case -3: error_message = "Server Error - Illegal Search"; break; + case -255: error_message = "Server Error - Return code not found"; break; + default: error_message = "Server Error - Unknown Error"; break; + } + + if (return_code != -1) + LOG_ERROR(GENERAL, "[Auto-updater] error: %s return code: %d", error_message, return_code); + else + LOG_WARNING(GENERAL, "[Auto-updater] error: %s return code: %d", error_message, return_code); + + // If a user clicks "Check for Updates" with a custom build ask him if he's sure he wants to update to latest version + if (!automatic && return_code == -1) + { + if (QMessageBox::question(m_progress_dialog, tr("Auto-updater"), tr("You're currently using a custom or PR build.\n\nDo you want to update to the latest official rpcs3 version?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) + { + m_progress_dialog->close(); + return true; + } + + hash_found = false; + } + else + { + return false; + } + } + + const auto& latest = json_data["latest_build"]; + if (!latest.isObject()) + { + LOG_ERROR(GENERAL, "[Auto-updater] Json doesn't contain latest_build section"); + return false; + } + + QString os; + +#ifdef _WIN32 + os = "windows"; +#elif defined(__linux__) + os = "linux"; +#else + LOG_ERROR(GENERAL, "[Auto-updater] Your os isn't currently supported by the auto-updater"); + return false; +#endif + + // Check that every bit of info we need is there + if (!latest[os].isObject() || !latest[os]["download"].isString() || !latest[os]["size"].isDouble() || !latest[os]["checksum"].isString() || !latest["version"].isString() || + !latest["datetime"].isString() || + (hash_found && (!json_data["current_build"].isObject() || !json_data["current_build"]["version"].isString() || !json_data["current_build"]["datetime"].isString()))) + { + LOG_ERROR(GENERAL, "[Auto-updater] Some information seems unavailable"); + return false; + } + + if (hash_found && return_code == 0) + { + LOG_SUCCESS(GENERAL, "[Auto-updater] RPCS3 is up to date!"); + m_progress_dialog->close(); + + if (!automatic) + QMessageBox::information(m_parent, tr("Auto-updater"), tr("Your version is already up to date!")); + + return true; + } + + if (hash_found) + { + // Calculates how old the build is + std::string cur_date = json_data["current_build"]["datetime"].toString().toStdString(); + std::string lts_date = latest["datetime"].toString().toStdString(); + + tm cur_tm, lts_tm; + QString timediff = ""; + + auto time_from_str = [](const std::string& str, const std::string& format, tm* tm) -> bool + { + std::istringstream input(str); + input.imbue(std::locale(setlocale(LC_ALL, nullptr))); + input >> std::get_time(tm, format.c_str()); + if (input.fail()) + return false; + + return true; + }; + + if (time_from_str(cur_date, "%Y-%m-%d %H:%M:%S", &cur_tm) && time_from_str(lts_date, "%Y-%m-%d %H:%M:%S", <s_tm)) + { + time_t cur_time = mktime(&cur_tm); + time_t lts_time = mktime(<s_tm); + + s64 u_timediff = (s64)std::difftime(lts_time, cur_time); + timediff = tr("Your version is %1 day(s), %2 hour(s) and %3 minute(s) old.").arg(u_timediff / (60 * 60 * 24)).arg((u_timediff / (60 * 60)) % 24).arg((u_timediff / 60) % 60); + } + + const QString to_show = tr("A new version of RPCS3 is available!\n\nCurrent version: %1\nLatest version: %2\n%3\n\nDo you want to update?") + .arg(json_data["current_build"]["version"].toString()) + .arg(latest["version"].toString()) + .arg(timediff); + if (QMessageBox::question(m_progress_dialog, tr("Update Available"), to_show, QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) + { + m_progress_dialog->close(); + return true; + } + } + + m_expected_hash = latest[os]["checksum"].toString().toStdString(); + m_expected_size = latest[os]["size"].toInt(); + + m_progress_dialog->setWindowTitle(tr("Downloading Update")); + + // Download RPCS3 + m_progress_dialog->setValue(0); + QNetworkReply* reply_rpcs3 = m_manager.get(QNetworkRequest(QUrl(latest[os]["download"].toString()))); + + connect(m_progress_dialog, &QProgressDialog::canceled, reply_rpcs3, &QNetworkReply::abort); + + // clang-format off + connect(reply_rpcs3, &QNetworkReply::downloadProgress, [&](qint64 bytesReceived, qint64 bytesTotal) + { + m_progress_dialog->setMaximum(bytesTotal); + m_progress_dialog->setValue(bytesReceived); + }); + + connect(reply_rpcs3, QOverload::of(&QNetworkReply::error), this, &update_manager::handle_error); + connect(reply_rpcs3, &QNetworkReply::finished, [=]() + { + handle_reply(reply_rpcs3, &update_manager::handle_rpcs3, automatic, "Retrieved RPCS3"); + }); + // clang-format on + + return true; +} + +bool update_manager::handle_rpcs3(const QByteArray& rpcs3_data, bool automatic) +{ + if (m_expected_size != rpcs3_data.size()) + { + LOG_ERROR(GENERAL, "[Auto-updater] Download size mismatch: %d expected: %d", rpcs3_data.size(), m_expected_size); + return false; + } + + u8 res_hash[32]; + mbedtls_sha256_context ctx; + mbedtls_sha256_init(&ctx); + mbedtls_sha256_starts_ret(&ctx, 0); + mbedtls_sha256_update_ret(&ctx, (const unsigned char*)rpcs3_data.data(), rpcs3_data.size()); + mbedtls_sha256_finish_ret(&ctx, res_hash); + + std::string res_hash_string("0000000000000000000000000000000000000000000000000000000000000000"); + for (size_t index = 0; index < 32; index++) + { + constexpr auto pal = "0123456789ABCDEF"; + res_hash_string[index * 2] = pal[res_hash[index] >> 4]; + res_hash_string[(index * 2) + 1] = pal[res_hash[index] & 15]; + } + + if (m_expected_hash != res_hash_string) + { + LOG_ERROR(GENERAL, "[Auto-updater] Hash mismatch: %s expected: %s", res_hash_string, m_expected_hash); + return false; + } + + std::string replace_path; + +#ifdef __linux__ + + const char* appimage_path = ::getenv("APPIMAGE"); + if (appimage_path != nullptr) + { + replace_path = appimage_path; + LOG_NOTICE(GENERAL, "[Auto-updater] Found appimage path: %s", appimage_path); + } + else + { + LOG_WARNING(GENERAL, "[Auto-updater] Failed to find AppImage path"); + char exe_path[PATH_MAX]; + ssize_t len = ::readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); + + if (len == -1) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to find executable path"); + return false; + } + + exe_path[len] = '\0'; + LOG_TRACE(GENERAL, "[Auto-updater] Found exec path: %s", exe_path); + + replace_path = exe_path; + } + + m_progress_dialog->setWindowTitle(tr("Updating RPCS3")); + + // Move the appimage/exe and replace with new appimage + fs::rename(replace_path, "/tmp/rpcs3_old", true); + fs::file new_appimage(replace_path, fs::read + fs::write + fs::create + fs::trunc); + if (!new_appimage) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to create new AppImage file: %s", replace_path); + return false; + } + if (new_appimage.write(rpcs3_data.data(), rpcs3_data.size()) != rpcs3_data.size()) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to write new AppImage file: %s", replace_path); + return false; + } + if (fchmod(new_appimage.get_handle(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to chmod rwxrxrx %s", replace_path); + return false; + } + new_appimage.close(); + + LOG_SUCCESS(GENERAL, "[Auto-updater] Successfully updated %s!", replace_path); + +#elif defined(_WIN32) + + char temp_path[PATH_MAX]; + + GetTempPathA(sizeof(temp_path) - 1, temp_path); + temp_path[PATH_MAX - 1] = 0; + + std::string tmpfile_path = temp_path; + tmpfile_path += "\\rpcs3_update.7z"; + + fs::file tmpfile(tmpfile_path, fs::read + fs::write + fs::create + fs::trunc); + if (!tmpfile) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to create temporary file: %s", tmpfile_path); + return false; + } + if (tmpfile.write(rpcs3_data.data(), rpcs3_data.size()) != rpcs3_data.size()) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to write temporary file: %s", tmpfile_path); + return false; + } + tmpfile.close(); + + m_progress_dialog->setWindowTitle(tr("Updating RPCS3")); + + // 7z stuff (most of this stuff is from 7z Util sample and has been reworked to be more stl friendly) + + ISzAlloc allocImp; + ISzAlloc allocTempImp; + + CFileInStream archiveStream; + CLookToRead2 lookStream; + CSzArEx db; + SRes res; + UInt16 temp_u16[PATH_MAX]; + u8 temp_u8[PATH_MAX]; + const size_t kInputBufSize = ((size_t)1 << 18); + const ISzAlloc g_Alloc = {SzAlloc, SzFree}; + + allocImp = g_Alloc; + allocTempImp = g_Alloc; + + if (InFile_Open(&archiveStream.file, tmpfile_path.c_str())) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to open temporary storage file: %s", tmpfile_path); + return false; + } + + FileInStream_CreateVTable(&archiveStream); + LookToRead2_CreateVTable(&lookStream, False); + lookStream.buf = NULL; + + res = SZ_OK; + { + lookStream.buf = (Byte*)ISzAlloc_Alloc(&allocImp, kInputBufSize); + if (!lookStream.buf) + res = SZ_ERROR_MEM; + else + { + lookStream.bufSize = kInputBufSize; + lookStream.realStream = &archiveStream.vt; + LookToRead2_Init(&lookStream); + } + } + + CrcGenerateTable(); + SzArEx_Init(&db); + + auto error_free7z = [&]() { + SzArEx_Free(&db, &allocImp); + ISzAlloc_Free(&allocImp, lookStream.buf); + + File_Close(&archiveStream.file); + + switch (res) + { + case SZ_OK: break; + case SZ_ERROR_UNSUPPORTED: LOG_ERROR(GENERAL, "[Auto-updater] 7z decoder doesn't support this archive"); break; + case SZ_ERROR_MEM: LOG_ERROR(GENERAL, "[Auto-updater] 7z decoder failed to allocate memory"); break; + case SZ_ERROR_CRC: LOG_ERROR(GENERAL, "[Auto-updater] 7z decoder CRC error"); break; + default: LOG_ERROR(GENERAL, "[Auto-updater] 7z decoder error: %d", (u64)res); break; + } + }; + + if (res != SZ_OK) + { + error_free7z(); + return false; + } + + res = SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp); + if (res != SZ_OK) + { + error_free7z(); + return false; + } + + UInt32 blockIndex = 0xFFFFFFFF; + Byte* outBuffer = 0; + size_t outBufferSize = 0; + + // Creates temp folder for moving active files + std::string tmp_folder = Emulator::GetEmuDir() + m_tmp_folder; + fs::create_dir(tmp_folder); + + for (UInt32 i = 0; i < db.NumFiles; i++) + { + size_t offset = 0; + size_t outSizeProcessed = 0; + size_t len; + unsigned isDir = SzArEx_IsDir(&db, i); + len = SzArEx_GetFileNameUtf16(&db, i, NULL); + + if (len >= PATH_MAX) + { + LOG_ERROR(GENERAL, "[Auto-updater] 7z decoder error: filename longer or equal to PATH_MAX"); + error_free7z(); + return false; + } + + SzArEx_GetFileNameUtf16(&db, i, temp_u16); + memset(temp_u8, 0, sizeof(temp_u8)); + // Simplistic conversion to UTF-8 + for (size_t index = 0; index < len; index++) + { + if (temp_u16[index] > 0xFF) + { + LOG_ERROR(GENERAL, "[Auto-updater] 7z decoder error: Failed to convert utf-16 to utf-8"); + error_free7z(); + return false; + } + + temp_u8[index] = (u8)temp_u16[index]; + } + temp_u8[len] = 0; + std::string name((char*)temp_u8); + + name = Emulator::GetEmuDir() + name; + + if (!isDir) + { + res = SzArEx_Extract(&db, &lookStream.vt, i, &blockIndex, &outBuffer, &outBufferSize, &offset, &outSizeProcessed, &allocImp, &allocTempImp); + if (res != SZ_OK) + break; + } + + if (size_t pos = name.find_last_of('/'); pos != std::string::npos) + { + LOG_TRACE(GENERAL, "[Auto-updater] Creating path: %s", name.substr(0, pos)); + fs::create_path(name.substr(0, pos)); + } + + if (isDir) + { + LOG_TRACE(GENERAL, "[Auto-updater] Creating dir: %s", name); + fs::create_dir(name); + continue; + } + + fs::file outfile(name, fs::read + fs::write + fs::create + fs::trunc); + if (!outfile) + { + // File failed to open, probably because in use, rename existing file and try again + const auto pos = name.find_last_of('/'); + std::string filename; + if (pos == std::string::npos) + filename = name; + else + filename = name.substr(pos + 1); + + // Moving to temp is not an option on windows as it will fail if the disk is different + // So we create a folder in config dir and move stuff there + const std::string rename_target = tmp_folder + filename; + LOG_TRACE(GENERAL, "[Auto-updater] Renaming %s to %s", name, rename_target); + if (!fs::rename(name, rename_target, true)) + { + LOG_ERROR(GENERAL, "[Auto-updater] Failed to rename %s to %s", name, rename_target); + res = SZ_ERROR_FAIL; + break; + } + + outfile.open(name, fs::read + fs::write + fs::create + fs::trunc); + if (!outfile) + { + LOG_ERROR(GENERAL, "[Auto-updater] can not open output file %s", name); + res = SZ_ERROR_FAIL; + break; + } + } + + if (outfile.write(outBuffer + offset, outSizeProcessed) != outSizeProcessed) + { + LOG_ERROR(GENERAL, "[Auto-updater] can not write output file: %s", name); + res = SZ_ERROR_FAIL; + break; + } + outfile.close(); + } + + error_free7z(); + if (res) + return false; + + replace_path = Emulator::GetEmuDir() + "rpcs3.exe"; + +#endif + + m_progress_dialog->close(); + + QMessageBox::information(m_parent, tr("Auto-updater"), tr("Update successful!")); + int ret = execl(replace_path.c_str(), replace_path.c_str(), nullptr); + + if (ret == -1) + { + LOG_ERROR(GENERAL, "[Auto-updater] Relaunching failed with result: %d(%s)", ret, strerror(errno)); + return false; + } + + return true; +} diff --git a/rpcs3/rpcs3qt/update_manager.h b/rpcs3/rpcs3qt/update_manager.h new file mode 100644 index 0000000000..0563c3837f --- /dev/null +++ b/rpcs3/rpcs3qt/update_manager.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include "progress_dialog.h" + +class update_manager : public QObject +{ + Q_OBJECT + +private: + const std::string m_update_url = "https://update.rpcs3.net/?api=v1&c="; + const std::string m_tmp_folder = "/rpcs3_old/"; + +private: + progress_dialog* m_progress_dialog = nullptr; + QWidget* m_parent = nullptr; + + QNetworkAccessManager m_manager; + QNetworkReply* reply_rpcs3 = nullptr; + + std::string m_expected_hash; + u64 m_expected_size = 0; + +private: + bool handle_reply(QNetworkReply* reply, std::function func, bool automatic, const std::string& message); + bool handle_json(const QByteArray& json_data, bool automatic); + bool handle_rpcs3(const QByteArray& rpcs3_data, bool automatic); + +public: + update_manager(); + void check_for_updates(bool automatic, QWidget* parent = nullptr); + +private Q_SLOTS: + void handle_error(QNetworkReply::NetworkError error); +};