PageRenderTime 1568ms CodeModel.GetById 39ms RepoModel.GetById 0ms app.codeStats 0ms

/BluRipWpf/LogWindow.xaml.cs

http://blurip.googlecode.com/
C# | 375 lines | 327 code | 31 blank | 17 comment | 25 complexity | 4b41f1f07e07dae4dd0e868fa78e3875 MD5 | raw file
Possible License(s): GPL-2.0
  1. //BluRip - one click BluRay/m2ts to mkv converter
  2. //Copyright (C) 2009-2010 _hawk_
  3. //This program is free software; you can redistribute it and/or
  4. //modify it under the terms of the GNU General Public License
  5. //as published by the Free Software Foundation; either version 2
  6. //of the License, or (at your option) any later version.
  7. //This program is distributed in the hope that it will be useful,
  8. //but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. //GNU General Public License for more details.
  11. //You should have received a copy of the GNU General Public License
  12. //along with this program; if not, write to the Free Software
  13. //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. //Contact: hawk.ac@gmx.net
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Windows;
  20. using System.Windows.Controls;
  21. using System.Windows.Data;
  22. using System.Windows.Documents;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using System.Windows.Media.Imaging;
  26. using System.Windows.Shapes;
  27. using System.Windows.Forms;
  28. namespace BluRip
  29. {
  30. /// <summary>
  31. /// Interaktionslogik für LogWindow.xaml
  32. /// </summary>
  33. public partial class LogWindow : Window
  34. {
  35. private delegate void Message(string msg);
  36. private MainWindow mainWindow = null;
  37. public LogWindow(MainWindow mainWindow)
  38. {
  39. try
  40. {
  41. InitializeComponent();
  42. this.mainWindow = mainWindow;
  43. checkBoxAutoscroll.IsChecked = mainWindow.Settings.autoScroll;
  44. }
  45. catch (Exception ex)
  46. {
  47. Global.ErrorMsg(ex);
  48. }
  49. }
  50. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  51. {
  52. try
  53. {
  54. e.Cancel = true;
  55. this.Hide();
  56. mainWindow.UncheckLogWindow();
  57. }
  58. catch (Exception)
  59. {
  60. }
  61. }
  62. private void Window_Loaded(object sender, RoutedEventArgs e)
  63. {
  64. }
  65. public void MessageMain(string msg)
  66. {
  67. try
  68. {
  69. if (richTextBoxMainLog.Dispatcher.CheckAccess())
  70. {
  71. richTextBoxMainLog.AppendText("[" + DateTime.Now.ToString() + "] " + msg + "\r");
  72. if(checkBoxAutoscroll.IsChecked == true) richTextBoxMainLog.ScrollToEnd();
  73. }
  74. else
  75. {
  76. richTextBoxMainLog.Dispatcher.Invoke(new Message(MessageMain), new object[] { msg });
  77. }
  78. }
  79. catch (Exception)
  80. {
  81. }
  82. }
  83. public void MessageDemux(string msg)
  84. {
  85. try
  86. {
  87. if (richTextBoxDemuxLog.Dispatcher.CheckAccess())
  88. {
  89. richTextBoxDemuxLog.AppendText("[" + DateTime.Now.ToString() + "] " + msg + "\r");
  90. if (checkBoxAutoscroll.IsChecked == true) richTextBoxDemuxLog.ScrollToEnd();
  91. MessageMain(msg);
  92. }
  93. else
  94. {
  95. richTextBoxDemuxLog.Dispatcher.Invoke(new Message(MessageDemux), new object[] { msg });
  96. }
  97. }
  98. catch (Exception)
  99. {
  100. }
  101. }
  102. public void MessageCrop(string msg)
  103. {
  104. try
  105. {
  106. if (richTextBoxCropLog.Dispatcher.CheckAccess())
  107. {
  108. richTextBoxCropLog.AppendText("[" + DateTime.Now.ToString() + "] " + msg + "\r");
  109. if (checkBoxAutoscroll.IsChecked == true) richTextBoxCropLog.ScrollToEnd();
  110. MessageMain(msg);
  111. }
  112. else
  113. {
  114. richTextBoxCropLog.Dispatcher.Invoke(new Message(MessageCrop), new object[] { msg });
  115. }
  116. }
  117. catch (Exception)
  118. {
  119. }
  120. }
  121. public void MessageSubtitle(string msg)
  122. {
  123. try
  124. {
  125. if (richTextBoxSubtitleLog.Dispatcher.CheckAccess())
  126. {
  127. richTextBoxSubtitleLog.AppendText("[" + DateTime.Now.ToString() + "] " + msg + "\r");
  128. if (checkBoxAutoscroll.IsChecked == true) richTextBoxSubtitleLog.ScrollToEnd();
  129. MessageMain(msg);
  130. }
  131. else
  132. {
  133. richTextBoxSubtitleLog.Dispatcher.Invoke(new Message(MessageSubtitle), new object[] { msg });
  134. }
  135. }
  136. catch (Exception)
  137. {
  138. }
  139. }
  140. public void MessageEncode(string msg)
  141. {
  142. try
  143. {
  144. if (richTextBoxEncodeLog.Dispatcher.CheckAccess())
  145. {
  146. richTextBoxEncodeLog.AppendText("[" + DateTime.Now.ToString() + "] " + msg + "\r");
  147. if (checkBoxAutoscroll.IsChecked == true) richTextBoxEncodeLog.ScrollToEnd();
  148. MessageMain(msg);
  149. }
  150. else
  151. {
  152. richTextBoxEncodeLog.Dispatcher.Invoke(new Message(MessageEncode), new object[] { msg });
  153. }
  154. }
  155. catch (Exception)
  156. {
  157. }
  158. }
  159. public void MessageMux(string msg)
  160. {
  161. try
  162. {
  163. if (richTextBoxMuxLog.Dispatcher.CheckAccess())
  164. {
  165. richTextBoxMuxLog.AppendText("[" + DateTime.Now.ToString() + "] " + msg + "\r");
  166. if (checkBoxAutoscroll.IsChecked == true) richTextBoxMuxLog.ScrollToEnd();
  167. MessageMain(msg);
  168. }
  169. else
  170. {
  171. richTextBoxMuxLog.Dispatcher.Invoke(new Message(MessageMux), new object[] { msg });
  172. }
  173. }
  174. catch (Exception)
  175. {
  176. }
  177. }
  178. private void menuLogClearAll_Click(object sender, RoutedEventArgs e)
  179. {
  180. try
  181. {
  182. richTextBoxMainLog.Document.Blocks.Clear();
  183. richTextBoxDemuxLog.Document.Blocks.Clear();
  184. richTextBoxCropLog.Document.Blocks.Clear();
  185. richTextBoxSubtitleLog.Document.Blocks.Clear();
  186. richTextBoxEncodeLog.Document.Blocks.Clear();
  187. richTextBoxMuxLog.Document.Blocks.Clear();
  188. }
  189. catch (Exception)
  190. {
  191. }
  192. }
  193. public void ClearAll()
  194. {
  195. try
  196. {
  197. menuLogClearAll_Click(null, null);
  198. }
  199. catch (Exception)
  200. {
  201. }
  202. }
  203. private void menuLogClear_Click(object sender, RoutedEventArgs e)
  204. {
  205. try
  206. {
  207. int index = tabControlLog.SelectedIndex;
  208. switch (index)
  209. {
  210. case 0:
  211. richTextBoxMainLog.Document.Blocks.Clear();
  212. break;
  213. case 1:
  214. richTextBoxDemuxLog.Document.Blocks.Clear();
  215. break;
  216. case 2:
  217. richTextBoxCropLog.Document.Blocks.Clear();
  218. break;
  219. case 3:
  220. richTextBoxSubtitleLog.Document.Blocks.Clear();
  221. break;
  222. case 4:
  223. richTextBoxEncodeLog.Document.Blocks.Clear();
  224. break;
  225. case 5:
  226. richTextBoxMuxLog.Document.Blocks.Clear();
  227. break;
  228. default:
  229. break;
  230. }
  231. }
  232. catch (Exception)
  233. {
  234. }
  235. }
  236. private void menuLogSave_Click(object sender, RoutedEventArgs e)
  237. {
  238. try
  239. {
  240. int index = tabControlLog.SelectedIndex;
  241. switch (index)
  242. {
  243. case 0:
  244. SaveLog(richTextBoxMainLog);
  245. break;
  246. case 1:
  247. SaveLog(richTextBoxDemuxLog);
  248. break;
  249. case 2:
  250. SaveLog(richTextBoxCropLog);
  251. break;
  252. case 3:
  253. SaveLog(richTextBoxSubtitleLog);
  254. break;
  255. case 4:
  256. SaveLog(richTextBoxEncodeLog);
  257. break;
  258. case 5:
  259. SaveLog(richTextBoxMuxLog);
  260. break;
  261. default:
  262. break;
  263. }
  264. }
  265. catch (Exception)
  266. {
  267. }
  268. }
  269. private void Window_LocationChanged(object sender, EventArgs e)
  270. {
  271. try
  272. {
  273. if(IsActive)
  274. mainWindow.UpdateDiffLog();
  275. }
  276. catch (Exception)
  277. {
  278. }
  279. }
  280. private void SaveLog(System.Windows.Controls.RichTextBox rtb)
  281. {
  282. try
  283. {
  284. SaveFileDialog sfd = new SaveFileDialog();
  285. sfd.Filter = Global.Res("LogSaveFileFilter");
  286. if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  287. {
  288. SaveLog(GetText(rtb), sfd.FileName);
  289. }
  290. }
  291. catch (Exception)
  292. {
  293. }
  294. }
  295. private string GetText(System.Windows.Controls.RichTextBox rtb)
  296. {
  297. try
  298. {
  299. TextRange textRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
  300. return textRange.Text;
  301. }
  302. catch (Exception)
  303. {
  304. return "";
  305. }
  306. }
  307. public void SaveMainLog(string filename)
  308. {
  309. try
  310. {
  311. SaveLog(GetText(richTextBoxMainLog), filename);
  312. }
  313. catch (Exception)
  314. {
  315. }
  316. }
  317. private void SaveLog(string log, string filename)
  318. {
  319. try
  320. {
  321. string[] lines = log.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
  322. string tmp = "";
  323. foreach (string s in lines) tmp += s.Trim() + "\r\n";
  324. System.IO.File.WriteAllText(filename, tmp);
  325. }
  326. catch (Exception)
  327. {
  328. }
  329. }
  330. private void checkBoxAutoscroll_Checked(object sender, RoutedEventArgs e)
  331. {
  332. try
  333. {
  334. if (mainWindow != null)
  335. {
  336. mainWindow.Settings.autoScroll = (bool)checkBoxAutoscroll.IsChecked;
  337. }
  338. }
  339. catch (Exception)
  340. {
  341. }
  342. }
  343. }
  344. }