-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmMain.cs
More file actions
641 lines (562 loc) · 23.8 KB
/
frmMain.cs
File metadata and controls
641 lines (562 loc) · 23.8 KB
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
using Newtonsoft.Json.Linq;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LineStickerDownloader
{
public partial class frmMain : Form
{
private settings iniFile;
private string savePath, urlId;
private bool isDraging = false;
private Point startPoint;
public frmMain()
{
InitializeComponent();
string iniPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.ini");
iniFile = new settings(iniPath);
}
private void Form1_Load(object sender, EventArgs e)
{
cbType.Items.Add("Common Sticker");
cbType.Items.Add("Animated Sticker");
cbType.SelectedIndex = 0;
menuStrip1.BackColor = Color.FromArgb(38, 41, 64);
cbType.Text = "Common Sticker";
savePath = iniFile.Read("Settings", "FolderPath");
#region Update Code
//================================ Remove the comments to enable auto-update =================================//
//try
//{
// string currentVersion = "1.3.2.1";
// string latestVersion = new WebClient().DownloadString("Paste Your Link Latest Version Here");
// if (latestVersion != currentVersion)
// {
// DialogResult result = MessageBox.Show($"A new update is available.\n\n Current Version : {currentVersion}\n Latest Version : {latestVersion}\n\n Do you want to update?", "Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
// if (result == DialogResult.Yes)
// {
// Process p = new Process();
// p.StartInfo.FileName = "Updater.exe";
// p.Start();
// Application.Exit();
// }
// }
//}
//catch
//{
// MessageBox.Show("Update check failed!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//}
//============================================================================================================//
#endregion
}
private void btnDownload_Click(object sender, EventArgs e)
{
pbLoading.BringToFront();
savePath = iniFile.Read("Settings", "FolderPath");
string ID = urlId;
switch (gbDownloadPanel.Text)
{
case "Sticker Download":
DownloadSticker(savePath, ID);
break;
case "Emoji Download":
DownloadEmoji(savePath, ID);
break;
}
}
#region GetIcon
//================================================ Get Icon Sticker =================================================//
//Sticker
private void LoadStickerIcon(string stickerID)
{
try
{
string url = $"https://stickershop.line-scdn.net/stickershop/v1/product/{stickerID}/LINEStorePC/main.png";
using (WebClient client = new WebClient())
{
byte[] imageData = client.DownloadData(url);
using (var ms = new System.IO.MemoryStream(imageData))
{
Image stickerImage = Image.FromStream(ms);
pbPreviewImg.Image = stickerImage;
}
}
}
catch (Exception)
{
//pbPreviewImg.Image = default;
//MessageBox.Show($"Gagal memuat stiker: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
//Emoji
private void LoadEmojiIcon(string emojiID)
{
try
{
string url = $"https://stickershop.line-scdn.net/sticonshop/v1/product/{emojiID}/iPhone/main.png";
using (WebClient client = new WebClient())
{
byte[] imageData = client.DownloadData(url);
using (var ms = new System.IO.MemoryStream(imageData))
{
Image stickerImage = Image.FromStream(ms);
pbPreviewImg.Image = stickerImage;
}
}
}
catch (Exception)
{
//pbPreviewImg.Image = default;
//MessageBox.Show($"Gagal memuat stiker: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
//===================================================================================================================//
#endregion
#region GetStickerName
//================================================ Get Sticker Name =================================================//
private async Task<string> GetHtmlContent(string url)
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}
private string ExtractJsonLd(string htmlContent)
{
string patern = @"<script type=""application/ld\+json"">(.*?)</script>";
Match match = Regex.Match(htmlContent, patern, RegexOptions.Singleline);
if (match.Success)
{
return match.Groups[1].Value;
}
return null;
}
private string GetProductName(string jsonLd)
{
JObject jsonObject = JObject.Parse(jsonLd);
return jsonObject["name"]?.ToString();
}
//===================================================================================================================//
#endregion
private void tbIDSticker_TextChanged(object sender, EventArgs e)
{
pDownload.Value = 0;
lblLog.Text = "◈ Iddle ◈ ";
GenerateUrlId();
//MessageBox.Show($"Sticker ID :{urlId}"); //Debug
if (string.IsNullOrEmpty(tbID.Text))
{
lblTitle.Text = "";
pbPreviewImg.Image = default;
}
else
{
switch (gbDownloadPanel.Text)
{
case "Sticker Download":
LoadStickerTitle();
break;
case "Emoji Download":
LoadEmojiTitle();
break;
}
}
}
#region LoadTitle
//================================================ Get Icon Sticker =================================================//
private async void LoadEmojiTitle()
{
string emojiId = urlId;
string url = $"https://store.line.me/emojishop/product/{emojiId}";
try
{
string htmlContent = await GetHtmlContent(url);
string jsonLd = ExtractJsonLd(htmlContent);
if (!string.IsNullOrEmpty(jsonLd))
{
string productName = GetProductName(jsonLd);
lblTitle.Text = productName;
}
else
{
lblTitle.Text = "Unknown";
}
}
catch (Exception)
{
lblTitle.Text = "Unknown";
}
LoadEmojiIcon(emojiId);
}
private async void LoadStickerTitle()
{
string stickerId = urlId;
string url = $"https://store.line.me/stickershop/product/{stickerId}";
try
{
string htmlContent = await GetHtmlContent(url);
string jsonLd = ExtractJsonLd(htmlContent);
if (!string.IsNullOrEmpty(jsonLd))
{
string productName = GetProductName(jsonLd);
lblTitle.Text = productName;
}
else
{
lblTitle.Text = "Unknown";
}
}
catch (Exception)
{
lblTitle.Text = "Unknown";
}
LoadStickerIcon(stickerId);
}
//===================================================================================================================//
#endregion
#region ButtonCode
//================================================== Button Code ===================================================//
private void btnEmoji_Click(object sender, EventArgs e)
{
tbID.Text = "";
gbDownloadPanel.Text = "Emoji Download";
lblID.Text = "Emoji Link :";
lblType.Text = "Emoji Type :";
cbType.Items.Clear();
cbType.Items.Add("Common Emoji");
cbType.Items.Add("Animated Emoji");
cbType.SelectedIndex = 0;
btnEmoji.Visible = false;
btnSticker.Visible = true;
}
private void btnSticker_Click(object sender, EventArgs e)
{
tbID.Text = "";
gbDownloadPanel.Text = "Sticker Download";
lblID.Text = "Sticker Link :";
lblType.Text = "Sticker Type :";
cbType.Items.Clear();
cbType.Items.Add("Common Sticker");
cbType.Items.Add("Animated Sticker");
cbType.SelectedIndex = 0;
btnEmoji.Visible = true;
btnSticker.Visible = false;
}
private void lblClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void pClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void lblClose_MouseEnter(object sender, EventArgs e)
{
pClose.BackColor = Color.Red;
}
private void lblClose_MouseLeave(object sender, EventArgs e)
{
pClose.BackColor = Color.Transparent;
}
private void pClose_MouseEnter(object sender, EventArgs e)
{
pClose.BackColor = Color.Red;
}
private void pClose_MouseLeave(object sender, EventArgs e)
{
pClose.BackColor = Color.Transparent;
}
private void lblMinimize_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void lblMinimize_MouseEnter(object sender, EventArgs e)
{
pMinimize.BackColor = Color.WhiteSmoke;
lblMinimize.ForeColor = Color.DarkGray;
}
private void lblMinimize_MouseLeave(object sender, EventArgs e)
{
pMinimize.BackColor = Color.Transparent;
lblMinimize.ForeColor = Color.White;
}
private void pMinimize_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void pMinimize_MouseEnter(object sender, EventArgs e)
{
pMinimize.BackColor = Color.WhiteSmoke;
lblMinimize.ForeColor = Color.DarkGray;
}
private void pMinimize_MouseLeave(object sender, EventArgs e)
{
pMinimize.BackColor = Color.Transparent;
lblMinimize.ForeColor = Color.White;
}
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
frmSettings setting = new frmSettings();
setting.ShowDialog();
}
private void changeLogToolStripMenuItem_Click(object sender, EventArgs e)
{
frmChangeLogs change = new frmChangeLogs();
change.ShowDialog();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
frmAbout about = new frmAbout();
about.ShowDialog();
}
private void label8_Click(object sender, EventArgs e)
{
MessageBox.Show("I give this ❤️ to you 😊", "❤️", MessageBoxButtons.OK);
}
private void lblHelp_Click(object sender, EventArgs e)
{
frmHelp help = new frmHelp();
help.ShowDialog();
}
//==================================================================================================================//
#endregion
#region DragControl
private void lblTitleApp_MouseDown(object sender, MouseEventArgs e)
{
isDraging = true;
startPoint = new Point(e.X, e.Y);
}
private void lblTitleApp_MouseMove(object sender, MouseEventArgs e)
{
if (isDraging)
{
Point currentScreenPos = PointToScreen(e.Location);
this.Location = new Point(currentScreenPos.X - startPoint.X, currentScreenPos.Y - startPoint.Y);
}
}
private void lblTitleApp_MouseUp(object sender, MouseEventArgs e)
{
isDraging = false;
}
private void pWindow_MouseDown(object sender, MouseEventArgs e)
{
isDraging = true;
startPoint = new Point(e.X, e.Y);
}
private void pWindow_MouseMove(object sender, MouseEventArgs e)
{
if (isDraging)
{
Point currentScreenPos = PointToScreen(e.Location);
this.Location = new Point(currentScreenPos.X - startPoint.X, currentScreenPos.Y - startPoint.Y);
}
}
private void pWindow_MouseUp(object sender, MouseEventArgs e)
{
isDraging = false;
}
#endregion
private void btnOpenFolder_Click(object sender, EventArgs e)
{
string folderPath = iniFile.Read("Settings", "FolderPath");
if (Directory.Exists(folderPath))
{
Process.Start("explorer.exe", folderPath);
}
else
{
MessageBox.Show("The folder path does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#region DownloadSticker Code
//================================================ Download Sticker =================================================//
public async void DownloadSticker(string savePath, string stickerID)
{
if (string.IsNullOrEmpty(tbID.Text))
{
MessageBox.Show("Enter sticker link!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
pbWetDream.BringToFront();
return;
}
try
{
pDownload.Value = 0;
lblLog.Text = "Starting download...";
string baseUrl = "https://stickershop.line-scdn.net/stickershop/v1/product/";
string urlSuffix = cbType.Text == "Common Sticker" ? "/iphone/stickers@2x.zip" : "/iphone/stickerpack@2x.zip";
string url = $"{baseUrl}{urlId}{urlSuffix}";
using (HttpClient client = new HttpClient())
{
using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
{
if (response.IsSuccessStatusCode)
{
var totalBytes = response.Content.Headers.ContentLength ?? -1L;
string filePath = Path.Combine(savePath, $"{urlId}.zip");
using (var contentStream = await response.Content.ReadAsStreamAsync())
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true))
{
var buffer = new byte[8192];
long totalRead = 0;
int bytesRead;
while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await fileStream.WriteAsync(buffer, 0, bytesRead);
totalRead += bytesRead;
if (totalBytes > 0)
{
pDownload.Value = (int)((totalRead * 100) / totalBytes);
if (totalRead < 1048576)
{
lblLog.Text = $"Downloaded {totalRead / 1024.0:F2} KB of {totalBytes / 1024.0:F2} KB...";
}
else
{
lblLog.Text = $"Downloaded {totalRead / 1048576.0:F2} MB of {totalBytes / 1048576.0:F2} MB...";
}
}
}
}
lblLog.Text = "Download completed successfully.";
string extractPath = Path.Combine(savePath, urlId);
System.IO.Compression.ZipFile.ExtractToDirectory(filePath, extractPath);
if (File.Exists(filePath))
{
File.Delete(filePath);
}
lblLog.Text = "Extract completed";
lblLog.Text = "Completed.";
MessageBox.Show("Sticker has been successfully downloaded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
pbWetDream.BringToFront();
}
else
{
lblLog.Text = "Sticker not found.";
MessageBox.Show("Sticker not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
pbWetDream.BringToFront();
}
}
}
}
catch (Exception ex)
{
lblLog.Text = $"Error: {ex.Message}";
MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
pbWetDream.BringToFront();
}
}
//===================================================================================================================//
#endregion
#region Emoji Download Code
//================================================ Download Emoji =================================================//
public async void DownloadEmoji(string savePath, string emojiID)
{
if (string.IsNullOrEmpty(tbID.Text))
{
MessageBox.Show("Enter emoji id!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
pbWetDream.BringToFront();
return;
}
try
{
pDownload.Value = 0;
lblLog.Text = "Starting download...";
string baseUrl = "https://stickershop.line-scdn.net/sticonshop/v1/sticon/";
string urlSuffix = cbType.Text == "Common Emoji" ? "/iphone/package.zip" : "/iphone/package_animation.zip";
string url = $"{baseUrl}{urlId}{urlSuffix}";
using (HttpClient client = new HttpClient())
{
using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
{
if (response.IsSuccessStatusCode)
{
var totalBytes = response.Content.Headers.ContentLength ?? -1L;
string filePath = Path.Combine(savePath, $"{urlId}.zip");
using (var contentStream = await response.Content.ReadAsStreamAsync())
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true))
{
var buffer = new byte[8192];
long totalRead = 0;
int bytesRead;
while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await fileStream.WriteAsync(buffer, 0, bytesRead);
totalRead += bytesRead;
if (totalBytes > 0)
{
pDownload.Value = (int)((totalRead * 100) / totalBytes);
if (totalRead < 1048576)
{
lblLog.Text = $"Downloaded {totalRead / 1024.0:F2} KB of {totalBytes / 1024.0:F2} KB...";
}
else
{
lblLog.Text = $"Downloaded {totalRead / 1048576.0:F2} MB of {totalBytes / 1048576.0:F2} MB...";
}
}
}
}
lblLog.Text = "Download completed successfully.";
string extractPath = Path.Combine(savePath, urlId);
System.IO.Compression.ZipFile.ExtractToDirectory(filePath, extractPath);
if (File.Exists(filePath))
{
File.Delete(filePath);
}
lblLog.Text = "Extract completed.";
lblLog.Text = "Completed.";
MessageBox.Show("Emoji has been successfully downloaded.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
pbWetDream.BringToFront();
}
else
{
lblLog.Text = "Emoji not found.";
MessageBox.Show("Emoji not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
pbWetDream.BringToFront();
}
}
}
}
catch (Exception ex)
{
lblLog.Text = $"Error: {ex.Message}";
MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
pbWetDream.BringToFront();
}
}
//===================================================================================================================//
#endregion
#region AutoComplete ID
private void GenerateUrlId()
{
string url = tbID.Text;
try
{
if(tbID.Text != null)
{
string id = url.Split('/')[5];
urlId = id;
}
else
{
urlId = null;
}
}
catch (Exception ex)
{
urlId = null;
}
}
#endregion
}
}