/// <summary>
        /// Initializes a new instance of the <see cref="ScanService"/> class.
        /// </summary>
        /// <param name="userSettingService">
        /// The user Setting Service.
        /// </param>
        public ScanService(IUserSettingService userSettingService)
        {
            this.userSettingService = userSettingService;
            this.logBuffer          = new StringBuilder();

            header = GeneralUtilities.CreateCliLogHeader();
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EncodeBase"/> class.
        /// </summary>
        /// <param name="userSettingService">
        /// The user Setting Service.
        /// </param>
        public EncodeBase(IUserSettingService userSettingService)
        {
            this.userSettingService = userSettingService;
            this.logBuffer          = new StringBuilder();
            header =
                GeneralUtilities.CreateCliLogHeader();

            this.LogIndex = 0;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LibScan"/> class.
        /// </summary>
        /// <param name="userSettingService">
        /// The user Setting Service.
        /// </param>
        public LibScan(IUserSettingService userSettingService)
        {
            logging = new StringBuilder();

            header = GeneralUtilities.CreateCliLogHeader();
            this.userSettingService = userSettingService;

            HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
            HandBrakeUtils.ErrorLogged   += this.HandBrakeInstanceErrorLogged;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LibScan"/> class.
        /// </summary>
        /// <param name="handBrakeInstance">
        /// The hand Brake Instance.
        /// </param>
        public LibScan(IHandBrakeInstance handBrakeInstance)
        {
            logging = new StringBuilder();

            header = GeneralUtilities.CreateCliLogHeader();

            instance = handBrakeInstance;
            instance.Initialize(1);
            instance.ScanProgress  += this.InstanceScanProgress;
            instance.ScanCompleted += this.InstanceScanCompleted;

            HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
            HandBrakeUtils.ErrorLogged   += this.HandBrakeInstanceErrorLogged;
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LibScan"/> class.
        /// </summary>
        public LibScan()
        {
            logging = new StringBuilder();

            header = GeneralUtilities.CreateCliLogHeader();

            try
            {
                HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
                HandBrakeUtils.ErrorLogged   += this.HandBrakeInstanceErrorLogged;
            }
            catch (Exception)
            {
                // Do nothing.
            }
        }
示例#6
0
        /// <summary>
        /// Setup the logging.
        /// </summary>
        /// <param name="encodeQueueTask">
        /// The encode QueueTask.
        /// </param>
        protected void SetupLogging(QueueTask encodeQueueTask)
        {
            ShutdownFileWriter();
            string logDir   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
            string logFile  = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.GetInstanceCount));
            string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", GeneralUtilities.GetInstanceCount));

            try
            {
                string query = QueryGeneratorUtility.GenerateQuery(new EncodeTask(encodeQueueTask.Task));
                this.logBuffer = new StringBuilder();
                this.logBuffer.AppendLine(String.Format("CLI Query: {0}", query));
                this.logBuffer.AppendLine(String.Format("User Query: {0}", encodeQueueTask.CustomQuery));
                this.logBuffer.AppendLine();

                // Clear the current Encode Logs)
                if (File.Exists(logFile))
                {
                    File.Delete(logFile);
                }

                if (File.Exists(logFile2))
                {
                    File.Delete(logFile2);
                }

                this.fileWriter = new StreamWriter(logFile)
                {
                    AutoFlush = true
                };
                this.fileWriter.WriteLine(GeneralUtilities.CreateCliLogHeader());
                this.fileWriter.WriteLine(String.Format("CLI Query: {0}", query));
                this.fileWriter.WriteLine(String.Format("User Query: {0}", encodeQueueTask.CustomQuery));
                this.fileWriter.WriteLine();
            }
            catch (Exception)
            {
                if (this.fileWriter != null)
                {
                    this.fileWriter.Close();
                    this.fileWriter.Dispose();
                }

                throw;
            }
        }
示例#7
0
        /// <summary>
        /// Setup the logging.
        /// </summary>
        /// <param name="encodeQueueTask">
        /// The encode QueueTask.
        /// </param>
        private void SetupLogging(QueueTask encodeQueueTask)
        {
            string logDir   = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
            string logFile  = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.GetInstanceCount));
            string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", GeneralUtilities.GetInstanceCount));

            try
            {
                logBuffer = new StringBuilder();

                // Clear the current Encode Logs
                if (File.Exists(logFile))
                {
                    File.Delete(logFile);
                }
                if (File.Exists(logFile2))
                {
                    File.Delete(logFile2);
                }

                fileWriter = new StreamWriter(logFile)
                {
                    AutoFlush = true
                };
                fileWriter.WriteLine(GeneralUtilities.CreateCliLogHeader(encodeQueueTask));
            }
            catch (Exception)
            {
                if (fileWriter != null)
                {
                    fileWriter.Close();
                    fileWriter.Dispose();
                }
                throw;
            }
        }
