Skip to content

Commit

Permalink
Fixed media downloading when option is de-selected in settings - bug #25
Browse files Browse the repository at this point in the history
  • Loading branch information
Asnivor committed Nov 17, 2016
1 parent eed1cdb commit eaa800a
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 87 deletions.
34 changes: 34 additions & 0 deletions MedLaunch/Classes/Input/Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JoytickInterop;
using System.Windows;

namespace MedLaunch.Classes.Input
{
public class Controller
{
public static void Start()
{

SDLJoystick.InitJoystickSystem();

List<string> sticks = SDLJoystick.JoystickNames;
foreach (var n in sticks)
{
MessageBox.Show(n.ToString());

SDLJoystick j = new SDLJoystick(n);
MessageBox.Show("Buttons: " + j.Buttons.ToString());
MessageBox.Show("Hats: " + j.Hats.ToString());
MessageBox.Show("Axis: " + j.Axes.ToString());
MessageBox.Show("Balls: " + j.Balls.ToString());
}


}

}
}
179 changes: 96 additions & 83 deletions MedLaunch/Classes/Scraper/MobyGames/MobyScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,109 +184,122 @@ public static ScrapedGameObjectWeb PullWebpageData(ScrapedGameObjectWeb o, Scrap
}
}

// cover art
// query the coverart page
string baseurlcover = "http://www.mobygames.com/game/";
string paramcover = masterrecord.MobyData.MobyPlatformName + "/" + masterrecord.MobyData.MobyURLName + "/cover-art";
string coverPage = ReturnWebpage(baseurlcover, paramcover, 10000);

// convert page string to htmldoc
HtmlDocument cDoc = new HtmlDocument();
cDoc.LoadHtml(coverPage);

// get all divs of class "row"
List<HtmlNode> coverDivs = cDoc.DocumentNode.SelectNodes("//div[@class ='row']").ToList();
// take the second one
HtmlNode cDiv = coverDivs[1];
// now get the div classes that make up the 3 images we want
if (coverPage.Contains("There are no covers for the selected platform."))
if (gs.scrapeBoxart == true || gs.scrapeMedia == true)
{
// no cover images found - skip
}
else
{
List<HtmlNode> imageDivs = cDiv.SelectNodes("//div[@class ='thumbnail']").ToList();

bool frontFound = false;
bool backFound = false;
bool mediaFound = false;

// iterate through every 'row' div
foreach (HtmlNode h in imageDivs)
// cover art
// query the coverart page
string baseurlcover = "http://www.mobygames.com/game/";
string paramcover = masterrecord.MobyData.MobyPlatformName + "/" + masterrecord.MobyData.MobyURLName + "/cover-art";
string coverPage = ReturnWebpage(baseurlcover, paramcover, 10000);

// convert page string to htmldoc
HtmlDocument cDoc = new HtmlDocument();
cDoc.LoadHtml(coverPage);

// get all divs of class "row"
List<HtmlNode> coverDivs = cDoc.DocumentNode.SelectNodes("//div[@class ='row']").ToList();
// take the second one
HtmlNode cDiv = coverDivs[1];
// now get the div classes that make up the 3 images we want
if (coverPage.Contains("There are no covers for the selected platform."))
{
// no cover images found - skip
}
else
{
// get media type
List<HtmlNode> type = h.SelectNodes("//div[@class ='thumbnail-cover-caption']").ToList();
List<HtmlNode> img = h.SelectNodes("//a[@class ='thumbnail-cover']").ToList();
int typeCount = type.Count;
List<HtmlNode> imageDivs = cDiv.SelectNodes("//div[@class ='thumbnail']").ToList();

for (int i = 0; i < typeCount; i++)
bool frontFound = false;
bool backFound = false;
bool mediaFound = false;

// iterate through every 'row' div
foreach (HtmlNode h in imageDivs)
{
string t = type[i].InnerText.Trim().ToLower();
string MEDIA = "http://mobygames.com" + img[i].Attributes["style"].Value.Replace(");", "").Replace("background-image:url(", "").Replace("/s/", "/l/");
// get media type
List<HtmlNode> type = h.SelectNodes("//div[@class ='thumbnail-cover-caption']").ToList();
List<HtmlNode> img = h.SelectNodes("//a[@class ='thumbnail-cover']").ToList();
int typeCount = type.Count;

if (frontFound == false && t == "front cover")
for (int i = 0; i < typeCount; i++)
{
if (o.FrontCovers == null || o.FrontCovers.Count == 0)
string t = type[i].InnerText.Trim().ToLower();
string MEDIA = "http://mobygames.com" + img[i].Attributes["style"].Value.Replace(");", "").Replace("background-image:url(", "").Replace("/s/", "/l/");

if (frontFound == false && t == "front cover")
{
o.FrontCovers = new List<string>();
o.FrontCovers.Add(MEDIA);
}
frontFound = true;
}
if (backFound == false && t == "back cover")
{
if (o.BackCovers == null || o.BackCovers.Count == 0)
if (o.FrontCovers == null || o.FrontCovers.Count == 0)
{
if (gs.scrapeBoxart == true)
{
o.FrontCovers = new List<string>();
o.FrontCovers.Add(MEDIA);
}
}
frontFound = true;
}
if (backFound == false && t == "back cover")
{
o.BackCovers = new List<string>();
o.BackCovers.Add(MEDIA);
if (o.BackCovers == null || o.BackCovers.Count == 0)
{
if (gs.scrapeBoxart == true)
{
o.BackCovers = new List<string>();
o.BackCovers.Add(MEDIA);
}
}
backFound = true;
}
backFound = true;
}
if (mediaFound == false && t == "media")
{
if (o.Medias == null || o.Medias.Count == 0)
if (mediaFound == false && t == "media")
{
o.Medias = new List<string>();
o.Medias.Add(MEDIA);
if (o.Medias == null || o.Medias.Count == 0)
{
if (gs.scrapeMedia == true)
{
o.Medias = new List<string>();
o.Medias.Add(MEDIA);
}
}
mediaFound = true;
}
mediaFound = true;
}

if (mediaFound == true && backFound == true && frontFound == true)
break;
if (mediaFound == true && backFound == true && frontFound == true)
break;
}
}
}
}

