Add Client Side Mods, restructurize tag detection

This commit is contained in:
SmallJoker 2017-04-10 19:54:50 +02:00
parent 25e7087faa
commit 0d2497bb5d
2 changed files with 71 additions and 38 deletions

26
Misc.cs
View File

@ -12,7 +12,8 @@ namespace ModIndexer
WIP_MODS = 9, WIP_MODS = 9,
REL_GAMES = 15, REL_GAMES = 15,
WIP_GAMES = 50, WIP_GAMES = 50,
OLD_MODS = 13 OLD_MODS = 13,
CSM_MODS = 53
} }
// The number in the database for the type // The number in the database for the type
@ -25,7 +26,28 @@ namespace ModIndexer
WIP_MP = 4, WIP_MP = 4,
OLD_MOD = 5, OLD_MOD = 5,
REL_GAME = 6, REL_GAME = 6,
WIP_GAME = 7 WIP_GAME = 7,
REL_CSM = 8,
WIP_CSM = 9
}
public static DATA_TYPE getDataType(string text)
{
switch (text.ToLower()) {
case "mod": return DATA_TYPE.REL_MOD;
case "mod pack":
case "modpack": return DATA_TYPE.REL_MP;
case "game": return DATA_TYPE.REL_GAME;
case "csm":
case "clientmod":
case "client mod": return DATA_TYPE.REL_CSM;
case "old clientmod": // TODO
case "old client mod": // TODO
case "old modpack": // TODO
case "old mod pack": // TODO
case "old mod": return DATA_TYPE.OLD_MOD;
}
return DATA_TYPE.INVALID;
} }
// Convert special characters to HTML code // Convert special characters to HTML code

View File

