Skip to content

Commit 985d1b9

Browse files
committed
*
1 parent 38ab1ac commit 985d1b9

File tree

10 files changed

+351
-126
lines changed

10 files changed

+351
-126
lines changed

SmartImage.Lib 3/Model/BaseImageHost.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ public static async Task<UniSource[]> ScanAsync(Url u, Predicate<UniSource> pred
6464

6565
try {
6666
res = await u.AllowAnyHttpStatus()
67-
.WithCookies(out var cj)
68-
.WithAutoRedirect(true)
69-
.WithHeaders(new
70-
{
71-
User_Agent = HttpUtilities.UserAgent
72-
})
73-
.OnError(f =>
74-
{
75-
// f.ExceptionHandled = true;
76-
return;
77-
}).GetAsync(cancellationToken: ct);
67+
.WithCookies(out var cj)
68+
.WithAutoRedirect(true)
69+
.WithHeaders(new
70+
{
71+
User_Agent = HttpUtilities.UserAgent
72+
})
73+
.OnError(f =>
74+
{
75+
// f.ExceptionHandled = true;
76+
return;
77+
}).GetAsync(cancellationToken: ct);
7878

7979
}
8080
catch (Exception e) {
@@ -97,7 +97,7 @@ public static async Task<UniSource[]> ScanAsync(Url u, Predicate<UniSource> pred
9797

9898
// var p = new HtmlParser();
9999
// var dd = await p.ParseDocumentAsync(stream, ct);
100-
100+
101101
var parser = new HtmlParser();
102102
var dd = await parser.ParseDocumentAsync(stream);
103103

@@ -154,6 +154,33 @@ public static bool UniSourcePredicate(UniSource us)
154154
return true;
155155
}
156156
}
157+
158+
public static async Task<UniSource[]> RunGalleryAsync(Url cri, CancellationToken ct = default)
159+
{
160+
using var p = Process.Start(new ProcessStartInfo("gallery-dl", $"-G {cri}")
161+
{
162+
CreateNoWindow = true,
163+
RedirectStandardOutput = true,
164+
RedirectStandardError = true,
165+
});
166+
await p.WaitForExitAsync(ct);
167+
var s = await p.StandardOutput.ReadToEndAsync(ct);
168+
var s2 = s.Split(Environment.NewLine);
169+
var rg = new ConcurrentBag<UniSource>();
170+
171+
await Parallel.ForEachAsync(s2, ct, async (s1, token) =>
172+
{
173+
var uni = await UniSource.TryGetAsync(s1, ct: token);
174+
175+
if (uni != null) {
176+
rg.Add(uni);
177+
}
178+
});
179+
180+
// p.Dispose();
181+
182+
return rg.ToArray();
183+
}
157184
}
158185

159186
public class DanbooruImageHost : GenericImageHost

SmartImage.UI/AppUtil.cs

Lines changed: 174 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
global using R2 = SmartImage.UI.Resources;
1+
global using R2 = SmartImage.UI.Resources;
32
global using R1 = SmartImage.Lib.Resources;
43
using System;
54
using System.Collections.Generic;
@@ -11,10 +10,16 @@
1110
using System.Threading.Tasks;
1211
using Microsoft.Win32;
1312
using Novus.OS;
13+
using Flurl.Http;
14+
using JetBrains.Annotations;
15+
using Kantan.Net.Utilities;
16+
using Newtonsoft.Json;
17+
// ReSharper disable InconsistentNaming
18+
1419
#nullable disable
1520
namespace SmartImage.UI;
1621

17-
public static class AppUtil
22+
internal static class AppUtil
1823
{
1924
#region
2025

@@ -32,6 +37,11 @@ public static string ExeLocation
3237
}
3338
}
3439

40+
static AppUtil()
41+
{
42+
43+
}
44+
3545
public static Version Version => Assembly.GetName().Version;
3646

