ResolvePath() public static method

Replace special character prefixes with full paths.
public static ResolvePath ( ) : string
return string
示例#1
0
        static void Initialize(Arguments args)
        {
            var supportDirArg = args.GetValue("Engine.SupportDir", null);

            if (supportDirArg != null)
            {
                Platform.OverrideSupportDir(supportDirArg);
            }

            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            // Load the engine version as early as possible so it can be written to exception logs
            try
            {
                EngineVersion = File.ReadAllText(Platform.ResolvePath(Path.Combine(".", "VERSION"))).Trim();
            }
            catch { }

            if (string.IsNullOrEmpty(EngineVersion))
            {
                EngineVersion = "Unknown";
            }

            Console.WriteLine("Engine version is {0}", EngineVersion);

            // Special case handling of Game.Mod argument: if it matches a real filesystem path
            // then we use this to override the mod search path, and replace it with the mod id
            var modID            = args.GetValue("Game.Mod", null);
            var explicitModPaths = new string[0];

            if (modID != null && (File.Exists(modID) || Directory.Exists(modID)))
            {
                explicitModPaths = new[] { modID };
                modID            = Path.GetFileNameWithoutExtension(modID);
            }

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("server", "server.log", true);
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("nat", "nat.log");

            var platforms = new[] { Settings.Game.Platform, "Default", null };

            foreach (var p in platforms)
            {
                if (p == null)
                {
                    throw new InvalidOperationException("Failed to initialize platform-integration library. Check graphics.log for details.");
                }

                Settings.Game.Platform = p;
                try
                {
                    var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + p + ".dll"));
                    var assembly     = Assembly.LoadFile(rendererPath);

                    var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));
                    if (platformType == null)
                    {
                        throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation.");
                    }

                    var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null);
                    Renderer = new Renderer(platform, Settings.Graphics);
                    Sound    = new Sound(platform, Settings.Sound);

                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Check graphics.log for details.");

                    if (Renderer != null)
                    {
                        Renderer.Dispose();
                    }

                    if (Sound != null)
                    {
                        Sound.Dispose();
                    }
                }
            }

            GeoIP.Initialize();

            if (Settings.Server.DiscoverNatDevices)
            {
                discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
            }

            var modSearchArg   = args.GetValue("Engine.ModSearchPaths", null);
            var modSearchPaths = modSearchArg != null?
                                 FieldLoader.GetValue <string[]>("Engine.ModsPath", modSearchArg) :
                                     new[] { Path.Combine(".", "mods") };

            Mods = new InstalledMods(modSearchPaths, explicitModPaths);
            Console.WriteLine("Internal mods:");
            foreach (var mod in Mods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
            }

            ExternalMods = new ExternalMods();

            Manifest currentMod;

            if (modID != null && Mods.TryGetValue(modID, out currentMod))
            {
                var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);

                // Sanitize input from platform-specific launchers
                // Process.Start requires paths to not be quoted, even if they contain spaces
                if (launchPath.First() == '"' && launchPath.Last() == '"')
                {
                    launchPath = launchPath.Substring(1, launchPath.Length - 2);
                }

                ExternalMods.Register(Mods[modID], launchPath, ModRegistration.User);

                ExternalMod activeMod;
                if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out activeMod))
                {
                    ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
                }
            }

            Console.WriteLine("External mods:");
            foreach (var mod in ExternalMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(modID, args);
        }
