Exemplo n.º 1
0
        public override PlatformData Create(string path, Game game, ProgressIndicator progress)
        {
            PlatformData  data    = new PlatformData(this, game);
            DirectoryNode maindir = data.GetDirectoryStructure(path);

            List <DirectoryNode> dirs = new List <DirectoryNode>(maindir.Directories);

            dirs.Add(maindir);

            progress.NewTask(dirs.Count);
            foreach (DirectoryNode dir in dirs)
            {
                SongData song = new SongData(data);
                song.Name = dir.Name;
                try {
                    data.Session["songdir"] = dir;
                    AddSong(data, song, progress);
                    data.Session.Remove("songdir");
                } catch (Exception exception) {
                    Exceptions.Warning(exception, "Unable to parse the Frets on Fire song from " + song.Name);
                }
                progress.Progress();
            }
            progress.EndTask();

            return(data);
        }
Exemplo n.º 2
0
        private void SaveDTBCache(PlatformData data)
        {
            data.Mutex.WaitOne();

            string path = Path.Combine(Path.Combine(Path.Combine(Path.Combine(data.Session["maindirpath"] as string, "rawk"), "rb2"), "customs"), "data");

            if (data.Songs.Count == 0)
            {
                if (File.Exists(path))
                {
                    Util.Delete(path);
                }
                data.Mutex.ReleaseMutex();
                return;
            }

            DTB.NodeTree tree = new DTB.NodeTree();

            foreach (FormatData formatdata in data.Songs)
            {
                SongsDTA dta = HarmonixMetadata.GetSongsDTA(formatdata.Song);
                tree.Nodes.Add(dta.ToDTB(PlatformRawkFile.Instance.IsRawkSD2(formatdata.Song)));
            }

            FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);

            tree.Save(new EndianReader(file, Endianness.LittleEndian));
            file.Close();

            data.Mutex.ReleaseMutex();
        }
Exemplo n.º 3
0
        public static Ark GetHarmonixArk(this PlatformData data, string path)
        {
            DirectoryNode dir = null;

            try {
                dir = data.GetDirectoryStructure(path);
            } catch {
                if (File.Exists(path))
                {
                    path = Path.GetDirectoryName(path);
                }
                if (!Directory.Exists(path))
                {
                    throw new FormatException();
                }
                dir = DirectoryNode.FromPath(path, data.Cache);
            }

            try {
                Ark ark = GetHarmonixArk(dir);
                data.Session["ark"] = ark;
                return(ark);
            } catch (Exception exception) {
                Exceptions.Error(exception, "Unable to open the ark file at " + path);
            }
            return(null);
        }
Exemplo n.º 4
0
        public override PlatformData Create(string path, Game game, ProgressIndicator progress)
        {
            PlatformData data = new PlatformData(this, game);

            DirectoryNode dir = data.GetDirectoryStructure(path);

            data.Game = Platform.DetermineGame(data);

            FileNode  tracklist = dir.Navigate("/Common/AUDIO/Audiotracks/TrackListing.xml") as FileNode;
            XmlReader reader    = XmlReader.Create(tracklist.Data);

            tracklist.Data.Close();
            XmlDocument doc = new XmlDocument();

            doc.Load(reader);

            var elements = doc.DocumentElement.GetElementsByTagName("Track");

            progress.NewTask(elements.Count);

            foreach (XmlElement element in elements)
            {
                SongData song = FreeStyleGamesMetadata.GetSongData(element);

                AddSong(data, song, progress);

                progress.Progress();
            }

            return(data);
        }
Exemplo n.º 5
0
        public override PlatformData Create(string path, Game game, ProgressIndicator progress)
        {
            PlatformData data = new PlatformData(this, game);

            data.Session["path"] = path;

            if (Directory.Exists(path))
            {
                Exceptions.Error("An RBN archive must be a file.");
            }

            if (File.Exists(path))
            {
                try {
                    RBA rba = new RBA(new EndianReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read), Endianness.LittleEndian));
                    data.Session["rba"] = rba;

                    SongData song = HarmonixMetadata.GetSongData(data, DTA.Create(rba.Data));

                    song.ID = ImportMap.GetShortName(song.Name);

                    AddSong(data, song, progress);
                } catch (Exception exception) {
                    Exceptions.Error(exception, "An error occurred while opening the RBN archive.");
                }
            }

            return(data);
        }
