public override void OnPanelVisible() { Username = Settings.UpdaterServiceUsername; LZMAStoragePath = Settings.UpdaterServiceLZMAStoragePath; ManifestStoragePath = Settings.UpdaterServiceManifestStoragePath; Password_TextBox.Password = Settings.DecryptUpdaterServicePassword(); var pw = Settings.DecryptUpdaterServicePassword(); SettingsExpanded = string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(LZMAStoragePath) || string.IsNullOrWhiteSpace(ManifestStoragePath) || string.IsNullOrWhiteSpace(Password_TextBox.Password) || mod == null; if (mod != null) { if (string.IsNullOrWhiteSpace(mod.UpdaterServiceServerFolder)) { HideChangelogArea(); CurrentActionText = M3L.GetString(M3L.string_modMissingUpdatesDescriptor); return; } } if (SettingsExpanded) { CurrentActionText = M3L.GetString(M3L.string_enterYourME3TweaksUpdaterServiceInformation); SettingsSubtext = M3L.GetString(M3L.string_pressSaveToValidateSettings); } else if (mod != null) { LZMAStoragePath = LZMAStoragePath.Trim(); ManifestStoragePath = ManifestStoragePath.Trim(); Username = Username.Trim(); CurrentActionText = M3L.GetString(M3L.string_authenticatingToME3Tweaks); CheckAuth(authCompletedCallback: (result) => { if (result is bool?) { var authed = (bool?)result; if (authed.HasValue && authed.Value) { StartPreparingModWrapper(); } } else { if (SettingsExpanded) { CurrentActionText = M3L.GetString(M3L.string_enterUpdaterServiceSettings); SettingsSubtext = M3L.GetString(M3L.string_pressSaveToValidateSettings); } } }); } }
private void CheckAuth(string pwOverride = null, Action <object> authCompletedCallback = null) { NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"UpdaterServiceAuthCheck"); nbw.DoWork += (a, b) => { b.Result = false; string host = @"ftp.me3tweaks.com"; string username = Username; string password = pwOverride ?? Password_TextBox.Password; if (string.IsNullOrWhiteSpace(password)) { return; } using (SftpClient sftp = new SftpClient(host, username, password)) { string currentOp = @"Connecting"; try { sftp.Connect(); currentOp = M3L.GetString(M3L.string_checkingLZMAStorageDirectory); sftp.ChangeDirectory(LZMAStoragePath.Trim()); currentOp = M3L.GetString(M3L.string_checkingManifestsStorageDirectory); sftp.ChangeDirectory(ManifestStoragePath.Trim()); b.Result = true; } catch (Exception e) { Log.Information($@"Error logging in during operation '{currentOp}': " + e.Message); b.Result = M3L.GetString(M3L.string_interp_errorValidatingSettingsXY, currentOp, e.Message); } } }; nbw.RunWorkerCompleted += (a, b) => { if (b.Error != null) { Log.Error($@"Exception occurred in {nbw.Name} thread: {b.Error.Message}"); } Log.Information(@"Auth checked"); OperationInProgress = false; authCompletedCallback?.Invoke(b.Result); }; OperationInProgress = true; nbw.RunWorkerAsync(); }