2828using System . Text . Unicode ;
2929using System . Threading ;
3030using System . Threading . Tasks ;
31+ using Windows . ApplicationModel . Background ;
3132using Windows . UI . Notifications ;
3233using Microsoft . Toolkit . Uwp . Notifications ;
3334using Novus . Win32 ;
3940using SmartImage . Lib . Searching ;
4041using SmartImage . Lib . Utilities ;
4142using SmartImage . Utilities ;
43+ using SmartImage . UX ;
4244
4345// ReSharper disable CognitiveComplexity
4446
@@ -65,7 +67,6 @@ public static class Program
6567 Description = AppInterface . Description
6668 } ;
6769
68-
6970 #endregion
7071
7172 /// <summary>
@@ -80,20 +81,18 @@ private static async Task Main(string[] args)
8081 }
8182
8283
83-
84-
8584#endif
8685
8786 /*
8887 * Setup
8988 * Check compatibility
9089 */
91-
9290
91+ ToastNotificationManagerCompat . OnActivated += AppToast . OnActivated ;
9392
9493 Native . SetConsoleOutputCP ( Native . CP_IBM437 ) ;
95-
96-
94+
95+
9796 Console . Title = $ "{ AppInfo . NAME } ";
9897
9998 NConsole . Init ( ) ;
@@ -125,37 +124,44 @@ private static async Task Main(string[] args)
125124 * Handle CLI args
126125 */
127126
128- var argEnumerator = args . GetEnumerator ( ) ;
127+ try {
128+
129+ var argEnumerator = args . GetEnumerator ( ) ;
130+
131+ while ( argEnumerator . MoveNext ( ) ) {
132+ object ? arg = argEnumerator . Current ;
129133
130- while ( argEnumerator . MoveNext ( ) ) {
131- object ? arg = argEnumerator . Current ;
134+ switch ( arg ) {
135+ case CMD_FIND_DIRECT :
136+ argEnumerator . MoveNext ( ) ;
132137
133- switch ( arg ) {
134- case CMD_FIND_DIRECT :
135- argEnumerator . MoveNext ( ) ;
138+ var directImages = ImageHelper . FindDirectImages ( ( string ) argEnumerator . Current ) ;
136139
137- var directImages = ImageHelper . FindDirectImages ( ( string ) argEnumerator . Current ) ;
138-
139- var imageResults = directImages . Select ( ImageResult . FromDirectImage ) ;
140- var directOptions = AppInterface . CreateResultOptions ( imageResults , "Image" ) ;
140+ var imageResults = directImages . Select ( ImageResult . FromDirectImage ) ;
141+ var directOptions = AppInterface . CreateResultOptions ( imageResults , "Image" ) ;
141142
142143
143- NConsole . ReadOptions ( new NConsoleDialog
144- {
145- Options = directOptions ,
146- Description = AppInterface . Description
147- } ) ;
144+ NConsole . ReadOptions ( new NConsoleDialog
145+ {
146+ Options = directOptions ,
147+ Description = AppInterface . Description
148+ } ) ;
148149
149- return ;
150- case CMD_SEARCH :
151- argEnumerator . MoveNext ( ) ;
152- Config . Query = ( string ) argEnumerator . Current ;
153- break ;
154- default :
155- Config . Query = args . First ( ) ;
156- break ;
150+ return ;
151+ case CMD_SEARCH :
152+ argEnumerator . MoveNext ( ) ;
153+ Config . Query = ( string ) argEnumerator . Current ;
154+ break ;
155+ default :
156+ Config . Query = args . First ( ) ;
157+ break ;
158+ }
157159 }
158160 }
161+ catch ( Exception e ) {
162+ Console . WriteLine ( e ) ;
163+ Console . ReadLine ( ) ;
164+ }
159165 }
160166
161167 try {
@@ -197,6 +203,7 @@ private static async Task Main(string[] args)
197203 }
198204 }
199205
206+
200207 private static void OnSearchCompleted ( object ? sender , EventArgs eventArgs , CancellationTokenSource cts )
201208 {
202209 AppInterface . FlashConsoleWindow ( ) ;
@@ -205,7 +212,7 @@ private static void OnSearchCompleted(object? sender, EventArgs eventArgs, Cance
205212 cts . Dispose ( ) ;
206213
207214 if ( Config . Notification ) {
208- AppInterface . ShowToast ( ) ;
215+ AppToast . Show ( ) ;
209216 }
210217 else {
211218 SystemSounds . Exclamation . Play ( ) ;
0 commit comments