FormWinmergePathSetting.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace ProcedureComparer
  11. {
  12. public partial class FormWinmergePathSetting : Form
  13. {
  14. private const string WINMERGE_PROGRAM_NAME = "WinMergeU.exe";
  15. private const string DEFAULT_WINMERGE_PATH = @"C:\Program Files\WinMerge";
  16. private const string INI_KEY_NAME_SECTION = "Config";
  17. private const string INI_KEY_NAME_PATH = "WinMergePath";
  18. private string _ConfigIniPath = string.Empty;
  19. private string _CurrentPath = string.Empty;
  20. private IniManager _IniManager = new IniManager();
  21. public FormWinmergePathSetting(string configIniPath)
  22. {
  23. InitializeComponent();
  24. _ConfigIniPath = configIniPath;
  25. }
  26. private void FormWinmergePathSetting_Load(object sender, EventArgs e)
  27. {
  28. _CurrentPath = _IniManager.GetIniValue(_ConfigIniPath, INI_KEY_NAME_SECTION, INI_KEY_NAME_PATH);
  29. if (CheckWinMergePath(_CurrentPath))
  30. {
  31. tb_Path.Text = _CurrentPath;
  32. }
  33. else
  34. {
  35. _IniManager.SetIniValue(_ConfigIniPath, INI_KEY_NAME_SECTION, INI_KEY_NAME_PATH, string.Empty);
  36. _CurrentPath = string.Empty;
  37. }
  38. }
  39. private bool CheckWinMergePath(string path)
  40. {
  41. return File.Exists(path);
  42. }
  43. private void btn_Path_Click(object sender, EventArgs e)
  44. {
  45. OpenFileDialog openFileDialog = new OpenFileDialog();
  46. openFileDialog.Filter = "실행 파일 (*.exe)|*.exe";
  47. openFileDialog.InitialDirectory = DEFAULT_WINMERGE_PATH;
  48. if (CheckWinMergePath(_CurrentPath))
  49. {
  50. openFileDialog.InitialDirectory = _CurrentPath;
  51. }
  52. if (DialogResult.OK == openFileDialog.ShowDialog())
  53. {
  54. if (WINMERGE_PROGRAM_NAME != ShortNameFromFile(openFileDialog.FileName))
  55. MessageBox.Show($"선택한 파일이 WinMerge 프로그램이 아닙니다.\r\n대상 프로그램명 : {WINMERGE_PROGRAM_NAME}", "안내", MessageBoxButtons.OK, MessageBoxIcon.Information);
  56. else
  57. tb_Path.Text = openFileDialog.FileName;
  58. }
  59. }
  60. private string ShortNameFromFile(string fileName)
  61. {
  62. int num = fileName.LastIndexOfAny(new char[2] { '\\', ':' }, fileName.Length - 1, fileName.Length);
  63. if (num > 0)
  64. {
  65. return fileName.Substring(num + 1, fileName.Length - num - 1);
  66. }
  67. return fileName;
  68. }
  69. private void btn_Save_Click(object sender, EventArgs e)
  70. {
  71. if (tb_Path.Text != string.Empty)
  72. {
  73. _IniManager.SetIniValue(_ConfigIniPath, INI_KEY_NAME_SECTION, INI_KEY_NAME_PATH, tb_Path.Text);
  74. MessageBox.Show("경로가 저장 되었습니다.");
  75. }
  76. else
  77. MessageBox.Show("경로가 설정되지 않았습니다.");
  78. }
  79. }
  80. }