Skip to content

Commit

Permalink
Finish overview panel and fix some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
hexafluoride committed Aug 14, 2014
1 parent f6f0dd2 commit c24f3df
Show file tree
Hide file tree
Showing 7 changed files with 500 additions and 446 deletions.
Binary file modified ByteFlood.suo
Binary file not shown.
1 change: 1 addition & 0 deletions ByteFlood/ByteFlood.csproj
Expand Up @@ -64,6 +64,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Formatters\FileNameToIcon.cs" />
<Compile Include="Formatters\Subtract5Formatter.cs" />
<Compile Include="InfoClasses\FileInfo.cs" />
<Compile Include="InfoClasses\PeerInfo.cs" />
<Compile Include="InfoClasses\PieceInfo.cs" />
Expand Down
22 changes: 22 additions & 0 deletions ByteFlood/Formatters/Subtract5Formatter.cs
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace ByteFlood.Formatters
{
// thanks obama
public class Subtract5Formatter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (double)value - 5;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (int)value + 5;
}
}
}
120 changes: 62 additions & 58 deletions ByteFlood/InfoClasses/TorrentInfo.cs
Expand Up @@ -30,61 +30,72 @@ public class TorrentInfo : INotifyPropertyChanged
public string Path = "";
public string SavePath = "";
public TorrentSettings TorrentSettings { get; set; }
public string Name { get; set; }
public int Progress { get; set; }
public long Size { get; set; }
public int DownloadSpeed { get; set; }
public int UploadSpeed { get; set; }
public TimeSpan Elapsed { get; set; }
public DateTime StartTime { get; set; }
public int Seeders { get; set; }
public int Leechers { get; set; }
public long Downloaded { get; set; }
public long Uploaded { get; set; }
public string Status { get; set; }
public int PeerCount { get; set; }
public float RawRatio { get; set; }
public string Name { get; set; }
public int Progress { get { return (int)Torrent.Progress; } set { } }
public long Size { get { return Torrent.Torrent.Size; } }
public int DownloadSpeed { get { return Torrent.Monitor.DownloadSpeed; } }
public int UploadSpeed { get { return Torrent.Monitor.UploadSpeed; } }
public TimeSpan Elapsed { get { return DateTime.Now.Subtract(StartTime); } }
public DateTime StartTime { get; set; }
public long PieceLength { get { return Torrent.Torrent.PieceLength; } }
public int HashFails { get { return Torrent.HashFails; } }
public long WastedBytes { get { return PieceLength * HashFails; } }
public int Seeders { get { return Torrent.Peers.Seeds; } }
public int Leechers { get { return Torrent.Peers.Leechs; } }
public long Downloaded { get { return Torrent.Monitor.DataBytesDownloaded; } }
public long Uploaded { get { return Torrent.Monitor.DataBytesUploaded; } }
public string Status { get { return Torrent.State.ToString() == "DontDownload" ? "Don't download" : Torrent.State.ToString(); } }
public int PeerCount { get { return Seeders + Leechers; } }
public float RawRatio { get; set; }
public float RatioLimit { get; set; }
[XmlIgnore]
public float AverageDownloadSpeed { get { return downspeeds.Average(); } set { } }
[XmlIgnore]
public float AverageUploadSpeed { get { return upspeeds.Average(); } set { } }
[XmlIgnore]
public ObservableCollection<PeerInfo> Peers = new ObservableCollection<PeerInfo>();
[XmlIgnore]
public ObservableCollection<PieceInfo> Pieces = new ObservableCollection<PieceInfo>();
public ObservableCollection<FileInfo> Files = new ObservableCollection<FileInfo>();
public ObservableCollection<TrackerInfo> Trackers = new ObservableCollection<TrackerInfo>();
[XmlIgnore]
private bool hooked_pieces = false;
private bool hooked_pieces = false;
private SynchronizationContext context;
#endregion
public List<float> DownSpeeds
{
get
{
var t = downspeeds.Skip(downspeeds.Count - 50);
if (t.Count() < 50)
{
int count = 50 - t.Count();
var f = Enumerable.Repeat<float>(0f, count);
t = f.Concat(t);
}
return t.ToList();
}
}
private List<float> upspeeds = new List<float>();
public List<float> UpSpeeds
{
get
{
var t = upspeeds.Skip(downspeeds.Count - 50);
if (t.Count() < 50)
{
int count = 50 - t.Count();
var f = Enumerable.Repeat<float>(0f, count);
t = f.Concat(t);
}
return t.ToList();
}
}
private List<float> downspeeds = new List<float>();
[XmlIgnore]
public List<float> DownSpeeds
{
get
{
var t = downspeeds.Skip(downspeeds.Count - 50);
if (t.Count() < 50)
{
int count = 50 - t.Count();
var f = Enumerable.Repeat<float>(0f, count);
t = f.Concat(t);
}
return t.ToList();
}
}
[XmlIgnore]
public List<float> upspeeds = new List<float>();
[XmlIgnore]
public List<float> UpSpeeds
{
get
{
var t = upspeeds.Skip(downspeeds.Count - 50);
if (t.Count() < 50)
{
int count = 50 - t.Count();
var f = Enumerable.Repeat<float>(0f, count);
t = f.Concat(t);
}
return t.ToList();
}
}
[XmlIgnore]
public List<float> downspeeds = new List<float>();
#endregion

