From 70b12325e60e54aeb8a3f6dfe598f4ddff063b65 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 3 Nov 2023 19:10:31 +0100 Subject: [PATCH] Fix Win32-FileTime error --- CHANGELOG.md | 4 ++++ MiniserverForm.Designer.cs | 2 +- MiniserverForm.cs | 14 +++++++++----- MsFileInfo.cs | 19 +++++++++++++++++-- Properties/AssemblyInfo.cs | 4 ++-- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2711dc3..776d013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.0.3.0 + +* Changed: Fixed Win32-FileTime error + ## v1.0.2.0 * Added: Support Miniserver newer generation for FTP download/upload by @mr-manuel diff --git a/MiniserverForm.Designer.cs b/MiniserverForm.Designer.cs index 94ac50d..5376bd3 100644 --- a/MiniserverForm.Designer.cs +++ b/MiniserverForm.Designer.cs @@ -119,7 +119,7 @@ private void InitializeComponent() aboutLabel.Name = "aboutLabel"; aboutLabel.Size = new System.Drawing.Size(171, 18); aboutLabel.TabIndex = 8; - aboutLabel.Text = "LoxStatEdit v1.0.2.0 (2023.09.26)"; + aboutLabel.Text = "LoxStatEdit v1.0.3.0 (2023.11.02)"; // // _urlTextBox // diff --git a/MiniserverForm.cs b/MiniserverForm.cs index d9f6621..edb2879 100644 --- a/MiniserverForm.cs +++ b/MiniserverForm.cs @@ -195,20 +195,24 @@ private void Download(FileItem fileItem) using(var response = ftpWebRequest.GetResponse()) using(var ftpStream = response.GetResponseStream()) using(var fileStream = File.OpenWrite(targetFileName)) - ftpStream.CopyTo(fileStream); + ftpStream.CopyTo(fileStream); File.SetLastWriteTime(targetFileName, fileItem.MsFileInfo.Date); + + // Log FTP output + // File.AppendAllText("./custom.log", $"Downloaded {fileItem.FileName} - Setting last write time to {fileItem.MsFileInfo.Date}\n\n"); + } catch (WebException ex) { var response = ex.Response as FtpWebResponse; if (response != null) { - MessageBox.Show(ex.Message, "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"# Message\n{ex.Message}\n\n# Data\n{ex.Data}\n\n# StackTrace\n{ex.StackTrace}", "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { - MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"# Message\n{ex.Message}\n\n# Data\n{ex.Data}\n\n# StackTrace\n{ex.StackTrace}", "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -229,12 +233,12 @@ private void Upload(FileItem fileItem) var response = ex.Response as FtpWebResponse; if (response != null) { - MessageBox.Show(ex.Message, "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"# Message\n{ex.Message}\n\n# Data\n{ex.Data}\n\n# StackTrace\n{ex.StackTrace}", "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { - MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"# Message\n{ex.Message}\n\n# Data\n{ex.Data}\n\n# StackTrace\n{ex.StackTrace}", "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/MsFileInfo.cs b/MsFileInfo.cs index c1c4a26..f7e1204 100644 --- a/MsFileInfo.cs +++ b/MsFileInfo.cs @@ -21,6 +21,10 @@ public static IList Load(Uri uri) { var list = new List(); var ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(uri); + + // Log FTP output + // File.AppendAllText("./custom.log", "\n\n- - - - -\n\n"); + ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; using (var response = ftpWebRequest.GetResponse()) using (var ftpStream = response.GetResponseStream()) @@ -29,6 +33,9 @@ public static IList Load(Uri uri) { var line = streamReader.ReadLine(); + // Log FTP output + // File.AppendAllText("./custom.log", $"{line}\n"); + // 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); @@ -43,6 +50,10 @@ public static IList Load(Uri uri) CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) ; else if (DateTime.TryParseExact(groups[2].Value.Replace(" ", " "), "MMM dd yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) ; + else if (DateTime.TryParseExact(groups[2].Value.Replace(" ", " "), "MMM d HH:mm", + CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) ; + else if (DateTime.TryParseExact(groups[2].Value.Replace(" ", " "), "MMM d yyyy", + CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) ; var fileName = groups[3].Value; @@ -52,6 +63,10 @@ public static IList Load(Uri uri) Date = dateTime, Size = size, }); + + // Log FTP output + // File.AppendAllText("./custom.log", $"|- Filename: {fileName} - Date: {dateTime} - Size: {size}\n\n"); + } } return list; @@ -61,13 +76,13 @@ public static IList Load(Uri uri) var response = ex.Response as FtpWebResponse; if (response != null) { - MessageBox.Show(ex.Message, "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"# Message\n{ex.Message}\n\n# Data\n{ex.Data}\n\n# StackTrace\n{ex.StackTrace}", "Error - FTP connection", MessageBoxButtons.OK, MessageBoxIcon.Error); } return null; } catch (Exception ex) { - MessageBox.Show(ex.Message, "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Message: {ex.Message}\n\nData: {ex.Data}\n\nStackTrace: {ex.StackTrace}", "Error - IList", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c419a51..1f8b870 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -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.2.0")] -[assembly: AssemblyFileVersion("1.0.2.0")] +[assembly: AssemblyVersion("1.0.3.0")] +[assembly: AssemblyFileVersion("1.0.3.0")]