@@ -61,7 +61,50 @@ private void UpdateGuiState()
6161 || passwordTextBox . Text . Length == 0
6262 || passwordTextBox2 . Text . Length == 0 ) ;
6363
64- startButton . Enabled = ! isEmpty ;
64+ applyButton . Enabled = ! isEmpty ;
65+ }
66+
67+ private bool ValidateSettings ( string bootDrive )
68+ {
69+ if ( ! Directory . Exists ( bootDrive ) )
70+ {
71+ MessageBox . Show ( "The drive you have selected is no longer accessible." , "Error" ,
72+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
73+ return false ;
74+ }
75+
76+ if ( ! File . Exists ( Path . Combine ( bootDrive , "kernel.img" ) ) )
77+ {
78+ MessageBox . Show ( "The drive you have selected is not a Raspbian SD card." , "Error" ,
79+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
80+ return false ;
81+ }
82+
83+ if ( passwordTextBox . Text != passwordTextBox2 . Text )
84+ {
85+ MessageBox . Show ( "The passwords you have entered do not match." , "Error" ,
86+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
87+ return false ;
88+ }
89+
90+ if ( typeComboBox . SelectedIndex == 0 && ( passwordTextBox . Text . Length < 8
91+ || passwordTextBox . Text . Length > 63 ) )
92+ {
93+ MessageBox . Show ( "Password must be between 8 and 63 characters long for WPA " +
94+ "Personal network." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
95+ return false ;
96+ }
97+
98+ if ( typeComboBox . SelectedIndex == 1 && passwordTextBox . Text . Length > 14
99+ && encryptCheckBox . Checked )
100+ {
101+ MessageBox . Show ( "Password cannot exceed 14 characters in length for WPA " +
102+ "Enterprise network when encryption is enabled." , "Error" ,
103+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
104+ return false ;
105+ }
106+
107+ return true ;
65108 }
66109
67110 private void ConfigureImage ( string bootDrive , string networkConfig , bool enableSsh )
@@ -73,7 +116,7 @@ private void ConfigureImage(string bootDrive, string networkConfig, bool enableS
73116 {
74117 DialogResult result = MessageBox . Show ( "The file /boot/wpa_supplicant.conf " +
75118 "already exists on the SD card. Are you sure you want to overwrite it?" ,
76- "Question" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) ;
119+ "Question" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
77120 writeConfig = ( result == DialogResult . Yes ) ;
78121 }
79122
@@ -102,62 +145,33 @@ private void refreshButton_Click(object sender, EventArgs e)
102145 UpdateDriveList ( ) ;
103146 }
104147
105- private void startButton_Click ( object sender , EventArgs e )
148+ private void applyButton_Click ( object sender , EventArgs e )
106149 {
107150 string bootDrive = driveComboBox . GetItemText (
108151 driveComboBox . SelectedItem ) . Split ( ' ' ) [ 0 ] . TrimEnd ( '\\ ' ) ;
109-
110- if ( ! Directory . Exists ( bootDrive ) )
111- {
112- MessageBox . Show ( "The drive you have selected is no longer accessible." , "Error" ,
113- MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
114- return ;
115- }
116-
117- if ( ! File . Exists ( Path . Combine ( bootDrive , "kernel.img" ) ) )
118- {
119- MessageBox . Show ( "The drive you have selected is not a Raspbian SD card." , "Error" ,
120- MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
121- return ;
122- }
123-
124- if ( passwordTextBox . Text != passwordTextBox2 . Text )
152+
153+ if ( ! ValidateSettings ( bootDrive ) )
125154 {
126- MessageBox . Show ( "The passwords you have entered do not match." , "Error" ,
127- MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
128- return ;
129- }
130-
131- if ( typeComboBox . SelectedIndex == 0 && ( passwordTextBox . Text . Length < 8
132- || passwordTextBox . Text . Length > 63 ) )
133- {
134- MessageBox . Show ( "Password must be between 8 and 63 characters long." , "Error" ,
135- MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
136- return ;
137- }
138- else if ( typeComboBox . SelectedIndex == 1 && passwordTextBox . Text . Length > 14 )
139- {
140- MessageBox . Show ( "Password cannot exceed 14 characters in length." , "Error" ,
141- MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
142155 return ;
143156 }
144157
145158 string networkName = nameTextBox . Text ;
146159 string username = userTextBox . Text ;
147160 string password = passwordTextBox . Text ;
161+ bool shouldEncrypt = encryptCheckBox . Checked ;
148162 string networkConfig ;
149163
150164 if ( typeComboBox . SelectedIndex == 0 )
151165 {
152- networkConfig = WpaPersonal . GetConfig ( networkName , password ) ;
166+ networkConfig = WpaPersonal . GetConfig ( networkName , password , shouldEncrypt ) ;
153167 }
154168 else
155169 {
156- networkConfig = WpaEnterprise . GetConfig ( networkName , username , password ) ;
170+ networkConfig = WpaEnterprise . GetConfig ( networkName , username , password ,
171+ shouldEncrypt ) ;
157172 }
158173
159174 ConfigureImage ( bootDrive , networkConfig , sshCheckBox . Checked ) ;
160-
161175 MessageBox . Show ( "SD card image has been configured successfully." , "Info" ) ;
162176 }
163177
0 commit comments