@@ -39,7 +39,7 @@ public override bool Initialize(IPluginHost host)
3939 {
4040 m_host = host ;
4141
42- PluginTranslate . TranslationChanged += delegate ( object sender , TranslationChangedEventArgs e )
42+ PluginTranslate . TranslationChanged += delegate ( object sender , TranslationChangedEventArgs e )
4343 {
4444 if ( ! string . IsNullOrEmpty ( KeePass . Program . Translation . Properties . Iso6391Code ) )
4545 PluginUpdateHandler . LanguageIso = KeePass . Program . Translation . Properties . Iso6391Code ;
@@ -123,8 +123,8 @@ private void MainWindow_FormLoadPost(object sender, EventArgs e)
123123 else if ( ! m_bRestartTriggered )
124124 {
125125 //Only load plugins, do NOT check for new translations
126- ThreadPool . QueueUserWorkItem ( new WaitCallback ( ( object o ) =>
127- {
126+ ThreadPool . QueueUserWorkItem ( new WaitCallback ( ( object o ) =>
127+ {
128128 PluginUpdateHandler . LoadPlugins ( false ) ;
129129 CheckExternalPluginUpdate ( ) ;
130130 } ) ) ;
@@ -180,7 +180,7 @@ private void LanguageFormAdded(object sender, EventArgs e)
180180
181181 private void WindowRemoved ( object sender , GwmWindowEventArgs e )
182182 {
183- if ( ( m_kpf != null ) && ( e . Form is KeyPromptForm ) ) m_kpf = null ;
183+ if ( ( m_kpf != null ) && ( e . Form is KeyPromptForm ) ) m_kpf = null ;
184184 }
185185
186186 #region Check for updates
@@ -281,7 +281,8 @@ private void UpdateCheckBackground()
281281
282282 if ( m_slUpdateCheck != null )
283283 {
284- m_host . MainWindow . Invoke ( new KeePassLib . Delegates . GAction ( ( ) => { m_slUpdateCheck . EndLogging ( ) ; } ) ) ;
284+ if ( bUpdAvail ) UpdateStatusLogger ( ) ;
285+ EndLogging ( ) ;
285286 m_slUpdateCheck = null ;
286287 }
287288
@@ -313,8 +314,8 @@ private void UpdateCheckBackground()
313314 }
314315 finally
315316 {
316- try { if ( m_slUpdateCheck != null ) m_slUpdateCheck . EndLogging ( ) ; }
317- catch ( Exception ) { }
317+ try { if ( m_slUpdateCheck != null ) EndLogging ( ) ; }
318+ catch ( Exception ex ) { lMsg . Add ( ex . Message ) ; }
318319 if ( bOK )
319320 lock ( m_lock ) { m_UpdateCheckStatus = UpdateCheckStatus . Checked ; }
320321 else
@@ -336,14 +337,14 @@ private void UpdateCheckBackground()
336337 }
337338 while ( true )
338339 {
339- if ( ( m_slUpdateCheck != null ) && ! m_slUpdateCheck . ContinueWork ( ) ) break ;
340+ if ( ( m_slUpdateCheck != null ) && ! ContinueWork ( ) ) break ;
340341 lock ( m_lock )
341342 {
342343 if ( m_UpdateCheckStatus == UpdateCheckStatus . Checked ) break ;
343344 if ( m_UpdateCheckStatus == UpdateCheckStatus . Error ) break ;
344345 }
345346 }
346- if ( m_slUpdateCheck != null ) m_slUpdateCheck . EndLogging ( ) ;
347+ if ( m_slUpdateCheck != null ) EndLogging ( ) ;
347348 if ( bOK ) return ;
348349 }
349350 catch ( Exception ex )
@@ -359,6 +360,61 @@ private void UpdateCheckBackground()
359360 }
360361 }
361362
363+ private bool ContinueWork ( )
364+ {
365+ try
366+ {
367+ var c = UIThread ( ( ) =>
368+ {
369+ bool cw = false ;
370+ lock ( m_slUpdateCheck )
371+ {
372+ if ( m_slUpdateCheck == null ) cw = false ;
373+ else cw = m_slUpdateCheck . ContinueWork ( ) ;
374+ }
375+ return cw ;
376+ } ) ;
377+ if ( c != null ) return ( bool ) c ;
378+ }
379+ catch { }
380+ return true ;
381+ }
382+
383+ private void EndLogging ( )
384+ {
385+ UIThread ( ( ) =>
386+ {
387+ lock ( m_slUpdateCheck )
388+ {
389+ if ( m_slUpdateCheck != null ) m_slUpdateCheck . EndLogging ( ) ;
390+ m_slUpdateCheck = null ;
391+ }
392+ return null ;
393+ } ) ;
394+ }
395+
396+ private object UIThread ( KeePassLib . Delegates . GFunc < object > a )
397+ {
398+ try
399+ {
400+ return m_bCancel . Invoke ( a ) ;
401+ }
402+ catch ( Exception ex )
403+ {
404+ PluginDebug . AddError ( "Show SecureDesktopHint" , 0 , ex . Message ) ;
405+ }
406+ return null ;
407+ }
408+
409+ private void UpdateStatusLogger ( )
410+ {
411+ if ( ! m_kpf . SecureDesktopMode ) return ;
412+ UIThread ( ( ) => {
413+ Tools . ShowInfo ( string . Format ( PluginTranslate . SecureDesktopMode , KeePass . Resources . KPRes . MasterKeyOnSecureDesktop , KeePass . Resources . KPRes . OpenDatabase ) ) ;
414+ return null ;
415+ } ) ;
416+ }
417+
362418 /// <summary>
363419 /// Check whether searching for updates of plugins or translations shall be done
364420 /// </summary>
@@ -383,17 +439,18 @@ private UpdateCheckType UpdateCheckRequired()
383439 return UpdateCheckType . Required ;
384440 }
385441
442+ private Button m_bCancel = null ;
386443 private IStatusLogger CreateUpdateCheckLogger ( )
387444 {
388445 IStatusLogger sl = StatusUtil . CreateStatusDialog ( null , out m_CheckProgress ,
389446 KeePass . Resources . KPRes . UpdateCheck , KeePass . Resources . KPRes . CheckingForUpd + "..." , true , true ) ;
390- Button btnCancel = ( Button ) Tools . GetControl ( "m_btnCancel" , m_CheckProgress ) ;
391- if ( btnCancel != null )
447+ m_bCancel = ( Button ) Tools . GetControl ( "m_btnCancel" , m_CheckProgress ) ;
448+ if ( m_bCancel != null )
392449 {
393- int x = btnCancel . Right ;
394- btnCancel . AutoSize = true ;
395- btnCancel . Text = PluginTranslate . EnterBackgroundMode ;
396- btnCancel . Left = x - btnCancel . Width ;
450+ int x = m_bCancel . Right ;
451+ m_bCancel . AutoSize = true ;
452+ m_bCancel . Text = PluginTranslate . EnterBackgroundMode ;
453+ m_bCancel . Left = x - m_bCancel . Width ;
397454 }
398455 return sl ;
399456 }
@@ -496,14 +553,14 @@ private void OnUpdateCheckFormShown(object sender, EventArgs e)
496553 }
497554 //https://github.com/mono/mono/issues/17747
498555 //Do NOT use ListView.SmallImageList
499- if ( m_ImgApply == null ) m_ImgApply = ( Image ) KeePass . Program . Resources . GetObject ( "B16x16_Apply" ) ;
556+ if ( m_ImgApply == null ) m_ImgApply = ( Image ) KeePass . Program . Resources . GetObject ( "B16x16_Apply" ) ;
500557 if ( m_ImgUnselected == null ) m_ImgUnselected = m_ImgApply == null ? null : UIUtil . CreateGrayImage ( m_ImgApply ) ;
501558 PluginDebug . AddInfo ( "Installed updatable plugins" , 0 , PluginUpdateHandler . Plugins . ConvertAll ( x => x . Name + " / " + x . Title + " / " + x . UpdateMode . ToString ( ) + " / " + x . UpdatePossible . ToString ( ) ) . ToArray ( ) ) ;
502559 KeePass_Update kpu = null ;
503560 foreach ( ListViewItem item in lvPlugins . Items )
504561 {
505562 PluginDebug . AddInfo ( "Check plugin update status" , 0 , item . SubItems [ 0 ] . Text , item . SubItems [ 1 ] . Text ) ;
506- string sHelp = "-" + item . SubItems [ 0 ] . Text + "-" + item . SubItems [ 1 ] . Text + "- " + ( ! item . SubItems [ 1 ] . Text . Contains ( KeePass . Resources . KPRes . NewVersionAvailable ) ) . ToString ( ) ;
563+ string sHelp = "-" + item . SubItems [ 0 ] . Text + "-" + item . SubItems [ 1 ] . Text + "- " + ( ! item . SubItems [ 1 ] . Text . Contains ( KeePass . Resources . KPRes . NewVersionAvailable ) ) . ToString ( ) ;
507564 if ( ! item . SubItems [ 1 ] . Text . Contains ( KeePass . Resources . KPRes . NewVersionAvailable ) ) continue ;
508565 if ( item . Index == 0 && item . Text == "KeePass" )
509566 {
@@ -537,7 +594,7 @@ private void OnUpdateCheckFormShown(object sender, EventArgs e)
537594 if ( ! bColumnAdded )
538595 {
539596 lvPlugins . Columns . Add ( PluginTranslate . PluginUpdate ) ;
540- lvPlugins . KeyPress += LvPlugins_KeyPress ;
597+ lvPlugins . KeyPress += LvPlugins_KeyPress ;
541598 bColumnAdded = true ;
542599 }
543600 ListViewItem . ListViewSubItem lvsiUpdate = new ListViewItem . ListViewSubItem ( item , PluginTranslate . PluginUpdate ) ;
@@ -562,7 +619,7 @@ private void OnUpdateCheckFormShown(object sender, EventArgs e)
562619 break ;
563620 }
564621 }
565- if ( bColumnAdded )
622+ if ( bColumnAdded )
566623 {
567624 UIUtil . ResizeColumns ( lvPlugins , new int [ ] { 3 , 3 , 2 , 2 , 1 } , true ) ;
568625 lvPlugins . MouseClick += OnUpdateCheckFormPluginMouseClick ;
@@ -571,7 +628,7 @@ private void OnUpdateCheckFormShown(object sender, EventArgs e)
571628 lvPlugins . DrawColumnHeader += LvPlugins_DrawColumnHeader ;
572629 ShowUpdateButton ( sender as Form , true , kpu ) ;
573630 }
574-
631+
575632 if ( m_lEventHandlerItemActivate . Count == 0 )
576633 {
577634 if ( lvPlugins . ContextMenuStrip == null )
@@ -588,16 +645,16 @@ private void OnUpdateCheckFormShown(object sender, EventArgs e)
588645 }
589646
590647 private bool m_bActivateKeePassUpdateTab = false ;
591- private void CheckKeePassInstallType ( bool bShowOptions )
592- {
648+ private void CheckKeePassInstallType ( bool bShowOptions )
649+ {
593650 if ( PluginConfig . KeePassInstallTypeConfigured ) return ;
594651 m_bActivateKeePassUpdateTab = true ;
595652 if ( ! bShowOptions ) Tools . ShowInfo ( PluginTranslate . KeePassUpdate_RequestInstallType ) ;
596653 if ( bShowOptions ) Tools . ShowOptions ( ) ;
597654 }
598655
599656 private void LvPlugins_KeyPress ( object sender , KeyPressEventArgs e )
600- {
657+ {
601658 if ( e . KeyChar != ( char ) Keys . Space ) return ;
602659 var lv = sender as ListView ;
603660 if ( lv == null || lv . SelectedItems . Count < 0 ) return ;
@@ -663,17 +720,17 @@ private void OnUpdateCheckFormPluginMouseClick(object sender, MouseEventArgs e)
663720 ToggleUpdateFlag ( sender as ListView , info . SubItem . Tag as PluginUpdate ) ;
664721 }
665722
666- private void ToggleUpdateFlag ( ListView lv , PluginUpdate upd )
667- {
723+ private void ToggleUpdateFlag ( ListView lv , PluginUpdate upd )
724+ {
668725 if ( lv == null || upd == null ) return ;
669726 upd . Selected = ! upd . Selected ;
670727 bool bAtLeast1Selected = PluginUpdateHandler . Plugins . Find ( x => x . Selected == true ) != null ;
671728 if ( ! bAtLeast1Selected )
672- {
729+ {
673730 //Check whether KeePass itself is selected for update
674731 bAtLeast1Selected = lv . Items [ 0 ] . SubItems [ lv . Items [ 0 ] . SubItems . Count - 1 ] . Tag is KeePass_Update ;
675732 if ( bAtLeast1Selected ) bAtLeast1Selected = ( lv . Items [ 0 ] . SubItems [ lv . Items [ 0 ] . SubItems . Count - 1 ] . Tag as KeePass_Update ) . Selected ;
676- }
733+ }
677734 if ( ! ShowUpdateButton ( lv . FindForm ( ) , bAtLeast1Selected , lv . Items [ 0 ] . SubItems [ lv . Items [ 0 ] . SubItems . Count - 1 ] . Tag ) )
678735 {
679736 upd . Selected = ! upd . Selected ;
@@ -736,13 +793,13 @@ private bool ShowUpdateButton(Form form, bool enable, object oKeePassUpdate)
736793 }
737794 bUpdate . Tag = oKeePassUpdate ;
738795 bUpdate . Enabled = enable ;
739-
796+
740797 SetUpdateButtonText ( bUpdate , oKeePassUpdate ) ;
741798 return true ;
742799 }
743800
744- private void SetUpdateButtonText ( Button bUpdate , object oKeePassUpdate )
745- {
801+ private void SetUpdateButtonText ( Button bUpdate , object oKeePassUpdate )
802+ {
746803 bool bAtLeast1PluginSelected = PluginUpdateHandler . Plugins . FindAll ( x => x . Selected ) . Count > 0 ;
747804 if ( ! bUpdate . Enabled )
748805 {
@@ -758,7 +815,7 @@ private void SetUpdateButtonText(Button bUpdate, object oKeePassUpdate)
758815 else if ( bAtLeast1PluginSelected ) bUpdate . Text = PluginTranslate . PluginUpdateSelected ;
759816 else if ( kpu != null & kpu . Selected ) bUpdate . Text = PluginTranslate . PluginUpdateKeePass ;
760817 else
761- {
818+ {
762819 bUpdate . Enabled = false ;
763820 bUpdate . Text = PluginTranslate . PluginUpdate ;
764821 }
@@ -776,9 +833,9 @@ private void LvPlugins_DrawSubItem(object sender, DrawListViewSubItemEventArgs e
776833
777834 int iMaxColumns = - 1 ;
778835 foreach ( ListViewItem lvi in lvPlugins . Items )
779- {
836+ {
780837 if ( iMaxColumns < lvi . SubItems . Count ) iMaxColumns = lvi . SubItems . Count ;
781- }
838+ }
782839 if ( e . ColumnIndex + 1 != iMaxColumns ) return ;
783840 PluginUpdate upd = PluginUpdateHandler . Plugins . Find ( x => x . Title == e . Item . SubItems [ 0 ] . Text ) ;
784841 if ( upd == null ) upd = PluginUpdateHandler . Plugins . Find ( x => x . Title + "*" == e . Item . SubItems [ 0 ] . Text ) ; //* is used to indicate a rename
@@ -886,34 +943,34 @@ private void DoUpdateKeePass(KeePass_Update kpu)
886943
887944 //Start installation of update or open download folder (zip / portable)
888945 success &= kpu . Execute ( ) ;
889-
946+
890947 //Restart KeePass to use new plugin versions
891948 PluginDebug . AddInfo ( "KeePass update/download finished" , "Succes: " + success . ToString ( ) , DebugPrint ) ;
892949 }
893950
894951 private void bUpdatePlugins_Click ( object sender , EventArgs e )
895952 {
896- KeePass_Update kpu = null ;
953+ KeePass_Update kpu = null ;
897954 Button bUpdate = sender as Button ;
898955 if ( bUpdate != null && bUpdate . Tag is KeePass_Update ) kpu = bUpdate . Tag as KeePass_Update ;
899956 UpdatePlugins ( UpdateFlags . All , kpu ) ;
900957 }
901958
902959 private void UpdatePlugins ( UpdateFlags uf , KeePass_Update kpu )
903- {
960+ {
904961 UpdatePlugins ( uf , false , kpu ) ;
905- }
962+ }
906963 private void UpdatePlugins ( UpdateFlags uf , bool bForceExternalPluginUpdatesDownload , KeePass_Update kpu )
907964 {
908965 if ( kpu != null ) DoUpdateKeePass ( kpu ) ;
909966
910967 //Check whether anything needs to be done
911968 if ( uf != UpdateFlags . ExternalUpdateInfo && PluginUpdateHandler . Plugins . FindAll ( x => x . Selected ) . Count == 0 ) return ;
912-
969+
913970 PluginDebug . AddInfo ( "UpdatePlugins start " , DebugPrint ) ;
914971 Form fUpdateLog = null ;
915972 m_slUpdatePlugins = StatusUtil . CreateStatusDialog ( GlobalWindowManager . TopWindow , out fUpdateLog , PluginTranslate . PluginUpdateCaption , string . Empty , true , true ) ;
916-
973+
917974 bool success = false ;
918975 string sTempPluginsFolder = PluginUpdateHandler . GetTempFolder ( ) ;
919976
@@ -1036,7 +1093,7 @@ private void Restart()
10361093 if ( m_slUpdateCheck != null )
10371094 {
10381095 PluginDebug . AddInfo ( "Closing update check progress form" , 0 , DebugPrint ) ;
1039- m_slUpdateCheck . EndLogging ( ) ;
1096+ EndLogging ( ) ;
10401097 }
10411098
10421099 if ( MonoWorkarounds . IsRequired ( 620618 ) )
@@ -1109,11 +1166,11 @@ private void HandleMutex(bool release)
11091166 lStrings . Add ( "Success: See next entry" ) ;
11101167 PluginDebug . AddInfo ( "Handle global mutex" , 0 , lStrings . ToArray ( ) ) ;
11111168 Thread t = new Thread ( new ThreadStart ( ( ) =>
1112- {
1113- Thread . Sleep ( PluginConfig . RestoreMutexThreshold ) ;
1114- bool bSuccess = GlobalMutexPool . CreateMutex ( KeePass . App . AppDefs . MutexName , true ) ;
1115- PluginDebug . AddInfo ( "Handle global mutex" , 0 , "Recreate mutex sucessful: " + bSuccess . ToString ( ) ) ;
1116- } ) ) ;
1169+ {
1170+ Thread . Sleep ( PluginConfig . RestoreMutexThreshold ) ;
1171+ bool bSuccess = GlobalMutexPool . CreateMutex ( KeePass . App . AppDefs . MutexName , true ) ;
1172+ PluginDebug . AddInfo ( "Handle global mutex" , 0 , "Recreate mutex sucessful: " + bSuccess . ToString ( ) ) ;
1173+ } ) ) ;
11171174 t . IsBackground = true ;
11181175 t . Start ( ) ;
11191176 return ;
@@ -1195,7 +1252,7 @@ private string DebugPrint
11951252 get
11961253 {
11971254 string result = "DifferentThread: {0}, Check status: {1}, UI interaction blocked: {2}" ;
1198- lock ( m_lock )
1255+ lock ( m_lock )
11991256 {
12001257 result = string . Format ( result , m_bRestartInvoke . ToString ( ) , m_UpdateCheckStatus . ToString ( ) , KeePass . Program . MainForm . UIIsInteractionBlocked ( ) . ToString ( ) ) ;
12011258 }
0 commit comments