示例#2
0
文件: Manifest.cs 项目: wytsep/OpenRA
        public Manifest(string mod)
        {
            var path = Platform.ResolvePath(".", "mods", mod, "mod.yaml");
            var yaml = new MiniYaml(null, MiniYaml.FromFile(path)).ToDictionary();

            Mod    = FieldLoader.Load <ModMetadata>(yaml["Metadata"]);
            Mod.Id = mod;

            // TODO: Use fieldloader
            Folders        = YamlList(yaml, "Folders", true);
            MapFolders     = YamlDictionary(yaml, "MapFolders", true);
            Packages       = YamlDictionary(yaml, "Packages", true);
            Rules          = YamlList(yaml, "Rules", true);
            Sequences      = YamlList(yaml, "Sequences", true);
            VoxelSequences = YamlList(yaml, "VoxelSequences", true);
            Cursors        = YamlList(yaml, "Cursors", true);
            Chrome         = YamlList(yaml, "Chrome", true);
            Assemblies     = YamlList(yaml, "Assemblies", true);
            ChromeLayout   = YamlList(yaml, "ChromeLayout", true);
            Weapons        = YamlList(yaml, "Weapons", true);
            Voices         = YamlList(yaml, "Voices", true);
            Notifications  = YamlList(yaml, "Notifications", true);
            Music          = YamlList(yaml, "Music", true);
            Movies         = YamlList(yaml, "Movies", true);
            Translations   = YamlList(yaml, "Translations", true);
            TileSets       = YamlList(yaml, "TileSets", true);
            ChromeMetrics  = YamlList(yaml, "ChromeMetrics", true);
            Missions       = YamlList(yaml, "Missions", true);

            ServerTraits  = YamlList(yaml, "ServerTraits");
            LoadScreen    = yaml["LoadScreen"];
            LobbyDefaults = yaml["LobbyDefaults"];

            if (yaml.ContainsKey("ContentInstaller"))
            {
                ContentInstaller = FieldLoader.Load <InstallData>(yaml["ContentInstaller"]);
            }

            Fonts = yaml["Fonts"].ToDictionary(my =>
            {
                var nd = my.ToDictionary();
                return(Pair.New(nd["Font"].Value, Exts.ParseIntegerInvariant(nd["Size"].Value)));
            });

            if (yaml.ContainsKey("TileSize"))
            {
                TileSize = FieldLoader.GetValue <Size>("TileSize", yaml["TileSize"].Value);
            }

            if (yaml.ContainsKey("TileShape"))
            {
                TileShape = FieldLoader.GetValue <TileShape>("TileShape", yaml["TileShape"].Value);
            }

            if (yaml.ContainsKey("SubCells"))
            {
                var subcells = yaml["SubCells"].ToDictionary();

                // Read (x,y,z) offset (relative to cell center) pairs for positioning subcells
                if (subcells.ContainsKey("Offsets"))
                {
                    SubCellOffsets = FieldLoader.GetValue <WVec[]>("Offsets", subcells["Offsets"].Value);
                }

                if (subcells.ContainsKey("DefaultIndex"))
                {
                    SubCellDefaultIndex = FieldLoader.GetValue <int>("DefaultIndex", subcells["DefaultIndex"].Value);
                }
                else                    // Otherwise set the default subcell index to the middle subcell entry
                {
                    SubCellDefaultIndex = SubCellOffsets.Length / 2;
                }
            }

            // Validate default index - 0 for no subcells, otherwise > 1 & <= subcell count (offset triples count - 1)
            if (SubCellDefaultIndex < (SubCellOffsets.Length > 1 ? 1 : 0) || SubCellDefaultIndex >= SubCellOffsets.Length)
            {
                throw new InvalidDataException("Subcell default index must be a valid index into the offset triples and must be greater than 0 for mods with subcells");
            }

            // Allow inherited mods to import parent maps.
            var compat = new List <string>();

            compat.Add(mod);

            if (yaml.ContainsKey("SupportsMapsFrom"))
            {
                foreach (var c in yaml["SupportsMapsFrom"].Value.Split(','))
                {
                    compat.Add(c.Trim());
                }
            }

            MapCompatibility = compat.ToArray();

            if (yaml.ContainsKey("SpriteFormats"))
            {
                SpriteFormats = FieldLoader.GetValue <string[]>("SpriteFormats", yaml["SpriteFormats"].Value);
            }
        }
示例#3
0
 public static void InitializeSettings(Arguments args)
 {
     Settings = new Settings(Platform.ResolvePath(Path.Combine(Platform.SupportDirPrefix, "settings.yaml")), args);
 }