// screenshots
// query the screenshots page
string baseurlscreen = "http://www.mobygames.com/game/";
string paramscreen = masterrecord.MobyData.MobyPlatformName + "/" + masterrecord.MobyData.MobyURLName + "/screenshots";
string screenPage = ReturnWebpage(baseurlscreen, paramscreen, 10000);

// convert page string to htmldoc
HtmlDocument sDoc = new HtmlDocument();
sDoc.LoadHtml(screenPage);

// get core information
if (!screenPage.Contains("There are no user screenshots on file"))
if (gs.scrapeScreenshots == true)
{
List<HtmlNode> screens = sDoc.DocumentNode.SelectNodes("//a[@class ='thumbnail-image']").ToList();
if (o.Screenshots == null)
o.Screenshots = new List<string>();
int co = 0;
foreach (var screen in screens)
// screenshots
// query the screenshots page
string baseurlscreen = "http://www.mobygames.com/game/";
string paramscreen = masterrecord.MobyData.MobyPlatformName + "/" + masterrecord.MobyData.MobyURLName + "/screenshots";
string screenPage = ReturnWebpage(baseurlscreen, paramscreen, 10000);

// convert page string to htmldoc
HtmlDocument sDoc = new HtmlDocument();
sDoc.LoadHtml(screenPage);

// get core information
if (!screenPage.Contains("There are no user screenshots on file"))
{
if (co >= gs.maxScreenshots)
break;
var attrib = screen.Attributes["style"].Value;
string path = attrib.Replace(");", "").Replace("background-image:url(", "").Replace("/s/", "/l/");
o.Screenshots.Add("http://mobygames.com" + path);
co++;
List<HtmlNode> screens = sDoc.DocumentNode.SelectNodes("//a[@class ='thumbnail-image']").ToList();
if (o.Screenshots == null)
o.Screenshots = new List<string>();
int co = 0;
foreach (var screen in screens)
{
if (co >= gs.maxScreenshots)
break;
var attrib = screen.Attributes["style"].Value;
string path = attrib.Replace(");", "").Replace("background-image:url(", "").Replace("/s/", "/l/");
o.Screenshots.Add("http://mobygames.com" + path);
co++;
}
}
}


