/* ----------------------------------------------------------------- */ /// /// ShowMessage /// /// <summary> /// エラーメッセージの表示、およびログファイルへの書き込みを行います。 /// </summary> /// /// <remarks> /// 複数のエラーメッセージが存在する場合、ダイアログには最後の Error /// レベル以上のメッセージを表示します。 /// </remarks> /// /* ----------------------------------------------------------------- */ private void ShowMessage() { CubePdf.Message error = null; foreach (var message in _messages) { Trace.WriteLine(message.ToString()); if (message.Level == Message.Levels.Fatal || message.Level == Message.Levels.Error || message.Level == Message.Levels.Warn) { error = message; } } if (error != null) { ShowMessage(error); } }
/* ----------------------------------------------------------------- */ /// /// IsValidOutput /// /// <summary> /// 出力先パスが正しいかどうかをチェックします。出力先パスが指定 /// されていない場合はエラーメッセージを表示します。また、指定された /// 出力先パスが既に存在する場合には確認ダイアログを表示します。 /// </summary> /// /* ----------------------------------------------------------------- */ private bool IsValidOutput(int do_existed_file) { if (string.IsNullOrEmpty(OutputPathTextBox.Text)) { ShowMessage(new CubePdf.Message(Message.Levels.Error, Properties.Resources.FileNotSpecified)); return(false); } var extension = IoEx.Path.GetExtension(OutputPathTextBox.Text); var compared = Parameter.GetExtension(Translator.ToFileType(FileTypeCombBox.SelectedIndex)); if (extension != compared) { OutputPathTextBox.Text += compared; } // パスは 260 文字未満、ディレクトリ名は 248 文字未満と言う Windows パス制限のチェック if (OutputPathTextBox.TextLength >= 260 || IoEx.Path.GetDirectoryName(OutputPathTextBox.Text).Length >= 248) { ShowMessage(new CubePdf.Message(Message.Levels.Error, Properties.Resources.TooLongFilenam)); return(false); } if (IoEx.File.Exists(OutputPathTextBox.Text) && Translator.ToExistedFile(ExistedFileComboBox.SelectedIndex) != Parameter.ExistedFiles.Rename) { var message = new CubePdf.Message(Message.Levels.Warn, string.Format(Properties.Resources.FileExists, OutputPathTextBox.Text, Appearance.GetString((Parameter.ExistedFiles)do_existed_file))); return(ShowMessage(message, MessageBoxButtons.OKCancel) != DialogResult.Cancel); } else { return(true); } }
/* ----------------------------------------------------------------- */ /// /// ShowMessage /// /// <summary> /// メッセージを表示します。 /// </summary> /// /* ----------------------------------------------------------------- */ private DialogResult ShowMessage(CubePdf.Message message, MessageBoxButtons button = MessageBoxButtons.OK) { var title = Properties.Resources.InfoTitle; var icon = MessageBoxIcon.Information; switch (message.Level) { case Message.Levels.Fatal: case Message.Levels.Error: title = Properties.Resources.ErrorTitle; icon = MessageBoxIcon.Error; break; case Message.Levels.Warn: title = Properties.Resources.WarningTitle; icon = MessageBoxIcon.Warning; break; default: break; } return(MessageBox.Show(message.Value, title, button, icon)); }
/* ----------------------------------------------------------------- */ /// /// IsValidOutput /// /// <summary> /// 出力先パスが正しいかどうかをチェックします。出力先パスが指定 /// されていない場合はエラーメッセージを表示します。また、指定された /// 出力先パスが既に存在する場合には確認ダイアログを表示します。 /// </summary> /// /* ----------------------------------------------------------------- */ private bool IsValidOutput(int do_existed_file) { if (string.IsNullOrEmpty(OutputPathTextBox.Text)) { ShowMessage(new CubePdf.Message(Message.Levels.Error, Properties.Resources.FileNotSpecified)); return false; } var extension = IoEx.Path.GetExtension(OutputPathTextBox.Text); var compared = Parameter.GetExtension(Translator.ToFileType(FileTypeCombBox.SelectedIndex)); if (extension != compared) OutputPathTextBox.Text += compared; // パスは 260 文字未満、ディレクトリ名は 248 文字未満と言う Windows パス制限のチェック if (OutputPathTextBox.TextLength >= 260 || IoEx.Path.GetDirectoryName(OutputPathTextBox.Text).Length >= 248) { ShowMessage(new CubePdf.Message(Message.Levels.Error, Properties.Resources.TooLongFilenam)); return false; } if (IoEx.File.Exists(OutputPathTextBox.Text) && Translator.ToExistedFile(ExistedFileComboBox.SelectedIndex) != Parameter.ExistedFiles.Rename) { var message = new CubePdf.Message(Message.Levels.Warn, string.Format(Properties.Resources.FileExists, OutputPathTextBox.Text, Appearance.GetString((Parameter.ExistedFiles)do_existed_file))); return ShowMessage(message, MessageBoxButtons.OKCancel) != DialogResult.Cancel; } else return true; }