Support creating .torrent with larger piece size

Warning: users are at their own discretion to create .torrent with >= 64 MiB piece size as not
every torrent client supports it.
Larger piece sizes are only available when using libtorrent 2.x. libtorrent 1.x is not
efficient with memory usage and in order to avoid user complaints it is limited to 128 MiB.
Also note that, as of this writing, libtorrent 2.0.9 has an internal limitation that only
allows loading maximum 256 MiB piece size. And therefore > 256 MiB size options are forbidden
for now.

Closes #19527.
PR #19535.
This commit is contained in:
Chocobo1
2023-09-03 14:31:32 +08:00
committed by GitHub
parent 2dc1a7d66f
commit 4d2015cfed
4 changed files with 27 additions and 76 deletions

View File

@@ -259,12 +259,14 @@ QString Utils::Misc::unitString(const SizeUnit unit, const bool isSpeed)
return ret;
}
QString Utils::Misc::friendlyUnit(const qint64 bytes, const bool isSpeed)
QString Utils::Misc::friendlyUnit(const qint64 bytes, const bool isSpeed, const int precision)
{
const std::optional<SplitToFriendlyUnitResult> result = splitToFriendlyUnit(bytes);
if (!result)
return QCoreApplication::translate("misc", "Unknown", "Unknown (size)");
return Utils::String::fromDouble(result->value, friendlyUnitPrecision(result->unit))
const int digitPrecision = (precision >= 0) ? precision : friendlyUnitPrecision(result->unit);
return Utils::String::fromDouble(result->value, digitPrecision)
+ C_NON_BREAKING_SPACE
+ unitString(result->unit, isSpeed);
}

View File

@@ -74,7 +74,7 @@ namespace Utils::Misc
// return the best user friendly storage unit (B, KiB, MiB, GiB, TiB)
// value must be given in bytes
QString friendlyUnit(qint64 bytes, bool isSpeed = false);
QString friendlyUnit(qint64 bytes, bool isSpeed = false, int precision = -1);
int friendlyUnitPrecision(SizeUnit unit);
qint64 sizeInBytes(qreal size, SizeUnit unit);