fix MT issue in session.Save

This commit is contained in:
Wizou 2021-09-27 17:08:22 +02:00
parent cb35ec3799
commit 66757ccd0b

View file

@ -88,12 +88,12 @@ namespace WTelegram
encryptor.TransformFinalBlock(finalBlock, 0, utf8Json.Length & 15).CopyTo(output.AsMemory(48 + utf8Json.Length & ~15));
if (!File.Exists(_pathname))
File.WriteAllBytes(_pathname, output);
else
{
string tempPathname = _pathname + ".tmp";
File.WriteAllBytes(tempPathname, output);
File.Replace(tempPathname, _pathname, null);
}
else lock (this)
{
string tempPathname = _pathname + ".tmp";
File.WriteAllBytes(tempPathname, output);
File.Replace(tempPathname, _pathname, null);
}
}
internal (long msgId, int seqno) NewMsg(bool isContent)
@ -104,7 +104,6 @@ namespace WTelegram
lock (this)
{
if (msgId <= CurrentDCSession.LastSentMsgId) msgId = CurrentDCSession.LastSentMsgId += 4; else CurrentDCSession.LastSentMsgId = msgId;
seqno = isContent ? CurrentDCSession.Seqno++ * 2 + 1 : CurrentDCSession.Seqno * 2;
Save();
}