本文整理汇总了C#中System.IO.FileStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream.WriteByte方法的具体用法?C# System.IO.FileStream.WriteByte怎么用?C# System.IO.FileStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了System.IO.FileStream.WriteByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFromDirectory
public void CreateFromDirectory( string Dir, string Outfile )
{
string[] Filepaths = System.IO.Directory.GetFiles( Dir );
ushort Filecount = (ushort)Filepaths.Length;
uint RequiredBytesForHeader = Util.Align( Filecount * 4u + 4u, 0x50u ); // pretty sure this is not right but should work
var Filestream = new System.IO.FileStream( Outfile, System.IO.FileMode.Create );
// header
Filestream.WriteByte( (byte)'S' ); Filestream.WriteByte( (byte)'C' );
Filestream.WriteByte( (byte)'M' ); Filestream.WriteByte( (byte)'P' );
uint TotalFilesize = RequiredBytesForHeader;
foreach ( string Path in Filepaths ) {
Filestream.Write( BitConverter.GetBytes( TotalFilesize ), 0, 4 );
TotalFilesize += (uint)( new System.IO.FileInfo( Path ).Length );
TotalFilesize = TotalFilesize.Align( 0x10u );
}
while ( Filestream.Length < RequiredBytesForHeader ) { Filestream.WriteByte( 0x00 ); }
// files
foreach ( string Path in Filepaths ) {
var File = new System.IO.FileStream( Path, System.IO.FileMode.Open );
Util.CopyStream( File, Filestream, (int)File.Length );
File.Close();
while ( Filestream.Length % 0x10 != 0 ) { Filestream.WriteByte( 0x00 ); }
}
Filestream.Close();
}
示例2: Execute
public static int Execute( List<string> args )
{
if ( args.Count < 2 ) {
Console.WriteLine( "Usage: ByteHotfix [filename] [location-byte] [location-byte] etc." );
Console.WriteLine( "example: ByteHotfix 325.new 3A9A3-94 3AA72-A4 3AA73-32 3AB53-51" );
return -1;
}
/*
args = new string[] { @"c:\#gn_chat\scenario.dat.ext.ex\325.new" ,
"3A9A3-94", "3AA72-A4", "3AA73-32", "3AB53-51" };
*/
try {
string inFilename = args[0];
using ( var fi = new System.IO.FileStream( inFilename, System.IO.FileMode.Open ) ) {
for ( int i = 1; i < args.Count; i++ ) {
String[] v = args[i].Split( new char[] { '-' } );
int location = int.Parse( v[0], NumberStyles.AllowHexSpecifier );
byte value = byte.Parse( v[1], NumberStyles.AllowHexSpecifier );
fi.Position = location;
fi.WriteByte( value );
}
fi.Close();
}
return 0;
} catch ( Exception ex ) {
Console.WriteLine( "Exception: " + ex.Message );
return -1;
}
}
示例3: CreateFromDirectory
public void CreateFromDirectory( string Dir, string Outfile )
{
string[] Filepaths = System.IO.Directory.GetFiles( Dir );
ushort Filecount = (ushort)Filepaths.Length;
uint RequiredBytesForHeader = Util.Align( Filecount * 3u + 5u, 0x10u ); // 3 bytes per filesize + 3 bytes for an extra pointer to first file + 2 bytes for filecount
var Filestream = new System.IO.FileStream( Outfile, System.IO.FileMode.Create );
// header
Filestream.Write( BitConverter.GetBytes( Filecount ), 0, 2 );
Filestream.Write( Util.GetBytesForUInt24( RequiredBytesForHeader ), 0, 3 );
uint TotalFilesize = RequiredBytesForHeader;
foreach ( string Path in Filepaths ) {
TotalFilesize += (uint)( new System.IO.FileInfo( Path ).Length );
Filestream.Write( Util.GetBytesForUInt24( TotalFilesize ), 0, 3 );
TotalFilesize = TotalFilesize.Align( 0x10u );
}
while ( Filestream.Length < RequiredBytesForHeader ) { Filestream.WriteByte( 0x00 ); }
// files
foreach ( string Path in Filepaths ) {
var File = new System.IO.FileStream( Path, System.IO.FileMode.Open );
Util.CopyStream( File, Filestream, (int)File.Length );
File.Close();
while ( Filestream.Length % 0x10 != 0 ) { Filestream.WriteByte( 0x00 ); }
}
Filestream.Close();
}
示例4: Main
static void Main(string[] args)
{
LasmParser p = new LasmParser();
LuaFile file = p.Parse(@"
.const ""print""
.const ""Hello""
getglobal 0 0
loadk 1 1
call 0 2 1
return 0 1
");
file.StripDebugInfo();
string code = file.Compile();
try
{
LuaFile f = Disassembler.Disassemble(code);
System.IO.FileStream fs = new System.IO.FileStream("lasm.luac", System.IO.FileMode.Create);
//foreach (char c in code)
foreach (char c in f.Compile())
fs.WriteByte((byte)c);
fs.Close();
// Test chunk compiling/loading
string s = f.Main.Compile(f);
Chunk chnk = Disassembler.DisassembleChunk(s);
// Test execution of code
string s2 = f.Compile();
LuaRuntime.Run(s2);
LuaRuntime.Run(code);
Console.WriteLine("The above line should say 'Hello'. If it doesn't there is an error.");
Console.WriteLine(LASMDecompiler.Decompile(file));
}
catch (System.Exception ex)
{
Console.WriteLine(ex.ToString());
}
try
{
LuaFile lf = p.Parse("breakpoint 0 0 0");
LuaRuntime.Run(lf.Compile());
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("Test(s) done. Press any key to continue.");
Console.ReadKey(true);
}
示例5: uncompressFile
public static void uncompressFile(string inFile, string outFile)
{
int data = 0;
int stopByte = -1;
System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read));
while (stopByte != (data = inZStream.Read()))
{
byte _dataByte = (byte)data;
outFileStream.WriteByte(_dataByte);
}
inZStream.Close();
outFileStream.Close();
}
示例6: Initialize
public void Initialize()
{
string libFolder = System.IO.Path.Combine(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\BackupV3\\PluginLib\\");
if (!System.IO.Directory.Exists(libFolder + "\\Compression"))
System.IO.Directory.CreateDirectory(libFolder + "\\Compression");
if (!System.IO.File.Exists(libFolder + "\\Compression\\Ionic.Zip.dll"))
{
//TODO extract the file from resources
using (System.IO.FileStream fs = new System.IO.FileStream(libFolder + "\\Compression\\Ionic.Zip.dll", System.IO.FileMode.CreateNew))
{
System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Compression_Plugin.Ionic.Zip.dll");
for(int i = 0; i < stream.Length; i++)
fs.WriteByte((byte)stream.ReadByte());
}
}
System.Reflection.Assembly.LoadFrom(Environment.GetEnvironmentVariable("APPDATA") + "\\returnzork\\BackupV3\\PluginLib\\Compression\\Ionic.Zip.dll");
}
示例7: WriteResource
public static void WriteResource(System.Reflection.Assembly targetAssembly, string resourceName, string filePath)
{
string[] resources = targetAssembly.GetManifestResourceNames();
List<string> resoruceList = resources.ToList();
foreach (string s in resoruceList)
{
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(s))
{
using (System.IO.FileStream fileStream = new System.IO.FileStream(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filePath), resourceName), System.IO.FileMode.Create))
{
for (int i = 0; i < stream.Length; i++)
{
fileStream.WriteByte((byte)stream.ReadByte());
}
fileStream.Close();
}
}
}
}
示例8: WriteBytes
private static void WriteBytes(System.IO.FileInfo aFile, long size)
{
System.IO.Stream stream = null;
try
{
stream = new System.IO.FileStream(aFile.FullName, System.IO.FileMode.Create);
for (int i = 0; i < size; i++)
{
stream.WriteByte((byte) Byten(i));
}
stream.Flush();
}
finally
{
if (stream != null)
{
stream.Close();
}
}
}
示例9: DownloadFile
public static void DownloadFile(this File f, DriveService ds, string s, System.IO.StreamWriter w)
{
try
{
String path = System.IO.Path.Combine(s, f.OriginalFilename);
if (System.IO.File.Exists(path))
{
if (!String.IsNullOrEmpty(f.OriginalFilename)) w.WriteDownloadStatus(f.OriginalFilename, 1);
return;
}
if (!System.IO.Directory.Exists(s)) System.IO.Directory.CreateDirectory(s);
byte[] arrBytes = ds.HttpClient.GetByteArrayAsync(f.DownloadUrl).Result;
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
foreach (byte b in arrBytes) fs.WriteByte(b);
fs.Close();
w.WriteDownloadStatus(f.OriginalFilename);
}
catch (Exception e) { if (!String.IsNullOrEmpty(f.OriginalFilename)) w.WriteDownloadStatus(f.OriginalFilename, 1); } //Skip it
}
示例10: ExtractEmbeddedResource
public static void ExtractEmbeddedResource(string resourceLocation, string outputDir, List<string> files)
{
foreach (string file in files)
{
using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceLocation + @"." + file))
{
using (System.IO.FileStream fileStream = new System.IO.FileStream(System.IO.Path.Combine(outputDir, file), System.IO.FileMode.Create))
{
for (int i = 0; i < stream.Length; i++)
{
fileStream.WriteByte((byte)stream.ReadByte());
}
fileStream.Close();
}
}
}
}
示例11: SaveRAWImage
public static void SaveRAWImage(string aname, Image Image)
{
Bitmap bitmap = new Bitmap(Image);
SizeF bnd = Image.PhysicalDimension;
System.IO.FileStream fm = new System.IO.FileStream(aname+".raw", System.IO.FileMode.Create);
for (int x = 0; x < bnd.Width; x++)
for (int y=0;y<bnd.Height;y++)
{
Color c = bitmap.GetPixel(x, y);
byte fch = (byte)((c.R & 248) | c.G >> 5);
byte fcl = (byte)((c.G & 28) << 3 | c.B >> 3);
fm.WriteByte(fch);
fm.WriteByte(fcl);
}
fm.Close();
fm = new System.IO.FileStream(aname + ".bmp", System.IO.FileMode.Create);
Image.Save(fm, System.Drawing.Imaging.ImageFormat.Bmp);
fm.Close();
}
示例12: HeartbeatThreadProc
void HeartbeatThreadProc()
{
int triesremain = heartbeatretries;
while (!badlocalhost && !stop)
{
try
{
using (System.IO.FileStream fs = new System.IO.FileStream(heartbeattempfile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None))
{
fs.WriteByte((byte)'T');
fs.Seek(0, System.IO.SeekOrigin.Begin);
if ((int)'T' != fs.ReadByte())
{
throw new System.IO.IOException("Heartbeat thread data written was not read back correctly.");
}
fs.Close();
}
System.IO.File.Delete(heartbeattempfile);
triesremain = heartbeatretries; //reset
lock (clientstm)
{
clientstm.WriteByte((byte)'h');
}
#if FAILOVER_DEBUG
System.IO.File.AppendAllText(@"c:\temp\vitalsreporter_A5B1E053-9A32-417b-8068-91A7CD5CDEAB.txt", DateTime.Now.ToString() + " heartbeat sent" + Environment.NewLine);
#endif
System.Threading.Thread.Sleep(heartbeattimeout);
}
catch(Exception e)
{
#if FAILOVER_DEBUG
System.IO.File.AppendAllText(@"c:\temp\vitalsreporter_A5B1E053-9A32-417b-8068-91A7CD5CDEAB.txt", DateTime.Now.ToString() +
" heartbeat thread error: " + e.ToString() + Environment.NewLine);
#endif
if (--triesremain <= 0)
{
#if FAILOVER_DEBUG
System.IO.File.AppendAllText(@"c:\temp\vitalsreporter_A5B1E053-9A32-417b-8068-91A7CD5CDEAB.txt", DateTime.Now.ToString() +
" heartbeat thread error; tries=" + triesremain.ToString()
+ " ;caused to break out: " + e.ToString() + Environment.NewLine);
#endif
break;
}
}
}
}
示例13: CreateFromDirectory
public void CreateFromDirectory( string Dir, string Outfile, string[] FileOrder )
{
List<string> Filepaths = new List<string>();
foreach ( string f in FileOrder ) {
Filepaths.Add( System.IO.Path.Combine( Dir, f ) );
}
var Filestream = new System.IO.FileStream( Outfile, System.IO.FileMode.Create );
uint RequiredBytesForHeader;
uint Filecount = (uint)Filepaths.Count;
uint TotalFilesize;
Xorbyte = 0x55;
//Xorbyte = 0x00;
// 0x20 Header + 0x28 per file
RequiredBytesForHeader = Util.Align( Filecount * 0x28u + 0x20u, 0x20u );
TotalFilesize = RequiredBytesForHeader;
foreach ( string Path in Filepaths ) {
TotalFilesize += (uint)( new System.IO.FileInfo( Path ).Length );
TotalFilesize = TotalFilesize.Align( 0x20u );
}
// header
Filestream.WriteByte( (byte)'R' ); Filestream.WriteByte( (byte)'T' );
Filestream.WriteByte( (byte)'D' ); Filestream.WriteByte( (byte)'P' );
Filestream.Write( BitConverter.GetBytes( RequiredBytesForHeader ), 0, 4 );
Filestream.Write( BitConverter.GetBytes( Filecount ), 0, 4 );
Filestream.Write( BitConverter.GetBytes( TotalFilesize ), 0, 4 );
Filestream.WriteByte( Xorbyte );
Filestream.WriteByte( 0x28 ); Filestream.WriteByte( 0x25 );
while ( Filestream.Length < 0x20 ) { Filestream.WriteByte( 0x00 ); }
// header file info
uint ptr = 0;
foreach ( string Path in Filepaths ) {
var fi = new System.IO.FileInfo( Path );
uint size = (uint)( fi.Length );
byte[] name = Encoding.ASCII.GetBytes( fi.Name );
Filestream.Write( name, 0, Math.Min( 0x20, name.Length ) );
for ( int i = name.Length; i < 0x20; ++i ) { Filestream.WriteByte( 0x00 ); }
Filestream.Write( BitConverter.GetBytes( size ), 0, 4 );
Filestream.Write( BitConverter.GetBytes( ptr ), 0, 4 );
ptr = Util.Align( ptr + size, 0x20u );
}
while ( Filestream.Length < RequiredBytesForHeader ) { Filestream.WriteByte( 0x00 ); }
// files
foreach ( string Path in Filepaths ) {
var File = new System.IO.FileStream( Path, System.IO.FileMode.Open );
while ( true ) {
int b = File.ReadByte();
if ( b == -1 ) { break; }
Filestream.WriteByte( (byte)( b ^ Xorbyte ) );
}
File.Close();
while ( Filestream.Length % 0x20 != 0 ) { Filestream.WriteByte( 0x00 ); }
}
Filestream.Close();
}
示例14: GenerateFiles
public void GenerateFiles( String Outdir )
{
System.IO.Directory.CreateDirectory( Outdir );
for ( int i = 0; i < FileData.Count; ++i ) {
RTDPfile r = FileData[i];
uint start = r.Pointer;
uint end = r.Pointer + r.Size;
uint count = r.Size;
string outfilename = r.Name;
string outpath = System.IO.Path.Combine( Outdir, outfilename );
var fs = new System.IO.FileStream( outpath, System.IO.FileMode.Create );
for ( int j = 0; j < count; ++j ) {
fs.WriteByte( (byte)( File[start + j] ^ Xorbyte ) );
}
fs.Close();
}
// write filename order
List<string> Filenames = new List<string>();
foreach ( RTDPfile r in FileData ) {
Filenames.Add( r.Name );
}
System.IO.File.WriteAllLines( Outdir + ".fileorder", Filenames.ToArray() );
}
示例15: Save
public void Save(string MainFileName)
{
if (MainFileName.Substring(MainFileName.Length - 4) != ".scr")
MainFileName = MainFileName + ".scr";
string IDsFileName = MainFileName.Substring(0,MainFileName.Length-4) + ".ids";
string DefsFileName = IDsFileName.Substring(0, IDsFileName.Length - 4) + ".h";
System.IO.FileStream fs = new System.IO.FileStream(MainFileName, System.IO.FileMode.Create);
System.Xml.XmlWriter fi = System.Xml.XmlWriter.Create(IDsFileName);
System.IO.StreamWriter fd = new System.IO.StreamWriter(DefsFileName);
//pnl.Image.Save(null, System.Drawing.Imaging.ImageFormat.Bmp);
fi.WriteStartDocument();
fi.WriteStartElement("Document");
fi.WriteStartElement("Screen");
fi.WriteElementString("SCREEN_Width", Width.ToString());
fi.WriteElementString("SCREEN_Height", Height.ToString());
fi.WriteElementString("SCREEN_BackColor", BackColor.ToString());
fi.WriteElementString("SCREEN_FontColor", FontColor.ToString());
fi.WriteElementString("SCREEN_ABorderColor", ActiveBorderColor.ToString());
fi.WriteElementString("SCREEN_PBorderColor", PassiveBorderColor.ToString());
if (pnl.Image != null)
{
string aname = String.Format("{0}\\{1}",System.IO.Path.GetDirectoryName(MainFileName),ScreenName);
utftUtils.SaveRAWImage(aname, pnl.Image);
fi.WriteElementString("Desctop", ScreenName);
}
fi.WriteEndElement();
byte lbl = 0;
byte btn = 0;
foreach (KeyValuePair<string, TInterfaceElement> e in listitem)
{
if (e.Value.GetItemTypeNumber() == 3)
e.Value.ID = lbl++;
else e.Value.ID = btn++;
}
fs.WriteByte((byte)(13 + ScreenName.Length));// размер данных экрана
utftUtils.Save2Bytes(fs, (UInt16)Width);
utftUtils.Save2Bytes(fs, (UInt16)Height);
UInt16 clr = utftUtils.GetUTFTColorBytes(BackColor);
utftUtils.Save2Bytes(fs, clr);
clr = utftUtils.GetUTFTColorBytes(FontColor);
utftUtils.Save2Bytes(fs, clr);
clr = utftUtils.GetUTFTColorBytes(ActiveBorderColor);
utftUtils.Save2Bytes(fs, clr);
clr = utftUtils.GetUTFTColorBytes(PassiveBorderColor);
utftUtils.Save2Bytes(fs, clr);
fs.WriteByte((byte)lbl);
fs.WriteByte((byte)btn);
fs.WriteByte((byte)ScreenName.Length);
for (int i = 0; i < ScreenName.Length; i++)
fs.WriteByte(Convert.ToByte(ScreenName[i]));
fi.WriteStartElement("Elements");
foreach (KeyValuePair<string, TInterfaceElement> e in listitem)
{
e.Value.Save(fs, fi);
if (e.Value.ItemType!="Label")
fd.WriteLine(String.Format("#define {0} {1}", e.Value.ItemName, e.Value.ID));
}
fi.WriteEndElement();
fi.WriteEndElement();
fi.WriteEndDocument();
fs.Close();
fi.Close();
fd.Close();
fs.Dispose();
fd.Dispose();
}