Esempio n. 1
0
 public MyDSI3(IPEndPoint afp)
 {
     Sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     Sock.Connect(afp);
     st = new NetworkStream(Sock, false);
     br = new BER(st);
     t  = new Thread(this.Receiver);
     t.Start();
 }
Esempio n. 2
0
        /// <summary>
        /// Function that will parse other sound files(VAG?)
        /// </summary>
        /// <param name="fs">Stream of the file</param>
        /// <returns></returns>
        public static Wavo[] ReadIV(Stream fs)
        {
            var binaryReader = new BinaryReader(fs);
            var bER          = new BER(binaryReader);

            fs.Position = 12L;
            int num   = binaryReader.ReadInt32();
            var array = new KeyValuePair <int, int> [num];

            fs.Position = 16L;
            for (int i = 0; i < num; i++)
            {
                int num2 = binaryReader.ReadInt32();
                if (num2 >= 0)
                {
                    num2 += 16 + 8 * num;
                }
                int value = binaryReader.ReadInt32();
                array[i] = new KeyValuePair <int, int>(num2, value);
            }
            var list = new List <Wavo>();

            for (int j = 0; j < array.Length; j++)
            {
                int key = array[j].Key;
                if (key >= 0)
                {
                    fs.Position = key + 12;
                    int count = bER.ReadInt32() - 32;
                    fs.Position = key + 16;
                    int nSamplesPerSec = bER.ReadInt32();
                    fs.Position = key + 64;
                    list.Add(new Wavo(j.ToString("00") + ".wav",
                                      SPUConv.ToWave(new MemoryStream(binaryReader.ReadBytes(count)), nSamplesPerSec)));
                }
            }
            return(list.ToArray());
        }
		private void GetTreeNodeFromNode( BER.CDCat.Export.TreeNode dir, System.Windows.Forms.TreeNode node ) {
			foreach ( System.Windows.Forms.TreeNode nodeChild in node.Nodes ) {
				BER.CDCat.Export.TreeNode child = new BER.CDCat.Export.TreeNode();
				child.Name = nodeChild.Text;
				child.Length = 10;
				child.IsDirectory = ( nodeChild.Nodes.Count > 0 );
				child.CreationTime = DateTime.Now;

				if ( child.IsDirectory ) {
					GetTreeNodeFromNode( child, nodeChild );
					dir.Directories.Add( child );
				} else {
					dir.Files.Add( child );
				}


			}
		}
Esempio n. 4
0
 public TransmitRes(DSIPack pack)
 {
     this.pack = pack;
     this.br   = new BER(new MemoryStream(pack.Payload, false));
 }
Esempio n. 5
0
		public void DoExport( BER.CDCat.Export.TreeNode volume, string fileName ) {
			m_volume = volume;
			m_fileName = fileName;
			m_creator.Tree2Iso( m_volume, m_fileName );
		}
Esempio n. 6
0
			public IsoCreatorTreeArgs( BER.CDCat.Export.TreeNode volume, string isoPath ) {
				m_volume = volume;
				m_isoPath = isoPath;
			}
Esempio n. 7
0
		/// <summary>
		/// Writes an ISO with the contains of the tree given as a parameter, to the specified path.
		/// </summary>
		/// <param name="volume">The directory structure to be turned into an iso.</param>
		/// <param name="isoPath">The path of the iso file to be created.</param>
		public void Tree2Iso( BER.CDCat.Export.TreeNode volume, string isoPath ) {
			try {
				FileStream isoFileStream = new FileStream( isoPath, FileMode.Create );
				BinaryWriter writer = new BinaryWriter( isoFileStream );
				try {
					this.Tree2Iso( volume, writer );

					writer.Close();
					isoFileStream.Close();

					this.OnFinished( "ISO writing process finished succesfully" );
				} catch ( Exception ex ) {
					writer.Close();
					isoFileStream.Close();
					throw ex;
				}
			} catch ( System.Threading.ThreadAbortException ex ) {
                System.Diagnostics.Debug.WriteLine(ex.Message);
				this.OnAbort( "Aborted by user" );
			} catch ( Exception ex ) {
				this.OnAbort( ex.Message );
			}
		}
