-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMain.cs
612 lines (567 loc) · 29.2 KB
/
frmMain.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
using DiscordRichPresence.constructors;
using DiscordRichPresence.enums;
using DiscordRichPresence.modules;
using Microsoft.Win32;
using NLog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DiscordRichPresence
{
public partial class frmMain : Form
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private bool insertMode = false;
private bool updateMode = false;
private bool autoMinimize = false;
private bool keyChanged = false;
public frmMain(bool minimize)
{
InitializeComponent();
autoMinimize = minimize;
}
private void frmMain_Load(object sender, EventArgs e)
{
logger.Info("Initialize Form frmMain");
//initialize combo box for the activity type selections
InitializeActivityTypes();
//Initialize help provider
InitializeHelpProvider();
//Fetch all existing Profiles
fetchAllProfiles();
}
private void frmMain_Shown(object sender, EventArgs e)
{
//Minimize application to system tray if the startup parameter was used
if (autoMinimize)
{
btnMinimize_Click(sender, e);
}
else
{
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
}
AppConf appConf = modUtil.GetAppConf();
if (appConf.AutoStartWebservice)
{
btnStart_Click(sender, e);
}
}
private void fetchAllProfiles()
{
cbxProfiles.Items.Clear();
var profiles = modSQL.FetchAllProfiles();
if (profiles != null && profiles.Count > 0)
{
cbxProfiles.Enabled = true;
profiles.ForEach(profile => cbxProfiles.Items.Add(profile));
}
else if (profiles == null)
{
cbxProfiles.Enabled = false;
modUtil.throwError("Profiles couldn't be obtained");
}
else
{
cbxProfiles.Enabled = false;
}
FillOptionsGroupBox(null);
btnDelete.Enabled = false;
btnUpdate.Enabled = false;
btnCopy.Enabled = false;
cbxProfiles.Focus();
}
private void InitializeActivityTypes()
{
foreach(ActivityType activityType in Enum.GetValues(typeof(ActivityType))){
IActivityType activity = new IActivityType(activityType);
cbxTypes.Items.Add(activity);
}
}
private void InitializeHelpProvider()
{
hlpProvider.SetShowHelp(cbxProfiles, true);
hlpProvider.SetShowHelp(btnAdd, true);
hlpProvider.SetShowHelp(btnUpdate, true);
hlpProvider.SetShowHelp(btnDelete, true);
hlpProvider.SetShowHelp(btnMinimize, true);
hlpProvider.SetShowHelp(btnOptions, true);
hlpProvider.SetShowHelp(btnStart, true);
hlpProvider.SetShowHelp(btnEnd, true);
hlpProvider.SetShowHelp(tbxProfileName, true);
hlpProvider.SetShowHelp(tbxSourceUrl, true);
hlpProvider.SetShowHelp(tbxTargetUrl, true);
hlpProvider.SetShowHelp(cbxTypes, true);
hlpProvider.SetShowHelp(tbxName, true);
hlpProvider.SetShowHelp(tbxState, true);
hlpProvider.SetShowHelp(chkTargetState, true);
hlpProvider.SetShowHelp(tbxDetails, true);
hlpProvider.SetShowHelp(chkTargetDetails, true);
hlpProvider.SetShowHelp(tbxLargeImage, true);
hlpProvider.SetShowHelp(chkTargetLargeImage, true);
hlpProvider.SetShowHelp(tbxLargeText, true);
hlpProvider.SetShowHelp(chkTargetLargeText, true);
hlpProvider.SetShowHelp(tbxSmallImage, true);
hlpProvider.SetShowHelp(chkTargetSmallImage, true);
hlpProvider.SetShowHelp(tbxSmallText, true);
hlpProvider.SetShowHelp(chkTargetSmallText, true);
hlpProvider.SetShowHelp(chkAudible, true);
hlpProvider.SetShowHelp(chkReload, true);
hlpProvider.SetShowHelp(btnSave, true);
hlpProvider.SetShowHelp(btnCancel, true);
hlpProvider.SetShowHelp(tbxPort, true);
hlpProvider.SetShowHelp(btnTest, true);
hlpProvider.SetShowHelp(tbxKey, true);
hlpProvider.SetShowHelp(btnCopy, true);
hlpProvider.SetShowHelp(btnAlbums, true);
hlpProvider.SetHelpString(cbxProfiles, "Select a registered profile to view the details or to enable additional buttons to either update or remove the selected profile.");
hlpProvider.SetHelpString(btnAdd, "Activate all components inside the Options group box for the creation of a new profile.");
hlpProvider.SetHelpString(btnUpdate, "Activate all components inside the Options group box to update a selected profile.");
hlpProvider.SetHelpString(btnDelete, "Delete a selected profile. Before the deletion, a message prompt appears to confirm the choice.");
hlpProvider.SetHelpString(btnMinimize, "Minimize application to the system tray.");
hlpProvider.SetHelpString(btnOptions, "Open the options page.");
hlpProvider.SetHelpString(btnStart, "Initialize the internal rest server to receive events from the browser extension.");
hlpProvider.SetHelpString(btnEnd, "Terminate the rest api webserver and stop from receiving events.");
hlpProvider.SetHelpString(tbxProfileName, "Required field which has to contain the name of the profile that has to be created or updated.");
hlpProvider.SetHelpString(tbxSourceUrl, "Required field which has to contain the url of the website where events have to be collected.\nThe format of the url has to contain the full domain name, while sub domains can be written directly or combined with a regex requests.\n\nExamples of valid urls:\n\n- https://google.com\n- https://discord.com/developers/docs\n- https://discord.com/{::regex:^.*$::}");
hlpProvider.SetHelpString(tbxTargetUrl, "Optional field which has to contain the url of the website where the source url is redirected to.\nThe format of the url has to contain the full domain name, while sub domains can be written directly or combined with a regex requests.\n\nExamples of valid urls:\n\n- https://google.com\n- https://discord.com/developers/docs\n- https://discord.com/{::regex:^.*$::}");
hlpProvider.SetHelpString(cbxTypes, "Combo box for the type of activity. The activity types are to be combined with the Name field.\n\n- Playing: 'Playing {name}'\n- Streaming: 'Streaming {name}'\n- Listening: 'Listening to {name}'\n- Watching: 'Watching {name}'\n- Custom: '{name}'\n- Competing: 'Competing in {name}'\n\nNote: Streaming is only supported with Twitch and YouTube.");
hlpProvider.SetHelpString(tbxName, "Required field which works together with the activity types combo box for the status display on Discord. For example 'Playing {name}'.");
hlpProvider.SetHelpString(tbxState, "Optional field that will fill the state spot for the activity display on Discord. Content of this field can be combined with various expressions.\n\n- Url: '{::url::}' or '{::url:{::regex:[\\d]*$::}::}'\n- HTML Location: '{::location:<div id=\"xyz\">::}', '{::location:<table id=\"xyz\">down<tbody>down<td [1]>down<tr>::{::regex:[\\d]{1,}::}', '{::location:<img class=\"xyz\">:src::}' or '{::location:<a id=\"episode\">:href:{::regex:[\\d]{1,}::}::}'\n- HTML Click Location: Same as HTML location only with '{::click:<content>::}'");
hlpProvider.SetHelpString(chkTargetState, "When selected, values will be taken from the target website. Else, it will be taken from the source website.");
hlpProvider.SetHelpString(tbxDetails, "Optional field that will fill the details spot for the activity display on Discord. Content of this field can be combined with various expressions.\n\n- Url: '{::url::}' or '{::url:{::regex:[\\d]*$::}::}'\n- HTML Location: '{::location:<div id=\"xyz\">::}', '{::location:<table id=\"xyz\">down<tbody>down<td [1]>down<tr>::{::regex:[\\d]{1,}::}', '{::location:<img class=\"xyz\">:src::}' or '{::location:<a id=\"episode\">:href:{::regex:[\\d]{1,}::}::}'\n- HTML Click Location: Same as HTML location only with '{::click:<content>::}'");
hlpProvider.SetHelpString(chkTargetDetails, "When selected, values will be taken from the target website. Else, it will be taken from the source website.");
hlpProvider.SetHelpString(tbxLargeImage, "Optional field that will fill the large image spot for the activity display on Discord. Content of this field can be combined with various expressions.\n\n- HTML Location: '{::location:<div id=\"xyz\">::}', '{::location:<table id=\"xyz\">down<tbody>down<td [1]>down<tr>::{::regex:[\\d]{1,}::}', '{::location:<img class=\"xyz\">:src::}' or '{::location:<a id=\"episode\">:href:{::regex:[\\d]{1,}::}::}'\n- HTML Click Location: Same as HTML location only with '{::click:<content>::}'\n- Favicon: '{::favicon::}'\n- Random Album image: '{::album:<album_id>::}'\n- Specific image from album: '{::album:<album_id>:<image_id>::}'\n- Image based on resolved key: '{::album:<album_id>:keybind::}'");
hlpProvider.SetHelpString(chkTargetLargeImage, "When selected, values will be taken from the target website. Else, it will be taken from the source website.");
hlpProvider.SetHelpString(tbxLargeText, "Optional field that will fill the large text spot for the activity display on Discord. Content of this field can be combined with various expressions.\n\n- Url: '{::url::}' or '{::url:{::regex:[\\d]*$::}::}'\n- HTML Location: '{::location:<div id=\"xyz\">::}', '{::location:<table id=\"xyz\">down<tbody>down<td [1]>down<tr>::{::regex:[\\d]{1,}::}', '{::location:<img class=\"xyz\">:src::}' or '{::location:<a id=\"episode\">:href:{::regex:[\\d]{1,}::}::}'\n- HTML Click Location: Same as HTML location only with '{::click:<content>::}'");
hlpProvider.SetHelpString(chkTargetLargeText, "When selected, values will be taken from the target website. Else, it will be taken from the source website.");
hlpProvider.SetHelpString(tbxSmallImage, "Optional field that will fill the small image spot for the activity display on Discord. Content of this field can be combined with various expressions.\n\n- HTML Location: '{::location:<div id=\"xyz\">::}', '{::location:<table id=\"xyz\">down<tbody>down<td [1]>down<tr>::{::regex:[\\d]{1,}::}', '{::location:<img class=\"xyz\">:src::}' or '{::location:<a id=\"episode\">:href:{::regex:[\\d]{1,}::}::}'\n- HTML Click Location: Same as HTML location only with '{::click:<content>::}'\n- Favicon: '{::favicon::}'\n- Random Album image: '{::album:<album_id>::}'\n- Specific image from album: '{::album:<album_id>:<image_id>::}'\n- Image based on resolved key: '{::album:<album_id>:keybind::}'");
hlpProvider.SetHelpString(chkTargetSmallImage, "When selected, values will be taken from the target website. Else, it will be taken from the source website.");
hlpProvider.SetHelpString(tbxSmallText, "Optional field that will fill the small text spot for the activity display on Discord. Content of this field can be combined with various expressions.\n\n- Url: '{::url::}' or '{::url:{::regex:[\\d]*$::}::}'\n- HTML Location: '{::location:<div id=\"xyz\">::}', '{::location:<table id=\"xyz\">down<tbody>down<td [1]>down<tr>::{::regex:[\\d]{1,}::}', '{::location:<img class=\"xyz\">:src::}' or '{::location:<a id=\"episode\">:href:{::regex:[\\d]{1,}::}::}'\n- HTML Click Location: Same as HTML location only with '{::click:<content>::}'");
hlpProvider.SetHelpString(chkTargetSmallText, "When selected, values will be taken from the target website. Else, it will be taken from the source website.");
hlpProvider.SetHelpString(chkAudible, "When selected, events are collected when the browser tab has an audio but works only with values to be collected from the source website. Else, values are collected when the website is visited.");
hlpProvider.SetHelpString(chkReload, "When selected, values for profiles will be recollected. A possible use case is for when a bookmark site has multiple pages.");
hlpProvider.SetHelpString(btnSave, "Save all input by either creating a new profile or by updating an existing one.");
hlpProvider.SetHelpString(btnCancel, "Undo all unsaved changes");
hlpProvider.SetHelpString(tbxPort, "Display the port that is in use from the webservice.");
hlpProvider.SetHelpString(btnTest, "Experiment with the displayed fields to display the activity on Discord.");
hlpProvider.SetHelpString(tbxKey, "For cases when the target site is visited directly without the source page, it will be possible to automatically autofill values obtained from the source page. Automatically saved are values that have to be obtained from the source page. Content of this field can be combined with various expressions.\n\n- Url: '{::url::}' or '{::url:{::regex:[\\d]*$::}::}'\n- HTML Location: '{::location:<div id=\"xyz\">::}', '{::location:<table id=\"xyz\">down<tbody>down<td [1]>down<tr>::{::regex:[\\d]{1,}::}', '{::location:<img class=\"xyz\">:src::}' or '{::location:<a id=\"episode\">:href:{::regex:[\\d]{1,}::}::}'");
hlpProvider.SetHelpString(btnCopy, "Copy an existing profile for the creation of a new profile.");
hlpProvider.SetHelpString(btnAlbums, "Manage albums and images on Imgur.");
}
private void cbxProfiles_SelectionChangeCommitted(object sender, EventArgs e)
{
logger.Debug("SelectionChangeCommitted event thrown for field cbxProfiles");
ComboBox item = sender as ComboBox;
if(item != null)
{
Profile profile = item.SelectedItem as Profile;
FillOptionsGroupBox(profile);
if(profile != null)
{
btnDelete.Enabled = true;
btnUpdate.Enabled = true;
btnCopy.Enabled = true;
}
else
{
btnDelete.Enabled = false;
btnUpdate.Enabled = false;
btnCopy.Enabled = false;
}
}
else
{
FillOptionsGroupBox(null);
btnDelete.Enabled = false;
btnUpdate.Enabled = false;
btnCopy.Enabled = false;
}
}
private void FillOptionsGroupBox(Profile? profile)
{
string profileName = "";
string sourceDomain = "";
string targetDomain = "";
int typeIndex = 0;
string name = "";
string state = "";
bool targetState = false;
string details = "";
bool targetDetails = false;
string largeImage = "";
bool targetLargeImage = false;
string largeText = "";
bool targetLargeText = false;
string smallImage = "";
bool targetSmallImage = false;
string smallText = "";
bool targetSmallText = false;
string key = "";
bool audible = false;
bool reload = false;
if(profile != null)
{
const string source = "source;";
const string target = "target;";
int sourceLength = source.Length;
int targetLength = target.Length;
profileName = profile.ProfileName;
sourceDomain = profile.SourceUrl;
targetDomain = profile.TargetUrl;
for (int i = 0; i < cbxTypes.Items.Count; i++)
{
if (((IActivityType)cbxTypes.Items[i]).Type == profile.Type)
{
typeIndex = i;
break;
}
}
name = profile.Name;
if(profile.State.StartsWith(target))
{
state = profile.State.Substring(targetLength);
targetState = true;
}
else
{
state = profile.State.Substring(sourceLength);
}
if(profile.Details.StartsWith(target))
{
details = profile.Details.Substring(targetLength);
targetDetails = true;
}
else
{
details = profile.Details.Substring(sourceLength);
}
if (profile.LargeImage.StartsWith(target))
{
largeImage = profile.LargeImage.Substring(targetLength);
targetLargeImage = true;
}
else
{
largeImage = profile.LargeImage.Substring(sourceLength);
}
if(profile.LargeText.StartsWith(target))
{
largeText = profile.LargeText.Substring(targetLength);
targetLargeText = true;
}
else
{
largeText = profile.LargeText.Substring(sourceLength);
}
if (profile.SmallImage.StartsWith(target))
{
smallImage = profile.SmallImage.Substring(targetLength);
targetSmallImage = true;
}
else
{
smallImage = profile.SmallImage.Substring(sourceLength);
}
if (profile.SmallText.StartsWith(target))
{
smallText = profile.SmallText.Substring(targetLength);
targetSmallText = true;
}
else
{
smallText = profile.SmallText.Substring(sourceLength);
}
key = profile.Key;
audible = profile.Audible;
reload = profile.Reload;
}
tbxProfileName.Text = profileName;
tbxSourceUrl.Text = sourceDomain;
tbxTargetUrl.Text = targetDomain;
cbxTypes.SelectedIndex = typeIndex;
tbxName.Text = name;
tbxState.Text = state;
chkTargetState.Checked = targetState;
tbxDetails.Text = details;
chkTargetDetails.Checked = targetDetails;
tbxLargeImage.Text = largeImage;
chkTargetLargeImage.Checked = targetLargeImage;
tbxLargeText.Text = largeText;
chkTargetLargeText.Checked = targetLargeText;
tbxSmallImage.Text = smallImage;
chkTargetSmallImage.Checked = targetSmallImage;
tbxSmallText.Text = smallText;
chkTargetSmallText.Checked = targetSmallText;
tbxKey.Text = key;
chkAudible.Checked = audible;
chkReload.Checked = reload;
}
private void HandleFieldEnableMode()
{
bool enabled = (insertMode || updateMode);
cbxProfiles.Enabled = !enabled && cbxProfiles.Items.Count > 0;
btnAdd.Enabled = !enabled;
btnUpdate.Enabled = !enabled;
btnDelete.Enabled = !enabled;
btnMinimize.Enabled = !enabled;
btnOptions.Enabled = !enabled;
tbxProfileName.Enabled = enabled;
tbxSourceUrl.Enabled = enabled;
tbxTargetUrl.Enabled = enabled;
cbxTypes.Enabled = enabled;
tbxName.Enabled = enabled;
tbxState.Enabled = enabled;
chkTargetState.Enabled = enabled;
tbxDetails.Enabled = enabled;
chkTargetDetails.Enabled = enabled;
tbxLargeImage.Enabled = enabled;
chkTargetLargeImage.Enabled = enabled;
tbxLargeText.Enabled = enabled;
chkTargetLargeText.Enabled = enabled;
tbxSmallImage.Enabled = enabled;
chkTargetSmallImage.Enabled = enabled;
tbxSmallText.Enabled = enabled;
chkTargetSmallText.Enabled = enabled;
tbxKey.Enabled = enabled;
chkAudible.Enabled = enabled;
chkReload.Enabled = enabled;
btnSave.Enabled = enabled;
btnCancel.Enabled = enabled;
}
private void btnAdd_Click(object sender, EventArgs e)
{
insertMode = true;
cbxProfiles.SelectedIndex = -1;
FillOptionsGroupBox(null);
HandleFieldEnableMode();
tbxProfileName.Focus();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
updateMode = true;
HandleFieldEnableMode();
tbxProfileName.Focus();
}
private void btnDelete_Click(object sender, EventArgs e)
{
const string title = "Delete Profile";
const string message = "Do you really want to delete the selected profile?";
DialogResult result = MessageBox.Show(message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if(result == DialogResult.Yes)
{
int dbResult = -1;
var profile = cbxProfiles.SelectedItem as Profile;
if(profile != null)
{
dbResult = modSQL.DeleteProfile(profile.ProfileId);
}
if(dbResult > 0)
{
fetchAllProfiles();
}
else
{
modUtil.throwError("Profile couldn't be deleted");
}
}
}
private void btnSave_Click(object sender, EventArgs e)
{
const string source = "source;";
const string target = "target;";
if (keyChanged && cbxProfiles.SelectedItem != null)
{
modSQL.DeleteKeyPreset(((Profile)cbxProfiles.SelectedItem).ProfileId);
}
keyChanged = false;
Profile profile = new Profile(
(cbxProfiles.SelectedItem != null ? ((Profile)cbxProfiles.SelectedItem).ProfileId : 0),
tbxProfileName.Text,
tbxSourceUrl.Text,
tbxTargetUrl.Text,
(cbxTypes.SelectedItem != null ? ((IActivityType)cbxTypes.SelectedItem).Type : (int)ActivityType.Playing),
tbxName.Text,
(chkTargetState.Checked ? target : source)+tbxState.Text,
(chkTargetDetails.Checked ? target : source) + tbxDetails.Text,
(chkTargetLargeImage.Checked ? target : source) + tbxLargeImage.Text,
(chkTargetLargeText.Checked ? target : source) + tbxLargeText.Text,
(chkTargetSmallImage.Checked ? target : source) + tbxSmallImage.Text,
(chkTargetSmallText.Checked ? target : source) + tbxSmallText.Text,
tbxKey.Text,
chkAudible.Checked,
chkReload.Checked
);
try
{
profile.Validate();
} catch(ValidationException ex)
{
logger.Warn(ex, "Fields have failed the validation");
modUtil.throwError(ex.Message);
return;
}
if (insertMode)
{
int result = modSQL.InsertProfile(profile);
if(result > 0)
{
fetchAllProfiles();
insertMode = false;
HandleFieldEnableMode();
logger.Info("New Profile has been created");
}
else
{
modUtil.throwError("New Profile couldn't be saved. Please try again!");
}
}
else if (updateMode)
{
int result = modSQL.UpdateProfile(profile);
if(result > 0)
{
int profileId = profile.ProfileId;
fetchAllProfiles();
updateMode = false;
HandleFieldEnableMode();
for (int i = 0; i < cbxProfiles.Items.Count; i++)
{
if (((Profile)cbxProfiles.Items[i]).ProfileId == profileId)
{
cbxProfiles.SelectedIndex = i;
cbxProfiles_SelectionChangeCommitted((ComboBox)cbxProfiles, e);
break;
}
}
logger.Info("Profile with the id {0} has been updated", profileId);
}
else
{
modUtil.throwError("Existing Profile couldn't be updated. Please try again!");
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
insertMode = false;
updateMode = false;
keyChanged = false;
FillOptionsGroupBox(null);
HandleFieldEnableMode();
cbxProfiles_SelectionChangeCommitted(cbxProfiles, e);
}
private void ntfIcon_DoubleClick(object sender, EventArgs e)
{
this.ShowInTaskbar = true;
this.Show();
this.WindowState = FormWindowState.Normal;
this.Activate();
}
private void btnMinimize_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.Hide();
}
private void btnOptions_Click(object sender, EventArgs e)
{
new frmOptions().ShowDialog();
AppConf conf = modUtil.GetAppConf();
//Initialize application auto start
RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
if (regKey == null)
{
logger.Warn("Auto start path in the registry couldn't be opened");
return;
}
if (conf.AutoStart)
{
regKey.SetValue(Application.ProductName, "\"" + Application.ExecutablePath + "\" /startup");
}
else
{
regKey.DeleteValue(Application.ProductName, false);
}
regKey.Close();
}
private void tsmOpen_Click(object sender, EventArgs e)
{
ntfIcon_DoubleClick(sender, e);
}
private void tsmClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnStart_Click(object sender, EventArgs e)
{
btnTest.Enabled = false;
btnStart.Enabled = false;
tsmRunWebservice.Enabled = false;
btnEnd.Enabled = true;
tsmEndWebservice.Enabled = true;
int port = modWebservice.RunWebservice();
tbxPort.Text = port.ToString();
}
private void btnEnd_Click(object sender, EventArgs e)
{
btnTest.Enabled = true;
btnEnd.Enabled = false;
tsmEndWebservice.Enabled = false;
btnStart.Enabled = true;
tsmRunWebservice.Enabled = true;
modWebservice.StopWebservice();
tbxPort.Text = "";
}
private void btnTest_Click(object sender, EventArgs e)
{
new frmTest().ShowDialog();
}
private void tbxKey_Leave(object sender, EventArgs e)
{
keyChanged = true;
}
private void btnCopy_Click(object sender, EventArgs e)
{
Profile profile = modSQL.GetProfile(((Profile)cbxProfiles.SelectedItem).ProfileId);
if(profile != null)
{
btnAdd_Click(sender, e);
FillOptionsGroupBox(profile);
}
else
{
logger.Error("Profile couldn't be copied.");
modUtil.throwError("Profile couldn't be copied. Please try again!");
}
}
private void btnAlbums_Click(object sender, EventArgs e)
{
AppConf appConf = modUtil.GetAppConf();
Imgur imgur = appConf.Imgur;
if (imgur.ClientId.Length == 0 || imgur.ClientSecret.Length == 0 || imgur.RefreshToken.Length == 0)
{
modUtil.throwError("Imgur settings not completed in the Options page. Pleae fill all options related to Imgur and then try again.");
}
else
{
var form = Application.OpenForms.OfType<frmAlbum>();
if (!form.Any())
{
new frmAlbum().Show();
}
else
{
form.First().Focus();
}
}
}
}
}