Exemplo n.º 1
0
        private SidTuneBase getFromBuffer(byte[] buffer, UInt32 bufferLen)
        {
            if (buffer == null || bufferLen == 0)
            {
                throw new loadError(ERR_EMPTY);
            }

            if (bufferLen > MAX_FILELEN)
            {
                throw new loadError(ERR_FILE_TOO_LONG);
            }

            byte[] buf1 = buffer;//, buffer +bufferLen);

            // Here test for the possible single file formats.
            SidTuneBase s = PSID.load(ref buf1);

            if (s == null)
            {
                s = (new MUS()).load(buf1.ToArray(), true);
            }
            if (s == null)
            {
                throw new loadError(ERR_UNRECOGNIZED_FORMAT);
            }

            List <byte> lstBuf1 = new List <byte>(buf1);

            s.acceptSidTune("-", "-", ref lstBuf1, false);
            return(s);
        }
Exemplo n.º 2
0
        // Initializing the object based upon what we find in the specified file.

        private SidTuneBase getFromFiles(string fileName, string[] fileNameExtensions, bool separatorIsSlash)
        {
            List <byte> fileBuf1 = new List <byte>();

            loadFile(fileName, ref fileBuf1);

            // File loaded. Now check if it is in a valid single-file-format.
            byte[]      aryFileBuf1 = fileBuf1.ToArray();
            SidTuneBase s           = PSID.load(ref aryFileBuf1);

            fileBuf1 = new List <byte>(aryFileBuf1);
            if (s == null)
            {
                // Try some native C64 file formats
                s = (new MUS()).load(fileBuf1.ToArray(), true);
                if (s != null)
                {
                    // Try to find second file.
                    string fileName2;
                    int    n = 0;
                    while (fileNameExtensions[n] != null)
                    {
                        createNewFileName(out fileName2, Encoding.ASCII.GetBytes(fileName), Encoding.ASCII.GetBytes(fileNameExtensions[n]));
                        // 1st data file was loaded into "fileBuf1",
                        // so we load the 2nd one into "fileBuf2".
                        // Do not load the first file again if names are equal.
                        if (fileName.Substring(0, fileName2.Length) != fileName2.Substring(0, fileName2.Length))
                        {
                            try
                            {
                                List <byte> fileBuf2 = new List <byte>();

                                loadFile(fileName2, ref fileBuf2);
                                // Check if tunes in wrong order and therefore swap them here
                                if (fileNameExtensions[n] == ".mus")
                                {
                                    SidTuneBase s2 = (new MUS()).load(fileBuf2.ToArray(), fileBuf1.ToArray(), 0, true);
                                    if (s2 != null)
                                    {
                                        s2.acceptSidTune(fileName2, fileName, ref fileBuf2, separatorIsSlash);
                                        return(s2);
                                    }
                                }
                                else
                                {
                                    SidTuneBase s2 = (new MUS()).load(fileBuf1.ToArray(), true);
                                    if (s2 != null)
                                    {
                                        s2.acceptSidTune(fileName, fileName2, ref fileBuf1, separatorIsSlash);
                                        return(s2);
                                    }
                                }
                                // The first tune loaded ok, so ignore errors on the
                                // second tune, may find an ok one later
                            }
                            catch (loadError)
                            {
                            }
                        }
                        n++;
                    }
                }
            }
            if (s == null)
            {
                s = p00.load(fileName, aryFileBuf1);
            }
            if (s == null)
            {
                s = prg.load(fileName, aryFileBuf1);
            }
            if (s == null)
            {
                throw new loadError(ERR_UNRECOGNIZED_FORMAT);
            }

            s.acceptSidTune(fileName, null, ref fileBuf1, separatorIsSlash);
            return(s);
        }