-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAboutWin.xaml.cs
More file actions
193 lines (188 loc) · 7.91 KB
/
AboutWin.xaml.cs
File metadata and controls
193 lines (188 loc) · 7.91 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
using System;
using System.Collections.Generic;
using System.IO;
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.Xml;
using System.Net;
using System.Xml.Linq;
using scripthea.options;
using UtilsNS;
namespace scripthea
{
/// <summary>
/// Interaction logic for AboutWin.xaml
/// </summary>
public partial class AboutWin : Window
{
public AboutWin()
{
InitializeComponent();
Title = "About Scripthea version " + UtilsNS.Utils.getAppFileVersion;
}
Options opts;
public bool closing = false;
public void Init(ref Options _opts)
{
opts = _opts;
}
public void Check4Updates(int lastChecked) // the date of last check / -1 forced; returns the new check date;
{
if (!Utils.IsInternetConnectionAvailable()) // no i-net
{
if (lastChecked.Equals(-1)) Utils.TimedMessageBox("No internet connection");
else
{
lbMessage.Foreground = Brushes.Red; lbMessage.Content = "Problem with the internet connection";
}
return;
}
lbMessage.Foreground = Brushes.Green;
DateTime refDate = new DateTime(2023, 1, 1); // reference date
TimeSpan timeSpan = DateTime.Today - refDate;
if ((timeSpan.Days - lastChecked) >= 14 || lastChecked.Equals(-1))
{
string msg;
bool bb = IsUpdateAvalaible(out msg); if (!bb && msg == "") return;
lbMessage.Content = msg;
if (bb) lbMessage.Foreground = Brushes.OrangeRed;
else lbMessage.Foreground = Brushes.Green;
opts.general.LastUpdateCheck = timeSpan.Days;
}
else
{
if (Utils.newerVersion(Utils.getAppFileVersion, opts.general.NewVersion))
{
lbMessage.Foreground = Brushes.Tomato;
lbMessage.Content = "New release (" + opts.general.NewVersion + ") is available at Scripthea.com !";
}
}
}
private string someStats()
{
string[] sl = Utils.getAppFileVersion.Split('.');
string st = "";
if (sl.Length > 3) st += "b=" + sl[3];
st += "&g=";
switch (opts.composer.API)
{
case "AddonGen": st += "D";
break;
case "SD-A1111/Forge": st += "A";
break;
case "SD-ComfyUI": st += "C";
break;
case "Craiyon": st += "R";
break;
default: st += "N";
break;
}
st += "&s=" + (int)(opts.composer.SessionSpan / 60.0);
st += "&v=" + (int)(opts.composer.TotalImageCount / 100.0);
st += "&r=" + (int)(opts.composer.TotalRatingCount / 100.0);
return st;
}
public bool IsUpdateAvalaible(out string msg) // return a message to show
{
if (!Utils.CheckFileExists(@"https://scripthea.com/scripthea.xml"))
{
Utils.TimedMessageBox(@"Error[927]: pad file https://scripthea.com/scripthea.xml is not avalable!", "Error", 5000); msg = ""; return false;
}
string remVer = ""; string[] sl = Utils.getAppFileVersion.Split('.');
string plus = "?" + someStats();
Dictionary<string, string> pad = readPAD(readXml(@"https://scripthea.com/scripthea.xml"+plus));
bool ok = true;
if (pad.ContainsKey("Program_Info.Program_Version")) remVer = pad["Program_Info.Program_Version"];
else ok = false;
ok &= pad.ContainsKey("Company_Info.Company_Name") && pad.ContainsKey("Program_Info.Program_Name");
if (ok) ok = pad["Company_Info.Company_Name"].Equals("Teodor Krastev") && pad["Program_Info.Program_Name"].Equals("Scripthea");
string[] sr = remVer.Split('.');
if ((sr.Length != 3) || !ok) { msg = "Problem with accessing update info from Scripthea.com"; opts.general.NewVersion = ""; return false; }
if (Utils.newerVersion(Utils.getAppFileVersion, remVer))
{
msg = "New release (" + remVer + ") is available at Scripthea.com !"; opts.general.NewVersion = remVer; return true;
}
msg = "Your version is up to date."; opts.general.NewVersion = ""; return false;
}
private void aboutWin_MouseDown(object sender, MouseButtonEventArgs e)
{
Hide();
}
private void tbSources_MouseDown(object sender, MouseButtonEventArgs e)
{
Utils.CallTheWeb(@"https://github.com/teodor-krastev/scripthea");
}
private void lbAuthor_MouseDown(object sender, MouseButtonEventArgs e)
{
Utils.CallTheWeb(@"https://sicyon.com/survey/comment.html?sj=scripthea");
}
private void tbkWebsite_MouseDown(object sender, MouseButtonEventArgs e)
{
Utils.CallTheWeb(@"https://scripthea.com");
}
public XmlDocument readXml(string url)
{
string xmlContent = Utils.DownloadString(url);
XDocument xDoc = XDocument.Parse(xmlContent);
XmlReader reader = xDoc.CreateReader();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(reader);
return xmlDocument;
}
public Dictionary<string, string> readPAD(XmlDocument xmlDoc)
{
Dictionary<string, string> pad = new Dictionary<string, string>();
// Access the root element
XmlElement root = xmlDoc.DocumentElement;
// Iterate through child elements
foreach (XmlNode topNode in root.ChildNodes)
{
foreach (XmlNode node in topNode.ChildNodes)
{
// Do something with the node
//Console.WriteLine($"Element Name: {node.Name}");
if (node.Attributes != null)
{
string attr = "";
foreach (XmlAttribute attribute in node.Attributes)
{
// Do something with the attribute
//Console.WriteLine($"Attribute Name: {attribute.Name}, Value: {attribute.Value}");
attr += attribute.Name + "=" + attribute.Value + " ; ";
}
if (!attr.Equals("")) pad.Add(topNode.Name + "." + node.Name+":ATTR", attr);
}
// Access the node value (if any)
if (!string.IsNullOrEmpty(node.InnerText))
{
//Console.WriteLine($"Node Value: {node.InnerText}");
pad.Add(topNode.Name+"."+node.Name, node.InnerText);
}
}
}
return pad;
}
private void AboutWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (closing) return;
// Cancel the window closing event
e.Cancel = true;
Hide();
}
private void lbCoffee_MouseDown(object sender, MouseButtonEventArgs e)
{
Utils.CallTheWeb("https://www.buymeacoffee.com/theokrastev");
}
private void tbEmail_MouseDown(object sender, MouseButtonEventArgs e)
{
Utils.CallTheWeb(@"mailto:scripthea@sicyon.com");
}
}
}