/// <summary>Converts the file size (in bytes) to human-readable string</summary> /// <param name="Input">The input value</param> /// <param name="ShortestNonhumanity">The miminal file size that should be shortened</param> /// <returns>Human-readable string (xxx yB)</returns> private string KiloMegaGigabyteConvert(long Input, SizeDisplayPolicy ShortenKB, SizeDisplayPolicy ShortenMB, SizeDisplayPolicy ShortenGB) { double ShortenedSize; //here will be writed the decimal value of the hum. readable size //TeraByte (will be shortened everywhen) if (Input > 1099511627776) { return((Input / 1099511627776).ToString() + " TB"); } //GigaByte if (Input > 1073741824) { ShortenedSize = Input / 1073741824; switch (ShortenGB) { case SizeDisplayPolicy.OneNumeral: return(string.Format("{0:0.#} GB", ShortenedSize)); case SizeDisplayPolicy.TwoNumeral: return(string.Format("{0:0.##} GB", ShortenedSize)); } } //MegaByte if (Input > 1048576) { ShortenedSize = Input / 1048576; switch (ShortenMB) { case SizeDisplayPolicy.OneNumeral: return(string.Format("{0:0.#} MB", ShortenedSize)); case SizeDisplayPolicy.TwoNumeral: return(string.Format("{0:0.##} MB", ShortenedSize)); } } //KiloByte if (Input > 1024) { ShortenedSize = Input / 1024; switch (ShortenKB) { case SizeDisplayPolicy.OneNumeral: return(string.Format("{0:0.#} KB", ShortenedSize)); case SizeDisplayPolicy.TwoNumeral: return(string.Format("{0:0.##} KB", ShortenedSize)); } } return(Input.ToString() + " B"); //if Input is less than 1k or shortening is disallowed }
/// <summary> /// Load the directory into the panel and set view options /// </summary> /// <param name="URL">Full path of the directory</param> /// <param name="ShortenKB">How kilobyte sizes should be humanized</param> /// <param name="ShortenMB">How megabyte sizes should be humanized</param> /// <param name="ShortenGB">How gigabyte sizes should be humanized</param> //плохой перевод? "так nбайтные размеры должны очеловечиваться" public void LoadDir(string URL, SizeDisplayPolicy ShortenKB, SizeDisplayPolicy ShortenMB, SizeDisplayPolicy ShortenGB) { CurShortenKB = ShortenKB; CurShortenMB = ShortenMB; CurShortenGB = ShortenGB; if (FS == null) { throw new InvalidOperationException("No filesystem is binded to this FileListPanel"); } //неспешное TODO:придумать, куда лучше закорячить; не забываем, что во время работы FS может меняться полностью FS.CLIstdoutDataReceived += new TypedEvent <string>(FS_CLIstdoutDataReceived); FS.CLIstderrDataReceived += (stderr) => { CLIoutput.Text += "\n" + stderr; pluginner.Utilities.ShowWarning(stderr); }; FS.CLIpromptChanged += new TypedEvent <string>(FS_CLIpromptChanged); LoadDir( URL, FS.DirectoryContent, ShortenKB, ShortenMB, ShortenGB ); }
/// <summary> /// Load the specifed directory with specifed content into the panel and set view options /// </summary> /// <param name="URL">The full URL of the directory (for reference needs)</param> /// <param name="dis">Directory item list</param> /// <param name="ShortenKB">How kilobyte sizes should be humanized</param> /// <param name="ShortenMB">How megabyte sizes should be humanized</param> /// <param name="ShortenGB">How gigabyte sizes should be humanized</param> //плохой перевод? "так nбайтные размеры должны очеловечиваться" public void LoadDir(string URL, List <DirItem> dis, SizeDisplayPolicy ShortenKB, SizeDisplayPolicy ShortenMB, SizeDisplayPolicy ShortenGB) { if (FS.CurrentDirectory == null) { //if this is first call in the session (the FLP is just initialized) using (Menu hm = HistoryButton.Menu) { MenuItem hmi = new MenuItem(URL); hmi.Clicked += (o, ea) => { NavigateTo(URL, (int)hmi.Tag); }; hmi.Tag = hm.Items.Count; hm.Items.Add(hmi); } } ListingView.Cursor = Xwt.CursorType.IBeam; //todo: modify XWT and add hourglass cursor ListingView.Sensitive = false; try { FS.CurrentDirectory = URL; ListingView.Clear(); UrlBox.Text = URL; FS.StatusChanged += new TypedEvent <string>(FS_StatusChanged); FS.ProgressChanged += new TypedEvent <double>(FS_ProgressChanged); string updir = URL + FS.DirSeparator + ".."; string rootdir = FS.GetMetadata(URL).RootDirectory; foreach (DirItem di in dis) { List <Object> Data = new List <Object>(); Data.Add(di.IconSmall ?? Xwt.Drawing.Image.FromResource("pluginner.Resources.image-missing.png")); Data.Add(di.Path); Data.Add(di.TextToShow); if (di.TextToShow == "..") { //parent dir Data.Add("<↑ UP>"); Data.Add(FS.GetMetadata(di.Path).LastWriteTimeUTC.ToLocalTime()); updir = di.Path; } else if (di.IsDirectory) { //dir Data.Add("<DIR>"); Data.Add(di.Date); } else { //file Data.Add(KiloMegaGigabyteConvert(di.Size, ShortenKB, ShortenMB, ShortenGB)); Data.Add(di.Date); } Data.Add(di); ListingView.AddItem(Data, di.Path); } GoUp.Clicked += (o, ea) => { LoadDir(updir); }; GoRoot.Clicked += (o, ea) => { LoadDir(rootdir); }; } catch (Exception ex) { if (ex.Message == "Object reference not set to an instance of an object.") { Xwt.MessageDialog.ShowWarning(ex.Message, ex.StackTrace + "\nInner exception: " + ex.InnerException.Message ?? "none"); } else { Xwt.MessageDialog.ShowWarning(ex.Message); } } ListingView.Sensitive = true; ListingView.Cursor = Xwt.CursorType.Arrow; if (ListingView.Items.Count > 0) { ListingView.SelectedRow = 0; ListingView.ScrollerIn.ScrollTo(0, 0); } ListingView.SetFocus(); //one fixed bug may make many other bugs...уточнить необходимость! }