Exemplo n.º 1
0
        public void Add_Files(ref Folder files, int id)
        {
            Sound file = SearchFile(id, sdat.files.root); // Archivo descomprimido
            files.name = file.name;
            sdat.files.root = FileToFolder((int)file.id, sdat.files.root);
            // Archivo convertido a medias a carpeta ;)
            files.id = file.id;
            if (file.offset != 0x00) // es medio archivo :)
                files.tag = String.Format("{0:X}", file.size).PadLeft(8, '0') +
                    String.Format("{0:X}", file.offset).PadLeft(8, '0');
            else
                files.tag = String.Format("{0:X}", file.size).PadLeft(8, '0') +
                                file.path;

            files = Add_ID(files);
            Add_Files(files, (ushort)file.id, sdat.files.root);
        }
Exemplo n.º 2
0
        private void FileSystem(ref sSDAT sdat, string file)
        {
            #region Folder declaration
            Folder root = new Folder();
            root.name    = "SDAT";
            root.id      = 0x0F000;
            root.folders = new List <Folder>();

            Folder sseq, ssar, sbnk, swar, strm;
            sseq       = new Folder();
            sseq.files = new List <Sound>();
            sseq.name  = "SSEQ";
            sseq.id    = 0x0F001;

            ssar       = new Folder();
            ssar.files = new List <Sound>();
            ssar.name  = "SSAR";
            ssar.id    = 0x0F002;

            sbnk       = new Folder();
            sbnk.files = new List <Sound>();
            sbnk.name  = "SBNK";
            sbnk.id    = 0x0F003;

            swar       = new Folder();
            swar.files = new List <Sound>();
            swar.name  = "SWAR";
            swar.id    = 0x0F005;

            strm       = new Folder();
            strm.files = new List <Sound>();
            strm.name  = "STRM";
            strm.id    = 0x0F006;
            #endregion

            BinaryReader br = new BinaryReader(new FileStream(file, FileMode.Open));
            for (int i = 0; i < sdat.fat.header.nRecords; i++)
            {
                br.BaseStream.Position = sdat.fat.records[i].offset;

                Sound sound = new Sound();
                sound.offset     = sdat.fat.records[i].offset;
                sound.size       = sdat.fat.records[i].size;
                sound.internalID = (uint)i;

                string magic = new String(Encoding.ASCII.GetChars(br.ReadBytes(4)));
                switch (magic)
                {
                case "SSEQ":
                    sound.type = FormatSound.SSEQ;
                    sound.name = "SSEQ_" + i.ToString() + ".sseq";
                    sseq.files.Add(sound);
                    break;

                case "SSAR":
                    sound.type = FormatSound.SSAR;
                    sound.name = "SSAR_" + i.ToString() + ".ssar";
                    ssar.files.Add(sound);
                    break;

                case "SBNK":
                    sound.type = FormatSound.SBNK;
                    sound.name = "SBNK_" + i.ToString() + ".sbnk";
                    sbnk.files.Add(sound);
                    break;

                case "SWAR":
                    sound.type = FormatSound.SWAR;
                    sound.name = "SWAR_" + i.ToString() + ".swar";
                    swar.files.Add(sound);
                    break;

                case "STRM":
                    sound.type = FormatSound.STRM;
                    sound.name = "STRM_" + i.ToString() + ".strm";
                    strm.files.Add(sound);
                    break;
                }
            }
            br.Close();

            root.folders.Add(sseq);
            root.folders.Add(ssar);
            root.folders.Add(sbnk);
            root.folders.Add(swar);
            root.folders.Add(strm);

            sdat.files.root = root;
        }
Exemplo n.º 3
0
        private TreeNode CarpetaToNodo(Folder carpeta)
        {
            TreeNode currNode = new TreeNode();

            currNode = new TreeNode(carpeta.name, 0, 0);
            currNode.Tag = carpeta.id;
            currNode.Name = carpeta.name;

            if (carpeta.folders is List<Folder>)
                foreach (Folder subFolder in carpeta.folders)
                    currNode.Nodes.Add(CarpetaToNodo(subFolder));

            if (carpeta.files is List<Sound>)
            {
                foreach (Sound archivo in carpeta.files)
                {
                    int formato = FormatoToImage(archivo.type);
                    TreeNode fileNode = new TreeNode(archivo.name, formato, formato);
                    fileNode.Name = archivo.name;
                    fileNode.Tag = archivo.id;
                    currNode.Nodes.Add(fileNode);
                }
            }

            return currNode;
        }
