57 lines
2.3 KiB
C#
57 lines
2.3 KiB
C#
using System.Reflection;
|
|
using GraphicsManager;
|
|
using GraphicsManager.Interfaces;
|
|
using GraphicsManager.Objects;
|
|
using GraphicsManager.Objects.Core;
|
|
using File = Luski.net.JsonTypes.File;
|
|
|
|
namespace Luski.GUI.MainScreen.UI;
|
|
|
|
public class ContentEmbed : UserControl
|
|
{
|
|
readonly File file;
|
|
long channel;
|
|
private Label fileNameLabel, fileSizeLabel;
|
|
private Rectangle downloadButton;
|
|
|
|
public ContentEmbed(File file, long channel)
|
|
{
|
|
this.channel = channel;
|
|
this.file = file;
|
|
string fst = "";
|
|
ulong size = file.Size;
|
|
if (size < 1000)
|
|
{
|
|
fst = size + " bytes";
|
|
} else if (size < 1000000)
|
|
{
|
|
fst= Math.Round((double)size / (double)1000, 2) + " KB";
|
|
} else if (size < 1000000000)
|
|
{
|
|
fst = Math.Round((double)size / (double)1000000, 2) + " MB";
|
|
} else if (size < 1000000000000)
|
|
{
|
|
fst = Math.Round((double)size / (double)1000000000, 2) + " GB";
|
|
}
|
|
Size = new(333, 66);
|
|
BackgroundColor = new(40, 40, 40, 255);
|
|
Controls.Add(fileSizeLabel = new Label() {Text = fst, Location = new(64, 39)});
|
|
Controls.Add(fileNameLabel = new Label() { Color = new(102/(float)255,227/(float)255,170/(float)255, 1), Text = file.Name, Location = new(64, 6)});
|
|
fileNameLabel.Clicked += FileNameLabelOnClicked;
|
|
byte[] tempp = Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Download.png");
|
|
Controls.Add(new Rectangle(Globals.ms.TextureManager.AddTexture(tempp)) { Location = new(8, 6), Size = new(50, 50)});
|
|
int temp = fileNameLabel.Size.X + fileNameLabel.Location.X;
|
|
int temp2 = fileSizeLabel.Size.X + fileSizeLabel.Location.X; ;
|
|
if (temp >= temp2) Size = new(temp + 4, Size.Y);
|
|
else Size = new(temp2 + 4, Size.Y);
|
|
}
|
|
|
|
private Task FileNameLabelOnClicked(IRenderObject arg)
|
|
{
|
|
string dir = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Downloads", "LuskiDownloads");
|
|
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
|
|
Thread t = new(() => file.DownloadBytes(Path.Join(dir, file.Name), channel, CancellationToken.None));
|
|
t.Start();
|
|
return Task.CompletedTask;
|
|
}
|
|
} |