Ejemplo n.º 1
0
        /// <summary>
        /// Implement Get().
        /// </summary>
        /// <param name="binder">Binder to apply bindings to.</param>
        /// <returns>True on success.</returns>
        private bool Load(IBinder binder)
        {
            if (binder == null)
            {
                Debug.LogError($"{name} has no binder set");
                return(false);
            }
            string fullPath = GetFullPath();

            if (!File.Exists(fullPath))
            {
                Debug.LogError($"{name} can't find file {fullPath}");
                return(false);
            }
            using (FileStream fileStream = new FileStream(GetFullPath(), FileMode.Open, FileAccess.Read))
            {
                using (StreamReader reader = new StreamReader(fileStream))
                {
                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        string binderName      = line.Replace(binderKey, "");
                        bool   isCorrectBinder = binderName == binder.Name;
                        Tools.SimpleConsole.AddLine(8, $"Got:{binderName}, Want:{binder.Name}, Math={isCorrectBinder}");
                        char[] separators = new char[] { ' ', ',' };
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (line.StartsWith(binderKey))
                            {
                                break;
                            }
                            if (isCorrectBinder)
                            {
                                string[] tokens = line.Split(separators, System.StringSplitOptions.RemoveEmptyEntries);
                                binder.CreateBinding(tokens[0], tokens[1]);
                            }
                        }
                    }
                }
            }
            return(true);
        }