示例#4
0
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            // Special case handling of Game.Mod argument: if it matches a real filesystem path
            // then we use this to override the mod search path, and replace it with the mod id
            var modArgument      = args.GetValue("Game.Mod", null);
            var explicitModPaths = new string[0];

            if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument)))
            {
                explicitModPaths = new[] { modArgument };
                args.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument));
            }

            InitializeSettings(args);

            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");
            Log.AddChannel("irc", "irc.log");
            Log.AddChannel("nat", "nat.log");

            var platforms = new[] { Settings.Game.Platform, "Default", null };

            foreach (var p in platforms)
            {
                if (p == null)
                {
                    throw new InvalidOperationException("Failed to initialize platform-integration library. Check graphics.log for details.");
                }

                Settings.Game.Platform = p;
                try
                {
                    var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + p + ".dll"));
                    var assembly     = Assembly.LoadFile(rendererPath);

                    var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t));
                    if (platformType == null)
                    {
                        throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation.");
                    }

                    var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null);
                    Renderer = new Renderer(platform, Settings.Graphics);
                    Sound    = new Sound(platform, Settings.Sound);

                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Check graphics.log for details.");

                    if (Renderer != null)
                    {
                        Renderer.Dispose();
                    }

                    if (Sound != null)
                    {
                        Sound.Dispose();
                    }
                }
            }

            GeoIP.Initialize();

            if (!Settings.Server.DiscoverNatDevices)
            {
                Settings.Server.AllowPortForward = false;
            }
            else
            {
                discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
                Settings.Server.AllowPortForward = true;
            }

            GlobalChat = new GlobalChat();

            var modSearchArg   = args.GetValue("Engine.ModSearchPaths", null);
            var modSearchPaths = modSearchArg != null?
                                 FieldLoader.GetValue <string[]>("Engine.ModsPath", modSearchArg) :
                                     new[] { Path.Combine(".", "mods"), Path.Combine("^", "mods") };

            Mods = new InstalledMods(modSearchPaths, explicitModPaths);
            Console.WriteLine("Internal mods:");
            foreach (var mod in Mods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);
            }

            var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);

            ExternalMods = new ExternalMods(launchPath);
            Console.WriteLine("External mods:");
            foreach (var mod in ExternalMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(Settings.Game.Mod, args);
        }
示例#5
0
        public Manifest(string mod)
        {
            var path = Platform.ResolvePath(".", "mods", mod, "mod.yaml");

            yaml = new MiniYaml(null, MiniYaml.FromFile(path)).ToDictionary();

            Mod    = FieldLoader.Load <ModMetadata>(yaml["Metadata"]);
            Mod.Id = mod;

            // TODO: Use fieldloader
            Folders        = YamlList(yaml, "Folders", true);
            MapFolders     = YamlDictionary(yaml, "MapFolders", true);
            Packages       = YamlDictionary(yaml, "Packages", true);
            Rules          = YamlList(yaml, "Rules", true);
            Sequences      = YamlList(yaml, "Sequences", true);
            VoxelSequences = YamlList(yaml, "VoxelSequences", true);
            Cursors        = YamlList(yaml, "Cursors", true);
            Chrome         = YamlList(yaml, "Chrome", true);
            Assemblies     = YamlList(yaml, "Assemblies", true);
            ChromeLayout   = YamlList(yaml, "ChromeLayout", true);
            Weapons        = YamlList(yaml, "Weapons", true);
            Voices         = YamlList(yaml, "Voices", true);
            Notifications  = YamlList(yaml, "Notifications", true);
            Music          = YamlList(yaml, "Music", true);
            Translations   = YamlList(yaml, "Translations", true);
            TileSets       = YamlList(yaml, "TileSets", true);
            ChromeMetrics  = YamlList(yaml, "ChromeMetrics", true);
            Missions       = YamlList(yaml, "Missions", true);

            ServerTraits = YamlList(yaml, "ServerTraits");

            if (!yaml.TryGetValue("LoadScreen", out LoadScreen))
            {
                throw new InvalidDataException("`LoadScreen` section is not defined.");
            }

            if (!yaml.TryGetValue("LobbyDefaults", out LobbyDefaults))
            {
                throw new InvalidDataException("`LobbyDefaults` section is not defined.");
            }

            Fonts = yaml["Fonts"].ToDictionary(my =>
            {
                var nd = my.ToDictionary();
                return(Pair.New(nd["Font"].Value, Exts.ParseIntegerInvariant(nd["Size"].Value)));
            });

            RequiresMods = yaml["RequiresMods"].ToDictionary(my => my.Value);

            // Allow inherited mods to import parent maps.
            var compat = new List <string>();

            compat.Add(mod);

            if (yaml.ContainsKey("SupportsMapsFrom"))
            {
                foreach (var c in yaml["SupportsMapsFrom"].Value.Split(','))
                {
                    compat.Add(c.Trim());
                }
            }

            MapCompatibility = compat.ToArray();

            if (yaml.ContainsKey("SoundFormats"))
            {
                SoundFormats = FieldLoader.GetValue <string[]>("SoundFormats", yaml["SoundFormats"].Value);
            }

            if (yaml.ContainsKey("SpriteFormats"))
            {
                SpriteFormats = FieldLoader.GetValue <string[]>("SpriteFormats", yaml["SpriteFormats"].Value);
            }
        }
