66using System . IO ;
77using System . Linq ;
88using System . Management ;
9- using System . Text ;
109using System . Threading ;
1110using System . Threading . Tasks ;
1211using System . Windows . Forms ;
13- using NLog ;
1412using Sunny . UI ;
1513using TG . INI ;
1614using TG . INI . Serialization ;
@@ -21,8 +19,8 @@ namespace X.Lucifer.LosslessZoom;
2119
2220public 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>
0 commit comments