Skip to content

Commit 8bbe369

Browse files
committed
1.fix global fonts
2.add nlog
1 parent 8a99618 commit 8bbe369

20 files changed

+165
-147
lines changed

src/LosslessZoom/ApiExtensions.cs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,13 @@
33
using System.Drawing.Text;
44
using System.IO;
55
using System.Windows.Forms;
6-
using NLog;
76
using Sunny.UI;
8-
using XLogLevel = NLog.LogLevel;
97

108
namespace X.Lucifer.LosslessZoom;
119

1210
public static class ApiExtensions
1311
{
14-
public static IAsyncResult BeginInvoke(this Action action)
15-
{
16-
return action.BeginInvoke(null, null);
17-
}
18-
19-
public static IAsyncResult BeginInvoke(this Func<bool> func)
20-
{
21-
return func.BeginInvoke(null, null);
22-
}
12+
public static readonly string FontPath = Path.Combine(AppContext.BaseDirectory, "lovestruck.ttf");
2313

2414
public static void SetLanguage(Language lang = Language.Chinese)
2515
{
@@ -32,29 +22,4 @@ public static void SetLanguage(Language lang = Language.Chinese)
3222
UILocalizeHelper.SetEN();
3323
}
3424
}
35-
36-
public static Font GetFonts()
37-
{
38-
var path = Path.Combine(AppContext.BaseDirectory, "fonts.ttf");
39-
using var pfc = new PrivateFontCollection();
40-
pfc.AddFontFile(path);
41-
var font = new Font(pfc.Families[0], 10.5F, FontStyle.Regular, GraphicsUnit.Point);
42-
return font;
43-
}
44-
45-
public static void ChangeFonts(Control.ControlCollection controls)
46-
{
47-
var font = GetFonts();
48-
foreach (Control control in controls)
49-
{
50-
if (control.HasChildren)
51-
{
52-
ChangeFonts(control.Controls);
53-
}
54-
control.BeginInvoke((Action<Font>) (x =>
55-
{
56-
control.Font = x;
57-
}), font);
58-
}
59-
}
6025
}

src/LosslessZoom/FormAbout.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LosslessZoom/FormAbout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics;
33
using System.Drawing;
44
using System.Reflection;
5+
using System.Threading.Tasks;
56
using Sunny.UI;
67

78
namespace X.Lucifer.LosslessZoom;
@@ -33,7 +34,6 @@ private void FormAbout_Load(object sender, System.EventArgs e)
3334
lblTitle.Text = _pack.FormAbout_lblTitle;
3435
lblxVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
3536
lblxCopyright.Text = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;
36-
ApiExtensions.ChangeFonts(Controls);
3737
}
3838

3939
private void lblxAuthor_Click(object sender, System.EventArgs e)

src/LosslessZoom/FormCopyright.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LosslessZoom/FormCopyright.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Drawing;
3+
using System.Threading.Tasks;
34
using Sunny.UI;
45

56
namespace X.Lucifer.LosslessZoom;
@@ -26,6 +27,5 @@ private void FormCopyright_Load(object sender, EventArgs e)
2627
{
2728
Text = _pack.FormCopyright_Title;
2829
txtInfo.Text = _pack.FormCopyright_txtInfo;
29-
ApiExtensions.ChangeFonts(Controls);
3030
}
3131
}

src/LosslessZoom/FormError.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LosslessZoom/FormError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Drawing;
3+
using System.Threading.Tasks;
34
using Sunny.UI;
45

56
namespace X.Lucifer.LosslessZoom;
@@ -28,6 +29,5 @@ public FormError()
2829
private void FormError_Load(object sender, EventArgs e)
2930
{
3031
txtError.Text = Message ?? "";
31-
ApiExtensions.ChangeFonts(Controls);
3232
}
3333
}

