Integrate FTP debug logging into UI toggle
This commit is contained in:
		@@ -75,14 +75,15 @@ namespace keepass2android.Io
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private readonly ICertificateValidationHandler _app;
 | 
							private readonly ICertificateValidationHandler _app;
 | 
				
			||||||
 | 
							private readonly Func<bool> _debugLogPrefGetter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public MemoryStream traceStream;
 | 
							public MemoryStream traceStream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public NetFtpFileStorage(Context context, ICertificateValidationHandler app)
 | 
							public NetFtpFileStorage(Context context, ICertificateValidationHandler app, Func<bool> debugLogPrefGetter)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
            _app = app;
 | 
					            _app = app;
 | 
				
			||||||
 | 
					            _debugLogPrefGetter = debugLogPrefGetter;
 | 
				
			||||||
            traceStream = new MemoryStream();
 | 
					            traceStream = new MemoryStream();
 | 
				
			||||||
			
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public IEnumerable<string> SupportedProtocols
 | 
							public IEnumerable<string> SupportedProtocols
 | 
				
			||||||
@@ -156,6 +157,9 @@ namespace keepass2android.Io
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			client.Config.EncryptionMode = settings.EncryptionMode;
 | 
								client.Config.EncryptionMode = settings.EncryptionMode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (_debugLogPrefGetter())
 | 
				
			||||||
 | 
									client.Logger = new Kp2aLogFTPLogger();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            client.Connect();
 | 
					            client.Connect();
 | 
				
			||||||
			return client;
 | 
								return client;
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
@@ -589,7 +593,7 @@ namespace keepass2android.Io
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        public void Log(FtpLogEntry entry)
 | 
					        public void Log(FtpLogEntry entry)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Kp2aLog.Log("FluentFTP: " + entry.Message);
 | 
					            Kp2aLog.Log("[FluentFTP] " + entry.Message);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -391,8 +391,8 @@ namespace keepass2android
 | 
				
			|||||||
										  string user = dlgContents.FindViewById<EditText>(Resource.Id.ftp_user).Text;
 | 
															  string user = dlgContents.FindViewById<EditText>(Resource.Id.ftp_user).Text;
 | 
				
			||||||
										  string password = dlgContents.FindViewById<EditText>(Resource.Id.ftp_password).Text;
 | 
															  string password = dlgContents.FindViewById<EditText>(Resource.Id.ftp_password).Text;
 | 
				
			||||||
										  string initialPath = dlgContents.FindViewById<EditText>(Resource.Id.ftp_initial_dir).Text;
 | 
															  string initialPath = dlgContents.FindViewById<EditText>(Resource.Id.ftp_initial_dir).Text;
 | 
				
			||||||
										  string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a).BuildFullPath(host, port, initialPath, user,
 | 
															  string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a, () => false)
 | 
				
			||||||
																										  password, encryption);
 | 
																  .BuildFullPath(host, port, initialPath, user, password, encryption);
 | 
				
			||||||
										  onStartBrowse(ftpPath);
 | 
															  onStartBrowse(ftpPath);
 | 
				
			||||||
									  });
 | 
														  });
 | 
				
			||||||
			EventHandler<DialogClickEventArgs> evtH = new EventHandler<DialogClickEventArgs>((sender, e) => onCancel());
 | 
								EventHandler<DialogClickEventArgs> evtH = new EventHandler<DialogClickEventArgs>((sender, e) => onCancel());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,7 +98,7 @@
 | 
				
			|||||||
	<string name="TrayTotp_SeedField_key">TrayTotp_SeedField_key</string>
 | 
						<string name="TrayTotp_SeedField_key">TrayTotp_SeedField_key</string>
 | 
				
			||||||
	<string name="TrayTotp_prefs_key">TrayTotp_prefs_key</string>
 | 
						<string name="TrayTotp_prefs_key">TrayTotp_prefs_key</string>
 | 
				
			||||||
  <string name="DebugLog_key">DebugLog_key</string>
 | 
					  <string name="DebugLog_key">DebugLog_key</string>
 | 
				
			||||||
  <string name="JSchDebug_key">JSchDebug_key</string>
 | 
					  <string name="FtpDebug_key">FtpDebug_key</string>
 | 
				
			||||||
  <string name="DebugLog_prefs_key">DebugLog_prefs_key</string>
 | 
					  <string name="DebugLog_prefs_key">DebugLog_prefs_key</string>
 | 
				
			||||||
  <string name="DebugLog_send_key">DebugLog_send</string>
 | 
					  <string name="DebugLog_send_key">DebugLog_send</string>
 | 
				
			||||||
  <string name="AutofillDisabledQueriesPreference_key">AutofillDisabledQueriesPreference_key</string>
 | 
					  <string name="AutofillDisabledQueriesPreference_key">AutofillDisabledQueriesPreference_key</string>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -699,7 +699,7 @@
 | 
				
			|||||||
	<string name="TrayTotp_prefs">TrayTotp</string>
 | 
						<string name="TrayTotp_prefs">TrayTotp</string>
 | 
				
			||||||
  <string name="DebugLog_prefs_prefs">Log-File for Debugging</string>
 | 
					  <string name="DebugLog_prefs_prefs">Log-File for Debugging</string>
 | 
				
			||||||
  <string name="DebugLog_title">Use log file</string>
 | 
					  <string name="DebugLog_title">Use log file</string>
 | 
				
			||||||
  <string name="JSchDebug_title">SFTP debug logging</string>
 | 
					  <string name="FtpDebug_title">FTP/SFTP debug logging</string>
 | 
				
			||||||
  <string name="DebugLog_summary">Write app output to a local log file</string>
 | 
					  <string name="DebugLog_summary">Write app output to a local log file</string>
 | 
				
			||||||
  <string name="DebugLog_send">Send debug log...</string>
 | 
					  <string name="DebugLog_send">Send debug log...</string>
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -677,10 +677,10 @@
 | 
				
			|||||||
               android:key="@string/DebugLog_send_key" />
 | 
					               android:key="@string/DebugLog_send_key" />
 | 
				
			||||||
      <CheckBoxPreference
 | 
					      <CheckBoxPreference
 | 
				
			||||||
							android:enabled="true"
 | 
												android:enabled="true"
 | 
				
			||||||
							  android:persistent="false"
 | 
												  android:persistent="true"
 | 
				
			||||||
							  android:defaultValue="false"
 | 
												  android:defaultValue="false"
 | 
				
			||||||
							  android:title="@string/JSchDebug_title"
 | 
												  android:title="@string/FtpDebug_title"
 | 
				
			||||||
							  android:key="@string/JSchDebug_key" />
 | 
												  android:key="@string/FtpDebug_key" />
 | 
				
			||||||
    </PreferenceScreen>
 | 
					    </PreferenceScreen>
 | 
				
			||||||
    </PreferenceScreen>
 | 
					    </PreferenceScreen>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -748,7 +748,7 @@ namespace keepass2android
 | 
				
			|||||||
						    new OneDrive2MyFilesFileStorage(),
 | 
											    new OneDrive2MyFilesFileStorage(),
 | 
				
			||||||
						    new OneDrive2AppFolderFileStorage(),
 | 
											    new OneDrive2AppFolderFileStorage(),
 | 
				
			||||||
                            new SftpFileStorage(LocaleManager.LocalizedAppContext, this),
 | 
					                            new SftpFileStorage(LocaleManager.LocalizedAppContext, this),
 | 
				
			||||||
							new NetFtpFileStorage(LocaleManager.LocalizedAppContext, this),
 | 
												new NetFtpFileStorage(LocaleManager.LocalizedAppContext, this, IsFtpDebugEnabled),
 | 
				
			||||||
							new WebDavFileStorage(this),
 | 
												new WebDavFileStorage(this),
 | 
				
			||||||
							new PCloudFileStorage(LocaleManager.LocalizedAppContext, this),
 | 
												new PCloudFileStorage(LocaleManager.LocalizedAppContext, this),
 | 
				
			||||||
							new MegaFileStorage(App.Context),
 | 
												new MegaFileStorage(App.Context),
 | 
				
			||||||