return o;
}

Expand Down
13 changes: 10 additions & 3 deletions MedLaunch/Classes/Scraper/ScraperHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ public void ScrapeGame(ProgressDialogController controller, string message)
{
if (gameObject.Manuals == null)
gameObject.Manuals = new List<string>();

gameObject.Manuals = MasterRecord.IDDBManual;
}
gameObject.Manuals = MasterRecord.IDDBManual;


// enumerate globalsettings
switch (_GlobalSettings.primaryScraper)
Expand Down Expand Up @@ -270,8 +272,13 @@ public void ScrapeGame(ProgressDialogController controller, string message)
glsc.SaveJson(gameObject);

// Download all the files
controller.SetMessage(message + "Downloading media");
ContentDownloadManager(gameObject, controller, glsc, message + "Downloading media...\n");
if (_GlobalSettings.scrapeBanners == true || _GlobalSettings.scrapeBoxart == true || _GlobalSettings.scrapeFanart == true || _GlobalSettings.scrapeManuals == true ||
_GlobalSettings.scrapeMedia == true || _GlobalSettings.scrapeScreenshots == true)
{
controller.SetMessage(message + "Downloading media");
ContentDownloadManager(gameObject, controller, glsc, message + "Downloading media...\n");
}


// Create / Update GDBLink table
CreateDatabaseLink(GameId, gameObject.GdbId);
Expand Down
Binary file added MedLaunch/ExternalAssemblies/SDL.dll
Binary file not shown.
Binary file added MedLaunch/ExternalAssemblies/SDL64.dll
Binary file not shown.
Binary file added MedLaunch/ExternalAssemblies/SDLJoystick.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions MedLaunch/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8317,6 +8317,11 @@
Dump all basic mobygames list from database to local json
</Button>
-->

<Button Margin="5" x:Name="btnPJoyTest" Click="btnPJoyTest_Click">
Joystick test
</Button>

</WrapPanel>
</TabItem>

Expand Down
6 changes: 5 additions & 1 deletion MedLaunch/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
using MedLaunch.Classes.Scraper;
using MedLaunch.Classes.Scraper.ReplacementDocs;
using MahApps.Metro;
using MedLaunch.Classes.Input;

namespace MedLaunch
{
Expand Down Expand Up @@ -2968,7 +2969,10 @@ private void SaveConfigToDisk_Click(object sender, RoutedEventArgs e)
string sysCode = rb.Name.Replace("btnConfig", "");
}


private void btnPJoyTest_Click(object sender, RoutedEventArgs e)
{
Controller.Start();
}
}
/*
public class SliderIgnoreDelta : Slider
Expand Down
8 changes: 8 additions & 0 deletions MedLaunch/MedLaunch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
<HintPath>..\packages\Remotion.Linq.2.0.1\lib\net45\Remotion.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SDLJoystick, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>ExternalAssemblies\SDLJoystick.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Expand Down Expand Up @@ -205,6 +209,7 @@
<Compile Include="Classes\CMenu.cs" />
<Compile Include="Classes\ConfigImport.cs" />
<Compile Include="Classes\ConfigReflection.cs" />
<Compile Include="Classes\Input\Controller.cs" />
<Compile Include="Classes\LogParser.cs" />
<Compile Include="Classes\Scraper\ReplacementDocs\RdScraper.cs" />
<Compile Include="Classes\Scraper\ScraperHandler.cs" />
Expand Down Expand Up @@ -401,6 +406,9 @@
<Resource Include="Data\Graphics\Systems\wswan.jpg" />
</ItemGroup>
<ItemGroup>
<Content Include="ExternalAssemblies\SDL.dll" />
<Content Include="ExternalAssemblies\SDL64.dll" />
<Content Include="ExternalAssemblies\SDLJoystick.dll" />
<Resource Include="LatestVersion.txt" />
<Resource Include="Data\Graphics\mediconsplash.png" />
<Content Include="ExternalAssemblies\FuzzyString.dll" />
Expand Down

0 comments on commit eaa800a

Please sign in to comment.