Exemplo n.º 4
0
        private void RecursivoExtractFolder(Folder currFolder, String path)
        {
            if (currFolder.files is List<Sound>)
                foreach (Sound archivo in currFolder.files)
                {
                    BinaryReader br = new BinaryReader(File.OpenRead(sdat.archivo));
                    br.BaseStream.Position = archivo.offset;

                    String fileName = archivo.name;
                    foreach (char c in Path.GetInvalidFileNameChars())
                        fileName = fileName.Replace(c.ToString(), "");
                    fileName = path + Path.DirectorySeparatorChar + fileName;

                    File.WriteAllBytes(fileName, br.ReadBytes((int)archivo.size));
                    br.Close();
                }

            if (currFolder.folders is List<Folder>)
            {
                foreach (Folder subFolder in currFolder.folders)
                {
                    string folderName = subFolder.name;
                    foreach (char c in Path.GetInvalidPathChars())
                        folderName = folderName.Replace(c.ToString(), "");
                    folderName = path + Path.DirectorySeparatorChar + folderName;

                    Directory.CreateDirectory(folderName);
                    RecursivoExtractFolder(subFolder, folderName);
                }
            }
        }
Exemplo n.º 5
0
        private Folder Add_ID(Folder currFolder)
        {
            if (currFolder.files is List<Sound>)
            {
                for (int i = 0; i < currFolder.files.Count; i++)
                {
                    Sound currFile = currFolder.files[i];
                    currFile.id = (ushort)lastFileID;
                    currFolder.files.RemoveAt(i);
                    currFolder.files.Insert(i, currFile);
                    lastFileID++;
                }
            }

            if (currFolder.folders is List<Folder>)
            {
                for (int i = 0; i < currFolder.folders.Count; i++)
                {
                    Folder newFolder = Add_ID(currFolder.folders[i]);
                    newFolder.name = currFolder.folders[i].name;
                    newFolder.id = (ushort)lastFolderID;
                    lastFolderID++;
                    currFolder.folders.RemoveAt(i);
                    currFolder.folders.Insert(i, newFolder);
                }
            }

            return currFolder;
        }
Exemplo n.º 6
0
        private void btnUncompress_Click(object sender, EventArgs e)
        {
            System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Load(Application.StartupPath + Path.DirectorySeparatorChar +
                "Plugins" + Path.DirectorySeparatorChar + "SDATLang.xml");
            xml = xml.Element(pluginHost.Get_Language());
            xml = xml.Element("iSDAT");

            if (btnUncompress.Text == xml.Element("S07").Value)
            {
                #region Unpack SWAR file
                string swar = SaveFile();

                sSWAV[] archivos = SWAR.ConvertToSWAV(SWAR.Read(swar));
                string[] swav = new string[archivos.Length];

                Folder carpeta = new Folder();
                carpeta.name = SearchFile().name;
                carpeta.files = new List<Sound>();

                for (int i = 0; i < archivos.Length; i++)
                {
                    swav[i] = pluginHost.Get_TempFolder() + '\\' + Path.GetRandomFileName();
                    SWAV.Write(archivos[i], swav[i]);

                    Sound newSound = new Sound();
                    newSound.id = lastFileID;
                    lastFileID++;
                    newSound.internalID = newSound.id;
                    newSound.name = "SWAV_" + i.ToString() + ".swav";
                    newSound.offset = 0x00;
                    newSound.type = FormatSound.SWAV;
                    newSound.path = swav[i];
                    newSound.size = (uint)new FileInfo(swav[i]).Length;

                    carpeta.files.Add(newSound);
                }

                // Lo añadimos al nodo
                Add_Files(ref carpeta, (int)SearchFile().id);

                TreeNode selected = treeFiles.SelectedNode;
                selected = CarpetaToNodo(carpeta);

                // Agregamos los nodos al árbol
                TreeNode[] nodos = new TreeNode[selected.Nodes.Count];
                selected.Nodes.CopyTo(nodos, 0);
                treeFiles.SelectedNode.Tag = selected.Tag;
                selected.Nodes.Clear();

                treeFiles.SelectedNode.Nodes.AddRange((TreeNode[])nodos);
                treeFiles.SelectedNode.Expand();
                #endregion
                btnUncompress.Text = xml.Element("S12").Value;
            }
            else
            {
                #region Pack SWAR file
                Folder swar = SearchFolder(Convert.ToInt32(treeFiles.SelectedNode.Tag), sdat.files.root);
                List<sSWAV> sounds = new List<sSWAV>();

                for (int i = 0; i < swar.files.Count; i++)
                {
                    String tempFile = SaveFile((int)swar.files[i].id);
                    sSWAV swav = SWAV.Read(tempFile);
                    sounds.Add(swav);
                    File.Delete(tempFile);
                }

                String fileout = Path.GetTempFileName();
                SWAR.Write(sounds.ToArray(), fileout);
                ChangeFile(Convert.ToInt32(treeFiles.SelectedNode.Tag), fileout);
                #endregion
            }
        }
