Skip to content

Commit

Permalink
WinGui: Some tidyup / Refactoring of the code post last 2 commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
sr55 committed Jul 2, 2023
1 parent 53bcb06 commit 95219ca
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 143 deletions.
3 changes: 1 addition & 2 deletions win/CS/HandBrake.Interop/Interop/HandBrakeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ namespace HandBrake.Interop.Interop
using HandBrake.Interop.Interop.Helpers;
using HandBrake.Interop.Interop.Interfaces;
using HandBrake.Interop.Interop.Interfaces.EventArgs;
using HandBrake.Interop.Interop.Interfaces.Model.Encoders;
using HandBrake.Interop.Interop.Interfaces.Model.Preview;
using HandBrake.Interop.Interop.Json.Encode;
using HandBrake.Interop.Interop.Json.Scan;
using HandBrake.Interop.Interop.Json.State;
using HandBrake.Interop.Utilities;

public class HandBrakeInstance : IHandBrakeInstance, IScanInstance, IDisposable
public class HandBrakeInstance : IEncodeInstance, IScanInstance
{
private const double ScanPollIntervalMs = 250;
private const double EncodePollIntervalMs = 250;
Expand Down
27 changes: 1 addition & 26 deletions win/CS/HandBrake.Interop/Interop/Interfaces/IEncodeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ namespace HandBrake.Interop.Interop.Interfaces

using HandBrake.Interop.Interop.Interfaces.EventArgs;
using HandBrake.Interop.Interop.Json.Encode;
using HandBrake.Interop.Interop.Json.State;

public interface IEncodeInstance
public interface IEncodeInstance : IHandBrakeInstance, IDisposable
{
/// <summary>
/// Fires when an encode has completed.
Expand All @@ -27,24 +26,6 @@ public interface IEncodeInstance
/// </summary>
event EventHandler<EncodeProgressEventArgs> EncodeProgress;

bool IsRemoteInstance { get; }

/// <summary>
/// Initializes this instance.
/// </summary>
/// <param name="verbosity">
/// The code for the logging verbosity to use.
/// </param>
/// <param name="noHardware">
/// Turn off Hardware Acceleration
/// </param>
void Initialize(int verbosity, bool noHardware);

/// <summary>
/// Frees any resources associated with this object.
/// </summary>
void Dispose();

/// <summary>
/// Pauses the current encode.
/// </summary>
Expand All @@ -67,11 +48,5 @@ public interface IEncodeInstance
/// Stops the current encode.
/// </summary>
void StopEncode();

/// <summary>
/// Get the current Progress State.
/// </summary>
/// <returns>A JsonState object</returns>
JsonState GetProgress();
}
}
86 changes: 12 additions & 74 deletions win/CS/HandBrake.Interop/Interop/Interfaces/IHandBrakeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,13 @@

