Skip to content

Commit

Permalink
WinGui: Improve Langauge for process isolation and be clear what it i…
Browse files Browse the repository at this point in the history
…s, and how it works.

Locked down protable mode so process isolation can't be tricked to be on.
  • Loading branch information
sr55 committed Apr 11, 2020
1 parent fa81cfa commit c0a4500
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 21 deletions.
3 changes: 2 additions & 1 deletion win/CS/HandBrakeWPF/Instance/HandBrakeInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace HandBrakeWPF.Instance

using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Logging.Interfaces;
using HandBrakeWPF.Utilities;

/// <summary>
/// The HandBrake Instance manager.
Expand Down Expand Up @@ -51,7 +52,7 @@ public static IEncodeInstance GetEncodeInstance(int verbosity, HBConfiguration c

IEncodeInstance newInstance;

if (userSettingService.GetUserSetting<bool>(UserSettingConstants.RemoteServiceEnabled))
if (userSettingService.GetUserSetting<bool>(UserSettingConstants.ProcessIsolationEnabled) && Portable.IsProcessIsolationEnabled())
{
newInstance = new RemoteInstance(configuration, logService, userSettingService);
}
Expand Down
2 changes: 1 addition & 1 deletion win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RemoteInstance(HBConfiguration configuration, ILog logService, IUserSetti
this.configuration = configuration;
this.logService = logService;
this.userSettingService = userSettingService;
this.port = this.GetOpenPort(userSettingService.GetUserSetting<int>(UserSettingConstants.RemoteServicePort));
this.port = this.GetOpenPort(userSettingService.GetUserSetting<int>(UserSettingConstants.ProcessIsolationPort));
this.serverUrl = string.Format("http://127.0.0.1:{0}/", this.port);
}

Expand Down
27 changes: 27 additions & 0 deletions win/CS/HandBrakeWPF/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions win/CS/HandBrakeWPF/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2222,4 +2222,13 @@ This is typically an indication that your system does not support the hardware r

Please choose a different preset.</value>
</data>
<data name="OptionsView_ProcessIsolation" xml:space="preserve">
<value>Process Isolation</value>
</data>
<data name="OptionsView_ProcessIsolation_Warning1" xml:space="preserve">
<value>Please note, using this feature will start an HTTP server bound to 127.0.0.1 on the port stated.</value>
</data>
<data name="OptionsView_ProcessIsolation_Warning2" xml:space="preserve">
<value>If the set port is in use, it will find the first free port within +100 from the defined port.</value>
</data>
</root>
4 changes: 2 additions & 2 deletions win/CS/HandBrakeWPF/Services/UserSettingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ private Dictionary<string, object> GetDefaults()
defaults.Add(UserSettingConstants.DefaultPlayer, false);

// Experimental
defaults.Add(UserSettingConstants.RemoteServiceEnabled, true);
defaults.Add(UserSettingConstants.RemoteServicePort, 8037);
defaults.Add(UserSettingConstants.ProcessIsolationEnabled, true);
defaults.Add(UserSettingConstants.ProcessIsolationPort, 8037);

// Misc
defaults.Add(UserSettingConstants.ShowPresetPanel, false);
Expand Down
4 changes: 2 additions & 2 deletions win/CS/HandBrakeWPF/UserSettingConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class UserSettingConstants
public const string PlaySoundWhenDone = "PlaySoundWhenDone";
public const string PlaySoundWhenQueueDone = "PlaySoundWhenQueueDone";
public const string WhenDoneAudioFile = "WhenDoneAudioFile";
public const string RemoteServiceEnabled = "RemoteServiceEnabled";
public const string RemoteServicePort = "RemoteServicePort";
public const string ProcessIsolationEnabled = "ProcessIsolationEnabled";
public const string ProcessIsolationPort = "ProcessIsolationPort";
public const string EnableQuickSyncEncoding = "EnableQuickSyncEncoding";
public const string EnableVceEncoder = "EnableVceEncoder";
public const string EnableNvencEncoder = "EnableNvencEncoder";
Expand Down
6 changes: 3 additions & 3 deletions win/CS/HandBrakeWPF/Utilities/Portable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ public static bool IsHardwareEnabled()
return true; // Default to On.
}

