Permalink
Browse files

Fix some issues with the AVDump Utility and use better logic for sele…

…ction output
  • Loading branch information...
da3dsoul committed Feb 12, 2018
1 parent 62ec780 commit 33ed62ad380699b925d24cc0170b554216a73ee1
@@ -155,12 +155,11 @@

<!-- Currently selected file details -->

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Padding="3" Margin="0,0,0,5" Grid.Row="0" Grid.Column="2"
Visibility="{Binding Path=OneVideoSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type usercontrols:AvdumpBatchControl}}, Converter={StaticResource BooleanToVisibilityConverter}}">
<ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="ccDetail" >
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Padding="3" Margin="0,0,0,5" Grid.Row="0" Grid.Column="2">
<ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="ccDetail" >
<ContentControl.ContentTemplate>
<DataTemplate>
<usercontrols:AvdumpFileControl/>
<usercontrols:AvdumpFileControl x:Name="FileDetails"/>
</DataTemplate>
</ContentControl.ContentTemplate>

@@ -169,16 +168,5 @@

</ScrollViewer>

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Grid.Column="2" Grid.Row="0" Padding="3" Margin="0,0,0,5"
Visibility="{Binding Path=MultipleVideosSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type usercontrols:AvdumpBatchControl}}, Converter={StaticResource BooleanToVisibilityConverter}}">
<ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="ccDetailMultiple" >
<ContentControl.ContentTemplate>
<DataTemplate>
<usercontrols:AvdumpFileControl/>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
</ScrollViewer>

</Grid>
</UserControl>
@@ -182,24 +182,27 @@ void lbVideos_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
VM_AVDump vid = lbVideos.SelectedItem as VM_AVDump;
ccDetail.Content = vid;
}

// if only one video selected
if (MultipleVideosSelected)
}else if (MultipleVideosSelected)
{
MultipleAvdumps mv = new MultipleAvdumps();
mv.SelectedCount = lbVideos.SelectedItems.Count;
mv.AVDumps = new List<VM_AVDump>();
MultipleAvdumps mv = new MultipleAvdumps()
{
SelectedCount = lbVideos.SelectedItems.Count,
AVDumps = new List<VM_AVDump>()
};

foreach (object obj in lbVideos.SelectedItems)
{
VM_AVDump vid = obj as VM_AVDump;
mv.AVDumps.Add(vid);
}

ccDetailMultiple.Content = mv;
ccDetail.Content = mv;
}

var control = Utils.FindElementByName<AvdumpFileControl>(ccDetail, "FileDetails");
control.DumpSingle = OneVideoSelected;
control.DumpMultiple = MultipleVideosSelected;


//SetConfirmDetails();
}
@@ -116,42 +116,40 @@
<StackPanel Orientation="Vertical" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Margin="5,0,2,2"
Visibility="{Binding Path=DumpSingle, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type usercontrols:AvdumpFileControl}}, Converter={StaticResource BooleanToVisibilityConverter}}">

<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Utilities_FileName}" Margin="3" FontWeight="DemiBold" />
<TextBlock Text="{Binding Path=VideoLocal.FileName}" Margin="3" />
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Utilities_Folder}" Margin="3" FontWeight="DemiBold" />
<TextBlock Text="{Binding Path=VideoLocal.FileDirectory}" Margin="3" />
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Utilities_Size}" Margin="3" FontWeight="DemiBold" />
<TextBlock Text="{Binding Path=VideoLocal.FormattedFileSize}" Margin="3" />
</StackPanel>