Esempio n. 8
0
		/// <summary>
		/// Writes an ISO with the contains of the tree given as a parameter.
		/// This is a "virtual" ISO, which means that you will find on it only a directory structure;
		/// files will actually not ocupy any space on it. (For a better picture of what happens here,
		/// run the VirtualIsoCreator form in Forms namespace. There is a demo. Also, if you have CDCat 
		/// installed on your PC, you should know by now the effect of the method below. Within CDCat, 
		/// this method is used through the ExportIso class in BER.CDCat.Export namespace)
		/// </summary>
		/// <param name="volume">The directory structure to be turned into an iso.</param>
		/// <param name="writer">A binary writer to write the data.</param>
		private void Tree2Iso( BER.CDCat.Export.TreeNode volume, BinaryWriter writer ) {

			ArrayList dirList;
			IsoDirectory[] dirArray;

			this.OnProgress( "Initializing ISO root directory...", 0, 1 );

			IsoDirectory root = new IsoDirectory( volume, 1, "0", Progress );

			//
			// Folder structure and path tables corresponding to the Primary Volume Descriptor:
			//

			this.OnProgress( "Preparing first set of directory extents...", 0, 1 );

			dirList = new ArrayList();
			dirList.Add( root );

			// Set all extents corresponding to the primary volume descriptor;
			// Memorize the SORTED directories in the dirList list.
			// The first extent (corresponding to the root) should be at the 19th sector 
			// (which is the first available sector: 0-15 are empty and the next 3 (16-18) 
			// are occupied by the volume descriptors).
			IsoDirectory.SetExtent1( dirList, 0, 19 );

			this.OnProgress( 1 );

			this.OnProgress( "Calculating directory numbers...", 0, 1 );

			dirArray = new IsoDirectory[dirList.Count];
			dirList.ToArray().CopyTo( dirArray, 0 );		// Copy to an array the sorted directory list.

			this.SetDirectoryNumbers( dirArray );			// Set the directory numbers, used in the path tables.

			this.OnProgress( 1 );

			this.OnProgress( "Preparing first set of path tables...", 0, 2 );

			// Create a memory stream where to temporarily save the path tables. 
			// (We can't write them directly to the file, because we first have to write - by convention - 
			// the directories. For now, we cannot do that, since we don't know the files' extents.
			// Those will be calculated later, when we know the actual size of the path tables, because
			// the files come at the end of the file, after the path tables.)
			// I used this algorihm, although a little backword, since this is the algorithm NERO uses,
			// and I gave them credit for choosing the best one ;)
			MemoryStream memory1 = new MemoryStream();
			BinaryWriter memoryWriter1 = new BinaryWriter( memory1 );

			// Calculate the position of the first little endian path table, which comes right after the last directory.
			IsoDirectory lastDir = dirArray[dirArray.Length-1];
			UInt32 typeLPathTable1 = lastDir.Extent1 + lastDir.Size1/IsoAlgorithm.SectorSize;

			this.WritePathTable( memoryWriter1, dirArray, Endian.LittleEndian, VolumeType.Primary );

			this.OnProgress( 1 );

			// Calculate the position of the first big endian path table.
			UInt32 typeMPathTable1 = typeLPathTable1 + (UInt32)( memory1.Length )/IsoAlgorithm.SectorSize;

			UInt32 pathTableSize1 = (UInt32)this.WritePathTable( memoryWriter1, dirArray, Endian.BigEndian, VolumeType.Primary );

			this.OnProgress( 2 );

			//
			// end
			//

			//
			// Folder structure and path tables corresponding to the Suplementary Volume Descriptor:
			//

			this.OnProgress( "Preparing second set of directory extents...", 0, 1 );

			dirList = new ArrayList();
			dirList.Add( root );

			UInt32 currentExtent = typeLPathTable1 + (UInt32)( memory1.Length )/IsoAlgorithm.SectorSize;

			IsoDirectory.SetExtent2( dirList, 0, currentExtent );

			dirArray = new IsoDirectory[dirList.Count];
			dirList.ToArray().CopyTo( dirArray, 0 );

			this.OnProgress( 1 );

			this.OnProgress( "Preparing second set of path tables...", 0, 2 );

			MemoryStream memory2 = new MemoryStream();
			BinaryWriter memoryWriter2 = new BinaryWriter( memory2 );

			lastDir = dirArray[dirArray.Length-1];
			UInt32 typeLPathTable2 = lastDir.Extent2 + lastDir.Size2/IsoAlgorithm.SectorSize;

			this.WritePathTable( memoryWriter2, dirArray, Endian.LittleEndian, VolumeType.Suplementary );

			this.OnProgress( 1 );

			UInt32 typeMPathTable2 = typeLPathTable2 + (UInt32)( memory2.Length )/IsoAlgorithm.SectorSize;

			UInt32 pathTableSize2 = (UInt32)this.WritePathTable( memoryWriter2, dirArray, Endian.BigEndian, VolumeType.Suplementary );

			this.OnProgress( 2 );

			//
			// end
			//

			this.OnProgress( "Initializing...", 0, 1 );

			// Now that we know the extents and sizes of all directories and path tables, 
			// all that remains is to calculate files extent. However, this being a virtual ISO,
			// it won't memorize real files, but only images of files, which will apear to have a real size,
			// but in fact, won't occupy any more space. So we will leave all the files' extents null (0).

			// Calculate the total size in sectors of the file to be made.
			UInt32 volumeSpaceSize = 19;
			volumeSpaceSize += root.TotalDirSize;	// This only calculates the size of the directories, without the files.
			volumeSpaceSize += (UInt32)memory1.Length / IsoAlgorithm.SectorSize;
			volumeSpaceSize += (UInt32)memory2.Length / IsoAlgorithm.SectorSize;

			// Prepare the buffers for the path tables.
			byte[] pathTableBuffer1 = memory1.GetBuffer();
			Array.Resize( ref pathTableBuffer1, (int)memory1.Length );

			byte[] pathTableBuffer2 = memory2.GetBuffer();
			Array.Resize( ref pathTableBuffer2, (int)memory2.Length );

			// Close the memory streams.
			memory1.Close();
			memory2.Close();
			memoryWriter1.Close();
			memoryWriter2.Close();

			this.OnProgress( 1 );

			//
			// Now all we have to do is to write all information to the ISO:
			//

			this.OnProgress( "Writing data to file...", 0, (int)volumeSpaceSize );

			// First, write the 16 empty sectors.
			this.WriteFirst16EmptySectors( writer );

			this.OnProgress( (int)(writer.BaseStream.Length/IsoAlgorithm.SectorSize) );

			// Write the three volume descriptors.
			this.WriteVolumeDescriptors(
				writer, volume.Name, root,
				volumeSpaceSize,
				pathTableSize1, pathTableSize2,
				typeLPathTable1, typeMPathTable1,
				typeLPathTable2, typeMPathTable2 );

			this.OnProgress( (int)( writer.BaseStream.Length/IsoAlgorithm.SectorSize ) );

			// Write the directories in a manner corresponding to the Primary Volume Descriptor.
			this.WriteDirectories( writer, dirArray, VolumeType.Primary );

			// Write the first two path tables.
			writer.Write( pathTableBuffer1 );

			this.OnProgress( (int)( writer.BaseStream.Length/IsoAlgorithm.SectorSize ) );

			// Write the directories in a manner corresponding to the Suplementary Volume Descriptor.
			this.WriteDirectories( writer, dirArray, VolumeType.Suplementary );

			// Write the other two path tables.
			writer.Write( pathTableBuffer2 );

			this.OnProgress( (int)( writer.BaseStream.Length/IsoAlgorithm.SectorSize ) );

			// If this were an ISO with real files, this is the part where we would write the files.

			// That's it ;)
		}