public static void FetchNotification(MainForm f) { if (Count < 0) Count = 0; if (Queued.Count != 0) { NotificationType n = Queued.Dequeue(); byte[] bytes = Encoding.Default.GetBytes(n.Control.Title); n.Control.Title = Encoding.UTF8.GetString(bytes); bytes = Encoding.Default.GetBytes(n.Control.Desc); n.Control.Desc = Encoding.UTF8.GetString(bytes); Notification notification = new Notification(f, n.Tag, n.Control.Image, n.Control.Title, n.Control.Desc, n.Link, !n.ShowInWindow); if (n.Type == 0) { if (OnGenericMessage != null) OnGenericMessage(n.Tag, notification); } else if (n.Type == 1) { if (OnYouTubeMessage != null) OnYouTubeMessage(n.Tag, new NotificationYoutube() { N = notification, Yt = ((YoutubeNotificationType)n).ID }); } else if (n.Type == 2) { if (OnFacebookMessage != null) OnFacebookMessage(n.Tag, new NotificationFacebook() { N = notification, Fb = ((FacebookNotificationType)n).Data }); } if (n.ShowInWindow) { if (DateTime.Now > Allow && Count <= Config.Settings.MaxNotifications && ShowNow) { notification.ShowInTaskbar = false; notification.Show(); notification.Left = Screen.PrimaryScreen.Bounds.Width - 375; if (SystemInformation.WorkingArea.Top > 0) notification.Top = Screen.PrimaryScreen.Bounds.Height - 100 * Count - 105; else notification.Top = Screen.PrimaryScreen.Bounds.Height - 100 * Count - 105 - GetTaskbarHeight(); Count++; notification.Opacity = 1; } } } }
public Notification(MainForm f, string tag, string image, string title, string desc, string link, bool read) { InitializeComponent(); if (image == null || title == null || desc == null || link == null) return; this.tag = tag; this.f = f; WebClient wc = new WebClient(); byte[] bytes = wc.DownloadData(image); MemoryStream ms = new MemoryStream(bytes); this.image = new Bitmap(ms); int y0 = 0, y1 = this.image.Height; bool isBlack = true; for (int y = 0; y < this.image.Height; y++) { for (int x = 0; x < this.image.Width; x++) { Color c = this.image.GetPixel(x, y); if (c.R + c.G + c.B > 30) isBlack = false; } if (isBlack) { if (y < this.image.Height / 2) y0 = y; else y1 = y; } isBlack = true; } clipRegion = new Rectangle(0, y0, this.image.Width, y1 - y0 * 2); this.title = title; this.desc = desc; this.link = link; timer1.Interval = Config.Settings.NotifyDelay * 100; proportion = clipRegion.Height / (float)this.image.Height; imgScale = 61.0f / this.image.Height; Bitmap b = new Bitmap(Image.FromStream(new MemoryStream(File.ReadAllBytes("Image/Palette.png")))); foreColor = b.GetPixel(Config.Settings.NotifyColor, 1); this.read = read; }
private static void Main(string[] args) { if (args.Contains("-a")) { try { ProcessStartInfo s = new ProcessStartInfo(); s.FileName = Application.ExecutablePath; s.Arguments = "-s"; Process.Start(s); } catch (Exception e) { using (StreamWriter w = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + "/error.txt")) { w.WriteLine("Error trying to start " + Application.ExecutablePath + " -s"); w.WriteLine(); w.WriteLine("============"); w.WriteLine(); w.WriteLine(e.Message); w.WriteLine(e.StackTrace); w.WriteLine(e.Source); w.WriteLine(); w.WriteLine("============"); w.WriteLine(); if (e.Data.Count > 0) { w.WriteLine(" Extra details:"); foreach (DictionaryEntry de in e.Data) w.WriteLine(" Key: {0,-20} Value: {1}", "'" + de.Key.ToString() + "'", de.Value); } w.WriteLine(); w.WriteLine("============"); w.WriteLine(); w.WriteLine("Send message to naronco pls!"); MessageBox.Show("Error Document written to " + Path.GetDirectoryName(Application.ExecutablePath) + "/error.txt"); } } } else { #if !DEBUG try { #endif if (mutex.WaitOne(TimeSpan.Zero, true)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm f = new MainForm(); if (args.Contains("-s")) { f.Hidden = true; } Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); Application.Run(f); mutex.ReleaseMutex(); } else { NativeMethods.PostMessage( (IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero); } #if !DEBUG } catch (Exception e) { using (StreamWriter w = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + "/error.txt")) { w.WriteLine("OMFG AN ERROR OCCURED!"); w.WriteLine(); w.WriteLine("============"); w.WriteLine(); w.WriteLine(e.Message); w.WriteLine(e.StackTrace); w.WriteLine(e.Source); w.WriteLine(); w.WriteLine("============"); w.WriteLine(); if (e.Data.Count > 0) { w.WriteLine(" Extra details:"); foreach (DictionaryEntry de in e.Data) w.WriteLine(" Key: {0,-20} Value: {1}", "'" + de.Key.ToString() + "'", de.Value); } w.WriteLine(); w.WriteLine("============"); w.WriteLine(); w.WriteLine("Send message to naronco pls!"); MessageBox.Show("Error Document written to " + Path.GetDirectoryName(Application.ExecutablePath) + "/error.txt"); } } #endif } }