Support DMD 2.097.0 as compiler (#1505)

* Support DMD 2.097.0 as compiler and resolve deprecation messages
This commit is contained in:
abraunegg 2021-06-07 08:26:36 +10:00 committed by GitHub
parent 16fdd928b6
commit 761cf3eb87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 89 deletions

View file

@ -154,6 +154,7 @@ void notify(T...)(T args)
private void logfileWriteLine(T...)(T args) private void logfileWriteLine(T...)(T args)
{ {
static import std.exception;
// Write to log file // Write to log file
string logFileName = .logFilePath ~ .username ~ ".onedrive.log"; string logFileName = .logFilePath ~ .username ~ ".onedrive.log";
auto currentTime = Clock.currTime(); auto currentTime = Clock.currTime();

View file

@ -163,7 +163,7 @@ class Notification {
this(in char[] summary, in char[] body_, in char[] icon="") this(in char[] summary, in char[] body_, in char[] icon="")
in { assert(is_initted(), "call dnotify.init() before using Notification"); } in { assert(is_initted(), "call dnotify.init() before using Notification"); }
body { do {
this.summary = summary; this.summary = summary;
this.body_ = body_; this.body_ = body_;
this.icon = icon; this.icon = icon;

View file

@ -1,88 +1,88 @@
import std.algorithm; import std.algorithm;
import std.digest; import std.digest;
// implementation of the QuickXorHash algorithm in D // implementation of the QuickXorHash algorithm in D
// https://github.com/OneDrive/onedrive-api-docs/blob/live/docs/code-snippets/quickxorhash.md // https://github.com/OneDrive/onedrive-api-docs/blob/live/docs/code-snippets/quickxorhash.md
struct QuickXor struct QuickXor
{ {
private immutable int widthInBits = 160; private enum int widthInBits = 160;
private immutable size_t lengthInBytes = (widthInBits - 1) / 8 + 1; private enum size_t lengthInBytes = (widthInBits - 1) / 8 + 1;
private immutable size_t lengthInQWords = (widthInBits - 1) / 64 + 1; private enum size_t lengthInQWords = (widthInBits - 1) / 64 + 1;
private immutable int bitsInLastCell = widthInBits % 64; // 32 private enum int bitsInLastCell = widthInBits % 64; // 32
private immutable int shift = 11; private enum int shift = 11;
private ulong[lengthInQWords] _data; private ulong[lengthInQWords] _data;
private ulong _lengthSoFar; private ulong _lengthSoFar;
private int _shiftSoFar; private int _shiftSoFar;
nothrow @safe void put(scope const(ubyte)[] array...) nothrow @safe void put(scope const(ubyte)[] array...)
{ {
int vectorArrayIndex = _shiftSoFar / 64; int vectorArrayIndex = _shiftSoFar / 64;
int vectorOffset = _shiftSoFar % 64; int vectorOffset = _shiftSoFar % 64;
immutable size_t iterations = min(array.length, widthInBits); immutable size_t iterations = min(array.length, widthInBits);
for (size_t i = 0; i < iterations; i++) { for (size_t i = 0; i < iterations; i++) {
immutable bool isLastCell = vectorArrayIndex == _data.length - 1; immutable bool isLastCell = vectorArrayIndex == _data.length - 1;
immutable int bitsInVectorCell = isLastCell ? bitsInLastCell : 64; immutable int bitsInVectorCell = isLastCell ? bitsInLastCell : 64;
if (vectorOffset <= bitsInVectorCell - 8) { if (vectorOffset <= bitsInVectorCell - 8) {
for (size_t j = i; j < array.length; j += widthInBits) { for (size_t j = i; j < array.length; j += widthInBits) {
_data[vectorArrayIndex] ^= cast(ulong) array[j] << vectorOffset; _data[vectorArrayIndex] ^= cast(ulong) array[j] << vectorOffset;
} }
} else { } else {
int index1 = vectorArrayIndex; int index1 = vectorArrayIndex;
int index2 = isLastCell ? 0 : (vectorArrayIndex + 1); int index2 = isLastCell ? 0 : (vectorArrayIndex + 1);
ubyte low = cast(ubyte) (bitsInVectorCell - vectorOffset); ubyte low = cast(ubyte) (bitsInVectorCell - vectorOffset);
ubyte xoredByte = 0; ubyte xoredByte = 0;
for (size_t j = i; j < array.length; j += widthInBits) { for (size_t j = i; j < array.length; j += widthInBits) {
xoredByte ^= array[j]; xoredByte ^= array[j];
} }
_data[index1] ^= cast(ulong) xoredByte << vectorOffset; _data[index1] ^= cast(ulong) xoredByte << vectorOffset;
_data[index2] ^= cast(ulong) xoredByte >> low; _data[index2] ^= cast(ulong) xoredByte >> low;
} }
vectorOffset += shift; vectorOffset += shift;
if (vectorOffset >= bitsInVectorCell) { if (vectorOffset >= bitsInVectorCell) {
vectorArrayIndex = isLastCell ? 0 : vectorArrayIndex + 1; vectorArrayIndex = isLastCell ? 0 : vectorArrayIndex + 1;
vectorOffset -= bitsInVectorCell; vectorOffset -= bitsInVectorCell;
} }
} }
_shiftSoFar = cast(int) (_shiftSoFar + shift * (array.length % widthInBits)) % widthInBits; _shiftSoFar = cast(int) (_shiftSoFar + shift * (array.length % widthInBits)) % widthInBits;
_lengthSoFar += array.length; _lengthSoFar += array.length;
} }
nothrow @safe void start() nothrow @safe void start()
{ {
_data = _data.init; _data = _data.init;
_shiftSoFar = 0; _shiftSoFar = 0;
_lengthSoFar = 0; _lengthSoFar = 0;
} }
nothrow @trusted ubyte[lengthInBytes] finish() nothrow @trusted ubyte[lengthInBytes] finish()
{ {
ubyte[lengthInBytes] tmp; ubyte[lengthInBytes] tmp;
tmp[0 .. lengthInBytes] = (cast(ubyte*) _data)[0 .. lengthInBytes]; tmp[0 .. lengthInBytes] = (cast(ubyte*) _data)[0 .. lengthInBytes];
for (size_t i = 0; i < 8; i++) { for (size_t i = 0; i < 8; i++) {
tmp[lengthInBytes - 8 + i] ^= (cast(ubyte*) &_lengthSoFar)[i]; tmp[lengthInBytes - 8 + i] ^= (cast(ubyte*) &_lengthSoFar)[i];
} }
return tmp; return tmp;
} }
} }
unittest unittest
{ {
assert(isDigest!QuickXor); assert(isDigest!QuickXor);
} }
unittest unittest
{ {
QuickXor qxor; QuickXor qxor;
qxor.put(cast(ubyte[]) "The quick brown fox jumps over the lazy dog"); qxor.put(cast(ubyte[]) "The quick brown fox jumps over the lazy dog");
assert(qxor.finish().toHexString() == "6CC4A56F2B26C492FA4BBE57C1F31C4193A972BE"); assert(qxor.finish().toHexString() == "6CC4A56F2B26C492FA4BBE57C1F31C4193A972BE");
} }
alias QuickXorDigest = WrapperDigest!(QuickXor); alias QuickXorDigest = WrapperDigest!(QuickXor);

View file

@ -2585,6 +2585,7 @@ final class SyncEngine
// downloads a File resource // downloads a File resource
private void downloadFileItem(const ref Item item, const(string) path) private void downloadFileItem(const ref Item item, const(string) path)
{ {
static import std.exception;
assert(item.type == ItemType.file); assert(item.type == ItemType.file);
write("Downloading file ", path, " ... "); write("Downloading file ", path, " ... ");
JSONValue fileDetails; JSONValue fileDetails;
@ -3825,6 +3826,7 @@ final class SyncEngine
// upload new items to OneDrive // upload new items to OneDrive
private void uploadNewItems(const(string) path) private void uploadNewItems(const(string) path)
{ {
static import std.utf;
import std.range : walkLength; import std.range : walkLength;
import std.uni : byGrapheme; import std.uni : byGrapheme;
// https://support.microsoft.com/en-us/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders // https://support.microsoft.com/en-us/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders
@ -6515,6 +6517,7 @@ final class SyncEngine
// Query itemdb.computePath() and catch potential assert when DB consistency issue occurs // Query itemdb.computePath() and catch potential assert when DB consistency issue occurs
string computeItemPath(string thisDriveId, string thisItemId) string computeItemPath(string thisDriveId, string thisItemId)
{ {
static import core.exception;
string calculatedPath; string calculatedPath;
log.vdebug("Attempting to calculate local filesystem path for ", thisDriveId, " and ", thisItemId); log.vdebug("Attempting to calculate local filesystem path for ", thisDriveId, " and ", thisItemId);
try { try {