Exemplo n.º 6
0
        public static DirectoryNode GetDirectoryStructure(this PlatformData platform, string path)
        {
            platform.Session["path"] = path;

            if (Directory.Exists(path))
            {
                DirectoryNode root = DirectoryNode.FromPath(path, platform.Cache, FileAccess.Read, FileShare.Read);
                platform.Session["rootdirnode"] = root;
                return(root);
            }
            else if (File.Exists(path))
            {
                Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                platform.Cache.AddStream(stream);

                try {
                    stream.Position = 0;
                    Iso9660 iso = new Iso9660(stream);
                    platform.Session["iso"]         = iso;
                    platform.Session["rootdirnode"] = iso.Root;
                    return(iso.Root);
                } catch (FormatException) { } catch (Exception exception) {
                    Exceptions.Warning(exception, "Trying to open as ISO: " + path);
                }

                try {
                    stream.Position = 0;
                    Disc disc = new Disc(stream);

                    platform.Session["wiidisc"] = disc;

                    Partition partition = disc.DataPartition;
                    if (partition == null)
                    {
                        throw new FormatException();
                    }

                    platform.Session["rootdirnode"] = partition.Root.Root;
                    return(partition.Root.Root);
                } catch (FormatException) { } catch (Exception exception) {
                    Exceptions.Warning(exception, "Trying to open as Wiidisc: " + path);
                }

                try {
                    stream.Position = 0;
                    U8 u8 = new U8(stream);
                    platform.Session["u8"]          = u8;
                    platform.Session["rootdirnode"] = u8.Root;
                    return(u8.Root);
                } catch (FormatException) { } catch (Exception exception) {
                    Exceptions.Warning(exception, "Trying to open as U8: " + path);
                }
            }

            Exceptions.Error("Could not find a proper file type handler for " + path);
            throw new NotSupportedException();
        }
Exemplo n.º 7
0
 public FormatData(SongData song, PlatformData data) : this()
 {
     PlatformData = data;
     if (song != null)
     {
         Song = song;
         song.PropertyChanged += new Action <SongData>(Song_PropertyChanged);
     }
 }
Exemplo n.º 8
0
        public void AddSongs(PlatformData data, ProgressIndicator progress)
        {
            if (Root == null)
            {
                return;
            }

            foreach (XmlNode node in Root.GetElementsByTagName("addsong"))
            {
                XmlElement element = node as XmlElement;

                if (element.Attributes["game"] != null && int.Parse(element.Attributes["game"].Value) != (int)data.Game)
                {
                    continue;
                }

                SongData song = new SongData(data);
                if (element.Attributes["id"] != null)
                {
                    song.ID = element.Attributes["id"].Value;
                }
                song.PopulateFromXML(element, RootPath);
                data.Platform.AddSong(data, song, progress);
            }

            data.Mutex.WaitOne();
            IList <FormatData> songs = data.Songs;

            foreach (XmlNode node in Root.GetElementsByTagName("deletesong"))
            {
                XmlElement element = node as XmlElement;

                if (element.Attributes["game"] != null && int.Parse(element.Attributes["game"].Value) != (int)data.Game)
                {
                    continue;
                }

                if (element.Attributes["id"] != null)
                {
                    foreach (FormatData song in songs.Where(f => string.Compare(f.Song.ID, element.Attributes["id"].Value, true) == 0).ToList())
                    {
                        data.RemoveSong(song);
                    }
                }

                if (element.Attributes["name"] != null)
                {
                    foreach (FormatData song in songs.Where(f => string.Compare(f.Song.Name, element.Attributes["name"].Value, true) == 0).ToList())
                    {
                        data.RemoveSong(song);
                    }
                }
            }
            data.Mutex.ReleaseMutex();
        }
Exemplo n.º 9
0
        public override void DeleteSong(PlatformData data, FormatData formatdata, ProgressIndicator progress)
        {
            if (!(formatdata is FolderFormatData))
            {
                return;
            }
            string path = (formatdata as FolderFormatData).Pathname;

            formatdata.Dispose();
            Directory.Delete(path, true);
            base.DeleteSong(data, formatdata, progress);
        }
Exemplo n.º 10
0
        private void AddSongFromBins(PlatformData data, SongData song, string dtapath, string contentpath, ProgressIndicator progress, bool replace = false)
        {
            if (File.Exists(contentpath) && File.Exists(dtapath))
            {
                Stream contentfile = null;
                Stream dtafile     = null;
                if (IterateBins)
                {
                    contentfile = new DelayedStream(data.Cache.GenerateFileStream(contentpath, FileMode.Open));
                    DlcBin content = new DlcBin(contentfile);
                    U8     u8      = new U8(content.Data);

                    // Read album art from the preview bin
                    dtafile = new DelayedStream(data.Cache.GenerateFileStream(dtapath, FileMode.Open));
                    DlcBin        dtabin  = new DlcBin(dtafile);
                    U8            dtau8   = new U8(dtabin.Data);
                    string        genpath = "/content/songs/" + song.ID + "/gen";
                    DirectoryNode dtagen  = dtau8.Root.Navigate(genpath) as DirectoryNode;
                    if (dtagen != null)
                    {
                        DirectoryNode contentgen = u8.Root.Navigate(genpath) as DirectoryNode;
                        if (contentgen != null)
                        {
                            contentgen.AddChildren(dtagen.Files);
                        }
                    }

                    data.Session["songdir"] = u8.Root;
                }

                if (replace)
                {
                    foreach (FormatData formatdata in data.Songs)
                    {
                        if (formatdata.Song.ID == song.ID)
                        {
                            base.DeleteSong(data, formatdata, progress);
                            break;
                        }
                    }
                }

                AddSong(data, song, progress);                 // TODO: Add dta bin to songdir for album art

                if (IterateBins)
                {
                    data.Session.Remove("songdir");
                    contentfile.Close();
                    dtafile.Close();
                }
            }
        }
