public static Ema Import(Stream stream) { Ema ema = new Ema(); using (BinaryReader reader = new BinaryReader(stream)) { byte[] imgData = reader.ReadToEnd(); var imgInfo = ImageInformation.FromMemory(imgData); ema.Data = new byte[imgData.Length + 13]; BinaryWriter dataWriter = new BinaryWriter(new MemoryStream(ema.Data)); dataWriter.Write(imgInfo.Width); dataWriter.Write(imgInfo.Height); string ext = Enum.GetName(typeof(ImageFileFormat), imgInfo.ImageFileFormat).ToLowerInvariant(); dataWriter.Write((byte)'.'); dataWriter.Write(Encoding.ASCII.GetBytes(ext)); dataWriter.Write((byte)0); if (imgInfo.ImageFileFormat == ImageFileFormat.Bmp) { dataWriter.Write((short)0); dataWriter.Write(imgData, 2, imgData.Length - 2); } else { dataWriter.Write(imgData); } } return ema; }
public Ema(Stream stream) { using (BinaryReader reader = new BinaryReader(stream)) { Data = reader.ReadToEnd(); } }
public ToolOutputParser(Stream stream) { using (BinaryReader reader = new BinaryReader(stream)) { contents = reader.ReadToEnd(); } }
public xaParser(Stream stream) { using (BinaryReader reader = new BinaryReader(stream)) { this.reader = reader; byte type = reader.ReadByte(); if (type == 0x00) { Format = -1; Section2 = ParseSection2(); MorphSection = ParseMorphSection(); AnimationSection = ParseAnimationSection(); } else if ((type == 0x02) || (type == 0x03)) { Header = new byte[5]; Header[0] = type; reader.ReadBytes(4).CopyTo(Header, 1); ParseSB3Format(); } else if (type == 0x01) { byte[] testBuf = reader.ReadBytes(4); if ((testBuf[0] | testBuf[1] | testBuf[2]) == 0) { Header = new byte[5]; Header[0] = type; testBuf.CopyTo(Header, 1); ParseSB3Format(); } else { Format = -1; MaterialSection = ParseMaterialSection(BitConverter.ToInt32(testBuf, 0)); Section2 = ParseSection2(); MorphSection = ParseMorphSection(); AnimationSection = ParseAnimationSection(); } } else { throw new Exception("Unable to determine .xa format"); } Footer = reader.ReadToEnd(); this.reader = null; } }
public static string ReadUnicode(this BinaryReader reader, int len = 0) { byte[] unicode = (len <= 0) ? reader.ReadToEnd():reader.ReadBytes(len * 2); string text = Encoding.Unicode.GetString(unicode); int i = text.IndexOf('\0'); if (i > 0) { text = text.Substring(0, i); } else { text = ""; } return(text); }
private static bool TryFileImage(Stream stream, ppSubfile subfile) { BinaryReader reader = new BinaryReader(stream); try { byte[] data = reader.ReadToEnd(); var imgInfo = ImageInformation.FromMemory(data); } catch { return false; } return true; }
private void OnReplay(BinaryReader packet) { byte[] replay = packet.ReadToEnd(); const string directory = "Replays"; if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); string otherName = _room.Position == 0 ? _room.Names[1] : _room.Names[0]; string file = DateTime.Now.ToString("yyyy-MM-dd.HH-mm.") + otherName + ".yrp"; string fullname = Path.Combine(directory, file); if (Regex.IsMatch(file, @"^[\w\-. ]+$")) File.WriteAllBytes(fullname, replay); Connection.Close(); }
private void soundSubfilesList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { try { if (!soundLib.isLoaded()) return; if (e.IsSelected) { IReadFile subfile = (IReadFile)e.Item.Tag; Stream stream = (Stream)Gui.Scripting.RunScript(EditorVar + ".ReadSubfile(name=\"" + subfile.Name + "\")", false); byte[] soundBuf; using (BinaryReader reader = new BinaryReader(stream)) { soundBuf = reader.ReadToEnd(); } soundLib.Play(e.Item.Text, soundBuf); } else { soundLib.Stop(e.Item.Text); } } catch (Exception ex) { Utility.ReportException(ex); } }
public byte[] ConvertToBinary(string text) { string outputFile = "$$tmp$$" + Extension; string inputFile = "$$tmp$$" + ".TXT"; byte[] output; try { using (StreamWriter writer = new StreamWriter(File.Create(inputFile), Utility.EncodingShiftJIS)) { writer.Write(text); writer.BaseStream.SetLength(writer.BaseStream.Position); } using (Process tool = new Process()) { tool.StartInfo.CreateNoWindow = true; tool.StartInfo.UseShellExecute = false; tool.StartInfo.RedirectStandardInput = true; tool.StartInfo.RedirectStandardOutput = true; tool.StartInfo.RedirectStandardError = true; tool.StartInfo.FileName = ToolPath; tool.StartInfo.Arguments = String.Format(ToBinaryOptions, outputFile, inputFile); tool.StartInfo.StandardOutputEncoding = Utility.EncodingShiftJIS; try { tool.Start(); } catch { Report.ReportLog("Failed to start process for " + ToolPath + " with \n\t" + tool.StartInfo.Arguments); return null; } using (StreamWriter writer = new StreamWriter(tool.StandardInput.BaseStream, Utility.EncodingShiftJIS)) { writer.Write(text); } string stderr = tool.StandardError.ReadToEnd(); string stdout = tool.StandardOutput.ReadToEnd(); tool.WaitForExit(); Report.ReportLog(Path.GetFileName(ToolPath) + " exited with " + tool.ExitCode); if (stderr.Length > 0) { Report.ReportLog(stderr); } if (stdout.Length > 0) { Report.ReportLog(stdout); } } using (BinaryReader reader = new BinaryReader(File.OpenRead(outputFile))) { output = reader.ReadToEnd(); } } finally { File.Delete(inputFile); File.Delete(outputFile); } return output; }
private void OnResponse(BinaryReader packet) { if (Game.State != GameState.Duel) return; if (State != PlayerState.Response) return; byte[] resp = packet.ReadToEnd(); if (resp.Length > 64) return; State = PlayerState.None; Game.SetResponse(resp); }
private static bool TryFileImage(ppSubfile subfile) { try { using (BinaryReader reader = new BinaryReader(subfile.CreateReadStream())) { byte[] data = reader.ReadToEnd(); var imgInfo = ImageInformation.FromMemory(data); } } catch { return false; } return true; }