示例#6
0
 public bool IsInstalled()
 {
     return(TestFiles.All(file => File.Exists(Path.GetFullPath(Platform.ResolvePath(file)))));
 }
示例#7
0
        public static void InitializeMod(string mod, Arguments args)
        {
            // Clear static state if we have switched mods
            LobbyInfoChanged       = () => { };
            ConnectionStateChanged = om => { };
            BeforeGameStart        = () => { };
            OnRemoteDirectConnect  = endpoint => { };
            delayedActions         = new ActionQueue();

            Ui.ResetAll();

            worldRenderer?.Dispose();
            worldRenderer = null;
            server?.Shutdown();
            OrderManager?.Dispose();

            if (ModData != null)
            {
                ModData.ModFiles.UnmountAll();
                ModData.Dispose();
            }

            ModData = null;

            if (mod == null)
            {
                throw new InvalidOperationException("Game.Mod argument missing.");
            }

            if (!Mods.ContainsKey(mod))
            {
                throw new InvalidOperationException("Unknown or invalid mod '{0}'.".F(mod));
            }

            Console.WriteLine("Loading mod: {0}", mod);

            Sound.StopVideo();

            ModData = new ModData(Mods[mod], Mods, true);

            LocalPlayerProfile = new LocalPlayerProfile(Platform.ResolvePath(Path.Combine("^", Settings.Game.AuthProfile)), ModData.Manifest.Get <PlayerDatabase>());

            if (!ModData.LoadScreen.BeforeLoad())
            {
                return;
            }

            using (new PerfTimer("LoadMaps"))
                ModData.MapCache.LoadMaps();

            ModData.InitializeLoaders(ModData.DefaultFileSystem);
            Renderer.InitializeFonts(ModData);

            var grid = ModData.Manifest.Contains <MapGrid>() ? ModData.Manifest.Get <MapGrid>() : null;

            Renderer.InitializeDepthBuffer(grid);

            Cursor?.Dispose();

            Cursor = new CursorManager(ModData.CursorProvider);

            PerfHistory.Items["render"].HasNormalTick           = false;
            PerfHistory.Items["batches"].HasNormalTick          = false;
            PerfHistory.Items["render_world"].HasNormalTick     = false;
            PerfHistory.Items["render_widgets"].HasNormalTick   = false;
            PerfHistory.Items["render_flip"].HasNormalTick      = false;
            PerfHistory.Items["terrain_lighting"].HasNormalTick = false;

            JoinLocal();

            try
            {
                discoverNat?.Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine("NAT discovery failed: {0}", e.Message);
                Log.Write("nat", e.ToString());
            }

            ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor);
            ChromeMetrics.TryGet("SystemMessageColor", out systemMessageColor);

            ModData.LoadScreen.StartGame(args);
        }
