private void ThreadProc() { bool fAbort = false; try { m_dev.OnProgress += new MFDevice.OnProgressHandler(OnStatus); if (m_evtShutdown.WaitOne(0, false)) { return; } m_evtDevice = m_dev.EventCancel; m_dev.DbgEngine.PauseExecution(); if (m_fEraseCmd) { if (!m_dev.Erase()) { throw new MFDeployEraseFailureException(); } } else { int cnt = 0; List <uint> executionPoints = new List <uint>(); foreach (string file in m_files) { uint entry = 0; if (!m_dev.Deploy(file, m_sigFiles[cnt++], ref entry)) { throw new MFDeployDeployFailureException(); } if (entry != 0) { executionPoints.Add(entry); } } executionPoints.Add(0); OnStatus(100, 100, "Executing Application"); foreach (uint addr in executionPoints) { if (m_dev.Execute(addr)) { break; } } } } catch (ThreadAbortException) { fAbort = true; } catch (MFUserExitException) { fAbort = true; } catch (Exception e) { if (!m_evtShutdown.WaitOne(0, false)) { this.Invoke((MethodInvoker) delegate { MessageBox.Show(this, Properties.Resources.ErrorPrefix + e.Message, Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); }); } } finally { m_evtDeviceFinished.Set(); if (m_dev.DbgEngine != null) { m_dev.DbgEngine.ResumeExecution(); } m_dev.OnProgress -= new MFDevice.OnProgressHandler(OnStatus); if (!fAbort && !m_evtShutdown.WaitOne(100, false)) { this.Invoke((MethodInvoker) delegate { Close(); }); } } }
private void ThreadProc() { bool fAbort = false; try { m_dev.OnProgress += new MFDevice.OnProgressHandler(OnStatus); if (m_evtShutdown.WaitOne(0, false)) { return; } m_evtDevice = m_dev.EventCancel; bool fMicroBooter = (m_dev.Ping() == PingConnectionType.MicroBooter); if (!fMicroBooter) { m_dev.DbgEngine.PauseExecution(); } if (m_fEraseCmd) { if (!m_dev.Erase(m_eraseBlocks)) { throw new MFDeployEraseFailureException(); } } else { int cnt = 0; List <uint> executionPoints = new List <uint>(); foreach (string file in m_files) { uint entry = 0; if (Path.GetExtension(file).ToLower() == ".nmf") { if (!m_dev.DeployUpdate(file)) { throw new MFDeployDeployFailureException(); } return; } else if (!m_dev.Deploy(file, m_sigFiles[cnt++], ref entry)) { throw new MFDeployDeployFailureException(); } if (entry != 0) { executionPoints.Add(entry); } } executionPoints.Add(0); if (!fMicroBooter) { for (int i = 0; i < 10; i++) { if (m_dev.Connect(500, true)) { break; } } } OnStatus(100, 100, "Executing Application"); foreach (uint addr in executionPoints) { if (m_dev.Execute(addr)) { break; } } } //if (!m_dev.CheckForMicroBooter() && m_dev.DbgEngine != null && m_dev.DbgEngine.IsConnected && // m_dev.DbgEngine.ConnectionSource == SPOT.Debugger.ConnectionSource.TinyCLR) //{ // m_dev.DbgEngine.ResumeExecution(); //} } catch (ThreadAbortException) { fAbort = true; } catch (MFUserExitException) { fAbort = true; } catch (Exception e) { if (!m_evtShutdown.WaitOne(0, false)) { this.Invoke((MethodInvoker) delegate { MessageBox.Show(this, Properties.Resources.ErrorPrefix + e.Message, Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); }); } } finally { m_evtDeviceFinished.Set(); if (m_dev.DbgEngine != null) { try { if (m_dev.IsConnected && m_dev.DbgEngine.ConnectionSource == SPOT.Debugger.ConnectionSource.TinyCLR) { m_dev.DbgEngine.ResumeExecution(); } } catch { } } m_dev.OnProgress -= new MFDevice.OnProgressHandler(OnStatus); if (!fAbort && !m_evtShutdown.WaitOne(100, false)) { this.Invoke((MethodInvoker) delegate { Close(); }); } } }
internal void Execute() { MFDeploy deploy = new MFDeploy(); MFDevice port = null; try { switch (m_cmd) { case Commands.Help: Console.WriteLine(); Console.WriteLine(Properties.Resources.HelpBanner); Console.WriteLine(); Console.WriteLine(Properties.Resources.HelpDescription); Console.WriteLine(); Console.WriteLine(Properties.Resources.HelpUsage); Console.WriteLine(); Console.WriteLine(Properties.Resources.HelpCommand); foreach (CommandMap cm in m_commandMap) { Console.WriteLine(" " + cm.HelpString); } Console.WriteLine(); Console.WriteLine(Properties.Resources.HelpInterface); foreach (InterfaceMap im in m_interfaceMap) { Console.WriteLine(" " + im.InterfaceHelp); } Console.WriteLine(); Console.WriteLine(Properties.Resources.HelpInterfaceSpecial); Console.WriteLine(); break; case Commands.List: foreach (MFPortDefinition pd in deploy.DeviceList) { Console.WriteLine(pd.Name); } break; case Commands.Ping: Console.Write(Properties.Resources.StatusPinging); try { port = deploy.Connect(m_transports[0]); Console.WriteLine(port.Ping().ToString()); } catch (Exception e) { Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message); } break; case Commands.Erase: Console.Write(Properties.Resources.StatusErasing); try { port = deploy.Connect(m_transports[0]); port.OnProgress += new MFDevice.OnProgressHandler(OnStatus); Console.WriteLine((port.Erase() ? Properties.Resources.ResultSuccess : Properties.Resources.ResultFailure)); port.OnProgress -= new MFDevice.OnProgressHandler(OnStatus); } catch (Exception e) { Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message); } break; case Commands.Deploy: try { bool fOK = false; uint entrypoint = 0; port = deploy.Connect(m_transports[0]); foreach (string file in m_flashFiles) { uint entry = 0; FileInfo fi = new FileInfo(file); string signature_file = file; if (fi.Extension != null || fi.Extension.Length > 0) { int index = file.LastIndexOf(fi.Extension); signature_file = file.Remove(index, fi.Extension.Length); } signature_file += ".sig"; if (!File.Exists(file)) { Console.WriteLine(string.Format(Properties.Resources.ErrorFileNotFound, file)); break; } if (!File.Exists(signature_file)) { Console.WriteLine(string.Format(Properties.Resources.ErrorFileNotFound, signature_file)); break; } Console.WriteLine(string.Format(Properties.Resources.StatusFlashing, file)); port.OnProgress += new MFDevice.OnProgressHandler(OnDeployStatus); fOK = port.Deploy(file, signature_file, ref entry); port.OnProgress -= new MFDevice.OnProgressHandler(OnDeployStatus); Console.WriteLine(); Console.WriteLine((fOK ? Properties.Resources.ResultSuccess : Properties.Resources.ResultFailure)); if (entry != 0 && entrypoint == 0 || file.ToLower().Contains("\\er_flash")) { entrypoint = entry; } } if (fOK) { Console.WriteLine(string.Format(Properties.Resources.StatusExecuting, entrypoint)); port.Execute(entrypoint); } } catch (Exception e) { Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message); } break; case Commands.Reboot: try { port = deploy.Connect(m_transports[0]); Console.WriteLine(Properties.Resources.StatusRebooting); port.Reboot(!m_fWarmReboot); } catch (Exception e) { Console.WriteLine(Properties.Resources.ErrorPrefix + e.Message); } break; } } catch (Exception e) { Console.WriteLine(string.Format(Properties.Resources.ErrorFailure, e.Message)); } finally { if (deploy != null) { deploy.Dispose(); deploy = null; } } }