Beispiel #1
0
        static bool verifyChecksum(int start, int end, byte[] arrayBytes)
        {
            int originalValue = BitConverter.ToInt32(arrayBytes, 22);

            arrayBytes[start + 22] = Convert.ToByte(0);
            arrayBytes[start + 23] = Convert.ToByte(0);
            arrayBytes[start + 24] = Convert.ToByte(0);
            arrayBytes[start + 25] = Convert.ToByte(0);

            return((originalValue - OggCrc.checksum(0, arrayBytes, start, end - start)) == 0);
        }
Beispiel #2
0
        public static void AppendOggFilesMain()
        {
            DirectoryInfo di = new DirectoryInfo(urlFolder);


            FileInfo[] files = di.GetFiles("*.txt");



            byte[] oggs = Encoding.ASCII.GetBytes("OggS");

            for (int k = 0; k < files.Length; k++)
            {
start:
                getDataArray(files[k].FullName);

                byte[] file1Bytes;

                try
                {
                    file1Bytes = File.ReadAllBytes(getFileNameFromPath(OggFilesArray[0][1], urlFolder));
                }
                catch (FileNotFoundException e)
                {
                    k++;
                    if (k >= files.Length)
                    {
                        goto end;
                    }
                    else
                    {
                        goto start;
                    }
                }


                List <int> places = FindCharsInArray(file1Bytes, oggs, false);

                List <OggPageAdaption> pages = new List <OggPageAdaption>(places.Count);

                OggPageAdaption previousOggPageAdaption = new OggPageAdaption(file1Bytes, places[places.Count - 1]);
                UInt32          previous_page_sequence_number_uint32 = previousOggPageAdaption.page_sequence_number_uint32;

                UInt64 previous_granule_position_u64 = 0;
                previous_granule_position_u64 = previousOggPageAdaption.granule_position_u64;
                using (FileStream fs = new FileStream(urlFolderOutput + files[k].Name.Substring(0, files[k].Name.Length - 4) + ".ogg", FileMode.Append))
                {
                    fs.Write(file1Bytes, 0, file1Bytes.Length);



                    for (int j = 1; j < OggFilesArray.Count; j++)
                    {
                        byte[] file2Bytes = File.ReadAllBytes(getFileNameFromPath(OggFilesArray[j][1], urlFolder));



                        List <int> places2 = FindCharsInArray(file2Bytes, oggs, false);



                        OggPageAdaption newOggPageAdaption = new OggPageAdaption();



                        for (int i = 0; i < places2.Count; i++)
                        {
                            Array.Copy(previousOggPageAdaption.bitstream_serial_number, 0, file2Bytes, places2[i] + 14, 4);
                            newOggPageAdaption = new OggPageAdaption(file2Bytes, places2[i]);


                            var finalGranule_position_u64 = newOggPageAdaption.granule_position_u64 + previous_granule_position_u64;

                            byte[] finalGranule_position = BitConverter.GetBytes(finalGranule_position_u64);

                            Array.Copy(finalGranule_position, 0, file2Bytes, places2[i] + 6, 8);


                            var newPage_sequence_number_uint32 = previous_page_sequence_number_uint32;

                            if (i > 1)
                            {
                                newPage_sequence_number_uint32 = previous_page_sequence_number_uint32 + 1;
                            }

                            var newPage_secuence_number = BitConverter.GetBytes(newPage_sequence_number_uint32);

                            Array.Copy(newPage_secuence_number, 0, file2Bytes, places2[i] + 18, 4);



                            previous_page_sequence_number_uint32 = newPage_sequence_number_uint32;


                            int end   = 0;
                            int start = places2[i];
                            if (i >= places2.Count - 1)
                            {
                                end = file2Bytes.Length - 1;
                            }
                            else
                            {
                                end = places2[i + 1];
                            }
                            if (i >= places2.Count - 1)
                            {
                                end = file2Bytes.Length;
                            }

                            file2Bytes[places2[i] + 22] = Convert.ToByte(0);
                            file2Bytes[places2[i] + 23] = Convert.ToByte(0);
                            file2Bytes[places2[i] + 24] = Convert.ToByte(0);
                            file2Bytes[places2[i] + 25] = Convert.ToByte(0);

                            int checkSum = OggCrc.checksum(0, file2Bytes, start, end - start);


                            byte[] crc = BitConverter.GetBytes(checkSum);

                            file2Bytes[places2[i] + 22] = crc[0];
                            file2Bytes[places2[i] + 23] = crc[1];
                            file2Bytes[places2[i] + 24] = crc[2];
                            file2Bytes[places2[i] + 25] = crc[3];
                        }

                        previous_granule_position_u64 = previous_granule_position_u64 + newOggPageAdaption.granule_position_u64;

                        fs.Write(file2Bytes, places2[2], file2Bytes.Length - places2[2]);

                        previousOggPageAdaption = newOggPageAdaption;



                        File.Move(urlFolder + getFileNameFromPath(OggFilesArray[j][1], ""), urlFolder + "archive/" + getFileNameFromPath(OggFilesArray[j][1], ""));
                    }
                }



                files[k].MoveTo(urlFolder + "archive/" + files[k].Name);
            }

            end : int a = 1;
        }