|
14 | 14 | #include "CVersionUpdater.Util.hpp"
|
15 | 15 | #include "CNewsBrowser.h"
|
16 | 16 | #include "SharedUtil.Thread.h"
|
| 17 | +#include <charconv> |
17 | 18 |
|
18 | 19 | ///////////////////////////////////////////////////////////////
|
19 | 20 | //
|
@@ -2176,6 +2177,35 @@ void CVersionUpdater::_UseVersionQueryURLs()
|
2176 | 2177 | m_JobInfo.bShowDownloadPercent = false;
|
2177 | 2178 | }
|
2178 | 2179 |
|
| 2180 | +/** |
| 2181 | + * @brief Extracts the revision from an update file name. |
| 2182 | + * @param fileName Name of the file |
| 2183 | + * @param revision Revision of the update |
| 2184 | +*/ |
| 2185 | +static bool GetRevisionFromFileName(std::string_view fileName, std::uint32_t& revision) |
| 2186 | +{ |
| 2187 | + revision = {}; |
| 2188 | + |
| 2189 | + // Example: mtasa-1.5.9-rc-21519-0-000-files-all-cksummed.rar |
| 2190 | + // Search for the delimiter before the revision ^^^^. |
| 2191 | + if (size_t revisionStart = fileName.find("-rc-"); revisionStart != std::string_view::npos) |
| 2192 | + { |
| 2193 | + revisionStart += 4; |
| 2194 | + |
| 2195 | + // Example: mtasa-1.5.9-rc-21519-0-000-files-all-cksummed.rar |
| 2196 | + // Search for the delimiter after the revision ^. |
| 2197 | + if (size_t revisionStop = fileName.find('-', revisionStart); revisionStop != std::string_view::npos) |
| 2198 | + { |
| 2199 | + std::string_view raw = fileName.substr(revisionStart, revisionStop - revisionStart); |
| 2200 | + |
| 2201 | + if (auto [ptr, ec] = std::from_chars(raw.data(), raw.data() + raw.size(), revision); ec == std::errc{}) |
| 2202 | + return true; |
| 2203 | + } |
| 2204 | + } |
| 2205 | + |
| 2206 | + return false; |
| 2207 | +} |
| 2208 | + |
2179 | 2209 | ///////////////////////////////////////////////////////////////
|
2180 | 2210 | //
|
2181 | 2211 | // CVersionUpdater::_ProcessPatchFileQuery
|
@@ -2303,16 +2333,20 @@ void CVersionUpdater::_ProcessPatchFileQuery()
|
2303 | 2333 | // Report update response
|
2304 | 2334 | if (!m_JobInfo.strStatus.empty() && m_JobInfo.strStatus != "noupdate" && !_strnicmp("mtasa-", m_JobInfo.strFilename.c_str(), 6))
|
2305 | 2335 | {
|
2306 |
| - unsigned short netRev = CCore::GetSingleton().GetNetwork()->GetNetRev(); |
2307 |
| - unsigned short netRel = CCore::GetSingleton().GetNetwork()->GetNetRel(); |
2308 |
| - SString playerVersion("%d.%d.%d-%d.%05d.%d.%03d", MTASA_VERSION_MAJOR, MTASA_VERSION_MINOR, MTASA_VERSION_MAINTENANCE, MTASA_VERSION_TYPE, |
2309 |
| - MTASA_VERSION_BUILD, netRev, netRel); |
2310 |
| - SString updateBuildType; |
2311 |
| - CVARS_GET("update_build_type", updateBuildType); |
| 2336 | + uint32_t revision{}; |
2312 | 2337 |
|
2313 |
| - AddReportLog(5060, SString("Processing patch file '%s' [%s, %s] with '%s' (version: %s, channel: %s)", m_JobInfo.strFilename.c_str(), |
2314 |
| - m_JobInfo.iFilesize.ToString().c_str(), m_JobInfo.strMD5.c_str(), m_JobInfo.strStatus.c_str(), playerVersion.c_str(), |
2315 |
| - updateBuildType.c_str())); |
| 2338 | + if (GetRevisionFromFileName(m_JobInfo.strFilename, revision) && revision < MTASA_VERSION_BUILD) |
| 2339 | + { |
| 2340 | + unsigned short netRev = CCore::GetSingleton().GetNetwork()->GetNetRev(); |
| 2341 | + unsigned short netRel = CCore::GetSingleton().GetNetwork()->GetNetRel(); |
| 2342 | + |
| 2343 | + SString playerVersion("%d.%d.%d-%d.%05d.%d.%03d", MTASA_VERSION_MAJOR, MTASA_VERSION_MINOR, MTASA_VERSION_MAINTENANCE, MTASA_VERSION_TYPE, |
| 2344 | + MTASA_VERSION_BUILD, netRev, netRel); |
| 2345 | + |
| 2346 | + AddReportLog(5061, SString("Processing patch file '%s' [%s, %s] with '%s' (version: %s) from '%s'", m_JobInfo.strFilename.c_str(), |
| 2347 | + m_JobInfo.iFilesize.ToString().c_str(), m_JobInfo.strMD5.c_str(), m_JobInfo.strStatus.c_str(), playerVersion.c_str(), |
| 2348 | + m_strLastQueryURL.c_str())); |
| 2349 | + } |
2316 | 2350 | }
|
2317 | 2351 | }
|
2318 | 2352 |
|
|
0 commit comments