Exemplo n.º 11
0
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            FormatData formatdata = new TemporaryFormatData(song, data);

            DirectoryNode dir = data.Session["rootdirnode"] as DirectoryNode;

            string        path     = song.Data.GetValue <string>("FolderLocation");
            DirectoryNode songdir  = dir.Navigate("Common/" + path) as DirectoryNode;
            DirectoryNode audiodir = dir.Navigate("Wii/" + path) as DirectoryNode;

            string mode       = "SinglePlayer";
            string difficulty = "Medium";

            path = mode + "/" + difficulty;

            //audiodir = audiodir.Navigate(path) as DirectoryNode;

            List <FileNode> audiofiles = new List <FileNode>();

            audiofiles.Add(audiodir.Find("AudioTrack_Main.fsb", SearchOption.AllDirectories) as FileNode);
            audiofiles.Add(audiodir.Find("AudioTrack_Main_P1.fsb", SearchOption.AllDirectories) as FileNode);
            audiofiles.Add(audiodir.Find("AudioTrack_Main_P2.fsb", SearchOption.AllDirectories) as FileNode);
            audiofiles.RemoveAll(f => f == null);

            List <FileNode> chartfiles = new List <FileNode>();

            chartfiles.Add(audiodir.Find("Markup_Main_P1_0.fsgmub", SearchOption.AllDirectories) as FileNode);
            chartfiles.Add(audiodir.Find("Markup_Main_P1_1.fsgmub", SearchOption.AllDirectories) as FileNode);
            chartfiles.Add(audiodir.Find("Markup_Main_P1_2.fsgmub", SearchOption.AllDirectories) as FileNode);
            chartfiles.Add(audiodir.Find("Markup_Main_P1_3.fsgmub", SearchOption.AllDirectories) as FileNode);
            chartfiles.Add(audiodir.Find("Markup_Main_P1_4.fsgmub", SearchOption.AllDirectories) as FileNode);
            chartfiles.Add(audiodir.Find("Markup_Main_P2.fsgmub", SearchOption.AllDirectories) as FileNode);
            chartfiles.Add(audiodir.Find("Markup_Main_P1.fsgmub", SearchOption.AllDirectories) as FileNode);
            chartfiles.RemoveAll(f => f == null);

            if (audiofiles.Count == 0 && chartfiles.Count == 0)
            {
                return(false);
            }

            if (audiofiles.Count > 0)
            {
                AudioFormatMp3.Instance.CreateFromFSB(formatdata, audiofiles.Select(a => a.Data).ToArray(), FreeStyleGamesMetadata.GetAudioFormat(song));
            }

            if (chartfiles.Count > 0)
            {
                ChartFormatFsgMub.Instance.Create(formatdata, chartfiles.Select(c => c.Data).ToArray());
            }

            return(true);
        }
Exemplo n.º 12
0
        public override PlatformData Create(string path, Game game, ProgressIndicator progress)
        {
            PlatformData data = new PlatformData(this, game);

            DirectoryNode dir = data.GetDirectoryStructure(path);

            data.Game = Platform.DetermineGame(data);

            FileNode qbpak = dir.Navigate("pak/qb.pak.ngc") as FileNode;

            if (qbpak == null)
            {
                Exceptions.Error("Couldn't find qb.pak.ngc on Guitar Hero 3 Wii disc.");
            }

            try {
                Pak          qb           = new Pak(new EndianReader(qbpak.Data, Endianness.BigEndian));
                FileNode     songlistfile = qb.Root.Find("songlist.qb.ngc", SearchOption.AllDirectories) as FileNode;
                FileNode     albumfile    = dir.Navigate("pak/album_covers/album_covers.pak.ngc", false, true) as FileNode;
                QbFile       songlist     = new QbFile(songlistfile.Data, PakFormat);
                QbItemStruct list         = songlist.FindItem(QbKey.Create(NeversoftMetadata.SonglistKeys[0]), true) as QbItemStruct;

                data.Session["rootdir"] = dir;
                data.Session["rootqb"]  = qb;

                if (albumfile != null)
                {
                    data.Session["albumpak"] = new Pak(new EndianReader(albumfile.Data, Endianness.BigEndian));
                }

                var items = list.Items;
                progress.NewTask(items.Count);
                foreach (QbItemStruct item in items)
                {
                    SongData song = NeversoftMetadata.GetSongData(data, item);

                    try {
                        AddSong(data, song, progress);
                    } catch (Exception exception) {
                        Exceptions.Warning(exception, "Unable to properly parse " + song.Name);
                    }

                    progress.Progress();
                }
                progress.EndTask();
            } catch (Exception exception) {
                Exceptions.Error(exception, "An error occurred while parsing the Guitar Hero 3 Wii disc.");
            }

            return(data);
        }
