-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
172 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,127 @@ | ||
//using System; | ||
//using System.Collections.Generic; | ||
//using System.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
|
||
//namespace TwilightBoxart.Crawlers.LibRetro | ||
//{ | ||
// // Currently unused because of no-intro sources. :) | ||
// public static class LibRetroDat | ||
// { | ||
// /// <summary> | ||
// /// Parses a libretro .dat file. The code is horrible and so is the format .. | ||
// /// y no standards libretro? | ||
// /// </summary> | ||
// /// <typeparam name="T"></typeparam> | ||
// /// <param name="data"></param> | ||
// /// <param name="root"></param> | ||
// /// <returns></returns> | ||
// public static List<T> ParseDat<T>(string data, string root) | ||
// { | ||
// var result = new List<T>(); | ||
// var split = new List<string>(); | ||
// var instr = false; | ||
// var value = ""; | ||
namespace TwilightBoxart.Crawlers.LibRetro | ||
{ | ||
public static class LibRetroDat | ||
{ | ||
public static List<LibRetroRomData> DownloadDat(string url) | ||
{ | ||
using (var wc = new WebClient()) | ||
{ | ||
var data = wc.DownloadString(url); | ||
return ParseDat<LibRetroRomData>(data, "game"); | ||
} | ||
} | ||
|
||
// // Remove whitespace and shit. Just get the values. | ||
// foreach (var c in data) | ||
// { | ||
// if (c == '"') | ||
// { | ||
// instr = !instr; | ||
// continue; | ||
// } | ||
// if (!instr && c == ' ' || c == '\t' || c == '\n') | ||
// { | ||
// if (value != "") | ||
// { | ||
// split.Add(value); | ||
// value = ""; | ||
// } | ||
// continue; | ||
// } | ||
// value += c; | ||
// } | ||
/// <summary> | ||
/// Parses a libretro .dat file. The code is horrible and so is the format .. | ||
/// y no standards libretro? | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="data"></param> | ||
/// <param name="root"></param> | ||
/// <returns></returns> | ||
public static List<T> ParseDat<T>(string data, string root) | ||
{ | ||
var result = new List<T>(); | ||
var split = new List<string>(); | ||
var instr = false; | ||
var value = ""; | ||
|
||
// // Parse them. | ||
// var skip = false; | ||
// var indent = 0; | ||
// for (int i = 0; i < split.Count; i++) | ||
// { | ||
// if (!skip) | ||
// { | ||
// if (split[i].ToLower() == root.ToLower()) | ||
// { | ||
// i += 2; | ||
// var entity = Activator.CreateInstance<T>(); | ||
// ListToObj(entity, split, "", ref i); | ||
// result.Add(entity); | ||
// continue; | ||
// } | ||
// else | ||
// { | ||
// skip = true; | ||
// continue; | ||
// } | ||
// } | ||
// if (split[i] == "(") | ||
// { | ||
// indent++; | ||
// } | ||
// if (split[i] == ")") | ||
// { | ||
// indent--; | ||
// } | ||
// if (skip && indent == 0) | ||
// { | ||
// skip = false; | ||
// } | ||
// } | ||
// Remove whitespace and shit. Just get the values. | ||
foreach (var c in data) | ||
{ | ||
if (c == '"') | ||
{ | ||
instr = !instr; | ||
continue; | ||
} | ||
if (!instr && c == ' ' || c == '\t' || c == '\n') | ||
{ | ||
if (value != "") | ||
{ | ||
split.Add(value); | ||
value = ""; | ||
} | ||
continue; | ||
} | ||
value += c; | ||
} | ||
|
||
// return result; | ||
// } | ||
// Parse them. | ||
var skip = false; | ||
var indent = 0; | ||
for (int i = 0; i < split.Count; i++) | ||
{ | ||
if (!skip) | ||
{ | ||
if (split[i].ToLower() == root.ToLower()) | ||
{ | ||
i += 2; | ||
var entity = Activator.CreateInstance<T>(); | ||
ListToObj(entity, split, "", ref i); | ||
result.Add(entity); | ||
continue; | ||
} | ||
else | ||
{ | ||
skip = true; | ||
continue; | ||
} | ||
} | ||
if (split[i] == "(") | ||
{ | ||
indent++; | ||
} | ||
if (split[i] == ")") | ||
{ | ||
indent--; | ||
} | ||
if (skip && indent == 0) | ||
{ | ||
skip = false; | ||
} | ||
} | ||
|
||
// public static void ListToObj<T>(T obj, List<string> values, string key, ref int index) | ||
// { | ||
// var properties = obj.GetType().GetProperties(); | ||
// var currentKey = ""; | ||
return result; | ||
} | ||
|
||
// for (int i = index; i < values.Count; i++) | ||
// { | ||
// var value = values[i]; | ||
public static void ListToObj<T>(T obj, List<string> values, string key, ref int index) | ||
{ | ||
var properties = obj.GetType().GetProperties(); | ||
var currentKey = ""; | ||
|
||
// if (value == "(") | ||
// { | ||
// i++; | ||
// ListToObj(obj, values, currentKey, ref i); | ||
// continue; | ||
// } | ||
// if (value == ")") | ||
// { | ||
// index = i++; | ||
// return; | ||
// } | ||
// if (currentKey == "") | ||
// { | ||
// currentKey = key + value; | ||
// } | ||
// else | ||
// { | ||
// var property = properties.FirstOrDefault(c => c.Name.ToLower() == currentKey.ToLower()); | ||
// if (property != null) | ||
// property.SetValue(obj, value); | ||
for (int i = index; i < values.Count; i++) | ||
{ | ||
var value = values[i]; | ||
|
||
// currentKey = ""; | ||
// } | ||
// } | ||
// } | ||
// } | ||
//} | ||
if (value == "(") | ||
{ | ||
i++; | ||
ListToObj(obj, values, currentKey, ref i); | ||
continue; | ||
} | ||
if (value == ")") | ||
{ | ||
index = i++; | ||
return; | ||
} | ||
if (currentKey == "") | ||
{ | ||
currentKey = key + value; | ||
} | ||
else | ||
{ | ||
var property = properties.FirstOrDefault(c => c.Name.ToLower() == currentKey.ToLower()); | ||
if (property != null) | ||
property.SetValue(obj, value); | ||
|
||
currentKey = ""; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace TwilightBoxart.Crawlers.LibRetro | ||
{ | ||
// game ( | ||
// name "2 Game Pack! - Hot Wheels - Stunt Track Challenge + Hot Wheels - World Race (USA, Europe)" | ||
// description "2 Game Pack! - Hot Wheels - Stunt Track Challenge + Hot Wheels - World Race (USA, Europe)" | ||
// rom (name "2 Game Pack! - Hot Wheels - Stunt Track Challenge + Hot Wheels - World Race (USA, Europe).gba" size 16777216 crc 20929EC1 md5 4DAF3D378D5F91277F43A5555829FDC7 sha1 717B2A739C8932374AB48A9C2BBD76A44B4CF2F3 ) | ||
// ) | ||
public class LibRetroRomData | ||
{ | ||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
public string RomName { get; set; } | ||
public string RomSize { get; set; } | ||
public string RomCrc { get; set; } | ||
public string RomMd5 { get; set; } | ||
public string RomSha1 { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"{Name} - {RomSize}"; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.