public TorrentInfo() // this is reserved for the XML deserializer.
{
Expand Down Expand Up @@ -255,7 +266,11 @@ public void Update()
"ETA",
"Size",
"Elapsed",
"TorrentSettings");
"TorrentSettings",
"WastedBytes",
"HashFails",
"AverageDownloadSpeed",
"AverageUploadSpeed");
}
}
catch (Exception ex)
Expand All @@ -272,26 +287,15 @@ public void UpdateList(params string[] columns)

private void UpdateProperties()
{
this.Elapsed = DateTime.Now.Subtract(StartTime);
this.Path = Torrent.Torrent.TorrentPath;
this.SavePath = Torrent.SavePath;
this.TorrentSettings = Torrent.Settings;
this.Status = Torrent.State.ToString();
this.Size = this.Torrent.Torrent.Size;
this.Progress = Convert.ToInt32(Torrent.Progress);
this.DownloadSpeed = Torrent.Monitor.DownloadSpeed;
var seconds = 0;
if (this.DownloadSpeed > 0)
{
seconds = Convert.ToInt32(this.Size / this.DownloadSpeed);
}
this.ETA = new TimeSpan(0, 0, seconds);
this.UploadSpeed = Torrent.Monitor.UploadSpeed;
this.Seeders = Torrent.Peers.Seeds;
this.Leechers = Torrent.Peers.Leechs;
this.Downloaded = Torrent.Monitor.DataBytesDownloaded;
this.Uploaded = Torrent.Monitor.DataBytesUploaded;
this.PeerCount = Seeders + Leechers;
if (!this.Torrent.Complete)
this.RawRatio = ((float)Torrent.Monitor.DataBytesUploaded / (float)Torrent.Monitor.DataBytesDownloaded);
else
Expand Down
51 changes: 40 additions & 11 deletions ByteFlood/UI/MainWindow.xaml
Expand Up @@ -29,14 +29,15 @@
<formatters:TimeSpanToString x:Key="TimeSpanToString" />
<formatters:SpeedFormatter x:Key="SpeedFormatter" />
<formatters:FileNameToIcon x:Key="FileNameToIcon" />
<formatters:Subtract5Formatter x:Key="Subtract5Formatter" />
</Window.Resources>
<Grid>
<Canvas Height="150" HorizontalAlignment="Stretch" Name="canvas1" VerticalAlignment="Bottom" Width="Auto">
<Grid Canvas.Left="219" Canvas.Top="72" />
<TabControl Name="tabControl1" Margin="0,0,0,0" Width="{Binding ElementName=canvas1, Path=ActualWidth}" Height="{Binding ElementName=canvas1, Path=ActualHeight}">
<TabItem Header="Overview" Name="overview">
<ScrollViewer>
<Canvas Name="overview_canvas" Height="1500">
<Canvas Name="overview_canvas" Height="200">
<TextBlock Canvas.Left="0" Canvas.Top="6" Height="23" Text=" Transfer" Width="{Binding ElementName=overview_canvas, Path=ActualWidth}" Background="WhiteSmoke" FontWeight="Bold" />
<TextBlock Canvas.Left="7" Canvas.Top="35" Height="23" Name="textBlock1" Text="Time elapsed:" />
<TextBlock Canvas.Left="7" Canvas.Top="54" Height="23" Name="textBlock2" Text="Downloaded:" />
Expand All @@ -45,7 +46,14 @@
<TextBlock Canvas.Left="7" Canvas.Top="111" Height="23" Name="textBlock5" Text="Status:" />
<TextBlock Canvas.Left="150" Canvas.Top="35" Height="23" Name="elapsed" Text="{Binding Elapsed, Converter={StaticResource TimeSpanToString}}" />
<TextBlock Canvas.Left="150" Canvas.Top="54" Height="23" Name="data_down" Text="{Binding Downloaded, Converter={StaticResource SizeToString}}" />
<TextBlock Canvas.Left="150" Canvas.Top="73" Height="23" Name="down_speed" Text="{Binding DownloadSpeed, Converter={StaticResource SpeedFormatter}}" />
<TextBlock Canvas.Left="150" Canvas.Top="73" Height="23" Name="down_speed">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} (avg. {1})">
<Binding Path="DownloadSpeed" Converter="{StaticResource SpeedFormatter}" />
<Binding Path="AverageDownloadSpeed" Converter="{StaticResource SpeedFormatter}" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Canvas.Left="150" Canvas.Top="92" Height="23" Name="down_limit" DataContext="{Binding TorrentSettings}" Text="{Binding MaxDownloadSpeed, Converter={StaticResource SpeedFormatter}}" />
<TextBlock Canvas.Left="150" Canvas.Top="111" Height="23" Name="status" Text="{Binding Status}" />
<TextBlock Canvas.Left="333" Canvas.Top="35" Height="23" Name="textBlock6" Text="ETA:" />
Expand All @@ -54,9 +62,30 @@
<TextBlock Canvas.Left="333" Canvas.Top="92" Height="23" Name="textBlock9" Text="Upload speed limit:" />
<TextBlock Canvas.Left="450" Canvas.Top="35" Height="23" Name="eta" Text="{Binding ETA, Converter={StaticResource TimeSpanToString}}" />
<TextBlock Canvas.Left="450" Canvas.Top="54" Height="23" Name="data_up" Text="{Binding Uploaded, Converter={StaticResource SizeToString}}" />
<TextBlock Canvas.Left="450" Canvas.Top="73" Height="23" Name="up_speed" Text="{Binding UploadSpeed, Converter={StaticResource SpeedFormatter}}" />
<TextBlock Canvas.Left="450" Canvas.Top="73" Height="23" Name="up_speed">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} (avg. {1})">
<Binding Path="UploadSpeed" Converter="{StaticResource SpeedFormatter}" />
<Binding Path="AverageUploadSpeed" Converter="{StaticResource SpeedFormatter}" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Canvas.Left="450" Canvas.Top="92" Height="23" Name="up_limit" DataContext="{Binding TorrentSettings}" Text="{Binding MaxUploadSpeed, Converter={StaticResource SpeedFormatter}}" />