src/LosslessZoom/FormMain.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LosslessZoom/FormMain.cs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
using System.IO;
77
using System.Linq;
88
using System.Management;
9-
using System.Text;
109
using System.Threading;
1110
using System.Threading.Tasks;
1211
using System.Windows.Forms;
13-
using NLog;
1412
using Sunny.UI;
1513
using TG.INI;
1614
using TG.INI.Serialization;
@@ -21,8 +19,8 @@ namespace X.Lucifer.LosslessZoom;
2119

2220
public partial class FormMain : UIForm
2321
{
22+
public bool IsAdmin = false;
2423
private readonly string _outdir = AppContext.BaseDirectory + @"output\";
25-
2624
private readonly List<string> _formats =
2725
[
2826
".jpg",
@@ -36,12 +34,13 @@ public partial class FormMain : UIForm
3634
private readonly List<int> _processlist;
3735
private bool _isai;
3836
private bool _isrun;
39-
private ILangPack _pack = new LangPack();
37+
private ILangPack _pack;
4038
public FormMain()
4139
{
4240
_processlist = [];
4341
_option = new RuntimeOption();
4442
_files = [];
43+
LoadIni();
4544
InitializeComponent();
4645
Load += async (_, _) => await FormMain_Load();
4746
}
@@ -57,8 +56,8 @@ public FormMain()
5756
/// </summary>
5857
private async Task FormMain_Load()
5958
{
60-
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
6159
this.ShowProcessForm();
60+
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
6261
FormClosed += async (_, _) => await FormMain_FormClosed();
6362
panelInfo.DragDrop += async (_, x) => await panelInfo_DragDrop(x);
6463
timer.Tick += Timer_Tick;
@@ -105,6 +104,10 @@ private async Task FormMain_Load()
105104
{
106105
this.HideProcessForm();
107106
}
107+
if (!IsAdmin)
108+
{
109+
this.ShowErrorDialog(_pack.RunAsAdmin);
110+
}
108111
}
109112

110113
/// <summary>
@@ -165,6 +168,14 @@ private void Timer_Tick(object sender, EventArgs e)
165168
/// 加载配置
166169
/// </summary>
167170
private bool LoadConfig()
171+
{
172+
SetLanguage(_option.Lang);
173+
LoadUiLang(_pack);
174+
WriteLog(_pack.FormMain_Init_Config);
175+
return true;
176+
}
177+
178+
private void LoadIni()
168179
{
169180
var file = AppContext.BaseDirectory + "config.ini";
170181
if (!File.Exists(file))
@@ -182,10 +193,6 @@ private bool LoadConfig()
182193
using var xdoc = new IniDocument(file);
183194
_option = IniSerialization.DeserializeDocument<RuntimeOption>(xdoc);
184195
_pack = _option.Lang == Language.Chinese ? new LangPack() : new LangPackEnglish();
185-
SetLanguage(_option.Lang);
186-
LoadUiLang(_pack);
187-
WriteLog(_pack.FormMain_Init_Config);
188-
return true;
189196
}
190197

191198
/// <summary>
@@ -246,8 +253,6 @@ private bool LoadMenu()
246253
topindex++;
247254
}
248255
navbarMenu.ResetFont();
249-
navbarMenu.DropMenuFont = GetFonts();
250-
navbarMenu.Font = GetFonts();
251256
navbarMenu.MenuItemClick += async (_, _, index) => await NavbarMenu_MenuItemClick(index);
252257
WriteLog(_pack.FormMain_Init_Menu);
253258
return true;
@@ -273,7 +278,6 @@ private async Task NavbarMenu_MenuItemClick(int index)
273278
{
274279
this.ShowErrorTip(_pack.FormMain_Engine_Fail);
275280
}
276-
277281
break;
278282
case 3:
279283
await Exit();
@@ -315,7 +319,6 @@ private void ChangeLang(Language lang = Language.Chinese)
315319

316320
private void LoadUiLang(ILangPack lang)
317321
{
318-
ChangeFonts(Controls);
319322
BeginInvoke((Action<string>) (x =>
320323
{
321324
Text = x;
@@ -414,7 +417,7 @@ private void ShowOption()
414417
return;
415418
}
416419

417-
using var form = new FormOption(_option, _pack);
420+
var form = new FormOption(_option, _pack);
418421
form.OnSaved += FormOption_OnSaved;
419422
form.ShowDialog(this);
420423
}
@@ -517,7 +520,6 @@ private async Task AddFiles(IReadOnlyCollection<string> files)
517520
FillHoverColor = Color.FromArgb(232, 127, 128),
518521
FillPressColor = Color.FromArgb(202, 87, 89),
519522
FillSelectedColor = Color.FromArgb(202, 87, 89),
520-
Font = new Font("微软雅黑", 12F),
521523
IsCircle = true,
522524
MinimumSize = new Size(1, 1),
523525
Name = $"rem_{_picid}",
@@ -600,25 +602,24 @@ private bool CheckEngine()
600602
{
601603
try
602604
{
603-
const string ainame = @"realesrgan\realesrgan-ncnn-vulkan.exe";
604-
var sinfo = new ProcessStartInfo(ainame)
605+
var file_list = new List<string>
605606
{
606-
CreateNoWindow = true,
607-
UseShellExecute = false,
608-
RedirectStandardError = true,
609-
RedirectStandardOutput = true,
610-
RedirectStandardInput = true,
611-
StandardOutputEncoding = Encoding.GetEncoding("GB2312"),
612-
StandardErrorEncoding = Encoding.GetEncoding("GB2312"),
613-
Verb = "runas",
614-
Arguments = "-h",
615-
WorkingDirectory = AppContext.BaseDirectory
607+
@"realesrgan\realesrgan-ncnn-vulkan.exe",
608+
@"realesrgan\vcomp140.dll",
609+
@"realesrgan\vcomp140d.dll",
610+
@"realesrgan\models\realesr-animevideov3-x2.bin",
611+
@"realesrgan\models\realesr-animevideov3-x3.bin",
612+
@"realesrgan\models\realesr-animevideov3-x4.bin",
613+
@"realesrgan\models\realesrgan-x4plus.bin",
614+
@"realesrgan\models\realesrgan-x4plus-anime.bin",
615+
@"realesrgan\models\realesr-animevideov3-x2.param",
616+
@"realesrgan\models\realesr-animevideov3-x3.param",
617+
@"realesrgan\models\realesr-animevideov3-x4.param",
618+
@"realesrgan\models\realesrgan-x4plus.param",
619+
@"realesrgan\models\realesrgan-x4plus-anime.param"
616620
};
617-
using var process = new Process();
618-
process.StartInfo = sinfo;
619-
process.EnableRaisingEvents = true;
620-
var status = process.Start();
621-
621+
var fail = file_list.Select(file => Path.Combine(AppContext.BaseDirectory, file)).Count(path => !File.Exists(path));
622+
var status = fail == 0;
622623
WriteLog(status ? _pack.FormMain_Init_Engine : _pack.FormMain_Engine_Fail);
623624
return status;
624625
}
@@ -729,8 +730,6 @@ private void WriteLog(string txt, bool isclear = false)
729730
{
730731
txtLog.Text = string.Empty;
731732
}
732-
733-
txtLog.Font = GetFonts();
734733
txtLog.AppendText($"[{DateTime.Now:G}] | {x}{Environment.NewLine}");
735734
txtLog.ScrollToCaret();
736735
}), txt, isclear);
@@ -958,8 +957,7 @@ await Task.Run(() =>
958957
RedirectStandardError = true,
959958
RedirectStandardOutput = true,
960959
RedirectStandardInput = true,
961-
Arguments = _option.OutDirPath,
962-
Verb = "runas"
960+
Arguments = _option.OutDirPath
963961
};
964962
using var process = new Process();
965963
process.StartInfo = sinfo;
@@ -1010,6 +1008,7 @@ private void Process_Exited(object sender, EventArgs e)
10101008
{
10111009
var process = (Process)sender;
10121010
_processlist.Remove(process.Id);
1011+
GC.Collect();
10131012
}
10141013

10151014
/// <summary>

src/LosslessZoom/FormOption.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)