private string MakeStatusbarText(string Template) { string txt = Template; if (ListingView.PointedItem != null) { DirItem di = (DirItem)ListingView.PointedItem.Data[dfDirItem]; txt = txt.Replace("{FullName}", di.TextToShow); txt = txt.Replace("{AutoSize}", KiloMegaGigabyteConvert(di.Size, CurShortenKB, CurShortenMB, CurShortenMB)); txt = txt.Replace("{Date}", di.Date.ToShortDateString()); txt = txt.Replace("{Time}", di.Date.ToLocalTime().ToShortTimeString()); txt = txt.Replace("{SelectedItems}", ListingView.SelectedItems.Count.ToString()); //todo: add masks SizeB, SizeKB, SizeMB, TimeUTC, Name, Extension } return(txt); }
private void LoadDir(string url) { currentDirectory = url; _CheckProtocol(url); Uri URI = new Uri(url); if (ftp == null) Connect(url); // ReSharper disable once PossibleNullReferenceException, because Connect(url) would initialize it or would crash this constructor Socket sck = ftp.GetDataSocket();//possible ftpexception, todo add try...catch string ListResult; ftp.SendCommand("CWD " + URI.PathAndQuery); ftp.SendCommand("TYPE A"); ftp.SendCommand("LIST", out ListResult); string directoryListing = "";//убрать после разборки с форматами ответов на "LIST" StreamReader sr = new StreamReader(new NetworkStream(sck)); directoryContent.Clear(); //todo: элемент "вверх по древу" /* if (URI.PathAndQuery != "/") { string upDirUrl = "ftp://" + URI.Host + ":" + URI.Port + URI.PathAndQuery; upDirUrl = URI.AbsolutePath.Substring(0, URI.AbsolutePath.LastIndexOf('/',0,1)); DirItem updir = new DirItem(); updir.URL = upDirUrl; updir.TextToShow = ".."; updir.MIMEType = "x-fcmd/up"; updir.IconSmall = Utilities.GetIconForMIME("x-fcmd/up"); directoryContent.Add(updir); }*/ while (!sr.EndOfStream) { string CurItem = sr.ReadLine(); if (CurItem == null) continue; directoryListing += CurItem+"\n"; DirItem di = new DirItem(); Match m = FtpListDirectoryDetailsRegex.Match(CurItem); string filename = m.Groups["fileName"].Value; di.IsDirectory = CurItem.StartsWith("d"); if (di.IsDirectory) { di.IconSmall = Utilities.GetIconForMIME("x-fcmd/directory"); } else { di.MIMEType = filename.LastIndexOf('.') > 0 ? Utilities.GetContentType(filename.Substring(filename.LastIndexOf('.') + 1)) : "application/octet-stream"; di.IconSmall = Utilities.GetIconForMIME(di.MIMEType); } di.TextToShow = filename; try { di.Date = DateTime.Parse(m.Groups["month"].Value + " " + m.Groups["day"].Value + " " + m.Groups["yearTime"].Value); } // ReSharper disable once EmptyGeneralCatchClause catch { } //to prevent crash if date is received in an invalid format di.URL = "ftp://" + URI.Host + ":" + URI.Port + URI.PathAndQuery + filename; if (di.IsDirectory && !di.URL.EndsWith("/")) di.URL += "/"; directoryContent.Add(di); } ftp.ReadResponse(); }