<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Hash" Margin="3" FontWeight="DemiBold" />
<TextBox Text="{Binding Path=VideoLocal.Hash}" Margin="3" Background="Transparent" BorderThickness="0" IsReadOnly="True" />
</StackPanel>
<StackPanel Name="StackPanelCRC32" Orientation="Horizontal" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">
<StackPanel Name="StackPanelCRC32" Orientation="Horizontal">
<TextBlock Text="CRC32" Margin="3" FontWeight="DemiBold" />
<TextBox Name="txtCRC32" Text="{Binding Path=VideoLocal.CRC32}" Margin="3" Background="Transparent" BorderThickness="0" IsReadOnly="True" />
</StackPanel>
<StackPanel Name="StackPanelSHA1" Orientation="Horizontal" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">
<StackPanel Name="StackPanelSHA1" Orientation="Horizontal">
<TextBlock Text="SHA1" Margin="3" FontWeight="DemiBold" />
<TextBox Name="txtSHA1" Text="{Binding Path=VideoLocal.SHA1}" Margin="3" Background="Transparent" BorderThickness="0" IsReadOnly="True" />
</StackPanel>
<StackPanel Name="StackPanelMD5" Orientation="Horizontal" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">
<StackPanel Name="StackPanelMD5" Orientation="Horizontal">
<TextBlock Text="MD5" Margin="3" FontWeight="DemiBold" />
<TextBox Name="txtMD5" Text="{Binding Path=VideoLocal.MD5}" Margin="3" Background="Transparent" BorderThickness="0" IsReadOnly="True" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3">
<TextBox Name="txtOutput" Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="3" Height="100" Margin="0" Text="{Binding Path=AVDumpFullResult}"
BorderThickness="1" ScrollViewer.VerticalScrollBarVisibility="Auto" TextWrapping="WrapWithOverflow"
HorizontalAlignment="Stretch"/>
</StackPanel >
<TextBox Name="txtOutput" Height="100" Margin="0"
Text="{Binding Path=OutputText, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type usercontrols:AvdumpFileControl}}}"
BorderThickness="1" ScrollViewer.VerticalScrollBarVisibility="Auto" TextWrapping="WrapWithOverflow" HorizontalAlignment="Stretch" />

</StackPanel >

@@ -171,7 +169,7 @@
<TextBlock Text="{Resx ResxName=Shoko.Commons.Properties.Resources, Key=Files}" Margin="5,0,0,0" VerticalAlignment="Center" FontWeight="Bold"/>
</StackPanel>

<TextBox Text="{Binding Path=AvDumpText, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type usercontrols:AvdumpFileControl}}}"
<TextBox Text="{Binding Path=OutputText, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type usercontrols:AvdumpFileControl}}}"
Grid.Column="0" Grid.Row="1" Margin="0,5,0,0" Height="130" ScrollViewer.VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"
HorizontalAlignment="Stretch"/>
</Grid>
@@ -116,6 +116,16 @@ public string AvDumpText
set => SetValue(AvDumpTextProperty, value);
}

public static readonly DependencyProperty OutputTextProperty = DependencyProperty.Register("OutputText",
typeof(string), typeof(AvdumpFileControl), new UIPropertyMetadata("", null));


public string OutputText
{
get => (string)GetValue(OutputTextProperty);
set => SetValue(OutputTextProperty, value);
}

