本文整理汇总了C#中System.IO.FileStream.WriteUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.WriteUInt16方法的具体用法?C# FileStream.WriteUInt16怎么用?C# FileStream.WriteUInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了FileStream.WriteUInt16方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public static int Execute( List<string> args )
{
if ( args.Count == 0 ) {
Console.WriteLine( "This is intended to help extracting skit audio from the Xbox 360 game files." );
Console.WriteLine( "Do the following in order:" );
Console.WriteLine( "-- unpack chat.svo (FPS4 archive, with HyoutaTools -> ToVfps4e)" );
Console.WriteLine( "-- decompress individual skit with xbdecompress" );
Console.WriteLine( "-- unpack skit (FPS4 archive, with HyoutaTools -> ToVfps4e)" );
Console.WriteLine( "-- cut SE3 header from audio file to get a nub archive" );
Console.WriteLine( " (file 0004, seems to be 0x800 bytes for skits but can be bigger, first four bytes of new file should be 0x00020100)" );
Console.WriteLine( "-- extract nub archive with NUBExt r12beta" );
Console.WriteLine( "-- this gives you an \"xma\" file that isn't actually an xma, run this tool on it" );
Console.WriteLine( "-- resulting file is a valid enough xma file that can be converted to WAV with \"toWav\"" );
return -1;
}
string filename = args[0];
using ( var source = new FileStream( filename, FileMode.Open ) ) {
using ( var dest = new FileStream( filename + "-real.xma", FileMode.Create ) ) {
source.Position = 0x100;
int dataLength = (int)( source.Length - source.Position );
dest.WriteAscii( "RIFF" );
dest.WriteUInt32( (uint)dataLength + 0x34 );
dest.WriteAscii( "WAVE" );
dest.WriteAscii( "fmt " );
dest.WriteUInt32( 0x20 );
source.Position = 0xBC;
dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
dest.WriteByte( (byte)source.ReadByte() );
dest.WriteByte( (byte)source.ReadByte() );
dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
dest.WriteByte( (byte)source.ReadByte() );
dest.WriteByte( (byte)source.ReadByte() );
dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
dest.WriteAscii( "data" );
dest.WriteUInt32( (uint)dataLength );
source.Position = 0x100;
Util.CopyStream( source, dest, dataLength );
}
}
return 0;
}
示例2: Pack
public void Pack( string[] files, string outFilename, string headerName = null, string metadata = null )
{
FileCount = (uint)files.Length + 1;
HeaderSize = 0x1C;
EntrySize = 0;
if ( ContainsStartPointers ) { EntrySize += 4; }
if ( ContainsSectorSizes ) { EntrySize += 4; }
if ( ContainsFileSizes ) { EntrySize += 4; }
if ( ContainsFilenames ) { EntrySize += 0x20; }
if ( ContainsFiletypes ) { EntrySize += 4; }
if ( ContainsFileMetadata ) { EntrySize += 4; }
bool headerToSeparateFile = false;
if ( headerName != null ) { headerToSeparateFile = true; }
using ( FileStream f = new FileStream( headerToSeparateFile ? headerName : outFilename, FileMode.Create ) ) {
// header
f.Write( Encoding.ASCII.GetBytes( "FPS4" ), 0, 4 );
f.WriteUInt32( FileCount.ToEndian( Endian ) );
f.WriteUInt32( HeaderSize.ToEndian( Endian ) );
f.WriteUInt32( 0 ); // start of first file goes here, will be filled in later
f.WriteUInt16( EntrySize.ToEndian( Endian ) );
f.WriteUInt16( ContentBitmask.ToEndian( Endian ) );
f.WriteUInt32( Unknown2.ToEndian( Endian ) );
f.WriteUInt32( 0 ); // ArchiveNameLocation, will be filled in later
// file list
for ( int i = 0; i < files.Length; ++i ) {
var fi = new System.IO.FileInfo( files[i] );
if ( ContainsStartPointers ) { f.WriteUInt32( 0 ); } // properly written later
if ( ContainsSectorSizes ) { f.WriteUInt32( 0 ); } // properly written later
if ( ContainsFileSizes ) { f.WriteUInt32( ( (uint)( fi.Length ) ).ToEndian( Endian ) ); }
if ( ContainsFilenames ) {
string filename = fi.Name.Truncate( 0x1F );
byte[] fnbytes = Util.ShiftJISEncoding.GetBytes( filename );
f.Write( fnbytes, 0, fnbytes.Length );
for ( int j = fnbytes.Length; j < 0x20; ++j ) {
f.WriteByte( 0 );
}
}
if ( ContainsFiletypes ) {
string extension = fi.Extension.TrimStart( '.' ).Truncate( 4 );
byte[] extbytes = Util.ShiftJISEncoding.GetBytes( extension );
f.Write( extbytes, 0, extbytes.Length );
for ( int j = extbytes.Length; j < 4; ++j ) {
f.WriteByte( 0 );
}
}
if ( ContainsFileMetadata ) {
if ( infile != null ) {
// copy this from original file, very hacky when filenames/filecount/metadata changes
infile.Position = f.Position;
f.WriteUInt32( infile.ReadUInt32() );
} else {
// place a null for now and go back to fix later
f.WriteUInt32( 0 );
}
}
}
// at the end of the file list, reserve space for a final entry pointing to the end of the container
for ( int j = 0; j < EntrySize; ++j ) {
f.WriteByte( 0 );
}
// the idea is to write a pointer here
// and at the target of the pointer you have a nullterminated string
// with all the metadata in a param=data format separated by spaces
// maybe including a filepath at the start without a param=
// strings should be after the filelist block but before the actual files
if ( ContainsFileMetadata && metadata != null ) {
for ( int i = 0; i < files.Length; ++i ) {
var fi = new System.IO.FileInfo( files[i] );
long ptrPos = 0x1C + ( ( i + 1 ) * EntrySize ) - 4;
// remember pos
uint oldPos = (uint)f.Position;
// jump to metaptr
f.Position = ptrPos;
// write remembered pos
f.WriteUInt32( oldPos.ToEndian( Endian ) );
// jump to remembered pos
f.Position = oldPos;
// write meta + nullterm
if ( metadata.Contains( 'p' ) ) {
string relativePath = GetRelativePath( f.Name, fi.FullName );
f.Write( Util.ShiftJISEncoding.GetBytes( relativePath ) );
}
if ( metadata.Contains( 'n' ) ) {
f.Write( Util.ShiftJISEncoding.GetBytes( "name=" + Path.GetFileNameWithoutExtension( fi.FullName ) ) );
}
f.WriteByte( 0 );
}
}
// write original archive filepath
if ( ArchiveName != null ) {
// put the location into the header
ArchiveNameLocation = Convert.ToUInt32( f.Position );
//.........这里部分代码省略.........