Exemplo n.º 13
0
        public override PlatformData Create(string path, Game game, ProgressIndicator progress)
        {
            PlatformData data = new PlatformData(this, game);

            DirectoryNode dir = data.GetDirectoryStructure(path);

            List <DirectoryNode> dirs = new List <DirectoryNode>();

            dirs.Add(dir);
            dirs.AddRange(dir.Directories);

            progress.NewTask(dirs.Count);

            foreach (DirectoryNode songdir in dirs)
            {
                data.Session["songdir"] = songdir;

                FileNode datafile    = songdir.Navigate("data", false, true) as FileNode;
                FileNode newdatafile = songdir.Navigate("songdata", false, true) as FileNode;
                if (datafile == null && newdatafile == null)
                {
                    Exceptions.Warning("Unable to find a custom in " + songdir.Filename);
                    continue;
                }

                try {
                    SongData song = null;
                    if (datafile != null)
                    {
                        song = HarmonixMetadata.GetSongData(data, DTB.Create(new EndianReader(datafile.Data, Endianness.LittleEndian)));
                        datafile.Data.Close();
                        AddSongOld(data, song, progress);
                    }
                    else
                    {
                        song = SongData.Create(newdatafile.Data);
                        newdatafile.Data.Close();
                        AddSongNew(data, song, progress);
                    }
                } catch (Exception exception) {
                    Exceptions.Error(exception, "Unable to open the custom from " + songdir.Filename);
                }

                progress.Progress();
            }
            progress.EndTask();

            return(data);
        }
Exemplo n.º 14
0
        public bool AddSongNew(PlatformData data, SongData song, ProgressIndicator progress)
        {
            FormatData formatdata = new TemporaryFormatData(song, data);

            DirectoryNode dir = data.Session["songdir"] as DirectoryNode;

            foreach (FileNode file in dir.Files)
            {
                formatdata.SetStream(file.Name, file.Data);
            }

            data.AddSong(formatdata);

            return(true);
        }
Exemplo n.º 15
0
        public override FormatData CreateSong(PlatformData data, SongData song)
        {
            string path = null;
            int    i    = 0;

            do
            {
                path = Path.Combine(data.Session["rootpath"] as string, song.ID) + (i == 0 ? "" : i.ToString());
                i++;
            } while (Directory.Exists(path));
            Directory.CreateDirectory(path);

            FormatData format = new FolderFormatData(song, data, path);

            return(format);
        }
Exemplo n.º 16
0
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            if (IterateBins)
            {
                return(PlatformRB2WiiDisc.Instance.AddSong(data, song, progress));
            }
            else
            {
                FormatData formatdata = new TemporaryFormatData(song, data);

                SongsDTA dta = HarmonixMetadata.GetSongsDTA(song);

                data.AddSong(formatdata);

                return(true);
            }
        }
Exemplo n.º 17
0
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            FormatData formatdata = new TemporaryFormatData(song, data);

            RBA rba = data.Session["rba"] as RBA;

            AudioFormat audio = HarmonixMetadata.GetAudioFormat(song);

            AudioFormatMogg.Instance.Create(formatdata, rba.Audio, audio);

            ChartFormatRB.Instance.Create(formatdata, rba.Chart, null, 0, rba.Weights, rba.Milo, ChartFormatRB.Milo3Version, false, false);

            //song.AlbumArt = XboxImage.Create(new EndianReader(albumfile.Data, Endianness.LittleEndian)).Bitmap;

            data.AddSong(formatdata);

            return(true);
        }
Exemplo n.º 18
0
        private void AddSongFromDTB(string path, PlatformData data, DTB.NodeTree dtb, ProgressIndicator progress)
        {
            SongData song = HarmonixMetadata.GetSongData(data, dtb);
            SongsDTA dta  = HarmonixMetadata.GetSongsDTA(song);

            if (song.ID.StartsWith("rwk"))
            {
                song.ID = dta.Song.Name.Split('/').Last();
            }

            string title       = dta.Song.Name.Substring(4, 4);
            int    index       = int.Parse(dta.Song.Name.Substring(9, 3));
            string indexpath   = Util.Pad((index + 1).ToString(), 3);
            string contentpath = Path.Combine(path, "private/wii/data/" + title + "/" + indexpath + ".bin");
            string dtapath     = Path.Combine(path, "private/wii/data/" + title + "/" + Util.Pad(index.ToString(), 3) + ".bin");

            AddSongFromBins(data, song, dtapath, contentpath, progress);
        }
