/// <summary> /// Execute the GpsBabel command defined by all parameters/options/properties. /// /// <p/>Raise a GpsBabelException whenever an error occurs. /// </summary> /// <param name="inputText"></param> /// <param name="outputText"></param> public void Execute(string args) { string tempFileInput = null; string tempFileOutput = null; bool quakeMapOutput = false; Exception exc = null; if (args != null && args.IndexOf("-i QuakeMap") != -1) { tempFileInput = GetTempFileName(); args = args.Replace("-i QuakeMap", "-i gpx -f \"" + tempFileInput + "\""); // run QuakeMap to dump required info into tempFileInput try { QMApiLib qmApiLib = new QMApiLib(); qmApiLib.exportToFile(tempFileInput); } catch (Exception ee) { LibSys.StatusBar.Error(ee.Message); try { File.Delete(tempFileInput); } catch {} throw(ee); } } if (args != null && args.IndexOf("-o QuakeMap") != -1) { quakeMapOutput = true; tempFileOutput = GetTempFileName(); args = args.Replace("-o QuakeMap", "-o gpx -F \"" + tempFileOutput + "\""); } CmdRunner runner = new CmdRunner(); string outputText; runner.executeCommand(Executable, args == null ? Args : args, Bindirectory, null, out outputText); m_result = runner.OutputString; m_error = runner.ErrorString; if (runner.exitcode == 0 && quakeMapOutput) { try { QMApiLib qmApiLib = new QMApiLib(); qmApiLib.resetZoom(); // prepare for a zoom into the file switch (MapType) { case MapType.Aerial: qmApiLib.CommandMappingEngine("/map=aerial"); break; case MapType.ColorAerial: qmApiLib.CommandMappingEngine("/map=color"); break; case MapType.Topo: qmApiLib.CommandMappingEngine("/map=topo"); break; case MapType.None: qmApiLib.CommandMappingEngine("/map=none"); break; } qmApiLib.CommandMappingEngine(tempFileOutput); } catch (Exception ee) { LibSys.StatusBar.Error(ee.Message); exc = ee; } } try { File.Delete(tempFileInput); } catch {} try { File.Delete(tempFileOutput); } catch {} if (exc != null) { throw exc; } }