OSDN Git Service

add win/C# diff files
[handbrake-jp/handbrake-jp.git] / win / C# / HandBrake.Framework / Services / ErrorService.cs.diff
diff --git a/win/C#/HandBrake.Framework/Services/ErrorService.cs.diff b/win/C#/HandBrake.Framework/Services/ErrorService.cs.diff
new file mode 100644 (file)
index 0000000..eb7b764
--- /dev/null
@@ -0,0 +1,115 @@
+diff --git a/win/C#/HandBrake.Framework/Services/ErrorService.cs b/win/C#/HandBrake.Framework/Services/ErrorService.cs
+new file mode 100644
+index 0000000..3858f16
+--- /dev/null
++++ b/win/C#/HandBrake.Framework/Services/ErrorService.cs
+@@ -0,0 +1,109 @@
++/*  ErrorService.cs $\r
++    This file is part of the HandBrake source code.\r
++    Homepage: <http://handbrake.fr>.\r
++    It may be used under the terms of the GNU General Public License. */\r
++\r
++namespace HandBrake.Framework.Services\r
++{\r
++    using System;\r
++    using System.IO;\r
++    using System.Threading;\r
++    using System.Windows.Forms;\r
++\r
++    using HandBrake.Framework.Services.Interfaces;\r
++    using HandBrake.Framework.Views;\r
++\r
++    /// <summary>\r
++    /// The Error Service\r
++    /// </summary>\r
++    public class ErrorService : IErrorService\r
++    {\r
++        private int exceptionCount;\r
++\r
++        /// <summary>\r
++        /// Show an Error Window\r
++        /// </summary>\r
++        /// <param name="shortError">\r
++        /// The short error message for the user to read\r
++        /// </param>\r
++        /// <param name="longError">\r
++        /// Exception string or advanced details\r
++        /// </param>\r
++        public void ShowError(string shortError, string longError)\r
++        {\r
++            exceptionCount++;\r
++\r
++            try\r
++            {\r
++                Thread newThread = new Thread(new ParameterizedThreadStart(this.LogError));\r
++                newThread.Start(shortError + Environment.NewLine + longError);\r
++            }\r
++            catch (Exception)\r
++            {\r
++                // Do Nothing\r
++            }\r
++\r
++            if (exceptionCount > 30)\r
++            {\r
++                // If we are getting a large number of exceptions, just die out. We don't want to fill the users drive with a ton \r
++                // of exception files.\r
++                return;\r
++            }\r
++\r
++            ExceptionWindow window = new ExceptionWindow();\r
++            window.Setup(shortError, longError);\r
++\r
++            // This seems far from ideal so maybe have a think about a better way of doing this.\r
++            // This method can be called from UI and worker threads, so the ExcWindow needs to be called on the UI thread or on it's on UI thread.\r
++            Application.Run(window); \r
++        }\r
++\r
++        /// <summary>\r
++        /// Show a Notice or Warning Message.\r
++        /// </summary>\r
++        /// <param name="notice">\r
++        /// The text to display to the user\r
++        /// </param>\r
++        /// <param name="isWarning">\r
++        /// Is a warning window, show the warning icon instead of the notice\r
++        /// </param>\r
++        public void ShowNotice(string notice, bool isWarning)\r
++        {\r
++            throw new NotImplementedException();\r
++        }\r
++\r
++        /// <summary>\r
++        /// Write Exceptions out to log files\r
++        /// </summary>\r
++        /// <param name="state">\r
++        /// The state.\r
++        /// </param>\r
++        public void LogError(object state)\r
++        {\r
++            try\r
++            {\r
++                if (exceptionCount > 30)\r
++                {\r
++                    // If we are getting a large number of exceptions, just die out. We don't want to fill the users drive with a ton \r
++                    // of exception files.\r
++                    return;\r
++                }\r
++\r
++                string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
++                string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));\r
++\r
++                if (!File.Exists(file))\r
++                {\r
++                    using (StreamWriter streamWriter = new StreamWriter(file))\r
++                    {\r
++                        streamWriter.WriteLine(state.ToString());\r
++                    }\r
++                }\r
++            }\r
++            catch\r
++            {\r
++                return; // Game over. Stop digging.\r
++            }\r
++        }\r
++    }\r
++}\r