Exemplo n.º 19
0
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            int index = int.Parse(song.ID.Substring(3));
            //song.ID = "dlc" + ImportMap.GetShortName(song.Name);

            FormatData formatdata = new TemporaryFormatData(song, data);

            NeversoftMetadata.SaveSongItem(formatdata);

            DirectoryNode dir = data.Session["rootdir"] as DirectoryNode;

            FileNode binfile = dir.Navigate(Util.Pad(index.ToString(), 3) + ".bin") as FileNode;

            if (binfile == null)
            {
                return(false);
            }
            DlcBin bin = new DlcBin(binfile.Data);
            U8     u8  = new U8(bin.Data);

            FileNode chartpak = u8.Root.Find(song.ID + "_song.pak.ngc", SearchOption.AllDirectories) as FileNode;
            FileNode textpak  = u8.Root.Find(song.ID + "_text.pak.ngc", SearchOption.AllDirectories) as FileNode;

            FileNode audiofile = u8.Root.Find(song.ID + ".bik", SearchOption.AllDirectories) as FileNode;

            if (chartpak == null || textpak == null || audiofile == null)
            {
                return(false);
            }

            ChartFormatGH4.Instance.Create(formatdata, new Stream[] { chartpak.Data, textpak.Data }, PlatformGH5WiiDisc.ImportExpertPlus);

            if (audiofile != null)
            {
                AudioFormatBink.Instance.Create(formatdata, audiofile.Data, null, null);
            }

            data.AddSong(formatdata);

            chartpak.Data.Close();

            return(true);
        }
Exemplo n.º 20
0
        public FolderFormatData(SongData song, PlatformData data, string path) : base()
        {
            Folder = path;

            if (!Directory.Exists(Folder))
            {
                Directory.CreateDirectory(Folder);
            }

            Refresh();

            if (data != null)
            {
                PlatformData = data;
            }
            if (song != null)
            {
                Song = song;
            }
        }
Exemplo n.º 21
0
        private static bool FindUnusedContent(PlatformData data, SongData song, out string title, out ushort index)
        {
            data.Mutex.WaitOne();

            Dictionary <string, List <ushort> > contents = data.Session["contents"] as Dictionary <string, List <ushort> >;

            foreach (FormatData formatdata in data.Songs)
            {
                SongData subsong = formatdata.Song;
                if (subsong.ID == song.ID && GetSongBin(subsong, out title, out index))
                {
                    data.Mutex.ReleaseMutex();
                    return(true);
                }
            }

            for (title = UnusedTitle; (byte)title[3] <= (byte)'Z'; title = title.Substring(0, 3) + (char)(((byte)title[3]) + 1))
            {
                if (!contents.ContainsKey(title))
                {
                    contents[title] = new List <ushort>();
                }
                var list = contents[title];
                for (index = 1; index < 510; index += 2)
                {
                    if (!list.Contains(index))
                    {
                        list.Add(index);
                        data.Mutex.ReleaseMutex();
                        return(true);
                    }
                }
            }

            data.Mutex.ReleaseMutex();

            title = null;
            index = 0;
            return(false);
        }
Exemplo n.º 22
0
        public static SongData GetSongData(PlatformData platformdata, DTB.NodeTree dtb)
        {
            SongData data = new SongData(platformdata);

            data.Data.SetSubtree("HmxSongsDtb", dtb);

            SongsDTA dta = SongsDTA.Create(dtb);

            data.Album = dta.Album;
            if (dta.Track.HasValue)
            {
                data.AlbumTrack = dta.Track.Value;
            }
            data.Artist = dta.Artist;
            data.ID     = dta.BaseName;
            for (Instrument instrument = Instrument.Ambient; instrument <= Instrument.Vocals; instrument++)
            {
                SongsDTA.Rankings rank = dta.Rank.SingleOrDefault(r => r.Name == InstrumentToString(instrument));
                if (rank != null)
                {
                    data.Difficulty[instrument] = rank.Rank;
                }
            }
            data.Genre        = dta.Genre;
            data.Master       = dta.Master;
            data.Name         = dta.Name;
            data.Pack         = dta.Pack;
            data.Vocalist     = dta.Vocalist;
            data.Year         = dta.Year;
            data.Version      = dta.Version;
            data.PreviewTimes = dta.Preview;
            if (dta.Song.HopoThreshold.HasValue)
            {
                data.HopoThreshold = dta.Song.HopoThreshold.Value;
            }

            return(data);
        }
Exemplo n.º 23
0
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            FormatData formatdata = new TemporaryFormatData(song, data);

            NeversoftMetadata.SaveSongItem(formatdata);

            DirectoryNode dir = data.Session["rootdir"] as DirectoryNode;

            FileNode chartpak = dir.Navigate("songs/" + song.ID + ".pak.ngc", false, true) as FileNode;

            if (chartpak == null)
            {
                return(false);
            }

            if (data.Game == Game.GuitarHero5 || data.Game == Game.BandHero)
            {
                ChartFormatGH5.Instance.Create(formatdata, new Stream[] { chartpak.Data }, ImportExpertPlus);
            }
            else
            {
                ChartFormatGH4.Instance.Create(formatdata, new Stream[] { chartpak.Data }, ImportExpertPlus);
            }

            FileNode audiofile   = dir.Navigate("music/" + song.ID + ".bik", false, true) as FileNode;
            FileNode previewfile = dir.Navigate("music/" + song.ID + "_preview.bik", false, true) as FileNode;

            if (audiofile != null)
            {
                AudioFormatBink.Instance.Create(formatdata, audiofile.Data, previewfile == null ? null : previewfile.Data, null);
            }

            data.AddSong(formatdata);

            chartpak.Data.Close();

            return(true);
        }
