OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / HandBrake.Framework / Services / ErrorService.cs
1 /*  ErrorService.cs $\r
2     This file is part of the HandBrake source code.\r
3     Homepage: <http://handbrake.fr>.\r
4     It may be used under the terms of the GNU General Public License. */\r
5 \r
6 namespace HandBrake.Framework.Services\r
7 {\r
8     using System;\r
9     using System.IO;\r
10     using System.Threading;\r
11 \r
12     using HandBrake.Framework.Services.Interfaces;\r
13     using HandBrake.Framework.Views;\r
14 \r
15     /// <summary>\r
16     /// The Error Service\r
17     /// </summary>\r
18     public class ErrorService : IErrorService\r
19     {\r
20         /// <summary>\r
21         /// Show an Error Window\r
22         /// </summary>\r
23         /// <param name="shortError">\r
24         /// The short error message for the user to read\r
25         /// </param>\r
26         /// <param name="longError">\r
27         /// Exception string or advanced details\r
28         /// </param>\r
29         public void ShowError(string shortError, string longError)\r
30         {\r
31             try\r
32             {\r
33                 Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));\r
34                 newThread.Start(shortError + Environment.NewLine + longError);\r
35             }\r
36             catch (Exception)\r
37             {\r
38                 // Do Nothing\r
39             }\r
40 \r
41             ExceptionWindow window = new ExceptionWindow();\r
42             window.Setup(shortError, longError);\r
43             window.Show();\r
44         }\r
45 \r
46         /// <summary>\r
47         /// Show a Notice or Warning Message.\r
48         /// </summary>\r
49         /// <param name="notice">\r
50         /// The text to display to the user\r
51         /// </param>\r
52         /// <param name="isWarning">\r
53         /// Is a warning window, show the warning icon instead of the notice\r
54         /// </param>\r
55         public void ShowNotice(string notice, bool isWarning)\r
56         {\r
57             throw new NotImplementedException();\r
58         }\r
59 \r
60         /// <summary>\r
61         /// Write Exceptions out to log files\r
62         /// </summary>\r
63         /// <param name="state">\r
64         /// The state.\r
65         /// </param>\r
66         public void WriteExceptionToFile(object state)\r
67         {\r
68             try\r
69             {\r
70                 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
71                 string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));\r
72 \r
73                 if (!File.Exists(file))\r
74                 {\r
75                     using (StreamWriter streamWriter = new StreamWriter(file))\r
76                     {\r
77                         streamWriter.WriteLine(state.ToString());\r
78                         streamWriter.Close();\r
79                         streamWriter.Dispose();\r
80                     }\r
81                 }\r
82             }\r
83             catch\r
84             {\r
85                 return; // Game over. Stop digging.\r
86             }\r
87         }\r
88     }\r
89 }\r