@ -18,17 +18,18 @@ namespace ModIndexer
"\n\t2) WIP mods [full]" + "\n\t2) WIP mods [full]" +
"\n\t3) Released games [full]" + "\n\t3) Released games [full]" +
"\n\t4) WIP games [full]" + "\n\t4) WIP games [full]" +
"\n\t5) Old mods [fast]" + "\n\t5) Client mods [full]" +
"\n\t6) Exit" + "\n\t6) Old mods [fast]" +
"\n\t7) Exit" +
"\n\nYour choice: "); "\n\nYour choice: ");
ConsoleKeyInfo k = new ConsoleKeyInfo(); ConsoleKeyInfo k = new ConsoleKeyInfo();
while (k.Key < ConsoleKey.D1 || while (k.Key < ConsoleKey.D1 ||
k.Key > ConsoleKey.D6) { k.Key > ConsoleKey.D7) {
k = Console.ReadKey(true); k = Console.ReadKey(true);
if (k.Key == ConsoleKey.D6) if (k.Key == ConsoleKey.D7)
return; return;
} }
Console.WriteLine(k.KeyChar + "\n"); Console.WriteLine(k.KeyChar + "\n");
@ -49,6 +50,9 @@ namespace ModIndexer
forum = Misc.FETCH_TYPE.WIP_GAMES; forum = Misc.FETCH_TYPE.WIP_GAMES;
break; break;
case ConsoleKey.D5: case ConsoleKey.D5:
forum = Misc.FETCH_TYPE.CSM_MODS;
break;
case ConsoleKey.D6:
forum = Misc.FETCH_TYPE.OLD_MODS; forum = Misc.FETCH_TYPE.OLD_MODS;
break; break;
default: default:
@ -215,18 +219,15 @@ namespace ModIndexer
goto flip; goto flip;
#region filter #region filter
Misc.DATA_TYPE type = Misc.DATA_TYPE.INVALID; Misc.DATA_TYPE type;
string mod_name;
title = parseTitle(title, out mod_name, out type);
string mod_name, switch (type) {
mod_tag; case Misc.DATA_TYPE.REL_MOD:
title = parseTitle(title, out mod_name, out mod_tag);
switch (mod_tag) {
case "mod":
case "old mod":
switch (forum) { switch (forum) {
case Misc.FETCH_TYPE.REL_MODS: case Misc.FETCH_TYPE.REL_MODS:
type = Misc.DATA_TYPE.REL_MOD; // Ok.
break; break;
case Misc.FETCH_TYPE.WIP_MODS: case Misc.FETCH_TYPE.WIP_MODS:
type = Misc.DATA_TYPE.WIP_GAME; type = Misc.DATA_TYPE.WIP_GAME;
@ -239,11 +240,10 @@ namespace ModIndexer
break; break;
} }
break; break;
case "modpack": case Misc.DATA_TYPE.REL_MP:
case "old modpack":
switch (forum) { switch (forum) {
case Misc.FETCH_TYPE.REL_MODS: case Misc.FETCH_TYPE.REL_MODS:
type = Misc.DATA_TYPE.REL_MP; // Ok.
break; break;
case Misc.FETCH_TYPE.WIP_MODS: case Misc.FETCH_TYPE.WIP_MODS:
type = Misc.DATA_TYPE.WIP_MP; type = Misc.DATA_TYPE.WIP_MP;
@ -256,24 +256,40 @@ namespace ModIndexer
break; break;
} }
break; break;
case "game": case Misc.DATA_TYPE.REL_GAME:
case "subgame":
switch (forum) { switch (forum) {
case Misc.FETCH_TYPE.REL_GAMES: case Misc.FETCH_TYPE.REL_GAMES:
type = Misc.DATA_TYPE.REL_GAME; // Ok.
break; break;
case Misc.FETCH_TYPE.WIP_GAMES: case Misc.FETCH_TYPE.WIP_GAMES:
case Misc.FETCH_TYPE.WIP_MODS: case Misc.FETCH_TYPE.WIP_MODS:
type = Misc.DATA_TYPE.WIP_GAME; type = Misc.DATA_TYPE.WIP_GAME;
break; break;
/*case Misc.FETCH_TYPE.OLD_GAMES: //case Misc.FETCH_TYPE.OLD_GAMES: // TODO
type = Misc.DATA_TYPE.OLD_GAME; // TODO case Misc.FETCH_TYPE.OLD_MODS:
break;*/ type = Misc.DATA_TYPE.OLD_MOD;
break;
default: default:
Console.WriteLine("INFO: Found a subgame in the wrong place"); Console.WriteLine("INFO: Found a subgame in the wrong place");
break; break;
} }
break; break;
case Misc.DATA_TYPE.REL_CSM:
switch (forum) {
case Misc.FETCH_TYPE.CSM_MODS:
// Ok.
break;
case Misc.FETCH_TYPE.WIP_MODS:
type = Misc.DATA_TYPE.WIP_CSM;
break;
case Misc.FETCH_TYPE.OLD_MODS:
type = Misc.DATA_TYPE.OLD_MOD;
break;
default:
Console.WriteLine("INFO: Found a CSM in the wrong place");
break;
}
break;
} }
if (type == Misc.DATA_TYPE.INVALID) { if (type == Misc.DATA_TYPE.INVALID) {
@ -452,12 +468,10 @@ namespace ModIndexer
string[] bad_content = { "wip", "beta", "test", "code", "indev", "git", "github" }; string[] bad_content = { "wip", "beta", "test", "code", "indev", "git", "github" };
// Beginnings of [mod-my_doors5] for wrong formatted titles // Beginnings of [mod-my_doors5] for wrong formatted titles
string[] bad_prefix = { "minetest", "mod", "mods" }; string[] bad_prefix = { "minetest", "mod", "mods" };
// [tags] to identify a mod
string[] identifiers = { "mod", "modpack", "game" };
string parseTitle(string title, out string mod_name, out string mod_tag) string parseTitle(string title, out string mod_name, out Misc.DATA_TYPE mod_tag)
{ {
mod_tag = ""; mod_tag = Misc.DATA_TYPE.INVALID;
mod_name = ""; mod_name = "";
string raw = title; string raw = title;
@ -482,17 +496,18 @@ namespace ModIndexer
string content = raw.Substring(open_pos + 1, len - 2).ToLower().Trim(); string content = raw.Substring(open_pos + 1, len - 2).ToLower().Trim();
double num = 0.0f; double num = 0.0f;
bool is_number = double.TryParse(content, out num); bool is_number = double.TryParse(content, out num);
Misc.DATA_TYPE tag = Misc.getDataType(content);
if (!is_number && mod_tag == "" if (!is_number && mod_tag == Misc.DATA_TYPE.INVALID
&& identifiers.IndexOf(content) != -1) { && tag != Misc.DATA_TYPE.INVALID) {
// Mod tag detected // Mod tag detected
mod_tag = content; mod_tag = tag;
delete = true; delete = true;
} }
if (delete || is_number if (delete || is_number
|| bad_content.IndexOf(content) != -1 || bad_content.IndexOf(content) != -1
|| identifiers.IndexOf(content) != -1) { || tag != Misc.DATA_TYPE.INVALID) {
// Remove this tag // Remove this tag
raw = raw.Remove(open_pos, len); raw = raw.Remove(open_pos, len);
@ -521,12 +536,8 @@ namespace ModIndexer
} else { } else {
// Replace this tag with the proper name // Replace this tag with the proper name
mod_name = content.Substring(start_substr); mod_name = content.Substring(start_substr);
raw = raw.Remove(open_pos, len); raw = raw.Remove(open_pos + 1, start_substr);
pos -= len; pos -= start_substr;
string to_insert = "[" + mod_name + "]";
raw.Insert(pos, to_insert);
pos += to_insert.Length;
} }
delete = false; delete = false;