Skip to content

Commit

Permalink
Merge pull request #131 from Asnivor/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Asnivor authored Jul 5, 2017
2 parents d94a523 + 794cd37 commit 2049411
Show file tree
Hide file tree
Showing 171 changed files with 237,464 additions and 352 deletions.
51 changes: 51 additions & 0 deletions MedLaunch/Classes/DAT/AsniDATDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Microsoft.Data.Entity;
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MedLaunch.Classes.DAT
{
public class AsniDATDbContext : DbContext
{
// Add a DbSet for each entity type that you want to include in your model.For more information
// on configuring and using a Code First model, see http://go.microsoft.com/fwlink/?LinkId=390109.

public DbSet<DAT_System> DAT_System { get; set; } // table containing thegamesdb.net platforms
public DbSet<DAT_Game> DAT_Game { get; set; } // table containing all top-level games
public DbSet<DAT_Rom> DAT_Rom { get; set; } // table containing all actual ROMs
public DbSet<DAT_Provider> DAT_Provider { get; set; } // table containing all DAT providers
public DbSet<DATMerge> DATMerge { get; set; } // master view table



// define keys and relationships
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<DAT_System>()
.HasKey(c => c.pid);

modelBuilder.Entity<DAT_Game>()
.HasKey(c => c.gid);

modelBuilder.Entity<DAT_Rom>()
.HasKey(c => c.rid);

modelBuilder.Entity<DAT_Provider>()
.HasKey(c => c.datProviderId);

modelBuilder.Entity<DATMerge>()
.HasKey(c => c.id);
}


// This method connects the context with the database
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var sqliteConn = new SqliteConnection(@"DataSource = Data\System\AsniDAT.db");
optionsBuilder.UseSqlite(sqliteConn);
}
}
}
201 changes: 201 additions & 0 deletions MedLaunch/Classes/DAT/DATMerge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MedLaunch.Classes.DAT
{
public class DATMerge
{
public int id { get; set; }
public string RomName { get; set; }
public string Name { get; set; }
public string CloneOf { get; set; }
public string Copyright { get; set; }
public string Country { get; set; }
public int DatProviderId { get; set; }
public string Description { get; set; }
public string DevelopmentStatus { get; set; }
public int? gid { get; set; }
public string Language { get; set; }
public string MD5 { get; set; }
public string OtherFlags { get; set; }
public int pid { get; set; }
public string GameName { get; set; }
public int? gdbid { get; set; }
public string Year { get; set; }
public string Developer { get; set; }
public string Publisher { get; set; }




/* Static Methods */

/// <summary>
/// return a list of entries based on systemid and md5 hash
/// </summary>
/// <param name="inputList"></param>
/// <param name="systemId"></param>
/// <param name="md5Hash"></param>
/// <returns></returns>
public static List<DATMerge> GetDATsByHash(List<DATMerge> inputList, int systemId, string md5Hash)
{
var pData = FilterByMedLaunchSystemId(inputList, systemId);

var cData = (from g in pData
where g.MD5.ToUpper().Trim() == md5Hash.ToUpper().Trim()
select g).ToList();
return cData;
}

/// <summary>
/// return a list of entries based on systemid and extraflags (serial number)
/// </summary>
/// <param name="inputList"></param>
/// <param name="systemId"></param>
/// <param name="md5Hash"></param>
/// <returns></returns>
public static List<DATMerge> GetDATsBySN(List<DATMerge> inputList, int systemId, string serialNumber)
{
var pData = FilterByMedLaunchSystemId(inputList, systemId);

var cData = (from g in pData
where g.OtherFlags.ToUpper().Trim() == serialNumber.ToUpper().Trim()
select g).ToList();
return cData;
}

public static List<DATMerge> FilterByMedLaunchSystemId(List<DATMerge> inputList, int medSysId)
{
List<DATMerge> working = new List<DATMerge>();

switch (medSysId)
{
case 1:
working = inputList.Where(a => a.pid == 4 || a.pid == 41).ToList();
break;
case 2:
working = inputList.Where(a => a.pid == 5).ToList();
break;
case 3:
working = inputList.Where(a => a.pid == 4924).ToList();
break;
case 4:
working = inputList.Where(a => a.pid == 36 || a.pid == 18).ToList();
break;
case 5:
working = inputList.Where(a => a.pid == 20).ToList();
break;
case 6:
working = inputList.Where(a => a.pid == 4923 || a.pid == 4924).ToList();
break;
case 7:
working = inputList.Where(a => a.pid == 34 || a.pid == 4955).ToList();
break;
case 8:
working = inputList.Where(a => a.pid == 4930).ToList();
break;
case 9:
working = inputList.Where(a => a.pid == 10).ToList();
break;
case 10:
working = inputList.Where(a => a.pid == 35).ToList();
break;
case 11:
working = inputList.Where(a => a.pid == 7 || a.pid == 4936).ToList();
break;
case 12:
working = inputList.Where(a => a.pid == 6).ToList();
break;
case 13:
working = inputList.Where(a => a.pid == 17).ToList();
break;
case 14:
working = inputList.Where(a => a.pid == 4918).ToList();
break;
case 15:
working = inputList.Where(a => a.pid == 4925 || a.pid == 4926).ToList();
break;
case 16:
working = inputList.Where(a => a.pid == 6).ToList();
break;
case 17:
working = inputList.Where(a => a.pid == 34 || a.pid == 4955).ToList();
break;
case 18:
working = inputList.Where(a => a.pid == 34 || a.pid == 4955).ToList();
break;
}

return working;
}


/// <summary>
/// return all entries
/// </summary>
/// <returns></returns>
public static List<DATMerge> GetDATs()
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DATMerge
select g);
return cData.ToList();
}
}