Exemplo n.º 7
0
 private static int Comparacion_Directorios(Folder f1, Folder f2)
 {
     return String.Compare(f1.name, f2.name);
 }
Exemplo n.º 8
0
        private Folder SearchFolder(int id, Folder carpeta)
        {
            if (carpeta.id == id)
                return carpeta;

            if (carpeta.folders is List<Folder>)
            {
                foreach (Folder subFolder in carpeta.folders)
                {
                    if (subFolder.id == id)
                        return subFolder;

                    Folder folder = SearchFolder(id, subFolder);
                    if (folder.name is string)
                        return folder;
                }
            }

            return new Folder();
        }
Exemplo n.º 9
0
        public void Set_LastFileID(Folder currFolder)
        {
            if (currFolder.files is List<Sound>)
                foreach (Sound archivo in currFolder.files)
                    if (archivo.id > lastFileID)
                        lastFileID = archivo.id;

            if (currFolder.folders is List<Folder>)
                foreach (Folder subFolder in currFolder.folders)
                    Set_LastFileID(subFolder);
        }
Exemplo n.º 10
0
        public void Set_LastFolderID(Folder currFolder)
        {
            if (currFolder.id > lastFolderID)
                lastFolderID = currFolder.id;

            if (currFolder.folders is List<Folder>)
                foreach (Folder subFolder in currFolder.folders)
                    Set_LastFolderID(subFolder);
        }
Exemplo n.º 11
0
        public Folder FileToFolder(int id, Folder currFolder)
        {
            if (currFolder.files is List<Sound>)
            {
                for (int i = 0; i < currFolder.files.Count; i++)
                {
                    if (currFolder.files[i].id == id)
                    {
                        Folder newFolder = new Folder();
                        newFolder.name = currFolder.files[i].name;
                        newFolder.id = currFolder.files[i].id;
                        if (currFolder.files[i].offset != 0x00) // es medio archivo :)
                            newFolder.tag = String.Format("{0:X}", currFolder.files[i].size).PadLeft(8, '0') +
                                String.Format("{0:X}", currFolder.files[i].offset).PadLeft(8, '0');
                        else
                            newFolder.tag = String.Format("{0:X}", currFolder.files[i].size).PadLeft(8, '0') +
                                            currFolder.files[i].path;

                        currFolder.files.RemoveAt(i);
                        if (!(currFolder.folders is List<Folder>))
                            currFolder.folders = new List<Folder>();
                        currFolder.folders.Add(newFolder);
                        return currFolder;
                    }
                }
            }

            if (currFolder.folders is List<Folder>)
            {
                foreach (Folder subFolder in currFolder.folders)
                {
                    Folder folder = FileToFolder(id, subFolder);
                    if (folder.name is string)
                    {
                        currFolder.folders.Remove(subFolder);
                        currFolder.folders.Add(folder);
                        return currFolder;
                    }
                }
            }

            return new Folder();
        }
