diff --git a/source2/Tools/File2ByteArray Converter/File2ByteArray Converter.csproj b/source2/Tools/File2ByteArray Converter/File2ByteArray Converter.csproj new file mode 100644 index 000000000..d1bda8e3a --- /dev/null +++ b/source2/Tools/File2ByteArray Converter/File2ByteArray Converter.csproj @@ -0,0 +1,71 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {9C96A7B5-19E5-4923-9569-DB9454E69C82} + WinExe + Properties + File2ByteArray_Converter + File2ByteArray Converter + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + + Form1.cs + + + + + \ No newline at end of file diff --git a/source2/Tools/File2ByteArray Converter/Form1.Designer.cs b/source2/Tools/File2ByteArray Converter/Form1.Designer.cs new file mode 100644 index 000000000..7bb24d86d --- /dev/null +++ b/source2/Tools/File2ByteArray Converter/Form1.Designer.cs @@ -0,0 +1,115 @@ +namespace File2ByteArray_Converter +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.tableLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // textBox1 + // + this.tableLayoutPanel1.SetColumnSpan(this.textBox1, 2); + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.Location = new System.Drawing.Point(3, 28); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.textBox1.Size = new System.Drawing.Size(573, 447); + this.textBox1.TabIndex = 0; + // + // textBox2 + // + this.textBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox2.Location = new System.Drawing.Point(3, 3); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(493, 20); + this.textBox2.TabIndex = 1; + // + // button1 + // + this.button1.Dock = System.Windows.Forms.DockStyle.Fill; + this.button1.Location = new System.Drawing.Point(499, 0); + this.button1.Margin = new System.Windows.Forms.Padding(0); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(80, 25); + this.button1.TabIndex = 2; + this.button1.Text = "Browse"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 80F)); + this.tableLayoutPanel1.Controls.Add(this.textBox2, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.button1, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.textBox1, 0, 1); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(579, 478); + this.tableLayoutPanel1.TabIndex = 3; + // + // openFileDialog1 + // + this.openFileDialog1.Filter = "All Files (*.*)|*.*"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(579, 478); + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "Form1"; + this.Text = "File to Byte Array Converter"; + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + } +} + diff --git a/source2/Tools/File2ByteArray Converter/Form1.cs b/source2/Tools/File2ByteArray Converter/Form1.cs new file mode 100644 index 000000000..decd9fa8a --- /dev/null +++ b/source2/Tools/File2ByteArray Converter/Form1.cs @@ -0,0 +1,123 @@ +using System; +using System.Windows.Forms; +using System.IO; + +namespace File2ByteArray_Converter +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + textBox2.Text = openFileDialog1.FileName; + FileStream strm = new FileStream(openFileDialog1.FileName, FileMode.Open); + StreamWriter strw = new StreamWriter(openFileDialog1.FileName + ".ByteArray.txt"); + textBox1.Text = ""; + strw.Write("byte[] " + Path.GetFileName(openFileDialog1.FileName).Replace('.', '_') + " = new byte[] \r\n{\r\n"); + int i = 0; + bool first = true; + for (int loc = 0; loc < strm.Length; loc++) + { + string byt = ConvertToHex((uint)strm.ReadByte()); + if (i >= 8) + { + i = 0; + strw.Flush(); + byt = ", \r\n" + byt; + } + else + { + if (!first) + { + byt = ", " + byt; + } + } + strw.Write(byt); + first = false; + i++; + } + strw.Write("\r\n};"); + strw.Flush(); + strw.Close(); + strw.Dispose(); + strm.Flush(); + strm.Close(); + strm.Dispose(); + StreamReader strdr = new StreamReader(openFileDialog1.FileName + ".ByteArray.txt"); + textBox1.Text = strdr.ReadToEnd(); + strdr.Close(); + strdr.Dispose(); + MessageBox.Show("Conversion Complete!"); + } + } + + private static string ConvertToHex(UInt32 num) + { + string xHex = string.Empty; + + if (num == 0) + { + xHex = "0"; + } + else + { + while (num != 0) + { + //Note; char is converted to string because Cosmos crashes when adding char and string. Frode, 7.june. + //TODO: Is this still true? I think Cosmos can handle char + string just fine now. + xHex = SingleDigitToHex((byte)(num & 0xf)) + xHex; + num = num >> 4; + } + } + + return "0x" + xHex; + } + + private static string SingleDigitToHex(byte d) + { + switch (d) + { + case 0: + return "0"; + case 1: + return "1"; + case 2: + return "2"; + case 3: + return "3"; + case 4: + return "4"; + case 5: + return "5"; + case 6: + return "6"; + case 7: + return "7"; + case 8: + return "8"; + case 9: + return "9"; + case 10: + return "A"; + case 11: + return "B"; + case 12: + return "C"; + case 13: + return "D"; + case 14: + return "E"; + case 15: + return "F"; + } + return " "; + + } + } +} diff --git a/source2/Tools/File2ByteArray Converter/Form1.resx b/source2/Tools/File2ByteArray Converter/Form1.resx new file mode 100644 index 000000000..788180329 --- /dev/null +++ b/source2/Tools/File2ByteArray Converter/Form1.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 25 + + \ No newline at end of file diff --git a/source2/Tools/File2ByteArray Converter/Program.cs b/source2/Tools/File2ByteArray Converter/Program.cs new file mode 100644 index 000000000..137dae3de --- /dev/null +++ b/source2/Tools/File2ByteArray Converter/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace File2ByteArray_Converter +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/source2/Tools/File2ByteArray Converter/Properties/AssemblyInfo.cs b/source2/Tools/File2ByteArray Converter/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..9c151170d --- /dev/null +++ b/source2/Tools/File2ByteArray Converter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("File2ByteArray Converter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Orvid Corp.")] +[assembly: AssemblyProduct("File2ByteArray Converter")] +[assembly: AssemblyCopyright("Copyright © Orvid Corp. 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ba3e5997-d93b-4c25-97ef-7d50fd073152")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]