/// <summary>
/// return all entries based on platformId
/// </summary>
/// <param name="pid"></param>
/// <returns></returns>
public static List<DATMerge> GetDATs(int pid)
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DATMerge
where g.pid == pid
select g);
return cData.ToList();
}
}

/// <summary>
/// return list where md5 matches
/// </summary>
/// <param name="md5"></param>
/// <returns></returns>
public static List<DATMerge> GetDATs(string md5)
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DATMerge
where g.MD5.ToUpper().Trim() == md5.ToUpper().Trim()
select g);
return cData.ToList();
}
}

/// <summary>
/// return the first entry where the MD5 hash matches
/// </summary>
/// <param name="md5"></param>
/// <returns></returns>
public static DATMerge GetDAT(string md5)
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DATMerge
where g.MD5.ToUpper().Trim() == md5.ToUpper().Trim()
select g).FirstOrDefault();
return cData;
}
}



}
}
85 changes: 85 additions & 0 deletions MedLaunch/Classes/DAT/DAT_Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MedLaunch.Classes.DAT
{
public class DAT_Game
{
public int gid { get; set; }
public string gameName { get; set; }
public int pid { get; set; }
public string year { get; set; }
public string publisher { get; set; }
public string developer { get; set; }
public int? gdbid { get; set; }


/// <summary>
/// return list of all top level games
/// </summary>
/// <returns></returns>
public static List<DAT_Game> GetGames()
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DAT_Game
select g);
return cData.ToList();
}
}

/// <summary>
/// return list of all top level games based on platformid
/// </summary>
/// <returns></returns>
public static List<DAT_Game> GetGames(int pid)
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DAT_Game
where g.pid == pid
select g);
return cData.ToList();
}
}

/// <summary>
/// return dat_game based on gid
/// </summary>
/// <returns></returns>
public static DAT_Game GetGame(int gid)
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DAT_Game
where g.gid == gid
select g).FirstOrDefault();
return cData;
}
}

/// <summary>
/// return dat_game based on gid
/// </summary>
/// <returns></returns>
public static DAT_Game GetGameByMD5(string md5)
{
DAT_Rom dr = DAT_Rom.GetRom(md5);
if (dr == null)
return null;

using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DAT_Game
where g.gid == dr.gid
select g).FirstOrDefault();
return cData;
}
}


}
}
28 changes: 28 additions & 0 deletions MedLaunch/Classes/DAT/DAT_Provider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MedLaunch.Classes.DAT
{
public class DAT_Provider
{
public int datProviderId { get; set; }
public string providerName { get; set; }

// <summary>
/// return a list with all providers
/// </summary>
/// <returns></returns>
public static List<DAT_Provider> GetProviders()
{
using (var context = new AsniDATDbContext())
{
var cData = (from g in context.DAT_Provider
select g);
return cData.ToList();
}
}
}
}
Loading

0 comments on commit 2049411

Please sign in to comment.