示例#8
0
        public void LoadMaps()
        {
            // Utility mod that does not support maps
            if (!modData.Manifest.Contains <MapGrid>())
            {
                return;
            }

            // Enumerate map directories
            foreach (var kv in modData.Manifest.MapFolders)
            {
                var name           = kv.Key;
                var classification = string.IsNullOrEmpty(kv.Value)
                                        ? MapClassification.Unknown : Enum <MapClassification> .Parse(kv.Value);

                IReadOnlyPackage package;
                var optional = name.StartsWith("~", StringComparison.Ordinal);
                if (optional)
                {
                    name = name.Substring(1);
                }

                try
                {
                    // HACK: If the path is inside the the support directory then we may need to create it
                    if (Platform.IsPathRelativeToSupportDirectory(name))
                    {
                        // Assume that the path is a directory if there is not an existing file with the same name
                        var resolved = Platform.ResolvePath(name);
                        if (!File.Exists(resolved))
                        {
                            Directory.CreateDirectory(resolved);
                        }
                    }

                    package = modData.ModFiles.OpenPackage(name);
                }
                catch
                {
                    if (optional)
                    {
                        continue;
                    }

                    throw;
                }

                mapLocations.Add(package, classification);
            }

            var mapGrid = modData.Manifest.Get <MapGrid>();

            foreach (var kv in MapLocations)
            {
                foreach (var map in kv.Key.Contents)
                {
                    IReadOnlyPackage mapPackage = null;
                    try
                    {
                        using (new Support.PerfTimer(map))
                        {
                            mapPackage = kv.Key.OpenPackage(map, modData.ModFiles);
                            if (mapPackage == null)
                            {
                                continue;
                            }

                            string uid = "";
                            try
                            {
                                uid = Map.ComputeUID(mapPackage);
                            }
                            catch (Exception mapex)
                            {
                                throw;
                            }

                            previews[uid].UpdateFromMap(mapPackage, kv.Key, kv.Value, modData.Manifest.MapCompatibility, mapGrid.Type);
                        }
                    }
                    catch (Exception e)
                    {
                        if (mapPackage != null)
                        {
                            mapPackage.Dispose();
                        }
                        Console.WriteLine("Failed to load map: {0}", map);
                        Console.WriteLine("Details: {0}", e);
                        Log.Write("debug", "Failed to load map: {0}", map);
                        Log.Write("debug", "Details: {0}", e);
                    }
                }
            }
        }
示例#9
0
文件: Game.cs 项目: huwpascoe/OpenRA
        public static void InitializeMod(string mod, Arguments args)
        {
            // Clear static state if we have switched mods
            LobbyInfoChanged       = () => { };
            ConnectionStateChanged = om => { };
            BeforeGameStart        = () => { };
            OnRemoteDirectConnect  = (a, b) => { };
            delayedActions         = new ActionQueue();

            Ui.ResetAll();

            if (worldRenderer != null)
            {
                worldRenderer.Dispose();
            }
            worldRenderer = null;
            if (server != null)
            {
                server.Shutdown();
            }
            if (OrderManager != null)
            {
                OrderManager.Dispose();
            }

            if (ModData != null)
            {
                ModData.ModFiles.UnmountAll();
                ModData.Dispose();
            }

            ModData = null;

            // Fall back to default if the mod doesn't exist or has missing prerequisites.
            if (!ModMetadata.AllMods.ContainsKey(mod) || !IsModInstalled(mod))
            {
                mod = new GameSettings().Mod;
            }

            Console.WriteLine("Loading mod: {0}", mod);
            Settings.Game.Mod = mod;

            Sound.StopVideo();

            ModData = new ModData(mod, !Settings.Server.Dedicated);

            Sound.Initialize();

            using (new PerfTimer("LoadMaps"))
                ModData.MapCache.LoadMaps();

            if (Settings.Server.Dedicated)
            {
                RunDedicatedServer();
                Environment.Exit(0);
            }

            var installData           = ModData.Manifest.Get <ContentInstaller>();
            var isModContentInstalled = installData.TestFiles.All(f => File.Exists(Platform.ResolvePath(f)));

            // Mod assets are missing!
            if (!isModContentInstalled)
            {
                InitializeMod("modchooser", new Arguments());
                return;
            }

            ModData.MountFiles();
            ModData.InitializeLoaders();
            Renderer.InitializeFonts(ModData.Manifest);

            if (Cursor != null)
            {
                Cursor.Dispose();
            }

            if (Settings.Graphics.HardwareCursors)
            {
                try
                {
                    Cursor = new HardwareCursor(ModData.CursorProvider);
                }
                catch (Exception e)
                {
                    Log.Write("debug", "Failed to initialize hardware cursors. Falling back to software cursors.");
                    Log.Write("debug", "Error was: " + e.Message);

                    Console.WriteLine("Failed to initialize hardware cursors. Falling back to software cursors.");
                    Console.WriteLine("Error was: " + e.Message);

                    Cursor = new SoftwareCursor(ModData.CursorProvider);
                }
            }
            else
            {
                Cursor = new SoftwareCursor(ModData.CursorProvider);
            }

            PerfHistory.Items["render"].HasNormalTick         = false;
            PerfHistory.Items["batches"].HasNormalTick        = false;
            PerfHistory.Items["render_widgets"].HasNormalTick = false;
            PerfHistory.Items["render_flip"].HasNormalTick    = false;

            JoinLocal();

            ModData.LoadScreen.StartGame(args);
        }
