示例#1
0
        public static ResultCode Load(ProgressHandler handler)
        {
            currentProgressHandler = handler;
            string gameConfigPath = Configuration.GetPath("GameConfigurations");

            if (gameConfigPath == "")
            {
                Error       = ErrorCode.MALFORMED_CONFIGURATION;
                ErrorString = "Couldn't find the game configurations path.";
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
                return(ResultCode.ERROR);
            }

            string gameConfigFile = Path.GetFullPath(gameConfigPath + Path.DirectorySeparatorChar + Configuration.CurrentGame + Path.DirectorySeparatorChar + "GUI.xml");

            if (!File.Exists(gameConfigFile))
            {
                Error       = ErrorCode.FILE_NOT_FOUND;
                ErrorString = "Couldn't find the file \"" + gameConfigFile + "\".";
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
                return(ResultCode.ERROR);
            }

            Debug.Log("GUIConfiguration", "Parsing the GUI configuration file \"" + gameConfigFile + "\".");
            try
            {
                XDocument configuration = XDocument.Load(gameConfigFile);
                Tabs = new List <Tab>();
                if (!ParseTabs(configuration.Root))
                {
                    Error       = ErrorCode.MALFORMED_CONFIGURATION;
                    ErrorString = "The configuration file \"" + gameConfigFile + "\" contains invalid elements.";
                    Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
                    return(ResultCode.ERROR);
                }
            }
            catch (System.Xml.XmlException ex)
            {
                Error       = ErrorCode.MALFORMED_CONFIGURATION;
                ErrorString = "The file \"" + gameConfigFile + "\" couldn't be parsed. Exception: " + ex.ToString();
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
                return(ResultCode.ERROR);
            }
            catch (Exception ex)
            {
                Error       = ErrorCode.MALFORMED_CONFIGURATION;
                ErrorString = "The file \"" + gameConfigFile + "\" couldn't be parsed. Unexpected exception: " + ex.ToString();
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
                return(ResultCode.ERROR);
            }
            Debug.Log("GUIConfiguration", "Successfully parsed the GUI configuration.");
            ChangeProgress(100f);
            return(ResultCode.OK);
        }
示例#2
0
        public static ResultCode Load(ProgressHandler handler)
        {
            CurrentProgressHandler = handler;
            var gameConfigPath = Configuration.GetPath("GameConfigurations");

            if (gameConfigPath == "")
            {
                Error       = ErrorCode.MalformedConfiguration;
                ErrorString = "Couldn't find the game configurations path.";
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.Error);
                return(ResultCode.ERROR);
            }

            var gameConfigFile = Path.GetFullPath(gameConfigPath + Path.DirectorySeparatorChar + Configuration.CurrentGame + Path.DirectorySeparatorChar + "GUI.xml");

            if (!File.Exists(gameConfigFile))
            {
                Error       = ErrorCode.FileNotFound;
                ErrorString = "Couldn't find the file \"" + gameConfigFile + "\".";
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.Error);
                return(ResultCode.ERROR);
            }

            Debug.Log("GUIConfiguration", "Parsing the GUI configuration file \"" + gameConfigFile + "\".");
            try
            {
                var configuration = XDocument.Load(gameConfigFile);
                Tabs = new List <Tab>();
                if (!ParseTabs(configuration.Root))
                {
                    Error       = ErrorCode.MalformedConfiguration;
                    ErrorString = "The configuration file \"" + gameConfigFile + "\" contains invalid elements.";
                    Debug.Log("GUIConfiguration", ErrorString, Debug.Type.Error);
                    return(ResultCode.ERROR);
                }
            }
            catch (XmlException ex)
            {
                Error       = ErrorCode.MalformedConfiguration;
                ErrorString = "The file \"" + gameConfigFile + "\" couldn't be parsed. Exception: " + ex;
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.Error);
                return(ResultCode.ERROR);
            }
            catch (Exception ex)
            {
                Error       = ErrorCode.MalformedConfiguration;
                ErrorString = "The file \"" + gameConfigFile + "\" couldn't be parsed. Unexpected exception: " + ex;
                Debug.Log("GUIConfiguration", ErrorString, Debug.Type.Error);
                return(ResultCode.ERROR);
            }
            Debug.Log("GUIConfiguration", "Successfully parsed the GUI configuration.");
            ChangeProgress(100f);
            return(ResultCode.Ok);
        }