Exemple #1
0
        private ActionResult Generate(string csv, string gctPath, ResourceNode sc_selmap, string relpath, ResourceNode info_pac, ResourceNode common2, string brstmPath)
        {
            Func <string, List <string> > split = s => {
                List <string> list    = new List <string>();
                StringBuilder current = new StringBuilder();
                bool          inQuote = false;
                foreach (char c in s)
                {
                    if (c == '"')
                    {
                        inQuote = !inQuote;
                    }
                    else if (c == ',' && !inQuote)
                    {
                        list.Add(current.ToString());
                        current.Clear();
                    }
                    else
                    {
                        current.Append(c);
                    }
                }
                list.Add(current.ToString());
                return(list);
            };

            List <CEPStage> stages    = new List <CEPStage>();
            IList <string>  firstLine = null;

            foreach (string line in System.IO.File.ReadAllLines(csv, Encoding.UTF8))
            {
                if (firstLine == null)
                {
                    firstLine = split(line);
                }
                else
                {
                    CEPStage s = new CEPStage();
                    int      i = 0;
                    foreach (string cell in split(line))
                    {
                        if (cell != "")
                        {
                            var prop = typeof(CEPStage).GetProperty(firstLine[i]);
                            if (prop?.PropertyType == typeof(bool))
                            {
                                prop.SetValue(s, bool.Parse(cell));
                            }
                            else
                            {
                                prop?.SetValue(s, cell);
                            }
                        }
                        i++;
                    }
                    stages.Add(s);
                }
            }

            byte[] gct = System.IO.File.ReadAllBytes(gctPath);
            var    sss = new BrawlManagerLib.CustomSSSCodeset(gct);

            foreach (CEPStage s in stages)
            {
                try {
                    string relname = StageIDMap.RelNameForPac(s.Filename, true);
                    using (var stream = new FileStream(Path.Combine(relpath, relname), FileMode.Open, FileAccess.Read)) {
                        stream.Seek(3, SeekOrigin.Begin);
                        s.ModuleBase = RelNames[stream.ReadByte()];
                    }
                } catch (FileNotFoundException) { }

                if (s.Alternate)
                {
                    continue;
                }
                int iconId          = sss.IconForStage(s.Stage.ID);
                TextureContainer tc = new TextureContainer(sc_selmap, iconId);
                if (tc.icon_tex0 != null)
                {
                    using (MemoryStream ms = new MemoryStream()) {
                        using (Bitmap b = tc.icon_tex0.GetImage(0)) {
                            b.Save(ms, ImageFormat.Png);
                            s.PngIcon = ms.ToArray();
                        }
                    }
                }
            }

            MSBinNode info = (MSBinNode)info_pac.FindChild("MiscData[140]", true);
            var       common2_titledata = new List <SongNameBar.SongIndexEntry>(0);

            foreach (ResourceNode child in common2.Children)
            {
                if (child is Common2MiscDataNode)
                {
                    SndBgmTitleDataNode sndBgmTitleData = child.Children.FirstOrDefault() as SndBgmTitleDataNode;
                    if (sndBgmTitleData != null)
                    {
                        common2_titledata = sndBgmTitleData.Children.Select(n => new SongNameBar.SongIndexEntry()
                        {
                            ID    = (ushort)((SndBgmTitleEntryNode)n).ID,
                            Index = ((SndBgmTitleEntryNode)n).SongTitleIndex
                        }).ToList();
                        break;
                    }
                }
            }

            List <string> brstms = Directory.EnumerateFiles(brstmPath)
                                   .Select(s => Path.GetFileNameWithoutExtension(s)).ToList();

            var sdsl = new StageDependentSongLoader(gct);

            foreach (CEPStage stage in stages)
            {
                Song song = sdsl.GetSong(stage.Stage.ID);
                if (song != null)
                {
                    stage.SongFilename = song.Filename;
                    stage.SongTitle    = info._strings[common2_titledata.Where(c => c.ID == song.ID).Select(c => c.Index).First()];
                    //brstms.RemoveAll(s => s == song.Filename);
                }
            }

            var expStages = stages.Where(s => s.Filename.Contains("CUSTOM"));

            return(View(new MainModel {
                Stages = stages.Except(expStages).Concat(expStages).ToList(),
                Songs = brstms.Select(b => {
                    var song = SongIDMap.Songs.SingleOrDefault(s => s.Filename == b);
                    return new CEPSong {
                        SongFilename = b,
                        SongTitle = info._strings[(
                                                      from c in common2_titledata
                                                      where c.ID == song.ID
                                                      select c.Index
                                                      ).SingleOrDefault()],
                        OriginalSongTitle = b.StartsWith("0000") ? null : song.DefaultName
                    };
                })
            }));
        }