1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Inoffizieller KE-Gamemanager

Discussion in 'Preview' started by Jan, Feb 6, 2014.

  1. Jan

    Jan New Member

    Joined:
    Jun 24, 2013
    Messages:
    91
    Likes Received:
    0
    So nach langer Zeit wo ich kaum was machen konnte mal ein Update:
    Die Fehlerquote liegt nun bei 3 Spielen auf 55.
    Derweil binde ich die Methode grad im Hauptprogramm ein und der KE-Loader wird demnächst auch noch eingebunden.

    So das wars erstmalk von mir aber ich hoffe das ihr bald mehr von mir hören werdet.

    Unten findet ihr die Klassen die für die 1.Nachricht zu viel Waren(10.000 Zeichen waren überschritten)

    Die Games-Klasse
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Xml;
    
    namespace Gamemanager
    {
    static class Games
    {
    static string gamedat = System.IO.Directory.GetCurrentDirectory() + "/Games/Games.KEM";
    
    static void addGameToList(String path,String name)
    {
    try
    {
    StreamReader SR = new StreamReader(gamedat);
    if (!(SR.ReadToEnd().Contains(path))&&!(SR.ReadToEnd().Contains(name)))
    {
    SR.Close();
    StreamWriter SW = File.AppendText(gamedat);
    SW.WriteLine(name + "[@]" + path);
    
    SW.Flush();
    SW.Close();
    
    }
    }
    catch (Exception ex)
    {
    
    }
    
    }
    
    static public Dictionary<String, String> getGameList()
    {
    StreamReader SR = new StreamReader(gamedat);
    Dictionary<String, String> list = new Dictionary<string, string>(1000);
    int i = 0;
    try
    {
    
    string s;
    
    while ((s = SR.ReadLine()) != null)
    {
    String[] kv = s.Split("[@]".ToCharArray());
    if (!list.ContainsKey(kv[0]) && !list.ContainsValue(kv[3]))
    {
    if (kv[3] != "removed")
    {
    list.Add(kv[0], kv[3]);
    i++;
    }
    
    }
    
    }
    SR.Close();
    
    }
    catch (Exception ex)
    {
    
    }
    
    return list;
    }
    
    static public void scanSteam(){
    try
    {
    if (Properties.Settings.Default.steamUsed)
    {
    string path = Properties.Settings.Default.steamPath;
    List<int> ids = SteamGameID.getGameIDs(path);
    List<string> o = SteamGameID.steamFolder(path);
    
    foreach (int id in ids)
    {
    string name = SteamGameID.getGameName(id);
    if (name != "ERROR")
    {
    foreach (string fol in o)
    {
    if (fol.Length < 1)
    {
    
    }
    else if (fol.ToLower().Length > 5)
    {
    if (fol.ToLower().Contains(name.Remove(4).ToLower()))
    {
    addGameToList("" + id, name);
    break;
    }
    }
    else if (fol.ToLower().Length > 3)
    {
    if (fol.ToLower().Contains(name.Remove(3).ToLower()))
    {
    addGameToList("" + id, name);
    break;
    }
    }
    else
    {
    if (fol.ToLower().Contains(name.Remove(2).ToLower()))
    {
    addGameToList("" + id, name);
    break;
    }
    }
    }
    }
    }
    }
    
    }
    catch (Exception ex)
    {
    
    }
    
    }
    
    static public void Remove(String path, String name)
    {
    try
    {
    StreamReader SR = new StreamReader(gamedat);
    String all = SR.ReadToEnd().Replace(name + "[@]" + path, name+"[@]removed");
    SR.Close();
    StreamWriter SW = File.CreateText(gamedat);
    SW.Write(all);
    SW.Close();
    }
    catch (Exception ex)
    {
    
    }
    
    }
    
    static public void changeName(String path, String name, String newName)
    {
    try
    {
    StreamReader SR = new StreamReader(gamedat);
    String all = SR.ReadToEnd().Replace(name + "[@]" + path, newName + "[@]" + path);
    SR.Close();
    StreamWriter SW = File.CreateText(gamedat);
    SW.Write(all);
    SW.Close();
    }
    catch (Exception ex)
    {
    
    }
    
    }
    
    }
    }
    
    Die Steam Game ID Klasse
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Net;
    
    namespace Gamemanager
    {
    class SteamGameID
    {
    
    public static string Updatepath(string path)
    {
    
    DirectoryInfo dir = new System.IO.DirectoryInfo(path + "/userdata/");
    string path2 = "";
    foreach (System.IO.DirectoryInfo d in dir.GetDirectories())
    {
    path2 = path +"/userdata/" + d.Name;
    break;
    }
    return path2;
    
    }
    
    public static List<int> getGameIDs(string path2)
    {
    string path = Updatepath(path2);
    
    StreamReader SR = new StreamReader(path + "/config/localconfig.vdf");
    String localconfig = SR.ReadToEnd();
    SR.Close();
    int i = localconfig.IndexOf("\"Software\"", 0);
    string remove = localconfig.Remove(i);
    localconfig = localconfig.Replace(remove, "");
    i = localconfig.IndexOf("\"ParentalSettings\"", 0);
    localconfig = localconfig.Remove(i);
    localconfig = localconfig.Replace("{", "").Replace("\"Software\"", "").Replace("}", "").Replace("\"", "").Replace("Valve", "").Replace("apps", "").Replace("\t", "-").Replace("Steam",""); 
    string[] lines = localconfig.Split("\n".ToCharArray());
    
    List<int> a = new List<int>();
    foreach (string s in lines)
    {
    
    string sz = s.Replace("-", "");
    
    if (int.TryParse(sz, out i))
    {
    a.Add(i);
    }
    
    }
    return a;
    }
    
    public static string getGameName(int id)
    {
    WebClient webClient = new WebClient(); 
    string html = webClient.DownloadString("http://store.steampowered.com/api/appdetails/?appids=" + id);
    if (html.Length < 49)
    {
    return "ERROR";
    }
    html = html.Replace(",", "!").Replace("{","!");
    html = html.Remove(html.IndexOf("\"steam_appid"));
    html = html.Replace("\"", "");
    string[] s = html.Split("!".ToCharArray());
    string ret = "ERROR";
    foreach (string n in s)
    {
    if (n.Contains("name:"))
    {
    ret = n.Replace("name:", "");
    }
    
    }
    return ret.Replace("\\u2122", "").Replace("\\u00ae", "").Replace("\\u2019", "'");
    }
    
    public static List<string>steamFolder(string gpath)
    {
    try
    {
    List<string> re = new List<string>();
    string Path = gpath + "/SteamApps/common/";
    
    DirectoryInfo dir = new System.IO.DirectoryInfo(Path);
    
    foreach (System.IO.DirectoryInfo d in dir.GetDirectories())
    {
    re.Add(d.Name);
    }
    return re;
    
    }
    catch (Exception ex)
    {
    
    }
    return null;
    
    }
    }
    }