@@ -115,8 +115,28 @@ class win10_wubi_patch
115115 }
116116 void RunThread ()
117117 {
118+ _start_time = GetTickCount ();
118119 _thread = std::thread (std::bind (&win10_wubi_patch::Execute, this ));
119120 }
121+
122+ bool CheckExit ()
123+ {
124+ bool bExit = false ;
125+ do
126+ {
127+ if (_patched_pids.size () <= 0 ) {
128+ break ;
129+ }
130+
131+ // /< wait 10 seconds
132+ if (GetTickCount () - _start_time <= 10 * 1000 ) {
133+ break ;
134+ }
135+
136+ bExit = true ;
137+ } while (0 );
138+ return bExit;
139+ }
120140protected:
121141 virtual int32_t Execute (void )
122142 {
@@ -185,6 +205,7 @@ class win10_wubi_patch
185205 volatile bool _exit;
186206 std::set<DWORD> _patched_pids;
187207 std::thread _thread;
208+ DWORD _start_time;
188209};
189210
190211bool check_support_version ()
@@ -209,10 +230,16 @@ bool check_support_version()
209230 return bSupport;
210231}
211232
212- int main ()
233+ static void Usage ()
234+ {
235+ printf (" if you want to exit when patch success, pass '--exit_when_patched' to launch command\n " );
236+ }
237+
238+ int main (int argc, char * argv[])
213239{
214240 printf (" ---Widows 10 Disable English Switch Key(Shift) For Wubi InputMethod---\n " );
215- printf (" ==key press [Q] to exit==\n " );
241+ printf (" key press [Q] to exit\n " );
242+ Usage ();
216243 printf (" \n " );
217244
218245 if (!check_support_version ()) {
@@ -226,16 +253,33 @@ int main()
226253 return -1 ;
227254 }
228255
256+ bool exit_when_patched = false ;
257+ if (argc >= 2 ) {
258+ std::string param1 = argv[1 ];
259+ if (param1 == " --exit_when_patched" ) {
260+ exit_when_patched = true ;
261+ }
262+ }
263+
229264 term_init ();
230265
231266 win10_wubi_patch wubi_patch;
232267 wubi_patch.RunThread ();
233268 do {
234269 if (read_key () == ' q' ) {
235- printf (" exit\n " );
270+ printf (" exit(user) \n " );
236271 sys_sleep (500 );
237272 break ;
238273 }
274+
275+ if (exit_when_patched) {
276+ if (wubi_patch.CheckExit ()) {
277+ printf (" exit(patched)\n " );
278+ sys_sleep (500 );
279+ break ;
280+ }
281+ }
282+
239283 sys_sleep (10 );
240284 } while (1 );
241285
0 commit comments