Skip to content

Commit

Permalink
added support for miniserver newer generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Sep 26, 2023
1 parent d8b04e3 commit 97f44db
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 47 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changelog

## Known issues
## v1.0.2.0

* FTP connection seems to not be possible with Miniserver Gen 2
* Added: Support Miniserver newer generation for FTP download/upload by @mr-manuel

## v1.0.1.1

Expand Down
4 changes: 2 additions & 2 deletions MiniserverForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MiniserverForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private void UploadButton_Click(object sender, EventArgs e)
// Launch project link
private void githubLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/ddeml/LoxStatEdit");
System.Diagnostics.Process.Start("https://github.com/mr-manuel/Loxone_LoxStatEdit");
}

#endregion
Expand Down
67 changes: 27 additions & 40 deletions MsFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace LoxStatEdit
Expand All @@ -18,38 +19,40 @@ public static IList<MsFileInfo> Load(Uri uri)
{
try
{
// TO DO: Does not connect with Miniserver Gen 2. Probably because of TLS
var list = new List<MsFileInfo>();
var ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(uri);
ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
using (var response = ftpWebRequest.GetResponse())
using (var ftpStream = response.GetResponseStream())
using (var streamReader = new StreamReader(ftpStream))
while (!streamReader.EndOfStream)
{
// Hacky but works fair enough in our particular use case (I hope...)
var line = streamReader.ReadLine();
Debug.WriteLine(line);
int datePos = line.IndexOf(' ', 24);
int size;
if (!int.TryParse(line.Substring(18, datePos - 18), out size))
size = -1;
datePos++;
int fileNamePos;
DateTime dateTime;
if (DateTime.TryParseExact(line.Substring(datePos, 12), "MMM dd HH:mm",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
fileNamePos = datePos + 13;
else if (DateTime.TryParseExact(line.Substring(datePos, 11), "MMM dd yyyy",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
fileNamePos = datePos + 12;
else fileNamePos = line.LastIndexOf(' ') + 1;
list.Add(new MsFileInfo

// string pattern that matches Miniserver Gen 1 and Miniserver Gen 2
string pattern = @"[-rwx]{10}\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+([0-9]+)\s+([A-Za-z]{3}\s+[0-9]{1,2}\s+[0-9:]+)\s+([0-9a-z_\-\.]+)";
var result = Regex.Match(line, pattern);

if (result.Success)
{
FileName = line.Substring(fileNamePos),
Date = dateTime,
Size = size,
});
var groups = result.Groups;
int.TryParse(groups[1].Value, out int size);

DateTime dateTime;
if (DateTime.TryParseExact(groups[2].Value.Replace(" ", " "), "MMM dd HH:mm",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) ;

Check warning on line 43 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build-release (Release, 3.1.426)

Possible mistaken empty statement

Check warning on line 43 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build (Release, 3.1.426)

Possible mistaken empty statement
else if (DateTime.TryParseExact(groups[2].Value.Replace(" ", " "), "MMM dd yyyy",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) ;

Check warning on line 45 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build-release (Release, 3.1.426)

Possible mistaken empty statement

Check warning on line 45 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build (Release, 3.1.426)

Possible mistaken empty statement

var fileName = groups[3].Value;

list.Add(new MsFileInfo
{
FileName = fileName,
Date = dateTime,
Size = size,
});
}
}
return list;
}
Expand All @@ -64,23 +67,7 @@ public static IList<MsFileInfo> Load(Uri uri)
}
catch (Exception ex)
{
if (ex.Source == "mscorlib" && ex.HResult == -2146233086)
{
MessageBox.Show(
"The connection to a Miniserver newer generation (with TLS) is " +
"not working yet. Use a third party FTP client (e.g. Filezilla, " +
"Windows Explorer, ...) to download and upload the statistics.\n\n" +
"Feel free to contribute to this project and help us to fix this. " +
"You find the GitHub link at the bottom of the main window.",
"Error - IList",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}
else
{
MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error);

return null;
}
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.1")]
[assembly: AssemblyFileVersion("1.0.1.1")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Loxone Statistic Editor

<small>GitHub repository: [mr-manuel/Loxone_LoxStatEdit](https://github.com/mr-manuel/Loxone_LoxStatEdit)</small>

<small>LoxWiki: [LoxStatsEditor - Statistikdaten bearbeiten](https://loxwiki.atlassian.net/wiki/spaces/LOX/pages/1520762996/LoxStatsEditor+-+Statistikdaten+bearbeiten)</small>

<small>LoxForum: [Loxone Statistik Editor ](https://www.loxforum.com/forum/faqs-tutorials-howto-s/21686-loxone-statistik-editor)</small>

### Disclaimer

This app was forked from [ddeml/LoxStatEdit](https://github.com/ddeml/LoxStatEdit). A huge thanks for creating this app!

I updates this app for myself. I'm not responsible, if you damage something using this app.


## Supporting/Sponsoring this project

You like the project and you want to support me?

[<img src="https://github.md0.eu/uploads/donate-button.svg" height="50">](https://www.paypal.com/donate/?hosted_button_id=3NEVZBDM5KABW)


### Purpose

This app was created to be able to correct spikes in the Loxone Statistics. You can download, edit and upload directly in the app.


### Screenshots

![LoxStatEdit - 1](/screenshots/loxstatedit-1.png)
![LoxStatEdit - 2](/screenshots/loxstatedit-2.png)
![LoxStatEdit - 3](/screenshots/loxstatedit-3.png)
![LoxStatEdit - 4](/screenshots/loxstatedit-4.png)
![LoxStatEdit - 5](/screenshots/loxstatedit-5.png)
Binary file added screenshots/loxstatedit-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/loxstatedit-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/loxstatedit-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/loxstatedit-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/loxstatedit-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 97f44db

Please sign in to comment.