@@ -83,7 +83,6 @@ public static ToolStripItem[] FindToolStripMenuItems(ToolStripItemCollection tsi
8383 }
8484 return lItems . ToArray ( ) ;
8585 }
86-
8786 #endregion
8887
8988 #region Plugin options and instance
@@ -121,7 +120,16 @@ public static Dictionary<string, Version> GetLoadedPluginsName()
121120 while ( PluginIterator . MoveNext ( ) )
122121 {
123122 object result = GetField ( "m_pluginInterface" , PluginIterator . Current ) ;
124- dPlugins [ result . GetType ( ) . FullName ] = result . GetType ( ) . Assembly . GetName ( ) . Version ;
123+ var x = result . GetType ( ) . Assembly ;
124+ object [ ] v = x . GetCustomAttributes ( typeof ( AssemblyFileVersionAttribute ) , true ) ;
125+ Version ver = null ;
126+ if ( ( v != null ) && ( v . Length > 0 ) )
127+ ver = new Version ( ( ( AssemblyFileVersionAttribute ) v [ 0 ] ) . Version ) ;
128+ else
129+ ver = result . GetType ( ) . Assembly . GetName ( ) . Version ;
130+ if ( ver . Build < 0 ) ver = new Version ( ver . Major , ver . Minor , 0 , 0 ) ;
131+ if ( ver . Revision < 0 ) ver = new Version ( ver . Major , ver . Minor , ver . Build , 0 ) ;
132+ dPlugins [ result . GetType ( ) . FullName ] = ver ;
125133 }
126134 }
127135 catch ( Exception ) { }
@@ -151,6 +159,7 @@ public static void AddPluginToOptionsForm(KeePass.Plugins.Plugin p, UserControl
151159 uc . Dock = DockStyle . Fill ;
152160 uc . Padding = new Padding ( 15 , 10 , 15 , 10 ) ;
153161 tPlugin . Controls . Add ( uc ) ;
162+ PluginDebug . AddInfo ( "Adding/Searching " + c_tabControlRookiestyle ) ;
154163 TabControl tcPlugins = AddPluginTabContainer ( ) ;
155164 int i = 0 ;
156165 bool insert = false ;
@@ -163,7 +172,12 @@ public static void AddPluginToOptionsForm(KeePass.Plugins.Plugin p, UserControl
163172 break ;
164173 }
165174 }
166- if ( ! insert ) i = tcPlugins . TabPages . Count ;
175+ if ( ! insert )
176+ {
177+ i = tcPlugins . TabPages . Count ;
178+ PluginDebug . AddInfo ( p . GetType ( ) . Name + " tab index : " + i . ToString ( ) + " - insert!" , 0 ) ;
179+ }
180+ else PluginDebug . AddInfo ( p . GetType ( ) . Name + " tab index : " + i . ToString ( ) , 0 ) ;
167181 tcPlugins . TabPages . Insert ( i , tPlugin ) ;
168182 AddPluginToOverview ( tPlugin . Name . Replace ( c_tabRookiestyle , string . Empty ) , tcPlugins ) ;
169183 if ( p . SmallIcon != null )
@@ -191,6 +205,7 @@ private static void AddPluginToOverview(string sPluginName, TabControl tcPlugins
191205 {
192206 tpOverview = tcPlugins . TabPages [ sTabName ] ;
193207 lv = ( ListView ) tpOverview . Controls . Find ( sListViewName , true ) [ 0 ] ;
208+ PluginDebug . AddInfo ( "Found " + sTabName , 0 , "Listview: " + ( lv == null ? "null" : lv . Items . Count . ToString ( ) + " /" + lv . Name . ToString ( ) ) ) ;
194209 }
195210 else
196211 {
@@ -224,13 +239,15 @@ private static void AddPluginToOverview(string sPluginName, TabControl tcPlugins
224239 lvi . Text = DefaultCaption ;
225240 Version v = new Version ( 0 , 0 ) ;
226241 GetLoadedPluginsName ( ) . TryGetValue ( sPluginName . Replace ( "Ext" , string . Empty ) + "." + sPluginName , out v ) ;
227- string ver = v . ToString ( ) ;
242+ if ( v == null ) PluginDebug . AddError ( "Could not get loaded plugins' data" , 0 ) ;
243+ string ver = ( v == null ) ? "???" : v . ToString ( ) ;
228244 if ( ver . EndsWith ( ".0" ) ) ver = ver . Substring ( 0 , ver . Length - 2 ) ;
229245 else ver += " (Dev)" ;
230246 lvi . SubItems . Add ( ver ) ;
231247 lv . Items . Add ( lvi ) ;
232248 tcPlugins . TabPages . Remove ( tpOverview ) ;
233249 tcPlugins . TabPages . Add ( tpOverview ) ;
250+ PluginDebug . AddInfo ( "Added " + sTabName , 0 , "Listview: " + ( lv == null ? "null" : lv . Items . Count . ToString ( ) + " /" + lv . Name . ToString ( ) ) ) ;
234251 }
235252
236253 private static void TpOverview_Layout ( object sender , LayoutEventArgs e )
@@ -373,14 +390,30 @@ private static void OnWindowRemoved(object sender, KeePass.UI.GwmWindowEventArgs
373390
374391 private static TabControl AddPluginTabContainer ( )
375392 {
393+ if ( m_of == null )
394+ {
395+ PluginDebug . AddError ( "Could not identify KeePass options form" , 0 ) ;
396+ return null ;
397+ }
376398 TabControl tcMain = Tools . GetControl ( "m_tabMain" , m_of ) as TabControl ;
399+ if ( tcMain == null )
400+ {
401+ PluginDebug . AddError ( "Could not locate m_tabMain" , 0 ) ;
402+ return null ;
403+ }
377404 TabPage tPlugins = null ;
378405 TabControl tcPlugins = null ;
379406 if ( tcMain . TabPages . ContainsKey ( c_tabRookiestyle ) )
380407 {
381408 tPlugins = tcMain . TabPages [ c_tabRookiestyle ] ;
382409 tcPlugins = ( TabControl ) tPlugins . Controls [ c_tabControlRookiestyle ] ;
410+ if ( tcPlugins == null )
411+ {
412+ PluginDebug . AddError ( "Could not locate " + c_tabControlRookiestyle , 0 ) ;
413+ return null ;
414+ }
383415 tcPlugins . Multiline = false ; //Older version of PluginTools might still be used by other plugins
416+ PluginDebug . AddInfo ( "Found " + c_tabControlRookiestyle , 0 ) ;
384417 return tcPlugins ;
385418 }
386419 tPlugins = new TabPage ( KeePass . Resources . KPRes . Plugin + " " + m_of . Text ) ;
@@ -390,6 +423,7 @@ private static TabControl AddPluginTabContainer()
390423 {
391424 while ( tcMain . TabCount > 0 )
392425 tcMain . TabPages . RemoveAt ( 0 ) ;
426+ PluginDebug . AddInfo ( "Removed tab pages from KeePass options form" , 0 ) ;
393427 }
394428 tcMain . TabPages . Add ( tPlugins ) ;
395429 tcPlugins = new TabControl ( ) ;
@@ -400,6 +434,7 @@ private static TabControl AddPluginTabContainer()
400434 if ( tcPlugins . ImageList == null )
401435 tcPlugins . ImageList = new ImageList ( ) ;
402436 tPlugins . Controls . Add ( tcPlugins ) ;
437+ PluginDebug . AddInfo ( "Added " + c_tabControlRookiestyle , 0 ) ;
403438 return tcPlugins ;
404439 }
405440
@@ -470,22 +505,6 @@ private static void FormClosed(object sender, FormClosedEventArgs e)
470505 #endregion
471506 }
472507
473- public static class DPIAwareness
474- {
475- public static readonly Size Size16 = new Size ( DpiUtil . ScaleIntX ( 16 ) , DpiUtil . ScaleIntY ( 16 ) ) ;
476-
477- public static Image Scale16x16 ( Image img )
478- {
479- return Scale ( img , 16 , 16 ) ;
480- }
481-
482- public static Image Scale ( Image img , int x , int y )
483- {
484- if ( img == null ) return null ;
485- return GfxUtil . ScaleImage ( img , DpiUtil . ScaleIntX ( x ) , DpiUtil . ScaleIntY ( y ) ) ;
486- }
487- }
488-
489508 public static class PluginDebug
490509 {
491510 [ Flags ]
@@ -512,14 +531,7 @@ public enum LogLevelFlags
512531 public static bool DebugMode
513532 {
514533 get { return m_DebugMode ; }
515- set
516- {
517- if ( m_DebugMode == value ) return ;
518- bool b = m_DebugMode ;
519- m_DebugMode = true ;
520- AddInfo ( "DebugMode changed" , "Old: " + b . ToString ( ) , "New: " + value . ToString ( ) ) ;
521- m_DebugMode = value ;
522- }
534+ set { m_DebugMode = value ; }
523535 }
524536 private static Dictionary < string , Version > m_plugins = new Dictionary < string , Version > ( ) ;
525537 public static Version DotNetVersion { get ; private set ; }
@@ -535,10 +547,13 @@ static PluginDebug()
535547
536548 ulong uInst = KeePass . Util . WinUtil . GetMaxNetFrameworkVersion ( ) ;
537549 DotNetVersion = new Version ( StrUtil . VersionToString ( uInst ) ) ;
538- RegistryKey rkRel = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" , false ) ;
539- try { m_DotNetRelease = ( int ) rkRel . GetValue ( "Release" ) ; }
550+ try
551+ {
552+ RegistryKey rkRel = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" , false ) ;
553+ m_DotNetRelease = ( int ) rkRel . GetValue ( "Release" ) ;
554+ if ( rkRel != null ) rkRel . Close ( ) ;
555+ }
540556 catch { }
541- if ( rkRel != null ) rkRel . Close ( ) ;
542557
543558 DebugFile = System . IO . Path . GetTempPath ( ) + "Debug_" + PluginName + "_" + m_Start . ToString ( "yyyyMMddTHHmmssZ" ) + ".xml" ;
544559
0 commit comments