SafeDispatch/SetupProj/SetupProj/MainForm.cs

5197 lines
219 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
using SafeMobileLib;
using Nini.Config;
using System.Threading;
using Telerik.WinControls.UI;
using System.ServiceProcess;
using System.Management;
using Telerik.WinControls;
using IWshRuntimeLibrary;
using System.Collections;
using System.Xml;
using System.Timers;
using Microsoft.Win32;
using SharedUI;
using IO = System.IO;
namespace SetupProj
{
public partial class MainForm : Telerik.WinControls.UI.RadForm
{
/*
private enum APP_ADD_REMOVE { UPDATER, DISPATCH, GW_TRBO, GW_REPEATER, GW_CPLUS, GW_TETRA, GW_TETRA_SDR, ADMIN_MODULE, APP_SERVER,
TCP_SERVER, TCP_CLIENT, DISPATCH_MOBILE, DATABASE }*/
//private Dictionary<String, String> productCodes = new Dictionary<String, String>();
public static RADIOTYPE radioType = RADIOTYPE.EXCERA;
public static Color HarrisColor = System.Drawing.SystemColors.ControlDark;
public static Color HarTextColor = Color.White;
public static String AppNAME = "Vision";
public static String ShortcutAppNAME = "Vision";
public static String GatewayNAME = "Momentum";
private Thread[] installThreads;
private volatile bool threadLock = false;
private IConfigSource source = null;
private string CFG_SUM = "SubsConfig.ini";
private string CFG_GW = "GWconfig.ini";
private string CFG_SD = "config.ini";
private string CFG_APP = "appConfig.ini";
private string CFG_Upd = "UpdateConfig.ini";
private string CFG_Server = "TCPServerService.exe.config";
private string CFG_Client = "TCPClientService.exe.config";
private string EXE_SUM = "AdministrativeModule.exe";
private string EXE_Gateway = "MotoTRBO_GW.exe";
private string EXE_Dispatcher = "SafeDispatch_4_0.exe";
private string EXE_APP = "AppServer.exe";
private string EXE_APPMobile = "AppServerMobile.exe";
private string EXE_Upd = "Updater.exe";
private string EXE_Server = "TCPServerService.exe";
private string EXE_Client = "TCPClientService.exe";
private string uInstall_SUM = "AdministrativeModule";
private string uInstall_Gateway = "Gateway";
private string uInstall_Dispatcher = "Vision";
private string uInstall_APP = "AppServer";
private string uInstall_Upd = "SoftwareUpdate";
private String DirName_Sepura3T_SDR = "Sepura3T_SDR";
private String DirName_Tetra_SDR = "Tetra_SDR";
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private string kitPath = "";
private string installPath = "";
private Boolean SystemType32 = false;
private int installNR = 0;
public static Boolean AdvanceSettings = false;
ManagementObjectSearcher allProducts;
private Hashtable uninstall_hash;
private Hashtable install_hash;
public static Boolean install_Repeater_GW = false;
public MainForm(EULA parent)
{
InitializeComponent();
RadMessageBox.SetThemeName("TelerikMetroBlue");
SM debug = new SM();
parent.Visible = false;
txDefPort.Value = 5432;
txDefPortSD.Value = 5432;
txDefPortSUM.Value = 5432;
txDefPortGW.Value = 5432;
dropGatewayList.DropDownListElement.DropDownWidth = 126;
switch (radioType)
{
case RADIOTYPE.MOTO:
AppNAME = "SafeDispatch";
GatewayNAME = "MotoTRBO";
uInstall_Dispatcher = "SafeDispatch";
ShortcutAppNAME = "SafeDispatch";
EXE_Dispatcher = "Dispatcher.exe";
EXE_Gateway = "MotoTRBO_GW.exe";
uInstall_Gateway = "Gateway";
dropGatewayList.Visible = true;
labelGatewayType.Visible = true;
dropGatewayList.SelectedIndex = 0;
linkAdvance.Location = new Point(linkAdvance.Location.X+90, linkAdvance.Location.Y +12);
gbDispatch.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255-192,255-219,0);
gbAdmin.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbDatabase.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbGateway.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
// move install checkbox location
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 33);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 51);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 47);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 33);
break;
case RADIOTYPE.LISF:
AppNAME = "SafeDispatch";
GatewayNAME = "Sepura3T_SDR";
uInstall_Dispatcher = "SafeDispatch";
ShortcutAppNAME = "SafeDispatch";
EXE_Dispatcher = "SafeDispatch.exe";
EXE_Gateway = "Sepura3T_SDR.exe";
uInstall_Gateway = "Gateway";
dropGatewayList.Items.Clear();
dropGatewayList.Items.Add(new RadListDataItem("SEPURA 3T SDR"));
dropGatewayList.Items.Add(new RadListDataItem("TETRA SDR"));
dropGatewayList.Visible = true;
labelGatewayType.Visible = true;
dropGatewayList.SelectedIndex = 0;
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
linkAdvance.Location = new Point(linkAdvance.Location.X + 90, linkAdvance.Location.Y + 12);
gbDispatch.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbAdmin.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbDatabase.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbGateway.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
// move install checkbox location
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 33);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 51);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 47);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 33);
break;
case RADIOTYPE.HYT:
this.BackgroundImage = global::SetupProj.Properties.Resources.HytLogin;
AppNAME = "SafeSyt";
GatewayNAME = "Hytera";
uInstall_Dispatcher = "SafeSyt";
ShortcutAppNAME = "SafeSyt";
EXE_Dispatcher = "SafeSyt.exe";
EXE_Gateway = "GateWAY.exe";
uInstall_Gateway = "Gateway";
gbDispatch.Text = AppNAME;
gbDispatch.BackColor = Color.Transparent;
gbDispatch.GroupBoxElement.Header.Fill.BackColor = Color.Moccasin;
gbAdmin.BackColor = Color.Transparent;
gbAdmin.GroupBoxElement.Header.Fill.BackColor = Color.Moccasin;
gbDatabase.BackColor = Color.Transparent;
gbDatabase.GroupBoxElement.Header.Fill.BackColor = Color.Moccasin;
gbGateway.BackColor = Color.Transparent;
gbGateway.GroupBoxElement.Header.Fill.BackColor = Color.Moccasin;
Color tmp = Color.DarkBlue;
cbDBinstall.ForeColor = tmp;
cbGWinstall.ForeColor = tmp;
cbSDinstall.ForeColor = tmp;
cbSUMinstall.ForeColor = tmp;
radLabel1.ForeColor = tmp;
radLabel2.ForeColor = tmp;
radLabel3.ForeColor = tmp;
radLabel4.ForeColor = tmp;
radLabel5.ForeColor = tmp;
radLabel6.ForeColor = tmp;
lbStatus.ForeColor = tmp;
install_folder.ForeColor = tmp;
gbDispatch.Text = AppNAME;
gbDispatch.Location = new Point(gbDispatch.Location.X - 55, gbDispatch.Location.Y + 10);
gbAdmin.Location = new Point(gbAdmin.Location.X - 55, gbAdmin.Location.Y + 10);
gbDatabase.Location = new Point(gbDatabase.Location.X - 55, gbDatabase.Location.Y + 10);
gbGateway.Location = new Point(gbGateway.Location.X - 55, gbGateway.Location.Y + 10);
closePanel.Location = new Point(closePanel.Location.X - 20, closePanel.Location.Y + 20);
cbGWinstall.Location = new Point(13, 37);
install_folder.Location = new Point(install_folder.Location.X, install_folder.Location.Y+5);
linkAdvance.Location = new Point(linkAdvance.Location.X+20, linkAdvance.Location.Y+20);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 50);
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 30);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 30);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 30);
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
case RADIOTYPE.HARRIS:
ThemeResolutionService.ApplicationThemeName = "Office2010Black";
this.BackgroundImage = global::SetupProj.Properties.Resources.vision588h;
AppNAME = "Vision";
GatewayNAME = "Momentum";
uInstall_Dispatcher = "Vision";
ShortcutAppNAME = "Vision";
EXE_Dispatcher = "Vision.exe";
EXE_Gateway = "GateWAY.exe";
uInstall_Gateway = "Gateway";
gbDispatch.Text = AppNAME;
gbDispatch.Location = new Point(gbDispatch.Location.X - 45, gbDispatch.Location.Y + 20);
// radGroupBox1.Size = new Size(radGroupBox1.Width + 20, radGroupBox1.Height);
gbDispatch.BackColor = Color.Transparent;
gbAdmin.Location = new Point(gbAdmin.Location.X - 45, gbAdmin.Location.Y + 20);
//radGroupBox2.Size = new Size(radGroupBox2.Width + 20, radGroupBox2.Height);
gbAdmin.BackColor = Color.Transparent;
gbDatabase.Location = new Point(gbDatabase.Location.X - 45, gbDatabase.Location.Y + 20);
// radGroupBox3.Size = new Size(radGroupBox3.Width + 20, radGroupBox3.Height);
gbDatabase.BackColor = Color.Transparent;
gbGateway.Location = new Point(gbGateway.Location.X - 45, gbGateway.Location.Y + 20);
// radGroupBox4.Size = new Size(radGroupBox4.Width + 20, radGroupBox4.Height);
gbGateway.BackColor = Color.Transparent;
// closePanel.Location = new Point(closePanel.Location.X - 20, closePanel.Location.Y + 20);
cbGWinstall.Location = new Point(13, 47);
//radGroupBox1
//cbSDinstall.Location = new Point(20, 37);
// radLabel1.Location = new Point(135, 23);
// cbChangePortSD.Location = new Point(110, 52);
// tbSDdb.Location = new Point(235, 21);
// txDefPortSD.Location = new Point(235, 50);
//radGroupBox2
/* cbGWinstall.Location = new Point(20, 37);
radLabel4.Location = new Point(135, 23);
cbChangePortSUM.Location = new Point(110, 52);
tbSUMdb.Location = new Point(235, 21);
txDefPortSUM.Location = new Point(235, 50);
//radGroupBox4
cbSUMinstall.Location = new Point(20, 37);
radLabel3.Location = new Point(135, 23);
cbChangePortGW.Location = new Point(110, 52);
tbGWdb.Location = new Point(235, 21);
txDefPortGW.Location = new Point(235, 50);
tbDBadminPass.Location = new Point(tbDBadminPass.Location.X + 10, tbDBadminPass.Location.Y);
tbDBdefaulPAss.Location = new Point(tbDBdefaulPAss.Location.X + 10, tbDBdefaulPAss.Location.Y);
txDefPort.Location = new Point(txDefPort.Location.X + 10, txDefPort.Location.Y);*/
tbSUMdb.BackColor = Color.White;
tbSDdb.BackColor = Color.White;
tbInstallPath.BackColor = Color.White;
tbGWdb.BackColor = Color.White;
tbDBdefaulPAss.BackColor = Color.White;
tbDBadminPass.BackColor = Color.White;
cbDBinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
cbGWinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
cbSDinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
cbSUMinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
install_folder.Location = new Point(install_folder.Location.X + 10, install_folder.Location.Y);
lbStatus.Location = new Point(lbStatus.Location.X + 10, lbStatus.Location.Y);
radLabel1.ForeColor = HarTextColor;
radLabel2.ForeColor = HarTextColor;
radLabel3.ForeColor = HarTextColor;
radLabel4.ForeColor = HarTextColor;
radLabel5.ForeColor = HarTextColor;
radLabel6.ForeColor = HarTextColor;
install_folder.ForeColor = HarTextColor;
lbStatus.ForeColor = HarTextColor;
version.BackColor = Color.Black;
version.ForeColor = HarTextColor;
version.Location = new Point(version.Location.X, version.Location.Y+5);
linkAdvance.BackColor = Color.Transparent;
linkAdvance.Location = new Point(linkAdvance.Location.X + 20, linkAdvance.Location.Y + 20);
rbTCPServer.BackColor = Color.Transparent;
rbTCPClient.BackColor = Color.Transparent;
rbNoService.BackColor = Color.Transparent;
lbServerIP.BackColor = Color.Transparent;
lbPort.BackColor = Color.Transparent;
lbServerIP.Font = new System.Drawing.Font("Segoe UI Semibold", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lbPort.Font = new System.Drawing.Font("Segoe UI Semibold", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
cbInstallSDMobile.BackColor = Color.Transparent;
cbSDinstall.BackColor = cbGWinstall.BackColor = cbDBinstall.BackColor = cbSUMinstall.BackColor = Color.Transparent;
cbSDinstall.ForeColor = cbGWinstall.ForeColor = cbDBinstall.ForeColor = cbSUMinstall.ForeColor = Color.White;
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 50);
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 30);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 30);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 30);
break;
case RADIOTYPE.ATLAS:
ThemeResolutionService.ApplicationThemeName = "Office2010Black"; //ATLASCHANGE
this.BackgroundImage = global::SetupProj.Properties.Resources.ATL25GUI2;
AppNAME = "Atl25";
GatewayNAME = "Astro";
uInstall_Dispatcher = "Atl25";
ShortcutAppNAME = "Atl25";
EXE_Dispatcher = "Atl25.exe";
EXE_Gateway = "ASTRO_GW.exe";
uInstall_Gateway = "Gateway";
gbDispatch.Text = "ATL25";
gbDispatch.Location = new Point(gbDispatch.Location.X - 400, gbDispatch.Location.Y + 10);
gbDispatch.BackColor = Color.Transparent;
gbAdmin.Location = new Point(gbAdmin.Location.X - 400, gbAdmin.Location.Y + 10);
gbAdmin.BackColor = Color.Transparent;
gbDatabase.Location = new Point(gbDatabase.Location.X - 400, gbDatabase.Location.Y + 10);
gbDatabase.BackColor = Color.Transparent;
gbGateway.Location = new Point(gbGateway.Location.X - 400, gbGateway.Location.Y + 10);
gbGateway.BackColor = Color.Transparent;
/*
gbDispatch.Size = new Size(gbDispatch.Width + 50, gbDispatch.Height);
gbAdmin.Size = new Size(gbAdmin.Width + 50, gbAdmin.Height);
gbDatabase.Size = new Size(gbDatabase.Width + 50, gbDatabase.Height);
gbGateway.Size = new Size(gbGateway.Width + 50, gbGateway.Height);
*/
//closePanel.Location = new Point(closePanel.Location.X - 20, closePanel.Location.Y + 20);
//gbDatabase
install_folder.Location = new Point(install_folder.Location.X - 240, install_folder.Location.Y - 30);
tbInstallPath.Location = new Point(tbInstallPath.Location.X - 390, tbInstallPath.Location.Y-10);
ChangeFolder.Location = new Point(ChangeFolder.Location.X - 390, ChangeFolder.Location.Y-10);
radLabel6.Location = new Point(radLabel6.Location.X - 230, radLabel6.Location.Y - 10);
lbStatus.Location = new Point(lbStatus.Location.X - 230, lbStatus.Location.Y-10);
radWaitingBar1.Location = new Point(radWaitingBar1.Location.X - 230, radWaitingBar1.Location.Y - 10);
version.Location = new Point(version.Location.X + 240, version.Location.Y - 10);
tbDBadminPass.Location = new Point(tbDBadminPass.Location.X + 10, tbDBadminPass.Location.Y);
tbDBdefaulPAss.Location = new Point(tbDBdefaulPAss.Location.X + 10, tbDBdefaulPAss.Location.Y);
txDefPort.Location = new Point(txDefPort.Location.X + 10, txDefPort.Location.Y);
btnInstall.Location = new Point(btnInstall.Location.X - 100, btnInstall.Location.Y-70);
btnUnInstall.Location = new Point(btnUnInstall.Location.X - 100, btnUnInstall.Location.Y-70);
btnInstall.Size = new Size(btnInstall.Size.Width+30, btnInstall.Size.Height);
btnUnInstall.Size = new Size(btnUnInstall.Size.Width+30, btnUnInstall.Size.Height);
tbSUMdb.BackColor = Color.White;
tbSDdb.BackColor = Color.White;
tbInstallPath.BackColor = Color.White;
tbGWdb.BackColor = Color.White;
tbDBdefaulPAss.BackColor = Color.White;
tbDBadminPass.BackColor = Color.White;
((Telerik.WinControls.Primitives.TextPrimitive)(this.rbTCPClient.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(0))).ForeColor = HarTextColor;
((Telerik.WinControls.Primitives.TextPrimitive)(this.rbTCPServer.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(0))).ForeColor = HarTextColor;
((Telerik.WinControls.Primitives.TextPrimitive)(this.rbNoService.GetChildAt(0).GetChildAt(1).GetChildAt(0).GetChildAt(0))).ForeColor = HarTextColor;
lbServerIP.ForeColor = HarTextColor;
lbPort.ForeColor = HarTextColor;
cbInstallSDMobile.ForeColor = HarTextColor;
cbDBinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
cbGWinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
cbSDinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
cbSUMinstall.ButtonElement.TextElement.ForeColor = HarTextColor;
radLabel1.ForeColor = HarTextColor;
radLabel2.ForeColor = HarTextColor;
radLabel3.ForeColor = HarTextColor;
radLabel4.ForeColor = HarTextColor;
radLabel5.ForeColor = HarTextColor;
radLabel6.ForeColor = HarTextColor;
((Telerik.WinControls.Primitives.TextPrimitive)(this.gbDispatch.GetChildAt(0).GetChildAt(1).GetChildAt(2).GetChildAt(1))).ForeColor = Color.White;
((Telerik.WinControls.Primitives.TextPrimitive)(this.gbAdmin.GetChildAt(0).GetChildAt(1).GetChildAt(2).GetChildAt(1))).ForeColor = Color.White;
((Telerik.WinControls.Primitives.TextPrimitive)(this.gbDatabase.GetChildAt(0).GetChildAt(1).GetChildAt(2).GetChildAt(1))).ForeColor = Color.White;
((Telerik.WinControls.Primitives.TextPrimitive)(this.gbGateway.GetChildAt(0).GetChildAt(1).GetChildAt(2).GetChildAt(1))).ForeColor = Color.White;
install_folder.ForeColor = HarTextColor;
lbStatus.ForeColor = HarTextColor;
version.BackColor = Color.Black;
version.ForeColor = HarTextColor;
linkAdvance.BackColor = Color.Transparent;
linkAdvance.Location = new Point(linkAdvance.Location.X - 300, linkAdvance.Location.Y + 20);
rbTCPServer.BackColor = Color.Transparent;
rbTCPClient.BackColor = Color.Transparent;
rbNoService.BackColor = Color.Transparent;
lbServerIP.BackColor = Color.Transparent;
lbPort.BackColor = Color.Transparent;
lbServerIP.Font = new System.Drawing.Font("Segoe UI Semibold", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
lbPort.Font = new System.Drawing.Font("Segoe UI Semibold", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
cbInstallSDMobile.BackColor = Color.Transparent;
cbSDinstall.BackColor = cbGWinstall.BackColor = cbDBinstall.BackColor = cbSUMinstall.BackColor = Color.Transparent;
cbSDinstall.ForeColor = cbGWinstall.ForeColor = cbDBinstall.ForeColor = cbSUMinstall.ForeColor =
radLabel7.ForeColor = radLabel8.ForeColor = radLabel9.ForeColor = radLabel10.ForeColor = Color.White;
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 50);
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 30);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 30);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 30);
break;
case RADIOTYPE.SIMOCO:
this.BackgroundImage = global::SetupProj.Properties.Resources.simoco3RE;
AppNAME = "SimocoDispatch";
GatewayNAME = "SimocoGWCore";
uInstall_Dispatcher = "SimocoDispatch";
ShortcutAppNAME = "Simoco Dispatch";
EXE_Dispatcher = "SimocoDispatch.exe";
EXE_Gateway = "SimocoGWCore.exe";
uInstall_Gateway = "Gateway";
gbDispatch.Text = AppNAME;
//depend on the desing picture
gbDispatch.BackColor = Color.Transparent;
gbDispatch.GroupBoxElement.Header.Fill.BackColor = Color.Transparent;
gbAdmin.BackColor = Color.Transparent;
gbAdmin.GroupBoxElement.Header.Fill.BackColor = Color.Transparent;
gbDatabase.BackColor = Color.Transparent;
gbDatabase.GroupBoxElement.Header.Fill.BackColor = Color.Transparent;
gbGateway.BackColor = Color.Transparent;
gbGateway.GroupBoxElement.Header.Fill.BackColor = Color.Transparent;
/* Color tmp = Color.DarkBlue;
cbDBinstall.ForeColor = tmp;
cbGWinstall.ForeColor = tmp;
cbSDinstall.ForeColor = tmp;
cbSUMinstall.ForeColor = tmp;
radLabel1.ForeColor = tmp;
radLabel2.ForeColor = tmp;
radLabel3.ForeColor = tmp;
radLabel4.ForeColor = tmp;
radLabel5.ForeColor = tmp;
radLabel6.ForeColor = tmp;
lbStatus.ForeColor = tmp;
install_folder.ForeColor = tmp;*/
gbDispatch.Text = AppNAME;
gbDispatch.Location = new Point(75, 230);
gbGateway.Location = new Point(75, 330);
gbAdmin.Location = new Point(450, 230);
gbDatabase.Location = new Point(450, 330);
linkAdvance.Location = new Point(75, 430);
linkAdvance.BackColor = Color.Transparent;
closePanel.Location = new Point(765,2);
rbTCPServer.BackColor = Color.Transparent;
rbTCPClient.BackColor = Color.Transparent;
rbNoService.BackColor = Color.Transparent;
lbServerIP.BackColor = Color.Transparent;
lbPort.BackColor = Color.Transparent;
cbInstallSDMobile.BackColor = Color.Transparent;
cbInstallSDMobile.Text = "Install Application Server for Dispatch Mobile";
version.BackColor = Color.Transparent;
/*Int32 Xdev = 500;
Int32 Ydev = -20;
rbTCPServer.Location = new Point(rbTCPServer.Location.X - Xdev, rbTCPServer.Location.Y-Ydev);
rbTCPClient.Location = new Point(rbTCPClient.Location.X - Xdev, rbTCPClient.Location.Y - Ydev);
rbNoService.Location = new Point(rbNoService.Location.X - Xdev, rbNoService.Location.Y - Ydev);*/
rbTCPServer.Location = new Point(185, 415);
lbServerIP.Location = new Point(85, 440);
version.Location = new Point(120, 500);
/* lbServerIP.Location = new Point(lbServerIP.Location.X - Xdev, lbServerIP.Location.Y - Ydev);
lbPort.Location = new Point(lbPort.Location.X - Xdev, lbPort.Location.Y - Ydev);
cbInstallSDMobile.Location = new Point(cbInstallSDMobile.Location.X - Xdev, cbInstallSDMobile.Location.Y - Ydev);
txTCPIP.Location = new Point(txTCPIP.Location.X - Xdev, txTCPIP.Location.Y - Ydev);
txTCPPort.Location = new Point(txTCPPort.Location.X - Xdev, txTCPPort.Location.Y - Ydev);*/
install_folder.Location = new Point(install_folder.Location.X, install_folder.Location.Y + 5);
cbSDinstall.BackColor = cbGWinstall.BackColor = cbDBinstall.BackColor = cbSUMinstall.BackColor = Color.Transparent;
// move install checkbox location
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 33);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 34);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 47);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 33);
break;
case RADIOTYPE.LINX:
case RADIOTYPE.LINXB:
AppNAME = "LinxDispatch";
GatewayNAME = "Linx";
uInstall_Dispatcher = "LinxDispatch";
ShortcutAppNAME = "LinxDispatch";
EXE_Dispatcher = "LinxDispatch.exe";
EXE_Gateway = "LinxGateway.exe";
uInstall_Gateway = "LinxGateway";
BackgroundImage = global::SetupProj.Properties.Resources.login_linx;
if(radioType == RADIOTYPE.LINXB)
{
dropGatewayList.Items.Clear();
dropGatewayList.Items.Add("LINX");
dropGatewayList.Items.Add("MOTOTRBO");
}
dropGatewayList.Visible = labelGatewayType.Visible = radioType == RADIOTYPE.LINXB;
dropGatewayList.SelectedIndex = 0;
gbDispatch.Text = AppNAME.ToUpper();
linkAdvance.Location = new Point(linkAdvance.Location.X + 90, linkAdvance.Location.Y + 12);
gbDispatch.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbAdmin.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbDatabase.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
gbGateway.GroupBoxElement.Header.TextPrimitive.ForeColor = Color.FromArgb(255 - 192, 255 - 219, 0);
// move install checkbox location
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 33);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 51);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 47);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 33);
break;
case RADIOTYPE.EXCERA:
AppNAME = "SafeDispatch";
GatewayNAME = "Excera";
uInstall_Dispatcher = "SafeDispatch";
ShortcutAppNAME = "SafeDispatch";
EXE_Dispatcher = "SafeDispatch.exe";
EXE_Gateway = "ExceraGateway.exe";
uInstall_Gateway = "ExceraGateway";
//ThemeResolutionService.ApplicationThemeName = "Office2010Black"; //ATLASCHANGE
this.BackgroundImage = Properties.Resources.axys;
this.BackgroundImageLayout = ImageLayout.Stretch;
linkAdvance.Location = new Point(linkAdvance.Location.X + 90, linkAdvance.Location.Y + 12);
// move install checkbox location
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 33);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 51);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 47);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 33);
break;
}
installThreads = new Thread[8];
if (CheckIPV6())//x86
{
SM.Debug("SYSTEM IPV6 ->ON");
}
else
{
SM.Debug("SYSTEM IPV6 ->OFF");
}
kitPath = System.Windows.Forms.Application.StartupPath;
kitPath += "\\";
tbInstallPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\" + Program.COMPANY;
SM.Debug("kitDir=" + kitPath);
this.Size = new Size(783, 588);
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
this.version.Text = "Version: " + v;
}
private void closePanel_Click(object sender, EventArgs e)
{
Close();
System.Windows.Forms.Application.Exit();
}
private void MainForm_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void btnInstall_Click(object sender, EventArgs e)
{
uninstall = false;
install_hash = new Hashtable();
if (tbDBadminPass.Text == "" || tbDBdefaulPAss.Text == "")
{
RadMessageBox.Show("Please insert a password for admin and default");
return;
}
//if no app selected return
if (!cbDBinstall.Checked && !cbGWinstall.Checked && !cbSDinstall.Checked && !cbSUMinstall.Checked && !AdvanceSettings)
{
RadMessageBox.Show("Please select an application for installing");
return;
}
btnInstall.Enabled = false;
radWaitingBar1.Visible = true;
installPath = tbInstallPath.Text + "\\";
if (8 == IntPtr.Size
|| (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
{
if(installPath.Contains("Program Files") && !installPath.Contains("Program Files (x86)"))
installPath = installPath.Replace("Program Files", "Program Files (x86)");
}
else SystemType32 = true;
string var = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432");
Console.WriteLine(var);
// Write path to the registry
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true);
if (key.OpenSubKey(Program.COMPANY) == null)
key.CreateSubKey(Program.COMPANY);
key = key.OpenSubKey(Program.COMPANY, true);
//if (key.GetValue("Path") == null)
key.SetValue("Path", tbInstallPath.Text);
var pathReg = key.GetValue("Path");
/*
key = Registry.CurrentUser.OpenSubKey("Software", true);
key.CreateSubKey("AppName");
key = key.OpenSubKey("AppName", true);
key.CreateSubKey("AppVersion");
key = key.OpenSubKey("AppVersion", true);
key.SetValue("yourkey", "yourvalue");
*/
try
{
DirectoryInfo dr = new DirectoryInfo(installPath);
if (!dr.Exists) dr.Create();
}
catch (Exception ex)
{
RadMessageBox.Show("Unable to create installation folder");
return;
}
btnUnInstall.Enabled = false;
if (cbDBinstall.Checked)
{
if (!Search4App("postgresql"))
{
installNR++;
installThreads[0] = new Thread(new ThreadStart(InstallDBcallback));
installThreads[0].IsBackground = true;
installThreads[0].Start();
AddToInstall_Hash("postgresql",true);
}
if (!IsAppInstalled(App.APP_SERVER)) //(!Search4App("AppServer"))
{
installNR++;
installThreads[1] = new Thread(new ThreadStart(InstallAPPcallback));
installThreads[1].IsBackground = true;
installThreads[1].Start();
AddToInstall_Hash("AppServer", true);
}
if (!IsAppInstalled(App.APP_SERVER_MOBILE)) //(!Search4App("AppServer"))
{
installNR++;
installThreads[1] = new Thread(new ThreadStart(InstallAPPcallback));
installThreads[1].IsBackground = true;
installThreads[1].Start();
AddToInstall_Hash("AppServer", true);
}
}
if (cbSDinstall.Checked)
{
App app = App.DISPATCH_MOTOROLA;
switch (radioType)
{
case RADIOTYPE.MOTO:
case RADIOTYPE.LISF:
app = App.DISPATCH_MOTOROLA;
AppNAME = "SafeDispatch"; break;
case RADIOTYPE.HYT: app = App.DISPATCH_HYTERA; AppNAME = "SafeSyt"; break;
case RADIOTYPE.HARRIS: app = App.DISPATCH_HARRIS; AppNAME = "Vision"; break;
case RADIOTYPE.ATLAS: app = App.DISPATCH_ATLAS; AppNAME = "Atl25"; break;
case RADIOTYPE.SIMOCO: app = App.DISPATCH_SIMOCO; AppNAME = "SimocoDispatch"; break;
case RADIOTYPE.LINX: case RADIOTYPE.LINXB: app = App.DISPATCH_LINX; AppNAME = "LINXDispatch"; break;
default: app = App.DISPATCH_MOTOROLA;break;
}
if (!IsAppInstalled(app)) // Search4App(AppNAME))
{
installNR++;
installThreads[2] = new Thread(new ThreadStart(InstallSDcallback));
installThreads[2].IsBackground = true;
installThreads[2].Start();
AddToInstall_Hash(AppNAME, true);
}
}
if (cbGWinstall.Checked)
{
bool isInstalled = false;
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 0) isInstalled = IsAppInstalled(App.GW_TRBO);
else if (dropGatewayList.SelectedIndex == 1) isInstalled = IsAppInstalled(App.GW_TETRA);
else if (dropGatewayList.SelectedIndex == 2) isInstalled = IsAppInstalled(App.GW_CPLUS);
else if (dropGatewayList.SelectedIndex == 3) isInstalled = IsAppInstalled(App.GW_TETRA_SDR);
else if (dropGatewayList.SelectedIndex == 4)
{
isInstalled = IsAppInstalled(App.GW_REPEATER); // Search4App("Repeater_Gateway");
install_Repeater_GW = true;
}
else if (dropGatewayList.SelectedIndex == 5) isInstalled = IsAppInstalled(App.GW_SMC);
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0) isInstalled = IsAppInstalled(App.GW_SEPURA_3T_SDR);
else if (dropGatewayList.SelectedIndex == 1) isInstalled = IsAppInstalled(App.GW_TETRA_SDR);
}
else if (radioType == RADIOTYPE.LINX)
isInstalled = IsAppInstalled(App.LINX_GATEWAY);
else if (radioType == RADIOTYPE.LINXB)
{
if(dropGatewayList.SelectedIndex == 0) isInstalled = IsAppInstalled(App.LINX_GATEWAY);
else if (dropGatewayList.SelectedIndex == 1) isInstalled = IsAppInstalled(App.GW_TRBO);
}
else
isInstalled = IsAppInstalled(App.GW_TRBO); // Search4App("Gateway");
if (!isInstalled)
{
installNR++;
installThreads[3] = new Thread(new ThreadStart(InstallGWcallback));
installThreads[3].IsBackground = true;
installThreads[3].Start();
AddToInstall_Hash("Gateway", true);
}
}
if (cbSUMinstall.Checked)
{
if (!IsAppInstalled(App.ADMIN_MODULE)) //Search4App("AdministrativeModule"))
{
installNR++;
installThreads[4] = new Thread(new ThreadStart(InstallSUMcallback));
installThreads[4].IsBackground = true;
installThreads[4].Start();
AddToInstall_Hash("AdministrativeModule", true);
}
}
//if any, then also install updater
if (cbDBinstall.Checked || cbSDinstall.Checked || cbGWinstall.Checked || cbSUMinstall.Checked)
{
// remove updater from the list of installed apps
/*
//if updater not previously not installed
if (!Search4App("Updater"))
{
installNR++;
installThreads[5] = new Thread(new ThreadStart(InstallUpdcallback));
installThreads[5].IsBackground = true;
installThreads[5].Start();
AddToInstall_Hash("Updater", true);
}*/
}
if (cbInstallSDMobile.Checked)
{
if (!Search4App("AppServerMobile"))
{
installNR++;
installThreads[6] = new Thread(new ThreadStart(InstallSDMobilecallback));
installThreads[6].IsBackground = true;
installThreads[6].Start();
AddToInstall_Hash("AppServerMobile", true);
}
}
if (AdvanceSettings)
{
if (rbTCPServer.IsChecked)
{
if (!IsAppInstalled(App.TCP_SERVER)) // Search4App("TCPServer"))
{
installNR++;
installThreads[7] = new Thread(new ThreadStart(InstallTCPServercallback));
installThreads[7].IsBackground = true;
installThreads[7].Start();
AddToInstall_Hash("TCPServer", true);
}
}
else if (rbTCPClient.IsChecked)
{
if (!IsAppInstalled(App.TCP_CLIENT)) // Search4App("TCPClient"))
{
installNR++;
installThreads[7] = new Thread(new ThreadStart(InstallTCPClientcallback));
installThreads[7].IsBackground = true;
installThreads[7].Start();
AddToInstall_Hash("TCPClient", true);
}
}
}
Console.WriteLine("Numbers of installs to be performed:" + installNR);
if (installNR == 0)
{
radWaitingBar1.Visible = false;
lbStatus.Text = "Installation not needed!!";
btnInstall.Enabled = true;
RadMessageBox.Show("All the applications that are selected are already installed.");
btnUnInstall.Enabled = true;
}
else
{
// copy remote support file to the installed path
if (Program.COMPANY.Equals("SafeMobile") && !IO.File.Exists(installPath + "\\" + "SafeMobileRemoteSupport.exe"))
{
IO.File.Copy("SafeMobileRemoteSupport.exe", installPath + "\\" + "SafeMobileRemoteSupport.exe");
// create shortcut for the remote support
CreateShortcut(installPath, "SafeMobileRemoteSupport", "SafeMobile Remote Support");
}
else if(!IO.File.Exists(installPath + "\\" + Program.COMPANY + "RemoteSupport.exe"))
{
IO.File.Copy("RemoteSupport.exe", installPath + "\\"+ Program.COMPANY + "RemoteSupport.exe");
// create shortcut for the remote support
CreateShortcut(installPath, Program.COMPANY + "RemoteSupport.exe", Program.COMPANY + " Remote Support");
}
}
}
#region Callbacks install
private void InstallDBcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
InstallDB(tbDBadminPass.Text, tbDBdefaulPAss.Text,txDefPort.Text);
}
private void InstallSDcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
InstallSD(tbSDdb.Text, txDefPortSD.Text);
}
private void InstallSDMobilecallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
InstallSDMobile(tbSDdb.Text, txDefPortSD.Text);
}
private void InstallTCPServercallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
InstallTCPServer(txTCPPort.Text);
}
private void InstallTCPClientcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
InstallTCPClient(txTCPIP.Text, txTCPPort.Text);
}
private void InstallGWcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
InstallGW(tbGWdb.Text, txDefPortGW.Text);
}
private void InstallSUMcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
InstallSUM(tbSUMdb.Text, txDefPortSUM.Text);
}
private void InstallAPPcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true; //allways in the same PC with DB
InstallAPP("127.0.0.1", txDefPort.Text);
}
private void InstallUpdcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
if (cbSDinstall.Checked)
{
InstallUpd(tbSDdb.Text, txDefPortSD.Text);
}
else if (cbGWinstall.Checked)
{
InstallUpd(tbGWdb.Text, txDefPortGW.Text);
}
else if (cbSUMinstall.Checked)
{
InstallUpd(tbSUMdb.Text, txDefPortSUM.Text);
}
else if (cbDBinstall.Checked)
{
InstallUpd("127.0.0.1", txDefPort.Text);
}
}
#endregion
#region installing methods
private void InstallDB(string adminPass, string defaultPass,String port)
{
updateStatus("Installing Database", true);
Console.WriteLine("======================================================");
SM.Debug("Installing DB");
//copy tools folder
//CopyFolder(kitPath + "Tools", installPath + "Tools");
if (port == "5432")
{
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
// unziping DB to install dir
sw.WriteLine(kitPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + kitPath + "PostgreSD" + '"');
sw.WriteLine("unzip -o postgresql.zip -d " + '"' + installPath + "postgresql" + '"');
bool testIPV6 = CheckIPV6();
if (testIPV6)//x86
{
SM.Debug("SYSTEM IPV6 ON... pg_hba64.conf copied to DB config");
sw.WriteLine("copy " + '"' + kitPath + "PostgreSD\\pg_hba64.conf" + '"' + " " + '"' + installPath + "postgresql\\SafeDB\\pg_hba.conf" + '"' + " /y");
}
else
{
SM.Debug("SYSTEM IPV6 OFF... old pg_hba.conf keeped");
}
//change Dir to install path
sw.WriteLine(installPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + installPath + "postgresql\\pgsql\\bin" + '"');
//register and start net process
sw.WriteLine("pg_ctl register -N PostgreSD -D " + '"' + installPath + "postgresql\\SafeDB" + '"');
sw.WriteLine("net start PostgreSD");
Environment.SetEnvironmentVariable("PGPASSWORD", "wizdemo26", EnvironmentVariableTarget.Machine);
}
sw.Close();
}
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
//Console.WriteLine(output);
p.WaitForExit();
//Utils.WriteLine("INSTALL Database OUTPUT RESULT " + output, ConsoleColor.Magenta);
SM.Debug("DB install completed!!!");
}
}
else InstallDBSpecial(port);
try
{
Int32 trys = 0; Boolean conectionOK = false;
DBuserManager db4users = null;
DBRadioTypeManager db4RadioType = null;
while ((trys < 4)&&(!conectionOK))
{
try
{
Thread.Sleep(3000);// wait for Postgres to start
db4users = new DBuserManager("localhost", "safedispatchdb", "postgres", "wizdemo26", port);
db4users.setPasswords(adminPass, defaultPass);
conectionOK = true;
SM.Debug("Saving new passwords in DB");
db4RadioType = new DBRadioTypeManager("localhost", "safedispatchdb", "postgres", "wizdemo26", port);
string radio_type = "";
var list = new List<int> { 1, 2, 3, 4, 5 };
if (list.Contains((int)radioType)) radio_type = ((int)radioType).ToString();
else
{
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 0) radio_type = "0";
else if (dropGatewayList.SelectedIndex == 1 || dropGatewayList.SelectedIndex == 3) radio_type = "6";
else if (dropGatewayList.SelectedIndex == 2) radio_type = "7";
else if (dropGatewayList.SelectedIndex == 4) radio_type = "8";
}
else if (radioType == RADIOTYPE.LINXB)
radio_type = ((int)RADIOTYPE.LINXB).ToString();
}
db4RadioType.setRadioType(radio_type);
conectionOK = true;
SM.Debug("Saving radio type in DB");
}
catch (Exception ex)
{
trys++;
SM.Debug("Number of trys:"+trys);
}
}
//if (conectionOK) db4users.setPasswords(adminPass, defaultPass);
SM.Debug("Saving new passwords done");
}
catch(Exception ex)
{
SM.Debug("Error opening DB" + ex.ToString());
}
Console.WriteLine("======================================================");
//signal thread complet
installNR--;
updateStatus("Database installed", false);
Thread.Sleep(1000);
threadLock = false;
}
private void InstallDBSpecial(String port)
{
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
// unziping DB to install dir
sw.WriteLine(kitPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + kitPath + "PostgreSD" + '"');
sw.WriteLine("unzip -o postgresql.zip -d " + '"' + installPath + "postgresql" + '"');
bool testIPV6 = CheckIPV6();
if (testIPV6)//x86
{
SM.Debug("SYSTEM IPV6 ON... pg_hba64.conf copied to DB config");
sw.WriteLine("copy " + '"' + kitPath + "PostgreSD\\pg_hba64.conf" + '"' + " " + '"' + installPath + "postgresql\\SafeDB\\pg_hba.conf" + '"' + " /y");
}
else
{
SM.Debug("SYSTEM IPV6 OFF... old pg_hba.conf keeped");
}
}
sw.Close();
}
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
//Console.WriteLine(output);
p.WaitForExit();
SM.Debug("DB unzip completed!!!");
}
replace_portForDB(installPath + "postgresql\\SafeDB\\postgresql.conf", "5432", port);
Process p2 = new Process();
ProcessStartInfo info2 = new ProcessStartInfo();
info2.CreateNoWindow = true;
info2.FileName = "cmd.exe";
info2.RedirectStandardInput = true;
info2.RedirectStandardOutput = true;
info2.UseShellExecute = false;
p2.StartInfo = info;
p2.Start();
StreamWriter sw2 = p2.StandardInput;
if (sw2.BaseStream.CanWrite)
{
//change Dir to install path
sw2.WriteLine(installPath.Substring(0, 2));
sw2.WriteLine("cd " + '"' + installPath + "postgresql\\pgsql\\bin" + '"');
//register and start net process
sw2.WriteLine("pg_ctl register -N PostgreSD -D " + '"' + installPath + "postgresql\\SafeDB" + '"');
sw2.WriteLine("net start PostgreSD");
Environment.SetEnvironmentVariable("PGPASSWORD", "wizdemo26", EnvironmentVariableTarget.Machine);
}
sw2.Close();
StreamReader reader2 = p2.StandardOutput;
string output2 = reader2.ReadToEnd();
//Console.WriteLine(output);
p2.WaitForExit();
SM.Debug("DB install completed!!!");
}
private void InstallSD(string ip, String port)
{
Console.WriteLine("======================================================");
SM.Debug("Installing SD");
updateStatus("Installing "+AppNAME, true);
String fileMSI = "";
string[] fileEntries;
try
{
fileEntries = Directory.GetFiles(kitPath + AppNAME);
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
fileMSI = fileNametmp.Remove(0, 1);
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + AppNAME + '"';
sw.WriteLine(kitPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + kitPath + AppNAME + '"');
sw.WriteLine(cmd);
Utils.WriteLine($"Installing Dispatcher: {cmd}", ConsoleColor.DarkYellow);
}
sw.Close();
p.WaitForExit();
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
Utils.WriteLine("INSTALL Dispatcher OUTPUT RESULT " + output, ConsoleColor.Magenta);
}
}
//Console.WriteLine(output);
FileInfo fi;
fi = new FileInfo(installPath + AppNAME+"\\" + CFG_SD);
int count = 0;
while (!fi.Exists && count < 10)
{
Thread.Sleep(1000);
count++;
SM.Debug("File " + installPath + AppNAME+"\\" + CFG_SD + " missing retry " + count);
}
try
{
//set DB IP
source = new IniConfigSource(installPath + AppNAME+"\\" + CFG_SD);
source.Configs["Server"].Set("IP", ip);
//source.Configs["Database"].Set("IP", ip);
//source.Configs["Database"].Set("Port", port);
source.Configs["Recordings"].Set("IP", ip);
source.Save();
SM.Debug("Added new DB ip to SD config file");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
installNR--;
threadLock = false;
//try
//{
// string destinationPath = installPath + AppNAME + "\\" + EXE_Dispatcher;
// string sourceFolder = getSourceFolderBasedOnSelectedGateway();
// if (radioType == RADIOTYPE.MOTO)
// {
// if (!string.IsNullOrEmpty(sourceFolder))
// {
// string sourcePath = $"{kitPath}{sourceFolder}\\{EXE_Dispatcher}";
// IO.File.Copy(sourcePath, destinationPath, true);
// }
// else
// Utils.WriteLine("Invalid sourcePath", ConsoleColor.Red);
// }
// else if (radioType == RADIOTYPE.LISF)
// {
// if (dropGatewayList.SelectedIndex == 0)
// IO.File.Copy(kitPath + DirName_Sepura3T_SDR + "\\" + EXE_Dispatcher, destinationPath, true);
// else if (dropGatewayList.SelectedIndex == 1)
// IO.File.Copy(kitPath + DirName_Tetra_SDR + "\\" + EXE_Dispatcher, destinationPath, true);
// }
// else if (radioType == RADIOTYPE.LINX || radioType == RADIOTYPE.LINXB)
// IO.File.Copy(kitPath + "Gateway\\" + EXE_Dispatcher, destinationPath, true);
// else if (radioType == RADIOTYPE.EXCERA)
// IO.File.Copy(kitPath + "Gateway\\" + EXE_Dispatcher, destinationPath, true);
// else if (radioType == RADIOTYPE.HYT)
// IO.File.Copy(kitPath + "Gateway\\" + EXE_Dispatcher, destinationPath, true);
//}
//catch (Exception ex)
//{
// Utils.WriteLine("Error on copying SD executable file " + ex.ToString(), ConsoleColor.Red);
// //SM.Debug("Error on copy files:" + ex.ToString());
//}
//done
SM.Debug("SD installed");
Console.WriteLine("======================================================");
updateStatus(AppNAME+" installed", false);
CreateShortcut(installPath + AppNAME+"\\", EXE_Dispatcher, ShortcutAppNAME);
//CreateShortcut(installPath + "SafeSyt\\", "SafeSyt.exe", "SafeSyt");
}
private string getSourceFolderBasedOnSelectedGateway()
{
switch (dropGatewayList.SelectedIndex)
{
case 0: return "Gateway" ;
case 1: return "Tetra";
case 2: return "CPlus";
case 3: return "Tetra_SDR";
case 4: return "Repeater_Gateway";
case 5: return "SMC_Gateway";
default: return "";
}
}
private void InstallTCPServer(String port)
{
Console.WriteLine("======================================================");
SM.Debug("Installing TCPServer");
updateStatus("Installing " + "TCPServer", true);
String fileMSI = "";
string[] fileEntries;
try
{
Utils.WriteEventLog(Program.COMPANY, "Installing TCPServer", EventLogEntryType.Information, 23456);
}
catch (Exception ex)
{
SM.Debug("Error Creating " + Program.COMPANY + " Source EventLog " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
try
{
fileEntries = Directory.GetFiles(kitPath + "TCPServer");
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
fileMSI = fileNametmp.Remove(0, 1);
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "TCPServer" + '"';
sw.WriteLine(kitPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + kitPath + "TCPServer" + '"');
sw.WriteLine(cmd);
Utils.WriteLine($"Installing TCPServer: {cmd}", ConsoleColor.DarkYellow);
}
sw.Close();
p.WaitForExit();
}
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
//Console.WriteLine(output);
Utils.WriteLine("INSTALL TCPServer OUTPUT RESULT " + output, ConsoleColor.Magenta);
}
FileInfo fi;
fi = new FileInfo(installPath + "TCPServer" + "\\" + CFG_Server);
int count = 0;
while (!fi.Exists && count < 10)
{
Thread.Sleep(1000);
count++;
SM.Debug("File " + installPath + "TCPServer" + "\\" + CFG_Server + " missing retry " + count);
}
if (count < 10)
{
try
{
XmlDocument xml = new XmlDocument();
xml.Load(installPath + "TCPServer" + "\\" + CFG_Server);
foreach (XmlElement element in xml.SelectNodes("//appSettings"))
{
Int32 step = 0;
foreach (XmlElement element1 in element)
{
step++;
if (step == 3)
{
element1.Attributes[1].InnerText = txTCPPort.Value.ToString();
}
}
}
xml.Save(installPath + "TCPServer" + "\\" + CFG_Server);
}
catch (Exception ex)
{
Console.WriteLine("Modify TCPServer file error: "+ex.ToString());
}
Process p2 = new Process();
p2.StartInfo = info;
p2.Start();
using (StreamWriter sw2 = p2.StandardInput)
{
if (sw2.BaseStream.CanWrite)
{
sw2.WriteLine("net stop TCPServerService");
sw2.WriteLine("net start TCPServerService");
}
sw2.Close();
}
p2.WaitForExit();
}
installNR--;
threadLock = false;
//done
SM.Debug("TCPServer installed");
Console.WriteLine("======================================================");
updateStatus("TCPServer" + " installed", false);
}
private void InstallTCPClient(String IP,String port)
{
Console.WriteLine("======================================================");
SM.Debug("Installing TCPClient");
updateStatus("Installing " + "TCPClient", true);
String fileMSI = "";
string[] fileEntries;
try
{
Utils.WriteEventLog(Program.COMPANY, "Installing TCPClient", EventLogEntryType.Information, 23456);
}
catch (Exception ex)
{
SM.Debug("Error Creating " + Program.COMPANY + " Source EventLog " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
try
{
fileEntries = Directory.GetFiles(kitPath + "TCPClient");
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
fileMSI = fileNametmp.Remove(0, 1);
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "TCPClient" + '"';
sw.WriteLine(kitPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + kitPath + "TCPClient" + '"');
sw.WriteLine(cmd);
Utils.WriteLine($"Installing TCPClient: {cmd}", ConsoleColor.DarkYellow);
}
sw.Close();
p.WaitForExit();
}
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
//Console.WriteLine(output);
Utils.WriteLine("INSTALL TCPClient OUTPUT RESULT " + output, ConsoleColor.Magenta);
}
FileInfo fi;
fi = new FileInfo(installPath + "TCPClient" + "\\" + CFG_Client);
int count = 0;
while (!fi.Exists && count < 10)
{
Thread.Sleep(1000);
count++;
SM.Debug("File " + installPath + "TCPClient" + "\\" + CFG_Client + " missing retry " + count);
}
if (count < 10)
{
try
{
XmlDocument xml = new XmlDocument();
xml.Load(installPath + "TCPClient" + "\\" + CFG_Client);
foreach (XmlElement element in xml.SelectNodes("//appSettings"))
{
Int32 step = 0;
foreach (XmlElement element1 in element)
{
step++;
if (step == 3)
{
element1.Attributes[1].InnerText = txTCPPort.Value.ToString();
}
if (step == 4)
{
element1.Attributes[1].InnerText = txTCPIP.Text;
}
}
}
xml.Save(installPath + "TCPClient" + "\\" + CFG_Client);
}
catch (Exception ex)
{
Console.WriteLine("Modify TCPClient file error:"+ex.ToString());
}
Process p2 = new Process();
p2.StartInfo = info;
p2.Start();
StreamWriter sw2 = p2.StandardInput;
if (sw2.BaseStream.CanWrite)
{
sw2.WriteLine("net stop TCPClientService");
sw2.WriteLine("net start TCPClientService");
}
sw2.Close();
p2.WaitForExit();
}
installNR--;
threadLock = false;
//done
SM.Debug("TCPClient installed");
Console.WriteLine("======================================================");
updateStatus("TCPClient" + " installed", false);
}
private void InstallSDMobile(string ip, String port)
{
Console.WriteLine("======================================================");
SM.Debug("Installing Appserver for SDMobile");
updateStatus("Installing " + "Application Server Mobile", true);
String fileMSI = "";
string[] fileEntries;
try
{
fileEntries = Directory.GetFiles(kitPath + "AppServerMobile");
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
fileMSI = fileNametmp.Remove(0, 1);
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
StreamWriter sw = p.StandardInput;
if (sw.BaseStream.CanWrite)
{
sw.WriteLine(kitPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + kitPath + "AppServerMobile" + '"');
sw.WriteLine("msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "AppServerMobile" + '"');
}
sw.Close();
p.WaitForExit();
StreamReader reader = p.StandardOutput;
string output = reader.ReadToEnd();
//Console.WriteLine(output);
FileInfo fi;
fi = new FileInfo(installPath + "AppServerMobile" + "\\" + CFG_APP);
int count = 0;
while (!fi.Exists && count < 10)
{
Thread.Sleep(1000);
count++;
SM.Debug("File " + installPath + "AppServerMobile" + "\\" + CFG_APP + " missing retry " + count);
}
try
{
//set DB IP
source = new IniConfigSource(installPath + "AppServerMobile" + "\\" + CFG_APP);
source.Configs["Database"].Set("IP", ip);
source.Configs["Database"].Set("Port", port);
//source.Configs["Recordings"].Set("IP", ip);
source.Save();
SM.Debug("Added new DB ip to SD config file");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
installNR--;
threadLock = false;
//done
SM.Debug("SDMobile installed");
Console.WriteLine("======================================================");
updateStatus("AppServerMobile" + " installed", false);
CreateShortcut(installPath + "AppServerMobile" + "\\", "AppServerMobile.exe", "AppServer for SafeDispatch Mobile");
//CreateShortcut(installPath + "SafeSyt\\", "SafeSyt.exe", "SafeSyt");
}
private void InstallGW(string ip, String port)
{
Console.WriteLine("======================================================");
SM.Debug("Installing GW");
if ((radioType == RADIOTYPE.MOTO)&&(dropGatewayList.SelectedIndex == 4))
updateStatus("Installing " + GatewayNAME, true);
else updateStatus("Installing " + GatewayNAME + " gateway", true);
String fileMSI = "";
string[] fileEntries = new string[] { };
string path = "";
try
{
if (radioType == RADIOTYPE.MOTO)
{
string sourceFolder = getSourceFolderBasedOnSelectedGateway();
if (!string.IsNullOrEmpty(sourceFolder))
fileEntries = Directory.GetFiles(path = (kitPath + "//" + sourceFolder));
else
Utils.WriteLine("Invalid sourcePath", ConsoleColor.Red);
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0)
fileEntries = Directory.GetFiles(path = (kitPath + DirName_Sepura3T_SDR));
else
fileEntries = Directory.GetFiles(path = (kitPath + DirName_Tetra_SDR));
}
else if (radioType == RADIOTYPE.LINX)
{
fileEntries = Directory.GetFiles(path = (kitPath + "gateway"));
}
else if(radioType == RADIOTYPE.LINXB)
{
if (dropGatewayList.SelectedIndex == 0) fileEntries = Directory.GetFiles(path = (kitPath + "LINX_gateway"));
else fileEntries = Directory.GetFiles(path = (kitPath + "Mototrbo_gateway"));
}
else
fileEntries = Directory.GetFiles(path = (kitPath + "gateway"));
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
fileMSI = fileNametmp.Remove(0, 1);
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
using (StreamWriter sw2 = p.StandardInput)
{
if (sw2.BaseStream.CanWrite)
{
sw2.WriteLine(kitPath.Substring(0, 2));
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 0)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Gateway" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
else if (dropGatewayList.SelectedIndex == 1)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Tetra" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
else if (dropGatewayList.SelectedIndex == 2)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "CPlus" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
else if (dropGatewayList.SelectedIndex == 3)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Tetra_SDR" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
else if (dropGatewayList.SelectedIndex == 4)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Repeater_Gateway" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
sw2.WriteLine(kitPath.Substring(0, 2));
sw2.WriteLine("cd " + '"' + kitPath + "PostgreSD" + '"');
sw2.WriteLine("unzip -o ftdi_driver.zip -d " + '"' + installPath + "ftdi_driver" + '"');
sw2.WriteLine(installPath.Substring(0, 2));
sw2.WriteLine("cd " + '"' + installPath + "ftdi_driver" + '"');
sw2.WriteLine("dpinst-amd64.exe /F");
}
else if (dropGatewayList.SelectedIndex == 5)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "SMC_Gateway" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + DirName_Sepura3T_SDR + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
else if (dropGatewayList.SelectedIndex == 1)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + DirName_Tetra_SDR + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
}
else if (radioType == RADIOTYPE.LINX)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Gateway" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
else if (radioType == RADIOTYPE.LINXB)
{
if (dropGatewayList.SelectedIndex == 0)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "LINX_gateway" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
else if (dropGatewayList.SelectedIndex == 1)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Mototrbo_gateway" + '"';
sw2.WriteLine("cd " + '"' + path + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
}
else
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Gateway" + '"';
sw2.WriteLine("cd " + '"' + kitPath + "Gateway" + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing Gateway: {cmd}", ConsoleColor.DarkYellow);
}
}
sw2.Close();
p.WaitForExit();
}
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
//Console.WriteLine(output);
Utils.WriteLine("INSTALL Gateway OUTPUT RESULT " + output, ConsoleColor.Magenta);
}
if (radioType == RADIOTYPE.SIMOCO || radioType == RADIOTYPE.EXCERA)
CFG_GW = "configSD.ini";
FileInfo fi = new FileInfo(installPath + "Gateway\\" + CFG_GW);
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 1) fi = new FileInfo(installPath + "Tetra\\" + CFG_GW);
else if (dropGatewayList.SelectedIndex == 2) fi = new FileInfo(installPath + "CPlus\\" + CFG_GW);
else if (dropGatewayList.SelectedIndex == 3) fi = new FileInfo(installPath + "Tetra_SDR\\" + CFG_GW);
else if (dropGatewayList.SelectedIndex == 4)
{
CFG_GW = "configSD.ini";
fi = new FileInfo(installPath + "Repeater_Gateway\\" + CFG_GW);
}
else if (dropGatewayList.SelectedIndex == 5) fi = new FileInfo(installPath + "SMC_Gateway\\" + CFG_GW);
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0)
fi = new FileInfo(installPath + DirName_Sepura3T_SDR + "\\" + CFG_GW);
else
fi = new FileInfo(installPath + DirName_Tetra_SDR + "\\" + CFG_GW);
}
else if (radioType == RADIOTYPE.LINX)
{
CFG_GW = "configSD.ini";
fi = new FileInfo(installPath + "Gateway\\" + CFG_GW);
}
if (radioType == RADIOTYPE.LINXB)
{
if (dropGatewayList.SelectedIndex == 0) fi = new FileInfo(installPath + "LINX_gateway\\" + CFG_GW);
else if (dropGatewayList.SelectedIndex == 1) fi = new FileInfo(installPath + "Mototrbo_gateway\\" + CFG_GW);
}
int count = 0;
while (!fi.Exists && count < 10)
{
Thread.Sleep(1000);
count++;
SM.Debug("File " + installPath + "Gateway\\" + CFG_GW + " missing retry " + count);
}
try
{
//set DB IP
source = null;
Boolean writeIP = false;
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 0 ||
dropGatewayList.SelectedIndex == 4 ||
dropGatewayList.SelectedIndex == 5)
writeIP = true;
}
else
writeIP = true;
if (writeIP)
{
if (radioType == RADIOTYPE.LISF)
{
Utils.WriteLine("LISF Gateway config file is " + fi.FullName);
source = new IniConfigSource(fi.FullName);
source.Configs["Server"].Set("IP", ip);
}
else
{
Utils.WriteLine("Gateway config file is : " + installPath + "Gateway\\" + CFG_GW);
source = new IniConfigSource(fi.FullName);// installPath + "Gateway\\" + CFG_GW);
if (radioType == RADIOTYPE.LINX || radioType == RADIOTYPE.LINXB || radioType == RADIOTYPE.SIMOCO)
source.Configs["Server"].Set("IP", ip);
else
{
//aici doar gatewayul de motorola are registration cu app serverul
if ((radioType == RADIOTYPE.MOTO && (dropGatewayList.SelectedIndex == 0 ||
dropGatewayList.SelectedIndex == 4 || dropGatewayList.SelectedIndex == 5)) || radioType == RADIOTYPE.HYT)
source.Configs["Server"].Set("IP", ip);
// la restul in blana
else
{
source.Configs["Database"].Set("IP", ip);
source.Configs["Database"].Set("Port", port);
}
}
if (radioType == RADIOTYPE.HARRIS)
source.Configs["Type"].Set("Hytera", "false");
}
//source.Configs["Database"].Set("IP", ip);
//source.Configs["Database"].Set("Port", port);
source.Save();
}
SM.Debug("Added new DB ip to GW config file");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
installNR--;
SM.Debug("Gateway installed");
Console.WriteLine("======================================================");
threadLock = false;
updateStatus("Gateway installed", false);
if (radioType == RADIOTYPE.MOTO)
{
string sourceFolder = getSourceFolderBasedOnSelectedGateway();
if (!string.IsNullOrEmpty(sourceFolder))
CreateShortcut(installPath + sourceFolder + "\\", EXE_Gateway, GatewayNAME + " Gateway");
else
Utils.WriteLine("Invalid sourcePath", ConsoleColor.Red);
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0) CreateShortcut(installPath + DirName_Sepura3T_SDR + "\\", EXE_Gateway, GatewayNAME + " Gateway");
else if (dropGatewayList.SelectedIndex == 1) CreateShortcut(installPath + DirName_Tetra_SDR + "\\", EXE_Gateway, GatewayNAME + " Gateway");
}
else if(radioType == RADIOTYPE.LINX)
CreateShortcut(installPath + "Gateway\\", EXE_Gateway, GatewayNAME + " Gateway");
else if (radioType == RADIOTYPE.LINXB)
{
if (dropGatewayList.SelectedIndex == 0) CreateShortcut(installPath + "LINX_gateway\\", EXE_Gateway, GatewayNAME + " Gateway");
else if (dropGatewayList.SelectedIndex == 1) CreateShortcut(installPath + "Mototrbo_gateway\\", EXE_Gateway, GatewayNAME + " Gateway");
}
else
CreateShortcut(installPath + "Gateway\\", EXE_Gateway, GatewayNAME+" Gateway");
}
private void InstallSUM(string ip, String port)
{
Console.WriteLine("======================================================");
SM.Debug("Installing AdministrativeModule");
updateStatus("Installing AdministrativeModule", true);
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
String fileMSI = "";
string[] fileEntries;
try
{
fileEntries = Directory.GetFiles(kitPath + "AdministrativeModule");
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
//Console.WriteLine("FILES:"+fileNametmp.ToUpper() +" NORMAL:"+fileNametmp);
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
{
fileMSI = fileNametmp.Remove(0, 1);
Console.WriteLine("Find MSI:"+fileMSI);
}
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
using (StreamWriter sw2 = p.StandardInput)
{
if (sw2.BaseStream.CanWrite)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "AdministrativeModule" + '"';
sw2.WriteLine(kitPath.Substring(0, 2));
sw2.WriteLine("cd " + '"' + kitPath + "AdministrativeModule" + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing AdministrativeModule: {cmd}", ConsoleColor.DarkYellow);
}
sw2.Close();
p.WaitForExit();
}
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
Utils.WriteLine("INSTALL AdministrativeModule OUTPUT RESULT " + output, ConsoleColor.Magenta);
}
FileInfo fi = new FileInfo(installPath + "AdministrativeModule\\" + CFG_SUM);
int count = 0;
while (!fi.Exists && count < 10)
{
Thread.Sleep(1000);
count++;
Console.WriteLine("File " + installPath + "AdministrativeModule\\" + CFG_SUM + " missing retry " + count);
}
try
{
//set DB IP
source = new IniConfigSource(installPath + "AdministrativeModule\\" + CFG_SUM);
source.Configs["Server"].Set("IP", ip);
//source.Configs["Database"].Set("IP", ip);
//source.Configs["Database"].Set("Port", port);
source.Save();
//SM.Debug("Added new DB ip to SUM config file");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
installNR--;
SM.Debug("AdministrativeModule installed.");
Console.WriteLine("======================================================");
threadLock = false;
updateStatus("AdministrativeModule installed", false);
CreateShortcut(installPath + "AdministrativeModule\\", "AdministrativeModule.exe", "AdministrativeModule");
// try
// {
// string destinationPath = installPath + "AdministrativeModule\\AdminModule.exe";
// string sourcePath = kitPath + "Gateway\\AdminModule.exe";
// if (radioType == RADIOTYPE.MOTO)
// {
// if (dropGatewayList.SelectedIndex == 1) IO.File.Copy(kitPath + "Tetra\\AdminModule.exe", destinationPath, true);
// else if (dropGatewayList.SelectedIndex == 2) IO.File.Copy(kitPath + "CPlus\\AdminModule.exe", destinationPath, true);
// else if (dropGatewayList.SelectedIndex == 3) IO.File.Copy(kitPath + "Tetra\\AdminModule.exe", destinationPath, true);
// else if (dropGatewayList.SelectedIndex == 4) IO.File.Copy(kitPath + "Repeater_Gateway\\AdminModule.exe", destinationPath, true);
// }
// if (radioType == RADIOTYPE.LISF)
// {
// if (dropGatewayList.SelectedIndex == 0) IO.File.Copy(kitPath + DirName_Sepura3T_SDR + "\\AdminModule.exe", destinationPath, true);
// else if (dropGatewayList.SelectedIndex == 1) IO.File.Copy(kitPath + DirName_Tetra_SDR + "\\AdminModule.exe", destinationPath, true);
// }
// else if (radioType == RADIOTYPE.LINX || radioType == RADIOTYPE.LINXB)
// IO.File.Copy(sourcePath, destinationPath, true);
// else if (radioType == RADIOTYPE.EXCERA)
// IO.File.Copy(sourcePath, destinationPath, true);
// else if (radioType == RADIOTYPE.HYT)
// IO.File.Copy(sourcePath, destinationPath, true);
// }
// catch (Exception ex)
// {
// SM.Debug("Error on copy files:"+ex.ToString());
// }
}
string linxExePath = "";
private void InstallAPP(string ip,String port)
{
updateStatus("Installing Application server", true);
Console.WriteLine("======================================================");
SM.Debug("Installing Application Server");
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
String fileMSI = "";
string[] fileEntries;
try
{
fileEntries = Directory.GetFiles(kitPath + "AppServer");
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
fileMSI = fileNametmp.Remove(0, 1);
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
using (StreamWriter sw2 = p.StandardInput)
{
if (sw2.BaseStream.CanWrite)
{
String cmd = "msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "AppServer" + '"';
sw2.WriteLine(kitPath.Substring(0, 2));
sw2.WriteLine("cd " + '"' + kitPath + "AppServer" + '"');
sw2.WriteLine(cmd);
Utils.WriteLine($"Installing AppServer: {cmd}", ConsoleColor.DarkYellow);
}
sw2.Close();
p.WaitForExit();
}
using (StreamReader reader = p.StandardOutput)
{
string output = reader.ReadToEnd();
Utils.WriteLine("INSTALL AppServer OUTPUT RESULT " + output, ConsoleColor.Magenta);
//Console.WriteLine(output);
}
FileInfo fi = new FileInfo(installPath + "AppServer\\" + CFG_APP);
int count = 0;
while (!fi.Exists && count<10)
{
Thread.Sleep(1000);
count++;
SM.Debug("File " + installPath + "AppServer\\" + CFG_APP + " missing retry " + count);
}
try
{
//set DB IP
source = new IniConfigSource(installPath + "AppServer\\" + CFG_APP);
source.Configs["Database"].Set("IP", ip);
source.Configs["Database"].Set("Port", port);
source.Save();
SM.Debug("Added new DB ip to appserver config file");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
//start service
//StartService("AppService", 3000);
installNR--;
SM.Debug("Aplication AppServer installed");
Console.WriteLine("======================================================");
threadLock = false;
updateStatus("Aplication AppServer installed", false);
CreateShortcut(installPath + "AppServer\\", "AppServer.exe", "AppServer");
//LINX run installer
if (radioType == RADIOTYPE.LINX || radioType == RADIOTYPE.LINXB)
{
linxExePath = kitPath + "LINX Server Setup.exe";
if (IO.File.Exists(linxExePath) && !Directory.Exists(installPath + "LINX Server"))
{
Process.Start(linxExePath);
}
}
}
private void InstallUpd(string ip, String port)
{
updateStatus("Installing updater", true);
Console.WriteLine("======================================================");
SM.Debug("Installing Updater");
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
String fileMSI = "";
string[] fileEntries;
try
{
fileEntries = Directory.GetFiles(kitPath + "Updater");
foreach (string fileName in fileEntries)
{
String fileNametmp = fileName.Substring(fileName.LastIndexOf('\\'));
if (fileNametmp.ToUpper().Contains(".MSI") || fileNametmp.Contains(".msi"))
fileMSI = fileNametmp.Remove(0, 1);
}
}
catch (Exception ex)
{
SM.Debug("Error finding MSI " + ex.Source + "\n" + ex.Message + "\n" + ex.StackTrace);
}
StreamWriter sw2 = p.StandardInput;
if (sw2.BaseStream.CanWrite)
{
sw2.WriteLine(kitPath.Substring(0, 2));
sw2.WriteLine("cd " + '"' + kitPath + "Updater" + '"');
sw2.WriteLine("msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + "Updater" + '"');
}
sw2.Close();
p.WaitForExit();
StreamReader reader = p.StandardOutput;
string output = reader.ReadToEnd();
//Console.WriteLine(output);
FileInfo fi = new FileInfo(installPath + "Updater\\" + CFG_Upd);
int count = 0;
while (!fi.Exists && count < 10)
{
Thread.Sleep(1000);
count++;
SM.Debug("File " + installPath + "Updater\\" + CFG_Upd + " missing retry " + count);
}
try
{
//set DB IP
source = new IniConfigSource(installPath + "Updater\\" + CFG_Upd);
source.Configs["DB connect"].Set("serverIP", ip);
source.Configs["DB connect"].Set("port", port);
if(radioType == RADIOTYPE.MOTO)
{
// TETRA case
if (dropGatewayList.SelectedIndex == 1)
{
source.Configs["Local"].Set("TetraEXEPath", "..//Tetra//Tetra_GW.exe");
source.Configs["Local"].Set("GatewayCFGPath", "..//Tetra//GWconfig.ini");
}
// Connect Plus case
else if (dropGatewayList.SelectedIndex == 2)
{
source.Configs["Local"].Set("GatewayEXEPath", "..//CPlus//CPlus_GW.exe");
source.Configs["Local"].Set("GatewayCFGPath", "..//CPlus//GWconfig.ini");
}
// Tetra case
else if (dropGatewayList.SelectedIndex == 3)
{
source.Configs["Local"].Set("GatewayEXEPath", "..//Tetra_SDR//SDRgateway.exe");
source.Configs["Local"].Set("GatewayCFGPath", "..//Tetra_SDR//GWconfig.ini");
}
// Repeater case
else if (dropGatewayList.SelectedIndex == 4)
{
source.Configs["Local"].Set("GatewayEXEPath", "..//Repeater_Gateway//MotoRepeater.exe");
source.Configs["Local"].Set("GatewayCFGPath", "..//Repeater_Gateway//configSD.ini");
}
}
else if (radioType == RADIOTYPE.LISF)
{
// TETRA case
if (dropGatewayList.SelectedIndex == 0)
{
source.Configs["Local"].Set("TetraEXEPath", $"..//{DirName_Sepura3T_SDR}//Sepura3T_SDR.exe");
source.Configs["Local"].Set("GatewayCFGPath", $"..//{DirName_Sepura3T_SDR}//GWconfig.ini");
}
// Tetra SDR case
else if (dropGatewayList.SelectedIndex == 1)
{
source.Configs["Local"].Set("GatewayEXEPath", $"..//{DirName_Tetra_SDR}//SDRgateway.exe");
source.Configs["Local"].Set("GatewayCFGPath", $"..//{DirName_Tetra_SDR}//GWconfig.ini");
}
}
source.Save();
SM.Debug("Added new DB ip to updater config file");
}
catch (Exception ex)
{
SM.Debug(ex.ToString());
}
//start service
//StartService("AppService", 3000);
installNR--;
threadLock = false;
SM.Debug("Updater installed");
Console.WriteLine("======================================================");
updateStatus("Updater installed", false);
try
{
string destinationPath = installPath + "Updater\\SoftwareUpdate.exe";
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 1) IO.File.Copy(kitPath + "Tetra\\SoftwareUpdate.exe", destinationPath, true);
else if (dropGatewayList.SelectedIndex == 2) IO.File.Copy(kitPath + "CPlus\\SoftwareUpdate.exe", destinationPath, true);
else if (dropGatewayList.SelectedIndex == 3) IO.File.Copy(kitPath + "Tetra\\SoftwareUpdate.exe", destinationPath, true);
else if (dropGatewayList.SelectedIndex == 4) IO.File.Copy(kitPath + "Repeater_Gateway\\SoftwareUpdate.exe", destinationPath, true);
}
}
catch (Exception ex)
{
SM.Debug("Error on copy files Updater:" + ex.ToString());
}
CreateShortcut(installPath + "Updater\\", "SoftwareUpdate.exe", "SoftwareUpdate");
CreateShortcut(installPath + "Updater\\", Program.COMPANY + "RemoteSupport.exe", Program.COMPANY + " Remote Support");
}
private WshShellClass WshShell;
private void DeleteShortcut(String ShortcutName)
{
try
{
string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// Delete old shortcut if it exist
string fullPath = desktopFolder + "\\" + ShortcutName + ".lnk";
if (IO.File.Exists(fullPath))
{
IO.File.Delete(fullPath);
Utils.WriteLine($" Delete shortcut [{fullPath}]");
}
string programsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
fullPath = programsFolder + "\\" + Program.COMPANY + "\\" + ShortcutName + ".lnk";
if (IO.File.Exists(fullPath))
{
IO.File.Delete(fullPath);
Utils.WriteLine($" Delete shortcut [{fullPath}]");
}
if (Directory.Exists(programsFolder + "\\" + Program.COMPANY))
{
string[] fileEntries;
fileEntries = Directory.GetFiles(programsFolder + "\\" + Program.COMPANY);
if (fileEntries.Count() == 0)
Directory.Delete(programsFolder + "\\" + Program.COMPANY);
}
}
catch (Exception ex)
{
Utils.WriteLine($"Error on delete shortcut [{ShortcutName}]:" + ex.ToString());
}
}
private void CreateShortcut(String appPath, string exeName, String ShortcutName)
{
try
{
string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// Delete old shortcut if it exist
string destopPath = desktopFolder + "\\" + ShortcutName + ".lnk";
if (IO.File.Exists(destopPath))
{
IO.File.Delete(destopPath);
Utils.WriteLine($"Delete existing shortcut [{destopPath}]");
}
Utils.WriteLine($"CreateShortcut for {ShortcutName} targetting {destopPath}");
// Create a new instance of WshShellClass
WshShell = new WshShellClass();
// Create the shortcut
IWshRuntimeLibrary.IWshShortcut MyShortcut;
// Choose the path for the shortcut
MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(destopPath);
// Where the shortcut should point to
MyShortcut.TargetPath = appPath + exeName;
//add startDIr
MyShortcut.WorkingDirectory = appPath;
// Description for the shortcut
MyShortcut.Description = ShortcutName;
// Create the shortcut at the given path
MyShortcut.Save();
#region Create Admin Privileges for Shortcut
// HACKHACK: update the link's byte to indicate that this is a admin shortcut
using (FileStream fs = new FileStream(destopPath, FileMode.Open, FileAccess.ReadWrite))
{
fs.Seek(21, SeekOrigin.Begin);
fs.WriteByte(0x22);
}
#endregion
string programsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
if (!Directory.Exists(programsFolder + "\\" + Program.COMPANY))
Directory.CreateDirectory(programsFolder + "\\" + Program.COMPANY);
string shortcutPath2 = programsFolder + "\\" + Program.COMPANY + "\\" + ShortcutName + ".lnk";
if (IO.File.Exists(shortcutPath2))
{
IO.File.Delete(shortcutPath2);
}
Utils.WriteLine($"CreateShortcut for {ShortcutName} targetting {shortcutPath2}");
// Create the shortcut
IWshRuntimeLibrary.IWshShortcut MyShortcut2;
// Choose the path for the shortcut
MyShortcut2 = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(shortcutPath2);
// Where the shortcut should point to
MyShortcut2.TargetPath = appPath + exeName;
//add startDIr
MyShortcut2.WorkingDirectory = appPath;
// Description for the shortcut
MyShortcut2.Description = ShortcutName;
// Create the shortcut at the given path
// Console.WriteLine("Shortcut 2:" + Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\SafeMobile\\" + ShortcutName + ".lnk");
MyShortcut2.Save();
#region Create Admin Privileges for Shortcut
// HACKHACK: update the link's byte to indicate that this is a admin shortcut
using (FileStream fs = new FileStream(shortcutPath2, FileMode.Open, FileAccess.ReadWrite))
{
fs.Seek(21, SeekOrigin.Begin);
fs.WriteByte(0x22);
}
#endregion
}
catch (Exception ex)
{
Console.WriteLine("Error on create shortcut:"+ex.ToString());
}
}
public static void StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
Utils.WriteLine("Starting Service :" + serviceName);
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch(Exception ex)
{
Utils.WriteLine("ERROR starting Service :" +serviceName);
Utils.WriteLine(ex.ToString());
}
Utils.WriteLine("Service :" + serviceName + " started!!!");
}
static public void CopyFolder(string sourceFolder, string destFolder)
{
try
{
if (!Directory.Exists(sourceFolder))
{
Console.WriteLine("Tools folder not found in kit folder");
return;
}
if (!Directory.Exists(destFolder))
Directory.CreateDirectory(destFolder);
string[] files = Directory.GetFiles(sourceFolder);
foreach (string file in files)
{
string name = Path.GetFileName(file);
string dest = Path.Combine(destFolder, name);
IO.File.Copy(file, dest);
}
string[] folders = Directory.GetDirectories(sourceFolder);
foreach (string folder in folders)
{
string name = Path.GetFileName(folder);
string dest = Path.Combine(destFolder, name);
CopyFolder(folder, dest);
}
}catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
#endregion
#region Registry Entry Management
private bool CreateAppEntry(String appFolder)
{
// Write path to the registry
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true);
if (key.OpenSubKey(Program.COMPANY) == null)
key.CreateSubKey(Program.COMPANY);
key = key.OpenSubKey(Program.COMPANY, true);
try
{
key.CreateSubKey(appFolder);
return true;
}
catch(Exception)
{
return false;
}
}
private bool InsertRegValue(String regKey, String regValue, String appFolder)
{
// Write path to the registry
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true);
if (key.OpenSubKey(Program.COMPANY) == null)
key.CreateSubKey(Program.COMPANY);
key = key.OpenSubKey(Program.COMPANY, true);
key = key.OpenSubKey(appFolder, true);
try
{
key.SetValue(regKey, regValue);
return true;
}
catch (Exception)
{
return false;
}
}
private String GetRegValue(String regKey, String appFolder)
{
// Write path to the registry
string path = "Software\\" + Program.COMPANY
+ (appFolder.Equals(Program.COMPANY) ? "" : "\\" + appFolder);
RegistryKey key = Registry.CurrentUser.OpenSubKey(path);
if (key != null)
{
Utils.WriteLine("Folder " + appFolder + " exists", ConsoleColor.DarkCyan);
try
{
return (String)key.GetValue(regKey);
}
catch (Exception)
{
return String.Empty;
}
}
else
{
// Key is not in HKEY_CURRENT_USER /SOFTWARE /SafeMobile
// Because of registry virtualization, it may be in HKEY_USERS/ SomeUser / SOFTWARE / ....
// Check all users key form HKEY_USERS
foreach (string user in Registry.Users.GetSubKeyNames())
{
key = Registry.Users.OpenSubKey(user + "\\" + path);
if (key != null)
{
Utils.WriteLine("Folder " + appFolder + "exists", ConsoleColor.DarkCyan);
try
{
return (String)key.GetValue(regKey);
}
catch (Exception)
{
return String.Empty;
}
}
}
return String.Empty;
}
}
private void DeleteRegValue(String regKey, String appFolder)
{
// Write path to the registry
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\" + Program.COMPANY
+ (appFolder.Equals(Program.COMPANY) ? "" : "\\" + appFolder), true);
if (key != null)
{
try
{
key.DeleteValue(regKey);
}
catch (Exception)
{
}
}
}
private void DeleteAppKey(String appFolder)
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\" + Program.COMPANY, true))
{
if (key == null)
{
// Key doesn't exist. Do whatever you want to handle
// this case
}
else
{
try
{
key.DeleteSubKeyTree(appFolder);
}
catch (Exception ) { }
}
}
}
#endregion
private void replace_portForDB(String Path, String text, String replace)
{
try
{
Int32 testpathCnt=0;
while (testpathCnt<5)
{
Thread.Sleep(1000);
SM.Debug("Wait 1 second to see if database is unziped");
if (IO.File.Exists(Path)) testpathCnt = 100;
testpathCnt++;
}
TextReader tr = new StreamReader(Path);
String w = tr.ReadToEnd();
String new_file = w.Replace(text, replace);
tr.Close();
TextWriter tw = new StreamWriter(Path);
tw.Write(new_file);
tw.Close();
}
catch (Exception ex)
{
SM.Debug("Unable to change the port form database:"+ex.ToString());
}
}
private void ChangeFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "Select instalation folder";
dialog.RootFolder = Environment.SpecialFolder.MyComputer;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folder = dialog.SelectedPath;
tbInstallPath.Text = folder;
}
}
private void updateStatus(string text,bool waitBar)
{
updateStatusCallback d = new updateStatusCallback(changeStatus);
this.Invoke(d, new object[] {text,waitBar });
}
delegate void updateStatusCallback(string text, bool waitBar);
public void changeStatus(string text, bool waitBar)
{
if (waitBar) radWaitingBar1.StartWaiting();
else radWaitingBar1.StopWaiting();
lbStatus.Text = text;
SM.Debug(installNR + " installs remaning");
if (installNR == 0 )
{
if (!uninstall)
{
radWaitingBar1.Visible = false;
lbStatus.Text = "Installation completed!!";
btnInstall.Enabled = true;
btnUnInstall.Enabled = true;
TestInstall();
}
else
{
try
{
if (cbDBinstall.Checked)
{
//try again to delete DB
int backUp = 0;
while (Directory.Exists(installPath + "postgresql"))
{
try
{
Directory.Delete(installPath + "postgresql", true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
backUp++;
if (backUp > 10) break;
Thread.Sleep(500);
}
}
}
catch (Exception) { };
radWaitingBar1.Visible = false;
lbStatus.Text = "Uninstall completed!!";
btnUnInstall.Enabled = true;
btnInstall.Enabled = true;
TestUninstall();
}
}
}
#region uninstall
private bool uninstall = false;
private void btnUnInstall_Click(object sender, EventArgs e)
{
uninstall_hash = new Hashtable();
DialogResult dr = RadMessageBox.Show("Please make sure that all programs that you wish to uninstall are closed!!!\n\r This process will delete all your save data for "
+ Program.COMPANY + " applications that are checked!!!\n\r Do you want to continue?", "Warning", MessageBoxButtons.OKCancel, RadMessageIcon.Exclamation);
if (dr != DialogResult.OK)
return;
btnUnInstall.Enabled = false;
uninstall = true;
radWaitingBar1.Visible = true;
installPath = tbInstallPath.Text + "\\";
//if no app selected return
if (!cbDBinstall.Checked && !cbGWinstall.Checked
&& !cbSDinstall.Checked && !cbSUMinstall.Checked && !AdvanceSettings)
{
RadMessageBox.Show("Please select an application for uninstalling");
radWaitingBar1.Visible = false;
lbStatus.Text = "Please select an application for uninstalling!!";
btnUnInstall.Enabled = true;
return;
}
if (8 == IntPtr.Size
|| (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
{
if (installPath.Contains("Program Files") && !installPath.Contains("Program Files (x86)"))
installPath = installPath.Replace("Program Files", "Program Files (x86)");
}
else SystemType32 = true;
string var = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432");
Console.WriteLine(var);
installPath = GetRegValue("Path", Program.COMPANY);
Utils.WriteLine("GetRegValue " + installPath, ConsoleColor.Cyan);
if (installPath != null && installPath.Length > 1)
tbInstallPath.Text = installPath;
installPath += "\\";
btnInstall.Enabled = false;
if (cbSDinstall.Checked)
{
App app = App.DISPATCH_MOTOROLA;
switch (radioType)
{
case RADIOTYPE.MOTO: app = App.DISPATCH_MOTOROLA; break;
case RADIOTYPE.HYT: app = App.DISPATCH_HYTERA; AppNAME = "SafeSyt"; break;
case RADIOTYPE.HARRIS: app = App.DISPATCH_HARRIS; AppNAME = "Vision"; break;
case RADIOTYPE.ATLAS: app = App.DISPATCH_ATLAS; AppNAME = "Atl25"; break;
case RADIOTYPE.SIMOCO: app = App.DISPATCH_SIMOCO; AppNAME = "SimocoDispatch"; break;
case RADIOTYPE.LINX: app = App.DISPATCH_LINX; AppNAME = "LINXDispatch"; break;
case RADIOTYPE.LINXB: app = App.DISPATCH_LINX; AppNAME = "LINXDispatch"; break;
default: app = App.DISPATCH_MOTOROLA; AppNAME = "SafeDispatch"; break;
}
bool isInstalled = false;
isInstalled = IsAppInstalled(app); // Search4App(AppNAME);
if (isInstalled)
{
installNR++;
installThreads[2] = new Thread(new ThreadStart(UnInstallSDcallback));
installThreads[2].IsBackground = true;
installThreads[2].Start();
AddToUninstall_Hash(AppNAME, true);
}
}
if (cbGWinstall.Checked)
{
bool isInstalled = false;
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 0) isInstalled = IsAppInstalled(App.GW_TRBO);// Search4App("Gateway");
else if (dropGatewayList.SelectedIndex == 1) isInstalled = IsAppInstalled(App.GW_TETRA); // Search4App("Tetra");
else if (dropGatewayList.SelectedIndex == 2) isInstalled = IsAppInstalled(App.GW_CPLUS); // Search4App("CPlus");
else if (dropGatewayList.SelectedIndex == 3) isInstalled = IsAppInstalled(App.GW_TETRA_SDR); // Search4App("Tetra_SDR");
else if (dropGatewayList.SelectedIndex == 4) isInstalled = IsAppInstalled(App.GW_REPEATER); // Search4App("Repeater_Gateway");
else if (dropGatewayList.SelectedIndex == 5) isInstalled = IsAppInstalled(App.GW_SMC);
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0) isInstalled = IsAppInstalled(App.GW_SEPURA_3T_SDR);// Search4App("Gateway");
else if (dropGatewayList.SelectedIndex == 1) isInstalled = IsAppInstalled(App.GW_TETRA_SDR); // Search4App("Tetra_SDR");
}
else if (radioType == RADIOTYPE.LINX)
{
isInstalled = IsAppInstalled(App.LINX_GATEWAY);
}
else if (radioType == RADIOTYPE.LINXB)
{
if (dropGatewayList.SelectedIndex == 0) isInstalled = IsAppInstalled(App.LINX_GATEWAY);
else if (dropGatewayList.SelectedIndex == 1) isInstalled = IsAppInstalled(App.GW_TRBO);
}
else if(radioType == RADIOTYPE.EXCERA)
isInstalled = IsAppInstalled(App.EXCERA_GATEWAY);
else if (radioType == RADIOTYPE.HYT)
isInstalled = IsAppInstalled(App.GW_HYTERA);
else if (radioType == RADIOTYPE.ATLAS)
isInstalled = IsAppInstalled(App.GW_ASTRO);
else
isInstalled = IsAppInstalled(App.GW_TRBO); // Search4App("Gateway");
if (isInstalled)
{
installNR++;
installThreads[3] = new Thread(new ThreadStart(UnInstallGWcallback));
installThreads[3].IsBackground = true;
installThreads[3].Start();
AddToUninstall_Hash("Gateway", true);
}
}
if (cbSUMinstall.Checked)
{
bool isInstalled = IsAppInstalled(App.ADMIN_MODULE); // Search4App("AdministrativeModule");
if (isInstalled)
{
installNR++;
installThreads[4] = new Thread(new ThreadStart(UnInstallSUMcallback));
installThreads[4].IsBackground = true;
installThreads[4].Start();
AddToUninstall_Hash("AdministrativeModule", true);
}
}
if (cbDBinstall.Checked)
{
bool isInstalled = Search4App("postgresql");
if (isInstalled)
{
installNR++;
installThreads[0] = new Thread(new ThreadStart(UnInstallDBcallback));
installThreads[0].IsBackground = true;
installThreads[0].Start();
AddToUninstall_Hash("postgresql", true);
}
isInstalled = IsAppInstalled(App.APP_SERVER); // Search4App("AppServer");
if (isInstalled)
{
installNR++;
installThreads[1] = new Thread(new ThreadStart(UnInstallAPPcallback));
installThreads[1].IsBackground = true;
installThreads[1].Start();
AddToUninstall_Hash("AppServer", true);
}
}
/*
bool isInstalled2 = Search4App("Updater");
if (isInstalled2)
{
if (unistallUpdater)
{
installNR++;
installThreads[5] = new Thread(new ThreadStart(UnInstallUpdcallback));
installThreads[5].IsBackground = true;
installThreads[5].Start();
AddToUninstall_Hash("Updater", true);
}
}*/
if (cbInstallSDMobile.Checked)
{
bool isInstalled = Search4App("AppServerMobile");
if (isInstalled)
{
installNR++;
installThreads[6] = new Thread(new ThreadStart(UnInstallSDMobilecallback));
installThreads[6].IsBackground = true;
installThreads[6].Start();
AddToUninstall_Hash("AppServerMobile", true);
}
}/*
else
{
if (Search4App("AppServerMobile"))
unistallUpdater = false;
}*/
if (AdvanceSettings)
{
if (rbTCPServer.IsChecked)
{
if (IsAppInstalled(App.TCP_SERVER)) // Search4App("TCPServer"))
{
installNR++;
installThreads[7] = new Thread(new ThreadStart(UnInstallTCPServercallback));
installThreads[7].IsBackground = true;
installThreads[7].Start();
AddToUninstall_Hash("TCPServer", true);
}
}
else if (rbTCPClient.IsChecked)
{
if (IsAppInstalled(App.TCP_CLIENT)) // Search4App("TCPClient"))
{
installNR++;
installThreads[7] = new Thread(new ThreadStart(UnInstallTCPClientcallback));
installThreads[7].IsBackground = true;
installThreads[7].Start();
AddToUninstall_Hash("TCPClient", true);
}
}
}
if (installNR == 0)
{
RadMessageBox.Show("No application found for uninstalling.\n\r Please make sure the path it's correct.");
radWaitingBar1.Visible = false;
lbStatus.Text = "No application found for uninstalling.";
btnUnInstall.Enabled = true;
btnInstall.Enabled = true;
}
}
private void AddToUninstall_Hash(string key, bool value)
{
if (uninstall_hash.ContainsKey(key))
{
uninstall_hash.Remove(key);
}
uninstall_hash.Add(key, value);
}
private void AddToInstall_Hash(string key, bool value)
{
if (install_hash.ContainsKey(key))
{
install_hash.Remove(key);
}
install_hash.Add(key, value);
}
#region Callbacks uninstall
private void UnInstallDBcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallDB();
}
private void UnInstallSDcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallSD();
}
private void UnInstallSDMobilecallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallSDMobile();
}
private void UnInstallTCPServercallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallTCPServer();
}
private void UnInstallTCPClientcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallTCPClient();
}
private void UnInstallGWcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallGW();
}
private void UnInstallSUMcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallSUM();
}
private void UnInstallAPPcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallAPP();
}
private void UnInstallUpdcallback()
{
while (threadLock) Thread.Sleep(400);
threadLock = true;
UnInstallUpd();
}
#endregion
#region Uninstal methods
/// <summary>
/// Uninstall Dispatcher from the hard-disk
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallSD()
{
try
{
Utils.WriteLine("Uninstalling SD", ConsoleColor.White);
updateStatus("Uninstall "+AppNAME, true);
// create backup for current config
BackupApp(AppNAME);
App app = App.DISPATCH_MOTOROLA;
// uninstall app using MSI file sillently
if (radioType == RADIOTYPE.LINX || radioType == RADIOTYPE.LINXB)
app = App.DISPATCH_LINX;
else if (radioType == RADIOTYPE.HYT)
app = App.DISPATCH_HYTERA;
else if (radioType == RADIOTYPE.HARRIS)
app = App.DISPATCH_HARRIS;
else if (radioType == RADIOTYPE.ATLAS)
app = App.DISPATCH_ATLAS;
else if (radioType == RADIOTYPE.SIMOCO)
app = App.DISPATCH_SIMOCO;
else if (radioType == RADIOTYPE.EXCERA)
app = App.DISPATCH_EXCERA;
// close app if running
CloseApp(app);
UninstallMSIExec(app);
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
if (property.Value.ToString() == uInstall_Dispatcher)
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
}
if (found_name && found_company) break;
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Utils.WriteLine("SD uninstaled successfully!");
}
else
{
Utils.WriteLine("Error uninstalling SD!");
}
}
else
{
Utils.WriteLine("SD not found for uninstall");
}
}
}
//delete SD folder
int backUp = 0;
while (Directory.Exists(installPath + AppNAME))
{
try
{
Directory.Delete(installPath + AppNAME, true);
}
catch (Exception ex)
{
Utils.WriteLine($"Uninstall {AppNAME} exception: " + ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
installNR--;
threadLock = false;
Utils.WriteLine(AppNAME+" uninstalled finish", ConsoleColor.White);
DeleteShortcut(ShortcutAppNAME);
updateStatus(AppNAME + " removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus(AppNAME+" removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus(AppNAME+" removal failed.", false);
}
}
/// <summary>
/// Uninstall the SafeDispatch Mobile from the hard-disk
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallSDMobile()
{
try
{
Utils.WriteLine("Uninstalling SD", ConsoleColor.White);
updateStatus("Uninstall " + "Application server for Dispatch Mobile", true);
// close app if running
//CloseApp(App.DISPATCH_MOBILE);
// create backup for current config
//BackupApp("AppServerMobile");
// uninstall app using MSI file sillently
UninstallMSIExec(App.DISPATCH_MOBILE);
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
if (property.Value.ToString() == "AppServerMobile")
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
}
if (found_name && found_company) break;
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Utils.WriteLine("SD uninstaled successfully!", ConsoleColor.White);
}
else
{
Utils.WriteLine("Error uninstalling SD!");
}
}
else
{
Utils.WriteLine("SD not found for uninstall");
}
}
}
//delete SD folder
int backUp = 0;
while (Directory.Exists(installPath + "AppServerMobile"))
{
try
{
Directory.Delete(installPath + "AppServerMobile", true);
}
catch (Exception ex)
{
Utils.WriteLine("AppServerMobile uninstall exception : " + ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
installNR--;
threadLock = false;
Utils.WriteLine("AppServerMobile" + " uninstalled finish", ConsoleColor.White);
updateStatus("AppServerMobile" + " removal succesfull.", false);
DeleteShortcut("AppServer for Dispatch Mobile");
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus(AppNAME + " removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus(AppNAME + " removal failed.", false);
}
}
/// <summary>
/// Uninstall the TCP Server including the service and the exe file.
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallTCPServer()
{
try
{
Utils.WriteLine("Uninstalling TCPServer", ConsoleColor.White);
updateStatus("Uninstall " + "TCP Server", true);
// close app if running
CloseApp(App.TCP_SERVER);
// create backup for current config
BackupApp("TCPServerService");
// uninstall app using MSI file sillently
UninstallMSIExec(App.TCP_SERVER);
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
StreamWriter sw = p.StandardInput;
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("sc stop TCPServerService");
//sw.WriteLine("sc delete TCPServerService");
}
sw.Close();
StreamReader reader = p.StandardOutput;
string output = reader.ReadToEnd();
Utils.WriteLine(output);
p.WaitForExit();
Thread.Sleep(3000);
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
//Console.WriteLine("Product: new");
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
//Console.WriteLine("Property: " + property.Value.ToString());
if (property.Value.ToString() == "TCPServerService")
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
}
if (found_name && found_company) break;
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Utils.WriteLine("TCPServer uninstaled successfully!", ConsoleColor.White);
}
else
{
Utils.WriteLine("Error uninstalling TCPServer!");
}
}
else
{
Utils.WriteLine("TCPServer not found for uninstall");
}
}
}
//delete SD folder
int backUp = 0;
while (Directory.Exists(installPath + "TCPServer"))
{
try
{
Directory.Delete(installPath + "TCPServer", true);
}
catch (Exception ex)
{
Utils.WriteLine("TCPServer uninstall exception: " + ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
installNR--;
threadLock = false;
Utils.WriteLine("TCPServer" + " uninstalled finish", ConsoleColor.White);
updateStatus("TCPServer" + " removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus(AppNAME + " removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine("TCPServer uninstall exception: " + e.ToString());
updateStatus(AppNAME + " removal failed.", false);
}
}
/// <summary>
/// Uninstall the TCP Client including the service and the exe file.
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallTCPClient()
{
try
{
Utils.WriteLine("Uninstalling TCPClient");
updateStatus("Uninstall " + "TCP Client", true);
// close app if running
CloseApp(App.TCP_CLIENT);
// create backup for current config
BackupApp("TCPClientService");
// uninstall app using MSI file sillently
UninstallMSIExec(App.TCP_CLIENT);
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
StreamWriter sw = p.StandardInput;
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("sc stop TCPClientService");
//sw.WriteLine("sc delete TCPClientService");
}
sw.Close();
StreamReader reader = p.StandardOutput;
string output = reader.ReadToEnd();
Console.WriteLine(output);
p.WaitForExit();
Thread.Sleep(3000);
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
if (property.Value.ToString() == "TCPClientService")
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
if (found_name && found_company) break;
}
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Utils.WriteLine("TCPClient uninstaled successfully!");
}
else
{
Utils.WriteLine("Error uninstalling SD!");
}
}
else
{
Utils.WriteLine("TCPClient not found for uninstall");
}
}
}
//delete SD folder
int backUp = 0;
while (Directory.Exists(installPath + "TCPClient"))
{
try
{
Directory.Delete(installPath + "TCPClient", true);
}
catch (Exception ex)
{
Utils.WriteLine("TCP Client uninstall exception: " + ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
installNR--;
threadLock = false;
Utils.WriteLine("TCPClient" + " uninstalled finish");
updateStatus("TCPClient" + " removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus(AppNAME + " removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus(AppNAME + " removal failed.", false);
}
}
private String ftdi_driver;
/// <summary>
/// Uninstall the Gateway from the hard-disk
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallGW()
{
try
{
Utils.WriteLine("UnInstalling GW", ConsoleColor.White);
//delete GW folder
updateStatus("Uninstalling " + GatewayNAME + " gateway", true);
String Direct = "";
if (radioType == RADIOTYPE.MOTO)
{
if (dropGatewayList.SelectedIndex == 0)
{
Direct = installPath + "Gateway";
// close app if running
CloseApp(App.GW_TRBO);
// create backup for current config
BackupApp("Gateway");
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_TRBO);
}
else if (dropGatewayList.SelectedIndex == 1)
{
Direct = installPath + "Tetra";
// close app if running
CloseApp(App.GW_TETRA);
// create backup for current config
BackupApp("Tetra");
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_TETRA);
}
else if (dropGatewayList.SelectedIndex == 2)
{
Direct = installPath + "CPlus";
// close app if running
CloseApp(App.GW_CPLUS);
// create backup for current config
BackupApp("CPlus");
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_CPLUS);
}
else if (dropGatewayList.SelectedIndex == 3)
{
Direct = installPath + "Tetra_SDR";
// close app if running
CloseApp(App.GW_TETRA_SDR);
// create backup for current config
BackupApp("Tetra_SDR");
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_TETRA_SDR);
}
else if (dropGatewayList.SelectedIndex == 4)
{
updateStatus("Uninstalling " + GatewayNAME, true);
Direct = installPath + "Repeater_Gateway";
// close app if running
CloseApp(App.GW_REPEATER);
// create backup for current config
BackupApp("Repeater_Gateway");
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_REPEATER);
}
else if (dropGatewayList.SelectedIndex == 5)
{
Direct = installPath + "SMC_Gateway";
// close app if running
CloseApp(App.GW_SMC);
// create backup for current config
BackupApp("SMC_Gateway");
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_SMC);
}
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0)
{
Direct = installPath + DirName_Sepura3T_SDR;
// close app if running
CloseApp(App.GW_SEPURA_3T_SDR);
// create backup for current config
BackupApp(DirName_Sepura3T_SDR);
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_SEPURA_3T_SDR);
}
else if (dropGatewayList.SelectedIndex == 1)
{
Direct = installPath + DirName_Tetra_SDR;
// close app if running
CloseApp(App.GW_TETRA_SDR);
// create backup for current config
BackupApp(DirName_Tetra_SDR);
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_TETRA_SDR);
}
}
else if (radioType == RADIOTYPE.LINX)
{
Direct = installPath + "Gateway";
// close app if running
CloseApp(App.LINX_GATEWAY);
// create backup for current config
BackupApp("Gateway");
// uninstall app using MSI file sillently
UninstallMSIExec(App.LINX_GATEWAY);
}
else if (radioType == RADIOTYPE.EXCERA)
{
Direct = installPath + "Gateway";
// close app if running
CloseApp(App.EXCERA_GATEWAY);
// create backup for current config
BackupApp("Gateway");
// uninstall app using MSI file sillently
UninstallMSIExec(App.EXCERA_GATEWAY);
}
if (radioType == RADIOTYPE.LINXB)
{
if (dropGatewayList.SelectedIndex == 0)
{
Direct = installPath + "LINX_gateway";
// close app if running
CloseApp(App.LINX_GATEWAY);
// create backup for current config
BackupApp("LINX_gateway");
// uninstall app using MSI file sillently
UninstallMSIExec(App.LINX_GATEWAY);
}
else if (dropGatewayList.SelectedIndex == 1)
{
Direct = installPath + "Mototrbo_gateway";
// close app if running
CloseApp(App.GW_TRBO);
// create backup for current config
BackupApp("Mototrbo_gateway");
// uninstall app using MSI file sillently
UninstallMSIExec(App.GW_TRBO);
}
}
else Direct = installPath + "Gateway";
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
ManagementObjectSearcher allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
//Console.WriteLine("Propert:X" + property.Value.ToString() + "Xcompareto:X" + uInstall_Gateway+"X");
if ((property.Value.ToString() == uInstall_Gateway))
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
if (found_name && found_company) break;
}
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Utils.WriteLine("GW uninstaled successfully!", ConsoleColor.White);
}
else
{
Utils.WriteLine("Error uninstalling GW");
}
}
else
{
Utils.WriteLine("GW not found for uninstall");
}
}
}
int backUp = 0;
while (Directory.Exists(Direct))
{
try
{
Directory.Delete(Direct, true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
if ((radioType == RADIOTYPE.MOTO) && (dropGatewayList.SelectedIndex == 4))
{
ftdi_driver = installPath + "ftdi_driver";
backUp = 0;
while (Directory.Exists(ftdi_driver))
{
try
{
Directory.Delete(ftdi_driver, true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
}
installNR--;
threadLock = false;
Utils.WriteLine("Gateway uninstalled", ConsoleColor.White);
if ((radioType == RADIOTYPE.MOTO) && (dropGatewayList.SelectedIndex == 4)) DeleteShortcut(GatewayNAME);
DeleteShortcut(GatewayNAME+" Gateway");
updateStatus("Gateway removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus("Gateway removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus("Gateway removal failed.", false);
}
}
/// <summary>
/// Uninstall Administrative Module from the hard-disk
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallSUM()
{
try
{
Utils.WriteLine("Uninstalling AdministrativeModule", ConsoleColor.White);
updateStatus("Uninstalling AdministrativeModule", true);
// close app if running
CloseApp(App.ADMIN_MODULE);
// create backup for current config
BackupApp("AdministrativeModule");
// uninstall app using MSI file sillently
UninstallMSIExec(App.ADMIN_MODULE);
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
ManagementObjectSearcher allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
if (property.Value.ToString() == uInstall_SUM)
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
}
if (found_name && found_company) break;
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Utils.WriteLine("AdministrativeModule uninstaled successfully!");
}
else
{
Utils.WriteLine("Error uninstalling AdministrativeModule");
}
}
else
{
Utils.WriteLine("AdministrativeModule not found for uninstall");
}
}
}
//delete SUM folder
int backUp = 0;
while (Directory.Exists(installPath + "AdministrativeModule"))
{
try
{
Directory.Delete(installPath + "AdministrativeModule", true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
installNR--;
threadLock = false;
Utils.WriteLine("AdministrativeModule uninstalled", ConsoleColor.White);
DeleteShortcut("AdministrativeModule");
updateStatus("Administrative Module removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus("Administartive Module removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus("Administartive Module removal failed.", false);
}
}
/// <summary>
/// Uninstall Application Server from the hard-disk
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallAPP()
{
try
{
updateStatus("Uninstalling Application server", true);
Utils.WriteLine("Uninstalling Application Server", ConsoleColor.White);
// close app if running
CloseApp(App.APP_SERVER);
// create backup for current config
BackupApp("AppServer");
// uninstall app using MSI file sillently
UninstallMSIExec(App.APP_SERVER);
DeleteAppKey(App.GetAppName(App.APP_SERVER));
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
ManagementObjectSearcher allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
if (property.Value.ToString() == uInstall_APP)
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
}
if (found_name && found_company) break;
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Console.WriteLine("Application server uninstaled successfully!");
}
else
{
Console.WriteLine("Error uninstalling Application server");
}
}
else
{
Console.WriteLine("Application server not found for uninstall");
}
}
}
//delete APP folder
int backUp = 0;
while (Directory.Exists(installPath + "AppServer"))
{
try
{
Directory.Delete(installPath + "AppServer", true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
installNR--;
threadLock = false;
DeleteShortcut("AppServer");
// copy remote support file to the installed path
if (Program.COMPANY.Equals("SafeMobile") && IO.File.Exists(installPath + "\\" + "SafeMobileRemoteSupport.exe"))
{
// delete shortcut
DeleteShortcut("SafeMobile Remote Support");
IO.File.Delete(installPath + "\\" + "SafeMobileRemoteSupport.exe");
}
else if (IO.File.Exists(installPath + "\\" + Program.COMPANY + "RemoteSupport.exe"))
{
// delete shortcut
DeleteShortcut(Program.COMPANY + "RemoteSupport");
IO.File.Delete(installPath + "\\" + Program.COMPANY + "RemoteSupport.exe");
}
Utils.WriteLine("Aplication AppServer uninstalled", ConsoleColor.White);
updateStatus("Application Server removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus("Application Server removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus("Application Server removal failed.", false);
}
}
/// <summary>
/// Uninstall Updater from the hard-disk
/// Also it will be removed from the Add/Remove programs
/// </summary>
private void UnInstallUpd()
{
try
{
updateStatus("Uninstalling updater", true);
Utils.WriteLine("Uninstalling Updater", ConsoleColor.White);
// close app if running
CloseApp(App.UPDATER);
// create backup for current config
BackupApp("Updater");
// uninstall app using MSI file sillently
UninstallMSIExec(App.UPDATER);
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
ManagementObjectSearcher allProducts = new ManagementObjectSearcher(allProductsQuery);
foreach (ManagementObject product in allProducts.Get())
{
PropertyDataCollection col = product.Properties;
bool found_name = false;
bool found_company = false;
foreach (PropertyData property in product.Properties)
{
if (property.Value != null)
{
if (property.Value.ToString() == uInstall_Upd)
{
found_name = true;
}
if (property.Value.ToString() == Program.COMPANY)
{
found_company = true;
}
}
if (found_name && found_company) break;
}
if (found_name && found_company)
{
ManagementObject product2 = new ManagementObject(product.Path.Path);
if ((product != null) && (product.Path.ClassName == "Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
//Console.WriteLine("The Uninstall method result is {0}", result.ToString());
if (result.ToString() == "0")
{
Console.WriteLine("updater uninstaled successfully!");
}
else
{
Console.WriteLine("Error uninstalling updater");
}
}
else
{
Console.WriteLine("updater not found for uninstall");
}
}
}
//delete UPD folder
int backUp = 0;
while (Directory.Exists(installPath + "Updater"))
{
try
{
Directory.Delete(installPath + "Updater", true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
installNR--;
threadLock = false;
Utils.WriteLine("Updater uninstalled", ConsoleColor.White);
DeleteShortcut("SoftwareUpdate");
DeleteShortcut(Program.COMPANY + " Remote Support");
updateStatus("Updater removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus("Updater removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus("Updater removal failed.", false);
}
}
/// <summary>
/// Uninstall Database fom the hard-disk and stops the service
/// </summary>
private void UnInstallDB()
{
try
{
updateStatus("Uninstalling Database", true);
Utils.WriteLine("UnInstalling DataBase");
// create backup for current config
BackupApp("postgresql");
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
StreamWriter sw = p.StandardInput;
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("sc stop PostgreSD");
//sw.WriteLine("net start PostgreSD");
sw.WriteLine("sc delete PostgreSD");
}
sw.Close();
StreamReader reader = p.StandardOutput;
string output = reader.ReadToEnd();
Console.WriteLine(output);
p.WaitForExit();
Utils.WriteLine("DB uninstall done!!! -- Removing DB files", ConsoleColor.White);
Thread.Sleep(3000);
//delete DB folder
//wait for process to stop
int backUp = 0;
bool loop = true;
while (loop)
{
Process[] processlist = Process.GetProcesses();
bool found = false;
foreach (Process theprocess in processlist)
{
if (theprocess.ProcessName == "postgres")
{
found = true;
Utils.WriteLine($"postgres.exe still in process list waiting to close (try:{backUp})");
}
}
Thread.Sleep(600);
if (found) loop = true;
else loop = false;
backUp++;
if (backUp > 10) break;
}
backUp = 0;
while (Directory.Exists(installPath + "postgresql"))
{
try
{
Directory.Delete(installPath + "postgresql", true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
backUp++;
if (backUp > 20) break;
Thread.Sleep(1000);
}
//signal thread complet
//deleting tools
DirectoryInfo dr = new DirectoryInfo(installPath + "Tools");
if (dr.Exists)
dr.Delete(true);
installNR--;
threadLock = false;
Utils.WriteLine("Database uninstalled", ConsoleColor.White);
updateStatus("Database removal succesfull.", false);
}
catch (ManagementException me)
{
installNR--;
threadLock = false;
Utils.WriteLine(me.Message);
Utils.WriteLine(me.ToString());
updateStatus("Database removal failed.", false);
}
catch (Exception e)
{
installNR--;
threadLock = false;
Utils.WriteLine(e.ToString());
updateStatus("Database removal failed.", false);
}
}
#endregion
#region Control Panel Add/Remove procedure
/// <summary>
/// Remove the desire appplication by running the msiexec command from a
/// Command-Prompt console sillently.
/// </summary>
/// <param name="product">Application product code that will be removed</param>
private void UninstallMSIExec(App product)
{
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
p.StartInfo = info;
p.Start();
StreamWriter sw = p.StandardInput;
if (sw.BaseStream.CanWrite)
{
sw.WriteLine(kitPath.Substring(0, 2));
sw.WriteLine("cd " + '"' + kitPath + AppNAME + '"');
String installedLocation = GetRegValue("InstalledLocation", App.GetAppName(product));
String productCode = GetRegValue("ProductCode", App.GetAppName(product));
// sw.WriteLine("MsiExec.exe /I" + productCodes[APP_ADD_REMOVE.UPDATER.ToString()] + " REINSTALL=ALL REINSTALLMODE=omus /l*v log.txt");
sw.WriteLine("MsiExec.exe /x" + productCode + " REBOOT=R /quiet");
//sw.WriteLine("msiexec /qn /i " + fileMSI + " TARGETDIR=" + '"' + installPath + AppNAME + '"');
}
sw.Close();
p.WaitForExit();
StreamReader reader = p.StandardOutput;
string output = reader.ReadToEnd();
Utils.WriteLine("UNINSTALL UPDATER OUTPUT RESULT " + output, ConsoleColor.Magenta);
}
#endregion
#region APP Close
private void CloseApp(App product)
{
String installedLocation = GetRegValue("InstalledLocation", App.GetAppName(product));
var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process";
using (var searcher = new ManagementObjectSearcher(wmiQueryString))
using (var results = searcher.Get())
{
var query = from p in Process.GetProcesses()
join mo in results.Cast<ManagementObject>()
on p.Id equals (int)(uint)mo["ProcessId"]
select new
{
Process = p,
Path = (string)mo["ExecutablePath"],
CommandLine = (string)mo["CommandLine"],
};
foreach (var item in query)
{
if (item.Path!= null && item.Path.StartsWith(installedLocation))
{
// Do what you want with the Process, Path, and CommandLine
Utils.WriteLine("APPLICATION " + App.GetAppName(product) + " IS RUNNING !!!! ", ConsoleColor.Yellow);
item.Process.Kill();
}
}
}
//Console.ReadKey();
}
#endregion
#region App Backup
string backupFolder = "";
private void BackupApp(String folderName)
{
//Utils.WriteLine("Backing up the application : " + folderName);
String path = tbInstallPath.Text + "\\";
//if no app selected return
if (!cbDBinstall.Checked && !cbGWinstall.Checked
&& !cbSDinstall.Checked && !cbSUMinstall.Checked && !AdvanceSettings)
{
RadMessageBox.Show("Please select an application for uninstalling");
radWaitingBar1.Visible = false;
lbStatus.Text = "Please select an application for uninstalling!!";
btnUnInstall.Enabled = true;
return;
}
if (8 == IntPtr.Size
|| (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
{
if (path.Contains("Program Files") && !installPath.Contains("Program Files (x86)"))
path = installPath.Replace("Program Files", "Program Files (x86)");
}
else
SystemType32 = true;
if (backupFolder.Length < 1)
backupFolder = path + "Backup_" + DateTime.Now.ToString("dd_MM_HH_mm");
Utils.WriteLine($"Backing up the application: {folderName} to path: {backupFolder}");
try
{
if (Directory.Exists(backupFolder))
{
// if folder exists => clean the folder
DirectoryInfo dInfo = new DirectoryInfo(backupFolder);
foreach (var file in dInfo.GetFiles("*.*"))
IO.File.Delete(file.FullName);
}
else
{
// if folder exists => create it
Directory.CreateDirectory(backupFolder);
}
DirectoryInfo d = new DirectoryInfo(path + folderName);
foreach (var file in d.GetFiles("*.ini"))
{
Directory.Move(file.FullName, backupFolder + "\\" + folderName + "_" + file.Name );
}
foreach (var file in d.GetFiles("*.config"))
{
Directory.Move(file.FullName, backupFolder + "\\" + folderName + "_" + file.Name);
}
if(folderName.Contains("AppServer"))
{
try
{
if (Directory.Exists(path + folderName) && Directory.Exists(path + folderName + "\\recordings"))
Directory.Move(path + folderName + "\\recordings", backupFolder + "\\recordings");
}
catch (Exception ex) { Utils.WriteLine("EXCEPTION " + ex.ToString(), ConsoleColor.Yellow); }
try {
if (Directory.Exists(path + folderName) && Directory.Exists(path + folderName + "\\backups"))
Directory.Move(path + folderName + "\\backups", backupFolder + "\\backups");
}
catch (Exception ex) { Utils.WriteLine("EXCEPTION " + ex.ToString(), ConsoleColor.Yellow); }
}
}
catch(Exception ex)
{
Utils.WriteLine("DDDDDD " + ex.ToString());
}
}
#endregion
private static void DeleteFileSystemInfo(FileSystemInfo fsi)
{
fsi.Attributes = FileAttributes.Normal;
var di = fsi as DirectoryInfo;
if (di != null)
{
foreach (var dirInfo in di.GetFileSystemInfos())
DeleteFileSystemInfo(dirInfo);
}
fsi.Delete();
}
#endregion
private bool CheckIPV6()
{
Process p = new Process();
p = new Process();
p.StartInfo.FileName = "cmd.exe";
String arguments = "/c route print";
p.StartInfo.Arguments = arguments;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
String output = p.StandardOutput.ReadToEnd();
return output.Contains("IPv6 Route Table");
}
private void MainForm_Load(object sender, EventArgs e)
{
var pathReg = GetRegValue("Path", Program.COMPANY);
Utils.WriteLine("GetRegValue " + pathReg, ConsoleColor.Cyan);
if (pathReg != null && pathReg.Length > 1)
tbInstallPath.Text = (string)pathReg;
txDefPortSUM.Enabled = true;
txDefPortSD.Enabled = true;
txDefPortGW.Enabled = true;
txDefPort.Enabled = true;
if(radioType == RADIOTYPE.LISF)
{
dropGatewayList.SelectedIndex = 0;
}
else if (radioType != RADIOTYPE.SIMOCO && radioType != RADIOTYPE.LINX && radioType != RADIOTYPE.LINXB && radioType != RADIOTYPE.MOTO && radioType != RADIOTYPE.HYT)
{
txDefPortGW.Visible = radLabel8.Visible = true;
radLabel3.Text = "Database IP";
}
}
//test install
#region test install/uninstall
private void TestInstall()
{
int iSD=2, iGW=2, iSUm=2, iapp=2, iUpd=2, idb=2,iappMobile=2,iServer=2,iClient=2;
if (cbSDinstall.Checked)
{
if (install_hash.ContainsKey(AppNAME))
{
bool sd = TestAPPlication(AppNAME, EXE_Dispatcher);
iSD = (sd) ? 1 : 0;
}
}
if (cbGWinstall.Checked)
{
if (install_hash.ContainsKey("Gateway"))
{
bool gw = false;
if (radioType == RADIOTYPE.MOTO)
{
string sourceFolder = getSourceFolderBasedOnSelectedGateway();
if (!string.IsNullOrEmpty(sourceFolder))
gw = TestAPPlication(sourceFolder, EXE_Gateway);
else
Utils.WriteLine("Invalid sourcePath", ConsoleColor.Red);
}
else if (radioType == RADIOTYPE.LISF)
{
if (dropGatewayList.SelectedIndex == 0) gw = TestAPPlication(DirName_Sepura3T_SDR, EXE_Gateway);
else if (dropGatewayList.SelectedIndex == 1) gw = TestAPPlication(DirName_Tetra_SDR, EXE_Gateway);
}
else if (radioType == RADIOTYPE.LINXB)
{
if (dropGatewayList.SelectedIndex == 0) gw = TestAPPlication("LINX_gateway", EXE_Gateway);
else if (dropGatewayList.SelectedIndex == 1) gw = TestAPPlication("Mototrbo_gateway", EXE_Gateway);
}
else gw = TestAPPlication("Gateway", EXE_Gateway);
iGW = (gw) ? 1 : 0;
}
}
if (cbSUMinstall.Checked)
{
if (install_hash.ContainsKey("AdministrativeModule"))
{
bool sum = TestAPPlication("AdministrativeModule", EXE_SUM);
iSUm = (sum) ? 1 : 0;
}
}
if (cbDBinstall.Checked)
{
if (install_hash.ContainsKey("AppServer"))
{
bool app = TestAPPlication("AppServer", EXE_APP);
iapp = (app) ? 1 : 0;
}
if (install_hash.ContainsKey("postgresql"))
{
bool db = TestPostgresDB();
idb = (db) ? 1 : 0;
}
}
if (install_hash.ContainsKey("Updater"))
{
//updater is always installing with an application
bool upd = TestAPPlication("Updater", EXE_Upd);
iUpd = (upd) ? 1 : 0;
}
if (cbInstallSDMobile.Checked)
{
if (install_hash.ContainsKey("AppServerMobile"))
{
bool appMobile = TestAPPlication("AppServerMobile", EXE_APPMobile);
iappMobile = (appMobile) ? 1 : 0;
}
}
if (AdvanceSettings)
{
if (rbTCPServer.IsChecked)
{
if (install_hash.ContainsKey("TCPServer"))
{
bool Server = TestAPPlication("TCPServer", EXE_Server);
iServer = (Server) ? 1 : 0;
}
}
else if (rbTCPClient.IsChecked)
{
if (install_hash.ContainsKey("TCPClient"))
{
bool Client = TestAPPlication("TCPClient", EXE_Client);
iClient = (Client) ? 1 : 0;
}
}
}
StatusForm sForm = null;
sForm = new StatusForm(true, iSD, iGW, iSUm, iUpd, iapp, idb,iappMobile,iServer,iClient);
sForm.ShowDialog();
}
private bool TestAPPlication(string name, string exe)
{
bool ret = false;
FileInfo fi = new FileInfo(installPath + name + "\\" + exe);
if (fi.Exists)
{
ret = true;
Console.WriteLine("File " + installPath + name + "\\" + exe + " found.");
}
else
{
Console.WriteLine("File " + installPath + name + "\\" + exe + " missing retry.");
}
return ret;
}
private bool TestPostgresDB()
{
bool valueToReturn = false;
int nbOfTries = 13;
bool tryAgain = false;
while (nbOfTries > 0)
{
if (tryAgain)
{
Utils.WriteLine("Wait 5 seconds ....", ConsoleColor.Green);
Thread.Sleep(5000); //
}
try
{
valueToReturn = TestDB();
break;
}
catch (Exception ex)
{
if (ex.ToString().Contains("the database system is starting up"))
{
Utils.WriteLine("The database system is starting up...", ConsoleColor.Green);
nbOfTries--;
tryAgain = true;
}
else
{
// error - i will stop
Utils.WriteLine("Error on open DB" + ex.ToString(), ConsoleColor.Red);
break;
}
}
}
return valueToReturn;
}
private bool TestDB()
{
bool ret = false;
DBuserManager db4users = null;
db4users= new DBuserManager("localhost", "safedispatchdb", "postgres", "wizdemo26", txDefPort.Text);
db4users.getAllUsers();
ret = true;
Console.WriteLine("TEST DB done");
// udpate DB
DBupdateManager db4update = null;
db4update= new DBupdateManager("localhost", "safedispatchdb", "postgres", "wizdemo26", txDefPort.Text);
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
db4update.Insert_New_DBUpdate(v.ToString());
db4update.Update_database_for_SD6();
if (install_Repeater_GW)
{
//delete old
DBgatewaysManager db4gateway = null;
db4gateway = new DBgatewaysManager("localhost", "safedispatchdb", "postgres", "wizdemo26", txDefPort.Text);
db4gateway.deleteGateway(1);
//add repeater gateway
db4gateway.add_a_default_Repeater_In_database();
}
return ret;
}
private void TestUninstall()
{
int iSD = 2, iGW = 2, iSUm = 2, iapp = 2, iUpd = 2, idb = 2, iappMobile = 2, iserver =2, iclient =2;
if (cbSDinstall.Checked)
{
if (uninstall_hash.ContainsKey(AppNAME))
{
bool sd = TestUninstall4App(AppNAME);
iSD = (sd) ? 1 : 0;
}
}
if (cbGWinstall.Checked)
{
if (uninstall_hash.ContainsKey("Gateway"))
{
bool gw = TestUninstall4App("Gateway");
iGW = (gw) ? 1 : 0;
}
}
if (cbSUMinstall.Checked)
{
if (uninstall_hash.ContainsKey("AdministrativeModule"))
{
bool sum = TestUninstall4App("AdministrativeModule");
iSUm = (sum) ? 1 : 0;
}
}
if (cbDBinstall.Checked)
{
if (uninstall_hash.ContainsKey("AppServer"))
{
bool app = TestUninstall4App("AppServer");
iapp = (app) ? 1 : 0;
}
if (uninstall_hash.ContainsKey("postgresql"))
{
bool db = TestUninstall4App("postgresql");
idb = (db) ? 1 : 0;
}
}
if (uninstall_hash.ContainsKey("Updater"))
{
bool upd = TestUninstall4App("Updater");
iUpd = (upd) ? 1 : 0;
}
if (cbInstallSDMobile.Checked)
{
if (uninstall_hash.ContainsKey("AppServerMobile"))
{
bool appMobile = TestUninstall4App("AppServerMobile");
iappMobile = (appMobile) ? 1 : 0;
}
}
if (AdvanceSettings)
{
if (rbTCPServer.IsChecked)
{
if (uninstall_hash.ContainsKey("TCPServer"))
{
bool Server = TestUninstall4App("TCPServer");
iserver = (Server) ? 1 : 0;
}
}
else if (rbTCPClient.IsChecked)
{
if (uninstall_hash.ContainsKey("TCPClient"))
{
bool Client = TestUninstall4App("TCPClient");
iclient = (Client) ? 1 : 0;
}
}
}
StatusForm sForm = null;
sForm = new StatusForm(false, iSD, iGW, iSUm, iUpd, iapp, idb,iappMobile,iserver,iclient);
sForm.ShowDialog();
}
private bool TestUninstall4App(string name)
{
bool ret = true;
DirectoryInfo fi = new DirectoryInfo(installPath + name + "\\" );
if (fi.Exists)
{
ret = false;
Console.WriteLine("Found->File " + installPath + name + "\\");
}
else
{
Console.WriteLine("Missing->File " + installPath + name + "\\");
}
return ret;
}
private bool Search4App(string name)
{
String instalationPath = installPath.Replace(@"\\", @"\");
Utils.WriteLine($"Searching for installed app {name} in {(instalationPath + name)}\\", ConsoleColor.DarkYellow);
bool ret = false;
DirectoryInfo fi = new DirectoryInfo(instalationPath.Replace(@"\\", @"\") + name + "\\");
if (fi.Exists)
{
ret = true;
Console.WriteLine("Found->File " + instalationPath + name + "\\");
}
else
{
Console.WriteLine("Missing->File " + instalationPath + name + "\\");
}
return ret;
}
private bool IsAppInstalled(App app)
{
String installedLocation = GetRegValue("InstalledLocation", App.GetAppName(app));
if (String.IsNullOrEmpty(installedLocation))
{
Utils.WriteLine($"{app} is not already installed");
return false;
}
Utils.WriteLine($"{app} IsAppInstalled to " + installedLocation, ConsoleColor.Yellow);
if (installedLocation.Length < 2)
return false;
// check if the folder exists
bool ret = false;
DirectoryInfo fi = new DirectoryInfo(installedLocation + "\\");
if (fi.Exists)
{
ret = true;
Utils.WriteLine("Found->File " + installedLocation + "\\", ConsoleColor.White);
// check if an exe file exists there
if (Directory.GetFiles(installedLocation, "*.exe").Length == 0)
{
//NO matching *.exe files
ret = false;
}
else
{
//has matching *.exe files
ret = true;
}
}
else
{
Utils.WriteLine("Missing->File " + installedLocation + "\\", ConsoleColor.White);
}
// check if product code is installed
// TODO
return ret;
}
#endregion
private void dropGatewayList_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if (radioType == RADIOTYPE.MOTO)
{
switch (dropGatewayList.SelectedIndex)
{
case 0:
EXE_Gateway = "MotoTRBO_GW.exe";
GatewayNAME = "MotoTRBO";
uInstall_Gateway = "Gateway";
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
case 1:
EXE_Gateway = "Tetra_GW.exe";
GatewayNAME = "Tetra";
uInstall_Gateway = "TetraGW";
txDefPortGW.Visible = radLabel8.Visible = true;
radLabel3.Text = "Database IP";
break;
case 2:
EXE_Gateway = "CPlus_GW.exe";
GatewayNAME = "Connect Plus";
uInstall_Gateway = "CPlusGW";
txDefPortGW.Visible = radLabel8.Visible = true;
radLabel3.Text = "Database IP";
break;
case 3:
EXE_Gateway = "SDRgateway.exe";
GatewayNAME = "Tetra_SDR";
uInstall_Gateway = "SDRgateway";
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
case 4:
EXE_Gateway = "MotoRepeater.exe";
GatewayNAME = "Repeater_Gateway";
uInstall_Gateway = "Repeater_Gateway";
txDefPortGW.Visible = radLabel8.Visible = true;
radLabel3.Text = "Database IP";
break;
case 5:
EXE_Gateway = "GatewaySMC.exe";
GatewayNAME = "SMC_Gateway";
uInstall_Gateway = "SMC_Gateway";
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
}
}
else if (radioType == RADIOTYPE.LISF)
{
switch (dropGatewayList.SelectedIndex)
{
case 0:
EXE_Gateway = "Sepura3T_SDR.exe";
GatewayNAME = "Sepura3T_SDR";
uInstall_Gateway = "Sepura3T_SDR";
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
case 1:
EXE_Gateway = "SDRgateway.exe";
GatewayNAME = "Tetra_SDR";
uInstall_Gateway = "SDRgateway";
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
}
}
else if (radioType == RADIOTYPE.LINXB)
{
switch (dropGatewayList.SelectedIndex)
{
case 0:
EXE_Gateway = "LinxGateway.exe";
GatewayNAME = "Linx";
uInstall_Gateway = "LinxGateway";
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
case 1:
EXE_Gateway = "MotoTRBO_GW.exe";
GatewayNAME = "MotoTRBO";
uInstall_Gateway = "Gateway";
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
break;
}
}
else if (radioType == RADIOTYPE.SIMOCO || radioType == RADIOTYPE.LINX || radioType == RADIOTYPE.LINXB)
{
txDefPortGW.Visible = radLabel8.Visible = false;
radLabel3.Text = "Server IP";
}
}
private void linkAdvance_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
AdvanceSettings = true;
linkAdvance.Visible = false;
rbTCPClient.Visible = true;
rbTCPServer.Visible = true;
rbNoService.Visible = true;
lbServerIP.Visible = true;
lbPort.Visible = true;
txTCPIP.Visible = true;
txTCPPort.Visible = true;
switch (radioType)
{
case RADIOTYPE.MOTO:
case RADIOTYPE.LINX:
case RADIOTYPE.LINXB:
case RADIOTYPE.LISF:
/*
gbDispatch.Location = new Point(gbDispatch.Location.X, gbDispatch.Location.Y - 12);
gbGateway.Location = new Point(gbGateway.Location.X, gbGateway.Location.Y - 18);
gbAdmin.Location = new Point(gbAdmin.Location.X, gbAdmin.Location.Y - 20);
gbDatabase.Location = new Point(gbDatabase.Location.X, gbDatabase.Location.Y - 25);*/
rbTCPServer.Location = new Point(rbTCPServer.Location.X + 60, rbTCPServer.Location.Y-10);
rbTCPClient.Location = new Point(rbTCPServer.Location.X + 100, rbTCPServer.Location.Y);
rbNoService.Location = new Point(rbTCPServer.Location.X - 100, rbTCPServer.Location.Y);
lbServerIP.Location = new Point(lbServerIP.Location.X - 10, lbServerIP.Location.Y );
txTCPIP.Location = new Point(lbServerIP.Location.X + 50, lbServerIP.Location.Y);
lbPort.Location = new Point(lbServerIP.Location.X + 125, lbServerIP.Location.Y);
txTCPPort.Location = new Point(680, lbServerIP.Location.Y);
cbInstallSDMobile.Visible = true;
cbInstallSDMobile.Location = new Point(cbInstallSDMobile.Location.X, cbInstallSDMobile.Location.Y + 7);
break;
case RADIOTYPE.EXCERA:
/*
gbDispatch.Location = new Point(gbDispatch.Location.X, gbDispatch.Location.Y - 12);
gbGateway.Location = new Point(gbGateway.Location.X, gbGateway.Location.Y - 18);
gbAdmin.Location = new Point(gbAdmin.Location.X, gbAdmin.Location.Y - 20);
gbDatabase.Location = new Point(gbDatabase.Location.X, gbDatabase.Location.Y - 25);*/
rbTCPServer.Location = new Point(rbTCPServer.Location.X + 60, rbTCPServer.Location.Y);
rbTCPClient.Location = new Point(rbTCPServer.Location.X + 100, rbTCPServer.Location.Y);
rbNoService.Location = new Point(rbTCPServer.Location.X - 100, rbTCPServer.Location.Y);
lbServerIP.Location = new Point(lbServerIP.Location.X - 10, lbServerIP.Location.Y+10);
txTCPIP.Location = new Point(lbServerIP.Location.X + 60, lbServerIP.Location.Y);
lbPort.Location = new Point(lbServerIP.Location.X + 125, lbServerIP.Location.Y);
txTCPPort.Location = new Point(680, lbServerIP.Location.Y);
cbInstallSDMobile.Visible = true;
cbInstallSDMobile.Location = new Point(cbInstallSDMobile.Location.X, cbInstallSDMobile.Location.Y + 7);
break;
case RADIOTYPE.HYT:
gbDispatch.Location = new Point(gbDispatch.Location.X, gbDispatch.Location.Y - 12);
gbGateway.Location = new Point(gbGateway.Location.X, gbGateway.Location.Y - 18);
gbAdmin.Location = new Point(gbAdmin.Location.X, gbAdmin.Location.Y - 20);
gbDatabase.Location = new Point(gbDatabase.Location.X, gbDatabase.Location.Y - 25);
rbTCPServer.Location = new Point(rbTCPServer.Location.X +10, rbTCPServer.Location.Y - 15);
rbTCPClient.Location = new Point(rbTCPServer.Location.X + 100, rbTCPServer.Location.Y);
rbNoService.Location = new Point(rbTCPServer.Location.X - 100, rbTCPServer.Location.Y);
lbServerIP.Location = new Point(lbServerIP.Location.X - 60, lbServerIP.Location.Y - 5);
txTCPIP.Location = new Point(lbServerIP.Location.X + 50, lbServerIP.Location.Y);
lbPort.Location = new Point(lbServerIP.Location.X + 125, lbServerIP.Location.Y);
txTCPPort.Location = new Point(630, lbServerIP.Location.Y);
cbInstallSDMobile.Visible = true;
cbInstallSDMobile.Location = new Point(cbInstallSDMobile.Location.X - 50, cbInstallSDMobile.Location.Y-10);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 50);
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 30);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 30);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 30);
break;
case RADIOTYPE.HARRIS:
gbDispatch.Location = new Point(gbDispatch.Location.X, gbDispatch.Location.Y);
gbGateway.Location = new Point(gbGateway.Location.X, gbGateway.Location.Y - 11);//2
gbAdmin.Location = new Point(gbAdmin.Location.X, gbAdmin.Location.Y - 20);//4
gbDatabase.Location = new Point(gbDatabase.Location.X, gbDatabase.Location.Y - 34);//6
rbTCPServer.Location = new Point(rbTCPServer.Location.X +20, rbTCPServer.Location.Y - 13);
rbTCPClient.Location = new Point(rbTCPServer.Location.X + 100, rbTCPServer.Location.Y);
rbNoService.Location = new Point(rbTCPServer.Location.X - 100, rbTCPServer.Location.Y);
lbServerIP.Location = new Point(lbServerIP.Location.X - 50, lbServerIP.Location.Y - 3);
txTCPIP.Location = new Point(lbServerIP.Location.X + 50, lbServerIP.Location.Y);
lbPort.Location = new Point(lbServerIP.Location.X + 125, lbServerIP.Location.Y);
txTCPPort.Location = new Point(640, lbServerIP.Location.Y);
cbInstallSDMobile.Visible = true;
cbInstallSDMobile.Location = new Point(cbInstallSDMobile.Location.X -40, cbInstallSDMobile.Location.Y + 4);
cbInstallSDMobile.ForeColor = Color.White;
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 50);
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 30);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 30);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 30);
break;
case RADIOTYPE.ATLAS:
gbDispatch.Location = new Point(gbDispatch.Location.X, gbDispatch.Location.Y - 12);
gbGateway.Location = new Point(gbGateway.Location.X, gbGateway.Location.Y - 21);//2
gbAdmin.Location = new Point(gbAdmin.Location.X, gbAdmin.Location.Y - 26);//4
gbDatabase.Location = new Point(gbDatabase.Location.X, gbDatabase.Location.Y - 34);//6
rbTCPServer.Location = new Point(rbTCPServer.Location.X -310, rbTCPServer.Location.Y - 25);
rbTCPClient.Location = new Point(rbTCPServer.Location.X + 100, rbTCPServer.Location.Y);
rbNoService.Location = new Point(rbTCPServer.Location.X - 100, rbTCPServer.Location.Y);
lbServerIP.Location = new Point(lbServerIP.Location.X - 380, lbServerIP.Location.Y - 15);
txTCPIP.Location = new Point(lbServerIP.Location.X + 60, lbServerIP.Location.Y);
lbPort.Location = new Point(lbServerIP.Location.X + 125, lbServerIP.Location.Y);
txTCPPort.Location = new Point(320, lbServerIP.Location.Y);
cbInstallSDMobile.Visible = true;
cbInstallSDMobile.Location = new Point(cbInstallSDMobile.Location.X-370, cbInstallSDMobile.Location.Y - 25);
cbDBinstall.Location = new Point(gbDatabase.Location.X + 218, gbDatabase.Location.Y + 50);
cbSDinstall.Location = new Point(gbDispatch.Location.X + 218, gbDispatch.Location.Y + 30);
cbGWinstall.Location = new Point(gbGateway.Location.X + 218, gbGateway.Location.Y + 30);
cbSUMinstall.Location = new Point(gbAdmin.Location.X + 218, gbAdmin.Location.Y + 30);
break;
case RADIOTYPE.SIMOCO:
//depend on the desing
//rbTCPServer.Location = new Point(rbTCPServer.Location.X + 60, rbTCPServer.Location.Y - 25);
rbTCPClient.Location = new Point(rbTCPServer.Location.X + 100, rbTCPServer.Location.Y);
rbNoService.Location = new Point(rbTCPServer.Location.X - 100, rbTCPServer.Location.Y);
//lbServerIP.Location = new Point(lbServerIP.Location.X - 10, lbServerIP.Location.Y - 15);
txTCPIP.Location = new Point(lbServerIP.Location.X + 50, lbServerIP.Location.Y);
lbPort.Location = new Point(lbServerIP.Location.X + 125, lbServerIP.Location.Y);
txTCPPort.Location = new Point(lbServerIP.Location.X+200, lbServerIP.Location.Y);
cbInstallSDMobile.Visible = true;
break;
}
//linkAdvance
}
private void rbTCPClient_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (rbTCPClient.IsChecked)
{
txTCPPort.Enabled = true;
txTCPIP.Enabled = true;
}
}
private void rbTCPServer_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (rbTCPServer.IsChecked)
{
txTCPPort.Enabled = true;
txTCPIP.Enabled = false;
}
}
private void rbNoService_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (rbNoService.IsChecked)
{
txTCPPort.Enabled = false;
txTCPIP.Enabled = false;
}
}
private void cbSDinstall_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
gbDispatch.Enabled = cbSDinstall.Checked;
}
private void cbGWinstall_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
gbGateway.Enabled = cbGWinstall.Checked;
}
private void cbSUMinstall_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
gbAdmin.Enabled = cbSUMinstall.Checked;
}
private void cbDBinstall_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
gbDatabase.Enabled = cbDBinstall.Checked;
}
private void MainForm_Shown(object sender, EventArgs e)
{
txDefPortSUM.Enabled = true;
txDefPortSD.Enabled = true;
txDefPortGW.Enabled = true;
txDefPort.Enabled = true;
cbSDinstall.Checked = true;
cbGWinstall.Checked = true;
cbSUMinstall.Checked = true;
cbDBinstall.Checked = true;
cbSDinstall_ToggleStateChanged(cbSDinstall, null);
cbGWinstall_ToggleStateChanged(cbSDinstall, null);
cbSUMinstall_ToggleStateChanged(cbSDinstall, null);
cbDBinstall_ToggleStateChanged(cbSDinstall, null);
txDefPortSUM.Enabled = true;
txDefPortSD.Enabled = true;
txDefPortGW.Enabled = true;
txDefPort.Enabled = true;
}
}
//public enum RADIOTYPE
//{
// MOTO = 0,
// HYT = 1,
// HARRIS = 2,
// ATLAS = 3,
// SIMOCO = 4,
// UNKNOWN = 5,
// LINX = 6,
// LINXB = 7
//}
}