Skip to content

Commit

Permalink
1.5: add csdb support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargaj committed Apr 29, 2023
1 parent 1dce1ab commit 27f4ca1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions Source/Conduit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<DependentUpon>SelectRunnableDialog.cs</DependentUpon>
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="Sites\CSDb.cs" />
<Compile Include="Sites\Demozoo.cs" />
<Compile Include="Sites\ISite.cs" />
<Compile Include="Sites\Pouet.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.3.0")]
[assembly: AssemblyFileVersion("1.4.3.0")]
[assembly: AssemblyVersion("1.5.0")]
[assembly: AssemblyFileVersion("1.5.0")]
1 change: 1 addition & 0 deletions Source/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void Initialize()
Sites = new List<ISite>();
Sites.Add(new Pouet());
Sites.Add(new Demozoo());
Sites.Add(new CSDb());

Unpackers = new List<IUnpacker>();
Unpackers.Add(new Zip());
Expand Down
73 changes: 73 additions & 0 deletions Source/Sites/CSDb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Newtonsoft.Json;

namespace Conduit.Sites
{
class CSDb : ISite
{
public string ID => "csdb";
public string Name => "CSDb";

public IEnumerable<string> ProdLists => new List<string>()
{
};

public async Task<IEnumerable<SiteProdInfo>> RetrieveProdList(string listName)
{
return new List<SiteProdInfo>();
}

public async Task<SiteProdInfo> RetrieveProdInfo(Uri uri)
{
var id = uri.Segments[2];
using (var wc = new System.Net.WebClient())
{
var csdbApiURL = $"https://csdb.dk/webservice/?type=release&id={id}";
string contents = await wc.DownloadStringTaskAsync(csdbApiURL);
if (contents == null || contents.Length <= 0)
{
return null;
}

XmlDocument document = new XmlDocument();
try
{
document.LoadXml(contents);
}
catch (XmlException)
{
return null;
}

SiteProdInfo prodInfo = new SiteProdInfo();
prodInfo.ID = Convert.ToInt32(id);
prodInfo.Name = document?.DocumentElement?.SelectSingleNode("//Release/Name")?.InnerText ?? string.Empty;

var groups = document?.DocumentElement?.SelectNodes("//Release/ReleasedBy/Group");
if (groups != null)
{
var groupNames = new List<string>();
foreach (XmlNode group in groups)
{
groupNames.Add(group.SelectSingleNode("Name").InnerText);
}
prodInfo.Group = string.Join(" & ", groupNames);
}

prodInfo.DownloadLink = document?.DocumentElement?.SelectSingleNode("//Release/DownloadLinks/DownloadLink/Link")?.InnerText ?? string.Empty;

prodInfo.ReleaseDate = new DateTime(
Convert.ToInt32(document?.DocumentElement?.SelectSingleNode("//Release/ReleaseYear")?.InnerText ?? "0"),
Convert.ToInt32(document?.DocumentElement?.SelectSingleNode("//Release/ReleaseMonth")?.InnerText ?? "0"),
Convert.ToInt32(document?.DocumentElement?.SelectSingleNode("//Release/ReleaseDay")?.InnerText ?? "0")
);
return prodInfo;
}
}
}
}

0 comments on commit 27f4ca1

Please sign in to comment.