Exemplo n.º 12
0
        public void ChangeFile(int id, Sound fileChanged, Folder currFolder)
        {
            if (currFolder.files is List<Sound>)
            {
                for (int i = 0; i < currFolder.files.Count; i++)
                {
                    if (currFolder.files[i].id == id)
                    {
                        currFolder.files[i] = fileChanged;
                    }
                }
            }

            if (currFolder.folders is List<Folder>)
            {
                for (int i = 0; i < currFolder.folders.Count; i++)
                {
                    if (currFolder.folders[i].id == id) // It's a decompressed file
                    {
                        Folder newFolder = currFolder.folders[i];
                        newFolder.tag = fileChanged.tag;
                        currFolder.folders[i] = newFolder;
                    }
                    else
                        ChangeFile(id, fileChanged, currFolder.folders[i]);
                }
            }
        }
Exemplo n.º 13
0
        public Folder Add_Files(Folder files, ushort idFolder, Folder currFolder)
        {
            if (currFolder.id == idFolder)
            {
                currFolder = files;
                return currFolder;
            }

            if (currFolder.folders is List<Folder>)   // Si tiene subdirectorios, buscamos en cada uno de ellos
            {
                for (int i = 0; i < currFolder.folders.Count; i++)
                {
                    Folder folder = Add_Files(files, idFolder, currFolder.folders[i]);
                    if (folder.name is string)  // Comprobamos que se haya devuelto un directorio, en cuyo caso es el buscado que lo devolvemos
                    {
                        currFolder.folders[i] = folder;
                        return currFolder;
                    }
                }
            }

            return new Folder();
        }
Exemplo n.º 14
0
Arquivo: SDAT.cs Projeto: MetLob/tinke
        private void FileSystem(ref sSDAT sdat, string file)
        {
            #region Folder declaration
            Folder root = new Folder();
            root.name = "SDAT";
            root.id = 0x0F000;
            root.folders = new List<Folder>();

            Folder sseq, ssar, sbnk, swar, strm;
            sseq = new Folder();
            sseq.files = new List<Sound>();
            sseq.name = "SSEQ";
            sseq.id = 0x0F001;

            ssar = new Folder();
            ssar.files = new List<Sound>();
            ssar.name = "SSAR";
            ssar.id = 0x0F002;

            sbnk = new Folder();
            sbnk.files = new List<Sound>();
            sbnk.name = "SBNK";
            sbnk.id = 0x0F003;

            swar = new Folder();
            swar.files = new List<Sound>();
            swar.name = "SWAR";
            swar.id = 0x0F005;

            strm = new Folder();
            strm.files = new List<Sound>();
            strm.name = "STRM";
            strm.id = 0x0F006;
            #endregion

            BinaryReader br = new BinaryReader(new FileStream (file, FileMode.Open));
            for (int i = 0; i < sdat.fat.header.nRecords; i++)
            {
                br.BaseStream.Position = sdat.fat.records[i].offset;

                Sound sound = new Sound();
                sound.offset = sdat.fat.records[i].offset;
                sound.size = sdat.fat.records[i].size;
                sound.internalID = (uint)i;

                string magic = new String(Encoding.ASCII.GetChars(br.ReadBytes(4)));
                switch (magic)
                {
                    case "SSEQ":
                        sound.type = FormatSound.SSEQ;
                        sound.name = "SSEQ_" + i.ToString() + ".sseq";
                        sseq.files.Add(sound);
                        break;
                    case "SSAR":
                        sound.type = FormatSound.SSAR;
                        sound.name = "SSAR_" + i.ToString() + ".ssar";
                        ssar.files.Add(sound);
                        break;
                    case "SBNK":
                        sound.type = FormatSound.SBNK;
                        sound.name = "SBNK_" + i.ToString() + ".sbnk";
                        sbnk.files.Add(sound);
                        break;
                    case "SWAR":
                        sound.type = FormatSound.SWAR;
                        sound.name = "SWAR_" + i.ToString() + ".swar";
                        swar.files.Add(sound);
                        break;
                    case "STRM":
                        sound.type = FormatSound.STRM;
                        sound.name = "STRM_" + i.ToString() + ".strm";
                        strm.files.Add(sound);
                        break;
                }
            }
            br.Close();

            root.folders.Add(sseq);
            root.folders.Add(ssar);
            root.folders.Add(sbnk);
            root.folders.Add(swar);
            root.folders.Add(strm);

            sdat.files.root = root;
        }