3747
public static string CurrentAppFolder => Path.GetDirectoryName(ExeLocation);
@@ -63,17 +73,15 @@ public static bool HandleContextMenu(bool option)
6373
/*
6474
* New context menu
6575
*/
66-
switch (option)
67-
{
76+
switch (option) {
6877
case true:
6978

7079
RegistryKey regMenu = null;
7180
RegistryKey regCmd = null;
7281

7382
string fullPath = ExeLocation;
7483

75-
try
76-
{
84+
try {
7785
regMenu = Registry.CurrentUser.CreateSubKey(R1.Reg_Shell);
7886
regMenu?.SetValue(String.Empty, R1.Name);
7987
regMenu?.SetValue("Icon", $"\"{fullPath}\"");
@@ -83,40 +91,34 @@ public static bool HandleContextMenu(bool option)
8391
regCmd?.SetValue(String.Empty,
8492
$"\"{fullPath}\" -i \"%1\" -as");
8593
}
86-
catch (Exception ex)
87-
{
94+
catch (Exception ex) {
8895
Trace.WriteLine($"{ex.Message}");
8996
return false;
9097
}
91-
finally
92-
{
98+
finally {
9399
regMenu?.Close();
94100
regCmd?.Close();
95101
}
96102

97103
break;
98104
case false:
99105

100-
try
101-
{
106+
try {
102107
var reg = Registry.CurrentUser.OpenSubKey(R1.Reg_Shell_Cmd);
103108

104-
if (reg != null)
105-
{
109+
if (reg != null) {
106110
reg.Close();
107111
Registry.CurrentUser.DeleteSubKey(R1.Reg_Shell_Cmd);
108112
}
109113

110114
reg = Registry.CurrentUser.OpenSubKey(R1.Reg_Shell);
111115

112-
if (reg != null)
113-
{
116+
if (reg != null) {
114117
reg.Close();
115118
Registry.CurrentUser.DeleteSubKey(R1.Reg_Shell);
116119
}
117120
}
118-
catch (Exception ex)
119-
{
121+
catch (Exception ex) {
120122
Trace.WriteLine($"{ex.Message}");
121123

122124
return false;
@@ -125,8 +127,160 @@ public static bool HandleContextMenu(bool option)
125127
break;
126128

127129
}
128-
130+
129131
return false;
130132

131133
}
134+
135+
internal static async Task<GHRelease[]> GetRepoReleasesAsync()
136+
{
137+
var res = await "https://api.github.com/repos/Decimation/SmartImage/releases"
138+
.WithAutoRedirect(true)
139+
.AllowAnyHttpStatus()
140+
.WithHeaders(new
141+
{
142+
User_Agent = HttpUtilities.UserAgent
143+
})
144+
.OnError(e =>
145+
{
146+
e.ExceptionHandled = true;
147+
})
148+
.GetJsonAsync<GHRelease[]>();
149+
150+
return res;
151+
}
152+
153+
public static async Task<GHRelease> GetLatestReleaseAsync()
154+
{
155+
var r = await GetRepoReleasesAsync();
156+
157+
if (r == null) {
158+
return null;
159+
}
160+
161+
return r.OrderByDescending(x => x.published_at).FirstOrDefault(x =>
162+
{
163+
if (Version.TryParse(x.tag_name[1..], out var xv)) {
164+
x.Version = xv;
165+
return xv > Version;
166+
}
167+
168+
return false;
169+
});
170+
}
171+
172+
// Root myDeserializedClass = JsonConvert.DeserializeObject<List<Root>>(myJsonResponse);
173+
}
174+
175+
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
176+
internal class GHReleaseAsset
177+
{
178+
public string url { get; set; }
179+
public int id { get; set; }
180+
public string node_id { get; set; }
181+
public string name { get; set; }
182+
public object label { get; set; }
183+
public GHUploader uploader { get; set; }
184+
public string content_type { get; set; }
185+
public string state { get; set; }
186+
public int size { get; set; }
187+
public int download_count { get; set; }
188+
public DateTime created_at { get; set; }
189+
public DateTime updated_at { get; set; }
190+
public string browser_download_url { get; set; }
191+
}
192+
193+
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
194+
internal class GHAuthor
195+
{
196+
public string login { get; set; }
197+
public int id { get; set; }
198+
public string node_id { get; set; }
199+
public string avatar_url { get; set; }
200+
public string gravatar_id { get; set; }
201+
public string url { get; set; }
202+
public string html_url { get; set; }
203+
public string followers_url { get; set; }
204+
public string following_url { get; set; }
205+
public string gists_url { get; set; }
206+
public string starred_url { get; set; }
207+
public string subscriptions_url { get; set; }
208+
public string organizations_url { get; set; }
209+
public string repos_url { get; set; }
210+
public string events_url { get; set; }
211+
public string received_events_url { get; set; }
212+
public string type { get; set; }
213+
public bool site_admin { get; set; }
214+
}
215+
216+
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
217+
internal class GHReactions
218+
{
219+
public string url { get; set; }
220+
public int total_count { get; set; }
221+
222+
[JsonProperty("+1")]
223+
public int Plus1 { get; set; }
224+
225+
[JsonProperty("-1")]
226+
public int Minus1 { get; set; }
227+
228+
public int laugh { get; set; }
229+
public int hooray { get; set; }
230+
public int confused { get; set; }
231+
public int heart { get; set; }
232+
public int rocket { get; set; }
233+
public int eyes { get; set; }
234+
}
235+
236+
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
237+
internal class GHUploader
238+
{
239+
public string login { get; set; }
240+
public int id { get; set; }
241+
public string node_id { get; set; }
242+
public string avatar_url { get; set; }
243+
public string gravatar_id { get; set; }
244+
public string url { get; set; }
245+
public string html_url { get; set; }
246+
public string followers_url { get; set; }
247+
public string following_url { get; set; }
248+
public string gists_url { get; set; }
249+
public string starred_url { get; set; }
250+
public string subscriptions_url { get; set; }
251+
public string organizations_url { get; set; }
252+
public string repos_url { get; set; }
253+
public string events_url { get; set; }
254+
public string received_events_url { get; set; }
255+
public string type { get; set; }
256+
public bool site_admin { get; set; }
257+
}
258+
259+
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
260+
internal class GHRelease
261+
{
262+
public string url { get; set; }
263+
public string assets_url { get; set; }
264+
public string upload_url { get; set; }
265+
public string html_url { get; set; }
266+
public int id { get; set; }
267+
public GHAuthor author { get; set; }
268+
public string node_id { get; set; }
269+
public string tag_name { get; set; }
270+
public string target_commitish { get; set; }
271+
public string name { get; set; }
272+
public bool draft { get; set; }
273+
public bool prerelease { get; set; }
274+
public DateTime created_at { get; set; }
275+
public DateTime published_at { get; set; }
276+
public List<GHReleaseAsset> assets { get; set; }
277+
public string tarball_url { get; set; }
278+
public string zipball_url { get; set; }
279+
public string body { get; set; }
280+
public string discussion_url { get; set; }
281+
public GHReactions reactions { get; set; }
282+
283+
[JsonIgnore]
284+
[NonSerialized]
285+
public Version Version;
132286
}

SmartImage.UI/Icon.ico

264 KB
Binary file not shown.

0 commit comments

Comments
 (0)