1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
using System;
using System.IO;
class splitDDB{
static void Main( string[] args ){
uint fcc = makefcc( "FRM2" );
Console.WriteLine( string.Format( "{0:X}", fcc ) );
if( args.Length <= 0 ){
return;
}
string file = args[0];
using( FileStream fs = new FileStream( file, FileMode.Open, FileAccess.Read ) ){
byte[] header = new byte[]{ 0x46, 0x52, 0x4d, 0x32 };
byte[] size = new byte[4];
int BUFLEN = 512;
byte[] buf = new byte[BUFLEN];
int count = 0;
while( true ){
Console.WriteLine( "-----------------------------" );
long pos = fs.Position;
Console.WriteLine( "pos=" + pos );
int len = fs.Read( header, 0, 4 );
if( len < 4 ){
break;
}
uint headerfcc = BitConverter.ToUInt32( header, 0 );
Console.WriteLine( "header=0x" + string.Format( "{0:X}", headerfcc ) );
if( headerfcc == makefcc( "FRM2" ) ||
headerfcc == makefcc( "SND " ) ){
// FRM2/SND チャンク
len = fs.Read( size, 0, 4 );
if( len < 4 ){
break;
}
int s = BitConverter.ToInt32( size, 0 );
Console.WriteLine( "size=" + s );
string datafile = "";
count++;
if( headerfcc == makefcc( "FRM2" ) ){
datafile = count + ".frm2";
Console.WriteLine( "frm2#" + count );
}else if( headerfcc == makefcc( "SND " ) ){
datafile = count + ".snd";
Console.WriteLine( "snd #" + count );
}
using( FileStream fsout = new FileStream( datafile, FileMode.Create, FileAccess.Write ) ){
fsout.Write( header, 0, 4 );
fsout.Write( size, 0, 4 );
int totalwrite = 8;
while( totalwrite < s ){
int remain = (s - totalwrite > BUFLEN) ? BUFLEN : s - totalwrite;
int len2 = fs.Read( buf, 0, remain );
if( len2 <= 0 ){
break;
}
fsout.Write( buf, 0, len2 );
totalwrite += len2;
}
fs.Seek( pos + s, SeekOrigin.Begin );
}
}else{
break;
}
}
}
}
static uint makefcc( string s ){
byte[] cha = new byte[4];
for( int i = 0; i < 4; i++ ){
if( s.Length >= i + 1 ){
cha[i] = (byte)s[i];
}else{
cha[i] = 0;
}
}
return BitConverter.ToUInt32( cha, 0 );
}
}
|