Exemplo n.º 24
0
        public bool AddSongOld(PlatformData data, SongData song, ProgressIndicator progress)
        {
            FormatData formatdata = new TemporaryFormatData(song, data);

            formatdata.Song.Data.SetValue("RawkSD2Compatibility", true);
            formatdata.Song.Version = 0;

            DirectoryNode dir = data.Session["songdir"] as DirectoryNode;

            FileNode audiofile   = dir.Navigate("audio") as FileNode;
            FileNode albumfile   = dir.Navigate("album") as FileNode;
            FileNode weightsfile = dir.Navigate("weights") as FileNode;
            FileNode panfile     = dir.Navigate("pan") as FileNode;
            FileNode milofile    = dir.Navigate("milo") as FileNode;
            FileNode chartfile   = dir.Navigate("chart") as FileNode;
            FileNode previewfile = dir.Navigate("preview") as FileNode;

            if (audiofile != null)
            {
                AudioFormat audio = HarmonixMetadata.GetAudioFormat(song);
                AudioFormatRB2Mogg.Instance.Create(formatdata, audiofile.Data, previewfile.Data, null);
            }

            if (albumfile != null)
            {
                song.AlbumArt = WiiImage.Create(new EndianReader(albumfile.Data, Endianness.LittleEndian)).Bitmap;
            }

            if (chartfile != null)
            {
                ChartFormatRB.Instance.Create(formatdata, chartfile == null ? null : chartfile.Data, panfile == null ? null : panfile.Data, weightsfile == null ? null : weightsfile.Data, milofile == null ? null : milofile.Data, false, false, Game.RockBand2);
            }

            data.AddSong(formatdata);

            return(true);
        }
Exemplo n.º 25
0
        public override PlatformData Create(string path, Game game, ProgressIndicator progress)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            PlatformData data = new PlatformData(this, game);

            data.Session["rootpath"] = path;

            DirectoryInfo[] dirs = new DirectoryInfo(path).GetDirectories();
            progress.NewTask(dirs.Length);
            foreach (DirectoryInfo dir in dirs)
            {
                progress.Progress();

                if (!File.Exists(Path.Combine(dir.FullName, "songdata")))
                {
                    continue;
                }

                try {
                    FormatData format = new FolderFormatData(data, dir.FullName);

                    if (format.Song != null)
                    {
                        data.AddSong(format);
                    }
                } catch (Exception exception) {
                    Exceptions.Warning(exception, "Unable to open the custom at " + dir.FullName);
                }
            }
            progress.EndTask();

            return(data);
        }
Exemplo n.º 26
0
        public override void DeleteSong(PlatformData data, FormatData formatdata, ProgressIndicator progress)
        {
            string path    = data.Session["maindirpath"] as string;
            string dtapath = "rawk/rb2/customs/" + formatdata.Song.ID;

            FileStream dtafile = new FileStream(Path.Combine(path, dtapath + "/data"), FileMode.Open, FileAccess.Read, FileShare.Read);

            EndianReader reader = new EndianReader(dtafile, Endianness.LittleEndian);

            DTB.NodeTree dtb = DTB.Create(reader);
            dtafile.Close();

            SongsDTA dta   = SongsDTA.Create(dtb);
            string   title = dta.Song.Name.Substring(4, 4);
            int      index = int.Parse(dta.Song.Name.Substring(9, 3));

            Util.Delete(Path.Combine(path, "private/wii/data/" + title + "/" + Util.Pad((index).ToString(), 3) + ".bin"));
            Util.Delete(Path.Combine(path, "private/wii/data/" + title + "/" + Util.Pad((index + 1).ToString(), 3) + ".bin"));
            Directory.Delete(Path.Combine(path, dtapath), true);

            base.DeleteSong(data, formatdata, progress);

            SaveDTBCache(data);
        }
Exemplo n.º 27
0
        private static void RefreshUnusedContent(PlatformData data)
        {
            data.Mutex.WaitOne();

            Dictionary <string, List <ushort> > contents = new Dictionary <string, List <ushort> >();

            foreach (FormatData formatdata in data.Songs)
            {
                string title;
                ushort index;
                if (GetSongBin(formatdata.Song, out title, out index))
                {
                    if (!contents.ContainsKey(title))
                    {
                        contents[title] = new List <ushort>();
                    }
                    contents[title].Add(index);
                }
            }

            data.Session["contents"] = contents;

            data.Mutex.ReleaseMutex();
        }
