Skip to content

Commit

Permalink
rewrite FirstRun module to allow for simple adding of additional steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Oct 30, 2016
1 parent fee4d58 commit 5873580
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 87 deletions.
2 changes: 1 addition & 1 deletion osu!StreamCompanion/Code/Modules/FirstRun/FirstRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Start(ILogger logger)

private void _setupFrm_Closing(object sender, EventArgs e)
{
CompletedSuccesfully = _setupFrm.completedSuccesfully;
CompletedSuccesfully = _setupFrm.CompletedSuccesfully;
}

public void SetSettingsHandle(Settings settings)
Expand Down
35 changes: 35 additions & 0 deletions osu!StreamCompanion/Code/Modules/FirstRun/FirstRunControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace osu_StreamCompanion.Code.Modules.FirstRun
{
public class CompletedEventArgs :EventArgs
{
public FirstRunControl.status ControlCompletionStatus { get; set; }
}
public class FirstRunControl : UserControl
{
public event EventHandler<CompletedEventArgs> Completed;

protected void OnCompleted(status completionStatus)
{
this.Completed?.Invoke(this,new CompletedEventArgs() {ControlCompletionStatus = completionStatus});
}
public enum status
{
Unknown = 0,
Ok = 1,
Fail=2,
}

public virtual void GotMsn(string msnString)
{
}
public virtual void GotOsuDirectory(string osuDir)
{
}
}
}

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

76 changes: 43 additions & 33 deletions osu!StreamCompanion/Code/Modules/FirstRun/FirstRunFrm.cs
Original file line number Diff line number Diff line change
@@ -1,69 +1,79 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using osu_StreamCompanion.Code.Core;
using osu_StreamCompanion.Code.Misc;
using osu_StreamCompanion.Code.Modules.FirstRun.Phases;

namespace osu_StreamCompanion.Code.Modules.FirstRun
{
public partial class FirstRunFrm : Form
{
private readonly SettingNames _names = SettingNames.Instance;

private Phase1 _phase1;
private Phase2 _phase2;

private Settings _settings;

public bool completedSuccesfully
{
get { return _phase2 != null; }
}
private List<FirstRunControl> phases = new List<FirstRunControl>();
public bool CompletedSuccesfully { get; set; }

public FirstRunFrm(Settings settings)
{
_settings = settings;
phases.Add(new FirstRunMsn());
phases.Add(new FirstRunFinish());
InitializeComponent();
}

private int _currentPhase = 0;
public void StartSetup()
{
_phase1 = new Phase1();
this.Controls.Add(_phase1);
this.ShowDialog();
if (phases.Count > 0)
{
var first = phases[0];
first.Completed += Phase_Completed;
this.Controls.Add(first);
this.ShowDialog();
}
else
{
CompletedSuccesfully = true;
}
}
public void GotMsn(string msnString)

private void Phase_Completed(object sender, CompletedEventArgs e)
{
if (_phase1 != null)
this.BeginInvoke((MethodInvoker)delegate
{
this.BeginInvoke((MethodInvoker)delegate
phases[_currentPhase].Completed -= Phase_Completed;
this.Controls.RemoveAt(0);
if (phases.Count > _currentPhase+1)
{
this.Controls.RemoveAt(0);
_phase1.Dispose();
_phase1 = null;

_phase2 = new Phase2();
_phase2.button_end.Click += ButtonEndOnClick;
_phase2.label_msnString.Text = msnString;
_phase2.label_osuDirectory.Text = _settings.Get<string>(_names.MainOsuDirectory);
this.Controls.Add(_phase2);
});
}
if (_phase2 != null)
if (_phase2.Created)
_currentPhase++;
var current = phases[_currentPhase];
current.Completed += Phase_Completed;
this.Controls.Add(current);
}
else
{
_phase2.BeginInvoke((MethodInvoker)delegate
CompletedSuccesfully = true;
this.BeginInvoke((MethodInvoker)delegate ()
{
_phase2.label_msnString.Text = msnString;
this.Close();
});
}
});
}

private void ButtonEndOnClick(object sender, EventArgs eventArgs)
public void GotMsn(string msnString)
{
this.BeginInvoke((MethodInvoker) delegate()
var osuDir = _settings.Get<string>(_names.MainOsuDirectory);

foreach (var phase in phases)
{
this.Close();
});
phase.GotMsn(msnString);
phase.GotOsuDirectory(osuDir);
}
}

}
}

12 changes: 0 additions & 12 deletions osu!StreamCompanion/Code/Modules/FirstRun/Phase1.cs

This file was deleted.

12 changes: 0 additions & 12 deletions osu!StreamCompanion/Code/Modules/FirstRun/Phase2.cs

This file was deleted.

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

56 changes: 56 additions & 0 deletions osu!StreamCompanion/Code/Modules/FirstRun/Phases/FirstRunFinish.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Windows.Forms;

namespace osu_StreamCompanion.Code.Modules.FirstRun.Phases
{
public partial class FirstRunFinish : FirstRunControl
{
public FirstRunFinish()
{
InitializeComponent();
this.HandleCreated += Finish_HandleCreated;
}

private void Finish_HandleCreated(object sender, System.EventArgs e)
{
this.label_msnString.Text = msnString;
this.label_osuDirectory.Text = osuDir;
}

private string msnString;
private string osuDir;
public override void GotMsn(string msnString)
{
if (this.IsHandleCreated)
{
this.BeginInvoke((MethodInvoker) delegate
{
this.label_msnString.Text = msnString;
});
}
else
{
this.msnString = msnString;
}
}

public override void GotOsuDirectory(string osuDir)
{
if (this.IsHandleCreated)
{
this.BeginInvoke((MethodInvoker)delegate
{
this.label_osuDirectory.Text = osuDir;
});
}
else
{
this.osuDir = osuDir;
}
}

private void button_end_Click(object sender, System.EventArgs e)
{
this.OnCompleted(status.Ok);
}
}
}

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

15 changes: 15 additions & 0 deletions osu!StreamCompanion/Code/Modules/FirstRun/Phases/FirstRunMsn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace osu_StreamCompanion.Code.Modules.FirstRun.Phases
{
public partial class FirstRunMsn : FirstRunControl
{
public FirstRunMsn()
{
InitializeComponent();
}

public override void GotMsn(string msnString)
{
this.OnCompleted(status.Ok);
}
}
}
Loading

0 comments on commit 5873580

Please sign in to comment.