Fix issue with session file corruption

This commit is contained in:
Wizou 2021-09-27 03:20:58 +02:00
parent 2ff0de667d
commit 6770f66270
2 changed files with 11 additions and 4 deletions

View file

@ -260,9 +260,9 @@ namespace TL
}
partial class Peer { public abstract long ID { get; } }
partial class PeerUser { public override long ID => user_id; }
partial class PeerChat { public override long ID => chat_id; }
partial class PeerChannel { public override long ID => channel_id; }
partial class PeerUser { public override long ID => user_id; public override string ToString() => "user " + user_id; }
partial class PeerChat { public override long ID => chat_id; public override string ToString() => "chat " + chat_id; }
partial class PeerChannel { public override long ID => channel_id; public override string ToString() => "channel " + channel_id; }
partial class JsonObjectValue { public override string ToString() => $"{HttpUtility.JavaScriptStringEncode(key, true)}:{value}"; }
partial class JsonNull { public override string ToString() => "null"; }

View file

@ -86,7 +86,14 @@ namespace WTelegram
encryptor.TransformBlock(utf8Json, 0, utf8Json.Length & ~15, output, 48);
utf8Json.AsSpan(utf8Json.Length & ~15).CopyTo(finalBlock);
encryptor.TransformFinalBlock(finalBlock, 0, utf8Json.Length & 15).CopyTo(output.AsMemory(48 + utf8Json.Length & ~15));
File.WriteAllBytes(_pathname, output);
if (!File.Exists(_pathname))
File.WriteAllBytes(_pathname, output);
else
{
string tempPathname = _pathname + ".tmp";
File.WriteAllBytes(tempPathname, output);
File.Replace(tempPathname, _pathname, null);
}
}
internal (long msgId, int seqno) NewMsg(bool isContent)