예제 #1
0
        public static void BuildSingleFileM3u(string pPath, Nsfe pNsfeData, string pTrackData, int pIndex, int pTrackIndex)
        {
            string outputFileName = Path.GetFileNameWithoutExtension(pPath) + " - " + pIndex.ToString().PadLeft(2, '0') +
                                    " - " + NsfUtil.ParseTitle(pNsfeData, pTrackIndex) + ".m3u";

            foreach (char c in Path.GetInvalidFileNameChars())
            {
                outputFileName = outputFileName.Replace(c, '_');
            }

            string outputPath = Path.GetDirectoryName(pPath);

            StreamWriter singleSW = File.CreateText(outputPath + Path.DirectorySeparatorChar + outputFileName);

            singleSW.WriteLine("#######################################################");
            singleSW.WriteLine("#");
            singleSW.WriteLine("# Game: " + pNsfeData.SongName);
            singleSW.WriteLine("# Artist: " + pNsfeData.SongArtist);
            singleSW.WriteLine("# Copyright: " + pNsfeData.SongCopyright);
            singleSW.WriteLine("# Ripper: " + pNsfeData.NsfRipper);
            singleSW.WriteLine("# Song: " + NsfUtil.ParseTitle(pNsfeData, pIndex));
            singleSW.WriteLine("#");
            singleSW.WriteLine("#######################################################");
            singleSW.WriteLine();
            singleSW.WriteLine(pTrackData);

            singleSW.Close();
            singleSW.Dispose();
        }
예제 #2
0
        public static string BuildTrackItem(int pIndex, Nsfe pNsfeData, string pPath)
        {
            int    tempTime;
            int    timeMinutes = 0;
            int    timeSeconds = 0;
            string timeTotal   = String.Empty;
            int    fadeMinutes = 0;
            int    fadeSeconds = 0;
            string fadeTotal   = String.Empty;
            string title;
            string entry;

            title = NsfUtil.ParseTitle(pNsfeData, pIndex);

            if (pNsfeData.Times != null)
            {
                tempTime = pNsfeData.Times[pIndex];

                if (tempTime >= 0)
                {
                    timeMinutes = tempTime / 60000;
                    timeSeconds = ((tempTime - (timeMinutes * 60000)) % 60000) / 1000;
                    timeTotal   = timeMinutes + ":" + timeSeconds.ToString("d2");
                }
            }

            if (pNsfeData.Fades != null)
            {
                tempTime = pNsfeData.Fades[pIndex];

                if (tempTime >= 0)
                {
                    fadeMinutes = tempTime / 60000;
                    fadeSeconds = ((tempTime - (fadeMinutes * 60000)) % 60000) / 1000;
                    fadeTotal   = fadeMinutes + ":" + fadeSeconds.ToString("d2");
                }
            }

            entry = NezPlugUtil.BuildPlaylistEntry(NezPlugUtil.FORMAT_NSF,
                                                   Path.GetFileNameWithoutExtension(pPath) + ".nsf",
                                                   (pIndex + 1).ToString(),
                                                   title.Trim(),
                                                   timeTotal,
                                                   String.Empty,
                                                   fadeTotal,
                                                   String.Empty);
            return(entry);
        }
예제 #3
0
        public static void BuildM3uForFile(NsfM3uBuilderStruct pNsfM3uBuilderStruct)
        {
            using (FileStream fs = File.OpenRead(pNsfM3uBuilderStruct.Path))
            {
                Type dataType            = FormatUtil.getObjectType(fs);
                System.Text.Encoding enc = System.Text.Encoding.ASCII;

                if (dataType != null && dataType.Name.Equals("Nsfe"))
                {
                    string filename  = Path.GetFileName(pNsfM3uBuilderStruct.Path);
                    string trackItem = String.Empty;

                    Nsfe nsfeData = new Nsfe();
                    fs.Seek(0, SeekOrigin.Begin);
                    nsfeData.Initialize(fs, pNsfM3uBuilderStruct.Path);

                    string outputFile = Path.GetDirectoryName(pNsfM3uBuilderStruct.Path) + Path.DirectorySeparatorChar +
                                        Path.GetFileNameWithoutExtension(pNsfM3uBuilderStruct.Path) + ".m3u";

                    using (StreamWriter sw = File.CreateText(outputFile))
                    {
                        string[] playlist = nsfeData.Playlist.Split(',');

                        sw.WriteLine("#######################################################");
                        sw.WriteLine("#");
                        sw.WriteLine("# Game: " + nsfeData.SongName);
                        sw.WriteLine("# Artist: " + nsfeData.SongArtist);
                        sw.WriteLine("# Copyright: " + nsfeData.SongCopyright);
                        sw.WriteLine("# Ripper: " + nsfeData.NsfRipper);
                        sw.WriteLine("#");
                        sw.WriteLine("#######################################################");
                        sw.WriteLine();

                        // Build by playlist if it exists
                        if (!String.IsNullOrEmpty(nsfeData.Playlist))
                        {
                            int fileIndex = 1;
                            int index;
                            foreach (string s in nsfeData.Playlist.Split(','))
                            {
                                index     = int.Parse(s.Trim());
                                trackItem = NsfUtil.BuildTrackItem(index, nsfeData, pNsfM3uBuilderStruct.Path);
                                sw.WriteLine(trackItem);

                                if (pNsfM3uBuilderStruct.OnePlaylistPerFile)
                                {
                                    NsfUtil.BuildSingleFileM3u(pNsfM3uBuilderStruct.Path, nsfeData, trackItem, fileIndex, index);
                                }

                                fileIndex++;
                            }
                        }
                        // Use default order if playlist does not exist
                        else
                        {
                            // !!! CHANGE TO START FROM nsfeData.StartingSong???????
                            for (int i = 0; i < nsfeData.TotalSongs[0]; i++)
                            {
                                trackItem = NsfUtil.BuildTrackItem(i, nsfeData, pNsfM3uBuilderStruct.Path);
                                sw.WriteLine(trackItem);

                                if (pNsfM3uBuilderStruct.OnePlaylistPerFile)
                                {
                                    NsfUtil.BuildSingleFileM3u(pNsfM3uBuilderStruct.Path, nsfeData, trackItem, i, i);
                                }
                            }
                        }
                    }

                    NsfUtil.NsfeToNsf(nsfeData, pNsfM3uBuilderStruct.Path);
                }
            }
        }