/// <summary> /// Read the file and generate a cartridge, if the format is correct /// </summary> /// <param name="fileName">filename of cartridge</param> /// <returns>True, if cartridge is opened</returns> public Boolean Read(String fileName) { Boolean retValue = false; filePath = Path.GetDirectoryName(fileName); fileStream = new FileStream(fileName, FileMode.Open); try { binaryReader = new BinaryReader(fileStream); if (FileOk()) { cartridge = new Cartridge(binaryReader); cartridge.FilePath = filePath; retValue = true; } } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Cartridge, ex); } finally { fileStream.Close(); } return(retValue); }
/// <summary> /// /// </summary> /// <param name="binaryReader"></param> public Cartridge(BinaryReader binaryReader) { try { objects = new Dictionary <short, Objects>(); ok = false; ushort count = SeekFile.GetUShort(binaryReader); for (int i = 0; i < count; i++) { short objectId = SeekFile.GetShort(binaryReader); long address = SeekFile.GetLong(binaryReader); Objects obj = new Objects(objectId, address); objects.Add(obj.ObjectId, obj); } long headerLenght = SeekFile.GetLong(binaryReader); latitude = SeekFile.GetDouble(binaryReader); longitude = SeekFile.GetDouble(binaryReader); altitude = SeekFile.GetDouble(binaryReader); unknown0 = SeekFile.GetLong(binaryReader); unknown1 = SeekFile.GetLong(binaryReader); splashScreenId = SeekFile.GetShort(binaryReader); smallIconId = SeekFile.GetShort(binaryReader); typeOfCartridge = SeekFile.GetASCIIZ(binaryReader); playerName = SeekFile.GetASCIIZ(binaryReader); unknown2 = SeekFile.GetLong(binaryReader); unknown3 = SeekFile.GetLong(binaryReader); cartridgeName = SeekFile.GetASCIIZ(binaryReader); cartridgeGuid = SeekFile.GetASCIIZ(binaryReader); cartridgeDesc = SeekFile.GetASCIIZ(binaryReader); startLocationDesc = SeekFile.GetASCIIZ(binaryReader); version = SeekFile.GetASCIIZ(binaryReader); author = SeekFile.GetASCIIZ(binaryReader); company = SeekFile.GetASCIIZ(binaryReader); recommendedDevice = SeekFile.GetASCIIZ(binaryReader); unknown4 = SeekFile.GetLong(binaryReader); completionCode = SeekFile.GetASCIIZ(binaryReader); foreach (Objects obj in objects.Values) { obj.LoadObject(binaryReader); } ok = true; } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Cartridge, ex); } }
private static void Main() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomainUnhandledException); Trace.DoTrace(Trace.TraceCategories.WherugoApp, Trace.TraceEventType.Start); Windows.Start startForm = new Windows.Start(); Application.Run(startForm); Trace.DoTrace(Trace.TraceCategories.WherugoApp, Trace.TraceEventType.Stop); }
static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { try { Exception ex = (Exception)e.ExceptionObject; Trace.DoTrace(Trace.TraceCategories.Unhandled, Trace.TraceEventType.Critical, ex); } finally { Application.Exit(); } }
private void btnExecute_Click(object sender, System.EventArgs e) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, "btnExecute_Click"); Lua.lua_State lState = Lua.luaL_newstate(); Lua.luaL_openlibs(lState); Lua.lua_register(lState, "msgbox", Lua_MsgBox); Lua.luaL_loadstring(lState, "msgbox('Called with Lua. It works!')"); Lua.lua_pcall(lState, 0, -1, 0); Lua.lua_close(lState); }
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { try { Exception ex = (Exception)e.Exception; Trace.DoTrace(Trace.TraceCategories.Unhandled, Trace.TraceEventType.Error, ex); } finally { MessageBox.Show("Unhandled Exception. See trace.log", "Application_ThreadException"); Environment.Exit(-1); } }
static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { try { Exception ex = (Exception)e.ExceptionObject; Trace.DoTrace(Trace.TraceCategories.Unhandled, Trace.TraceEventType.Error, ex); } finally { MessageBox.Show("Unhandled Exception. See trace.log", "CurrentDomainUnhandledException"); Environment.Exit(-1); } }
/// <summary> /// If GPS-port is open, it will be closed /// </summary> public void StopGPS() { try { Trace.DoTrace(Trace.TraceCategories.Communication, "Stop GPS"); if (serialPort.IsOpen == true) { serialPort.Close(); } } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Communication, Trace.TraceEventType.Error, ex); } }
private void mnExportItem_Click(object sender, EventArgs e) { try { short id = Convert.ToInt16(lbObject.SelectedItem.ToString().Split(' ')[0]); ExportItem(id); } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, ex); } finally { MessageBox.Show(Locale.GetString("export_finished"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Instanciate the serialPort and add the event-handler /// </summary> public GPS() { try { Trace.DoTrace(Trace.TraceCategories.Communication, "GPS Constructor"); serialPort.PortName = DeviceConfig.PortName; serialPort.BaudRate = Convert.ToInt32(DeviceConfig.BaudRate); serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived); serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort_ErrorReceived); serialPort.PinChanged += new SerialPinChangedEventHandler(serialPort_PinChanged); } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Communication, Trace.TraceEventType.Error, ex); } }
private void mnExportItems_Click(object sender, EventArgs e) { try { for (short id = 0; id < gwc.cartridge.Obj().Count; id++) { ExportItem(id); } } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, ex); } finally { MessageBox.Show(Locale.GetString("export_finished"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void ExportItem(short id) { Objects obj; System.IO.FileStream file; try { obj = gwc.cartridge.GetObject(id); file = new System.IO.FileStream(String.Format("{0}\\obj_{1:000}.{2}", gwc.cartridge.FilePath, id, obj.ObjectTypeString), System.IO.FileMode.Create); System.IO.BinaryWriter writer = new System.IO.BinaryWriter(file); writer.Write(obj.Data); writer.Flush(); writer.Close(); } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, ex); } }
/// <summary> /// Read the object directly from the file /// </summary> /// <param name="binaryReader">filehandle</param> /// <returns>True, if no errors occured</returns> public bool LoadObject(BinaryReader binaryReader) { bool retValue = false; binaryReader.BaseStream.Seek(address, SeekOrigin.Begin); try { long length; if (objectId == 0) { length = SeekFile.GetLong(binaryReader); data = new byte[length]; for (int i = 0; i < length; i++) { data[i] = binaryReader.ReadByte(); } } else { byte validObj = SeekFile.GetByte(binaryReader); if (validObj != 0) { objectType = SeekFile.GetLong(binaryReader); length = SeekFile.GetLong(binaryReader); data = new byte[length]; for (int i = 0; i < length; i++) { data[i] = binaryReader.ReadByte(); } } } retValue = true; } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Cartridge, ex); } return(retValue); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { lock (lockObject) { SerialPort portSender = (SerialPort)sender; if (portSender != null) { data = portSender.ReadExisting(); } Trace.DoTrace(Trace.TraceCategories.Communication, data); OnNewData(new GPSEventArgs(DateTime.Now, data)); } } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Communication, Trace.TraceEventType.Error, ex); } }
public Start() { try { InitializeComponent(); m_btnExit.Text = "Exit"; m_btnExit.Click += new EventHandler(btnExit_Click); Controls.Add(m_btnExit); m_btnStart.Text = "StartGPS"; m_btnStart.Top = 20; m_btnStart.Click += new EventHandler(btnStart_Click); Controls.Add(m_btnStart); m_btnStop.Text = "StopGPS"; m_btnStop.Top = m_btnStart.Top; m_btnStop.Left = m_btnStart.Width + 5; m_btnStop.Click += new EventHandler(btnStop_Click); Controls.Add(m_btnStop); m_btnExecute.Text = "LuaMsgbox"; m_btnExecute.Top = m_btnStart.Top; m_btnExecute.Left = m_btnStop.Left + m_btnStop.Width + 5; m_btnExecute.Click += new EventHandler(btnExecute_Click); Controls.Add(m_btnExecute); m_txt.Top = 40; m_txt.Multiline = true; m_txt.Height = Screen.PrimaryScreen.Bounds.Height - 60; m_txt.Width = Screen.PrimaryScreen.Bounds.Width; Controls.Add(m_txt); m_gps.NewData += new GPS.NewDataEventHandler(gps_NewData); } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Exception, ex); } }
/// <summary> /// Checks, if the file has the desired format /// </summary> /// <returns>True, if file format is correct</returns> private Boolean FileOk() { bool retValue = true; try { fileStream.Seek(0, SeekOrigin.Begin); for (int i = 0; i < cartId.Length; i++) { if (Convert.ToChar(binaryReader.Read()) != cartId[i]) { retValue = false; } } } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.Cartridge, ex); } return(retValue); }
private void InitializeData() { lbObject.Items.Clear(); try { foreach (KeyValuePair <short, Objects> pair in gwc.cartridge.Obj()) { if (pair.Value.Data != null) { lbObject.Items.Add(String.Format("{0} ({1} - {2:#,###} Bytes)", pair.Value.ObjectId, pair.Value.ObjectTypeString, pair.Value.Data.Length)); } else { lbObject.Items.Add(String.Format("{0} ({1})", pair.Value.ObjectId, pair.Value.ObjectTypeString)); } } } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, ex); } }
private void lbObject_SelectedIndexChanged(object sender, EventArgs e) { short id; Objects obj; pbImage.Image = null; try { id = Convert.ToInt16(lbObject.SelectedItem.ToString().Split(' ')[0]); obj = gwc.cartridge.GetObject(id); if (obj.ObjectType >= 1 && obj.ObjectType <= 4) { ImageConverter ic = new ImageConverter(); Image objImage = (Image)ic.ConvertFrom(obj.Data); Bitmap objBitmap = new Bitmap(objImage); pbImage.Image = objBitmap; } } catch (Exception ex) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, ex); } }
private void gps_NewData(object sender, GPSEventArgs e) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, "gps_NewData"); ScreenHelper.SetValue(m_txt, ScreenHelper.Property.Text, e.Data); }
private void btnExit_Click(object sender, System.EventArgs e) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, "btnExit_Click"); Application.Exit(); }
private void btnStop_Click(object sender, System.EventArgs e) { Trace.DoTrace(Trace.TraceCategories.WherugoApp, "btnStop_Click"); m_gps.StopGPS(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void serialPort_PinChanged(object sender, SerialPinChangedEventArgs e) { Trace.DoTrace(Trace.TraceCategories.Communication, "The method serialPort_PinChanged is not implemented."); }