From afcbfbd96a5536171ea640a67f6c14c907744894 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 22 Jan 2011 18:02:19 +0000 Subject: [PATCH] WinGui: - Refactored some more code out of the UI project into the Services Project. - Added support for showing bluray drives to the "Source" dropdown menu git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3764 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Functions/Main.cs | 66 --------- .../Functions/Converters.cs | 44 +----- .../Functions/EnumHelper.cs | 2 +- .../Functions/Logging.cs | 52 ------- .../Functions/Main.cs | 24 ---- .../HandBrake.ApplicationServices.csproj | 8 +- .../Model/DriveInformation.cs | 9 +- .../Model/EncodeTask.cs | 2 +- .../Model/Encoding/Anamorphic.cs | 7 +- .../Model/Encoding/AudioEncoder.cs | 7 +- .../Model/Encoding/Decomb.cs | 7 +- .../Model/Encoding/Deinterlace.cs | 10 +- .../Model/Encoding/Denoise.cs | 10 +- .../Model/Encoding/Detelecine.cs | 10 +- .../Model/Encoding/Mixdown.cs | 7 +- .../Model/Encoding/OutputFormat.cs | 7 +- .../Model/Encoding/PointToPointMode.cs | 7 +- .../Model/Encoding/SubtitleTrack.cs | 2 +- .../Model/Encoding/VideoEncodeMode.cs | 17 +++ .../Model/Encoding/VideoEncodeRateType.cs | 9 -- .../Model/Encoding/VideoEncoder.cs | 10 +- .../Model/QueueTask.cs | 4 +- .../Parsing/Title.cs | 10 +- .../Services/Encode.cs | 4 +- .../Services/{Scan.cs => ScanService.cs} | 5 +- .../Services/UtilityService.cs | 131 ++++++++++++++++++ win/C#/HandBrake10.5.1.ReSharper | 1 + win/C#/HandBrakeCS.csproj | 1 - win/C#/frmMain.cs | 6 +- win/C#/frmOptions.cs | 3 +- 30 files changed, 257 insertions(+), 225 deletions(-) delete mode 100644 win/C#/HandBrake.ApplicationServices/Functions/Logging.cs delete mode 100644 win/C#/HandBrake.ApplicationServices/Functions/Main.cs rename win/C#/{ => HandBrake.ApplicationServices}/Model/DriveInformation.cs (77%) create mode 100644 win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeMode.cs delete mode 100644 win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeRateType.cs rename win/C#/HandBrake.ApplicationServices/Services/{Scan.cs => ScanService.cs} (95%) create mode 100644 win/C#/HandBrake.ApplicationServices/Services/UtilityService.cs diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index d2d7ff5e5..578d2e8b0 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -471,46 +471,6 @@ namespace Handbrake.Functions } } - /// - /// Clear all the encode log files. - /// - public static void ClearLogs() - { - string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs"; - if (Directory.Exists(logDir)) - { - DirectoryInfo info = new DirectoryInfo(logDir); - FileInfo[] logFiles = info.GetFiles("*.txt"); - foreach (FileInfo file in logFiles) - { - if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log")) - File.Delete(file.FullName); - } - } - } - - /// - /// Clear old log files x days in the past - /// - public static void ClearOldLogs() - { - string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs"; - if (Directory.Exists(logDir)) - { - DirectoryInfo info = new DirectoryInfo(logDir); - FileInfo[] logFiles = info.GetFiles("*.txt"); - - foreach (FileInfo file in logFiles) - { - if (file.LastWriteTime < DateTime.Now.AddDays(-30)) - { - if (!file.Name.Contains("last_scan_log.txt") && !file.Name.Contains("last_encode_log.txt")) - File.Delete(file.FullName); - } - } - } - } - /// /// Map languages and their iso639_2 value into a IDictionary /// @@ -709,32 +669,6 @@ namespace Handbrake.Functions return languageMap; } - /// - /// Get a list of available DVD drives which are ready and contain DVD content. - /// - /// A List of Drives with their details - public static List GetDrives() - { - List drives = new List(); - DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives(); - int id = 0; - foreach (DriveInfo curDrive in theCollectionOfDrives) - { - if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady && - File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO")) - { - drives.Add(new DriveInformation - { - Id = id, - VolumeLabel = curDrive.VolumeLabel, - RootDirectory = curDrive.RootDirectory + "VIDEO_TS" - }); - id++; - } - } - return drives; - } - /// /// Change a string to Title Case/ /// diff --git a/win/C#/HandBrake.ApplicationServices/Functions/Converters.cs b/win/C#/HandBrake.ApplicationServices/Functions/Converters.cs index c4ba59f14..84df3dac3 100644 --- a/win/C#/HandBrake.ApplicationServices/Functions/Converters.cs +++ b/win/C#/HandBrake.ApplicationServices/Functions/Converters.cs @@ -1,7 +1,11 @@ -namespace HandBrake.ApplicationServices.Functions +/* Converters.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Functions { using System; - using System.Collections.Generic; using System.Text.RegularExpressions; /// @@ -30,41 +34,5 @@ return converted; } - - /// - /// Video Framerate Converter - /// - private static readonly Dictionary vrates = new Dictionary - { - {5, 5400000}, - {10, 2700000}, - {12, 2250000}, - {15, 1800000}, - {23.976, 1126125}, - {24, 1125000}, - {25, 1080000}, - {29.97, 900900} - }; - - /// - /// Convert the desired framerate to the video rate. - /// - /// - /// The framerate. - /// - /// - /// The Video Rate. - /// - /// - /// - public static int FramerateToVrate(double framerate) - { - if (!vrates.ContainsKey(framerate)) - { - throw new ArgumentException("Framerate not recognized.", "framerate"); - } - - return vrates[framerate]; - } } } diff --git a/win/C#/HandBrake.ApplicationServices/Functions/EnumHelper.cs b/win/C#/HandBrake.ApplicationServices/Functions/EnumHelper.cs index 6cf7342a9..0bbc746d7 100644 --- a/win/C#/HandBrake.ApplicationServices/Functions/EnumHelper.cs +++ b/win/C#/HandBrake.ApplicationServices/Functions/EnumHelper.cs @@ -5,9 +5,9 @@ namespace HandBrake.ApplicationServices.Functions { + using System; using System.ComponentModel; using System.Reflection; - using System; /// /// Enum Helpers diff --git a/win/C#/HandBrake.ApplicationServices/Functions/Logging.cs b/win/C#/HandBrake.ApplicationServices/Functions/Logging.cs deleted file mode 100644 index 1bb08cdfb..000000000 --- a/win/C#/HandBrake.ApplicationServices/Functions/Logging.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* Logging.cs $ - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -namespace HandBrake.ApplicationServices.Functions -{ - using System; - using System.IO; - using System.Text; - using System.Windows.Forms; - - using HandBrake.ApplicationServices.Model; - - /// - /// The System Information. - /// - public class Logging - { - /// - /// Add the CLI Query to the Log File. - /// - /// - /// The Encode Job Object - /// - /// - /// The create cli log header. - /// - public static string CreateCliLogHeader(QueueTask encJob) - { - StringBuilder logHeader = new StringBuilder(); - - logHeader.AppendLine(String.Format("# {0}", Init.HandBrakeGuiVersionString)); - logHeader.AppendLine(String.Format("# Running: {0}", Environment.OSVersion)); - logHeader.AppendLine(String.Format("# CPU: {0}", SystemInfo.GetCpuCount)); - logHeader.AppendLine(String.Format("# Ram: {0} MB", SystemInfo.TotalPhysicalMemory)); - logHeader.AppendLine(String.Format("# Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height)); - logHeader.AppendLine(String.Format("# Temp Dir: {0}", Path.GetTempPath())); - logHeader.AppendLine(String.Format("# Install Dir: {0}", Application.StartupPath)); - logHeader.AppendLine(String.Format("# Data Dir: {0}\n", Application.UserAppDataPath)); - - if (encJob != null) - { - logHeader.AppendLine(String.Format("# CLI Query: {0}", encJob.Query)); - logHeader.AppendLine(String.Format("# User Query: {0}", encJob.CustomQuery)); - } - logHeader.AppendLine("-------------------------------------------"); - - return logHeader.ToString(); - } - } -} \ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Functions/Main.cs b/win/C#/HandBrake.ApplicationServices/Functions/Main.cs deleted file mode 100644 index 368065dca..000000000 --- a/win/C#/HandBrake.ApplicationServices/Functions/Main.cs +++ /dev/null @@ -1,24 +0,0 @@ -/* Main.cs $ - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -namespace HandBrake.ApplicationServices.Functions -{ - using System.Diagnostics; - - /// - /// Useful functions which various screens can use. - /// - public static class Main - { - /// - /// Get the Process ID of HandBrakeCLI for the current instance. - /// - /// A list of processes - public static Process[] GetCliProcess() - { - return Process.GetProcessesByName("HandBrakeCLI"); - } - } -} \ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 12b5bc624..57c3ca4ce 100644 --- a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -89,13 +89,12 @@ - - + @@ -110,7 +109,7 @@ - + @@ -133,7 +132,8 @@ - + + diff --git a/win/C#/Model/DriveInformation.cs b/win/C#/HandBrake.ApplicationServices/Model/DriveInformation.cs similarity index 77% rename from win/C#/Model/DriveInformation.cs rename to win/C#/HandBrake.ApplicationServices/Model/DriveInformation.cs index d7cef0ee5..65708cee2 100644 --- a/win/C#/Model/DriveInformation.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/DriveInformation.cs @@ -3,7 +3,7 @@ Homepage: . It may be used under the terms of the GNU General Public License. */ -namespace Handbrake.Model +namespace HandBrake.ApplicationServices.Model { /// /// Information about a DVD drive @@ -25,6 +25,11 @@ namespace Handbrake.Model /// public string RootDirectory { get; set; } + /// + /// Gets or sets a value indicating whether this is a BluRay Drive. + /// + public bool IsBluRay { get; set; } + /// /// Returns "Drive" + Id (e.g Drive2) /// @@ -33,7 +38,7 @@ namespace Handbrake.Model /// public override string ToString() { - return "Drive" + Id; + return "Drive" + this.Id; } } } \ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Model/EncodeTask.cs b/win/C#/HandBrake.ApplicationServices/Model/EncodeTask.cs index b10168aa5..dfc0fbf08 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/EncodeTask.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/EncodeTask.cs @@ -200,7 +200,7 @@ namespace HandBrake.ApplicationServices.Model /// /// Gets or sets VideoEncodeRateType. /// - public VideoEncodeRateType VideoEncodeRateType { get; set; } + public VideoEncodeMode VideoEncodeRateType { get; set; } /// /// Gets or sets Quality. diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Anamorphic.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Anamorphic.cs index b3b524cf9..c958b777c 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Anamorphic.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Anamorphic.cs @@ -1,4 +1,9 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* Anamorphic.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { using System.ComponentModel; diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs index d98b120bf..c6f838ed7 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs @@ -1,4 +1,9 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* AudioEncoder.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { using System.ComponentModel; diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Decomb.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Decomb.cs index c09c5b98e..ae8b8a3d4 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Decomb.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Decomb.cs @@ -1,4 +1,9 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* Decomb.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { /// /// Decomb Mode diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Deinterlace.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Deinterlace.cs index 308b025a9..154428987 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Deinterlace.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Deinterlace.cs @@ -1,5 +1,13 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* Deinterlace.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { + /// + /// The Deinterlace Filter + /// public enum Deinterlace { Off = 0, diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Denoise.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Denoise.cs index 6698e775d..fc81e9f20 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Denoise.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Denoise.cs @@ -1,5 +1,13 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* Denoise.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { + /// + /// The Denose Filters + /// public enum Denoise { Off = 0, diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Detelecine.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Detelecine.cs index 19614971b..09c948dbd 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Detelecine.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Detelecine.cs @@ -1,5 +1,13 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* Detelecine.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { + /// + /// Detelecine Filter + /// public enum Detelecine { Off = 0, diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs index 373ee6b00..12611b454 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs @@ -1,4 +1,9 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* Mixdown.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { using System.ComponentModel; diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/OutputFormat.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/OutputFormat.cs index c5565914b..fa5c3225f 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/OutputFormat.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/OutputFormat.cs @@ -1,4 +1,9 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* OutputFormat.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { using System.ComponentModel; diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/PointToPointMode.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/PointToPointMode.cs index 8c58aa4cf..dcee4cac4 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/PointToPointMode.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/PointToPointMode.cs @@ -1,4 +1,9 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* PointToPoint.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { /// /// Point to Point Mode diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/SubtitleTrack.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/SubtitleTrack.cs index 5a3635689..f69abed7d 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/SubtitleTrack.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/SubtitleTrack.cs @@ -1,4 +1,4 @@ -/* Subtitle.cs $ +/* SubtitleTrack.cs $ This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeMode.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeMode.cs new file mode 100644 index 000000000..cf42f3ca6 --- /dev/null +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeMode.cs @@ -0,0 +1,17 @@ +/* VideoEncoderMode.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding +{ + /// + /// The Mode of Video Encoding. Bitrate, Filesize or Quality + /// + public enum VideoEncodeMode + { + TargetSize = 0, + AverageBitrate, + ConstantQuality + } +} diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeRateType.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeRateType.cs deleted file mode 100644 index b128fdbc4..000000000 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncodeRateType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace HandBrake.ApplicationServices.Model.Encoding -{ - public enum VideoEncodeRateType - { - TargetSize = 0, - AverageBitrate, - ConstantQuality - } -} diff --git a/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncoder.cs b/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncoder.cs index 4eddbf44b..b5a2556e3 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncoder.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Encoding/VideoEncoder.cs @@ -1,7 +1,15 @@ -namespace HandBrake.ApplicationServices.Model.Encoding +/* VideoEncoder.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Model.Encoding { using System.ComponentModel; + /// + /// The Video Encoder + /// public enum VideoEncoder { [Description("H.264 (x264)")] diff --git a/win/C#/HandBrake.ApplicationServices/Model/QueueTask.cs b/win/C#/HandBrake.ApplicationServices/Model/QueueTask.cs index 9f92ec609..83948a1f3 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/QueueTask.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/QueueTask.cs @@ -1,4 +1,4 @@ -/* QueueItem.cs $ +/* QueueTask.cs $ This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ @@ -6,7 +6,7 @@ namespace HandBrake.ApplicationServices.Model { /// - /// The job. + /// The QueueTask. /// public class QueueTask { diff --git a/win/C#/HandBrake.ApplicationServices/Parsing/Title.cs b/win/C#/HandBrake.ApplicationServices/Parsing/Title.cs index e7266207f..3a9e6a56a 100644 --- a/win/C#/HandBrake.ApplicationServices/Parsing/Title.cs +++ b/win/C#/HandBrake.ApplicationServices/Parsing/Title.cs @@ -30,9 +30,9 @@ namespace HandBrake.ApplicationServices.Parsing /// public Title() { - AudioTracks = new List(); - Chapters = new List(); - Subtitles = new List(); + this.AudioTracks = new List(); + this.Chapters = new List(); + this.Subtitles = new List(); } #region Properties @@ -112,8 +112,8 @@ namespace HandBrake.ApplicationServices.Parsing /// /// Parse the Title Information /// - /// A stingreader of output data - /// A Title + /// A StringReader of output data + /// A Title Object public static Title Parse(StringReader output) { var thisTitle = new Title(); diff --git a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs index bc5220e1e..9d3f7bb2e 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs @@ -446,8 +446,8 @@ namespace HandBrake.ApplicationServices.Services fileWriter = new StreamWriter(logFile) { AutoFlush = true }; - fileWriter.WriteLine(Logging.CreateCliLogHeader(encodeQueueTask)); - logBuffer.AppendLine(Logging.CreateCliLogHeader(encodeQueueTask)); + fileWriter.WriteLine(UtilityService.CreateCliLogHeader(encodeQueueTask)); + logBuffer.AppendLine(UtilityService.CreateCliLogHeader(encodeQueueTask)); } catch (Exception) { diff --git a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs b/win/C#/HandBrake.ApplicationServices/Services/ScanService.cs similarity index 95% rename from win/C#/HandBrake.ApplicationServices/Services/Scan.cs rename to win/C#/HandBrake.ApplicationServices/Services/ScanService.cs index d6925b304..9b85740cd 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/ScanService.cs @@ -13,7 +13,6 @@ namespace HandBrake.ApplicationServices.Services using System.Windows.Forms; using HandBrake.ApplicationServices.EventArgs; - using HandBrake.ApplicationServices.Functions; using HandBrake.ApplicationServices.Parsing; using HandBrake.ApplicationServices.Services.Interfaces; @@ -236,7 +235,7 @@ namespace HandBrake.ApplicationServices.Services // Only write the log file to disk if it's less than 100MB. if (this.readData.Buffer.Length < 100000000) { - scanLog.WriteLine(Logging.CreateCliLogHeader(null)); + scanLog.WriteLine(UtilityService.CreateCliLogHeader(null)); scanLog.Write(this.readData.Buffer); logBuffer.AppendLine(this.readData.Buffer.ToString()); } @@ -327,7 +326,7 @@ namespace HandBrake.ApplicationServices.Services logFilePosition = 0; logBuffer = new StringBuilder(); if (addHeader) - logBuffer.AppendLine(Logging.CreateCliLogHeader(null)); + logBuffer.AppendLine(UtilityService.CreateCliLogHeader(null)); } /// diff --git a/win/C#/HandBrake.ApplicationServices/Services/UtilityService.cs b/win/C#/HandBrake.ApplicationServices/Services/UtilityService.cs new file mode 100644 index 000000000..b705cb8e1 --- /dev/null +++ b/win/C#/HandBrake.ApplicationServices/Services/UtilityService.cs @@ -0,0 +1,131 @@ +/* UtilityService.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Services +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.IO; + using System.Text; + using System.Windows.Forms; + + using HandBrake.ApplicationServices.Functions; + using HandBrake.ApplicationServices.Model; + + /// + /// A Set of Static Utilites + /// + public class UtilityService + { + /// + /// The Default Log Directory + /// + private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs"; + + /// + /// Clear all the log files older than 30 Days + /// + /// + /// The Number of Days to Keep + /// + public static void ClearLogFiles(int daysToKeep) + { + if (Directory.Exists(LogDir)) + { + // Get all the log files + DirectoryInfo info = new DirectoryInfo(LogDir); + FileInfo[] logFiles = info.GetFiles("*.txt"); + + // Delete Them + foreach (FileInfo file in logFiles) + { + if (file.LastWriteTime < DateTime.Now.AddDays(-daysToKeep)) + { + if (!file.Name.Contains("last_scan_log.txt") && !file.Name.Contains("last_encode_log.txt")) + { + File.Delete(file.FullName); + } + else if (file.Length > 104857600) + { + File.Delete(file.FullName); + } + } + } + } + } + + /// + /// Get a list of available DVD drives which are ready and contain DVD content. + /// + /// A List of Drives with their details + public static List GetDrives() + { + List drives = new List(); + DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives(); + int id = 0; + foreach (DriveInfo curDrive in theCollectionOfDrives) + { + if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady) + { + if (Directory.Exists(curDrive.RootDirectory + "VIDEO_TS") || Directory.Exists(curDrive.RootDirectory + "BDMV")) + { + drives.Add( + new DriveInformation + { + Id = id, + VolumeLabel = curDrive.VolumeLabel, + RootDirectory = curDrive.RootDirectory.ToString() + }); + id++; + } + } + } + + return drives; + } + + /// + /// Get the Process ID of HandBrakeCLI for the current instance. + /// + /// A list of processes + public static Process[] GetCliProcess() + { + return Process.GetProcessesByName("HandBrakeCLI"); + } + + /// + /// Add the CLI Query to the Log File. + /// + /// + /// The Encode Job Object + /// + /// + /// The create cli log header. + /// + public static string CreateCliLogHeader(QueueTask encJob) + { + StringBuilder logHeader = new StringBuilder(); + + logHeader.AppendLine(String.Format("# {0}", Init.HandBrakeGuiVersionString)); + logHeader.AppendLine(String.Format("# Running: {0}", Environment.OSVersion)); + logHeader.AppendLine(String.Format("# CPU: {0}", SystemInfo.GetCpuCount)); + logHeader.AppendLine(String.Format("# Ram: {0} MB", SystemInfo.TotalPhysicalMemory)); + logHeader.AppendLine(String.Format("# Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height)); + logHeader.AppendLine(String.Format("# Temp Dir: {0}", Path.GetTempPath())); + logHeader.AppendLine(String.Format("# Install Dir: {0}", Application.StartupPath)); + logHeader.AppendLine(String.Format("# Data Dir: {0}\n", Application.UserAppDataPath)); + + if (encJob != null) + { + logHeader.AppendLine(String.Format("# CLI Query: {0}", encJob.Query)); + logHeader.AppendLine(String.Format("# User Query: {0}", encJob.CustomQuery)); + } + logHeader.AppendLine("-------------------------------------------"); + + return logHeader.ToString(); + } + } +} diff --git a/win/C#/HandBrake10.5.1.ReSharper b/win/C#/HandBrake10.5.1.ReSharper index 9d75ad0d1..70de4715c 100644 --- a/win/C#/HandBrake10.5.1.ReSharper +++ b/win/C#/HandBrake10.5.1.ReSharper @@ -88,6 +88,7 @@ + diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index a8471102f..0eb720f83 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -255,7 +255,6 @@ frmActivityWindow.cs - diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index fa85b4763..b4feee8f2 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -88,7 +88,7 @@ namespace Handbrake // We have a drive, selected as a folder. if (this.sourcePath.EndsWith("\\")) { - drives = Main.GetDrives(); + drives = UtilityService.GetDrives(); foreach (DriveInformation item in drives) { if (item.RootDirectory.Contains(this.sourcePath)) @@ -148,7 +148,7 @@ namespace Handbrake // Clear the log files in the background if (Settings.Default.clearOldLogs) { - Thread clearLog = new Thread(Main.ClearOldLogs); + Thread clearLog = new Thread(() => UtilityService.ClearLogFiles(30)); clearLog.Start(); } @@ -2470,7 +2470,7 @@ namespace Handbrake return; } - drives = Main.GetDrives(); + drives = UtilityService.GetDrives(); List menuItems = new List(); foreach (DriveInformation drive in drives) diff --git a/win/C#/frmOptions.cs b/win/C#/frmOptions.cs index 11034f9a3..89c5aaee1 100644 --- a/win/C#/frmOptions.cs +++ b/win/C#/frmOptions.cs @@ -12,6 +12,7 @@ namespace Handbrake using System.Windows.Forms; using HandBrake.ApplicationServices; + using HandBrake.ApplicationServices.Services; using Handbrake.Functions; using Handbrake.Model; @@ -406,7 +407,7 @@ namespace Handbrake MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { - Main.ClearLogs(); + UtilityService.ClearLogFiles(30); MessageBox.Show(this, "HandBrake's Log file directory has been cleared!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information); } -- 2.40.0