示例#1
0
        public static Configuration Read(Stream source)
        {
            try
            {
                StreamReader reader = new StreamReader(source);
                Encoding enc = Encoding.Unicode;
                Configuration result = new Configuration(enc);
                InfoCollection currentKey = null;
                string currentKeyName = "";

                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim();
                    if (line.StartsWith("[") && line.EndsWith("]"))
                    {
                        if (line.Length > 2)
                        {
                            currentKey = new InfoCollection();
                            currentKeyName = line.Substring(1, line.Length - 2);
                            result[currentKeyName] = currentKey;
                        }
                        else
                        {
                            currentKey = null;
                            currentKeyName = "";
                        }
                    }
                    else if (currentKey != null && line.Contains("="))
                    {
                        string keyTag = line.Substring(0, line.IndexOf("=")).Trim().ToUpper();
                        string keyValue = line.Substring(line.IndexOf("=") + 1).Trim();
                        currentKey[keyTag] = keyValue;
                    }
                    else if (line.Length > 0)
                    {
                        currentKey[line] = "";
                    }
                }

                return result;
            }
            catch
            {
                return new Configuration(Encoding.Unicode);
            }
        }
示例#2
0
        public static void ConvertChart(Chart chart, Configuration config, string filename, int index, int[] map)
        {
            if (config == null)
            {
                config = LoadConfig();
            }

            int quantizeNotes = config["BMS"].GetValue("QuantizeNotes");
            int quantizeMeasure = config["BMS"].GetValue("QuantizeMeasure");
            int difficulty = config["IIDX"].GetValue("Difficulty" + index.ToString());
            string title = config["BMS"]["Players" + config["IIDX"]["Players" + index.ToString()]] + " " + config["BMS"]["Difficulty" + difficulty.ToString()];
            title = title.Trim();

            if (quantizeMeasure > 0)
                chart.QuantizeMeasureLengths(quantizeMeasure);

            using (MemoryStream mem = new MemoryStream())
            {
                BMS bms = new BMS();
                bms.Charts = new Chart[] { chart };

                string name = "";
                if (chart.Tags.ContainsKey("TITLE"))
                    name = chart.Tags["TITLE"];
                if (name == "")
                    name = Path.GetFileNameWithoutExtension(Path.GetFileName(filename)); //ex: "1204 [1P Another]"

                // write some tags
                bms.Charts[0].Tags["TITLE"] = name;
                if (chart.Tags.ContainsKey("ARTIST"))
                    bms.Charts[0].Tags["ARTIST"] = chart.Tags["ARTIST"];
                if (chart.Tags.ContainsKey("GENRE"))
                    bms.Charts[0].Tags["GENRE"] = chart.Tags["GENRE"];

                if (difficulty > 0)
                    bms.Charts[0].Tags["DIFFICULTY"] = difficulty.ToString();

                if (bms.Charts[0].Players > 1)
                    bms.Charts[0].Tags["PLAYER"] = "3";
                else
                    bms.Charts[0].Tags["PLAYER"] = "1";

                name = name.Replace(":", "_");
                name = name.Replace("/", "_");
                name = name.Replace("?", "_");
                name = name.Replace("\\", "_");

                if (title != null && title.Length > 0)
                {
                    name += " [" + title + "]";
                }

                string output = Path.Combine(Path.GetDirectoryName(filename), @"@" + name + ".bms");

                if (map == null)
                    bms.GenerateSampleMap();
                else
                    bms.SampleMap = map;

                if (quantizeNotes > 0)
                    bms.Charts[0].QuantizeNoteOffsets(quantizeNotes);
                bms.GenerateSampleTags();
                bms.Write(mem, true);

                File.WriteAllBytes(output, mem.ToArray());
            }
        }
示例#3
0
 public static void ConvertArchive(Archive archive, Configuration config, string filename)
 {
     for (int j = 0; j < archive.ChartCount; j++)
     {
         if (archive.Charts[j] != null)
         {
             Console.WriteLine("Converting Chart " + j.ToString());
             ConvertChart(archive.Charts[j], config, filename, j, null);
         }
     }
 }