OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / Main.cs
index 022a025..3071cf5 100644 (file)
@@ -14,18 +14,19 @@ using System.Xml.Serialization;
 using System.Threading;\r
 using Handbrake.EncodeQueue;\r
 using System.Net;\r
+using Handbrake.Model;\r
 \r
 namespace Handbrake.Functions\r
 {\r
     static class Main\r
     {\r
         // Private Variables\r
-        private static readonly XmlSerializer ser = new XmlSerializer(typeof(List<Job>));\r
+        private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Job>));\r
 \r
         /// <summary>\r
         /// Calculate the duration of the selected title and chapters\r
         /// </summary>\r
-        public static TimeSpan calculateDuration(int chapterStart, int chapterEnd, Parsing.Title selectedTitle)\r
+        public static TimeSpan CalculateDuration(int chapterStart, int chapterEnd, Parsing.Title selectedTitle)\r
         {\r
             TimeSpan duration = TimeSpan.FromSeconds(0.0);\r
             chapterStart++; chapterEnd++;\r
@@ -41,7 +42,7 @@ namespace Handbrake.Functions
         /// <summary>\r
         /// Select the longest title in the DVD title dropdown menu on frmMain\r
         /// </summary>\r
-        public static Parsing.Title selectLongestTitle(Parsing.DVD thisDvd)\r
+        public static Parsing.Title SelectLongestTitle(Parsing.DVD thisDvd)\r
         {\r
             TimeSpan longestDurationFound = TimeSpan.FromSeconds(0.0);\r
             Parsing.Title returnTitle = null;\r
@@ -60,7 +61,7 @@ namespace Handbrake.Functions
         /// <summary>\r
         /// Set's up the DataGridView on the Chapters tab (frmMain)\r
         /// </summary>\r
-        public static DataGridView chapterNaming(DataGridView dataChpt, string chapterEnd)\r
+        public static DataGridView ChapterNaming(DataGridView dataChpt, string chapterEnd)\r
         {\r
             int i = 0, finish = 0;\r
 \r
@@ -86,7 +87,7 @@ namespace Handbrake.Functions
         /// <param name="dataChpt"></param>\r
         /// <param name="filename"></param>\r
         /// <returns></returns>\r
-        public static DataGridView importChapterNames(DataGridView dataChpt, string filename)\r
+        public static DataGridView ImportChapterNames(DataGridView dataChpt, string filename)\r
         {\r
             IDictionary<int, string> chapterMap = new Dictionary<int, string>();\r
             try\r
@@ -97,10 +98,11 @@ namespace Handbrake.Functions
                 {\r
                     if (csv.Trim() != "")\r
                     {\r
+                        csv = csv.Replace("\\,", "<!comma!>");\r
                         string[] contents = csv.Split(',');\r
                         int chapter;\r
                         int.TryParse(contents[0], out chapter);\r
-                        chapterMap.Add(chapter, contents[1]);\r
+                        chapterMap.Add(chapter, contents[1].Replace("<!comma!>", ","));\r
                     }\r
                     csv = sr.ReadLine();\r
                 }\r
@@ -124,13 +126,13 @@ namespace Handbrake.Functions
         /// Function which generates the filename and path automatically based on \r
         /// the Source Name, DVD title and DVD Chapters\r
         /// </summary>\r
-        public static string autoName(frmMain mainWindow) //ComboBox drpDvdtitle, string chapter_start, string chatper_end, string source, string dest, int format, Boolean chapters)\r
+        public static string AutoName(frmMain mainWindow)\r
         {\r
             string AutoNamePath = string.Empty;\r
             if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
             {\r
                 // Get the Source Name \r
-                string sourceName = Path.GetFileNameWithoutExtension(mainWindow.sourcePath);\r
+                string sourceName = mainWindow.SourceName;\r
 \r
                 // Get the Selected Title Number\r
                 string[] titlesplit = mainWindow.drp_dvdtitle.Text.Split(' ');\r
@@ -191,14 +193,23 @@ namespace Handbrake.Functions
         /// Get's HandBrakes version data from the CLI.\r
         /// </summary>\r
         /// <returns>Arraylist of Version Data. 0 = hb_version 1 = hb_build</returns>\r
-        public static void setCliVersionData()\r
+        public static void SetCliVersionData()\r
         {\r
             String line;\r
 \r
             // 0 = SVN Build / Version\r
             // 1 = Build Date\r
+\r
+            DateTime lastModified = File.GetLastWriteTime("HandBrakeCLI.exe");\r
+\r
+\r
+            if (Properties.Settings.Default.cliLastModified == lastModified && Properties.Settings.Default.hb_build != 0)\r
+                return;\r
+\r
+            Properties.Settings.Default.cliLastModified = lastModified;\r
+\r
             Process cliProcess = new Process();\r
-            ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u")\r
+            ProcessStartInfo handBrakeCLI = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0")\r
                                                 {\r
                                                     UseShellExecute = false,\r
                                                     RedirectStandardError = true,\r
@@ -216,7 +227,7 @@ namespace Handbrake.Functions
                 while (!cliProcess.HasExited)\r
                 {\r
                     line = stdOutput.ReadLine() ?? "";\r
-                    Match m = Regex.Match(line, @"HandBrake ([0-9.]*)(svn[0-9M]*) \([0-9]*\)");\r
+                    Match m = Regex.Match(line, @"HandBrake ([svnM0-9.]*) \([0-9]*\)");\r
                     Match platform = Regex.Match(line, @"- ([A-Za-z0-9\s ]*) -");\r
 \r
                     if (m.Success)\r
@@ -237,6 +248,7 @@ namespace Handbrake.Functions
                             cli.Kill();\r
                     }\r
                 }\r
+                Properties.Settings.Default.Save();\r
             }\r
             catch (Exception e)\r
             {\r
@@ -249,16 +261,16 @@ namespace Handbrake.Functions
         /// If it does, it means the last queue did not complete before HandBrake closed.\r
         /// So, return a boolean if true. \r
         /// </summary>\r
-        public static Boolean checkQueueRecovery()\r
+        public static Boolean CheckQueueRecovery()\r
         {\r
             try\r
             {\r
-                string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");\r
+                string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\hb_queue_recovery.xml");\r
                 if (File.Exists(tempPath))\r
                 {\r
                     using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))\r
                     {\r
-                        List<Job> list = ser.Deserialize(strm) as List<Job>;\r
+                        List<Job> list = Ser.Deserialize(strm) as List<Job>;\r
                         if (list != null)\r
                             if (list.Count != 0)\r
                                 return true;\r
@@ -277,7 +289,7 @@ namespace Handbrake.Functions
         /// </summary>\r
         /// <param name="before">List of processes before the new process was started</param>\r
         /// <returns>Int - Process ID</returns>\r
-        public static int getCliProcess(Process[] before)\r
+        public static int GetCliProcess(Process[] before)\r
         {\r
             // This is a bit of a cludge. Maybe someone has a better idea on how to impliment this.\r
             // Since we used CMD to start HandBrakeCLI, we don't get the process ID from hbProc.\r
@@ -324,7 +336,7 @@ namespace Handbrake.Functions
         /// <summary>\r
         ///  Clear all the encode log files.\r
         /// </summary>\r
-        public static void clearLogs()\r
+        public static void ClearLogs()\r
         {\r
             string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
             if (Directory.Exists(logDir))\r
@@ -335,6 +347,30 @@ namespace Handbrake.Functions
                 {\r
                     if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") && !file.Name.Contains("tmp_appReadable_log.txt"))\r
                         File.Delete(file.FullName);\r
+\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Clear old log files x days in the past\r
+        /// </summary>\r
+        public static void ClearOldLogs()\r
+        {\r
+            string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+            if (Directory.Exists(logDir))\r
+            {\r
+                DirectoryInfo info = new DirectoryInfo(logDir);\r
+                FileInfo[] logFiles = info.GetFiles("*.txt");\r
+\r
+                foreach (FileInfo file in logFiles)\r
+                {\r
+                    if (file.LastWriteTime < DateTime.Now.AddDays(-30))\r
+                    {\r
+                        if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") && !file.Name.Contains("tmp_appReadable_log.txt"))\r
+                            File.Delete(file.FullName);\r
+\r
+                    }\r
                 }\r
             }\r
         }\r
@@ -359,10 +395,10 @@ namespace Handbrake.Functions
                     AppcastReader reader = new AppcastReader();\r
 \r
                     // Get the data, convert it to a string, and parse it into the AppcastReader\r
-                    reader.getInfo(new StreamReader(response.GetResponseStream()).ReadToEnd());\r
+                    reader.GetInfo(new StreamReader(response.GetResponseStream()).ReadToEnd());\r
 \r
                     // Further parse the information\r
-                    string build = reader.build;\r
+                    string build = reader.Build;\r
 \r
                     int latest = int.Parse(build);\r
                     int current = Properties.Settings.Default.hb_build;\r
@@ -402,36 +438,10 @@ namespace Handbrake.Functions
         }\r
 \r
         /// <summary>\r
-        /// Used in EndUpdateCheck() for update checking and the IAsyncResult design pattern.\r
-        /// </summary>\r
-        private class UpdateCheckResult : IAsyncResult\r
-        {\r
-            public UpdateCheckResult(object asyncState, UpdateCheckInformation info)\r
-            {\r
-                AsyncState = asyncState;\r
-                Result = info;\r
-            }\r
-\r
-            /// <summary>\r
-            /// Gets whether the check was executed in debug mode.\r
-            /// </summary>\r
-            public object AsyncState { get; private set; }\r
-\r
-            /// <summary>\r
-            /// Gets the result of the update check.\r
-            /// </summary>\r
-            public UpdateCheckInformation Result { get; private set; }\r
-\r
-            public WaitHandle AsyncWaitHandle { get { throw new NotImplementedException(); } }\r
-            public bool CompletedSynchronously { get { throw new NotImplementedException(); } }\r
-            public bool IsCompleted { get { throw new NotImplementedException(); } }\r
-        }\r
-\r
-        /// <summary>\r
         /// Map languages and their iso639_2 value into a IDictionary\r
         /// </summary>\r
         /// <returns></returns>\r
-        public static IDictionary<string, string> mapLanguages()\r
+        public static IDictionary<string, string> MapLanguages()\r
         {\r
             IDictionary<string, string> languageMap = new Dictionary<string, string>\r
                                                           {\r
@@ -625,5 +635,26 @@ namespace Handbrake.Functions
             return languageMap;\r
         }\r
 \r
+        /// <summary>\r
+        /// Get a list of available DVD drives which are ready and contain DVD content.\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        public static List<DriveInformation> GetDrives()\r
+        {\r
+            List<DriveInformation> drives = new List<DriveInformation>();\r
+            DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
+            foreach (DriveInfo curDrive in theCollectionOfDrives)\r
+            {\r
+                if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady && File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))\r
+                {\r
+                    drives.Add(new DriveInformation\r
+                                             {\r
+                                                 VolumeLabel = curDrive.VolumeLabel,\r
+                                                 RootDirectory = curDrive.RootDirectory + "VIDEO_TS"\r
+                                             });\r
+                }\r
+            }\r
+            return drives;\r
+        }\r
     }\r
-}\r
+}
\ No newline at end of file