コード例 #1
0
ファイル: D2MP.cs プロジェクト: KingCohort/D2ModdinClient
        public static void main()
        {
            log.Debug("D2MP starting...");

            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var iconThread = new Thread(delegate()
            {
                using (icon = new ProcessIcon())
                {
                    icon.Display();
                    Application.Run();
                }
            });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var steam = new SteamFinder();
                var steamDir = steam.FindSteam(true);
                dotaDir = steam.FindDota(true);
                if (steamDir == null || dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                else
                {
                    log.Debug("Steam found: " + steamDir);
                    log.Debug("Dota found: " + dotaDir);
                }

                addonsDir = Path.Combine(dotaDir, "dota/addons/");
                d2mpDir = Path.Combine(dotaDir, "dota/d2moddin/");
                modDir = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                    Directory.CreateDirectory(addonsDir);
                if (!Directory.Exists(d2mpDir))
                    Directory.CreateDirectory(d2mpDir);
                if (!Directory.Exists(modDir))
                    Directory.CreateDirectory(modDir);

                {
                    var dirs = Directory.GetDirectories(d2mpDir);
                    modNames = new string[dirs.Length];
                    int i = 0;
                    foreach (var dir in dirs)
                    {
                        var modName = Path.GetFileName(dir);
                        log.Debug("Found mod: " + modName + " detecting version...");
                        var infoPath = Path.Combine(d2mpDir, modName + "/addoninfo.txt");
                        string versionFile = "";
                        if (File.Exists(infoPath))
                        {
                            versionFile = File.ReadAllText(infoPath);
                        }
                        var match = Regex.Match(versionFile, @"(addonversion)(\s+)(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)",
                                                RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            string version = match.Groups.Cast<Group>()
                                             .ToList()
                                             .Skip(3)
                                             .Aggregate("", (current, part) => current + part.Value);
                            log.Debug(modName + "=" + version);
                            modNames[i] = modName + "=" + version;
                        }
                        else
                        {
                            log.Error("Can't find version info for mod: " + modName + ", not including");
                            modNames[i] = modName + "=?";
                        }
                        i++;
                    }
                }

                //Detect user
                var config = File.ReadAllText(Path.Combine(steamDir, @"config\config.vdf"));
                var matches = Regex.Matches(config, "\"\\d{17}\"");
                string steamid;
                List<string> steamids = new List<string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                FileSystemWatcher watcher = new FileSystemWatcher();
                watcher.Path = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter = "d2mp.pid";
                watcher.Deleted += (sender, args) =>
                {
                    shutDown = true;
                };
                watcher.EnableRaisingEvents = true;

                shutDown = false;
                int tryCount = 0;
                while (tryCount < 30 && !shutDown)
                {
                    using (ws = new WebSocket(server))
                    {
                        ws.OnMessage += (sender, e) =>
                        {
                            log.Debug("server: " + e.Data);
                            if (e.Data == "invalidid")
                            {
                                log.Debug("Invalid ID!");
                                shutDown = true;
                                return;
                            }

                            if (e.Data == "close")
                            {
                                log.Debug("Shutting down due to server request.");
                                shutDown = true;
                                return;
                            }

                            if (e.Data == "uninstall")
                            {
                                log.Debug("Uninstalling due to server request...");
                                Uninstall();
                                shutDown = true;
                                return;
                            }

                            var msgParts = e.Data.Split(':');
                            switch (msgParts[0])
                            {
                                case "installmod":
                                    ThreadPool.QueueUserWorkItem(InstallMod, msgParts);
                                    break;
                                case "deletemod":
                                    ThreadPool.QueueUserWorkItem(DeleteMod, msgParts);
                                    break;
                                case "setmod":
                                    ThreadPool.QueueUserWorkItem(SetMod, msgParts);
                                    break;
                                case "dconnect":
                                    ThreadPool.QueueUserWorkItem(ConnectDota, msgParts);
                                    break;
                                case "launchdota":
                                    ThreadPool.QueueUserWorkItem(LaunchDota, msgParts);
                                    break;
                                case "dspectate":
                                    ThreadPool.QueueUserWorkItem(SpectateGame, msgParts);
                                    break;
                                default:
                                    log.Error("Command not recognized: " + msgParts[0]);
                                    break;
                            }
                        };

                        ws.OnOpen += (sender, e) => log.Debug("Connected");
                        ws.OnClose += (sender, args) => log.Debug("Disconnected");
                        ws.Connect();
                        tryCount++;
                        if (!ws.IsAlive)
                        {
                            if (tryCount == 1)
                            {
                                icon.DisplayBubble("Disconnected, attempting to reconnect...");
                            }
                            log.Debug("Can't connect to server, tries: " + tryCount);
                            Thread.Sleep(500);
                            continue;
                        }

                        if (tryCount > 1)
                        {
                            icon.DisplayBubble("Reconnected!");
                        }
                        else
                        {
                            icon.DisplayBubble("Connected and ready to begin installing mods.");
                        }

                        try
                        {
                            var ver =
                                File.ReadAllText(
                                    Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                                 "version.txt"));
                            log.Debug("sending version: " + ver);
                            ws.Send("init:" + String.Join(",", steamids.ToArray(), 0, steamids.Count) + ":" + ver +
                                    ":" + String.Join(",", modNames));
                        }
                        catch (Exception ex)
                        {
                            log.Debug("Can't detect ID from version.txt, : " + ex);
                            return;
                        }

                        tryCount = 0;
                        while (ws.IsAlive && !shutDown)
                        {
                            Thread.Sleep(100);
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            UnmodGameInfo();
            Application.Exit();
        }
コード例 #2
0
ファイル: D2MP.cs プロジェクト: DarkEndain/D2ModdinClient
        public static void main()
        {
            log.Debug("D2MP starting...");

            Application.ThreadException += (sender, args) => log.Error("Unhandled thread exception.", args.Exception);
            AppDomain.CurrentDomain.UnhandledException += (sender, args) => log.Error("Unhandled domain exception.", (Exception) args.ExceptionObject);

            var notifyThread = new Thread(delegate()
            {
                using (notifier = new notificationForm())
                {
                    notifier.Visible = true;
                    Application.Run();
                }
            });
            notifyThread.SetApartmentState(ApartmentState.STA);
            notifyThread.Start();
            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
                                        {
                                            using (icon = new ProcessIcon())
                                            {
                                                icon.Display();
                                                icon.showNotification = () => notifier.Invoke(new MethodInvoker(() => { notifier.Fade(1); notifier.hideTimer.Start(); }));
                                                Application.Run();
                                            }
                                        });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            if (Settings.createShortcutAtStartup)
                ShortcutWriter.writeDesktopShortcut();

            try
            {
                var steam = new SteamFinder();
                if (!steam.checkProtocol())
                {
                    log.Error("Steam protocol not found. Trying to repair...");
                    var steamDir = steam.FindSteam(true, false);
                    var steamservicePath = Path.Combine(steamDir, @"bin\steamservice.exe");
                    if (File.Exists(steamservicePath))
                    {
                        Process process = new Process() { StartInfo = { FileName = steamservicePath, Arguments = "/repair" } };
                        try
                        {
                            process.Start();
                        }
                        catch
                        {
                            log.Fatal("Could not repair protocol. Steamservice couldn't run. Elevation refused?");
                        }
                        process.WaitForExit();
                        Restart();
                    }
                    else
                    {
                        log.Fatal("Could not repair protocol. Steam directory could not be found. Is steam installed? If so, please reinstall steam.");
                    }

                }
                if (!Directory.Exists(Settings.steamDir) || !Directory.Exists(Settings.dotaDir) || !SteamFinder.checkDotaDir(Settings.dotaDir))
                {
                    Settings.steamDir = steam.FindSteam(true);
                    Settings.dotaDir = steam.FindDota(true);
                }

                if (Settings.steamDir == null || Settings.dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + Settings.steamDir);
                log.Debug("Dota found: " + Settings.dotaDir);

                addonsDir = Path.Combine(Settings.dotaDir, @"dota\addons\");
                d2mpDir = Path.Combine(Settings.dotaDir, @"dota\d2moddin\");
                modDir = Path.Combine(addonsDir, "d2moddin");

                if (!Directory.Exists(addonsDir))
                    Directory.CreateDirectory(addonsDir);
                else
                {
                    var contents = Directory.GetDirectories(addonsDir);
                    foreach (var dir in contents)
                    {
                        try
                        {
                            Directory.Delete(dir, true);
                        }
                        catch (Exception ex)
                        {
                            log.Error("Can't delete addon dir, "+dir, ex);
                        }
                    }
                }
                if (!Directory.Exists(d2mpDir))
                    Directory.CreateDirectory(d2mpDir);
                if (!Directory.Exists(modDir))
                    Directory.CreateDirectory(modDir);

                modController.getLocalMods();

                Dictionary<int, string> usersDict = steam.FindUsers();
                if (usersDict.Count > 0)
                {
                    steamids.AddRange(usersDict.OrderByDescending(x => x.Key).Select(m=>m.Value));
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, PIDFile);
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter = PIDFile;
                watcher.Deleted += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                try
                {
                    SetupClient();
                    client.Open();
                }
                catch (Exception)
                {
                    notifier.Notify(NotificationType.Error, "Server error", "Can't connect to the lobby server!");
                    Wait(5);
                    HandleClose();
                }
                while (!shutDown)
                {
                    Thread.Sleep(100);
                }

                if (client != null && client.IsConnected) client.Close();
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            shutDown = true;
            Application.Exit();
        }
コード例 #3
0
ファイル: D2MP.cs プロジェクト: Kolpa/D2ModdinClient
        public static void main()
        {
            log.Debug("D2MP starting...");
            var notifyThread = new Thread(delegate()
            {
                using (notifier = new notificationForm())
                {
                    notifier.Visible = true;
                    Application.Run();
                }
            });
            notifyThread.SetApartmentState(ApartmentState.STA);
            notifyThread.Start();
            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
                                        {
                                            using (icon = new ProcessIcon())
                                            {
                                                icon.Display();
                                                icon.showNotification = () => notifier.Invoke(new MethodInvoker(() => { notifier.Fade(1); notifier.hideTimer.Start(); }));
                                                Application.Run();
                                            }
                                        });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var steam = new SteamFinder();
                if (!steam.checkProtocol())
                {
                    log.Error("Steam protocol not found. Trying to repair...");
                    var steamDir = steam.FindSteam(true, false);
                    var steamservicePath = Path.Combine(steamDir, @"bin\steamservice.exe");
                    if (File.Exists(steamservicePath))
                    {
                        Process process = new Process() { StartInfo = { FileName = steamservicePath, Arguments = "/repair" } };
                        try
                        {
                            process.Start();
                        }
                        catch
                        {
                            log.Fatal("Could not repair protocol. Steamservice couldn't run. Elevation refused?");
                        }
                        process.WaitForExit();
                        Restart();
                    }
                    else
                    {
                        log.Fatal("Could not repair protocol. Steam directory could not be found. Is steam installed? If so, please reinstall steam.");
                    }

                }
                if (!Directory.Exists(Settings.steamDir) || !Directory.Exists(Settings.dotaDir) || !SteamFinder.checkDotaDir(Settings.dotaDir))
                {
                    Settings.steamDir = steam.FindSteam(true);
                    Settings.dotaDir = steam.FindDota(true);
                }

                if (Settings.steamDir == null || Settings.dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + Settings.steamDir);
                log.Debug("Dota found: " + Settings.dotaDir);

                addonsDir = Path.Combine(Settings.dotaDir, @"dota\addons\");
                d2mpDir = Path.Combine(Settings.dotaDir, @"dota\d2moddin\");
                modDir = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                    Directory.CreateDirectory(addonsDir);
                if (!Directory.Exists(d2mpDir))
                    Directory.CreateDirectory(d2mpDir);
                if (!Directory.Exists(modDir))
                    Directory.CreateDirectory(modDir);

                {
                    modController.getLocalMods();
                }

                //Detect user
                string config = File.ReadAllText(Path.Combine(Settings.steamDir, @"config\config.vdf"));
                MatchCollection matches = Regex.Matches(config, "\"\\d{17}\"");
                string steamid;
                steamids = new List<string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter = "d2mp.pid";
                watcher.Deleted += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                try
                {
                    SetupClient();
                    client.Open();
                }
                catch (Exception)
                {
                    notifier.Notify(4, "Server error", "Can't connect to the lobby server!");
                    Thread.Sleep(5000);
                    HandleClose();
                }
                while (!shutDown)
                {
                    Thread.Sleep(100);
                }
                if (client != null)
                    client.Close();
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            shutDown = true;
            Application.Exit();
        }
コード例 #4
0
ファイル: D2MP.cs プロジェクト: intergalactic7/D2ModdinClient
        public static void main()
        {
            log.Debug("D2MP starting...");

            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
            {
                using (icon = new ProcessIcon())
                {
                    icon.Display();
                    Application.Run();
                }
            });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var    steam    = new SteamFinder();
                string steamDir = steam.FindSteam(true);
                dotaDir = steam.FindDota(true);
                if (steamDir == null || dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + steamDir);
                log.Debug("Dota found: " + dotaDir);

                addonsDir = Path.Combine(dotaDir, "dota/addons/");
                d2mpDir   = Path.Combine(dotaDir, "dota/d2moddin/");
                modDir    = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                {
                    Directory.CreateDirectory(addonsDir);
                }
                if (!Directory.Exists(d2mpDir))
                {
                    Directory.CreateDirectory(d2mpDir);
                }
                if (!Directory.Exists(modDir))
                {
                    Directory.CreateDirectory(modDir);
                }

                {
                    string[] dirs = Directory.GetDirectories(d2mpDir);
                    int      i    = 0;
                    foreach (string dir in dirs)
                    {
                        string modName = Path.GetFileName(dir);
                        log.Debug("Found mod: " + modName + " detecting version...");
                        string infoPath    = Path.Combine(d2mpDir, modName + "/addoninfo.txt");
                        string versionFile = "";
                        if (File.Exists(infoPath))
                        {
                            versionFile = File.ReadAllText(infoPath);
                        }
                        Match match = Regex.Match(versionFile, @"(addonversion)(\s+)(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)",
                                                  RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            string version = match.Groups.Cast <Group>()
                                             .ToList()
                                             .Skip(3)
                                             .Aggregate("", (current, part) => current + part.Value);
                            log.Debug(modName + "=" + version);
                            mods.Add(new ClientMod {
                                name = modName, version = version
                            });
                        }
                        else
                        {
                            log.Error("Can't find version info for mod: " + modName + ", not including");
                        }
                        i++;
                    }
                }

                //Detect user
                string          config  = File.ReadAllText(Path.Combine(steamDir, @"config\config.vdf"));
                MatchCollection matches = Regex.Matches(config, "\"\\d{17}\"");
                string          steamid;
                var             steamids = new List <string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path         = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter              = "d2mp.pid";
                watcher.Deleted            += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                shutDown = false;
                int tryCount = 0;
                while (tryCount < 240 && !shutDown)
                {
                    using (ws = new WebSocket(server))
                    {
                        ws.OnMessage += (sender, e) =>
                        {
                            log.Debug("server: " + e.Data);
                            JObject msg = JObject.Parse(e.Data);

                            switch (msg["msg"].Value <string>())
                            {
                            case Shutdown.Msg:
                                log.Debug("Shutting down due to server request.");
                                shutDown = true;
                                return;

                            case ClientCommon.Methods.Uninstall.Msg:
                                log.Debug("Uninstalling due to server request...");
                                Uninstall();
                                shutDown = true;
                                return;

                            case ClientCommon.Methods.InstallMod.Msg:
                                ThreadPool.QueueUserWorkItem(InstallMod, msg.ToObject <InstallMod>());
                                break;

                            case ClientCommon.Methods.DeleteMod.Msg:
                                ThreadPool.QueueUserWorkItem(DeleteMod, msg.ToObject <DeleteMod>());
                                break;

                            case ClientCommon.Methods.SetMod.Msg:
                                ThreadPool.QueueUserWorkItem(SetMod, msg.ToObject <SetMod>());
                                break;

                            case ClientCommon.Methods.ConnectDota.Msg:
                                ThreadPool.QueueUserWorkItem(ConnectDota, msg.ToObject <ConnectDota>());
                                break;

                            case ClientCommon.Methods.LaunchDota.Msg:
                                ThreadPool.QueueUserWorkItem(LaunchDota, msg.ToObject <LaunchDota>());
                                break;

                            case ClientCommon.Methods.ConnectDotaSpectate.Msg:
                                ThreadPool.QueueUserWorkItem(SpectateGame, msg.ToObject <ConnectDotaSpectate>());
                                break;

                            default:
                                log.Error("Command not recognized.");
                                break;
                            }
                        };

                        ws.OnOpen  += (sender, e) => log.Debug("Connected");
                        ws.OnClose += (sender, args) => log.Debug("Disconnected");
                        ws.Connect();
                        tryCount++;
                        if (!ws.IsAlive)
                        {
                            if (tryCount == 1)
                            {
                                icon.DisplayBubble("Disconnected, attempting to reconnect...");
                            }
                            log.Debug("Can't connect to server, tries: " + tryCount);
                            Thread.Sleep(500);
                            continue;
                        }

                        log.Debug("Sending init, version: " + ClientCommon.Version.ClientVersion);
                        var init = new Init {
                            SteamIDs = steamids.ToArray(), Version = ClientCommon.Version.ClientVersion, Mods = mods.ToArray()
                        };
                        var json = JObject.FromObject(init).ToString(Formatting.None);
                        ws.Send(json);

                        icon.DisplayBubble(tryCount > 1
                            ? "Reconnected!"
                            : "Connected and ready to begin installing mods.");

                        tryCount = 0;
                        while (ws.IsAlive && !shutDown)
                        {
                            Thread.Sleep(100);
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            Application.Exit();
        }
コード例 #5
0
        public static void main()
        {
            log.Debug("D2MP starting...");

            Application.ThreadException += (sender, args) => log.Error("Unhandled thread exception.", args.Exception);
            AppDomain.CurrentDomain.UnhandledException += (sender, args) => log.Error("Unhandled domain exception.", (Exception)args.ExceptionObject);

            var notifyThread = new Thread(delegate()
            {
                using (notifier = new notificationForm())
                {
                    notifier.Visible = true;
                    Application.Run();
                }
            });

            notifyThread.SetApartmentState(ApartmentState.STA);
            notifyThread.Start();
            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
            {
                using (icon = new ProcessIcon())
                {
                    icon.Display();
                    icon.showNotification = () => notifier.Invoke(new MethodInvoker(() => { notifier.Fade(1); notifier.hideTimer.Start(); }));
                    Application.Run();
                }
            });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            if (Settings.createShortcutAtStartup)
            {
                ShortcutWriter.writeDesktopShortcut();
            }

            try
            {
                var steam = new SteamFinder();
                if (!steam.checkProtocol())
                {
                    log.Error("Steam protocol not found. Trying to repair...");
                    var steamDir         = steam.FindSteam(true, false);
                    var steamservicePath = Path.Combine(steamDir, @"bin\steamservice.exe");
                    if (File.Exists(steamservicePath))
                    {
                        Process process = new Process()
                        {
                            StartInfo = { FileName = steamservicePath, Arguments = "/repair" }
                        };
                        try
                        {
                            process.Start();
                        }
                        catch
                        {
                            log.Fatal("Could not repair protocol. Steamservice couldn't run. Elevation refused?");
                        }
                        process.WaitForExit();
                        Restart();
                    }
                    else
                    {
                        log.Fatal("Could not repair protocol. Steam directory could not be found. Is steam installed? If so, please reinstall steam.");
                    }
                }
                if (!Directory.Exists(Settings.steamDir) || !Directory.Exists(Settings.dotaDir) || !SteamFinder.checkDotaDir(Settings.dotaDir))
                {
                    Settings.steamDir = steam.FindSteam(true);
                    Settings.dotaDir  = steam.FindDota(true);
                }

                if (Settings.steamDir == null || Settings.dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + Settings.steamDir);
                log.Debug("Dota found: " + Settings.dotaDir);

                addonsDir = Path.Combine(Settings.dotaDir, @"dota\addons\");
                d2mpDir   = Path.Combine(Settings.dotaDir, @"dota\d2moddin\");
                modDir    = Path.Combine(addonsDir, "d2moddin");

                if (!Directory.Exists(addonsDir))
                {
                    Directory.CreateDirectory(addonsDir);
                }
                else
                {
                    var contents = Directory.GetDirectories(addonsDir);
                    foreach (var dir in contents)
                    {
                        try
                        {
                            Directory.Delete(dir, true);
                        }
                        catch (Exception ex)
                        {
                            log.Error("Can't delete addon dir, " + dir, ex);
                        }
                    }
                }
                if (!Directory.Exists(d2mpDir))
                {
                    Directory.CreateDirectory(d2mpDir);
                }
                if (!Directory.Exists(modDir))
                {
                    Directory.CreateDirectory(modDir);
                }

                modController.getLocalMods();

                Dictionary <int, string> usersDict = steam.FindUsers();
                if (usersDict.Count > 0)
                {
                    steamids.AddRange(usersDict.OrderByDescending(x => x.Key).Select(m => m.Value));
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, PIDFile);
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path         = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter              = PIDFile;
                watcher.Deleted            += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                try
                {
                    SetupClient();
                    client.Open();
                }
                catch (Exception)
                {
                    notifier.Notify(NotificationType.Error, "Server error", "Can't connect to the lobby server!");
                    Wait(5);
                    HandleClose();
                }
                while (!shutDown)
                {
                    Thread.Sleep(100);
                }

                if (client != null && client.IsConnected)
                {
                    client.Close();
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            shutDown = true;
            Application.Exit();
        }
コード例 #6
0
        public static void main()
        {
            log.Debug("D2MP starting...");

            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var iconThread = new Thread(delegate()
            {
                using (icon = new ProcessIcon())
                {
                    icon.Display();
                    Application.Run();
                }
            });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var steam    = new SteamFinder();
                var steamDir = steam.FindSteam(true);
                dotaDir = steam.FindDota(true);
                if (steamDir == null || dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                else
                {
                    log.Debug("Steam found: " + steamDir);
                    log.Debug("Dota found: " + dotaDir);
                }

                addonsDir = Path.Combine(dotaDir, "dota/addons/");
                d2mpDir   = Path.Combine(dotaDir, "dota/d2moddin/");
                modDir    = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                {
                    Directory.CreateDirectory(addonsDir);
                }
                if (!Directory.Exists(d2mpDir))
                {
                    Directory.CreateDirectory(d2mpDir);
                }
                if (!Directory.Exists(modDir))
                {
                    Directory.CreateDirectory(modDir);
                }

                {
                    var dirs = Directory.GetDirectories(d2mpDir);
                    modNames = new string[dirs.Length];
                    int i = 0;
                    foreach (var dir in dirs)
                    {
                        var modName = Path.GetFileName(dir);
                        log.Debug("Found mod: " + modName + " detecting version...");
                        var    infoPath    = Path.Combine(d2mpDir, modName + "/addoninfo.txt");
                        string versionFile = "";
                        if (File.Exists(infoPath))
                        {
                            versionFile = File.ReadAllText(infoPath);
                        }
                        var match = Regex.Match(versionFile, @"(addonversion)(\s+)(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)",
                                                RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            string version = match.Groups.Cast <Group>()
                                             .ToList()
                                             .Skip(3)
                                             .Aggregate("", (current, part) => current + part.Value);
                            log.Debug(modName + "=" + version);
                            modNames[i] = modName + "=" + version;
                        }
                        else
                        {
                            log.Error("Can't find version info for mod: " + modName + ", not including");
                            modNames[i] = modName + "=?";
                        }
                        i++;
                    }
                }

                //Detect user
                var           config  = File.ReadAllText(Path.Combine(steamDir, @"config\config.vdf"));
                var           matches = Regex.Matches(config, "\"\\d{17}\"");
                string        steamid;
                List <string> steamids = new List <string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                FileSystemWatcher watcher = new FileSystemWatcher();
                watcher.Path         = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter   = "d2mp.pid";
                watcher.Deleted += (sender, args) =>
                {
                    shutDown = true;
                };
                watcher.EnableRaisingEvents = true;

                shutDown = false;
                int tryCount = 0;
                while (tryCount < 30 && !shutDown)
                {
                    using (ws = new WebSocket(server))
                    {
                        ws.OnMessage += (sender, e) =>
                        {
                            log.Debug("server: " + e.Data);
                            if (e.Data == "invalidid")
                            {
                                log.Debug("Invalid ID!");
                                shutDown = true;
                                return;
                            }

                            if (e.Data == "close")
                            {
                                log.Debug("Shutting down due to server request.");
                                shutDown = true;
                                return;
                            }

                            if (e.Data == "uninstall")
                            {
                                log.Debug("Uninstalling due to server request...");
                                Uninstall();
                                shutDown = true;
                                return;
                            }

                            var msgParts = e.Data.Split(':');
                            switch (msgParts[0])
                            {
                            case "installmod":
                                ThreadPool.QueueUserWorkItem(InstallMod, msgParts);
                                break;

                            case "deletemod":
                                ThreadPool.QueueUserWorkItem(DeleteMod, msgParts);
                                break;

                            case "setmod":
                                ThreadPool.QueueUserWorkItem(SetMod, msgParts);
                                break;

                            case "dconnect":
                                ThreadPool.QueueUserWorkItem(ConnectDota, msgParts);
                                break;

                            case "launchdota":
                                ThreadPool.QueueUserWorkItem(LaunchDota, msgParts);
                                break;

                            case "dspectate":
                                ThreadPool.QueueUserWorkItem(SpectateGame, msgParts);
                                break;

                            default:
                                log.Error("Command not recognized: " + msgParts[0]);
                                break;
                            }
                        };

                        ws.OnOpen  += (sender, e) => log.Debug("Connected");
                        ws.OnClose += (sender, args) => log.Debug("Disconnected");
                        ws.Connect();
                        tryCount++;
                        if (!ws.IsAlive)
                        {
                            if (tryCount == 1)
                            {
                                icon.DisplayBubble("Disconnected, attempting to reconnect...");
                            }
                            log.Debug("Can't connect to server, tries: " + tryCount);
                            Thread.Sleep(500);
                            continue;
                        }

                        if (tryCount > 1)
                        {
                            icon.DisplayBubble("Reconnected!");
                        }
                        else
                        {
                            icon.DisplayBubble("Connected and ready to begin installing mods.");
                        }

                        try
                        {
                            var ver =
                                File.ReadAllText(
                                    Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                                 "version.txt"));
                            log.Debug("sending version: " + ver);
                            ws.Send("init:" + String.Join(",", steamids.ToArray(), 0, steamids.Count) + ":" + ver +
                                    ":" + String.Join(",", modNames));
                        }
                        catch (Exception ex)
                        {
                            log.Debug("Can't detect ID from version.txt, : " + ex);
                            return;
                        }

                        tryCount = 0;
                        while (ws.IsAlive && !shutDown)
                        {
                            Thread.Sleep(100);
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            UnmodGameInfo();
            Application.Exit();
        }
コード例 #7
0
ファイル: D2MP.cs プロジェクト: shad0w19991/D2ModdinClient
        public static void main()
        {
            log.Debug("D2MP starting...");
            var notifyThread = new Thread(delegate() {
                using (notifier = new notificationForm())
                {
                    notifier.Visible = true;
                    Application.Run();
                }
            });

            notifyThread.SetApartmentState(ApartmentState.STA);
            notifyThread.Start();
            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
            {
                using (icon = new ProcessIcon())
                {
                    icon.Display();
                    icon.showNotification = delegate { notifier.Invoke(new MethodInvoker(delegate { notifier.Fade(1); notifier.hideTimer.Start(); })); };
                    Application.Run();
                }
            });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var steam = new SteamFinder();
                if (!Directory.Exists(Settings.steamDir) || !Directory.Exists(Settings.dotaDir))
                {
                    Settings.steamDir = steam.FindSteam(true);
                    Settings.dotaDir  = steam.FindDota(true);
                }

                if (Settings.steamDir == null || Settings.dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + Settings.steamDir);
                log.Debug("Dota found: " + Settings.dotaDir);

                addonsDir = Path.Combine(Settings.dotaDir, @"dota\addons\");
                d2mpDir   = Path.Combine(Settings.dotaDir, @"dota\d2moddin\");
                modDir    = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                {
                    Directory.CreateDirectory(addonsDir);
                }
                if (!Directory.Exists(d2mpDir))
                {
                    Directory.CreateDirectory(d2mpDir);
                }
                if (!Directory.Exists(modDir))
                {
                    Directory.CreateDirectory(modDir);
                }

                {
                    string[] dirs = Directory.GetDirectories(d2mpDir);
                    int      i    = 0;
                    foreach (string modName in dirs.Select(Path.GetFileName))
                    {
                        log.Debug("Found mod: " + modName + " detecting version...");
                        string infoPath    = Path.Combine(d2mpDir, modName + @"\addoninfo.txt");
                        string versionFile = "";
                        if (File.Exists(infoPath))
                        {
                            versionFile = File.ReadAllText(infoPath);
                        }
                        Match match = Regex.Match(versionFile, @"(addonversion)(\s+)(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)",
                                                  RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            string version = match.Groups.Cast <Group>()
                                             .ToList()
                                             .Skip(3)
                                             .Aggregate("", (current, part) => current + part.Value);
                            log.Debug(modName + "=" + version);
                            mods.Add(new ClientMod {
                                name = modName, version = version
                            });
                        }
                        else
                        {
                            log.Error("Can't find version info for mod: " + modName + ", not including");
                        }
                        i++;
                    }
                }

                //Detect user
                string          config  = File.ReadAllText(Path.Combine(Settings.steamDir, @"config\config.vdf"));
                MatchCollection matches = Regex.Matches(config, "\"\\d{17}\"");
                string          steamid;
                steamids = new List <string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path         = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter              = "d2mp.pid";
                watcher.Deleted            += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                try
                {
                    SetupClient();
                    client.Open();
                }
                catch (Exception ex)
                {
                    notifier.Notify(4, "Server error", "Can't connect to the lobby server!");
                    //icon.DisplayBubble("Can't connect to the lobby server!");
                }
                while (!shutDown)
                {
                    Thread.Sleep(100);
                }
                client.Close();
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            shutDown = true;
            Application.Exit();
        }
コード例 #8
0
ファイル: D2MP.cs プロジェクト: Beelzemon/D2ModdinClient
        public static void main()
        {
            log.Debug("D2MP starting...");

            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
                                        {
                                            using (icon = new ProcessIcon())
                                            {
                                                icon.Display();
                                                Application.Run();
                                            }
                                        });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var steam = new SteamFinder();
                string steamDir = steam.FindSteam(true);
                dotaDir = steam.FindDota(true);
                if (steamDir == null || dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + steamDir);
                log.Debug("Dota found: " + dotaDir);

                addonsDir = Path.Combine(dotaDir, "dota/addons/");
                d2mpDir = Path.Combine(dotaDir, "dota/d2moddin/");
                modDir = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                    Directory.CreateDirectory(addonsDir);
                if (!Directory.Exists(d2mpDir))
                    Directory.CreateDirectory(d2mpDir);
                if (!Directory.Exists(modDir))
                    Directory.CreateDirectory(modDir);

                {
                    string[] dirs = Directory.GetDirectories(d2mpDir);
                    int i = 0;
                    foreach (string dir in dirs)
                    {
                        string modName = Path.GetFileName(dir);
                        log.Debug("Found mod: " + modName + " detecting version...");
                        string infoPath = Path.Combine(d2mpDir, modName + "/addoninfo.txt");
                        string versionFile = "";
                        if (File.Exists(infoPath))
                        {
                            versionFile = File.ReadAllText(infoPath);
                        }
                        Match match = Regex.Match(versionFile, @"(addonversion)(\s+)(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)",
                            RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            string version = match.Groups.Cast<Group>()
                                .ToList()
                                .Skip(3)
                                .Aggregate("", (current, part) => current + part.Value);
                            log.Debug(modName + "=" + version);
                            mods.Add(new ClientMod {name = modName, version = version});
                        }
                        else
                        {
                            log.Error("Can't find version info for mod: " + modName + ", not including");
                        }
                        i++;
                    }
                }

                //Detect user
                string config = File.ReadAllText(Path.Combine(steamDir, @"config\config.vdf"));
                MatchCollection matches = Regex.Matches(config, "\"\\d{17}\"");
                string steamid;
                var steamids = new List<string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter = "d2mp.pid";
                watcher.Deleted += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                client = new XSocketClient(server, "*");
                bool hasConnected = false;
                client.OnOpen += (sender, args) =>
                {
                    icon.DisplayBubble(hasConnected
                        ? "Reconnected!"
                        : "Connected and ready to begin installing mods.");
                    hasConnected = true;

                    log.Debug("Sending init, version: " + ClientCommon.Version.ClientVersion);
                    var init = new Init
                    {
                        SteamIDs = steamids.ToArray(),
                        Version = ClientCommon.Version.ClientVersion,
                        Mods = mods.ToArray()
                    };
                    var json = JObject.FromObject(init).ToString(Formatting.None);
                    Send(json);
                };

                client.Bind("commands", e =>
                {
                    log.Debug("server: " + e.data);
                    JObject msg = JObject.Parse(e.data);
                    switch (msg["msg"].Value<string>())
                    {
                        case Shutdown.Msg:
                            log.Debug("Shutting down due to server request.");
                            shutDown = true;
                            return;
                        case ClientCommon.Methods.Uninstall.Msg:
                            log.Debug("Uninstalling due to server request...");
                            Uninstall();
                            shutDown = true;
                            return;
                        case ClientCommon.Methods.InstallMod.Msg:
                            ThreadPool.QueueUserWorkItem(InstallMod, msg.ToObject<InstallMod>());
                            break;
                        case ClientCommon.Methods.DeleteMod.Msg:
                            ThreadPool.QueueUserWorkItem(DeleteMod, msg.ToObject<DeleteMod>());
                            break;
                        case ClientCommon.Methods.SetMod.Msg:
                            ThreadPool.QueueUserWorkItem(SetMod, msg.ToObject<SetMod>());
                            break;
                        case ClientCommon.Methods.ConnectDota.Msg:
                            ThreadPool.QueueUserWorkItem(ConnectDota, msg.ToObject<ConnectDota>());
                            break;
                        case ClientCommon.Methods.LaunchDota.Msg:
                            ThreadPool.QueueUserWorkItem(LaunchDota, msg.ToObject<LaunchDota>());
                            break;
                        case ClientCommon.Methods.ConnectDotaSpectate.Msg:
                            ThreadPool.QueueUserWorkItem(SpectateGame,
                                msg.ToObject<ConnectDotaSpectate>());
                            break;
                        default:
                            log.Error("Command not recognized.");
                            break;
                    }
                });
                client.OnClose += (sender, args) =>
                                  {
                                      if (hasConnected)
                                      {
                                          icon.DisplayBubble("Disconnected, attempting to reconnect...");
                                          hasConnected = false;
                                      }
                                      try
                                      {
                                          client.Open();
                                      }
                                      catch (Exception ex)
                                      {
                                          icon.DisplayBubble("Can't connect to the lobby server!");
                                      }
                                  };
                try
                {
                    client.Open();
                }
                catch (Exception ex)
                {
                    icon.DisplayBubble("Can't connect to the lobby server!");
                }
                while (!shutDown)
                {
                    Thread.Sleep(100);
                }
                client.Close();
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            shutDown = true;
            Application.Exit();
        }
コード例 #9
0
        public static void main()
        {
            log.Debug("D2MP starting...");
            var notifyThread = new Thread(delegate()
            {
                using (notifier = new notificationForm())
                {
                    notifier.Visible = true;
                    Application.Run();
                }
            });

            notifyThread.SetApartmentState(ApartmentState.STA);
            notifyThread.Start();
            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
            {
                using (icon = new ProcessIcon())
                {
                    icon.Display();
                    icon.showNotification = delegate { notifier.Invoke(new MethodInvoker(delegate { notifier.Fade(1); notifier.hideTimer.Start(); })); };
                    Application.Run();
                }
            });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var steam = new SteamFinder();
                if (!Directory.Exists(Settings.steamDir) || !Directory.Exists(Settings.dotaDir))
                {
                    Settings.steamDir = steam.FindSteam(true);
                    Settings.dotaDir  = steam.FindDota(true);
                }

                if (Settings.steamDir == null || Settings.dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + Settings.steamDir);
                log.Debug("Dota found: " + Settings.dotaDir);

                addonsDir = Path.Combine(Settings.dotaDir, @"dota\addons\");
                d2mpDir   = Path.Combine(Settings.dotaDir, @"dota\d2moddin\");
                modDir    = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                {
                    Directory.CreateDirectory(addonsDir);
                }
                if (!Directory.Exists(d2mpDir))
                {
                    Directory.CreateDirectory(d2mpDir);
                }
                if (!Directory.Exists(modDir))
                {
                    Directory.CreateDirectory(modDir);
                }

                {
                    modController.getLocalMods();
                }

                //Detect user
                string          config  = File.ReadAllText(Path.Combine(Settings.steamDir, @"config\config.vdf"));
                MatchCollection matches = Regex.Matches(config, "\"\\d{17}\"");
                string          steamid;
                steamids = new List <string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path         = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter              = "d2mp.pid";
                watcher.Deleted            += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                try
                {
                    SetupClient();
                    client.Open();
                }
                catch (Exception ex)
                {
                    notifier.Notify(4, "Server error", "Can't connect to the lobby server!");
                    Thread.Sleep(5000);
                    HandleClose();
                }
                while (!shutDown)
                {
                    Thread.Sleep(100);
                }
                client.Close();
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            shutDown = true;
            Application.Exit();
        }