public static bool IsRemoteWorkerProcessEnabled()
public static bool IsProcessIsolationEnabled()
{
if (keyPairs.ContainsKey("remote.worker.enabled"))
if (keyPairs.ContainsKey("process.isolation.enabled"))
{
string enabled = keyPairs["remote.worker.enabled"];
string enabled = keyPairs["process.isolation.enabled"];
if (!string.IsNullOrEmpty(enabled) && enabled.Trim() == "true")
{
return true;
Expand Down
12 changes: 6 additions & 6 deletions win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,11 @@ public int RemoteServicePort
}
}

public bool IsRemoteWorkedAllowed
public bool IsProcessIsolationAllowed
{
get
{
return Portable.IsRemoteWorkerProcessEnabled();
return Portable.IsProcessIsolationEnabled();
}
}

Expand Down Expand Up @@ -1677,8 +1677,8 @@ public override void OnLoad()
// #############################
// Experimental
// #############################
this.RemoteServiceEnabled = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.RemoteServiceEnabled);
this.RemoteServicePort = userSettingService.GetUserSetting<int>(UserSettingConstants.RemoteServicePort);
this.RemoteServiceEnabled = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ProcessIsolationEnabled);
this.RemoteServicePort = userSettingService.GetUserSetting<int>(UserSettingConstants.ProcessIsolationPort);
}

/// <summary>
Expand Down Expand Up @@ -1790,8 +1790,8 @@ private void Save()
this.userSettingService.SetUserSetting(UserSettingConstants.LowBatteryLevel, this.LowBatteryLevel);

/* Experimental */
this.userSettingService.SetUserSetting(UserSettingConstants.RemoteServiceEnabled, this.RemoteServiceEnabled);
this.userSettingService.SetUserSetting(UserSettingConstants.RemoteServicePort, this.RemoteServicePort);
this.userSettingService.SetUserSetting(UserSettingConstants.ProcessIsolationEnabled, this.RemoteServiceEnabled);
this.userSettingService.SetUserSetting(UserSettingConstants.ProcessIsolationPort, this.RemoteServicePort);
}

/// <summary>
Expand Down
11 changes: 7 additions & 4 deletions win/CS/HandBrakeWPF/Views/OptionsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,20 @@
</StackPanel>
</StackPanel>

<StackPanel Orientation="Vertical" Visibility="{Binding IsRemoteWorkedAllowed, Converter={StaticResource boolToVisConverter}}">
<StackPanel Orientation="Vertical" Visibility="{Binding IsProcessIsolationAllowed, Converter={StaticResource boolToVisConverter}}">

<TextBlock Text="Worker Processes" FontSize="14" Margin="0,10,0,10"/>
<TextBlock Text="{x:Static Properties:Resources.OptionsView_ProcessIsolation}" FontSize="14" Margin="0,10,0,10"/>

<CheckBox Content="{x:Static Properties:Resources.OptionsView_EnableWorkerProcesses}" IsChecked="{Binding RemoteServiceEnabled}" Margin="10,5,0,0" />
<TextBlock Text="{x:Static Properties:Resources.OptionsView_ProcessIsolation_Warning1}" Margin="10,0,0,0" TextWrapping="Wrap" FontStyle="Italic" />
<TextBlock Text="{x:Static Properties:Resources.OptionsView_ProcessIsolation_Warning2}" Margin="10,0,0,0" TextWrapping="Wrap" FontStyle="Italic" />

<CheckBox Content="{x:Static Properties:Resources.OptionsView_EnableWorkerProcesses}" IsChecked="{Binding RemoteServiceEnabled}" Margin="10,10,0,0" />

<StackPanel Orientation="Horizontal" Margin="10,10,0,0">
<TextBlock Text="{x:Static Properties:Resources.OptionsView_WorkerDefaultPort}" />
<TextBox Text="{Binding RemoteServicePort}" Width="100" />
</StackPanel>

</StackPanel>


Expand Down
6 changes: 4 additions & 2 deletions win/CS/HandBrakeWPF/portable.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#################################
# Notes:
# - Rename this file to portable.ini to activate feature.
#
# - storage.dir => Stores Presets, Settings and Log Files.
# - tmp.dir => temporary files only. (i.e Preview images)
# - update.check => true | false (enabled / disabled, default disabled for portable)
# - hardware.enabled => true | false (Enables the hardware encoders such as QSV, NVENC or VCE)
# - remote.worker.enabled => true | false (Allows use of the remote worker process 'HandBrake.worker.exe' which uses a localhost http server. Setting to false will process jobs in-process.)
# - process.isolation.enabled => true | false
# (Process Isolation uses an HTTP server on 127.0.0.1 port 8037 or within +100 if in use. This is 'HandBrake.worker.exe' and it is designed to protect the user interface and queue should one job cause an application crash.)
#
# Set to 'cwd' to use the current applications directory. It will automatically create "storage" and "tmp" folders in this instance.
# Leave blank to use the system "TMP" directory and the "AppData" user profile folder.
Expand All @@ -17,4 +19,4 @@ storage.dir = cwd
tmp.dir = cwd
update.check = false
hardware.enabled = true
remote.worker.enabled = true
process.isolation.enabled = true

0 comments on commit c0a4500

Please sign in to comment.