private void TSMSecondFileDecimal_Click(object sender, EventArgs e) { this.eSecondFile = eEncoding.Decimal; if (FormMain.fSecond != null) { this.ReloadSecondForm(); } }
private void TSMFirstFileDecimal_Click(object sender, EventArgs e) { this.eFirstFile = eEncoding.Decimal; if (FormMain.fFirst != null) { this.ReloadFirstForm(); } }
//Devuelve los bytes de una cadena de texto public static byte[] ToBytes(string value, eEncoding encoding = eEncoding.ASCII) { try { byte[] bytes = null; switch (encoding) { case eEncoding.ASCII: bytes = Encoding.ASCII.GetBytes(value); break; case eEncoding.UTF7: bytes = Encoding.UTF7.GetBytes(value); break; case eEncoding.UTF8: bytes = Encoding.UTF8.GetBytes(value); break; case eEncoding.UTF32: bytes = Encoding.UTF32.GetBytes(value); break; case eEncoding.Unicode: bytes = Encoding.Unicode.GetBytes(value); break; default: bytes = Encoding.Default.GetBytes(value); break; } return(bytes); } catch { return(null); } }
/// <summary> /// Constructor /// </summary> public FormFile(string sPath, eEncoding eE) { InitializeComponent(); try { this.sPath = sPath; this.eE = eE; this.Text = string.Concat(this.sPath, " + ", this.eE.ToString()); byte[] buf = File.ReadAllBytes(this.sPath); for (var i = 0; i < buf.Length; i += FormFile.iStep) { string[] sBuf = new string[FormFile.iSizeList]; sBuf[0] = i.ToString("X").PadLeft(16, '0'); for (var j = 0; j < FormFile.iStep && i + j < buf.Length; ++j) { sBuf[j + 1] = Convert.ToString(buf[i + j], 16); } if (this.eE == eEncoding.ASCII) { Encoding enc = Encoding.ASCII; for (var j = 0; j < FormFile.iStep && i + j < buf.Length; ++j) { sBuf[j + 1 + FormFile.iStep] = enc.GetString(new byte[] { buf[i + j] }); } } else if (this.eE == eEncoding.Decimal) { for (var j = 0; j < FormFile.iStep && i + j < buf.Length; ++j) { sBuf[j + 1 + FormFile.iStep] = buf[i + j].ToString(); } } else if (this.eE == eEncoding.Octal) { for (var j = 0; j < FormFile.iStep && i + j < buf.Length; ++j) { sBuf[j + 1 + FormFile.iStep] = Convert.ToString(buf[i + j], 8); } } else { Encoding enc = Encoding.Unicode; byte[] bBuf = new byte[FormFile.iStep]; for (var j = 0; j < bBuf.Length && i + j < buf.Length; ++j) { bBuf[j] = buf[i + j]; } string sTmp = enc.GetString(bBuf); for (var j = 0; j < sTmp.Length; ++j) { sBuf[j + 1 + FormFile.iStep] = sTmp[j].ToString(); } } this.LWShow.Items.Add(new ListViewItem(sBuf)); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Edit encoding /// </summary> /// <param name="newEncode"></param> public void EditEncoding(eEncoding newEncode) { this.eE = newEncode; this.Text = string.Concat(this.sPath, " + ", this.eE.ToString()); //А вот тут изменение }