Ejemplo n.º 1
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 = () => 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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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();
        }