@@ -20,6 +20,8 @@ internal class FtpClientGUI
2020
2121 int ClientID = 0 ;
2222
23+ bool EnableIcons = ConfigFile . ShowFileIcons ;
24+
2325 /// <summary>
2426 /// Create an instance of Web-FTP client GUI
2527 /// </summary>
@@ -28,6 +30,14 @@ public FtpClientGUI(HttpRequest ClientRequest)
2830 {
2931 this . ClientRequest = ClientRequest ;
3032 RequestArguments = System . Web . HttpUtility . ParseQueryString ( ClientRequest . Url . Query ) ;
33+
34+ if ( EnableIcons )
35+ {
36+ if ( ! File . Exists ( ConfigFile . ContentDirectory + "/filetypes/_dir.gif" ) ) EnableIcons = false ;
37+ if ( ! File . Exists ( ConfigFile . ContentDirectory + "/filetypes/_dir-up.gif" ) ) EnableIcons = false ;
38+ if ( ! File . Exists ( ConfigFile . ContentDirectory + "/filetypes/_file.gif" ) ) EnableIcons = false ;
39+ if ( ! File . Exists ( ConfigFile . ContentDirectory + "/filetypes/_link.gif" ) ) EnableIcons = false ;
40+ }
3141 }
3242
3343 /// <summary>
@@ -86,14 +96,15 @@ public FtpClientPage GetWelcomePage()
8696
8797 Page . Header = "File Transfer Protocol client" ;
8898 Page . Content = "<p>Welcome to space of computer files, directories and servers. Here you'll be able to download something to your PC from FTP servers without quitting a web browser.</p>" ;
99+ Page . HtmlHeaders += "\n <style>.formlabel { width: 80px; display: inline-block; display:-moz-inline-block; display:-moz-inline-stack; text-align: right; }</style>" ;
89100
90101 string Form =
91102 "<form action=\" /!ftp/\" method=\" GET\" name=\" Connect\" >\n " +
92103 "<center><input type=\" hidden\" name=\" client\" value=\" -1\" >\n " +
93- "<p>Server: <input type=\" text\" size=\" 23\" name=\" server\" value=\" \" ><br>\n " +
94- "or URI: <input type=\" text\" size=\" 23\" name=\" uri\" value=\" \" ></p>\n " +
95- "<p>Username: <input type=\" text\" size=\" 20\" name=\" user\" value=\" anonymous\" ><br>\n " +
96- "Password: <input type=\" password\" size=\" 20\" name=\" pass\" value=\" user@domain.su\" ></p>\n " +
104+ "<p><label class= \" formlabel \" for= \" server \" > Server:</label> <input type=\" text\" size=\" 23\" name= \" server \" id =\" server\" value=\" \" ><br>\n " +
105+ "<label class= \" formlabel \" for= \" uri \" > or URI:</label> <input type=\" text\" size=\" 23\" name= \" uri \" id =\" uri\" value=\" \" ></p>\n " +
106+ "<p><label class= \" formlabel \" for= \" user \" > Username:</label> <input type=\" text\" size=\" 20\" name= \" user \" id =\" user\" value=\" anonymous\" ><br>\n " +
107+ "<label class= \" formlabel \" for= \" pass \" > Password:</label> <input type=\" password\" size=\" 20\" name=\" pass\" id= \" pass \" value=\" user@domain.su\" ></p>\n " +
97108 "<p><input type=\" submit\" value=\" Let's go!\" ></p>\n " +
98109 "</center></form>" ;
99110
@@ -228,7 +239,7 @@ public FtpClientPage GetResultPage()
228239 if ( cmd . Code != 257 )
229240 {
230241 Page . Content += "<p><b>"Print Working Directory" command has returned an unexpected result:</b> " + cmd . ToString ( ) + "</p>" ;
231- Page . Content += "<p>Return to <a href=\" /!ftp/\" ><b>start page</b></a> and try to connect again.</p>" ;
242+ Page . Content += "<p>Reload this page or return to <a href=\" /!ftp/\" ><b>start page</b></a> and try to connect again.</p>" ;
232243 return Page ;
233244 }
234245
@@ -321,6 +332,7 @@ public FtpClientPage GetResultPage()
321332 {
322333 Page . Content += "<tr>" ;
323334 Page . Content += "<td>" ;
335+ if ( EnableIcons ) Page . Content += "<img border=\" 0\" src=\" " + GetIconFileName ( "._dir-up" ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
324336 Page . Content += "[<a href=\" /!ftp/?client=" + ClientID + "&task=listdir&cwd=" + Uri . EscapeDataString ( Backend . WorkdirPath + ".." ) + "\" >..</a>]" ;
325337 Page . Content += "</td>" ;
326338 Page . Content += "<td>" ;
@@ -332,23 +344,34 @@ public FtpClientPage GetResultPage()
332344 foreach ( var Item in FileListTable )
333345 {
334346 string FileName = Item . Name ;
347+ string IconHtml = "" ;
348+
349+ if ( EnableIcons )
350+ {
351+ if ( Item . Directory ) IconHtml = "<img border=\" 0\" src=\" " + GetIconFileName ( "._dir" ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
352+ else IconHtml = "<img border=\" 0\" src=\" " + GetIconFileName ( FileName ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
353+ }
335354
336355 Page . Content += "<tr>" ;
337356 Page . Content += "<td>" ;
338357 if ( Item . Directory && ! Item . SymLink )
339358 {
359+ Page . Content += IconHtml ;
340360 Page . Content += "[<a href=\" /!ftp/?client=" + ClientID + "&task=listdir&cwd=" + Uri . EscapeDataString ( Backend . WorkdirPath + FileName ) + "\" >" + FileName + "</a>]" ;
341361 }
342362 else if ( Item . Directory && Item . SymLink )
343363 {
364+ if ( EnableIcons ) Page . Content += "<img border=\" 0\" src=\" " + GetIconFileName ( "._link" ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
344365 Page . Content += "<i>[" + FileName + "]</i>" ;
345366 }
346367 else if ( ! Item . Directory && Item . SymLink )
347368 {
369+ if ( EnableIcons ) Page . Content += "<img border=\" 0\" src=\" " + GetIconFileName ( "._link" ) + "\" width=\" 16px\" height=\" 16px\" class=\" fileicon\" > " ;
348370 Page . Content += "<i>" + FileName + "</i>" ;
349371 }
350372 else
351373 {
374+ Page . Content += IconHtml ;
352375 Page . Content += "<a href=\" /!ftp/?client=" + ClientID + "&task=retr&name=" + Uri . EscapeDataString ( Backend . WorkdirPath + FileName ) + "\" target='_blank'>" + FileName + "</a>" ;
353376 }
354377 Page . Content += "</td>" ;
@@ -463,6 +486,35 @@ public FtpClientPage GetDisabledPage()
463486 Page . Content = "The server administrator has disabled FTP browsing via this proxy." ;
464487 return Page ;
465488 }
489+
490+ /// <summary>
491+ /// Get content file name for icon, describing the file in Web-FTP directory listing
492+ /// </summary>
493+ /// <param name="OriginalFileName">File name on remote FTP server</param>
494+ string GetIconFileName ( string OriginalFileName )
495+ {
496+ if ( ! EnableIcons ) throw new InvalidOperationException ( "File type icons are disabled." ) ;
497+ if ( ! OriginalFileName . Contains ( '.' ) )
498+ {
499+ return "/filetypes/_file.gif" ;
500+ }
501+ string ext = OriginalFileName . Substring ( OriginalFileName . LastIndexOf ( "." ) + 1 ) ;
502+ if ( string . IsNullOrWhiteSpace ( ext ) )
503+ {
504+ return "/filetypes/_file.gif" ;
505+ }
506+ else
507+ {
508+ try
509+ {
510+ if ( File . Exists ( ConfigFile . ContentDirectory + "/filetypes/" + ext + ".gif" ) )
511+ return "/filetypes/" + ext + ".gif" ;
512+ else
513+ return "/filetypes/_file.gif" ;
514+ }
515+ catch { return "/filetypes/_file.gif" ; }
516+ }
517+ }
466518 }
467519
468520 /// <summary>
@@ -483,7 +535,7 @@ public FtpClientPage(string Title = "WebOne: FTP client", string Header = "File
483535 this . Content = Content ;
484536 this . ShowFooter = false ;
485537 this . AddCss = false ;
486- this . HtmlHeaders = @ "<link href="" /webone.css"" rel="" stylesheet""/> <link rel="" shortcut icon"" href="" /ftpfav.ico"" type="" image/x-icon" ">";
538+ this . HtmlHeaders = "<link href=\" /webone.css\" rel=\" stylesheet\" /> \n <link rel=\" shortcut icon\" href=\" /ftpfav.ico\" type=\" image/x-icon\ " >" ;
487539 }
488540 }
489541}
0 commit comments