OpenRA.Platform.GetSupportDir C# (CSharp) Method

GetSupportDir() static private method

static private GetSupportDir ( ) : string
return string
        static string GetSupportDir()
        {
            // Use a local directory in the game root if it exists
            if (Directory.Exists("Support"))
                return "Support" + Path.DirectorySeparatorChar;

            var dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            switch (CurrentPlatform)
            {
                case PlatformType.Windows:
                    dir += Path.DirectorySeparatorChar + "OpenRA";
                    break;
                case PlatformType.OSX:
                    dir += "/Library/Application Support/OpenRA";
                    break;
                default:
                    dir += "/.openra";
                    break;
            }

            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            return dir + Path.DirectorySeparatorChar;
        }

Usage Example

Example #1
0
        public ExternalMods()
        {
            sheetBuilder = new SheetBuilder(SheetType.BGRA, 256);

            // Several types of support directory types are available, depending on
            // how the player has installed and launched the game.
            // Read registration metadata from all of them
            var sources = Enum.GetValues(typeof(SupportDirType))
                          .Cast <SupportDirType>()
                          .Select(t => Platform.GetSupportDir(t))
                          .Distinct();

            foreach (var source in sources)
            {
                var metadataPath = Path.Combine(source, "ModMetadata");
                if (!Directory.Exists(metadataPath))
                {
                    continue;
                }

                foreach (var path in Directory.GetFiles(metadataPath, "*.yaml"))
                {
                    try
                    {
                        var yaml = MiniYaml.FromStream(File.OpenRead(path), path).First().Value;
                        LoadMod(yaml, path);
                    }
                    catch (Exception e)
                    {
                        Log.Write("debug", "Failed to parse mod metadata file '{0}'", path);
                        Log.Write("debug", e.ToString());
                    }
                }
            }
        }
All Usage Examples Of OpenRA.Platform::GetSupportDir