Skip to content

Commit d8b04e3

Browse files
committed
Added more error handling and clearer messages
1 parent fd570c0 commit d8b04e3

File tree

7 files changed

+142
-74
lines changed

7 files changed

+142
-74
lines changed

CHANGELOG.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
# Changelog
22

3+
## Known issues
4+
5+
* FTP connection seems to not be possible with Miniserver Gen 2
6+
7+
## v1.0.1.1
8+
9+
* Added: FTP error handling for upload and download by @mr-manuel
10+
* Added: Message that Miniserver newer generations are not supported by @mr-manuel
11+
* Added: Notes on how to apply modified statistics (in save dialog) by @mr-manuel
12+
* Changed: Edit | Download | Upload to Download | Edit | Upload by @mr-manuel
13+
314
## v1.0.1.0
415

5-
* Added: FTP error handling by @mr-manuel
16+
* Added: FTP error handling for fetching filelist by @mr-manuel
617
* Added: Keyboard shortcuts by @mr-manuel
718

819
**Miniserver Browser**
920
* `ALT + M`: Refresh MS
1021
* `ALT + F`: Refresh FS
1122
* Press `Enter` in the `Miniserver` input field: Refresh MS
12-
* Press `Enter` in the `Working Folder` input field: Refresh MS
23+
* Press `Enter` in the `Working Folder` input field: Refresh FS
1324

1425
**File Editor**
1526
* `ALT + B`: Browse
@@ -20,7 +31,3 @@
2031
* Added: Version info and GitHub link by @mr-manuel
2132
* Changed: Fixed button position in statistic editor by @mr-manuel
2233
* Changed: Fixed error when # was in password by @mr-manuel
23-
24-
### Known issues
25-
26-
* FTP connection seems to not be possible with Miniserver Gen 2