示例#10
0
文件: Game.cs 项目: huwpascoe/OpenRA
 public static void InitializeSettings(Arguments args)
 {
     Settings = new Settings(Platform.ResolvePath("^", "settings.yaml"), args);
 }
示例#11
0
文件: Game.cs 项目: wytsep/OpenRA
        internal static void Initialize(Arguments args)
        {
            Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);

            AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly;

            Settings = new Settings(Platform.ResolvePath("^", "settings.yaml"), args);

            Log.LogPath = Platform.ResolvePath("^", "Logs");
            Log.AddChannel("perf", "perf.log");
            Log.AddChannel("debug", "debug.log");
            Log.AddChannel("sync", "syncreport.log");
            Log.AddChannel("server", "server.log");
            Log.AddChannel("sound", "sound.log");
            Log.AddChannel("graphics", "graphics.log");
            Log.AddChannel("geoip", "geoip.log");

            if (Settings.Server.DiscoverNatDevices)
            {
                UPnP.TryNatDiscovery();
            }
            else
            {
                Settings.Server.NatDeviceAvailable = false;
                Settings.Server.AllowPortForward   = false;
            }

            try
            {
                GeoIpDatabase = new DatabaseReader("GeoLite2-Country.mmdb");
            }
            catch (Exception e)
            {
                Log.Write("geoip", "DatabaseReader failed: {0}", e);
            }

            GlobalFileSystem.Mount(Platform.GameDir);             // Needed to access shaders
            var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", null };

            foreach (var r in renderers)
            {
                if (r == null)
                {
                    throw new InvalidOperationException("No suitable renderers were found. Check graphics.log for details.");
                }

                Settings.Graphics.Renderer = r;
                try
                {
                    Renderer.Initialize(Settings.Graphics.Mode);
                    break;
                }
                catch (Exception e)
                {
                    Log.Write("graphics", "{0}", e);
                    Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details.");
                }
            }

            Renderer = new Renderer();

            try
            {
                Sound.Create(Settings.Sound.Engine);
            }
            catch (Exception e)
            {
                Log.Write("sound", "{0}", e);
                Console.WriteLine("Creating the sound engine failed. Fallback in place. Check sound.log for details.");
                Settings.Sound.Engine = "Null";
                Sound.Create(Settings.Sound.Engine);
            }

            Console.WriteLine("Available mods:");
            foreach (var mod in ModMetadata.AllMods)
            {
                Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
            }

            InitializeMod(Settings.Game.Mod, args);

            if (Settings.Server.DiscoverNatDevices)
            {
                RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.StoppingNatDiscovery);
            }
        }
示例#12
0
        public Sound(string engineName)
        {
            var enginePath = Platform.ResolvePath(".", "OpenRA.Platforms." + engineName + ".dll");

            soundEngine = CreateDevice(Assembly.LoadFile(enginePath));
        }