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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#define BINARYFILE_TO_BASE64
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using bocoree;
//using Boare.Lib.AppUtil;
namespace DevUtl {
class Program {
static void Main( string[] args ) {
#if BINARYFILE_TO_BASE64
Console.WriteLine( "BINARYFILE_TO_BASE64" );
if ( args.Length < 1 ) {
Console.WriteLine( "error; too few arguments" );
return;
}
if ( !File.Exists( args[0] ) ) {
Console.WriteLine( "error; file not found" );
return;
}
string str = "";
using ( FileStream fs = new FileStream( args[0], FileMode.Open ) ) {
byte[] b = new byte[fs.Length];
fs.Read( b, 0, b.Length );
str = Base64.encode( b );
}
int length = str.Length;
int split_length = 100;
Console.Write( "string foo = " );
uint count = 0;
while ( length > 0 ) {
count++;
string pref = " ";
if ( count == 1 ) {
pref = "";
}
if ( length < split_length ) {
Console.WriteLine( pref + "\"" + str + "\";" );
break;
} else {
string part = str.Substring( 0, split_length );
str = str.Substring( split_length );
length = str.Length;
Console.WriteLine( pref + "\"" + part + "\" +" );
}
}
#endif
#if BINARYFILE_TO_BYTEARRAY
Console.WriteLine( "BINARYFILE_TO_BYTEARRAY" );
if ( args.Length < 2 ) {
Console.WriteLine( "error; too few arguments" );
return;
}
if ( !File.Exists( args[0] ) ) {
Console.WriteLine( "error; file not found" );
return;
}
byte[] hoge = new byte[] { 0x00, 0x01, };
using ( StreamWriter sw = new StreamWriter( args[1], false, Encoding.UTF8 ) ) {
sw.Write( "byte[] foo = new byte[] { " );
bool first = true;
using ( FileStream fs = new FileStream( args[0], FileMode.Open ) ) {
const int BUF = 20;
byte[] buffer = new byte[BUF];
while ( true ) {
int len = fs.Read( buffer, 0, BUF );
if ( len <= 0 ) {
break;
}
if ( first ) {
first = false;
} else {
sw.WriteLine();
sw.Write( " " );
}
for ( int i = 0; i < len; i++ ) {
sw.Write( "0x" + Convert.ToString( buffer[i], 16 ) + ", " );
}
}
}
sw.WriteLine( "};" );
}
#else
#if LANGUAGE_FILE_CONVERSION
Console.WriteLine( "LANGUAGE_FILE_CONVERSION" );
//Console.WriteLine( "input the name of message definition file" );
string msg_dat = @"C:\cvs\lipsync\LipSync\en.lang";// Console.ReadLine();
Dictionary<string, string> dict = new Dictionary<string, string>();
using ( StreamReader sr = new StreamReader( msg_dat ) ) {
while ( sr.Peek() >= 0 ) {
string line = sr.ReadLine();
if ( line.StartsWith( "#" ) ) {
continue;
}
string[] spl = line.Split( "\t".ToCharArray() );
dict.Add( spl[0], spl[1] );
}
}
while ( true ) {
Console.WriteLine( "input edit target file" );
string cs = Console.ReadLine();
string new_file = Path.Combine( Path.GetDirectoryName( cs ), Path.GetFileNameWithoutExtension( cs ) + "_.tmp" );
using ( StreamWriter sw = new StreamWriter( new_file ) )
using ( StreamReader sr = new StreamReader( cs ) ) {
while ( sr.Peek() >= 0 ) {
sw.WriteLine( sr.ReadLine() );
}
}
using ( StreamWriter sw = new StreamWriter( cs ) )
using ( StreamReader sr = new StreamReader( new_file ) ) {
while ( sr.Peek() >= 0 ) {
string line = sr.ReadLine();
int index = line.IndexOf( "Messaging.GetMessage( MessageID." );
if ( index >= 0 ) {
while ( index >= 0 ) {
int right = line.IndexOf( ")", index );
string item = line.Substring( index + 32, right - (index + 32) );
item = item.Trim();
Console.WriteLine( "item=\"" + item + "\"" );
string new_line = line.Substring( 0, index ) + "_( \"" + dict[item] + "\" )" + line.Substring( right + 1 );
line = new_line;
index = line.IndexOf( "Messaging.GetMessage( MessageID." );
}
sw.WriteLine( line );
} else {
sw.WriteLine( line );
}
}
}
}
#endif
#endif
}
}
}
|