-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ImageOptionsView.xaml.cs
121 lines (110 loc) · 3.68 KB
/
ImageOptionsView.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using Microsoft.Win32;
using System.IO;
namespace HtmlExporterPlugin
{
public partial class ImageOptionsView : UserControl
{
private readonly HtmlExporterPlugin plugin;
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}
public ImageOptionsView()
{
InitializeComponent();
}
public ImageOptionsView(HtmlExporterPlugin plugin)
{
this.plugin = plugin;
InitializeComponent();
}
private bool ValidWidthHeight(string Text)
{
int userVal;
if (int.TryParse(Text, out userVal))
{
return (userVal >= 1) && (userVal <= 10000);
}
else
{
return false;
}
}
private bool ValidNumber(string Text, int minval, int maxval)
{
int userVal;
if (int.TryParse(Text, out userVal))
{
return (userVal >= minval) && (userVal <= maxval);
}
else
{
return false;
}
}
public bool ValidateInput()
{
return ValidNumber(tbMaxTasks.Text, 1, 16) && ValidNumber(tbJpgQuality.Text,1, 100) && ValidWidthHeight(tbBackgroundImageHeight.Text) && ValidWidthHeight(tbBackgroundImageWidth.Text) &&
ValidWidthHeight(tbCoverImageHeight.Text) && ValidWidthHeight(tbCoverImageWidth.Text) && ValidWidthHeight(tbIconImageHeight.Text) &&
ValidWidthHeight(tbIconImageWidth.Text);
}
string MagickInstallPath(RegistryView view)
{
string Result = String.Empty;
RegistryKey Key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, view);
if (Key != null)
{
RegistryKey SubKey = Key.OpenSubKey("Software\\ImageMagick\\Current");
if (SubKey != null)
{
object RegInstallDir = SubKey.GetValue("BinPath");
if (RegInstallDir != null)
{
Result = RegInstallDir.ToString();
if (Directory.Exists(Result))
{
Result = System.IO.Path.Combine(Result, "magick.exe");
}
}
}
}
return !File.Exists(Result) ? String.Empty : Result;
}
private void ButDetect_Click(object sender, RoutedEventArgs e)
{
string tmp = MagickInstallPath(RegistryView.Registry64);
if (String.IsNullOrEmpty(tmp))
{
tmp = MagickInstallPath(RegistryView.Registry32);
}
if (!String.IsNullOrEmpty(tmp))
{
TbImageMagickLocation.Text = tmp;
}
}
private void ButSelectExe_Click(object sender, RoutedEventArgs e)
{
string tmp = plugin.PlayniteApi.Dialogs.SelectFile("Exe Files|*.exe");
if (File.Exists(tmp))
{
TbImageMagickLocation.Text = tmp;
}
}
}
}