136 lines
4.1 KiB
C#
136 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
|
|
namespace OliviaAddIn
|
|
{
|
|
|
|
/**
|
|
* @file ButtonInicio.cs
|
|
* Clase del botón del AddIn OLIVIA para ArcMap.
|
|
* Contiene el manejo de sus eventos como el Click o la actualización de su estado.
|
|
*/
|
|
/**
|
|
* Clase del botón del AddIn OLIVIA para ArcMap.
|
|
* Contiene el manejo de sus eventos como el Click o la actualización de su estado.
|
|
*/
|
|
public class ButtonInicio : ESRI.ArcGIS.Desktop.AddIns.Button
|
|
{
|
|
//*************************************************************************************
|
|
//Variables
|
|
|
|
//*************************************************************************************
|
|
//Métodos
|
|
public ButtonInicio()
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnClick()
|
|
{
|
|
try
|
|
{
|
|
bool ini_bien = true;
|
|
try
|
|
{
|
|
string err_str = "";
|
|
if (!OliviaGlob.lee_ini_gen(out err_str))
|
|
{
|
|
ini_bien = false;
|
|
MessageBox.Show(err_str, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
ini_bien = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("Error al iniciar Olivia. No se puede acceder al archivo de configuración: cfg.ini. Comprobar accesibilidad a la carpeta.", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
if (!ini_bien)
|
|
return;
|
|
|
|
if (!coge_ip())
|
|
return; //FALTA loguear error...
|
|
|
|
if (!comprueba_dlls())
|
|
return;
|
|
|
|
////////////////////////////
|
|
|
|
Application.EnableVisualStyles();
|
|
ArcMap.Application.CurrentTool = null;
|
|
|
|
//abre la ventana de configuración inicial
|
|
OliviaGlob.inidlg = new InicioDlg();
|
|
OliviaGlob.ya_open_app = true;
|
|
OliviaGlob.inidlg.Show();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
MessageBox.Show(e.Message, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
Enabled = !OliviaGlob.ya_open_app;
|
|
}
|
|
|
|
/**
|
|
* Coge la ip local para la comunicación con geofoto
|
|
*/
|
|
protected bool coge_ip()
|
|
{
|
|
try
|
|
{
|
|
string[] ips = OliviaGlob.dame_local_ips();
|
|
if (ips != null && ips.Length > 0)
|
|
OliviaGlob.ip = ips[0];
|
|
else
|
|
OliviaGlob.ip = "127.0.0.1";
|
|
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("Error al coger la IP.", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* La primera vez copia las dlls necesarias en el directorio del arcmap
|
|
*/
|
|
protected bool comprueba_dlls()
|
|
{
|
|
string path_dll_dest = null, dll = null;
|
|
try
|
|
{
|
|
//comprueba igt_base.dll
|
|
dll = "igt_base.dll";
|
|
|
|
path_dll_dest = Path.Combine(Application.StartupPath, dll);
|
|
if (!File.Exists(path_dll_dest))
|
|
{
|
|
MessageBox.Show("No se encuentran las librerías necesarias, compruebe la instalación", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("Error al comprobar las dll " + dll + "ubicada en:" + path_dll_dest, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|