using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MessengerDotNet; namespace WlmImage { static class Program { static Image online; static Image away; static Image busy; static Image offline; /// /// The main entry point for the application. /// [STAThread] static void Main() { Console.WriteLine("Loading contacts..."); var contacts = MessengerDotNet.MessengerAPI.Contacts.ToList(); contacts.Add(MessengerDotNet.MessengerAPI.Me); Console.WriteLine("Loading images..."); online = Image.FromFile("online.png"); away = Image.FromFile("away.png"); busy = Image.FromFile("busy.png"); offline = Image.FromFile("offline.png"); HttpListener httpListener = new HttpListener(); httpListener.Prefixes.Add("http://+/"); httpListener.Start(); Console.WriteLine("Listening..."); while (true) { HttpListenerContext context = httpListener.GetContext(); HttpListenerResponse response = context.Response; try { var requestedEmail = context.Request.Url.LocalPath; if (requestedEmail.StartsWith("/")) { requestedEmail = requestedEmail.Remove(0, 1); } if (requestedEmail.EndsWith(".png")) { requestedEmail = requestedEmail.Remove(requestedEmail.Length - 4, 4); } Console.WriteLine($"{requestedEmail} requested from {context.Request.RemoteEndPoint.ToString()}"); Bitmap bitmap = null; foreach (var item in contacts) { if (item.Email == requestedEmail) { bitmap = GetBitmap(item); response.StatusCode = (int)HttpStatusCode.Found; break; } } if (bitmap == null) { bitmap = GetBitmap(requestedEmail,"", requestedEmail, "unknown.png", MessengerStatus.Offline); response.StatusCode = (int)HttpStatusCode.NotFound; } if (bitmap != null) { using (var memoryStream = new MemoryStream()) { bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); response.ContentLength64 = memoryStream.Length; memoryStream.WriteTo(response.OutputStream); } response.ContentType = "image/png"; } } catch (Exception ex) { response.StatusCode = (int)HttpStatusCode.InternalServerError; var stream = new StreamWriter(response.OutputStream); stream.WriteLine("Oof. \n\n" + ex.ToString()); stream.Flush(); } finally { try { context.Response.Close(); } catch {} } } } public static Bitmap GetBitmap(string name, string psm, string email, string displayPicture, MessengerStatus status) { var bmp = (Bitmap)Bitmap.FromFile("bg.png"); using (var g = Graphics.FromImage(bmp)) { const bool includePicture = true; var x = 0; if (includePicture) { var frame = Image.FromFile("frame.png"); g.DrawImage(frame, 8, 8, 62, 62); frame.Dispose(); var picture = Image.FromFile(displayPicture); g.DrawImage(picture, 14, 14, 46, 46); picture.Dispose(); x += 66; } Font font; Image statusIcon = offline; switch (status) { case MessengerStatus.Online: statusIcon = online; break; case MessengerStatus.Away: case MessengerStatus.BeRightBack: case MessengerStatus.OutToLunch: statusIcon = away; break; case MessengerStatus.Busy: case MessengerStatus.OnThePhone: statusIcon = busy; break; } if (string.IsNullOrWhiteSpace(psm)) { psm = status.ToString(); } g.DrawImage(statusIcon, x + 8, 11); font = new Font("Segoe UI", 13); g.DrawString(name, font, Brushes.White, x + 8 + statusIcon.Width, 6); font = new Font("Segoe UI", 10); g.DrawString(psm, font, Brushes.White, new Rectangle(x + 8, 28, bmp.Width - 8 - x, bmp.Height - 28)); } return bmp; } public static Bitmap GetBitmap(MessengerContact contact) { const string profilePath = @"A:\Data\Documents\windows live messenger\profiles\"; string picturePath = Path.Combine(profilePath, contact.Email + ".png"); string psmPath = Path.Combine(profilePath, contact.Email + ".txt"); return GetBitmap(contact.Name, File.Exists(psmPath) ? File.ReadAllText(psmPath) : "", contact.Email, File.Exists(picturePath) ? picturePath : "picture.png", contact.Status); } } }