forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultSettings.cs
108 lines (89 loc) · 3.23 KB
/
DefaultSettings.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
using log4net;
using MissionPlanner.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MissionPlanner.Controls
{
public partial class DefaultSettings : UserControl, IActivate
{
private static readonly ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
List<GitHubContent.FileInfo> paramfiles;
public event EventHandler OnChange;
public DefaultSettings()
{
InitializeComponent();
}
public void Activate()
{
CMB_paramfiles.Enabled = false;
BUT_paramfileload.Enabled = false;
UpdateDefaultList();
}
void UpdateDefaultList()
{
Task.Run(delegate ()
{
try
{
if (paramfiles == null)
{
paramfiles = GitHubContent.GetDirContent("ardupilot", "ardupilot", "/Tools/Frame_params/", ".param");
}
if (!this.IsHandleCreated || this.IsDisposed)
return;
this.BeginInvoke((Action)delegate
{
CMB_paramfiles.DataSource = paramfiles.ToArray();
CMB_paramfiles.DisplayMember = "name";
CMB_paramfiles.Enabled = true;
BUT_paramfileload.Enabled = true;
});
}
catch (Exception ex)
{
log.Error(ex);
}
});
}
private void BUT_paramfileload_Click(object sender, EventArgs e)
{
string filepath = Settings.GetUserDataDirectory() + CMB_paramfiles.Text;
if (CMB_paramfiles.SelectedValue == null)
{
CustomMessageBox.Show("Please select an option first");
return;
}
try
{
byte[] data = GitHubContent.GetFileContent("ardupilot", "ardupilot",
((GitHubContent.FileInfo)CMB_paramfiles.SelectedValue).path);
File.WriteAllBytes(filepath, data);
var param2 = Utilities.ParamFile.loadParamFile(filepath);
Form paramCompareForm = new ParamCompare(null, MainV2.comPort.MAV.param, param2);
ThemeManager.ApplyThemeTo(paramCompareForm);
if (paramCompareForm.ShowDialog() == DialogResult.OK)
{
CustomMessageBox.Show("Loaded parameters!", "Loaded");
}
if (OnChange != null)
{
OnChange(null, null);
return;
}
this.Activate();
}
catch (Exception ex)
{
CustomMessageBox.Show("Failed to load file.\n" + ex);
}
}
private void ConfigDefaultSettings_Load(object sender, EventArgs e)
{
Activate();
}
}
}