<TextBlock Canvas.Left="622" Canvas.Top="35" Height="23" Name="textBlock10" Text="Wasted:" />
<TextBlock Canvas.Left="622" Canvas.Top="54" Height="23" Name="textBlock11" Text="Seeds:" />
<TextBlock Canvas.Left="622" Canvas.Top="73" Height="23" Name="textBlock12" Text="Peers:" />
<TextBlock Canvas.Left="622" Canvas.Top="92" Height="23" Name="textBlock13" Text="Ratio:" />
<TextBlock Height="23" Name="textBlock14" Canvas.Left="745" Canvas.Top="35" >
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} ({1} hashfails)">
<Binding Path="WastedBytes" Converter="{StaticResource SizeToString}" />
<Binding Path="HashFails" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Height="23" Name="textBlock15" Text="{Binding Seeders}" Canvas.Left="745" Canvas.Top="54" />
<TextBlock Height="23" Name="textBlock16" Text="{Binding PeerCount}" Canvas.Left="745" Canvas.Top="73" />
<TextBlock Height="23" Name="textBlock17" Text="{Binding Ratio}" Canvas.Left="745" Canvas.Top="92" />
</Canvas>
</ScrollViewer>
</TabItem>
Expand Down Expand Up @@ -114,10 +143,10 @@
</GridViewColumn.CellTemplate>
</GridViewColumn>

