Skip to content

Commit

Permalink
Added (in top-left menu system) an option to Audit the Scraped Data F…
Browse files Browse the repository at this point in the history
…older - #32
  • Loading branch information
Asnivor committed Feb 16, 2017
1 parent 2b58bec commit 00bffb4
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 3 deletions.
4 changes: 1 addition & 3 deletions MedLaunch/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@
<MenuItem x:Name="MenuScanRoms5" Header="Rescan GG" Click="ScanRoms_Click" />
<MenuItem x:Name="MenuScanRoms3" Header="Rescan LYNX" Click="ScanRoms_Click" />
</MenuItem>
<MenuItem Header="Scraping" ContextMenuService.IsEnabled="False" Click="TopMenu_Click" Visibility="{Binding Source={x:Static diag:Debugger.IsAttached}, Converter={StaticResource BoolToVisibilityConverter}}">
<MenuItem Header="Audit Scraped Data Folder" ToolTip="Show a list of game data that has been scraped along with system and game title" />
</MenuItem>
<MenuItem Name="AuditScrapedData" Header="Audit Scraped Data Folder" ToolTip="Show a list of game data that has been scraped along with system and game title" Click="AuditScrapedData_Click"/>
<MenuItem Header="Library Column Visibility" Click="MenuItemColumn_Click" />
</ContextMenu>
</Button.ContextMenu>
Expand Down
13 changes: 13 additions & 0 deletions MedLaunch/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4426,6 +4426,19 @@ private void rbSettings_Netplay_Checked(object sender, RoutedEventArgs e)
if (SettingsDirtyFlag == true)
ConfigsVisualHandler.SaveSettings(SettingGroup.NetplaySettings);
}