public string SelectedCount
{
get
@@ -179,14 +189,15 @@ void AvdumpFileControl_DataContextChanged(object sender, DependencyPropertyChang
if (string.IsNullOrEmpty(dump.AVDumpFullResult))
{
string ed2kDump = "Pre-calculated ED2K Dump string" + Environment.NewLine;
ed2kDump += "---------------------------" + Environment.NewLine;
ed2kDump += "----------------------------------------------------------" + Environment.NewLine;
ed2kDump += "This does not mean the data has been uploaded to AniDB yet" + Environment.NewLine;
ed2kDump += "---------------------------" + Environment.NewLine;
ed2kDump += "----------------------------------------------------------" + Environment.NewLine;
ed2kDump += $@"ed2k://|file|{dump.FileName}|{dump.FileSize}|{dump.VideoLocal.Hash}|/" + Environment.NewLine;

dump.AVDumpFullResult = ed2kDump;
}

OutputText = dump.AVDumpFullResult;
dump.ED2KDump = Utils.GetED2KDump(dump.AVDumpFullResult);
SetED2KDump(dump.ED2KDump);
}
@@ -202,20 +213,41 @@ void AvdumpFileControl_DataContextChanged(object sender, DependencyPropertyChang
{
SearchAnime(dumpList.AVDumps[0]);

foreach (VM_AVDump dump in dumpList.AVDumps)
bool areDumped = !dumpList.AVDumps.Any(a => string.IsNullOrEmpty(a.AVDumpFullResult));
if (areDumped)
{
if (string.IsNullOrEmpty(dump.AVDumpFullResult))
string intersect = null;
foreach (VM_AVDump dump in dumpList.AVDumps)
{
string ed2kDump = "Pre-calculated ED2K Dump string" + Environment.NewLine;
ed2kDump += "---------------------------" + Environment.NewLine;
ed2kDump += "This does not mean the data has been uploaded to AniDB yet" + Environment.NewLine;
ed2kDump += "---------------------------" + Environment.NewLine;
ed2kDump += $@"ed2k://|file|{dump.FileName}|{dump.FileSize}|{dump.VideoLocal.Hash}|/" + Environment.NewLine;
dump.ED2KDump = Utils.GetED2KDump(dump.AVDumpFullResult);
massAvDump += dump.ED2KDump + Environment.NewLine;
if (intersect == null) intersect = dump.AVDumpFullResult;
else
{
string[] lines = intersect.Split(Environment.NewLine.ToCharArray(),
StringSplitOptions.RemoveEmptyEntries);
string[] avdumpLines = dump.AVDumpFullResult.Split(
Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
intersect = string.Join(Environment.NewLine, lines.Intersect(avdumpLines));
}
}

dump.AVDumpFullResult = ed2kDump;
OutputText = intersect + Environment.NewLine + Environment.NewLine + massAvDump;
}
else
{
string ed2kDump = "Pre-calculated ED2K Dump strings" + Environment.NewLine;
ed2kDump += "----------------------------------------------------------" + Environment.NewLine;
ed2kDump += "This does not mean the data has been uploaded to AniDB yet" + Environment.NewLine;
ed2kDump += "----------------------------------------------------------" + Environment.NewLine;
foreach (VM_AVDump dump in dumpList.AVDumps)
{
dump.ED2KDump = $@"ed2k://|file|{dump.FileName}|{dump.FileSize}|{dump.VideoLocal.Hash}|/";
massAvDump += dump.ED2KDump + Environment.NewLine;
}
dump.ED2KDump = Utils.GetED2KDump(dump.AVDumpFullResult);
massAvDump += dump.ED2KDump + Environment.NewLine;

ed2kDump += massAvDump;
OutputText = ed2kDump;
}
}
SetED2KDump(massAvDump);
@@ -13,6 +13,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using Microsoft.Win32;
using NLog;
using Shoko.Desktop.Forms;
@@ -889,5 +890,28 @@ public static bool IsDirectoryWritable(string dirPath, bool throwIfFails = false
return false;
}
}

public static T FindElementByName<T>(FrameworkElement element, string sChildName) where T : FrameworkElement
{
T childElement = null;
var nChildCount = VisualTreeHelper.GetChildrenCount(element);
for (int i = 0; i < nChildCount; i++)
{
if (!(VisualTreeHelper.GetChild(element, i) is FrameworkElement child))
continue;

if (child is T typedChild && child.Name.Equals(sChildName))
{
childElement = typedChild;
break;
}

childElement = FindElementByName<T>(child, sChildName);

if (childElement != null)
break;
}
return childElement;
}
}
}
@@ -113,23 +113,13 @@ public VM_AVDump()
{
}

/*public AVDumpVM(VideoDetailedVM vid)
{
this.FullPath = vid.FullPath;
this.FileSize = vid.VideoLocal_FileSize;
this.ED2KDump = "";
this.AVDumpFullResult = "";
this.HasBeenDumped = false;
this.IsBeingDumped = false;
this.DumpStatus = "To be processed";
}*/

public VM_AVDump(VM_VideoLocal vid)
{
FullPath = vid.GetLocalFileSystemFullPath();
FileSize = vid.FileSize;
ED2KDump = "";
AVDumpFullResult = "";HasBeenDumped = false;
AVDumpFullResult = "";
HasBeenDumped = false;
IsBeingDumped = false;
DumpStatus = "To be processed";
VideoLocal = vid;

0 comments on commit 33ed62a

Please sign in to comment.