1
1
using AiZoom . Models ;
2
2
using Autofac ;
3
3
using CliWrap ;
4
+ using CommunityToolkit . Mvvm . ComponentModel ;
5
+ using CommunityToolkit . Mvvm . Input ;
4
6
using MahApps . Metro . Controls . Dialogs ;
5
- using Microsoft . Toolkit . Mvvm . ComponentModel ;
6
- using Microsoft . Toolkit . Mvvm . Input ;
7
7
using System ;
8
8
using System . IO ;
9
9
using System . Threading . Tasks ;
@@ -21,7 +21,7 @@ class HomeViewModel : ObservableObject
21
21
public IAsyncRelayCommand OpenSourceImageCmd { get ; set ; }
22
22
public IAsyncRelayCommand OpenResultImageCmd { get ; set ; }
23
23
24
-
24
+
25
25
#endregion
26
26
#region Fields
27
27
@@ -43,7 +43,7 @@ public HomeViewModel()
43
43
_dialog = Locator . Container . Resolve < IDialogCoordinator > ( ) ;
44
44
45
45
OpenImageCmd = new RelayCommand ( OnOpenImageCmd ) ;
46
- StartCmd = new AsyncRelayCommand ( async ( ) => await OnStartCmd ( ) ) ;
46
+ StartCmd = new AsyncRelayCommand ( async ( ) => await OnStartCmd ( ) ) ;
47
47
OpenSourceImageCmd = new AsyncRelayCommand ( OnOpenSourceImageCmd ) ;
48
48
OpenResultImageCmd = new AsyncRelayCommand ( OnOpenResultImageCmd ) ;
49
49
@@ -88,9 +88,9 @@ private async Task OnStartCmd()
88
88
var sourceImageFile = new FileInfo ( SourceImage ) ;
89
89
var sourceImageName = Path . GetFileNameWithoutExtension ( sourceImageFile . Name ) ;
90
90
91
-
92
91
93
-
92
+
93
+
94
94
95
95
var engine = @"realesrgan\realesrgan-ncnn-vulkan.exe" ;
96
96
@@ -102,9 +102,9 @@ private async Task OnStartCmd()
102
102
}
103
103
104
104
var outputFileFullName = $ "{ settings . OutputDirectory } \\ { outputFileName } .{ settings . OutputFormat } ";
105
-
105
+
106
106
var arg = $ " -i \" { SourceImage } \" -o \" { outputFileFullName } \" -n { settings . Module } -f { settings . OutputFormat } -s 4 -g auto -j 2:2:2 -v";
107
-
107
+
108
108
var result = await Cli . Wrap ( engine )
109
109
. WithArguments ( arg )
110
110
. WithWorkingDirectory ( AppContext . BaseDirectory )
@@ -118,40 +118,40 @@ private void ProcessImage(string output)
118
118
var isDone = output . IndexOf ( "done" , 0 ) ;
119
119
120
120
// process
121
- if ( isPercentage != - 1 )
121
+ if ( isPercentage != - 1 )
122
122
{
123
123
ProgressString = output ;
124
- ProgressValue = Double . Parse ( output . Remove ( output . Length - 1 , 1 ) ) ;
124
+ ProgressValue = Double . Parse ( output . Remove ( output . Length - 1 , 1 ) ) ;
125
125
}
126
126
127
127
// done
128
- if ( isDone != - 1 )
128
+ if ( isDone != - 1 )
129
129
{
130
130
ProgressString = "100%" ;
131
131
ProgressValue = 100 ;
132
132
133
133
// get final output file here. if the source images has alpha channel, the original file extension is preserved
134
134
var startIndex = output . IndexOf ( " -> " , 0 ) ;
135
135
136
- var tail = output . Substring ( startIndex + 4 ) ;
136
+ var tail = output . Substring ( startIndex + 4 ) ;
137
137
ResultImage = tail . Substring ( 0 , tail . Length - 5 ) ;
138
138
}
139
139
140
140
141
-
141
+
142
142
}
143
143
144
144
private void OnOpenImageCmd ( )
145
145
{
146
- var dialog = new Ookii . Dialogs . Wpf . VistaOpenFileDialog ( ) { Filter = "jpeg (*.jpg)|*.jpg|PNG (*.png)|*.png|webp (*.webp)|*.webp" } ;
146
+ var dialog = new Ookii . Dialogs . Wpf . VistaOpenFileDialog ( ) { Filter = "jpeg (*.jpg)|*.jpg|PNG (*.png)|*.png|webp (*.webp)|*.webp" } ;
147
147
148
148
bool ? success = dialog . ShowDialog ( ) ;
149
149
if ( success == true )
150
150
{
151
151
SourceImage = dialog . FileName ;
152
152
ResultImage = null ;
153
153
}
154
-
154
+
155
155
}
156
156
}
157
157
}
0 commit comments