Ejemplo n.º 1
0
        private FormatoAlternancia ArquivoALTAssembly(Byte[] file)
        {
            FormatoAlternancia fa = new FormatoAlternancia();

            if (file != null)
            {
                fa.versao          = file[0];
                fa.QtdAlternancias = file[1];

                unsafe
                {
                    for (int i = 0; i < 60; i++)
                    {
                        fa.reservado[i] = file[i + 2];
                    }
                }

                fa.crc = (UInt16)(file[62] << 8);
                fa.crc = (UInt16)(fa.crc + ((byte)(file[63])));

                //montagem dos itens de alternancia.
                for (int i = 0; i < fa.QtdAlternancias; i++)
                {
                    //1 7 32
                    ItemAlternancia item = new ItemAlternancia();

                    byte[] dados = new byte[40];
                    Array.Copy(file, 64 + (i * 40), dados, 0, 40);
                    item.fromByteArray(dados);
                    //item.qntExibicoes = ((byte)file[i + 64]); //no setter;
                    ////qtd 40 bytes
                    //for(int exibicoes = 0; exibicoes < 7; exibicoes++)
                    //{
                    //    item.Exibicoes.Add((TipoExibicao) file[exibicoes + 65]);
                    //}

                    //Byte[] nomeTemp = new byte[32];
                    //for (int nome = 0; nome < 32; nome++)
                    //     nomeTemp[nome] = file[nome + 72];

                    //item.NomeAlternancia = System.Text.Encoding.Default.GetString(nomeTemp);

                    this.listaAlternancias.Add(item);
                }
            }
            else
            {
                throw new Exception(rm.GetString("ARQUIVO_ALT_ERRO_NULO_ARQUIVO")); //"Arquivo de Alternância nulo em ArquivoALTAssembly - Arquivo_ALT.cs");
            }

            return(fa);
        }
Ejemplo n.º 2
0
        public override object Abrir(string arquivoNome)
        {
            byte[] fileBytes = null;

            this.ArquivoNome = arquivoNome;

            FormatoAlternancia fa = new FormatoAlternancia();

            unsafe
            {
                //fileBytes = new byte[sizeof (FormatoAlternancia)];

                if (!VerificarIntegridade(arquivoNome))
                {
                    throw new Exception(rm.GetString("ARQUIVO_ALT_ERRO_ARQUIVO_CORROMPIDO")); //"Arquivo Corrompido!!!");
                }
                else
                {
                    FileStream fs = File.OpenRead(arquivoNome);
                    fileBytes = new byte[(int)fs.Length];
                    fs.Read(fileBytes, 0, fileBytes.Length);
                    fs.Close();

                    fa = ArquivoALTAssembly(fileBytes);

                    this.versao = fa.versao;
                    for (int i = 0; i < 60; i++)
                    {
                        this.reservado[i] = fa.reservado[i];
                    }

                    this.crc = fa.crc;
                }
            }

            return(fa);
        }