public CommandResult SerialConfig() { SerialTerminalConnection stc = _connection as SerialTerminalConnection; if (stc == null) { return(CommandResult.Failed); } try { SerialConfigForm f = new SerialConfigForm(); f.ApplyParam(stc); if (GCUtil.ShowModalDialog(GApp.Frame, f) == DialogResult.OK) { return(CommandResult.Success); } else { return(CommandResult.Cancelled); } } catch (NotSupportedException) { GUtil.Warning(GApp.Frame, GApp.Strings.GetString("Message.SerialConfigIsSerialOnly")); return(CommandResult.Failed); } }
public CommandResult SaveShortCut() { //コネクションがあればファイルを尋ねる SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = GApp.Strings.GetString("Util.SaveShortcut"); dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.DefaultExt = "gts"; dlg.AddExtension = true; dlg.Filter = "Terminal Shortcut(*.gts)|*.gts"; if (GCUtil.ShowModalDialog(GApp.Frame, dlg) == DialogResult.OK) { try { ConfigNode cn = new ConfigNode("poderosa-shortcut"); _connection.Param.Export(cn); XmlWriter wr = XMLUtil.CreateDefaultWriter(dlg.FileName); DOMNodeConverter.Write(wr, cn); wr.WriteEndDocument(); wr.Close(); GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); return(CommandResult.Success); } catch (Exception ex) { MessageBox.Show(GEnv.Frame, ex.Message, GApp.Strings.GetString("Message.SaveError"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(CommandResult.Failed); } } else { return(CommandResult.Cancelled); } }
public CommandResult ShowSendFileDialog() { if (_frame.XModemDialog != null) { if (!_frame.XModemDialog.Receiving) { return(CommandResult.Ignored); } else { GUtil.Warning(GEnv.Frame, GApp.Strings.GetString("Message.NowFileReceiving")); return(CommandResult.Failed); } } if (GEnv.Connections.ActiveTag == null) { return(CommandResult.Failed); } XModemDialog dlg = new XModemDialog(); dlg.Owner = _frame; dlg.Receiving = false; dlg.ConnectionTag = GEnv.Connections.ActiveTag; _frame.CenteringDialog(dlg); dlg.Show(); _frame.XModemDialog = dlg; return(CommandResult.Success); }
public CommandResult RenameTab() { try { InputBox box = new InputBox(); box.AllowsZeroLenString = false; box.Text = GApp.Strings.GetString("Util.RenameTab"); box.Content = _connection.Param.Caption; if (GCUtil.ShowModalDialog(GApp.Frame, box) == DialogResult.OK) { _connection.Param.Caption = box.Content; GApp.ConnectionHistory.ReplaceIdenticalParam(_connection.Param); GApp.Frame.AdjustMRUMenu(); GApp.Frame.RefreshConnection(GEnv.Connections.FindTag(_connection)); return(CommandResult.Success); } else { return(CommandResult.Cancelled); } } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); GUtil.Warning(GApp.Frame, ex.Message); return(CommandResult.Failed); } }
public static Keys ParseKey(string[] value) //modifier込みでパース { Keys modifier = Keys.None; for (int i = 0; i < value.Length - 1; i++) //最後以外 { string m = value[i]; if (m == "Alt") { modifier |= Keys.Alt; } else if (m == "Shift") { modifier |= Keys.Shift; } else if (m == "Ctrl") { modifier |= Keys.Control; } else { throw new Exception(m + " is unknown modifier"); } } return(modifier | GUtil.ParseKey(value[value.Length - 1])); }
static void Main(string[] args) { //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new MainForm()); try { if (args.Length > 0) { if (InterProcessService.SendShortCutFileNameToExistingInstance(args[0])) { return; } } GApp.Run(args); } catch (Exception e) { #if DEBUG Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); #else GUtil.ReportCriticalError(e); #endif } }
public CommandResult CopyToFile() { if (GEnv.TextSelection.IsEmpty) { return(CommandResult.Ignored); } SaveFileDialog dlg = new SaveFileDialog(); dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.Title = GApp.Strings.GetString("Util.DestinationToSave"); dlg.Filter = "All Files(*.*)|*.*"; string selectedtext = GEnv.TextSelection.GetSelectedText(); //このファイル選択ダイアログを閉じた直後にOnGotFocusが発生し、テキスト選択がクリアされることがあるので事前に取得しておく if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK) { GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); try { StreamWriter wr = new StreamWriter(new FileStream(dlg.FileName, FileMode.Create), Encoding.Default); wr.Write(selectedtext); wr.Close(); return(CommandResult.Success); } catch (Exception ex) { GUtil.Warning(GApp.Frame, ex.Message); return(CommandResult.Failed); } } else { return(CommandResult.Cancelled); } }
public ConnectionTag SilentOpenShortCut(string filename) { XmlReader r = null; try { if (GApp.Frame.WindowState == FormWindowState.Minimized) { GApp.Frame.WindowState = FormWindowState.Normal; } ConfigNode cn = DOMNodeConverter.Read(XMLUtil.FileToDOM(filename).DocumentElement); TerminalParam param = TerminalParam.CreateFromConfigNode(cn); param.FeedLogOption(); return(SilentNewConnection(param)); } catch (Exception ex) { GUtil.Warning(_frame, ex.Message); } finally { if (r != null) { r.Close(); } } return(null); }
private void CopyToClipboard(string data) { try { Clipboard.SetDataObject(data, false); } catch (Exception ex) { //きわめて稀にだがここで失敗するらしい GUtil.Warning(GEnv.Frame, ex.Message); } }
public static void OnThreadException(object sender, ThreadExceptionEventArgs e) { GUtil.ReportThreadException(e.Exception); /* * string msg = DateTime.Now.ToString() + " : " + "OnThreadException() sender=" + sender.ToString() + "\r\n StackTrace=" + new StackTrace(true).ToString(); * Debug.WriteLine(msg); * GUtil.WriteDebugLog(msg); * throw e.Exception; */ }
public CommandResult Close() { try { _connection.Disconnect(); _connection.Close(); } catch (Exception ex) { //ここでエラーが発生しても処理は続行してアプリ自体は実行を継続 GUtil.Warning(GEnv.Frame, GEnv.Strings.GetString("Message.ConnectionCommandTarget.CloseError") + ex.Message); } bool active = _connection == GEnv.Connections.ActiveConnection; ConnectionTag ct = GEnv.Connections.FindTag(_connection); //Debug.WriteLine("ct==null? " + (ct==null)); if (ct == null) { return(CommandResult.Ignored); } TerminalPane pane = ct.AttachedPane; ct.IsTerminated = true; GEnv.Frame.RemoveConnection(ct); ConnectionTag next = GEnv.Connections.GetCandidateOfActivation(ct.PositionIndex, ct); GEnv.Connections.Remove(_connection); if (next != null) { if (pane != null) { pane.Attach(next); } if (active) { GEnv.Frame.ActivateConnection(next); //もともとアクティブでない接続が切れたときは変更しない } } else { if (pane != null) { pane.FakeVisible = false; pane.Detach(); } GEnv.Frame.RefreshConnection(null); } if (GEnv.Options.QuitAppWithLastPane && GEnv.Connections.Count == 0) { GEnv.Frame.AsForm().Close(); } return(CommandResult.Success); }
internal bool CheckPaneCount() { if (GEnv.Connections.Count >= 32) { GUtil.Warning(_frame, GApp.Strings.GetString("Messages.ConnectionLimitExceeds")); return(false); } else { return(true); } }
private static void SaveEnvironment() { //OptionDialogで、レジストリへの書き込み権限がないとOptionPreservePlaceは変更できないようにしてあるのでWritableなときだけ書いておけばOK if (IsRegistryWritable) { RegistryKey g = Registry.CurrentUser.CreateSubKey(GCConst.REGISTRY_PATH); g.SetValue("option-place", EnumDescAttribute.For(typeof(OptionPreservePlace)).GetName(_options.OptionPreservePlace)); } if (Win32.WaitForSingleObject(_globalMutex, 10000) != Win32.WAIT_OBJECT_0) { throw new Exception("Global mutex lock error"); } try { string dir = GetOptionDirectory(_options.OptionPreservePlace); TextWriter wr = null; try { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } _sshKnownHosts.WriteTo(dir + "ssh_known_hosts"); wr = new StreamWriter(dir + "options.conf", false, Encoding.Default); } catch (Exception ex) { //GUtil.ReportCriticalError(ex); GUtil.Warning(Form.ActiveForm, String.Format(GApp.Strings.GetString("Message.GApp.WriteError"), ex.Message, dir)); } if (wr != null) { try { ConfigNode node = new ConfigNode("poderosa"); _options.Save(node); _history.Save(node); _macroManager.Save(node); wr.WriteLine(GCConst.CONFIG_HEADER); node.WriteTo(wr); wr.Close(); } catch (Exception ex) { GUtil.ReportCriticalError(ex); } } } finally { Win32.ReleaseMutex(_globalMutex); } }
public CommandResult PasteFromFile() { OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.Title = GApp.Strings.GetString("Util.SourceToLoad"); dlg.Filter = "All Files(*.*)|*.*"; ConnectionTag ct = GEnv.Connections.FindTag(_connection); if (ct.ModalTerminalTask != null) { return(CommandResult.Denied); } if (GCUtil.ShowModalDialog(GApp.Frame, dlg) == DialogResult.OK) { GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); try { StreamReader re = new StreamReader(new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read), _connection.Param.EncodingProfile.Encoding); if (new FileInfo(dlg.FileName).Length > 0x1000) //4KB以上は非同期 { SendingLargeText dlg2 = new SendingLargeText(new PasteProcessor(ct, re)); re.Close(); if (GCUtil.ShowModalDialog(GApp.Frame, dlg2) == DialogResult.OK) { return(CommandResult.Success); } else { return(CommandResult.Cancelled); } } else { PasteProcessor p = new PasteProcessor(ct, re); p.Perform(); re.Close(); } //GEnv.Frame.StatusBar.IndicateSendData(); return(CommandResult.Success); } catch (Exception ex) { GUtil.Warning(GEnv.Frame, ex.Message); return(CommandResult.Failed); } } else { return(CommandResult.Cancelled); } }
protected CommandResult PasteMain(string value) { ConnectionTag tag = GEnv.Connections.FindTag(_connection); PasteProcessor p = new PasteProcessor(tag, value); try { p.Perform(); return(CommandResult.Success); } catch (Exception ex) { Debug.WriteLine(ex.StackTrace); GUtil.Warning(GEnv.Frame, GEnv.Strings.GetString("Message.ConnectionCommandTarget.SendError") + ex.Message); return(CommandResult.Failed); } }
public CommandResult CloseAll() { if (GApp.Options.AskCloseOnExit && GEnv.Connections.LiveConnectionsExist) { if (GUtil.AskUserYesNo(_frame, GApp.Strings.GetString("Message.AskExitEvenIfConnected"), MessageBoxIcon.Exclamation) == DialogResult.No) { return(CommandResult.Cancelled); } } GEnv.Connections.CloseAllConnections(); _frame.RemoveAllConnections(); _frame.AdjustTerminalUI(false, null); GEnv.Connections.Clear(); return(CommandResult.Success); }
//既存のファイルであったり、書き込み不可能だったら警告する public static LogFileCheckResult CheckLogFileName(string path, Form parent) { try { if (path.Length == 0) { GUtil.Warning(parent, GApp.Strings.GetString("Message.CheckLogFileName.EmptyPath")); return(LogFileCheckResult.Cancel); } if (File.Exists(path)) { if ((FileAttributes.ReadOnly & File.GetAttributes(path)) != (FileAttributes)0) { GUtil.Warning(parent, String.Format(GApp.Strings.GetString("Message.CheckLogFileName.NotWritable"), path)); return(LogFileCheckResult.Cancel); } Poderosa.Forms.ThreeButtonMessageBox mb = new Poderosa.Forms.ThreeButtonMessageBox(); mb.Message = String.Format(GApp.Strings.GetString("Message.CheckLogFileName.AlreadyExist"), path); mb.Text = GApp.Strings.GetString("Util.CheckLogFileName.Caption"); mb.YesButtonText = GApp.Strings.GetString("Util.CheckLogFileName.OverWrite"); mb.NoButtonText = GApp.Strings.GetString("Util.CheckLogFileName.Append"); mb.CancelButtonText = GApp.Strings.GetString("Util.CheckLogFileName.Cancel"); switch (GCUtil.ShowModalDialog(parent, mb)) { case DialogResult.Cancel: return(LogFileCheckResult.Cancel); case DialogResult.Yes: //上書き return(LogFileCheckResult.Create); case DialogResult.No: //追記 return(LogFileCheckResult.Append); default: break; } } return(LogFileCheckResult.Create); //!!書き込み可能なディレクトリにあることを確認すればなおよし } catch (Exception ex) { GUtil.Warning(parent, ex.Message); return(LogFileCheckResult.Error); } }
private void BadCharDetected() { switch (GEnv.Options.WarningOption) { case WarningOption.StatusBar: GEnv.Frame.SetStatusBarText(_msg); break; case WarningOption.MessageBox: { WarningWithDisableOption dlg = new WarningWithDisableOption(_msg); if (GUtil.ShowModalDialog(GEnv.Frame, dlg) == DialogResult.OK && dlg.CheckedDisableOption) { GEnv.Options.WarningOption = WarningOption.Ignore; } break; } } }
public CommandResult OpenShortCut(string filename) { try { if (GApp.Frame.WindowState == FormWindowState.Minimized) { GApp.Frame.WindowState = FormWindowState.Normal; } ConfigNode cn = DOMNodeConverter.Read(XMLUtil.FileToDOM(filename).DocumentElement); TerminalParam param = TerminalParam.CreateFromConfigNode(cn); param.FeedLogOption(); NewConnection(param); return(CommandResult.Success); } catch (Exception ex) { GUtil.Warning(_frame, ex.Message); return(CommandResult.Failed); } }
public CommandResult OpenShortCutWithDialog() { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = GApp.Strings.GetString("Util.OpenShortcutFile"); dlg.Multiselect = false; dlg.InitialDirectory = GApp.Options.DefaultFileDir; dlg.DefaultExt = "gts"; dlg.AddExtension = true; dlg.Filter = "Terminal Shortcut(*.gts)|*.gts|All Files(*.*)|*.*"; if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK) { GApp.Options.DefaultFileDir = GUtil.FileToDir(dlg.FileName); return(OpenShortCut(dlg.FileName)); } return(CommandResult.Cancelled); }
public CommandResult LaunchPortforwarding() { try { Process p = Process.Start(GApp.BaseDirectory + "\\portforwarding.exe"); if (p == null) { GUtil.Warning(GApp.Frame, GApp.Strings.GetString("Message.PFLaunchFailed")); return(CommandResult.Failed); } else { return(CommandResult.Success); } } catch (Exception ex) { GUtil.Warning(GApp.Frame, GApp.Strings.GetString("Message.PFLaunchFailed") + "\n" + ex.Message); return(CommandResult.Failed); } }
public CommandResult SendBreak() { if (_connection.IsClosed) { return(CommandResult.Ignored); } if (GEnv.Connections.FindTag(_connection).ModalTerminalTask != null) { return(CommandResult.Denied); } try { _connection.SendBreak(); return(CommandResult.Success); } catch (NotSupportedException) { GUtil.Warning(GEnv.Frame, GEnv.Strings.GetString("Message.ConnectionCommandTarget.BreakCondition")); return(CommandResult.Failed); } }
public virtual void ProcessMessage(IntPtr wParam, IntPtr lParam) { switch ((Service)(int)wParam) { case Service.Warning: GUtil.Warning(GEnv.Frame, _msg); break; case Service.Information: GUtil.Warning(GEnv.Frame, _msg, MessageBoxIcon.Information); break; case Service.AskUserYesNo: _dialogResult = GUtil.AskUserYesNo(GEnv.Frame, _msg); break; case Service.DisconnectedFromServer: DisconnectedFromServer(); break; case Service.IndicateBell: GEnv.Frame.IndicateBell(); break; case Service.CriticalError: GUtil.ReportCriticalError(_exception); break; case Service.InvalidCharDetected: //いまはこの3つはメッセージテキストでしか区別しない case Service.UnsupportedCharSetDetected: case Service.UnsupportedEscapeSequence: case Service.InvalidDocumentOperation: BadCharDetected(); break; case Service.RefreshConnection: GEnv.Frame.RefreshConnection(GEnv.Connections.FindTag(_connection)); break; } }
public CommandResult Reproduce() { if (!GApp.GlobalCommandTarget.CheckPaneCount()) { return(CommandResult.Failed); } try { ConnectionTag con = _connection.Reproduce(); if (con == null) { return(CommandResult.Failed); //接続失敗時はこの中でメッセージが出ている } if (_connection.IsClosed) //再接続 { ConnectionTag old = GEnv.Connections.FindTag(_connection); con.Document.InsertBefore(old.Document, _connection.TerminalHeight); GEnv.Connections.Replace(old, con); con.ImportProperties(old); if (old.AttachedPane != null) { old.AttachedPane.Attach(con); } con.Receiver.Listen(); GApp.Frame.ReplaceConnection(old, con); GApp.Frame.RefreshConnection(con); GApp.GlobalCommandTarget.ActivateConnection(con.Connection); } else { GApp.GlobalCommandTarget.AddNewTerminal(con); } return(CommandResult.Success); } catch (Exception ex) { GUtil.Warning(GApp.Frame, ex.Message); return(CommandResult.Failed); } }
private static void LoadConfigFiles(string dir, InitialAction act) { if (Win32.WaitForSingleObject(_globalMutex, 10000) != Win32.WAIT_OBJECT_0) { throw new Exception("Global mutex lock error"); } try { string optionfile = dir + "options.conf"; bool config_loaded = false; bool macro_loaded = false; TextReader reader = null; try { if (File.Exists(optionfile)) { reader = new StreamReader(File.Open(optionfile, FileMode.Open, FileAccess.Read), Encoding.Default); if (VerifyConfigHeader(reader)) { ConfigNode root = new ConfigNode("root", reader).FindChildConfigNode("poderosa"); if (root != null) { _options.Load(root); config_loaded = true; _history.Load(root); _macroManager.Load(root); macro_loaded = true; } } } } catch (Exception ex) { //_errorOccurredOnBoot = true; Debug.WriteLine(ex.StackTrace); GUtil.WriteDebugLog(ex.StackTrace); act.AddMessage("Failed to read the configuration file.\n" + ex.Message); } finally { if (!config_loaded) { _options.Init(); } if (!macro_loaded) { _macroManager.SetDefault(); } if (reader != null) { reader.Close(); } } GEnv.Options = _options; //これでDefaultRenderProfileが初期化される string kh = dir + "ssh_known_hosts"; if (File.Exists(kh)) { try { _sshKnownHosts.Load(kh); } catch (Exception ex) { _sshKnownHosts.Clear(); act.AddMessage("Failed to read the 'ssh_known_hosts' file.\n" + ex.Message); } } } finally { Win32.ReleaseMutex(_globalMutex); } }
public override void ImportFrom(object holder, ConfigNode node) { _fieldInfo.SetValue(holder, GUtil.ParseColor(node[_externalName], ToColor(_initial))); }