Skip to content

Commit d5fe30c

Browse files
committed
Only show AutoDiscover/revert options when necessary
1 parent 10ec4a7 commit d5fe30c

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

Refresher.Core/Pipelines/PS3PatchPipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class PS3PatchPipeline : Pipeline
88
public override string Name => "PS3 Patch";
99

1010
protected override Type SetupAccessorStepType => typeof(SetupPS3AccessorStep);
11-
protected override bool ReplacesEboot => true;
11+
public override bool ReplacesEboot => true;
1212

1313
public override string GuideLink => "https://docs.littlebigrefresh.com/ps3";
1414

Refresher.Core/Pipelines/Pipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public float Progress
4646
public float CurrentProgress => this.State == PipelineState.Finished ? 1 : this._currentStep?.Progress ?? 0;
4747

4848
protected virtual Type? SetupAccessorStepType => null;
49-
protected virtual bool ReplacesEboot => false;
49+
public virtual bool ReplacesEboot => false;
5050

5151
protected abstract List<Type> StepTypes { get; }
5252
private List<Step> _steps = [];

Refresher/UI/PipelineForm.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace Refresher.UI;
2121
private TPipeline? _pipeline;
2222

2323
private readonly Button _button;
24-
private readonly Button _revertButton;
25-
private readonly Button _autoDiscoverButton;
24+
private readonly Button? _revertButton;
25+
private readonly Button? _autoDiscoverButton;
2626
private readonly ProgressBar _currentProgressBar;
2727
private readonly ProgressBar _progressBar;
2828
private readonly ListBox _messages;
@@ -38,6 +38,7 @@ namespace Refresher.UI;
3838

3939
public PipelineForm() : base(typeof(TPipeline).Name, new Size(700, -1), false)
4040
{
41+
StackLayout layout;
4142
this.Content = new Splitter
4243
{
4344
Orientation = Orientation.Vertical,
@@ -47,14 +48,12 @@ namespace Refresher.UI;
4748
Spacing = new Size(5, 5),
4849
Padding = new Padding(0, 0, 0, 10),
4950
},
50-
Panel2 = new StackLayout([
51+
Panel2 = layout = new StackLayout([
5152
new StackLayoutItem(this._messages = new ListBox
5253
{
5354
Height = -1,
5455
}, VerticalAlignment.Top, true),
5556
this._button = new Button(this.OnButtonClick) { Text = "Patch!" },
56-
this._revertButton = new Button(this.OnRevertEbootClick) { Text = "Revert EBOOT" },
57-
this._autoDiscoverButton = new Button(this.OnAutoDiscoverClick) { Text = "AutoDiscover" },
5857
new Button(this.OnViewGuideClick) { Text = "View Guide" },
5958
this._currentProgressBar = new ProgressBar(),
6059
this._progressBar = new ProgressBar(),
@@ -71,6 +70,18 @@ namespace Refresher.UI;
7170
this.InitializePipeline();
7271
this.InitializeFormStateUpdater();
7372

73+
if (this._pipeline?.ReplacesEboot ?? false)
74+
{
75+
this._revertButton = new Button(this.OnRevertEbootClick) { Text = "Revert EBOOT" };
76+
layout.Items.Insert(2, this._revertButton);
77+
}
78+
79+
if (this._pipeline?.RequiredInputs.Any(i => i == CommonStepInputs.ServerUrl) ?? false)
80+
{
81+
this._autoDiscoverButton = new Button(this.OnAutoDiscoverClick) { Text = "AutoDiscover" };
82+
layout.Items.Insert(2, this._autoDiscoverButton);
83+
}
84+
7485
State.Log += this.OnLog;
7586
}
7687

@@ -89,14 +100,19 @@ private void UpdateFormState()
89100

90101
// disable other things
91102
this._formLayout.Enabled = enableControls;
92-
this._autoDiscoverButton.Enabled = enableControls && this._pipeline?.AutoDiscover == null;
93-
this._revertButton.Enabled = enableControls;
103+
if(this._autoDiscoverButton != null)
104+
this._autoDiscoverButton.Enabled = enableControls && this._pipeline?.AutoDiscover == null;
105+
if(this._revertButton != null)
106+
this._revertButton.Enabled = enableControls;
94107

95108
// set text of autodiscover button
96-
if (this._autoDiscoverCts != null)
97-
this._autoDiscoverButton.Text = "Running AutoDiscover... (click to cancel)";
98-
else if (this._pipeline?.AutoDiscover == null)
99-
this._autoDiscoverButton.Text = "AutoDiscover";
109+
if (this._autoDiscoverButton != null)
110+
{
111+
if (this._autoDiscoverCts != null)
112+
this._autoDiscoverButton.Text = "Running AutoDiscover... (click to cancel)";
113+
else if (this._pipeline?.AutoDiscover == null)
114+
this._autoDiscoverButton.Text = "AutoDiscover";
115+
}
100116

101117
this._button.Text = this._pipeline?.State switch
102118
{
@@ -195,9 +211,9 @@ private void OnButtonClick(object? sender, EventArgs e)
195211
this._pipeline.Reset();
196212
}
197213

198-
if (!this._usedAutoDiscover)
214+
if (!this._usedAutoDiscover && this._autoDiscoverButton != null)
199215
{
200-
DialogResult result = MessageBox.Show("You didn't use AutoDiscover. Would you like to try to run it now?", "AutoDiscover",
216+
DialogResult result = MessageBox.Show("You haven't used AutoDiscover. Would you like to try to run it now?", "AutoDiscover",
201217
MessageBoxButtons.YesNoCancel, MessageBoxType.Question);
202218

203219
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault

0 commit comments

Comments
 (0)