diff --git a/src/Helpers.TL.cs b/src/Helpers.TL.cs index 84047c0..7a412d1 100644 --- a/src/Helpers.TL.cs +++ b/src/Helpers.TL.cs @@ -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"; } diff --git a/src/Session.cs b/src/Session.cs index 8ee577f..79243aa 100644 --- a/src/Session.cs +++ b/src/Session.cs @@ -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)