<GridViewColumn Width="140" Header="Progress">
<GridViewColumn Width="140" x:Name="file_progress_column" Header="Progress">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ProgressBar Maximum="100" Value="{Binding Progress}" Width="140" />
<ProgressBar Maximum="100" Value="{Binding Progress}" Width="{Binding ElementName=file_progress_column, Path=Width, Converter={StaticResource Subtract5Formatter}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Expand Down Expand Up @@ -171,10 +200,10 @@
<GridView>
<GridViewColumn Width="200" Header="Name" DisplayMemberBinding="{Binding Name}" />

<GridViewColumn Width="100" Header="Progress">
<GridViewColumn Width="100" x:Name="progress_column" Header="Progress">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ProgressBar Maximum="100" Value="{Binding Progress}" Width="140" />
<ProgressBar Maximum="100" Value="{Binding Progress}" Width="{Binding ElementName=progress_column, Path=Width, Converter={StaticResource Subtract5Formatter}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Expand All @@ -185,8 +214,8 @@
<GridViewColumn Width="100" Header="Downloaded" DisplayMemberBinding="{Binding Downloaded, Converter={StaticResource SizeToString}}" />

<GridViewColumn Width="100" Header="ETA" DisplayMemberBinding="{Binding ETA, Converter={StaticResource TimeSpanToString}}" />
<GridViewColumn Width="50" Header="Down Speed" DisplayMemberBinding="{Binding DownloadSpeed, Converter={StaticResource SpeedFormatter}}" />
<GridViewColumn Width="100" Header="Up Speed" DisplayMemberBinding="{Binding UploadSpeed, Converter={StaticResource SpeedFormatter}}" />
<GridViewColumn Width="75" Header="Down Speed" DisplayMemberBinding="{Binding DownloadSpeed, Converter={StaticResource SpeedFormatter}}" />
<GridViewColumn Width="75" Header="Up Speed" DisplayMemberBinding="{Binding UploadSpeed, Converter={StaticResource SpeedFormatter}}" />
<GridViewColumn Width="50" Header="Peers" DisplayMemberBinding="{Binding PeerCount}" />
<GridViewColumn Width="50" Header="Seeds" DisplayMemberBinding="{Binding Seeders}" />
<GridViewColumn Width="50" Header="Leechers" DisplayMemberBinding="{Binding Leechers}" />
Expand All @@ -195,6 +224,6 @@
</GridView>
</ListView.View>
</ListView>
<Button Content="Preferences" Height="26" HorizontalAlignment="Left" Margin="110,7,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
<Button Content="Preferences" Height="26" HorizontalAlignment="Left" Margin="110,7,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
</Grid>
</Window>
4 changes: 2 additions & 2 deletions ByteFlood/Utility.cs
Expand Up @@ -31,14 +31,14 @@ public static class Utility
public static string PrettifyAmount(double amount)
{
if (amount > T)
return (amount / T) + " TB";
return (amount / T).ToString("0.00") + " TB";
if (amount > G)
return (amount / G).ToString("0.00") + " GB";
if (amount > M)
return (amount / M).ToString("0.00") + " MB";
if (amount > K)
return (amount / K).ToString("0.00") + " KB";
return amount.ToString() + " B";
return amount.ToString("0.00") + " B";
}

//public static string PrettifyAmount(long amount)
Expand Down

0 comments on commit c24f3df

Please sign in to comment.