private async void AuditScrapedData_Click(object sender, RoutedEventArgs e)
{
MainWindow mw = Application.Current.Windows.OfType<MainWindow>().FirstOrDefault();
await mw.ShowChildWindowAsync(new ScrapedDataAudit()
{
IsModal = true,
AllowMove = false,
Title = "Scraped Data Folder Audit",
CloseOnOverlay = false,
ShowCloseButton = false
}, RootGrid);
}
}
/*
public class SliderIgnoreDelta : Slider
Expand Down
7 changes: 7 additions & 0 deletions MedLaunch/MedLaunch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@
<Compile Include="Models\ScraperMaster.cs" />
<Compile Include="Models\SearchOrdering.cs" />
<Compile Include="Models\Versions.cs" />
<Compile Include="ScrapedDataAudit.xaml.cs">
<DependentUpon>ScrapedDataAudit.xaml</DependentUpon>
</Compile>
<Compile Include="ThemeManagerHelper.cs" />
<Page Include="AccentStyleWindow.xaml">
<SubType>Designer</SubType>
Expand Down Expand Up @@ -403,6 +406,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="ScrapedDataAudit.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Models\MyDbContext.cs" />
Expand Down
81 changes: 81 additions & 0 deletions MedLaunch/ScrapedDataAudit.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<simpleChildWindow:ChildWindow x:Class="MedLaunch.ScrapedDataAudit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
mc:Ignorable="d"
d:DesignHeight="800"
d:DesignWidth="600"
CloseOnOverlay="True"
GlowBrush="{DynamicResource AccentColorBrush}"
BorderBrush="{DynamicResource AccentColorBrush}"
BorderThickness="1"
ShowCloseButton="True"
IsModal="True">

<simpleChildWindow:ChildWindow.Icon>
<Rectangle Width="22"
Height="22"
Fill="{DynamicResource IdealForegroundColorBrush}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform"
Visual="{DynamicResource appbar_cog}" />
</Rectangle.OpacityMask>
</Rectangle>
</simpleChildWindow:ChildWindow.Icon>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="5"
FontSize="36"
FontWeight="Thin"
Text="Matches Found" />

<DataGrid Height="500" x:Name="dgAudit" AutoGenerateColumns="False" ItemsSource="{Binding}" IsReadOnly="True" SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn Header="Folder" Binding="{Binding FolderName}" />
<DataGridTextColumn Header="Game" Binding="{Binding GameName}" />
<DataGridTextColumn Header="Platform" Binding="{Binding System}" />
<DataGridCheckBoxColumn Header="In Use" Binding="{Binding IsLinked}" />
<DataGridTemplateColumn Header="Local">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnLocal" Click="btnLocal_Click">
Open Folder
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Online">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnOnline" Click="btnOnline_Click">
View on thegamesdb.net
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>

</DataGrid>


<Button Grid.Row="3"

Margin="5"
IsDefault="True"
VerticalAlignment="Bottom"
FontSize="20"
FontWeight="Thin"
Content="Close"
Click="CloseSec_OnClick" />
</Grid>
</simpleChildWindow:ChildWindow>
141 changes: 141 additions & 0 deletions MedLaunch/ScrapedDataAudit.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using MahApps.Metro.SimpleChildWindow;
using MedLaunch.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MedLaunch
{
/// <summary>
/// Interaction logic for ScrapedDataAudit.xaml
/// </summary>
public partial class ScrapedDataAudit : ChildWindow
{
public List<FolderData> Data { get; set; }
public string BaseFolder { get; set; }
public List<ScraperMaster> Master { get; set; }

public ScrapedDataAudit()
{
InitializeComponent();

Data = new List<FolderData>();

// load the MasterGames.json
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\Data\\System\\MasterGames.json"))
{
MessageBox.Show("Unable to locate the MasterGames.json file! MedLaunch re-install may be necessary..");
this.Close();
}

string json = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "\\Data\\System\\MasterGames.json");
Master = JsonConvert.DeserializeObject<List<ScraperMaster>>(json);

// enumerate game data folder
BaseFolder = AppDomain.CurrentDomain.BaseDirectory + "\\Data\\Games";

var fol = Directory.GetDirectories(BaseFolder);
foreach (var d in fol)
{
string fName = System.IO.Path.GetFileName(d);

// check whether folder name is a valid number
int n;
bool isNumeric = int.TryParse(fName, out n);
if (isNumeric == false)
continue;

// build folderdata object
FolderData fd = new FolderData();
fd.FolderName = n;

// find gdbid from Master
var g = (from a in Master
where a.GamesDbId == n
select a).FirstOrDefault();

// is result empty?
if (g == null)
continue;

fd.GameName = g.TGDBData.GamesDBTitle;
fd.System = GSystem.GetSystemName(Convert.ToInt32(g.MedLaunchSystemId));

// now check whether it is linked anywhere in the database
var search = from a in Game.GetGames()
where a.gdbId == n
select a;

if (search.Count() > 0)
{
fd.IsLinked = true;
}
else
{
fd.IsLinked = false;
}

// add to list
Data.Add(fd);
}

Data.OrderBy(a => a.FolderName);

// populate the datagrid
dgAudit.ItemsSource = Data;
}

private void CloseSec_OnClick(object sender, RoutedEventArgs e)
{
this.Close();
}

private void btnLocal_Click(object sender, RoutedEventArgs e)
{
// get the id
var r = (FolderData)dgAudit.SelectedItem;
string gdbid = r.FolderName.ToString();

// open the folder in windows explorer
string dirPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\Data\Games\" + gdbid;
// check folder exists
if (Directory.Exists(dirPath))
{
// open the folder
Process.Start(dirPath);
}
}

private void btnOnline_Click(object sender, RoutedEventArgs e)
{
// get the id
var r = (FolderData)dgAudit.SelectedItem;
string gdbid = r.FolderName.ToString();

// open thegamesdb.net url in the default browser
string url = @"http://thegamesdb.net/game/" + gdbid;
Process.Start(url);
}
}

public class FolderData
{
public int FolderName { get; set; } // gdbid
public string System { get; set; }
public string GameName { get; set; }
public bool IsLinked { get; set; }
}
}

0 comments on commit 00bffb4

Please sign in to comment.