namespace HandBrake.Interop.Interop.Interfaces
{
using System;
using System.Collections.Generic;

using HandBrake.Interop.Interop.Interfaces.EventArgs;
using HandBrake.Interop.Interop.Interfaces.Model.Preview;
using HandBrake.Interop.Interop.Json.Encode;
using HandBrake.Interop.Interop.Json.Scan;
using HandBrake.Interop.Interop.Json.State;

/// <summary>
/// The Interface for HandBrakeInstance
/// </summary>
public interface IHandBrakeInstance : IEncodeInstance
public interface IHandBrakeInstance
{
#region Events

/// <summary>
/// Fires when a scan has completed.
/// </summary>
event EventHandler<System.EventArgs> ScanCompleted;

/// <summary>
/// Fires for progress updates when scanning.
/// </summary>
event EventHandler<ScanProgressEventArgs> ScanProgress;

#endregion

#region Properties

/// <summary>
/// Gets the index of the default title.
/// </summary>
int FeatureTitle { get; }

/// <summary>
/// Gets the list of titles on this instance.
/// </summary>
JsonScanObject Titles { get; }

/// <summary>
/// Gets the HandBrake version string.
/// </summary>
Expand All @@ -58,54 +26,24 @@ public interface IHandBrakeInstance : IEncodeInstance
/// </summary>
int Build { get; }

#endregion

#region Public Methods

/// <summary>
/// Gets an image for the given job and preview
/// </summary>
/// <remarks>
/// Only incorporates sizing and aspect ratio into preview image.
/// </remarks>
/// <param name="job">
/// The encode job to preview.
/// </param>
/// <param name="previewNumber">
/// The index of the preview to get (0-based).
/// </param>
/// <returns>
/// An image with the requested preview.
/// </returns>
RawPreviewData GetPreview(JsonEncodeObject job, int previewNumber);
bool IsRemoteInstance { get; }

/// <summary>
/// Starts a scan of the given path.
/// Initializes this instance.
/// </summary>
/// <param name="path">
/// The path of the video to scan.
/// </param>
/// <param name="previewCount">
/// The number of previews to make on each title.
/// <param name="verbosity">
/// The code for the logging verbosity to use.
/// </param>
/// <param name="minDuration">
/// The min Duration.
/// <param name="noHardware">
/// Turn off Hardware Acceleration
/// </param>
/// <param name="titleIndex">
/// The title Index.
/// </param>
/// <param name="excludedExtensions">
/// A list of file extensions to exclude.
/// These should be the extension name only. No .
/// Case Insensitive.
/// </param>
void StartScan(string path, int previewCount, TimeSpan minDuration, int titleIndex, List<string> excludedExtensions);
void Initialize(int verbosity, bool noHardware);

/// <summary>
/// Stop any running scans
/// Get the current Progress State.
/// </summary>
void StopScan();

#endregion
/// <returns>A JsonState object</returns>
JsonState GetProgress();
}
}
28 changes: 8 additions & 20 deletions win/CS/HandBrake.Interop/Interop/Interfaces/IScanInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace HandBrake.Interop.Interop.Interfaces
{
using System;
using System.Collections.Generic;

using HandBrake.Interop.Interop.Interfaces.EventArgs;
using HandBrake.Interop.Interop.Interfaces.Model.Preview;
Expand All @@ -19,7 +20,7 @@ namespace HandBrake.Interop.Interop.Interfaces
/// <summary>
/// The Interface for HandBrakeInstance
/// </summary>
public interface IScanInstance
public interface IScanInstance : IHandBrakeInstance, IDisposable
{
/// <summary>
/// Fires when a scan has completed.
Expand All @@ -31,8 +32,6 @@ public interface IScanInstance
/// </summary>
event EventHandler<ScanProgressEventArgs> ScanProgress;

bool IsRemoteInstance { get; }

/// <summary>
/// Gets the index of the default title.
/// </summary>
Expand All @@ -43,22 +42,6 @@ public interface IScanInstance
/// </summary>
JsonScanObject Titles { get; }

/// <summary>
/// Initializes this instance.
/// </summary>
/// <param name="verbosity">
/// The code for the logging verbosity to use.
/// </param>
/// <param name="noHardware">
/// Turn off Hardware Acceleration
/// </param>
void Initialize(int verbosity, bool noHardware);

/// <summary>
/// Frees any resources associated with this object.
/// </summary>
void Dispose();

/// <summary>
/// Gets an image for the given job and preview
/// </summary>
Expand Down Expand Up @@ -91,7 +74,12 @@ public interface IScanInstance
/// <param name="titleIndex">
/// The title Index.
/// </param>
void StartScan(string path, int previewCount, TimeSpan minDuration, int titleIndex);
/// <param name="excludedExtensions">
/// A list of file extensions to exclude.
/// These should be the extension name only. No .
/// Case Insensitive.
/// </param>
void StartScan(string path, int previewCount, TimeSpan minDuration, int titleIndex, List<string> excludedExtensions);

/// <summary>
/// Stop any running scans
Expand Down
2 changes: 1 addition & 1 deletion win/CS/HandBrake.Worker/Routing/ApiRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public string StartScan(HttpListenerRequest request)

this.Initialise(command.InitialiseCommand);

this.handbrakeInstance.StartScan(command.Path, command.PreviewCount, command.MinDuration, command.TitleIndex);
this.handbrakeInstance.StartScan(command.Path, command.PreviewCount, command.MinDuration, command.TitleIndex, command.InitialiseCommand.ExcludeExtnesionList);

return JsonSerializer.Serialize(new CommandResult() { WasSuccessful = true }, JsonSettings.Options);
}
Expand Down
2 changes: 1 addition & 1 deletion win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static IEncodeInstance GetEncodeInstance(int verbosity, ILog logService,
/// <returns>
/// The <see cref="IHandBrakeInstance"/>.
/// </returns>
public static IHandBrakeInstance GetScanInstance(int verbosity)
public static IScanInstance GetScanInstance(int verbosity)
{
if (!HandBrakeUtils.IsInitialised())
{
Expand Down
26 changes: 26 additions & 0 deletions win/CS/HandBrakeWPF/Instance/RemoteBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace HandBrakeWPF.Instance
using System.Text;
using System.Threading.Tasks;

using HandBrakeWPF.Instance.Model;
using HandBrakeWPF.Model.Options;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Logging.Interfaces;
Expand All @@ -37,6 +38,31 @@ public RemoteBase(ILog logService, IUserSettingService userSettingService, IPort

public bool IsRemoteInstance => true;

public string Version
{
get
{
Task<ServerResponse> response = this.MakeHttpGetRequest("Version");
response.Wait();

if (!response.Result.WasSuccessful)
{
return null;
}

return response.Result?.JsonResponse;
}
}

public int Build
{
get
{
throw new NotImplementedException("This method is not implemented yet");
return 0;
}
}

public void Initialize(int verbosityLvl, bool noHardwareMode)
{
try
Expand Down
17 changes: 9 additions & 8 deletions win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,15 @@ private void RunEncodeInitProcess(JsonEncodeObject jobToStart)
if (this.IsServerRunning())
{
InitCommand initCommand = new InitCommand
{
EnableDiskLogging = false,
AllowDisconnectedWorker = false,
EnableLibDvdNav = !this.userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav),
EnableHardwareAcceleration = true,
LogDirectory = DirectoryUtilities.GetLogDirectory(),
LogVerbosity = this.userSettingService.GetUserSetting<int>(UserSettingConstants.Verbosity),
ExcludeExtnesionList = this.userSettingService.GetUserSetting<List<string>>(null) // TODO
{
EnableDiskLogging = false,
AllowDisconnectedWorker = false,
EnableLibDvdNav = !this.userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav),
EnableHardwareAcceleration = true,
LogDirectory = DirectoryUtilities.GetLogDirectory(),
LogVerbosity = this.userSettingService.GetUserSetting<int>(UserSettingConstants.Verbosity),
Mode = 1,
ExcludeExtnesionList = this.userSettingService.GetUserSetting<List<string>>(UserSettingConstants.ExcludedExtensions)
};

initCommand.LogFile = Path.Combine(initCommand.LogDirectory, string.Format("activity_log.worker.{0}.txt", GeneralUtilities.ProcessId));
Expand Down
38 changes: 28 additions & 10 deletions win/CS/HandBrakeWPF/Instance/RemoteScanInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace HandBrakeWPF.Instance
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
Expand Down Expand Up @@ -79,7 +80,7 @@ public RawPreviewData GetPreview(JsonEncodeObject job, int previewNumber)
return null;
}

public void StartScan(string path, int previewCount, TimeSpan minDuration, int titleIndex)
public void StartScan(string path, int previewCount, TimeSpan minDuration, int titleIndex, List<string> fileExclusionList)
{
if (this.IsServerRunning())
{
Expand All @@ -101,20 +102,37 @@ public async void StopScan()
}
}

public JsonState GetProgress()
{
Task<ServerResponse> response = this.MakeHttpGetRequest("PollEncodeProgress");
response.Wait();

if (!response.Result.WasSuccessful)
{
return null;
}

string statusJson = response.Result?.JsonResponse;

JsonState state = JsonSerializer.Deserialize<JsonState>(statusJson, JsonSettings.Options);
return state;
}

private void RunScanInitProcess(string path, int previewCount, TimeSpan minDuration, int titleIndex)
{
if (this.IsServerRunning())
{
InitCommand initCommand = new InitCommand
{
EnableDiskLogging = false,
AllowDisconnectedWorker = false,
EnableLibDvdNav = !this.userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav),
EnableHardwareAcceleration = true,
LogDirectory = DirectoryUtilities.GetLogDirectory(),
LogVerbosity = this.userSettingService.GetUserSetting<int>(UserSettingConstants.Verbosity),
Mode = 2
};
{
EnableDiskLogging = false,
AllowDisconnectedWorker = false,
EnableLibDvdNav = !this.userSettingService.GetUserSetting<bool>(UserSettingConstants.DisableLibDvdNav),
EnableHardwareAcceleration = true,
LogDirectory = DirectoryUtilities.GetLogDirectory(),
LogVerbosity = this.userSettingService.GetUserSetting<int>(UserSettingConstants.Verbosity),
Mode = 2,
ExcludeExtnesionList = this.userSettingService.GetUserSetting<List<string>>(UserSettingConstants.ExcludedExtensions)
};

initCommand.LogFile = Path.Combine(initCommand.LogDirectory, string.Format("activity_log.worker.{0}.txt", GeneralUtilities.ProcessId));

Expand Down
2 changes: 1 addition & 1 deletion win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class LibScan : IScan, IDisposable

private TitleFactory titleFactory = new TitleFactory();
private string currentSourceScanPath;
private IHandBrakeInstance instance;
private IScanInstance instance;
private Action<bool, Source> postScanOperation;
private bool isCancelled = false;

Expand Down

0 comments on commit 95219ca

Please sign in to comment.