public static ProfileAttachment Decode(G2Header root) { ProfileAttachment file = new ProfileAttachment(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Name: file.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Size: file.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(file); }
public void LoadProfile(ulong id) { OpProfile profile = GetProfile(id); if (profile == null) { return; } try { string path = GetFilePath(profile); if (!File.Exists(path)) { return; } profile.Attached = new List <ProfileAttachment>(); using (TaggedStream file = new TaggedStream(path, Network.Protocol)) using (IVCryptoStream crypto = IVCryptoStream.Load(file, profile.File.Header.FileKey)) { PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read); G2Header root = null; while (stream.ReadPacket(ref root)) { if (root.Name == ProfilePacket.Attachment) { ProfileAttachment packet = ProfileAttachment.Decode(root); if (packet == null) { continue; } profile.Attached.Add(packet); } } } profile.Loaded = true; } catch (Exception ex) { Network.UpdateLog("Profile", "Error loading file " + ex.Message); } }
public static ProfileAttachment Decode(G2Header root) { ProfileAttachment file = new ProfileAttachment(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_Name: file.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Size: file.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; } } return file; }