/
BulkExportOutputFormatStage.cs
357 lines (306 loc) · 11.1 KB
/
BulkExportOutputFormatStage.cs
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
using System;
using System.Drawing;
using System.IO;
using System.Net.NetworkInformation;
using System.Windows.Forms;
using Common.Controls;
using Common.Controls.Scaling;
using Common.Controls.Theme;
using Common.Controls.Wizard;
using Common.Resources;
using Common.Resources.Properties;
using NLog;
namespace VixenModules.App.ExportWizard
{
public partial class BulkExportOutputFormatStage : WizardStage
{
private static readonly Logger Logging = LogManager.GetCurrentClassLogger();
private readonly BulkExportWizardData _data;
public BulkExportOutputFormatStage(BulkExportWizardData data)
{
_data = data;
InitializeComponent();
int iconSize = (int)(16 * ScalingTools.GetScaleFactor());
btnOuputFolderSelect.Image = Tools.GetIcon(Resources.folder_explore, iconSize);
btnOuputFolderSelect.Text = "";
btnAudioOutputFolder.Image = Tools.GetIcon(Resources.folder_explore, iconSize);
btnAudioOutputFolder.Text = "";
btnFalconUniverseFolder.Image = Tools.GetIcon(Resources.folder_explore, iconSize);
btnFalconUniverseFolder.Text = "";
ThemeUpdateControls.UpdateControls(this);
txtFalconInfo.BackColor = ThemeColorTable.BackgroundColor;
SizeFalconInfo();
}
private void SizeFalconInfo()
{
// amount of padding to add
const int padding = 3;
// get number of lines (first line is 0, so add 1)
int numLines = txtFalconInfo.GetLineFromCharIndex(txtFalconInfo.TextLength) + 1;
// get border thickness
int border = txtFalconInfo.Height - txtFalconInfo.ClientSize.Height;
// set height (height of one line * number of lines + spacing)
txtFalconInfo.Height = txtFalconInfo.Font.Height * numLines + padding + border;
}
public override void StageStart()
{
outputFormatComboBox.Items.Clear();
outputFormatComboBox.Items.AddRange(_data.Export.FormatTypes);
outputFormatComboBox.Sorted = true;
outputFormatComboBox.SelectedItem = _data.ActiveProfile.Format;
resolutionComboBox.SelectedItem = _data.ActiveProfile.Interval.ToString();
txtOutputFolder.Text = _data.ActiveProfile.OutputFolder;
chkFppIncludeAudio.Checked = chkIncludeAudio.Checked = _data.ActiveProfile.IncludeAudio;
chkRenameAudio.Enabled = btnAudioOutputFolder.Enabled = lblAudioExportPath.Enabled = txtAudioOutputFolder.Enabled = _data.ActiveProfile.IncludeAudio;
chkRenameAudio.Checked = _data.ActiveProfile.RenameAudio;
grpFalcon.Visible = _data.ActiveProfile.IsFalconFormat;
grpAudio.Visible = grpSequence.Visible = !grpFalcon.Visible;
chkCreateUniverseFile.Checked = _data.ActiveProfile.CreateUniverseFile;
chkBackupUniverseFile.Checked = _data.ActiveProfile.BackupUniverseFile;
txtFalconOutputFolder.Text = _data.ActiveProfile.FalconOutputFolder;
txtAudioOutputFolder.Text = _data.ActiveProfile.AudioOutputFolder;
_WizardStageChanged();
}
private void btnOuputFolderSelect_Click(object sender, EventArgs e)
{
var folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
folderBrowserDialog.SelectedPath = _data.ActiveProfile.OutputFolder;
folderBrowserDialog.Description = @"Select the sequence export location";
DialogResult dr = folderBrowserDialog.ShowDialog();
if (dr == DialogResult.OK)
{
_data.ActiveProfile.OutputFolder = folderBrowserDialog.SelectedPath;
txtOutputFolder.Text = _data.ActiveProfile.OutputFolder;
_WizardStageChanged();
}
}
private void txtOutputFolder_Leave(object sender, EventArgs e)
{
_data.ActiveProfile.OutputFolder = txtOutputFolder.Text;
ValidatePath(_data.ActiveProfile.OutputFolder);
_WizardStageChanged();
}
private void btnAudioOutputFolder_Click(object sender, EventArgs e)
{
var folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
folderBrowserDialog.SelectedPath = _data.ActiveProfile.AudioOutputFolder;
folderBrowserDialog.Description = @"Select the audio export location";
DialogResult dr = folderBrowserDialog.ShowDialog();
if (dr == DialogResult.OK)
{
_data.ActiveProfile.AudioOutputFolder = folderBrowserDialog.SelectedPath;
txtAudioOutputFolder.Text = _data.ActiveProfile.AudioOutputFolder;
_WizardStageChanged();
}
}
private void txtAudioOutputFolder_Leave(object sender, EventArgs e)
{
_data.ActiveProfile.OutputFolder = txtAudioOutputFolder.Text;
ValidatePath(_data.ActiveProfile.AudioOutputFolder);
_WizardStageChanged();
}
private void btnFalconOutputFolder_Click(object sender, EventArgs e)
{
var folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
folderBrowserDialog.SelectedPath = _data.ActiveProfile.FalconOutputFolder;
folderBrowserDialog.Description = @"Select the universe file export location";
DialogResult dr = folderBrowserDialog.ShowDialog();
if (dr == DialogResult.OK)
{
UpdateFalconPaths(folderBrowserDialog.SelectedPath);
ValidateFalconOutputFolder();
}
}
private void UpdateFalconPaths(string path)
{
_data.ActiveProfile.FalconOutputFolder = path;
txtFalconOutputFolder.Text = path;
if (!string.IsNullOrEmpty(path))
{
_data.ActiveProfile.OutputFolder = Path.Combine(path, _data.ActiveProfile.IsFalconEffectFormat ? @"effects" : @"sequences");
_data.ActiveProfile.AudioOutputFolder = Path.Combine(path, @"music");
}
_WizardStageChanged();
}
private bool ValidateFalconOutputFolder()
{
var path = _data.ActiveProfile.FalconOutputFolder;
if (string.IsNullOrEmpty(path)) return false;
if (CanTestPath() && Directory.Exists(path))
{
_data.ActiveProfile.FalconOutputFolder = path;
return true;
}
var messageBox =
new MessageBoxForm("The selected output path does not exist. Do you want to create it?",
"Invalid output path", MessageBoxButtons.OKCancel, SystemIcons.Error);
var response = messageBox.ShowDialog(this);
if (response == DialogResult.OK)
{
try
{
Directory.CreateDirectory(path);
_WizardStageChanged();
return true;
}
catch (Exception e)
{
messageBox = new MessageBoxForm($"Unable to create the target directory.\n{e.Message}",
"Error creating directory.", MessageBoxButtons.OK, SystemIcons.Error);
messageBox.ShowDialog(this);
Logging.Error(e, "An error occured trying to create the Falcon target directory structure.");
}
}
return false;
}
public override bool CanMoveNext
{
get
{
if (_data.ActiveProfile.IsFalconFormat)
{
if (CanTestPath() && Directory.Exists(_data.ActiveProfile.FalconOutputFolder))
{
return true;
}
return false;
}
bool ok = Directory.Exists(_data.ActiveProfile.OutputFolder);
if (_data.ActiveProfile.IncludeAudio && !Directory.Exists((_data.ActiveProfile.AudioOutputFolder)))
{
ok = false;
}
return ok;
}
}
private void ValidatePath(string path)
{
if (!Directory.Exists(path))
{
var messageBox =
new MessageBoxForm("The selected output path does not exist. Do you want to create it?",
"Invalid output path", MessageBoxButtons.OKCancel, SystemIcons.Error);
var response = messageBox.ShowDialog(this);
if (response == DialogResult.OK)
{
try
{
Directory.CreateDirectory(path);
_WizardStageChanged();
}
catch (Exception e)
{
messageBox = new MessageBoxForm($"Unable to create the target directory.\n{e.Message}",
"Error creating directory.", MessageBoxButtons.OK, SystemIcons.Error);
messageBox.ShowDialog(this);
Logging.Error(e, "An error occured trying to create the Falcon target directory structure.");
}
}
}
}
private bool CanTestPath()
{
bool success = true;
if (!string.IsNullOrEmpty(_data.ActiveProfile.FalconOutputFolder))
{
try
{
Uri uri = new Uri(_data.ActiveProfile.FalconOutputFolder);
if (uri.HostNameType != UriHostNameType.Unknown && !string.IsNullOrEmpty(uri.Host))
{
success = PingHost(uri.Host);
}
}
catch (Exception e)
{
Logging.Error(e, "Error determining if path can be tested.");
success = false;
}
}
return success;
}
public static bool PingHost(string nameOrAddress)
{
bool pingable = false;
Ping pinger = null;
try
{
pinger = new Ping();
PingReply reply = pinger.Send(nameOrAddress,500);
if (reply != null) pingable = reply.Status == IPStatus.Success;
}
catch (PingException)
{
// Discard PingExceptions and return false;
}
finally
{
pinger?.Dispose();
}
return pingable;
}
private void groupBoxes_Paint(object sender, PaintEventArgs e)
{
ThemeGroupBoxRenderer.GroupBoxesDrawBorder(sender, e, Font);
}
private void comboBox_DrawItem(object sender, DrawItemEventArgs e)
{
ThemeComboBoxRenderer.DrawItem(sender, e);
}
private void outputFormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox comboBox = (ComboBox)sender;
_data.ActiveProfile.Format = comboBox.SelectedItem.ToString();
grpFalcon.Visible = _data.ActiveProfile.IsFalconFormat;
grpAudio.Visible = grpSequence.Visible = !grpFalcon.Visible;
if (_data.ActiveProfile.IsFalconFormat)
{
UpdateFalconPaths(_data.ActiveProfile.FalconOutputFolder);
ValidateFalconOutputFolder();
}
_WizardStageChanged();
}
private void resolutionComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox comboBox = (ComboBox)sender;
_data.ActiveProfile.Interval = Convert.ToInt32(comboBox.SelectedItem);
}
private void chkIncludeAudio_CheckedChanged(object sender, EventArgs e)
{
if (_data.ActiveProfile.IsFalconFormat)
{
_data.ActiveProfile.RenameAudio = chkFppIncludeAudio.Checked;
_data.ActiveProfile.IncludeAudio = chkFppIncludeAudio.Checked;
}
else
{
_data.ActiveProfile.IncludeAudio = chkIncludeAudio.Checked;
chkRenameAudio.Enabled = btnAudioOutputFolder.Enabled = lblAudioExportPath.Enabled = txtAudioOutputFolder.Enabled = chkIncludeAudio.Checked;
}
}
private void chkRenameAudio_CheckedChanged(object sender, EventArgs e)
{
_data.ActiveProfile.RenameAudio = chkRenameAudio.Checked;
}
private void chkCreateUniverseFile_CheckedChanged(object sender, EventArgs e)
{
_data.ActiveProfile.CreateUniverseFile = chkCreateUniverseFile.Checked;
}
private void chkBackupUniverseFile_CheckedChanged(object sender, EventArgs e)
{
_data.ActiveProfile.BackupUniverseFile = chkBackupUniverseFile.Checked;
}
private void txtFalconOutputFolder_Leave(object sender, EventArgs e)
{
UpdateFalconPaths(txtFalconOutputFolder.Text);
ValidateFalconOutputFolder();
}
private void txtFalconOutputFolder_TextChanged(object sender, EventArgs e)
{
//UpdateFalconPaths(txtFalconOutputFolder.Text);
}
}
}