Exemplo n.º 28
0
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            DirectoryNode songdir = data.Session["songdir"] as DirectoryNode;

            SongsDTA dta = HarmonixMetadata.GetSongsDTA(song);

            if (dta == null)               // GH1's <addsong />
            {
                dta            = HarmonixMetadata.GetSongData(song);
                dta.Song.Cores = new List <int>()
                {
                    -1, -1, 1, 1
                };
                dta.Song.Vols = new List <float>()
                {
                    0, 0, 0, 0
                };
                dta.Song.Pans = new List <float>()
                {
                    -1, 1, -1, 1
                };
                dta.Song.Tracks.Find(t => t.Name == "guitar").Tracks.AddRange(new int[] { 2, 3 });
                HarmonixMetadata.SetSongsDTA(song, dta.ToDTB());
            }

            dta.Bank = "sfx/tambourine_bank.milo";

            DirectoryNode songnode = songdir.Navigate(song.ID) as DirectoryNode;

            FileNode chartfile = songnode.Find(song.ID + ".mid") as FileNode;

            if (chartfile == null)
            {
                return(false);
            }

            for (int coop = 0; coop < 2; coop++)
            {
                if (coop == 1)
                {
                    song       = new SongData(song);
                    song.ID   += "_coop";
                    song.Name += " [coop]";
                    if (dta.SongCoop != null)
                    {
                        dta.Song     = dta.SongCoop;
                        dta.SongCoop = null;
                    }
                    else
                    {
                        return(false);
                    }
                }
                HarmonixMetadata.SetSongsDTA(song, dta.ToDTB());
                FormatData formatdata = new TemporaryFormatData(song, data);

                FileNode songaudiofile = songnode.Find(song.ID + ".vgs") as FileNode;
                if (songaudiofile == null)
                {
                    songaudiofile = songnode.Find(song.ID + "_sp.vgs") as FileNode;
                }
                if (songaudiofile == null)
                {
                    return(false);
                }

                if (data.Game == Game.GuitarHero1)
                {
                    ChartFormatGH1.Instance.Create(formatdata, chartfile == null ? null : chartfile.Data);
                }
                else
                {
                    ChartFormatGH2.Instance.Create(formatdata, chartfile == null ? null : chartfile.Data, coop == 1);
                }

                AudioFormatVGS.Instance.Create(formatdata, songaudiofile.Data, null);

                data.AddSong(formatdata);
            }

            return(true);
        }
Exemplo n.º 29
0
        public override PlatformData Create(string path, Game game, ProgressIndicator progress)
        {
            if (File.Exists(path))
            {
                if (String.Compare(Path.GetExtension(path), ".ark", true) == 0 || String.Compare(Path.GetExtension(path), ".hdr", true) == 0)
                {
                    path = Path.GetDirectoryName(path);
                }
            }

            PlatformData data = new PlatformData(this, game);

            data.Game = Platform.DetermineGame(data);

            Ark ark = data.GetHarmonixArk(path);

            DirectoryNode songdir = ark.Root.Find("songs", true) as DirectoryNode;

            if (songdir == null)
            {
                Exceptions.Error("This is not a Guitar Hero PS2 disc; the songs dir is missing from the ark.");
            }

            FileNode songsdtbfile = ark.Root.Navigate("config/gen/songs.dtb", false, true) as FileNode;

            if (songsdtbfile == null)
            {
                Exceptions.Error("Couldn't find songs.dtb; this is not a Guitar Hero PS2 disc.");
            }

            data.Session["songdir"] = songdir;

            try {
                List <SongsDTA> dtas      = new List <SongsDTA>();
                Stream          dtbstream = new MemoryStream((int)songsdtbfile.Size);
                CryptedDtbStream.DecryptOld(dtbstream, new EndianReader(songsdtbfile.Data, Endianness.LittleEndian), (int)songsdtbfile.Size);
                dtbstream.Position = 0;
                DTB.NodeTree dtb = DTB.Create(new EndianReader(dtbstream, Endianness.LittleEndian));
                progress.NewTask(dtb.Nodes.Count);
                foreach (DTB.Node node in dtb.Nodes)
                {
                    DTB.NodeTree tree = node as DTB.NodeTree;
                    if (tree == null || tree.Nodes[0].Type != 0x00000005 || songdir.Find((tree.Nodes[0] as DTB.NodeString).Text) == null)
                    {
                        progress.Progress();
                        continue;
                    }

                    SongsDTA dta = SongsDTA.Create(tree);
                    if (dtas.FirstOrDefault(d => d.BaseName == dta.BaseName) != null)
                    {
                        progress.Progress();
                        continue;                         // Don't import songs twice
                    }
                    dtas.Add(dta);

                    SongData song = HarmonixMetadata.GetSongData(data, tree);
                    try {
                        AddSong(data, song, progress);
                    } catch (Exception exception) {
                        Exceptions.Warning(exception, "Unable to properly parse " + song.Name);
                    }
                    progress.Progress();
                }
                progress.EndTask();
            } catch (Exception exception) {
                Exceptions.Error(exception, "An error occurred while parsing the Guitar Hero PS2 disc.");
            }

            return(data);
        }
