public override void RenderResource(ResourceData resourceData) { var data = (_data = resourceData).RawData; if (data.Length > 1024 * 1024) { var r = MessageBox.Show(this, "The resource to display is larger than one megabyte. Are you sure you want to continue loading it?", "Anolis Resourcer", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (r == DialogResult.Cancel) { this.Visible = false; return; } else { this.Visible = true; } } try { __text.Text = TextEncoding.GetString(data); } catch (EncoderFallbackException fex) { MessageBox.Show(this, "Could not render the text stream using the current encoder: " + fex.Message, "Anolis Resourcer", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
public HuFileEntry GetEntry(DataController dc, int sector, int pos) { var fe = new HuFileEntry(); string Name = TextEncoding.GetString(dc.Copy(pos + 0x01, HuFileEntry.MaxNameLength)).TrimEnd((Char)0x20); string Extension = TextEncoding.GetString(dc.Copy(pos + 0x0e, HuFileEntry.MaxExtensionLength)).TrimEnd((Char)0x20); fe.SetEntryFromSector(dc, sector, pos, Name, Extension); return(fe); }
private void OnReceived(DataReceivedUnit ou) { SpecificResult.ReceivedData = ou.DataFrame.Payload; if (TextEncoding != null) { SpecificResult.ReceivedText = TextEncoding.GetString(SpecificResult.ReceivedData); } SetStateCompleted(ou); }
private HuFileEntry GetFileEntry(string Filename, int EntrySector) { int Sector = EntrySector; Filename = Filename.ToUpper(); // 名前 string Name = Path.GetFileNameWithoutExtension(Filename); if (Name.Length > HuFileEntry.MaxNameLength) { Name = Name.Substring(0, HuFileEntry.MaxNameLength); } // 拡張子 string Extension = Path.GetExtension(Filename); if (Extension.Length > 0) { Extension = Extension.Substring(1); } if (Extension.Length > HuFileEntry.MaxExtensionLength) { Extension = Extension.Substring(0, HuFileEntry.MaxExtensionLength); } Filename = Name + "." + Extension; for (int i = 0; i < ClusterPerSector; i++, Sector++) { var dc = DiskImage.GetDataControllerForRead(Sector); for (var j = 0; j < EntriesInSector; j++) { int pos = (j * FileEntrySize); var mode = dc.GetByte(pos); if (mode == EntryEnd) { return(null); } string EntryName = TextEncoding.GetString(dc.Copy(pos + 0x01, HuFileEntry.MaxNameLength)).TrimEnd((Char)0x20); string EntryExtension = TextEncoding.GetString(dc.Copy(pos + 0x0e, HuFileEntry.MaxExtensionLength)).TrimEnd((Char)0x20); string EntryFilename = (EntryName + "." + EntryExtension).ToUpper(); if (Filename != EntryFilename) { continue; } return(GetEntry(dc, Sector, pos)); } } return(null); }
private void OnRead(ArraySegment <byte> buffer) { int start = buffer.Offset; for (int i = buffer.Offset; i + 1 < buffer.Count; i++) { if (buffer.Array[i] == 13 && buffer.Array[i + 1] == 10) { ParseMessage(TextEncoding.GetString(buffer.Array, start, i - start)); i += 2; start = i; } } }
/// <summary> /// Initializes a new instance of the <c>QuoteMessage</c> class with the given byte array, start index, and number of bytes. /// </summary> /// <param name="message">the byte array that contains this <c>QuoteMessage</c>.</param> /// <param name="offset">the position where message begins.</param> /// <param name="count">the length of this message in bytes.</param> /// <exception cref="System.ArgumentNullException">The input byte array is null or empty.</exception> /// <exception cref="System.ArgumentOutOfRangeException">The input offset or count is out of range.</exception> public QuoteMessage(byte[] message, int offset, int count) { if (message == null || message.Length <= 0) { throw new ArgumentNullException("message cannot be null or empty."); } if (offset < 0 || count <= MinLength || message.Length - offset < count) { throw new ArgumentOutOfRangeException("offset or count out of range."); } m_bodyLength = count - HeaderLength; string bodyString = TextEncoding.GetString(message, offset + HeaderLength, m_bodyLength); Debug.Assert(!string.IsNullOrEmpty(bodyString)); m_fields = bodyString.Split(','); Debug.Assert(m_fields.Length > 0); }