-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomMethods.cs
3168 lines (2932 loc) · 172 KB
/
CustomMethods.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
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using Microsoft.Win32;
using static SkinText.NativeMethods;
namespace SkinText {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
public static class CustomMethods {
private static string appDataPath;
private static int autoSaveTimer = 5 * 60 * 1000;
private static string currentSkin;
private static bool fileChanged;
private static string filepath;
private static string filepathAsociated;
private static string imagepath;
private static string screenShotPath;
private static string oldScreenShotPath;
private static bool screenshotUpload;
private static MainWindow mainW;
public static string AppDataPath { get => appDataPath; set => appDataPath = value; }
public static int AutoSaveTimer { get => autoSaveTimer; set => autoSaveTimer = value; }
public static string CurrentSkin { get => currentSkin; set => currentSkin = value; }
public static bool FileChanged { get => fileChanged; set => fileChanged = value; }
public static string Filepath { get => filepath; set => filepath = value; }
public static string FilepathAssociated { get => filepathAsociated; set => filepathAsociated = value; }
public static string GAppPath {
get {
string path = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
#if !PORTABLE
Assembly assm;
Type at;
Type at2;
object[] r;
object[] r2;
// Get the .EXE assembly
assm = Assembly.GetEntryAssembly();
// Get a 'Type' of the AssemblyCompanyAttribute
at = typeof(AssemblyCompanyAttribute);
at2 = typeof(AssemblyTitleAttribute);
// Get a collection of custom attributes from the .EXE assembly
r = assm.GetCustomAttributes(at, false);
r2 = assm.GetCustomAttributes(at2, false);
// Get the Company Attribute
AssemblyCompanyAttribute ct = ((AssemblyCompanyAttribute)(r[0]));
AssemblyTitleAttribute ct2 = ((AssemblyTitleAttribute)(r2[0]));
// Build the User App Data Path
path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
path += @"\" + ct.Company;
path += @"\" + ct2.Title;
//path += @"\Default";
//path += @"\" + assm.GetName().Name.ToString();
//path += @"\" + assm.GetName().Version.ToString();
#endif
return path;
}
}
public static string Imagepath { get => imagepath; set => imagepath = value; }
public static MainWindow MainW { get => mainW; set => mainW = value; }
public static string ScreenShotPath { get => screenShotPath; set => screenShotPath = value; }
public static string OldScreenShotPath { get => oldScreenShotPath; set => oldScreenShotPath = value; }
public static bool ScreenshotUpload { get => screenshotUpload; set => screenshotUpload = value; }
#region Bg Image
/// <summary>
/// Correct way to load an image and release it from the Hdd, also allows to unload it from memory effectively
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static ImageSource BitmapFromUri(Uri source) {
//throws System.NotSupportedException but must be catched in LoadImage
System.Windows.Media.Imaging.BitmapImage bitmap = new System.Windows.Media.Imaging.BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = source;
bitmap.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
bitmap.CreateOptions = System.Windows.Media.Imaging.BitmapCreateOptions.IgnoreImageCache;
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
/// <summary>
/// Clears, Disposes, Makes null, Unload, Frees from memory and HDD the loaded image
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.GC.Collect")]
public static void ImageClear() {
string oldpath = Imagepath;
if (!string.IsNullOrWhiteSpace(oldpath) && !oldpath.Contains("\\"))
{//if is a relative path, use current .exe path to find it
oldpath = AppDataPath + CurrentSkin + "\\" + oldpath;
}
Imagepath = "";
MainW.backgroundimg.Source = null;
WpfAnimatedGif.ImageBehavior.SetAnimatedSource(MainW.backgroundimg, null);
XamlAnimatedGif.AnimationBehavior.SetSourceUri(MainW.backgroundimg, null);
XamlAnimatedGif.AnimationBehavior.SetSourceStream(MainW.backgroundimg, null);
if (((SolidColorBrush)MainW.window.Background).Color.A == 0) {
MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#85949494");
}
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
try {
if (File.Exists(oldpath)) {
File.Delete(oldpath);
}
}
catch (Exception ex) {
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
/// <summary>
/// Will try to load <paramref name="imagepath"/> into <see cref="MainWindow.backgroundimg"/> and set <see cref="Imagepath"/> to either <paramref name="imagepath"/> or "" (<see cref="string.Empty"/>)
/// </summary>
/// <param name="imagepath"></param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public static void LoadImage(string imagepath) {
//string newImagePath = AppDataPath + CurrentSkin + @"\bgImg" + Path.GetExtension(imagepath);
string newImagePath = AppDataPath + CurrentSkin + "\\" + Path.GetFileName(imagepath);// + Path.GetExtension(imagepath);
if (!string.IsNullOrWhiteSpace(imagepath) && !imagepath.Contains("\\") )
{//if is a relative path, use current .exe path to find it
//oldimagepath should contain the skin to be able to copy it
imagepath = AppDataPath + CurrentSkin + "\\" + imagepath;
}
//MessageBox.Show("DEBUG:\r\nnewimagepath=\r\n"+newImagePath+"\r\nimagepath=\r\n"+imagepath);
try {
if (imagepath != newImagePath) {
ImageClear();//this image clear should not be called when creating a skin, but the copy below should
File.Copy(imagepath, newImagePath, true);
//imagepath = newImagePath;
//first copy the img to appdata, then load it
}
if (File.Exists(newImagePath)) {
Uri uri = new Uri(newImagePath);
if (Path.GetExtension(newImagePath).ToUpperInvariant() == ".GIF") {
if (MainW.Conf.GifMethodCPU.IsChecked.Value) {//CPU Method
XamlAnimatedGif.AnimationBehavior.SetSourceUri(MainW.backgroundimg, uri);
}
else {//RAM Method
ImageSource bitmap = BitmapFromUri(uri);
bitmap.Freeze();
WpfAnimatedGif.ImageBehavior.SetAnimatedSource(MainW.backgroundimg, bitmap);
bitmap = null;
}
}
else {//default (no gif animation)
ImageSource bitmap = BitmapFromUri(uri);
bitmap.Freeze();
MainW.backgroundimg.Source = bitmap;
bitmap = null;
}
//imagedir.Content = newImagePath.Substring(newImagePath.LastIndexOf("\\")+1);
//imagedir.ToolTip = newImagePath;
if (MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor.Value.A == 255) {
MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor = Color.Subtract(MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor.Value, Color.FromArgb(155, 0, 0, 0));
}
//MainW.WinConfig.ClrPcker_WindowBackground.SelectedColor = Colors.Transparent;
uri = null;
Imagepath = newImagePath; //set Global Imagepath
}
else {
throw new FileNotFoundException("Error: File not found", newImagePath);
}
}
catch (Exception ex) {
if (!string.IsNullOrWhiteSpace(newImagePath)) {
MessageBox.Show("Failed to Load Image:\r\n " + newImagePath, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
}
ImageClear();
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
/// <summary>
/// Calls a <see cref="OpenFileDialog"/> to select the image to load
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public static void OpenImage() {
OpenFileDialog openFileDialog = new OpenFileDialog() {
Multiselect = false,
CheckFileExists = true,
CheckPathExists = true,
ValidateNames = true,
RestoreDirectory = true,
Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png, *.gif) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png; *.gif"
};
//openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (openFileDialog.ShowDialog() == true) {
LoadImage(openFileDialog.FileName);
SaveConfig();
}
else {
ImageClear();
//imagedir.Content = par.imagepath.Substring(par.imagepath.LastIndexOf("\\") + 1); // "" when imagepath is empty
//imagedir.ToolTip = par.imagepath;
}
}
/// <summary>
/// Sets the <see cref="MainWindow.backgroundimg"/> opacity to <paramref name="opacity"/>
/// </summary>
/// <param name="opacity"></param>
public static void WindowImageOpacity(double opacity) {
MainW.backgroundimg.Opacity = opacity;
}
public static void BlurBGImage(double blurVal, bool gauss) {
System.Windows.Media.Effects.BlurEffect blur = new System.Windows.Media.Effects.BlurEffect {
Radius = blurVal
};
if (gauss) {
blur.KernelType = System.Windows.Media.Effects.KernelType.Gaussian;
}
else {
blur.KernelType = System.Windows.Media.Effects.KernelType.Box;
}
mainW.backgroundimg.Effect = blur;
}
#endregion Bg Image
#region Config File
/// <summary>
/// Loads Default Values
/// <para>Called from <see cref="MainWindow.Window_Loaded"/> and <see cref="ResetDefaults"/></para>
/// </summary>
public static void LoadDefault() {
//window size
MainW.window.Width = 525;
MainW.window.Height = 350;
//Window position
MainW.Left = (SystemParameters.PrimaryScreenWidth / 2) - (MainW.Width / 2);
MainW.Top = (SystemParameters.PrimaryScreenHeight / 2) - (MainW.Height / 2);
//Text position
System.Windows.Controls.Canvas.SetLeft(MainW.TitleBorder, 25);
System.Windows.Controls.Canvas.SetTop(MainW.TitleBorder, 25);
//Text Size
MainW.TitleBorder.Width = 475;
MainW.TitleBorder.Height = 300;
//Text border corner radius
MainW.Conf.CornerRadius1Slider.Value = 20;
MainW.Conf.CornerRadius2Slider.Value = 20;
MainW.Conf.CornerRadius3Slider.Value = 20;
MainW.Conf.CornerRadius4Slider.Value = 20;
//Text border max corner radius
MainW.Conf.CornerMax.Value = 500;
//Text border corner radius linked
MainW.Conf.lockSlidersCheckbox.IsChecked = true;
//Text border size
MainW.Conf.bordersize.Value = 5;
#region Legacy styles
/*Application.Current.Resources["BorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#997E7E7E"));
Application.Current.Resources["MainWindowBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#85949494"));
Application.Current.Resources["RTBBackgroundColor"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("Transparent"));
Application.Current.Resources["BackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#C03A3A3A"));
Application.Current.Resources["ButtonBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#602C2C2C"));
Application.Current.Resources["ButtonFrontColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("##FFE6E6E6"));
Application.Current.Resources["ButtonBackgroundMouseOverColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#85949494"));
Application.Current.Resources["ButtonBorderMouseOverColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE6E6E6"));
Application.Current.Resources["ButtonBackgroundCheckedColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#607E7E7E"));
Application.Current.Resources["ButtonBorderCheckedColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF808080"));
Application.Current.Resources["TextColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE6E6E6"));
Application.Current.Resources["FontPickBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#AA606060"));
Application.Current.Resources["FontPickTextColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE6E6E6"));
Application.Current.Resources["FontPickMouseOverBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#20FFFFFF"));
Application.Current.Resources["FontPickMouseOverBorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#90FFFFFF"));
Application.Current.Resources["FontPickSelectedBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#40FFFFFF"));
Application.Current.Resources["FontPickSelectedBorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF"));
Application.Current.Resources["MenuBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#aa535353"));
Application.Current.Resources["MenuItem1BorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("Transparent"));
Application.Current.Resources["MenuItem2HighlightTextColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("Black"));
Application.Current.Resources["MenuItem2HighlightBorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#602C2C2C"));
Application.Current.Resources["MenuItem2DisabledColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF2C2C2C"));
*/
#endregion Legacy styles
#region Legacy color reset method
/*
Application.Current.Resources["BorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF424242"));
Application.Current.Resources["MainWindowBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#55FFFFFF"));
Application.Current.Resources["RTBBackgroundColor"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#7DFFFFFF"));
Application.Current.Resources["BackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF1C1C1C"));
Application.Current.Resources["ButtonBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF262626"));
Application.Current.Resources["ButtonFrontColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE6E6E6"));
Application.Current.Resources["ButtonBackgroundMouseOverColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00B5FF"));
Application.Current.Resources["ButtonBorderMouseOverColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE6E6E6"));
Application.Current.Resources["ButtonBackgroundCheckedColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#CD000000"));
Application.Current.Resources["ButtonBorderCheckedColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF808080"));
Application.Current.Resources["TextColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF808080"));
Application.Current.Resources["FontPickBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#23696969"));
Application.Current.Resources["FontPickTextColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE6E6E6"));
Application.Current.Resources["FontPickMouseOverBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF000000"));
Application.Current.Resources["FontPickMouseOverBorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00B5FF"));
Application.Current.Resources["FontPickSelectedBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8C000000"));
Application.Current.Resources["FontPickSelectedBorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDB6929"));
Application.Current.Resources["MenuBackgroundColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#C9000000"));
Application.Current.Resources["MenuItem1BorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00FFFFFF"));
Application.Current.Resources["MenuItem2HighlightTextColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00B5FF"));
Application.Current.Resources["MenuItem2HighlightBorderColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFDB6929"));
Application.Current.Resources["MenuItem2DisabledColorBrush"] = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#73696969"));
//text bg color
//Colors:
MainW.Conf.ClrPcker_BorderColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("BorderColorBrush")).Color;
MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("MainWindowBackgroundColorBrush")).Color;
MainW.Conf.ClrPcker_RTBBackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("RTBBackgroundColorBrush")).Color;
//Advanced Colors:
MainW.Conf.ClrPcker_BackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("BackgroundColorBrush")).Color;
MainW.Conf.ClrPcker_ButtonBackgroundCheckedColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("ButtonBackgroundCheckedColorBrush")).Color;
MainW.Conf.ClrPcker_ButtonBackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("ButtonBackgroundColorBrush")).Color;
MainW.Conf.ClrPcker_ButtonBackgroundMouseOverColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("ButtonBackgroundMouseOverColorBrush")).Color;
MainW.Conf.ClrPcker_ButtonBorderMouseOverColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("ButtonBorderMouseOverColorBrush")).Color;
MainW.Conf.ClrPcker_ButtonBorderCheckedColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("ButtonBorderCheckedColorBrush")).Color;
MainW.Conf.ClrPcker_ButtonFrontColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("ButtonFrontColorBrush")).Color;
MainW.Conf.ClrPcker_FontPickBackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("FontPickBackgroundColorBrush")).Color;
MainW.Conf.ClrPcker_FontPickMouseOverBackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("FontPickMouseOverBackgroundColorBrush")).Color;
MainW.Conf.ClrPcker_FontPickMouseOverBorderColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("FontPickMouseOverBorderColorBrush")).Color;
MainW.Conf.ClrPcker_FontPickSelectedBackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("FontPickSelectedBackgroundColorBrush")).Color;
MainW.Conf.ClrPcker_FontPickSelectedBorderColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("FontPickSelectedBorderColorBrush")).Color;
MainW.Conf.ClrPcker_MenuBackgroundColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("MenuBackgroundColorBrush")).Color;
MainW.Conf.ClrPcker_MenuItem1BorderColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("MenuItem1BorderColorBrush")).Color;
MainW.Conf.ClrPcker_MenuItem2DisabledColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("MenuItem2DisabledColorBrush")).Color;
MainW.Conf.ClrPcker_MenuItem2HighlightBorderColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("MenuItem2HighlightBorderColorBrush")).Color;
MainW.Conf.ClrPcker_MenuItem2HighlightTextColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("MenuItem2HighlightTextColorBrush")).Color;
MainW.Conf.ClrPcker_TextColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("TextColorBrush")).Color;
MainW.Conf.ClrPcker_FontPickTextColorBrush.SelectedColor = ((SolidColorBrush)MainW.TryFindResource("FontPickTextColorBrush")).Color;
*/
#endregion Legacy color reset method
MainW.Conf.ClrPcker_BorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF424242");
MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#55FFFFFF");
MainW.Conf.ClrPcker_RTBBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#7DFFFFFF");
MainW.Conf.ClrPcker_BackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#CA1C1C1C");
MainW.Conf.ClrPcker_ButtonBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF262626");
MainW.Conf.ClrPcker_ButtonFrontColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FFE6E6E6");
MainW.Conf.ClrPcker_ButtonBackgroundMouseOverColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF00B5FF");
MainW.Conf.ClrPcker_ButtonBorderMouseOverColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FFE6E6E6");
MainW.Conf.ClrPcker_ButtonBackgroundCheckedColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#CD000000");
MainW.Conf.ClrPcker_ButtonBorderCheckedColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF808080");
MainW.Conf.ClrPcker_TextColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF808080");
MainW.Conf.ClrPcker_FontPickBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#23696969");
MainW.Conf.ClrPcker_FontPickTextColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FFE6E6E6");
MainW.Conf.ClrPcker_FontPickMouseOverBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF000000");
MainW.Conf.ClrPcker_FontPickMouseOverBorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF00B5FF");
MainW.Conf.ClrPcker_FontPickSelectedBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#8C000000");
MainW.Conf.ClrPcker_FontPickSelectedBorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FFDB6929");
MainW.Conf.ClrPcker_MenuBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#C9000000");
MainW.Conf.ClrPcker_MenuItem1BorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#00FFFFFF");
MainW.Conf.ClrPcker_MenuItem2HighlightTextColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FF00B5FF");
MainW.Conf.ClrPcker_MenuItem2HighlightBorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#FFDB6929");
MainW.Conf.ClrPcker_MenuItem2DisabledColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString("#73696969");
//rotation angle
MainW.Conf.slValue.Value = 0;
//no file
NewFile();
//BG image clear
//this makes Imagepath = "";
ImageClear();
//BgImage Blur
MainW.Conf.imageBlurSlider.Value = 0;
//opacity
MainW.Conf.imageopacityslider.Value = 100;
MainW.Conf.windowopacityslider.Value = 100;
MainW.Conf.textopacityslider.Value = 100;
//Auto Save Timer
MainW.Conf.autosavetimersider.Value = 5;
//window Checkboxes
MainW.Conf.alwaysontop.IsChecked = false;
MainW.Conf.taskbarvisible.IsChecked = true;
MainW.Conf.NotificationVisible.IsChecked = true;
MainW.Conf.ResizeVisible.IsChecked = true;
MainW.Conf.BgBlur.IsChecked = true;
MainW.Conf.toolsalwaysontop.IsChecked = true;
MainW.Conf.StartWithWindows.IsChecked = true;
MainW.Conf.RegisterFileTypes.IsChecked = true;
//Image Checkboxes
MainW.Conf.GifMethodCPU.IsChecked = true;
MainW.Conf.ImageBlurGauss.IsChecked = true;
//menu checkboxes
MainW.LineWrapMenuItem.IsChecked = true;
MainW.ToolBarMenuItem.IsChecked = false;
MainW.Conf.ToolBarEnabled.IsChecked = false;
//text checkboxes
MainW.Conf.TextWrap.IsChecked = true;
MainW.Conf.readOnlyCheck.IsChecked = false;
MainW.Conf.spellcheck.IsChecked = false;
MainW.Conf.resizecheck.IsChecked = false;
MainW.Conf.FlipXButton.IsChecked = false;
MainW.Conf.FlipYButton.IsChecked = false;
}
/// <summary>
/// <para>Reads the skintext.ini and calls <see cref="ReadConfigLine"/> line by line to load the config</para>
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public static void ReadConfig() {
try {
string configFile = AppDataPath + CurrentSkin + @"\skintext.ini";
if (File.Exists(configFile)) {
using (StreamReader reader = new StreamReader(configFile, System.Text.Encoding.UTF8)) {
string currentLine;
string[] line;
while ((currentLine = reader.ReadLine()) != null) {
line = currentLine.Split('=');
line[0] = line[0].Trim();
line[0] = line[0].ToUpperInvariant();
if (!string.IsNullOrEmpty(line[0]) && line.Length > 1 && !string.IsNullOrWhiteSpace(line[1])) {
line[1] = line[1].Trim();
ReadConfigLine(line);
}
}
}
}
}
catch (Exception ex) {
// The appdata folders dont exist
//can be first open, let default values
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
/// <summary>
/// Takes a line of the SkinText.ini config file and interpret it to load it's config values
/// </summary>
/// <param name="line">Line of the SkinText.ini config file</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
public static void ReadConfigLine(string[] line) {
if (line != null) {
try {
double double1;
double double2;
bool bool1;
string string1;
string[] array;
switch (line[0]) {//Changed var names to use less variables CA1809
case "WINDOW_POSITION": {
array = line[1].Split(',');
if (double.TryParse(array[0], out double1) && //top
double.TryParse(array[1], out double2)) //left
{
MainW.window.Top = double1;
MainW.window.Left = double2;
}
break;
}
case "WINDOW_SIZE": {
array = line[1].Split(',');
if (double.TryParse(array[0], out double1) && //window width
double.TryParse(array[1], out double2)) //window height
{
if (double1 > MainW.window.MinWidth && double1 < MainW.window.MaxWidth) {
MainW.window.Width = double1;
}
if (double2 > MainW.window.MinHeight && double2 < MainW.window.MaxHeight) {
MainW.window.Height = double2;
}
}
break;
}
case "BORDER_SIZE": {
if (int.TryParse(line[1], out int int1)) //border size
{
if (int1 <= MainW.Conf.bordersize.Maximum && int1 >= MainW.Conf.bordersize.Minimum) {
MainW.Conf.bordersize.Value = int1;
}
}
break;
}
case "TEXT_POSITION": {
array = line[1].Split(',');
if (double.TryParse(array[0], out double1) && //left
double.TryParse(array[1], out double2)) //top
{
System.Windows.Controls.Canvas.SetLeft(MainW.TitleBorder, double1);
System.Windows.Controls.Canvas.SetTop(MainW.TitleBorder, double2);
/*
double borderSize = MainW.Conf.bordersize.Value;
*if ((double1 < MainW.window.Width - (borderSize * 2 + 1)) && (double1 >= 0)){//left
System.Windows.Controls.Canvas.SetLeft(MainW.TitleBorder, double1);
}
if ((double2 < MainW.window.Height - (borderSize * 2 + 1)) && (double2 >= 0)){//top
System.Windows.Controls.Canvas.SetTop(MainW.TitleBorder, double2);
}*/
}
break;
}
case "TEXT_SIZE": {
array = line[1].Split(',');
if (double.TryParse(array[0], out double1) && //width
double.TryParse(array[1], out double2)) //height
{
MainW.TitleBorder.Width = double1;
MainW.TitleBorder.Height = double2;
/*
double borderSize = MainW.Conf.bordersize.Value;
* if ((double1 < MainW.window.Width - (borderSize * 2 + 1)) && (double1 > 0)) {//width
MainW.TitleBorder.Width = double1;
}
if ((double2 < MainW.window.Height - (borderSize * 2 + 1)) && (double2 > 0)) {//height
MainW.TitleBorder.Height =double2;
}*/
}
break;
}
case "TEXT_MAX_CORNER_RADIUS": {
if (double.TryParse(line[1], out double1)) {
if (double1 >= 0 && double1 < 1000000) {
MainW.Conf.CornerMax.Value = Convert.ToDecimal(double1);
}
}
break;
}
case "TEXT_CORNER_RADIUS_LOCKED": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.lockSlidersCheckbox.IsChecked = bool1;
}
break;
}
case "TEXT_CORNER_RADIUS": {
array = line[1].Split(',');
if (double.TryParse(array[0], out double1) && //left-top
double.TryParse(array[1], out double2) && //right-top
double.TryParse(array[2], out double double3) && //right-bottom
double.TryParse(array[3], out double double4)) //left-bottom
{
if (double1 >= 0 && double1 <= Convert.ToDouble(MainW.Conf.CornerMax.Value, System.Globalization.CultureInfo.InvariantCulture)) {
MainW.Conf.CornerRadius1Slider.Value = double1;
}
if (double2 >= 0 && double2 <= Convert.ToDouble(MainW.Conf.CornerMax.Value, System.Globalization.CultureInfo.InvariantCulture)) {
MainW.Conf.CornerRadius2Slider.Value = double2;
}
if (double3 >= 0 && double3 <= Convert.ToDouble(MainW.Conf.CornerMax.Value, System.Globalization.CultureInfo.InvariantCulture)) {
MainW.Conf.CornerRadius3Slider.Value = double3;
}
if (double4 >= 0 && double4 <= Convert.ToDouble(MainW.Conf.CornerMax.Value, System.Globalization.CultureInfo.InvariantCulture)) {
MainW.Conf.CornerRadius4Slider.Value = double4;
}
}
break;
}
/*case "FILE": {//moved to config.ini
string1 = line[1].Trim(); //fileName
if (!string1.Contains("\\") && !string.IsNullOrEmpty(string1)) {//if is a relative path, use current .exe path to find it //not necesary as it will never be relative, but for historical pruposes
string1 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + string1;
}
ReadFile(string1); //this sets Global Filepath
break;
}*/
case "RESIZE_ENABLED": {
if (bool.TryParse(line[1], out bool1)) //resize checked
{
MainW.Conf.resizecheck.IsChecked = bool1;
}
break;
}
case "BORDER_COLOR": {
MainW.Conf.ClrPcker_BorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "WINDOW_COLOR": {
MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "TEXT_BG_COLOR": {
MainW.Conf.ClrPcker_RTBBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "ROTATION": {
if (double.TryParse(line[1], out double1)) //angle
{
if (double1 <= MainW.Conf.slValue.Maximum && double1 >= MainW.Conf.slValue.Minimum) {
MainW.Conf.slValue.Value = double1;
}
}
break;
}
case "GIF_USES_RAM": {//GIF rendering method
if (bool.TryParse(line[1], out bool1)) {// true = RAM //DEFAULT = false (Use CPU)
MainW.Conf.GifMethodRAM.IsChecked = bool1;
}
break;
}
case "BG_IMAGE": {//(always after GIF method)
string1 = line[1].Trim();
if (!string1.Contains("\\") && !string.IsNullOrEmpty(string1)) {//if is a relative path, use current .exe path to find it
string1 = AppDataPath + CurrentSkin + "\\" + string1;
}
LoadImage(string1);//this sets Global Imagepath
break;
}
case "IMAGE_OPACITY": {
if (double.TryParse(line[1], out double1)) {
if (double1 <= MainW.Conf.imageopacityslider.Maximum && double1 >= MainW.Conf.imageopacityslider.Minimum) {
MainW.Conf.imageopacityslider.Value = double1;
}
}
break;
}
case "TEXT_OPACITY": {
if (double.TryParse(line[1], out double1)) {
if (double1 <= MainW.Conf.textopacityslider.Maximum && double1 >= MainW.Conf.textopacityslider.Minimum) {
MainW.Conf.textopacityslider.Value = double1;
}
}
break;
}
case "WINDOW_OPACITY": {
if (double.TryParse(line[1], out double1)) {
if (double1 <= MainW.Conf.windowopacityslider.Maximum && double1 >= MainW.Conf.windowopacityslider.Minimum) {
MainW.Conf.windowopacityslider.Value = double1;
}
}
break;
}
case "READ_ONLY": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.readOnlyCheck.IsChecked = bool1;
}
break;
}
case "SPELL_CHECK": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.spellcheck.IsChecked = bool1;
}
break;
}
case "ALWAYS_ON_TOP": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.alwaysontop.IsChecked = bool1;
}
break;
}
case "TASKBAR_ICON": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.taskbarvisible.IsChecked = bool1;
}
break;
}
case "NOTIFICATION_ICON": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.NotificationVisible.IsChecked = bool1;
}
break;
}
case "RESIZE_VISIBLE": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.ResizeVisible.IsChecked = bool1;
}
break;
}
case "FLIP_RTB": {//flip rich text box (rendertransform)
array = line[1].Split(',');
if (bool.TryParse(array[0], out bool1) && // X
bool.TryParse(array[1], out bool bool2)) // Y
{
MainW.Conf.FlipXButton.IsChecked = bool1;
MainW.Conf.FlipYButton.IsChecked = bool2;
}
break;
}
case "LINE_WRAP": {//Line Wrapping (Default on)
if (bool.TryParse(line[1], out bool1)) {
MainW.LineWrapMenuItem.IsChecked = bool1;
MainW.Conf.TextWrap.IsChecked = bool1;
}
break;
}
////////////////////////////////////
case "BACKGROUNDCOLORBRUSH": {
MainW.Conf.ClrPcker_BackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "BUTTONBACKGROUNDCHECKEDCOLORBRUSH": {
MainW.Conf.ClrPcker_ButtonBackgroundCheckedColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "BUTTONBORDERCHECKEDCOLORBRUSH": {
MainW.Conf.ClrPcker_ButtonBorderCheckedColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "BUTTONBACKGROUNDCOLORBRUSH": {
MainW.Conf.ClrPcker_ButtonBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "BUTTONFRONTCOLORBRUSH": {
MainW.Conf.ClrPcker_ButtonFrontColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "BUTTONBACKGROUNDMOUSEOVERCOLORBRUSH": {
MainW.Conf.ClrPcker_ButtonBackgroundMouseOverColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "BUTTONBORDERMOUSEOVERCOLORBRUSH": {
MainW.Conf.ClrPcker_ButtonBorderMouseOverColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "FONTPICKBACKGROUNDCOLORBRUSH": {
MainW.Conf.ClrPcker_FontPickBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "FONTPICKMOUSEOVERBACKGROUNDCOLORBRUSH": {
MainW.Conf.ClrPcker_FontPickMouseOverBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "FONTPICKMOUSEOVERBORDERCOLORBRUSH": {
MainW.Conf.ClrPcker_FontPickMouseOverBorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "FONTPICKSELECTEDBACKGROUNDCOLORBRUSH": {
MainW.Conf.ClrPcker_FontPickSelectedBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "FONTPICKSELECTEDBORDERCOLORBRUSH": {
MainW.Conf.ClrPcker_FontPickSelectedBorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "MENUBACKGROUNDCOLORBRUSH": {
MainW.Conf.ClrPcker_MenuBackgroundColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "MENUITEM1BORDERCOLORBRUSH": {
MainW.Conf.ClrPcker_MenuItem1BorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "MENUITEM2DISABLEDCOLORBRUSH": {
MainW.Conf.ClrPcker_MenuItem2DisabledColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "MENUITEM2HIGHLIGHTBORDERCOLORBRUSH": {
MainW.Conf.ClrPcker_MenuItem2HighlightBorderColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "MENUITEM2HIGHLIGHTTEXTCOLORBRUSH": {
MainW.Conf.ClrPcker_MenuItem2HighlightTextColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "TEXTCOLORBRUSH": {
MainW.Conf.ClrPcker_TextColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "FONTPICKTEXTCOLORBRUSH": {
MainW.Conf.ClrPcker_FontPickTextColorBrush.SelectedColor = (Color)ColorConverter.ConvertFromString(line[1]);
break;
}
case "IMG_BLUR_VAL": {
if (double.TryParse(line[1], out double1)) //angle
{
if (double1 <= MainW.Conf.imageBlurSlider.Maximum && double1 >= MainW.Conf.imageBlurSlider.Minimum) {
MainW.Conf.imageBlurSlider.Value = double1;
}
}
break;
}
case "IMG_BLUR_BOX": {
if (bool.TryParse(line[1], out bool1)) {// true = Gauss (DEFAULT) false = Box
MainW.Conf.ImageBlurBox.IsChecked = bool1;
}
break;
}
case "WINDOW_BLUR": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.BgBlur.IsChecked = bool1;
}
break;
}
case "TOOLBAR_ENABLED": {
if (bool.TryParse(line[1], out bool1)) {
MainW.ToolBarMenuItem.IsChecked = bool1;
MainW.Conf.ToolBarEnabled.IsChecked = bool1;
}
break;
}
case "TOOLS_TOP": {
if (bool.TryParse(line[1], out bool1)) {
MainW.Conf.toolsalwaysontop.IsChecked = bool1;
}
break;
}
case "AUTOSAVE_ENABLED": {
if (bool.TryParse(line[1], out bool1)) {
AutoSaveEnabled = bool1;
}
break;
}
case "AUTOSAVE_TIMER": {
if (double.TryParse(line[1], out double1)) {
if (double1 <= MainW.Conf.autosavetimersider.Maximum && double1 >= MainW.Conf.autosavetimersider.Minimum) {
MainW.Conf.autosavetimersider.Value = double1;
}
}
break;
}
case "START_WITH_WINDOWS":{
if (bool.TryParse(line[1], out bool1))
{
MainW.Conf.StartWithWindows.IsChecked = bool1;
}
break;
}
case "REGISTER_FILE_TYPES":{
if (bool.TryParse(line[1], out bool1))
{
MainW.Conf.RegisterFileTypes.IsChecked = bool1;
}
break;
}
default: {
#if DEBUG
MessageBox.Show("Not recognized: \"" + line[0] + "\" in SkinConfig file");
#endif
break;
}
}
}
catch (Exception ex) {
//System.FormatException catched from COLOR converters
#if DEBUG
MessageBox.Show("DEBUG: "+ex.ToString());
//throw;
#endif
}
}
}
/// <summary>
/// Saves SkinText config into SkinText.ini in /appdata
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
public static void SaveConfig() {// had to do this: https://msdn.microsoft.com/library/ms182334.aspx
FileStream fs = null;
try {
string configFile = AppDataPath + CurrentSkin + @"\skintext.ini";
Directory.CreateDirectory(AppDataPath + CurrentSkin);//!Exists ? create it : ignore
fs = new FileStream(configFile, FileMode.Create, FileAccess.Write);
using (TextWriter writer = new StreamWriter(fs, System.Text.Encoding.UTF8)) {
fs = null; //is no longer needed
string data;
//window_position
data = "window_position = " +
Math.Truncate(MainW.window.Top).ToString(System.Globalization.CultureInfo.InvariantCulture) + " , " +
Math.Truncate(MainW.window.Left).ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//window_size
data = "window_size = " +
Math.Truncate(MainW.window.Width).ToString(System.Globalization.CultureInfo.InvariantCulture) + " , " +
Math.Truncate(MainW.window.Height).ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//border_size
data = "border_size = " +
Math.Truncate(MainW.Conf.bordersize.Value).ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//text_size
data = "text_size = " +
Math.Truncate(MainW.TitleBorder.Width).ToString(System.Globalization.CultureInfo.InvariantCulture) + " , " +
Math.Truncate(MainW.TitleBorder.Height).ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//text_position
data = "text_position = " +
Math.Truncate(System.Windows.Controls.Canvas.GetLeft(MainW.TitleBorder)).ToString(System.Globalization.CultureInfo.InvariantCulture) + " , " +
Math.Truncate(System.Windows.Controls.Canvas.GetTop(MainW.TitleBorder)).ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//text_corner_radius_locked
data = "text_corner_radius_locked = " +
MainW.Conf.lockSlidersCheckbox.IsChecked.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//text_max_corner_radius
data = "text_max_corner_radius = " +
MainW.Conf.CornerMax.Value.ToString();
writer.WriteLine(data);
//text_corner_radius
data = "text_corner_radius = " +
MainW.Conf.CornerRadius1Slider.Value.ToString(System.Globalization.CultureInfo.InvariantCulture) + " , " +
MainW.Conf.CornerRadius2Slider.Value.ToString(System.Globalization.CultureInfo.InvariantCulture) + " , " +
MainW.Conf.CornerRadius3Slider.Value.ToString(System.Globalization.CultureInfo.InvariantCulture) + " , " +
MainW.Conf.CornerRadius4Slider.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//filetry
#region relative Path (Disabled)
/*
//To store as relative Path
int index = filepath.LastIndexOf("\\");
string tempdir;
if (index>0)
{
tempdir = filepath.Substring(0, index).ToLower();
}
else
{
tempdir = filepath.ToLower();
}
string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).ToLower();
if (object.Equals(tempdir, dir))
{
filepath = filepath.Substring(index + 1);
}
*/
#endregion relative Path (Disabled)
/*
//moved to config.ini
data = "file = " + Filepath;
writer.WriteLine(data);
*/
//resize_enabled
data = "resize_enabled = " + MainW.Conf.resizecheck.IsChecked.Value.ToString();
writer.WriteLine(data);
//border_color
data = "border_color = " + MainW.Conf.ClrPcker_BorderColorBrush.SelectedColor.ToString();
writer.WriteLine(data);
//border_color
data = "window_color = " + MainW.Conf.ClrPcker_MainWindowBackgroundColorBrush.SelectedColor.ToString();
writer.WriteLine(data);
//border_color
data = "text_bg_color = " + MainW.Conf.ClrPcker_RTBBackgroundColorBrush.SelectedColor.ToString();
writer.WriteLine(data);
//rotation
data = "rotation = " + MainW.Conf.slValue.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
writer.WriteLine(data);
//GIF Method
data = "gif_uses_ram = " + MainW.Conf.GifMethodRAM.IsChecked.Value.ToString();
writer.WriteLine(data);
//bg_image (always after GIF method) (since when reading it is needed to know the method beforehand)
string imgpath = Imagepath;
#region relative Path