This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
983 lines (919 loc) · 37.7 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EmotesEverywhere
{
public partial class Form1 : Window
{
// Variables
public int
integer,
division = 10,
page = 0,
paging,
paging_multiplier,
search_length;
public string
searchEmotes = "Search Emotes",
firstLabel = "Drag and Drop with RMB gives best results.";
public bool processStop = false;
public bool merge = false;
public List<PictureBox> pictureList = new List<PictureBox>();
public List<string> emoteString;
public FlowLayoutPanel flowPanel = new FlowLayoutPanel();
public FlowLayoutPanel flowPanelFav = new FlowLayoutPanel();
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
MatchCollection matches;
SemaphoreSlim semaphore = new SemaphoreSlim(1);
// PreStart
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
// Start
public Form1()
{
if (Process.GetProcessesByName("EmotesEverywhere").Length > 1)
{
MessageBox.Show("Emotes Everywhere is already open!");
Application.Exit();
}
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
SetVisibleCore(false);
if (!Directory.Exists(temp_path)) Directory.CreateDirectory(temp_path);
Borderless();
flowPanel = new FlowLayoutPanel();
flowPanelFav = new FlowLayoutPanel();
Controls.Add(flowPanel);
Controls.Add(flowPanelFav);
linkLabel1.LinkBehavior = LinkBehavior.NeverUnderline;
linkLabel2.LinkBehavior = LinkBehavior.NeverUnderline;
linkLabel3.LinkBehavior = LinkBehavior.NeverUnderline;
label1.Text = firstLabel;
label5.Text = Text;
label5.MouseDown += title_MouseDown;
label5.MouseUp += title_MouseUp;
label5.MouseMove += title_MouseMove;
pictureBox2.MouseDown += title_MouseDown;
pictureBox2.MouseUp += title_MouseUp;
pictureBox2.MouseMove += title_MouseMove;
pictureBox1.MouseMove += buttonGenerated_MouseMove;
pictureBox1.Click += buttonGenerated_Click;
toolTip_Settings();
Cache_Check();
ImageFirstGetting();
RefreshWindow();
SetVisibleCore(true);
textBox2.Focus();
CheckForUpdates();
}
private void Cache_Check()
{
//try
{
using (Stream stream2 = WebRequest.Create($"{baseLink}downloads/EmotesEverywhere/cache").GetResponse().GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream2))
{
string cached = reader.ReadToEnd();
if (cached != (string)Properties.Settings.Default["Cache"])
{
Properties.Settings.Default["Cache"] = cached;
Properties.Settings.Default.Save();
Temp_Clean();
}
}
}
}
//catch
//{
// Temp_Clean();
//}
}
// AppData
public void Temp_Clean()
{
Directory.CreateDirectory(temp_path);
DirectoryInfo di = new DirectoryInfo(temp_path);
bool empty = true;
foreach (FileInfo file in di.GetFiles())
{
empty = false;
break;
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
empty = false;
break;
}
if (!empty)
{
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
}
}
// Window Overrites
public override void ColorProfiles()
{
BackColor = (Color)Properties.Settings.Default["Color_BG"];
for (int ix = Controls.Count - 1; ix >= 0; ix--)
{
if (Controls[ix] is Button)
{
Controls[ix].BackColor = (Color)Properties.Settings.Default["Button_BG"];
Controls[ix].ForeColor = (Color)Properties.Settings.Default["Color_FG"];
}
else if (Controls[ix] is LinkLabel)
{
((LinkLabel)Controls[ix]).LinkColor = (Color)Properties.Settings.Default["Color_Link"];
((LinkLabel)Controls[ix]).ActiveLinkColor = (Color)Properties.Settings.Default["Color_Link"];
((LinkLabel)Controls[ix]).VisitedLinkColor = (Color)Properties.Settings.Default["Color_VLink"];
}
else if (Controls[ix] is Label)
{
Controls[ix].ForeColor = (Color)Properties.Settings.Default["Color_FG"];
}
else if (Controls[ix] is TextBox)
{
Controls[ix].ForeColor = (Color)Properties.Settings.Default["Color_NonText"];
Controls[ix].BackColor = (Color)Properties.Settings.Default["TextBox_BG"];
}
}
textBox2.ForeColor = (Color)Properties.Settings.Default["Color_FG"];
label5.BackColor = (Color)Properties.Settings.Default["Button_BG"];
pictureBox2.BackColor = (Color)Properties.Settings.Default["Button_BG"];
button14.ForeColor = (Color)Properties.Settings.Default["Copy"];
ToolTip1.BackColor = (Color)Properties.Settings.Default["Button_BG"];
Option_Button_BG();
Invalidate();
}
public override void SettingsRefresh()
{
base.SettingsRefresh();
int temp_paging = (int)Properties.Settings.Default["Paging"];
if (paging_multiplier != temp_paging)
{
paging_multiplier = temp_paging;
paging = division * paging_multiplier;
NewSearch();
FlowFavorite();
}
}
// First Get
public void ImageFirstGetting()
{
emoteString = new List<string>();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(emotesLink);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string html = reader.ReadToEnd();
Regex regex = new Regex(GetDirectoryListingRegexForUrl(emotesLink));
matches = regex.Matches(html);
}
}
}
public string GetDirectoryListingRegexForUrl(string url)
{
if (url.Equals(emotesLink))
{
//return "alt=\"\\[IMG\\]\"></td><td><a href=\".*\">(?<name>.*?)</a>";
return "<a href=\"(?<name>.*?)\">.*</a>";
}
throw new NotSupportedException();
}
// Search
public async void NewSearch()
{
try
{
processStop = true;
await semaphore.WaitAsync();
processStop = false;
textBox2.Text = textBox2.Text.Trim(' ');
if (textBox2.Text == searchEmotes || textBox2.Text.Length < 1)
{
label1.ForeColor = (Color)Properties.Settings.Default["Color_FG"];
label1.Text = firstLabel;
await ImageFilter();
}
else
{
label1.ForeColor = (Color)Properties.Settings.Default["Color_FG"];
label1.Text = $"Searching for {textBox2.Text.ToLower()} ...";
await ImageFilter(textBox2.Text.ToLower());
}
semaphore.Release();
}
catch (Exception ex) { SendErrorMessage("1 " + ex.ToString()); }
}
public async Task ImageFilter(string keyword = "")
{
if (processStop) return;
flowPanel.Dispose();
flowPanel = new FlowLayoutPanel
{
Size = new Size(562, 272),
Location = new Point(14, 126),
AutoScroll = true,
};
Controls.Add(flowPanel);
FlowFavorite();
integer = 0;
emoteString = new List<string>();
pictureList = new List<PictureBox>();
if (processStop) return;
ImageGetting(keyword);
label2.Text = $"{emoteString.Count} Search Results";
label3.Text = $"{page + 1} / {emoteString.Count / paging + 1}";
int emotesOnPage = Math.Min(paging, emoteString.Count - page * paging);
for (int x = 0; x < emotesOnPage; x++)
{
if (processStop) break;
await Task.Run(() => ImageLoading(x));
if (processStop) break;
flowPanel.Controls.Add(pictureList[x]);
label4.Text = $"{integer} / {emotesOnPage} Loaded";
}
label4.Text = $"{integer} / {emotesOnPage} Loaded";
}
public void ImageLoading(int y)
{
PictureBox picture = new PictureBox()
{
Name = emoteString[y + page * paging],
TabStop = false,
Size = new Size(48, 48),
Image = GetImage(emoteString[y + page * paging]),
};
picture.SizeMode = PictureBoxSizeMode.Zoom;
picture.Click += buttonGenerated_Click;
picture.MouseMove += buttonGenerated_MouseMove;
ToolTip1.SetToolTip(picture, picture.Name.Substring(0, picture.Name.Length - 4));
pictureList.Add(picture);
integer++;
}
public Image GetImage(string filename, string prefix = "")
{
string path = Path.Combine(temp_path, prefix + filename);
try
{
if (!File.Exists(path))
{
DownloadImage(filename, path);
}
return Image.FromFile(path);
}
catch
{
DownloadImage(filename, path);
return Image.FromFile(path);
}
}
public Image DownloadImage(string filename, string path)
{
using (Stream stream2 = WebRequest.Create($"{emotesLink}{filename}").GetResponse().GetResponseStream())
using (FileStream fs = File.Create(path))
{
stream2.CopyTo(fs);
}
return Image.FromFile(path);
}
public void ImageGetting(string keyword)
{
if (matches.Count > 0)
{
string temp;
for (int i = 1; i < matches.Count; i++)
{
if (matches[i].Success)
{
temp = matches[i].Groups["name"].ToString();
if (temp.Substring(0, temp.Length - 4) == keyword && !merge)
{
Execution(temp);
}
if (temp.Contains(keyword))
{
emoteString.Add(temp);
}
}
}
}
}
public void Execution(string emoteToSearch)
{
pictureBox1.Image = GetImage(emoteToSearch);
pictureBox1.Name = emoteToSearch;
textBox2.Focus();
GetFocused();
}
public void GetFocused()
{
try
{
if (pictureBox1.Name.ToLower() == "picturebox1")
{
label1.ForeColor = (Color)Properties.Settings.Default["Color_FG"];
switch (Properties.Settings.Default["Option"])
{
case 1:
label1.Text = "Now click on emotes to copy them as RGB.";
break;
case 2:
label1.Text = "Now click on emotes to copy them as Device independent Bitmap.";
break;
case 3:
label1.Text = "Now click on emotes to copy them as Links.";
break;
case 4:
label1.Text = "Now click on emotes to copy them as Files.";
break;
default:
break;
}
}
else
{
string labelText = $"{pictureBox1.Name} - Copied to clipboard";
switch (Properties.Settings.Default["Option"])
{
case 1:
Bitmap blank = new Bitmap(Convert.ToInt32(pictureBox1.Image.Width), Convert.ToInt32(pictureBox1.Image.Height));
Graphics g = Graphics.FromImage(blank);
g.Clear(Color.FromArgb(54, 57, 63));
g.DrawImage(pictureBox1.Image, 0, 0, Convert.ToInt32(pictureBox1.Image.Width), Convert.ToInt32(pictureBox1.Image.Height));
Bitmap tempImage = new Bitmap(blank);
blank.Dispose();
Clipboard.SetImage(new Bitmap(tempImage));
tempImage.Dispose();
labelText = $"{pictureBox1.Name} - Copied to clipboard as RGB!";
break;
case 2:
new Option2().Start(new Bitmap(pictureBox1.Image));
labelText = $"{pictureBox1.Name} - Copied to clipboard as DiB!";
break;
case 3:
if (!merge)
{
Clipboard.SetText($"{emotesLink}{pictureBox1.Name}");
labelText = $"{pictureBox1.Name} - Copied to clipboard as link!";
}
else
{
labelText = "You can't copy the link of a merged image.";
}
break;
case 4:
//string prefix = "t_";
//GetImage(pictureBox1.Name, prefix);
//Clipboard.SetData(DataFormats.FileDrop, new string[] { Path.Combine(temp_path, prefix + pictureBox1.Name) });
Clipboard.SetData(DataFormats.FileDrop, new string[] { Path.Combine(temp_path, pictureBox1.Name) });
labelText = $"{pictureBox1.Name} - Copied to clipboard as file!";
break;
default:
break;
}
label1.ForeColor = (Color)Properties.Settings.Default["Copy"];
label1.Text = labelText;
}
}
catch (Exception ex) { SendErrorMessage("3 " + ex.ToString()); }
}
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
if (textBox2.Text.Length != search_length)
{
search_length = textBox2.Text.Length;
page = 0;
NewSearch();
}
}
// Generated Events
private void buttonGenerated_MouseMove(object sender, MouseEventArgs e)
{
if ((sender as PictureBox).Name.ToLower() == "picturebox1") return;
try
{
string filename = (sender as PictureBox).Name;
if (e.Button == MouseButtons.Right)
{
label1.ForeColor = (Color)Properties.Settings.Default["Copy"];
label1.Text = $"{filename} - Drag and Drop!";
if (filename != "generated.png")
{
pictureBox1.Image = GetImage(filename);
}
pictureBox1.Name = filename;
string path = Path.Combine(temp_path, filename);
string[] paths = new[] { path };
DoDragDrop(new DataObject(DataFormats.FileDrop, paths), DragDropEffects.Copy);
}
}
catch (Exception ex) { SendErrorMessage("4 " + ex.ToString()); }
}
private void FlowFavorite()
{
System.Collections.Specialized.StringCollection favorites = (System.Collections.Specialized.StringCollection)Properties.Settings.Default["Favorite"];
if (favorites == null) favorites = new System.Collections.Specialized.StringCollection();
if (favorites.Count < 1)
{
flowPanelFav.Size = new Size(562, 0);
flowPanel.Size = new Size(562, 272);
}
else
{
flowPanel.Size = new Size(562, 216);
flowPanelFav.Dispose();
flowPanelFav = new FlowLayoutPanel
{
Size = new Size(562, 54),
Location = new Point(14, 344),
AutoScroll = true,
};
Controls.Add(flowPanelFav);
foreach (string favorite in favorites)
{
PictureBox picture = new PictureBox()
{
Name = favorite,
TabStop = false,
Size = new Size(48, 48),
Image = GetImage(favorite, "f_"),
};
picture.SizeMode = PictureBoxSizeMode.Zoom;
picture.Click += buttonGenerated_Click;
picture.MouseMove += buttonGenerated_MouseMove;
flowPanelFav.Controls.Add(picture);
}
}
}
private void buttonGenerated_Click(object sender, EventArgs e)
{
if ((sender as PictureBox).Name.ToLower() == "picturebox1") return;
try
{
string filename = (sender as PictureBox).Name;
if (ModifierKeys == Keys.Shift)
{
System.Collections.Specialized.StringCollection favorites = (System.Collections.Specialized.StringCollection)Properties.Settings.Default["Favorite"];
if (favorites == null) favorites = new System.Collections.Specialized.StringCollection();
if (favorites.Contains(filename))
{
favorites.Remove(filename);
Properties.Settings.Default["Favorite"] = favorites;
Properties.Settings.Default.Save();
label1.ForeColor = (Color)Properties.Settings.Default["Copy"];
label1.Text = $"{filename} - Removed from Favorites! - {favorites.Count}/20";
}
else if (favorites.Count < 20)
{
favorites.Add(filename);
Properties.Settings.Default["Favorite"] = favorites;
Properties.Settings.Default.Save();
label1.ForeColor = (Color)Properties.Settings.Default["Copy"];
label1.Text = $"{filename} - Added to Favorites! - {favorites.Count}/20";
}
else
{
label1.ForeColor = (Color)Properties.Settings.Default["Error"];
label1.Text = $"{filename} - Favorites Full - {favorites.Count}/20";
}
FlowFavorite();
}
else if (!merge || pictureBox1.Name.ToLower() == "picturebox1")
{
Execution(filename);
}
else if (merge)
{
Merge(filename);
}
}
catch (Exception ex) { SendErrorMessage("5 " + ex.ToString()); }
}
// Options
private void button2_Click(object sender, EventArgs e)
{
Properties.Settings.Default["Option"] = 1;
Properties.Settings.Default.Save();
Option_Button_BG();
GetFocused();
}
private void button3_Click(object sender, EventArgs e)
{
Properties.Settings.Default["Option"] = 2;
Properties.Settings.Default.Save();
Option_Button_BG();
GetFocused();
}
private void button4_Click(object sender, EventArgs e)
{
Properties.Settings.Default["Option"] = 3;
Properties.Settings.Default.Save();
Option_Button_BG();
GetFocused();
}
private void button10_Click(object sender, EventArgs e)
{
Properties.Settings.Default["Option"] = 4;
Properties.Settings.Default.Save();
Option_Button_BG();
GetFocused();
}
private void Option_Button_BG()
{
int option = (int)Properties.Settings.Default["Option"];
Button[] buttons = new Button[] { button2, button3, button4, button10 };
for (int i = 0; i < buttons.Length; i++)
{
if (i == (option - 1))
{
buttons[i].BackColor = (Color)Properties.Settings.Default["Button_BG"];
}
else
{
buttons[i].BackColor = (Color)Properties.Settings.Default["Color_BG"];
}
}
}
// Links
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
VisitLink(linkLabel1, baseLink);
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
VisitLink(linkLabel2, $"{baseLink}discord");
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
VisitLink(linkLabel3, "https://github.com/Kellphy/KEE/releases/");
}
public void VisitLink(LinkLabel label, string link)
{
try
{
label.LinkVisited = true;
System.Diagnostics.Process.Start(link);
}
catch (Exception ex) { SendErrorMessage("0 " + ex.ToString()); }
}
// Pages & Reset
private void button6_Click(object sender, EventArgs e)
{
if (page > 0)
{
page--;
NewSearch();
}
}
private void button7_Click(object sender, EventArgs e)
{
if (page < emoteString.Count / paging)
{
page++;
NewSearch();
}
}
private void button8_Click(object sender, EventArgs e)
{
page = 0;
TextColor(textBox2, searchEmotes, "", (Color)Properties.Settings.Default["Color_NonText"], true);
NewSearch();
}
// Textbox Test
private void textBox2_Enter(object sender, EventArgs e)
{
TextColor(textBox2, "", searchEmotes, (Color)Properties.Settings.Default["Color_FG"]);
}
private void textBox2_Leave(object sender, EventArgs e)
{
TextColor(textBox2, searchEmotes, "", (Color)Properties.Settings.Default["Color_NonText"]);
}
public void TextColor(TextBox textBox, string text, string reqText, Color color, bool forcedReplace = false)
{
if (textBox.Text == reqText || forcedReplace)
{
textBox.ForeColor = color;
textBox.Text = text;
}
}
// Errors
public void SendErrorMessage(string error)
{
MessageBox.Show(error);
}
private void button12_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button13_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
// Info
private void button1_Click(object sender, EventArgs e)
{
new Form2().Start();
}
// Profiles
private void button5_Click(object sender, EventArgs e)
{
Form3 Frm = new Form3();
Frm.ClosePanel += HandleCloseRequest;
Frm.Start();
}
// Settings
private void button9_Click(object sender, EventArgs e)
{
Form4 Frm = new Form4();
Frm.ClosePanel += HandleCloseRequest;
Frm.Start();
}
private void button26_Click(object sender, EventArgs e)
{
Form5 Frm = new Form5(this);
Frm.ClosePanel += HandleCloseRequest;
Frm.Start();
}
private void HandleCloseRequest(object sender, EventArgs e)
{
RefreshWindow();
}
// Save
private void button15_Click(object sender, EventArgs e)
{
SaveFocused(true);
}
private void button11_Click(object sender, EventArgs e)
{
SaveFocused(false);
}
void SaveFocused(bool withDialog)
{
label1.Text = "Click an emote to access its save option";
if (pictureBox1.Name.ToLower() != "picturebox1")
{
label1.Text = "Quick Saving";
if (((string)Properties.Settings.Default["Quick_Save"]).Length < 1 || withDialog)
{
using (SaveFileDialog dialog = new SaveFileDialog())
{
dialog.Filter = "All files (*.*)|*.*";
dialog.FilterIndex = 1;
dialog.RestoreDirectory = true;
dialog.FileName = pictureBox1.Name;
dialog.Title = pictureBox1.Name;
if (dialog.ShowDialog() == DialogResult.OK)
{
if (!File.Exists(dialog.FileName))
{
pictureBox1.Image.Save(dialog.FileName);
}
label1.ForeColor = (Color)Properties.Settings.Default["Copy"];
string quick = withDialog ? string.Empty : "Quick ";
label1.Text = $"{quick}Saved: " + dialog.FileName;
Properties.Settings.Default["Quick_Save"] = Path.GetDirectoryName(dialog.FileName);
Properties.Settings.Default.Save();
}
}
}
else
{
string fullpath = Path.Combine((string)Properties.Settings.Default["Quick_Save"], pictureBox1.Name);
label1.Text = "Quick Saved: " + fullpath;
if (!File.Exists(fullpath))
{
pictureBox1.Image.Save(fullpath);
}
}
}
}
//Update
void CheckForUpdates()
{
string name = "EmotesEverywhere";
string webfolder = $"{baseLink}downloads/{name}";
using (Stream stream2 = WebRequest.Create($"{webfolder}/version").GetResponse().GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream2))
{
string toVer = reader.ReadToEnd();
if (toVer.Length > 0 && toVer != linkLabel3.Text)
{
button14.Visible = true;
button14.Text = $"Update to {toVer}";
}
}
}
}
private void button14_Click(object sender, EventArgs e)
{
try
{
System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
{
MessageBox.Show("Please run Emotes Everywhere as an Administrator!");
Process.Start("explorer.exe", $"{Environment.CurrentDirectory}");
}
else
{
string name = "Updater.exe";
string updaterPath = Path.Combine(Environment.CurrentDirectory, $"{name}");
using (WebClient webClient = new WebClient())
{
webClient.DownloadFile($"{baseLink}downloads/EmotesEverywhere/{name}", updaterPath);
}
Process.Start(updaterPath);
}
Application.Exit();
}
catch (Exception ex) { SendErrorMessage("1 " + ex.ToString()); }
}
// Borders for textbox, picturebox, flowpanel
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen pen = new Pen(new SolidBrush((Color)Properties.Settings.Default["Outline"]), 4);
e.Graphics.DrawRectangle(pen, flowPanel.Location.X, flowPanel.Location.Y, flowPanel.Width, flowPanel.Height);
e.Graphics.DrawRectangle(pen, flowPanelFav.Location.X, flowPanelFav.Location.Y, flowPanelFav.Width, flowPanelFav.Height);
e.Graphics.DrawRectangle(pen, pictureBox1.Location.X, pictureBox1.Location.Y, pictureBox1.Width, pictureBox1.Height);
e.Graphics.DrawRectangle(pen, textBox2.Location.X, textBox2.Location.Y, textBox2.Width, textBox2.Height);
}
void Image_Edit(int option)
{
if (pictureBox1.Name.ToLower() != "picturebox1")
{
SixLabors.ImageSharp.Image baseImage = SixLabors.ImageSharp.Image.Load(Path.Combine(temp_path, pictureBox1.Name));
SixLabors.ImageSharp.Image newImage = baseImage.Clone(ipc =>
{
switch (option)
{
case 1:
ipc.Grayscale();
break;
case 2:
ipc.Brightness(0.9f);
break;
case 3:
ipc.Brightness(1.1f);
break;
case 4:
ipc.Contrast(1.1f);
//ipc.ColorBlindness(ColorBlindnessMode.Achromatomaly);
//ipc.ColorBlindness(ColorBlindnessMode.Achromatopsia);
//ipc.ColorBlindness(ColorBlindnessMode.Deuteranomaly);
//ipc.ColorBlindness(ColorBlindnessMode.Deuteranopia);
//ipc.ColorBlindness(ColorBlindnessMode.Protanomaly);
//ipc.ColorBlindness(ColorBlindnessMode.Protanopia);
//ipc.ColorBlindness(ColorBlindnessMode.Tritanomaly);
//ipc.ColorBlindness(ColorBlindnessMode.Tritanopia);
break;
case 5:
ipc.Contrast(0.9f);
break;
case 6:
ipc.Flip(FlipMode.Horizontal);
break;
case 7:
ipc.Flip(FlipMode.Vertical);
break;
case 8:
ipc.GaussianSharpen();
break;
case 9:
ipc.EntropyCrop();
break;
case 10:
ipc.Dither();
break;
case 11:
ipc.AdaptiveThreshold();
break;
}
});
using (MemoryStream memoryStream = new MemoryStream())
{
SixLabors.ImageSharp.Formats.IImageEncoder imageEncoder = newImage.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance);
newImage.Save(memoryStream, imageEncoder);
(new Bitmap(memoryStream)).Save(Path.Combine(temp_path, "generated.png"));
Merge_Execution(new Bitmap(memoryStream));
}
}
}
void Merge(string addImageName)
{
SixLabors.ImageSharp.Image baseImage = SixLabors.ImageSharp.Image.Load(Path.Combine(temp_path, pictureBox1.Name));
SixLabors.ImageSharp.Image addImage = SixLabors.ImageSharp.Image.Load(Path.Combine(temp_path, addImageName));
SixLabors.ImageSharp.Point toRight = new SixLabors.ImageSharp.Point(x: baseImage.Width, y: 0);
SixLabors.ImageSharp.Point topLeft = new SixLabors.ImageSharp.Point(x: 0, y: 0);
SixLabors.ImageSharp.Image newImage = new SixLabors.ImageSharp.Image<Rgba32>(baseImage.Width + addImage.Width, baseImage.Height);
newImage = newImage.Clone(ipc =>
{
ipc.DrawImage(baseImage, topLeft, 1);
ipc.DrawImage(addImage, toRight, 1);
});
using (MemoryStream memoryStream = new MemoryStream())
{
SixLabors.ImageSharp.Formats.IImageEncoder imageEncoder = newImage.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance);
newImage.Save(memoryStream, imageEncoder);
(new Bitmap(memoryStream)).Save(Path.Combine(temp_path, "generated.png"));
Merge_Execution(new Bitmap(memoryStream));
}
}
public void Merge_Execution(Bitmap bmp)
{
pictureBox1.Image = bmp;
pictureBox1.Name = "generated.png";
textBox2.Focus();
GetFocused();
}
public string PictureBoxName
{
get { return pictureBox1.Name; }
}
public bool MergeOnOff
{
get { return merge; }
set { merge = value; }
}
private void toolTip_Settings()
{
ToolTip1.ShowAlways = true;
ToolTip1.AutomaticDelay = 0;
ToolTip1.AutoPopDelay = 0;
ToolTip1.OwnerDraw = true;
ToolTip1.InitialDelay = 0;
ToolTip1.ReshowDelay = 0;
ToolTip1.UseFading = true;
ToolTip1.UseAnimation = false;
ToolTip1.Draw += toolTip_Draw;
ToolTip1.Popup += toolTip_Popup;
}
private void toolTip_Draw(object sender, DrawToolTipEventArgs e)
{
e.DrawBackground();
//e.DrawBorder();
//e.Graphics.DrawLines(new Pen(new SolidBrush((Color)Properties.Settings.Default["Outline"]), 4), new Point[] {
// new Point (0, e.Bounds.Height - 1),
// new Point (0, 0),
// new Point (e.Bounds.Width - 1, 0)
// });
//e.Graphics.DrawLines(new Pen(new SolidBrush((Color)Properties.Settings.Default["Outline"]), 3), new Point[] {
// new Point (0, e.Bounds.Height - 1),
// new Point (e.Bounds.Width - 1, e.Bounds.Height - 1),
// new Point (e.Bounds.Width - 1, 0)
// });
//e.DrawText();
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
sf.FormatFlags = StringFormatFlags.NoWrap;
using (Font f = new Font("Segoe", 10f, FontStyle.Bold))
{
e.Graphics.DrawString(e.ToolTipText, f,
new SolidBrush((Color)Properties.Settings.Default["Color_FG"]), e.Bounds, sf);
}
}
}
private void toolTip_Popup(object sender, PopupEventArgs e)
{
using (Font f = new Font("Segoe", 10f, FontStyle.Bold))
{
e.ToolTipSize = TextRenderer.MeasureText(
ToolTip1.GetToolTip(e.AssociatedControl), f) + new Size(0, 8);
}
}
}
}