Skip to content

Commit

Permalink
Fix Win32-FileTime error
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Nov 3, 2023
1 parent ded6958 commit 70b1232
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion MiniserverForm.Designer.cs

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

14 changes: 9 additions & 5 deletions MiniserverForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
19 changes: 17 additions & 2 deletions MsFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public static IList<MsFileInfo> Load(Uri uri)
{
var list = new List<MsFileInfo>();
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())
Expand All @@ -29,6 +33,9 @@ public static IList<MsFileInfo> 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);
Expand All @@ -43,6 +50,10 @@ public static IList<MsFileInfo> Load(Uri uri)
CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) ;

Check warning on line 50 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build (Release, 3.1.426)

Possible mistaken empty statement

Check warning on line 50 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build-release (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 52 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build (Release, 3.1.426)

Possible mistaken empty statement

Check warning on line 52 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build-release (Release, 3.1.426)

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

Check warning on line 54 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build (Release, 3.1.426)

Possible mistaken empty statement

Check warning on line 54 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build-release (Release, 3.1.426)

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

Check warning on line 56 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build (Release, 3.1.426)

Possible mistaken empty statement

Check warning on line 56 in MsFileInfo.cs

View workflow job for this annotation

GitHub Actions / build-release (Release, 3.1.426)

Possible mistaken empty statement

var fileName = groups[3].Value;

Expand All @@ -52,6 +63,10 @@ public static IList<MsFileInfo> Load(Uri uri)
Date = dateTime,
Size = size,
});

// Log FTP output
// File.AppendAllText("./custom.log", $"|- Filename: {fileName} - Date: {dateTime} - Size: {size}\n\n");

}
}
return list;
Expand All @@ -61,13 +76,13 @@ public static IList<MsFileInfo> 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;
}
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.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]

0 comments on commit 70b1232

Please sign in to comment.