private void Form_Send(object sender, SendEventArgs e) { Debug.WriteLine(""); Debug.WriteLine("---------------------DEBUG STRINGS-----------------------"); Debug.WriteLine(""); Debug.WriteLine($"Code:{Environment.NewLine}{e.Code}"); Debug.WriteLine($"Tokens:{Environment.NewLine}{e.ToString()}"); //Init a copy of controlpoints Encoder ENCODER = new Encoder(); ENCODER.SetControlPoints(SelectedPrg); //ENCODE THE PROGRAM byte[] ByteEncoded = ENCODER.EncodeBytes(e.Tokens); var PSize = BitConverter.ToInt16(ByteEncoded, 0); CoderHelper.ConsolePrintBytes(ByteEncoded, "Encoded"); MessageBox.Show($"Resource compiled succceded{System.Environment.NewLine}Total size 2000 bytes{System.Environment.NewLine}Already used {PSize} bytes.", "T3000"); // MessageBox.Show(Encoding.UTF8.GetString(ByteEncoded), "Tokens"); SelectedPrg.ProgramCodes[Index_EditProgramCode].Code = ByteEncoded; //The need of this code, means that constructor must accept byte array and fill with nulls to needSize value SelectedPrg.ProgramCodes[Index_EditProgramCode].Count = 2000; SelectedPrg.Programs[Index_EditProgramCode].Length = PSize; //Also that save, must recalculate and save the lenght in bytes of every programcode into program.lenght //Prg.Save($"{PrgPath.Substring(0,PrgPath.Length-4)}.PRG"); }
private void EditCodeColumn(object sender, EventArgs e) { try { var row = view.CurrentRow; Index_EditProgramCode = row.GetValue <int>(NumberColumn) - 1; var form = new ProgramEditorForm(); form.Caption = $"Edit Code: Panel 1 - Program {Index_EditProgramCode } - Label {SelectedPrg.Programs[Index_EditProgramCode].Description}"; Debug.WriteLine("--------------ORIGINAL CODE-------------------"); CoderHelper.ConsolePrintBytes(Codes[Index_EditProgramCode].Code, "Original"); Decoder DECODER = new Decoder(); DECODER.SetControlPoints(SelectedPrg); string ProgramText = DECODER.DecodeBytes(Codes[Index_EditProgramCode].Code); Debug.WriteLine("--------------NEW PROGRAM TEXT-------------------"); Debug.WriteLine(ProgramText); //STEP 1: create a local copy of all identifiers form.Identifiers = DECODER.Identifiers; //STEP 2: Create a local copy for Control Basic program text form.SetCode(ProgramText); //STEP 3: Override Send Event Handler and encode program into bytes. form.Send += Form_Send; //STEP 4: Who's your daddy?!! form.MdiParent = this.MdiParent; form.Show(); //if (form.ShowDialog() != DialogResult.OK) return; } catch (Exception exception) { MessageBoxUtilities.ShowException(exception); } }