blob: 2193f8a2ad45edc4cd384a48bd6dc93cb79c13bb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine;
namespace ShiftOS.WinForms.Applications
{
[WinOpen("installer")]
[RequiresUpgrade("installer")]
[MultiplayerOnly]
[DefaultTitle("Installer")]
[Launcher("Installer", true, "al_installer", "Utilities")]
public partial class Installer : UserControl, IShiftOSWindow
{
public Installer()
{
InitializeComponent();
lbtitle.Text = "Select file";
}
public void InitiateInstall(Installation install)
{
pnlselectfile.Hide();
install.ProgressReported += (p) =>
{
this.Invoke(new Action(() =>
{
pginstall.Value = p;
}));
};
install.StatusReported += (s) =>
{
this.Invoke(new Action(() =>
{
lbprogress.Text = s;
}));
};
install.InstallCompleted += () =>
{
this.Invoke(new Action(() =>
{
lbtitle.Text = "Select file";
pnlselectfile.Show();
}));
isInstalling = false;
InstallCompleted?.Invoke();
};
isInstalling = true;
install.Install();
}
public void OnLoad()
{
}
private bool isInstalling = false;
public void OnSkinLoad()
{
}
public bool OnUnload()
{
return !isInstalling; //Don't close if an install is running.
}
public void OnUpgrade()
{
}
private void pnlselectfile_VisibleChanged(object sender, EventArgs e)
{
if(this.ParentForm != null)
{
this.ParentForm.Height = (pnlselectfile.Visible == true) ? this.ParentForm.Height + pnlselectfile.Height : this.ParentForm.Height - pnlselectfile.Height;
}
}
public event Action InstallCompleted;
}
public abstract class Installation
{
/// <summary>
/// The display name of the installation.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Occurs when the installation updates its status.
/// </summary>
public event Action<string> StatusReported;
/// <summary>
/// Occurs when the installation updates its progress percentage.
/// </summary>
public event Action<int> ProgressReported;
/// <summary>
/// Occurs when the installation completes.
/// </summary>
public event Action InstallCompleted;
/// <summary>
/// Start the installation.
/// </summary>
public void Install()
{
var t = new System.Threading.Thread(() =>
{
ProgressReported?.Invoke(0);
StatusReported?.Invoke("");
Run();
ProgressReported?.Invoke(100);
StatusReported?.Invoke("Installation completed.");
InstallCompleted?.Invoke();
});
t.IsBackground = true;
t.Start();
}
/// <summary>
/// Sets the install progress percentage.
/// </summary>
/// <param name="value">The installation percentage.</param>
protected void SetProgress(int value)
{
if (value < 0 || value > 100)
throw new ArgumentOutOfRangeException("value", "A percentage is typically between 0 and 100.... derp...");
ProgressReported?.Invoke(value);
}
/// <summary>
/// Sets the install status text.
/// </summary>
/// <param name="status">Text to display as status.</param>
protected void SetStatus(string status)
{
StatusReported?.Invoke(status);
}
/// <summary>
/// User-defined code to run during install. Once this code is ran, the installation is complete.
/// </summary>
protected abstract void Run();
}
}
|