Beispiel #1
0
        public void LoadImageFromKsh()
        {
            string[]   kshFiles = Directory.GetFiles(data["kshFolder"], "*.ksh");
            FileStream fs       = new FileStream(kshFiles[0], FileMode.Open);

            (Dictionary <string, string> kshInfoParse, List <string> _) = ParseKshInfo(fs);

            fs.Close();

            string imagePath = data["kshFolder"] + "\\" + kshInfoParse["jacket"];

            image = new KshImage(imagePath);
        }
Beispiel #2
0
        // From K-Shoot
        public Song(string label,
                    string kshPath,
                    int specificVer = 0)
        {
            // ogg mp3 wav

            if (!Directory.Exists(kshPath))
            {
                throw new DirectoryNotFoundException();
            }

            string[] kshFiles = Directory.GetFiles(kshPath, "*.ksh");

            if (kshFiles.Length == 0)
            {
                throw new Exception("No .ksh found in this folder!");
            }

            // Parsing the first file for song infos.
            FileStream fs = new FileStream(kshFiles[0], FileMode.Open);

            (Dictionary <string, string> kshInfoParse, List <string> _) = ParseKshInfo(fs);
            fs.Close();

            data["label"]           = label;
            data["title_name"]      = kshInfoParse["title"];
            data["title_yomigana"]  = "";
            data["artist_name"]     = kshInfoParse["artist"];
            data["artist_yomigana"] = "";
            string[] asciiInfo = { data["title_name"], data["artist_name"] };
            data["ascii"] = MakeAscii(asciiInfo);

            string[] bpms = kshInfoParse["t"].Split('-');
            if (bpms.Length == 1)
            {
                data["bpm_max"] = string.Format("{0:0}", (Convert.ToDouble(bpms[0]) * 100.0));
                data["bpm_min"] = string.Format("{0:0}", (Convert.ToDouble(bpms[0]) * 100.0));
            }
            else if (bpms.Length == 2)
            {
                data["bpm_max"] = string.Format("{0:0}", (Convert.ToDouble(bpms[1]) * 100.0));
                data["bpm_min"] = string.Format("{0:0}", (Convert.ToDouble(bpms[0]) * 100.0));
            }
            else
            {
                throw new Exception("Ksh bpm format error!");
            }

            data["distribution_date"] = "22222222";
            data["volume"]            = "100";
            data["bg_no"]             = "0";
            data["genre"]             = "16";
            data["is_fixed"]          = "1";
            if (specificVer == 0)
            {
                data["version"] = "3";
            }
            else
            {
                data["version"] = specificVer.ToString();
            }
            data["demo_pri"] = "-2";
            data["inf_ver"]  = "3";

            // Indicates that this is a custom simfile
            data["custom"] = "1";

            // Caching imformation
            data["kshFolder"]     = kshPath;
            data["lastModFolder"] = Directory.GetLastWriteTime(kshPath).ToString();

            // Parsing for Charts
            foreach (string kshFile in kshFiles)
            {
                // Detect if some object is in 1st Measure (Shift with +1 measure)
                FileStream fs1 = new FileStream(kshFile, FileMode.Open);
                (Dictionary <string, string> kshCheckParse, List <string> chartCheck) = ParseKshInfo(fs1);
                fs1.Close();

                Chart checkVoxChart = new Chart(chartCheck, kshCheckParse["t"], false);

                bool shift = checkVoxChart.SomethingIsInFirstMeasure();

                double offset = checkVoxChart.FirstMesureLength();

                FileStream fs2 = new FileStream(kshFile, FileMode.Open);
                (Dictionary <string, string> kshParse, List <string> chart) = ParseKshInfo(fs2);
                fs2.Close();

                int id = 0;
                if (kshParse["difficulty"] == "light")
                {
                    id = 0;
                }
                else if (kshParse["difficulty"] == "challenge")
                {
                    id = 1;
                }
                else if (kshParse["difficulty"] == "extended")
                {
                    id = 2;
                }
                else if (kshParse["difficulty"] == "infinite")
                {
                    id = 3;
                }
                else
                {
                    new Exception("Invalid dif num in .ksh!");
                }

                charts          [SongList.DIFS[id]] = new Chart(chart, kshParse["t"], shift);

                chartData   [SongList.DIFS[id]]                = new Dictionary <string, string>();
                chartData   [SongList.DIFS[id]]["difnum"]      = kshParse["level"];
                chartData   [SongList.DIFS[id]]["illustrator"] = kshParse["illustrator"];
                chartData   [SongList.DIFS[id]]["effected_by"] = kshParse["effect"];
                chartData   [SongList.DIFS[id]]["price"]       = "-1";
                chartData   [SongList.DIFS[id]]["limited"]     = "3";

                // Parsing for wav

                string soundPath = kshPath + "\\" + kshParse["m"].Split(';').ElementAt <string>(0);

                if (!soundCaches.ContainsKey(soundPath))
                {
                    string ext = Path.GetExtension(soundPath);
                    if (!((ext == ".mp3") || (ext == ".ogg") || (ext == ".wav")))
                    {
                        throw new Exception("Music file format " + ext + " invalid!");
                    }

                    string outSoundPath = Util.cachePath + BaseName() + Suffix(SongList.DIFS[id]) + ".wav";
                    string preSoundPath = Util.cachePath + BaseName() + Suffix(SongList.DIFS[id]) + "_p.wav";

                    string oriSoundPath = soundPath;

                    // SOX BUG: the mp3 to wav conversion seems to ignore the implicit offset in mp3.
                    // so here we do a conversion first with
                    if (ext == ".mp3")
                    {
                        using (Mp3FileReader mp3 = new Mp3FileReader(soundPath))
                        {
                            using (WaveStream pcm = WaveFormatConversionStream.CreatePcmStream(mp3))
                            {
                                FileInfo mp3Path = new FileInfo(soundPath);
                                string   mp3Name = mp3Path.Name;

                                string tempPath = Util.cachePath + Util.RandomString(10) + "\\";
                                Directory.CreateDirectory(tempPath);
                                string wavPath = tempPath + mp3Name.Substring(0, mp3Name.Length - 4) + ".wav";
                                if (File.Exists(wavPath))
                                {
                                    File.Delete(wavPath);
                                }
                                WaveFileWriter.CreateWaveFile(wavPath, pcm);

                                soundPath = wavPath;
                            }
                        }
                    }

                    if (shift)
                    {
                        ConvertAndTrimToWav(soundPath, outSoundPath, int.Parse(kshParse["o"]) - Convert.ToInt32(offset * 1000), -1);
                    }
                    else
                    {
                        ConvertAndTrimToWav(soundPath, outSoundPath, int.Parse(kshParse["o"]), -1);
                    }

                    if (soundCaches.Count == 0)
                    {
                        soundCaches.Add(oriSoundPath, new Tuple <string, string>(outSoundPath, ""));
                    }
                    else
                    {
                        soundCaches.Add(oriSoundPath, new Tuple <string, string>(outSoundPath, Suffix(SongList.DIFS[id])));
                    }

                    // Preview sound

                    ConvertAndTrimToWav(soundPath, preSoundPath, int.Parse(kshParse["po"]), int.Parse(kshParse["plength"]));

                    // Fix ms-adpcm BlockSize mismatch, and fade in/out effect for the sample music

                    Fade(preSoundPath);
                    WavBlockSizeFix(preSoundPath);

                    if (preSoundCaches.Count == 0)
                    {
                        preSoundCaches.Add(oriSoundPath, new Tuple <string, string>(preSoundPath, ""));
                    }
                    else
                    {
                        preSoundCaches.Add(oriSoundPath, new Tuple <string, string>(preSoundPath, Suffix(SongList.DIFS[id])));
                    }
                }

                // Parsing for Image

                string imagePath = kshPath + "\\" + kshParse["jacket"];

                // ONLY supporting one jacket now!

                image = new KshImage(imagePath);

                /*
                 * if (!images.ContainsKey(imagePath))
                 * {
                 *  string ext = Path.GetExtension(imagePath);
                 *  if (!((ext == ".bmp") || (ext == ".jpg") || (ext == ".png")))
                 *      throw new Exception("Image file format " + ext + " invalid!");
                 *
                 *  if (images.Count == 0)
                 *  {
                 *      string imageName = "jk_" + BaseNameNum();
                 *      images.Add(imagePath, new Tuple<Image, string>(new Image(imagePath, imageName), "_1"));
                 *  }
                 *  else
                 *      images.Add(imagePath, new Tuple<Image, string>(new Image(imagePath), "_" + id.ToString()));
                 *
                 * }
                 */
            }

            // Fill in empty data for chartdata
            foreach (string dif in SongList.DIFS)
            {
                if (!chartData.ContainsKey(dif))
                {
                    chartData[dif]                = new Dictionary <string, string>();
                    chartData[dif]["difnum"]      = "0";
                    chartData[dif]["illustrator"] = "";
                    chartData[dif]["effected_by"] = "";
                    chartData[dif]["price"]       = "-1";
                    chartData[dif]["limited"]     = "3";
                }
            }

            loaded = true;
        }