private void comic_update(object sender, EventArgs e, Comic comic, ComicSource source) { currentcomic = new CurrentComicInfo(comic, source); date.ResetBindings(); date.Checked = true; //i keep getting argumentoutofrangeexceptions. lets try this date.MaxDate = DateTimePicker.MaximumDateTime; date.MinDate = DateTimePicker.MinimumDateTime; //reset mindate and maxdate values then set it again date.MaxDate = source.getMaxDate(comic); date.MinDate = source.getMinDate(comic); date.Value = date.Value; statuscomic.Text = String.Format("({0}) {1}", currentcomic.source.name, currentcomic.comic.name); strip_update(null, null); }
public Garfield() { try { string json = File.ReadAllText(@"strips.json"); comics = JsonConvert.DeserializeObject <List <Comic> >(json); } catch (Exception suck) { MessageBox.Show(String.Format("Your strips.json is wrong.\n\n{0}\n\n...but I'll let you pass this time.", suck.ToString()), "UH OH IO!", MessageBoxButtons.OK, MessageBoxIcon.Error); comics = JsonConvert.DeserializeObject <List <Comic> >(@"[ { 'name': 'Garfield', 'numPanels': 3, 'minDate': '1978-06-19', 'fileName': '{0:yyyy-MM-dd}.gif', 'sources': [ // These are ComicSources. It contains information of the name of the source, the URL format, whether or not it's an HTML and regex for the data. // maxDate and minDate will override the top-layer date settings { 'name': 'GoComics', 'urlFormat': 'https://www.gocomics.com/garfield/{0:yyyy}/{0:MM}/{0:dd}', 'isHtml': true, // This is a RegexInfo. It simply contains the expression and group to tell the program how to pull the comic image URL from the HTML data. 'regex': { 'expression': 'item-comic-image.*data-srcset=\""(.*?) (.*?)(,|\\"")', 'group': 1 } }, { 'name': 'the-eye', 'urlFormat': 'https://the-eye.eu/public/Comics/Garfield/{0:yyyy-MM-dd}.gif', 'maxDate': '2020-07-21' }, { 'name': 'Uclick', 'minDate': '1978-06-19', 'urlFormat': 'http://images.ucomics.com/comics/ga/{0:yyyy}/ga{0:yyMMdd}.gif' }, { 'name': 'archive.org', 'urlFormat': 'https://web.archive.org/web/2019id_/https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/{0:yyyy}/{0:yyyy-MM-dd}.gif', 'maxDate': '2020-07-21' } ] } ]" ); } file = new ToolStripMenuItem("&File"); comic = new ToolStripMenuItem("&Comic"); gimmick = new ToolStripMenuItem("&Gimmicks"); gimmicks = new Gimmicks(); foreach (Gimmick gimmick in gimmicks.gimmicks) { ToolStripMenuItem temp = new ToolStripMenuItem(gimmick.contentlabel, null); temp.Click += (sender, e) => strip_gimmick(sender, e, gimmick); // Not using the EventHandler in constructor this time lol gimmickMenus.Add(temp); } change = new ToolStripMenuItem("&Change comic"); save = new ToolStripMenuItem("&Save strip", null, new EventHandler(strip_save), (Keys.Control | Keys.S)); copy = new ToolStripMenuItem("&Copy strip image to clipboard", null, new EventHandler(strip_copy), (Keys.Control | Keys.C)); copyURL = new ToolStripMenuItem("Copy strip &URL to clipboard", null, new EventHandler(strip_copyURL), (Keys.Control | Keys.Shift | Keys.C)); nextstrip = new ToolStripMenuItem("&Next strip", null, new EventHandler(strip_next)); previousstrip = new ToolStripMenuItem("&Previous strip", null, new EventHandler(strip_previous)); gorando = new ToolStripMenuItem("&Go rando", null, new EventHandler(strip_rando)); exit = new ToolStripMenuItem("E&xit", null, new EventHandler(delegate(object sender, EventArgs e) { this.Close(); }), (Keys.Alt | Keys.F4)); currentcomic = new CurrentComicInfo(comics[0], comics[0].sources[0]); this.AutoSize = true; this.MinimumSize = new Size(661, 480); this.Text = @"Garfield strip picker - " + taglines[new Random().Next(0, taglines.Length)]; stripretriever = new HttpClient(); System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13; stripretriever.DefaultRequestHeaders.UserAgent.TryParseAdd("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); // f**k you msdn you lied to me /*stripretriever.DownloadProgressChanged += new DownloadProgressChangedEventHandler(delegate (object sender, DownloadProgressChangedEventArgs e) { * statusprogress.Value = e.ProgressPercentage; * });*/ panel = new TableLayoutPanel(); panel.ColumnCount = 0; panel.RowCount = 2; panel.Dock = DockStyle.Fill; panel.RowStyles.Clear(); panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 32)); panel.RowStyles.Add(new RowStyle(SizeType.Percent, 90)); this.Controls.Add(panel); picker = new TableLayoutPanel(); picker.ColumnCount = 3; picker.RowCount = 0; picker.Dock = DockStyle.Fill; picker.AutoSize = true; picker.ColumnStyles.Clear(); picker.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 64)); picker.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 90)); picker.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 64)); panel.Controls.Add(picker); stripmenu = new ContextMenuStrip(); stripmenu.Opening += new System.ComponentModel.CancelEventHandler(delegate(object sender, CancelEventArgs e) { stripmenu.Items.Clear(); stripmenu.Items.AddRange(new ToolStripMenuItem[] { save, copy, copyURL, nextstrip, previousstrip, gorando }); }); previous = new Button(); previous.Dock = DockStyle.Fill; previous.Text = "Previous"; previous.Click += new EventHandler(strip_previous); previous.Anchor = AnchorStyles.Left; picker.Controls.Add(previous); date = new DateTimePicker(); date.MinDate = currentcomic.source.getMinDate(currentcomic.comic); date.MaxDate = currentcomic.source.getMaxDate(currentcomic.comic); date.CustomFormat = "yyyy-MM-dd"; date.Format = DateTimePickerFormat.Custom; date.Dock = DockStyle.Fill; date.Anchor = AnchorStyles.None; date.ValueChanged += new EventHandler(strip_update); picker.Controls.Add(date); next = new Button(); next.Dock = DockStyle.Fill; next.Text = "Next"; next.Click += new EventHandler(strip_next); next.Anchor = AnchorStyles.Right; picker.Controls.Add(next); strip = new PictureBox(); strip.SizeMode = PictureBoxSizeMode.Zoom; strip.Dock = DockStyle.Fill; strip.ContextMenuStrip = stripmenu; strip.MinimumSize = new Size(640, 0); panel.Controls.Add(strip); status = new StatusStrip(); statuscomic = new ToolStripStatusLabel(String.Format("({0}) {1}", currentcomic.source.name, currentcomic.comic.name)); statusdate = new ToolStripStatusLabel(); statusprogress = new ToolStripProgressBar(); statusprogress.Alignment = ToolStripItemAlignment.Right; statusprogress.Visible = false; status.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { statuscomic, statusdate, statusprogress }); this.Controls.Add(status); menu = new MenuStrip(); file.DropDownOpening += new EventHandler(delegate(object sender, EventArgs e) { file.DropDownItems.Clear(); file.DropDownItems.AddRange(new ToolStripMenuItem[] { save, copy, copyURL, exit }); }); comic.DropDownOpening += new EventHandler(delegate(object sender, EventArgs e) { comic.DropDownItems.Clear(); comic.DropDownItems.AddRange(new ToolStripMenuItem[] { change, nextstrip, previousstrip, gorando }); }); gimmick.DropDownOpening += new EventHandler(delegate(object sender, EventArgs e) { gimmick.DropDownItems.Clear(); gimmick.DropDownItems.AddRange(gimmickMenus.ToArray()); }); for (int x = 0; x < comics.Count; x++) { // im so f****d up Comic item = comics[x]; ToolStripMenuItem f**k = new ToolStripMenuItem(item.name, null); //, new EventHandler((sender, e) => comic_update(sender, e))); for (int y = 0; y < item.sources.Count; y++) { ComicSource source = item.sources[y]; ToolStripMenuItem sourcemenu = new ToolStripMenuItem(source.name, null); sourcemenu.Click += (sender, e) => comic_update(sender, e, item, source); f**k.DropDownItems.Add(sourcemenu); } change.DropDownItems.Add(f**k); } menu.Items.AddRange(new ToolStripItem[] { file, comic, gimmick }); this.Controls.Add(menu); strip_rando(null, null); strip_update(null, null); }