SphereStudio.Project.FromSgm C# (CSharp) Method

FromSgm() public static method

Creates a new Sphere Studio project from a Sphere 1.x game.sgm file.
public static FromSgm ( string fileName ) : Project
fileName string The fully qualified filename of the game.sgm to import.
return Project
        public static Project FromSgm(string fileName)
        {
            if (!File.Exists(fileName))
                throw new FileNotFoundException();

            var rootPath = Path.GetDirectoryName(fileName);
            Project project = new Project(Path.Combine(rootPath, "game.ssproj"))
            {
                BackCompatible = true,
                Name = "Untitled",
                Author = "Author Unknown",
                Summary = "",
                ScreenWidth = 320,
                ScreenHeight = 240,
                MainScript = "main.js",
            };

            string[] sgmText = File.ReadAllLines(fileName);
            foreach (string line in sgmText)
            {
                try
                {
                    Match match = new Regex("(.+)=(.*)").Match(line);
                    if (match.Success)
                    {
                        string key = match.Groups[1].Value;
                        string value = match.Groups[2].Value;
                        switch (key)
                        {
                            case "name": project.Name = value; break;
                            case "author": project.Author = value; break;
                            case "description": project.Summary = value; break;
                            case "script": project.MainScript = value; break;
                            case "screen_width": project.ScreenWidth = int.Parse(value); break;
                            case "screen_height": project.ScreenHeight = int.Parse(value); break;
                        }
                    }
                }
                catch
                {
                    // ignore any parsing errors. if an error occurs parsing the manifest,
                    // we'll just use the default values. this ensures it is always possible
                    // to upgrade a Sphere 1.x project even if the game.sgm is damaged.
                }
            }

            project.FileName = Path.Combine(rootPath, MakeFileName(project.Name));
            project.Compiler = "Vanilla";
            project.User.Engine = "Sphere 1.x";
            return project;
        }