LoxStatFileForm.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,32 @@ private void SaveButton_Click(object sender, EventArgs e)
152152
RefreshProblems();
153153
if(_problems.Any())
154154
ShowProblems();
155-
if(MessageBox.Show(this, "- I will not (and can not) take any " +
156-
"responsibility for any issues of your Loxone installation whatsoever!\n" +
157-
"- Loxone will most likely not support any issues if you use the files " +
158-
"generated by this tool either!\n" +
159-
"- I am just a desparate Loxone user in need of a solution for a problem " +
160-
"and lucky enough to be a professional coder!\n" +
161-
"- Loxone did not provide me a full file format documentation and I used " +
162-
"Hexinator (thank you!) to decode the file format to some degree!\n\n" +
155+
if(MessageBox.Show(
156+
this,
157+
"### DISCLAIMER ###\n" +
158+
"- I will not (and can not) take any responsibility for any\n" +
159+
" issues of your Loxone installation whatsoever!\n" +
160+
"- Loxone will most likely not support any issues, if you use the\n" +
161+
" files generated by this tool either!\n" +
162+
"- I am just a desparate Loxone user in need of a solution for a\n" +
163+
" problem and lucky enough to be a professional coder!\n" +
164+
"- Loxone did not provide me a full file format documentation\n" +
165+
" and I used Hexinator (thank you!) to decode the file format\n" +
166+
" to some degree!\n\n" +
167+
"### NOTICE ###\n" +
168+
"To apply the modified statistics further steps are needed!\n" +
169+
"1. Upload the modified statistics\n" +
170+
"2. Restart the Miniserver\n" + "" +
171+
"3. Clear the app cache\n" +
172+
"If you don't know how to clear the app cache, then remove\n" +
173+
"and re-add the Miniserver in the app. Should this not help\n" + "" +
174+
"then uninstall and install the app again.\n\n" +
163175
"Would you still like to save the file?",
164-
"DISCLAIMER! USE AT YOUR OWN RISK!", MessageBoxButtons.YesNo,
165-
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
176+
"DISCLAIMER! USE AT YOUR OWN RISK!",
177+
MessageBoxButtons.YesNo,
178+
MessageBoxIcon.Warning,
179+
MessageBoxDefaultButton.Button2
180+
) != DialogResult.Yes)
166181
return;
167182
_loxStatFile.FileName = Path.GetFullPath(_fileNameTextBox.Text);
168183
_loxStatFile.Save();

MiniserverForm.Designer.cs

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MiniserverForm.cs

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,56 @@ private Uri GetFileNameUri(string fileName)
186186

187187
private void Download(FileItem fileItem)
188188
{
189-
var ftpWebRequest = (FtpWebRequest)FtpWebRequest.
189+
try
190+
{
191+
var ftpWebRequest = (FtpWebRequest)FtpWebRequest.
190192
Create(GetFileNameUri(fileItem.FileName));
191-
ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile;
192-
var targetFileName = Path.Combine(_folderTextBox.Text, fileItem.FileName);
193-
using(var response = ftpWebRequest.GetResponse())
194-
using(var ftpStream = response.GetResponseStream())
195-
using(var fileStream = File.OpenWrite(targetFileName))
196-
ftpStream.CopyTo(fileStream);
197-
File.SetLastWriteTime(targetFileName, fileItem.MsFileInfo.Date);
193+
ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile;
194+
var targetFileName = Path.Combine(_folderTextBox.Text, fileItem.FileName);
195+
using(var response = ftpWebRequest.GetResponse())
196+
using(var ftpStream = response.GetResponseStream())
197+
using(var fileStream = File.OpenWrite(targetFileName))
198+
ftpStream.CopyTo(fileStream);
199+
File.SetLastWriteTime(targetFileName, fileItem.MsFileInfo.Date);
200+
}
201+
catch (WebException ex)
202+
{
203+
var response = ex.Response as FtpWebResponse;
204+
if (response != null)
205+
{
206+
MessageBox.Show(ex.Message, "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
207+
}
208+
}
209+
catch (Exception ex)
210+
{
211+
MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error);
212+
}
198213
}
199214

200215
private void Upload(FileItem fileItem)
201216
{
202-
var ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(GetFileNameUri(fileItem.FileName));
203-
ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
204-
using(var fileStream = File.OpenRead(
205-
Path.Combine(_folderTextBox.Text, fileItem.FileInfo.FullName)))
206-
using(var ftpStream = ftpWebRequest.GetRequestStream())
207-
fileStream.CopyTo(ftpStream);
208-
using(var response = ftpWebRequest.GetResponse()) { }
217+
try
218+
{
219+
var ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(GetFileNameUri(fileItem.FileName));
220+
ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
221+
using (var fileStream = File.OpenRead(
222+
Path.Combine(_folderTextBox.Text, fileItem.FileInfo.FullName)))
223+
using (var ftpStream = ftpWebRequest.GetRequestStream())
224+
fileStream.CopyTo(ftpStream);
225+
using (var response = ftpWebRequest.GetResponse()) { }
226+
}
227+
catch (WebException ex)
228+
{
229+
var response = ex.Response as FtpWebResponse;
230+
if (response != null)
231+
{
232+
MessageBox.Show(ex.Message, "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
233+
}
234+
}
235+
catch (Exception ex)
236+
{
237+
MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error);
238+
}
209239
}
210240

211241
#endregion
@@ -268,8 +298,8 @@ private void DataGridView_CellValueNeeded(object sender, DataGridViewCellValueEv
268298
case 0: e.Value = fileItem.Name; break;
269299
case 1: e.Value = fileItem.YearMonth; break;
270300
case 2: e.Value = fileItem.Status; break;
271-
case 3: e.Value = "Edit"; break;
272-
case 4: e.Value = "Download"; break;
301+
case 3: e.Value = "Download"; break;
302+
case 4: e.Value = "Edit"; break;
273303
case 5: e.Value = "Upload"; break;
274304
default: e.Value = null; break;
275305
}
@@ -289,15 +319,15 @@ private void DataGridView_CellContentClick(object sender, DataGridViewCellEventA
289319
var fileItem = _fileItems[e.RowIndex];
290320
switch(e.ColumnIndex)
291321
{
292-
case 3: //Edit
293-
using(var form = new LoxStatFileForm(fileItem.FileInfo.FullName))
294-
form.ShowDialog(this);
295-
break;
296-
case 4: //Download
322+
case 3: //Download
297323
Download(fileItem);
298324
RefreshLocal();
299325
RefreshGridView();
300326
break;
327+
case 4: //Edit
328+
using(var form = new LoxStatFileForm(fileItem.FileInfo.FullName))
329+
form.ShowDialog(this);
330+
break;
301331
case 5: //Upload
302332
Upload(fileItem);
303333
RefreshMs();

MiniserverForm.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@
147147
<metadata name="_statusCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
148148
<value>True</value>
149149
</metadata>
150-
<metadata name="_editCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
150+
<metadata name="_downloadCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
151151
<value>True</value>
152152
</metadata>
153-
<metadata name="_downloadCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
153+
<metadata name="_editCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
154154
<value>True</value>
155155
</metadata>
156156
<metadata name="_uploadCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

MsFileInfo.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,23 @@ public static IList<MsFileInfo> Load(Uri uri)
6464
}
6565
catch (Exception ex)
6666
{
67-
MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error);
67+
if (ex.Source == "mscorlib" && ex.HResult == -2146233086)
68+
{
69+
MessageBox.Show(
70+
"The connection to a Miniserver newer generation (with TLS) is " +
71+
"not working yet. Use a third party FTP client (e.g. Filezilla, " +
72+
"Windows Explorer, ...) to download and upload the statistics.\n\n" +
73+
"Feel free to contribute to this project and help us to fix this. " +
74+
"You find the GitHub link at the bottom of the main window.",
75+
"Error - IList",
76+
MessageBoxButtons.OK,
77+
MessageBoxIcon.Error
78+
);
79+
}
80+
else
81+
{
82+
MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error);
83+
}
6884

6985
return null;
7086
}

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.1.0")]
35-
[assembly: AssemblyFileVersion("1.0.1.0")]
34+
[assembly: AssemblyVersion("1.0.1.1")]
35+
[assembly: AssemblyFileVersion("1.0.1.1")]

0 commit comments

Comments
 (0)