@@ -763,6 +763,12 @@ namespace keepass2android
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							private static bool IsFtpDebugEnabled()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
					            return PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext)
 | 
				
			||||||
 | 
									.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.FtpDebug_key), false);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void TriggerReload(Context ctx, Action<bool> actionOnResult)
 | 
							public void TriggerReload(Context ctx, Action<bool> actionOnResult)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Handler handler = new Handler(Looper.MainLooper);
 | 
								Handler handler = new Handler(Looper.MainLooper);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -179,9 +179,9 @@ namespace keepass2android
 | 
				
			|||||||
            FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug;
 | 
					            FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
 | 
					#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
 | 
				
			||||||
            FindPreference(GetString(Resource.String.JSchDebug_key)).PreferenceChange += OnJSchDebugChanged;
 | 
					            FindPreference(GetString(Resource.String.FtpDebug_key)).PreferenceChange += OnJSchDebugChanged;
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
            FindPreference(GetString(Resource.String.JSchDebug_key)).Enabled = false;
 | 
					            FindPreference(GetString(Resource.String.FtpDebug_key)).Enabled = false;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            HashSet<string> supportedLocales = new HashSet<string>() { "en", "af", "ar", "az", "be", "bg", "ca", "cs", "da", "de", "el", "es", "eu", "fa", "fi", "fr", "gl", "he", "hr", "hu", "id", "in", "it", "iw", "ja", "ko", "ml", "nb", "nl", "nn", "no", "pl", "pt", "ro", "ru", "si", "sk", "sl", "sr", "sv", "tr", "uk", "vi", "zh" };
 | 
					            HashSet<string> supportedLocales = new HashSet<string>() { "en", "af", "ar", "az", "be", "bg", "ca", "cs", "da", "de", "el", "es", "eu", "fa", "fi", "fr", "gl", "he", "hr", "hu", "id", "in", "it", "iw", "ja", "ko", "ml", "nb", "nl", "nn", "no", "pl", "pt", "ro", "ru", "si", "sk", "sl", "sr", "sv", "tr", "uk", "vi", "zh" };
 | 
				
			||||||
@@ -393,9 +393,8 @@ namespace keepass2android
 | 
				
			|||||||
                Kp2aLog.FinishLogFile();
 | 
					                Kp2aLog.FinishLogFile();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
 | 
					#if !EXCLUDE_JAVAFILESTORAGE && !NoNet
 | 
				
			||||||
            bool jschLogEnable = PreferenceManager.GetDefaultSharedPreferences(Application.Context)
 | 
					            SetJSchLogging(PreferenceManager.GetDefaultSharedPreferences(Application.Context)
 | 
				
			||||||
                .GetBoolean(Application.Context.GetString(Resource.String.JSchDebug_key), false);
 | 
					                .GetBoolean(Application.Context.GetString(Resource.String.FtpDebug_key), false));
 | 
				
			||||||
            SetJSchLogging(jschLogEnable);
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -415,6 +414,7 @@ namespace keepass2android
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            sftpStorage.SetJschLogging(enabled, logFilename);
 | 
					            sftpStorage.SetJschLogging(enabled, logFilename);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void AlgorithmPrefChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs)
 | 
					        private void AlgorithmPrefChange(object sender, Preference.PreferenceChangeEventArgs preferenceChangeEventArgs)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user