Exemplo n.º 30
0
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            FormatData formatdata = new TemporaryFormatData(song, data);

            DirectoryNode dir = data.Session["songdir"] as DirectoryNode;

            int         delay      = 0;
            bool        eighthhopo = false;
            int         hopofreq   = -1;
            AudioFormat format     = new AudioFormat();
            FileNode    songini    = dir.Navigate("song.ini", false, true) as FileNode;

            if (songini != null)
            {
                Ini ini = Ini.Create(songini.Data);
                songini.Data.Close();
                string value = ini.GetValue("song", "name"); if (value != null)
                {
                    song.Name = value;
                }
                value = ini.GetValue("song", "artist"); if (value != null)
                {
                    song.Artist = value;
                }
                value = ini.GetValue("song", "album"); if (value != null)
                {
                    song.Album = value;
                }
                value = ini.GetValue("song", "genre"); if (value != null)
                {
                    song.Genre = value;
                }
                value = ini.GetValue("song", "year"); if (value != null)
                {
                    song.Year = int.Parse(value);
                }
                value = ini.GetValue("song", "version"); if (value != null)
                {
                    song.Version = int.Parse(value);
                }
                value = ini.GetValue("song", "delay"); if (value != null)
                {
                    delay = int.Parse(value);
                }
                value = ini.GetValue("song", "eighthnote_hopo"); if (value != null)
                {
                    eighthhopo = string.Compare(value, "true", true) == 0 ? true : false;
                }
                value = ini.GetValue("song", "hopofreq"); if (value != null)
                {
                    hopofreq = int.Parse(value);
                }
                value = ini.GetValue("song", "tags"); if (value != null)
                {
                    song.Master = string.Compare(value, "cover", true) == 0 ? false : true;
                }
                value = ini.GetValue("song", "icon"); if (value != null)
                {
                    song.Game = GetGameFromIcon(value);
                }
                value = ini.GetValue("song", "diff_band"); if (value != null)
                {
                    song.Difficulty[Instrument.Ambient] = ImportMap.GetBaseRank(Instrument.Ambient, int.Parse(value));
                }
                value = ini.GetValue("song", "diff_bass"); if (value != null)
                {
                    song.Difficulty[Instrument.Bass] = ImportMap.GetBaseRank(Instrument.Bass, int.Parse(value));
                }
                value = ini.GetValue("song", "diff_drums"); if (value != null)
                {
                    song.Difficulty[Instrument.Drums] = ImportMap.GetBaseRank(Instrument.Drums, int.Parse(value));
                }
                value = ini.GetValue("song", "diff_guitar"); if (value != null)
                {
                    song.Difficulty[Instrument.Guitar] = ImportMap.GetBaseRank(Instrument.Guitar, int.Parse(value));
                }
            }

            format.InitialOffset = -delay;

            FileNode album = dir.Navigate("album.png", false, true) as FileNode;

            if (album != null)
            {
                song.AlbumArt = new Bitmap(album.Data);
            }

            FileNode  chartfile = dir.Navigate("notes.mid", false, true) as FileNode;
            NoteChart chart     = null;

            if (chartfile != null)
            {
                ChartFormatRB.Instance.Create(formatdata, chartfile.Data, null, 0, null, null, 0, false, true);
                chart = NoteChart.Create(Midi.Create(Mid.Create(chartfile.Data)));
                chartfile.Data.Close();
            }

            if (chart != null && eighthhopo)
            {
                song.HopoThreshold = chart.Division.TicksPerBeat / 2 + 10;
            }
            else if (hopofreq >= 0)
            {
                // TODO: This
            }

            List <Stream> streams = new List <Stream>();

            foreach (Node node in dir)
            {
                FileNode file = node as FileNode;
                if (file == null)
                {
                    continue;
                }
                string extension = Path.GetExtension(file.Name).ToLower();
                if (extension != ".ogg")
                {
                    continue;
                }

                string            name       = Path.GetFileNameWithoutExtension(file.Name);
                Instrument        instrument = Platform.InstrumentFromString(name);
                RawkAudio.Decoder decoder    = new RawkAudio.Decoder(file.Data, RawkAudio.Decoder.AudioFormat.VorbisOgg);
                for (int i = 0; i < decoder.Channels; i++)
                {
                    format.Mappings.Add(new AudioFormat.Mapping(0, 0, instrument));
                }
                decoder.Dispose();
                file.Data.Close();

                streams.Add(file.Data);
            }
            format.AutoBalance();

            if (streams.Count > 0)
            {
                AudioFormatOgg.Instance.Create(formatdata, streams.ToArray(), format);
            }
            else if (chartfile == null)
            {
                return(false);
            }

            data.AddSong(formatdata);

            return(true);
        }