コード例 #1
0
        /// <summary>
        /// Automatically works out available config control options from mednafen.cfg
        /// </summary>
        /// <param name="maps"></param>
        public static void ParseOptionsFromConfig(DeviceDefinition dd)
        {
            dd.MapList = new List <Mapping>();

            // step through every line
            for (int i = 0; i < dd.ConfigList.Length; i++)
            {
                if (dd.ConfigList[i].TrimStart().StartsWith((dd.CommandStart + "." + dd.ControllerName + ".").Replace("..", ".")))
                {
                    // ignore these
                    if (dd.ConfigList[i].ToLower().Contains("default position for"))
                    {
                        continue;
                    }

                    if (dd.ConfigList[i].ToLower().Contains(" axis scale coefficient for "))
                    {
                        continue;
                    }

                    // this line is needed
                    Mapping map = new Mapping();

                    string[] arr = dd.ConfigList[i].Split(' ');
                    if (arr.Length < 1)
                    {
                        continue;
                    }

                    map.MednafenCommand = arr[0];

                    // now get description from previous line
                    string prev = dd.ConfigList[i - 1];

                    // ignore these
                    if (prev.ToLower().Contains("default position for"))
                    {
                        continue;
                    }

                    if (prev.ToLower().Contains(" axis scale coefficient for "))
                    {
                        continue;
                    }

                    string[] descSplit = prev.Split(new string[] { ", " }, StringSplitOptions.None);

                    if (map.MednafenCommand.StartsWith("command"))
                    {
                        // this is a command binding - take whole description without the leading ;
                        map.Description = prev.TrimStart(';');
                    }
                    else
                    {
                        // non command binding
                        if (descSplit.Length < 1)
                        {
                            map.Description = prev;
                        }
                        else if (descSplit.Length > 2)
                        {
                            string res = string.Empty;
                            for (int s = 1; s < descSplit.Length; s++)
                            {
                                res += descSplit[s];
                                if (s != descSplit.Length - 1)
                                {
                                    res += ", ";
                                }
                            }
                            map.Description = res;
                        }
                        else
                        {
                            string last = descSplit.Last();
                            map.Description = last;
                        }

                        // attempt to remove the beginning nonsense
                        string[] n = map.Description.Split(new string[] { ": " }, StringSplitOptions.None);
                        if (n.Length < 2)
                        {
                            map.Description = map.Description;
                        }
                        else
                        {
                            map.Description = n.Last();
                        }
                    }


                    // add to maplist
                    dd.MapList.Add(map);
                }
            }

            dd.PerformOrdering();
            //dd.MapList = dd.MapList.OrderBy(a => a.Description).ToList();
        }