Exemplo n.º 15
0
        private void Add_Group()
        {
            Folder group = new Folder();
            group = new Folder();
            group.name = "GROUP";
            group.id = 0x0F007;
            group.folders = new List<Folder>();

            // Add files to GROUP folder
            for (int i = 0; i < sdat.info.block[5].nEntries; i++)
            {
                Info.GROUP entry = (Info.GROUP)sdat.info.block[5].entries[i];
                Folder entryFld = new Folder();
                entryFld.name = "Entry " + i.ToString();
                entryFld.id = (uint)(0x0F008 + i);
                entryFld.files = new List<Sound>();
                for (int n = 0; n < entry.nCount; n++)
                {
                    switch (entry.subgroup[n].type)
                    {
                        case 0x700: // SSEQ
                            if (sdat.files.root.folders[0].files.Count > entry.subgroup[n].nEntry)
                                entryFld.files.Add(sdat.files.root.folders[0].files[(int)entry.subgroup[n].nEntry]);
                            break;

                        case 0x803: // SSAR
                            if (sdat.files.root.folders[1].files.Count > entry.subgroup[n].nEntry)
                                entryFld.files.Add(sdat.files.root.folders[1].files[(int)entry.subgroup[n].nEntry]);
                            break;

                        case 0x601: // SBNK
                            if (sdat.files.root.folders[2].files.Count > entry.subgroup[n].nEntry)
                                entryFld.files.Add(sdat.files.root.folders[2].files[(int)entry.subgroup[n].nEntry]);
                            break;

                        case 0x402: // SWAR
                            if (sdat.files.root.folders[3].files.Count > entry.subgroup[n].nEntry)
                                entryFld.files.Add(sdat.files.root.folders[3].files[(int)entry.subgroup[n].nEntry]);
                            break;

                        default:
                            break;
                    }
                }
                group.folders.Add(entryFld);
            }

            sdat.files.root.folders.Add(group);
        }
Exemplo n.º 16
0
Arquivo: SDAT.cs Projeto: MetLob/tinke
        private Sound SearchFile(int id, Folder currentFolder)
        {
            if (currentFolder.files is List<Sound>)
                foreach (Sound sound in currentFolder.files)
                    if (sound.id == id)
                        return sound;

            if (currentFolder.folders is List<Folder>)
            {
                foreach (Folder subFolder in currentFolder.folders)
                {
                    Sound currFile = SearchFile(id, subFolder);
                    if (currFile.name is String)
                        return currFile;
                }
            }

            return new Sound();
        }
Exemplo n.º 17
0
        private Sound SearchFile(int id, Folder carpeta)
        {
            if (carpeta.id == id) // Archivos descomprimidos
            {
                Sound folderFile = new Sound();
                folderFile.name = carpeta.name;
                folderFile.id = carpeta.id;
                if (((String)carpeta.tag).Length != 16)
                    folderFile.path = ((string)carpeta.tag).Substring(8);
                else
                    folderFile.offset = Convert.ToUInt32(((String)carpeta.tag).Substring(8), 16);
                folderFile.size = Convert.ToUInt32(((String)carpeta.tag).Substring(0, 8), 16);
                folderFile.type = (carpeta.name.ToUpper().EndsWith(".SWAR") ? FormatSound.SWAR : FormatSound.SSAR);
                folderFile.tag = "Descomprimido"; // Tag para indicar que ya ha sido procesado

                return folderFile;
            }

            if (carpeta.files is List<Sound>)
                foreach (Sound archivo in carpeta.files)
                    if (archivo.id == id)
                        return archivo;

            if (carpeta.folders is List<Folder>)
            {
                foreach (Folder subFolder in carpeta.folders)
                {
                    Sound currFile = SearchFile(id, subFolder);
                    if (currFile.name is String)
                        return currFile;
                }
            }

            return new Sound();
        }