Exemple #1
0
        /// <summary>
        /// This is the SaveSFO Function for PS3/PS4/PSVita/And PSP no longer needed for Sony's CMD
        /// </summary>
        /// <param name="psfo">SFO That has been opened</param>
        /// <param name="filename">Save Location</param>
        public void SaveSFO(PARAM_SFO psfo, string filename)
        {
            //we start by opening the stream to the file
            using (var stream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                if (!stream.CanSeek)
                {
                    throw new ArgumentException("Stream must be seekable"); //throw this error we cant seek the stream
                }
                var utf8 = new UTF8Encoding(false);                         //encoding
                using (var writer = new BinaryWriter(stream, utf8, true))   //start binary reader
                {
                    #region << Header Info (DevWiki) >>

                    /*
                     * Header
                     *  0x00	0x04	magic	PSF
                     *  0x04	0x04	version	01 01 00 00	1.01
                     *  0x08	0x04	key_table_start	24 00 00 00	Absolute start offset of key_table = 0x24
                     *  0x0C	0x04	data_table_start	30 00 00 00	Absolute start offset of data_table = 0x30
                     *  0x10	0x04	tables_entries	01 00 00 00	Number of entries in index_table, key_table, and data_table = 1
                     */

                    #endregion <<Header Info >>

                    //so lets start writing the info
                    writer.Write(Header.Magic);                                    //write magic "\0PSF"
                    writer.Write(Header.version);                                  //write version info this is mayjor and minor (01 01 00 00	1.01)
                    Header.KeyTableStart = 0x14 + Header.IndexTableEntries * 0x10; /*we can write all this lovely info from the tables back*/
                    writer.Write(Header.KeyTableStart);

                    Header.DataTableStart = Convert.ToUInt32(Header.KeyTableStart + Tables.Sum(i => i.Name.Length + 1));//needs to be Uint
                    if (Header.DataTableStart % 4 != 0)
                    {
                        Header.DataTableStart = (Header.DataTableStart / 4 + 1) * 4;
                    }
                    writer.Write(Header.DataTableStart);
                    Header.IndexTableEntries = Convert.ToUInt32(Tables.Count);
                    writer.Write(Header.IndexTableEntries);

                    int lastKeyOffset   = Convert.ToInt32(Header.KeyTableStart);
                    int lastValueOffset = Convert.ToInt32(Header.DataTableStart);
                    for (var i = 0; i < Tables.Count; i++)
                    {
                        var entry = Tables[i];

                        writer.BaseStream.Seek(0x14 + i * 0x10, SeekOrigin.Begin);
                        writer.Write((ushort)(lastKeyOffset - Header.KeyTableStart));


                        writer.Write((ushort)entry.Indextable.param_data_fmt);

                        writer.Write(entry.Indextable.param_data_len);
                        writer.Write(entry.Indextable.param_data_max_len);
                        writer.Write(lastValueOffset - Header.DataTableStart);

                        writer.BaseStream.Seek(lastKeyOffset, SeekOrigin.Begin);
                        writer.Write(utf8.GetBytes(entry.Name));
                        writer.Write((byte)0);
                        lastKeyOffset = (int)writer.BaseStream.Position;

                        writer.BaseStream.Seek(lastValueOffset, SeekOrigin.Begin);
                        writer.Write(entry.ValueBuffer);
                        lastValueOffset = (int)writer.BaseStream.Position;
                    }

                    //I'm doing this to just rewrite the first item (Some Cleanup will be needed)
                    //Or maybe not as when I checked this gives a 1 - 1 match with how the Sony tool works
                    //we need to rewrite that first item (PS4/PS3/PSV should be APP-VER)
                    lastKeyOffset   = Convert.ToInt32(Header.KeyTableStart);
                    lastValueOffset = Convert.ToInt32(Header.DataTableStart);

                    var tableentry = Tables[0];

                    writer.BaseStream.Seek(lastKeyOffset, SeekOrigin.Begin);
                    writer.Write(utf8.GetBytes(tableentry.Name));
                    writer.Write((byte)0);
                    lastKeyOffset = (int)writer.BaseStream.Position;
                }
            }
        }
    void Update()
    {
        if (EnEditorTexto)
        {
            if ((Input.GetAxis("dpad1_vertical") > 0 || Input.GetAxis("leftstick1vertical") < 0 || Input.GetAxis("rightstick1vertical") < 0 || Input.GetKey(KeyCode.UpArrow)) && PanelEditorTexto.GetComponentInChildren <Scrollbar>().value < 1 && Paso)
            {
                Paso = false;
                PanelEditorTexto.GetComponentInChildren <Scrollbar>().value += 0.05f;
                StartCoroutine(SeguirPasando());
            }

            if ((Input.GetAxis("dpad1_vertical") < 0 || Input.GetAxis("leftstick1vertical") > 0 || Input.GetAxis("rightstick1vertical") > 0 || Input.GetKey(KeyCode.DownArrow)) && PanelEditorTexto.GetComponentInChildren <Scrollbar>().value > 0 && Paso)
            {
                Paso = false;
                PanelEditorTexto.GetComponentInChildren <Scrollbar>().value -= 0.05f;
                StartCoroutine(SeguirPasando());
            }
        }

        if (!EnOpciones && !EnImagen && !Pegando && !EnEditorTexto && !EnTeclado)
        {
            // multiselecion
            if (Input.GetKeyDown(KeyCode.Joystick1Button5) || Input.GetKeyDown(KeyCode.M))
            {
                // selecionar todos si RT esta presionado...
                if (!Directory.Exists(camino) && Input.GetAxis("joystick1_right_trigger") != 0) // Input.GetKey(KeyCode.LeftShift)
                {
                    Multiseleccion        = true;
                    MultiseleccionCopiada = false;
                    MultiseleccionCortada = false;
                    ObjetosSelecionados.Clear();
                    ObjetosCaminos.Clear();

                    for (int i = 0; i < TODOS.Count; i++)
                    {
                        if (!Directory.Exists(TODOS[i]))
                        {
                            ObjetosSelecionados.Add(i);
                            ObjetosCaminos.Add(TODOS[i]);
                            ObjetosCreados[i].transform.GetChild(1).gameObject.SetActive(true);
                        }
                    }

                    return;
                }

                if (!Multiseleccion)
                {
                    ObjetosCaminos.Clear();
                }

                Multiseleccion = true;
                bool ok = true;
                for (int i = 0; i < ObjetosSelecionados.Count; i++)
                {
                    if (ObjetosSelecionados[i] == Posicion)
                    {
                        if (MultiseleccionCopiada || MultiseleccionCortada)
                        {
                            MultiseleccionCopiada = false;
                            MultiseleccionCortada = false;
                            ObjetosSelecionados.Clear();
                        }

                        ObjetosSelecionados.RemoveAt(i);
                        ObjetosCaminos.RemoveAt(i);
                        ObjetosCreados[Posicion].transform.GetChild(1).gameObject.SetActive(false);
                        ok = false;
                    }
                }

                if (ok == true)
                {
                    if (!Directory.Exists(camino))
                    {
                        if (MultiseleccionCopiada || MultiseleccionCortada)
                        {
                            MultiseleccionCopiada = false;
                            MultiseleccionCortada = false;
                            ObjetosSelecionados.Clear();
                        }

                        ObjetosSelecionados.Add(Posicion);
                        ObjetosCaminos.Add(camino);
                        ObjetosCreados[Posicion].transform.GetChild(1).gameObject.SetActive(true);
                    }
                }
                if (ObjetosSelecionados.Count == 0)
                {
                    Multiseleccion = false;
                }
            }

            // cancelar multiselecion
            if (Input.GetKeyDown(KeyCode.Joystick1Button4) || Input.GetKeyDown(KeyCode.C))
            {
                ObjetosSelecionados.Clear();
                ObjetosCaminos.Clear();
                Multiseleccion        = false;
                MultiseleccionCopiada = false;
                MultiseleccionCortada = false;

                for (int i = 0; i < scaneo.Length; i++)
                {
                    ObjetosCreados[i].transform.GetChild(1).gameObject.SetActive(false);
                }
            }

            // movimientos arriba y abajo
            if ((Input.GetAxis("dpad1_vertical") > 0 || Input.GetAxis("leftstick1vertical") < 0 || Input.GetAxis("rightstick1vertical") < 0 || Input.GetKey(KeyCode.UpArrow)) && Posicion > 0 && Paso)
            {
                Paso = false;

                ObjetosCreados[Posicion].transform.GetChild(0).gameObject.SetActive(false);
                Posicion--;
                ObjetosCreados[Posicion].transform.GetChild(0).gameObject.SetActive(true);
                camino = TODOS[Posicion];

                if (contentPanel.anchoredPosition.y > 0)
                {
                    contentPanel.anchoredPosition -= new Vector2(0, 69);
                }

                StartCoroutine(SeguirPasando());
            }

            if ((Input.GetAxis("dpad1_vertical") < 0 || Input.GetAxis("leftstick1vertical") > 0 || Input.GetAxis("rightstick1vertical") > 0 || Input.GetKey(KeyCode.DownArrow)) && Posicion < scaneo.Length - 1 && Paso)
            {
                Paso = false;

                ObjetosCreados[Posicion].transform.GetChild(0).gameObject.SetActive(false);
                Posicion++;
                ObjetosCreados[Posicion].transform.GetChild(0).gameObject.SetActive(true);
                camino = TODOS[Posicion];

                if (scrollRect.verticalNormalizedPosition >= 0 && Posicion > 9)
                {
                    contentPanel.anchoredPosition += new Vector2(0, 69);
                }

                StartCoroutine(SeguirPasando());
            }

            // accesos directos a los USB con el DPad <- , ->
            if ((Input.GetAxis("dpad1_horizontal") < 0 || Input.GetKeyDown(KeyCode.LeftArrow)) && Paso)
            {
                Paso = false;

                LOG = "";
                LimpiarTodo();
                camino = "/mnt/usb0";
                CrearDirectorio();

                StartCoroutine(SeguirPasando());
            }

            if ((Input.GetAxis("dpad1_horizontal") > 0 || Input.GetKeyDown(KeyCode.RightArrow)) && Paso)
            {
                Paso = false;

                LOG = "";
                LimpiarTodo();
                camino = "/mnt/usb1";
                CrearDirectorio();

                StartCoroutine(SeguirPasando());
            }
        }

        // abrir o ejecutar
        if (Input.GetKeyDown(KeyCode.Joystick1Button0) || Input.GetKeyDown(KeyCode.Keypad2))
        {
            try
            {
                LOG = "";

                #region << Check what file type for the ps4 this is >>

                var ps4filetype = PS4_Tools.Tools.Get_PS4_File_Type(camino);

                #endregion << Check What file type for the ps4 this is >>

                if (!EnOpciones && !Pegando && !EnEditorTexto && !EnTeclado && !EnImagen)
                {
                    if (Directory.Exists(camino)) // si es una carpeta abrirla
                    {
                        LimpiarTodo();
                        CrearDirectorio();
                    }
                    else // si no ejecutar el fichero si esta soportado
                    {
                        switch (Path.GetExtension(camino).ToLower())
                        {
                        case ".pkg":
                            var temp = PS4_Tools.PKG.SceneRelated.Read_PKG(camino);                                    // You can either use this method or the liborbis method
                            break;

                        case ".sfo":
                            var sfo = new Param_SFO.PARAM_SFO(camino);                                    //This will read an sfo and allow you to work with it as you please
                            break;

                        case ".ogg":
                        case ".wav":
                            PlayAudio();
                            break;

                        case ".mp4":
                            PlayVideo();
                            break;

                        case ".jpg":
                        case ".png":
                            MostrarImagen();
                            break;

                        case ".txt":
                        case ".ini":
                        case ".bat":
                        case ".xml":
                            MostrarTexto();
                            break;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                LOG = "Error " + ex.Message;
            }
        }

        // mostrar opciones
        if (Input.GetKeyDown(KeyCode.Joystick1Button3) || Input.GetKeyDown(KeyCode.Keypad8))
        {
            if (Input.GetAxis("joystick1_left_trigger") == 0) // normales
            {
                if (!EnImagen && !Pegando && !EnEditorTexto && !EnTeclado && !PanelOpcionesAvanzadas.gameObject.activeInHierarchy)
                {
                    if (FullRwActivado)
                    {
                        LOG        = "";
                        EnOpciones = !EnOpciones;
                        PanelOpciones.SetActive(EnOpciones);
                    }
                    else if (camino.IndexOf("/dev") != 0) // "/dev"
                    {
                        LOG        = "";
                        EnOpciones = !EnOpciones;
                        PanelOpciones.SetActive(EnOpciones);
                    }
                }
            }
            else // avanzadas
            {
                if (!EnImagen && !Pegando && !EnEditorTexto && !EnTeclado && !PanelOpciones.gameObject.activeInHierarchy)
                {
                    LOG        = "";
                    EnOpciones = !EnOpciones;
                    PanelOpcionesAvanzadas.SetActive(EnOpciones);
                }
            }
        }

        // stop musica
        if (Input.GetKeyDown(KeyCode.Joystick1Button2) || Input.GetKeyDown(KeyCode.Keypad4))
        {
            if (!EnTeclado)
            {
                LOG = "";
                miAudioSource.Stop();
            }
        }

        // atras o cerrar opciones
        if (Input.GetKeyDown(KeyCode.Joystick1Button1) || Input.GetKeyDown(KeyCode.Keypad6))
        {
            if (EnOpciones)
            {
                LOG        = "";
                EnOpciones = false;
                PanelOpciones.SetActive(false);
                PanelOpcionesAvanzadas.SetActive(false);
                return;
            }

            if (EnImagen)
            {
                LOG      = "";
                EnImagen = false;
                PanelImagen.gameObject.SetActive(false);
                PanelVideo.gameObject.SetActive(false);
                return;
            }

            if (EnEditorTexto)
            {
                LOG           = "";
                EnEditorTexto = false;
                PanelEditorTexto.gameObject.SetActive(false);
                return;
            }

            if (EnTeclado)
            {
                LOG       = "";
                EnTeclado = false;
                PanelTeclado.gameObject.SetActive(false);
                return;
            }

            if (!Pegando)
            {
                LOG = "";
                LimpiarTodo();

                camino = txtCamino.text.Substring(0, txtCamino.text.LastIndexOf("/")); // para PS4 cambiar por /
                if (camino.Length <= 1)                                                // para PS4 cambiar por 1
                {
                    camino += "/";                                                     // para PS4 cambiar por /
                }

                CrearDirectorio();
            }
        }

        // Instrucciones
        if (Input.GetKeyDown(KeyCode.Joystick1Button7) || Input.GetKeyDown(KeyCode.O))
        {
            EnImagen = true;

            PanelImagenImagen.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(1300, 900);
            PanelImagen.gameObject.SetActive(true);
            PanelImagenImagen.sprite = instrucciones;
        }

        // progressbar para cuando este pegando
        if (PanelCopiando.gameObject.activeInHierarchy)
        {
            if (CantArchivos <= 0)
            {
                PanelCopiando.gameObject.SetActive(false);
                Pegando = false;
                SistemaSonidos.instancia.PlayFinalizoCopia();
            }
            else
            {
                PanelCopiando.GetComponentInChildren <Slider>().value = PanelCopiando.GetComponentInChildren <Slider>().maxValue - CantArchivos;
            }
        }

        txtLog.text = LOG;
    }