示例#8
0
        /// <summary>
        /// Start a scan for a given source path and title
        /// </summary>
        /// <param name="sourcePath">
        /// Path to the source file
        /// </param>
        /// <param name="title">
        /// the title number to look at
        /// </param>
        /// <param name="previewCount">
        /// The preview Count.
        /// </param>
        private void ScanSource(object sourcePath, int title, int previewCount)
        {
            try
            {
                this.IsScanning = true;
                if (this.ScanStared != null)
                {
                    this.ScanStared(this, new EventArgs());
                }

                this.logBuffer = new StringBuilder();

                string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
                string logDir           = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                          "\\HandBrake\\logs";
                string dvdInfoPath = Path.Combine(
                    logDir,
                    string.Format("last_scan_log{0}.txt", GeneralUtilities.GetInstanceCount));

                // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
                if (File.Exists(dvdInfoPath))
                {
                    File.Delete(dvdInfoPath);
                }

                string extraArguments = string.Empty;

                if (previewCount != 10)
                {
                    extraArguments += " --previews " + previewCount;
                }

                if (this.userSettingService.GetUserSetting <bool>(ASUserSettingConstants.DisableLibDvdNav))
                {
                    extraArguments += " --no-dvdnav";
                }

                extraArguments += string.Format(" --min-duration={0}", this.userSettingService.GetUserSetting <int>(ASUserSettingConstants.MinScanDuration));

                if (title > 0)
                {
                    extraArguments += " --scan ";
                }

                // Quick fix for "F:\\" style paths. Just get rid of the \\ so the CLI doesn't fall over.
                // Sould probably clean up the escaping of the strings later.
                string source = sourcePath.ToString().EndsWith("\\") ? sourcePath.ToString() : "\"" + sourcePath + "\"";
                string query  = string.Format(@" -i {0} -t{1} {2} -v ", source, title, extraArguments);

                this.hbProc = new Process
                {
                    StartInfo =
                    {
                        FileName  = handbrakeCLIPath,
                        Arguments = string.Format(@" -i {0} -t{1} {2} -v ", source, title, extraArguments),
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                        UseShellExecute        = false,
                        CreateNoWindow         = true
                    }
                };

                // Start the Scan
                this.hbProc.Start();

                this.readData = new Parser(this.hbProc.StandardError.BaseStream);
                this.readData.OnScanProgress += this.OnScanProgress;
                this.SouceData          = Source.Parse(this.readData);
                this.SouceData.ScanPath = source;

                // Write the Buffer out to file.
                using (StreamWriter scanLog = new StreamWriter(dvdInfoPath))
                {
                    // Only write the log file to disk if it's less than 50MB.
                    if (this.readData.Buffer.Length < 50000000)
                    {
                        scanLog.WriteLine(GeneralUtilities.CreateCliLogHeader());
                        scanLog.WriteLine(query);
                        scanLog.Write(this.readData.Buffer);

                        this.logBuffer.AppendLine(query);
                        this.logBuffer.AppendLine(this.readData.Buffer.ToString());
                    }
                    else
                    {
                        throw new Exception(
                                  "The Log file has not been written to disk as it has grown above the 100MB limit. This indicates there was a problem during the scan process.");
                    }
                }

                this.IsScanning = false;

                if (this.ScanCompleted != null)
                {
                    this.ScanCompleted(this, new ScanCompletedEventArgs(true, null, string.Empty));
                }
            }
            catch (Exception exc)
            {
                this.Stop();

                if (this.ScanCompleted != null)
                {
                    this.ScanCompleted(this, new ScanCompletedEventArgs(false, exc, "An Error has occured in ScanService.ScanSource()"));
                }
            }
        }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EncodeBase"/> class.
 /// </summary>
 public EncodeBase()
 {
     this.logBuffer = new StringBuilder();
     header         = GeneralUtilities.CreateCliLogHeader();
     this.LogIndex  = 0;
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LibScan"/> class.
 /// </summary>
 public LibScan()
 {
     this.logging = new StringBuilder();
     this.header  = GeneralUtilities.CreateCliLogHeader();
 }