2051 lines
82 KiB
C#
2051 lines
82 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace NX_Installation
|
|
{
|
|
public partial class FrmMain : Form
|
|
{
|
|
#region Legende und History
|
|
// ----------------------------------------------------------------------------------------------------------------------
|
|
// Dient zum Installieren von NX mit SVAI Umgebung.
|
|
// Es kann unter bis zu drei unterschiedlichen NX Versionen gewählt werden.
|
|
// Es kann unter beliebig vielen Locations gewählt werden.
|
|
// Es kann ausgewählt werden, ob die NX Dokumentation mitinstalliert wird oder nicht.
|
|
// Weiters ist einzustellen ob der Rechner ein Desktopgerät oder Laptop ist und ob sich dieser Rechner im SVAI MT Netzwerk
|
|
// befindet. Ist der Rechner im SVAI MT Netzwerk und es handelt sich um einen Laptop, dann wird ein Synchronisations-
|
|
// prozess eingerichtet, welcher die für die SVAI MT Umgebung notwendigen Daten synchronisiert, sobald der Laptop mit dem
|
|
// SVAI MT Netzwerk verbunden ist. Dadurch steht die SVAI MT Umgebung auch zur Verfügung, wenn der Laptop nicht mit dem
|
|
// SVAI MT Netzwerk verbunden ist.
|
|
// Genau so verhält sich auch ein Desktop Rechner der nicht mit dem SVAI MT Netzwerk verbunden ist, nur dass hier die
|
|
// Synchronisation manuell durchgeführt werden muss, z.B.: Supplier, welcher das Verzeichnis NX_VAI zum Projektstart aus-
|
|
// gehändigt bekommt.
|
|
// ----------------------------------------------------------------------------------------------------------------------
|
|
// (C) 2012 - 2017 by Eugen Höglinger
|
|
// ----------------------------------------------------------------------------------------------------------------------
|
|
// - init 2012-04-25 E. Höglinger
|
|
// - Um Logdatei 'C:\TMP\NX-Installation.log' erweitert. 2012-07-23 E. Höglinger
|
|
// - Das Tool log4net.dll durch selbstprogrammierten Logmechanismus ersetzt. 2012-07-26 E. Höglinger
|
|
// - Wenn das Verzeichnis 'C:\TMP' nicht existiert, dann anlegen. 2012-08-22 E. Höglinger
|
|
// - Das Verzeichnis 'LocationSpecificDatas' und die Dateien darin sowie die Dateien
|
|
// 'Install_NX.cmd' und '_InstallNX.cmd' werden für die Installation nicht mehr benötigt. 2012-09-25 E. Höglinger
|
|
// - Überprüfung ob genügend Festplattenplatz auf Laufwerk C:\ frei ist. Für die Vollinstallation
|
|
// wird als Größe vier mal die Summe aus NX- und NX-Doku-Installationsverzeichnis angenommen,
|
|
// für ein Update, drei mal das Update-Installationsvereichnis. 2012-10-18 E. Höglinger
|
|
// - Die Installationsroutinene für NX, NX-Doku und NX-Portal und diverse Logfileeinträge
|
|
// überarbeitet.
|
|
// NX-Logo mit Transparenten Hintergrund. 2012-10-21 E. Höglinger
|
|
// - Kleine Korrekturen in den Log-Texten.
|
|
// Übergabeparameter für die NX-Portal-Gruppe angepasst.
|
|
// Pfad der NX-Docu-Installationsdateien korrigiert.
|
|
// Umgebungsvariable 'COMPSOLVE_MACHINE' zur Laufzeit gesetzt. Wird von NX-Update benötigt.
|
|
// Verzichtserklärung neu dazu. 2012-11-08 E. Höglinger
|
|
// - Vom Anwender ausgewählte Schalter und Menüpunkte werden in der Logdatei mitprotokolliert. 2012-11-12 E. Höglinger
|
|
// - Windows version und Plattform wird in Logfile eingetragen. 2012-11-13 E. Höglinger
|
|
// - Alle Logfiles werden jetzt nach 'C:\TMP\Logfiles'. Das war notwendig, weil Win7 mit UAC,
|
|
// ohne Administrator Rechte, nicht in das Programmverzeichnis schreiben kann.
|
|
// Abfrage ob das Logfileverzeichnis bereits existiert. Wenn nicht dann anlegen.
|
|
// Die Installationsroutinen von NX und NX-Doku über 'Runas' starten. Wird sonst unter Win7
|
|
// mit UAC ignorriert. 2012-11-18 E. Höglinger
|
|
// - Cancel-Button und -Menü nach dem anwählen des Start-Buttons oder -Menüs deaktivieren.
|
|
// Anzeigetext im Feld 'System message' verbessert. 2012-11-19 E. Höglinger
|
|
// - Die Dateinamen für <Namen>.msi ab Version NX8 werden berücksichtigt. 2012-11-29 E. Höglinger
|
|
// Version 2.2 - Konvertiert für Visual Studio 2010 2013-02-14 E. Höglinger
|
|
// - Manifest hinzugefügt, damit Programm immer mit Administrator-Rechten startet 2013-04-25 E. Höglinger
|
|
// - Ist das Betriessystem Windows Vista oder neuer, dann wird bei installierter 3D-Mouse die
|
|
// Installation korrigiert (Startup-Eintrag wird entfernt, Scheduled Task wird erzeugt, welcher
|
|
// den 3D-Mouse-Server beim Login mit Administrator-Rechten startet. 2013-04-26 E. Höglinger
|
|
// - 'CorrectSpacemouse();' in der Methode 'private void PerformInstallation(string messageText)'
|
|
// vorübergehend deaktiviert. 2013-06-13 E. Höglinger
|
|
// - Ab NX9 gibt es nur mehr eine 64bit Version. Darum werden die Pfade für die Dokumentation
|
|
// korrigiert. 2013-10-10 E. Höglinger
|
|
// - Die Variable 'NxLongVersion' eingeführt, damit auch Versionen ohne Nachkomma aufgelöst
|
|
// werden können.
|
|
// Bildschirmausgabe welche in den Logfile geschrieben wird, in einzelne Zeilen aufgelöst. 2013-10-22 E. Höglinger
|
|
// - init Version 2.3 Built20170818 2017-08-18 E. Höglinger
|
|
// - Versionsnummerierung umgestellt. Zählt nun automatisch hoch. Copyright Enddatum wird nun
|
|
// automatisch generiert. 2017-08-18 E. Höglinger
|
|
// - Pfade und Umgebung an ENGEL angepasst. 2017-08-22 E. Höglinger
|
|
// - Logik der Statusanzeige verbessert. Statusanzeige bleibt so lange rot, bis alle notwendigen
|
|
// Einstellungen getroffen wurden.
|
|
// - Windows-Erkennung verbessert. Erkennt nun auch Windows 10.
|
|
//
|
|
// ----------------------------------------------------------------------------------------------------------------------
|
|
#endregion
|
|
|
|
|
|
#region Version und Copyright
|
|
// Version und Copyright
|
|
string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
|
string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
string copyright = String.Concat(((AssemblyCopyrightAttribute)attributes[0]).Copyright, "-", Year(), " by Eugen Hoeglinger");
|
|
string icon = Application.StartupPath + "\\Info.bmp";
|
|
//Assembly Datum und Zeit
|
|
static DateTime value = AssemblyDateTime();
|
|
string date = value.ToShortDateString();
|
|
string time = value.ToLongTimeString();
|
|
private static DateTime AssemblyDateTime()
|
|
{
|
|
var programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * programVersion.Build + TimeSpan.TicksPerSecond * 2 * programVersion.Revision));
|
|
//Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original)
|
|
return buildDateTime;
|
|
}
|
|
private static string Year()
|
|
{
|
|
DateTime d = DateTime.Now;
|
|
return d.Year.ToString();
|
|
}
|
|
#endregion
|
|
|
|
#region Globale Variablen
|
|
const string line = "--------------------------------------------------";
|
|
const string leftSpace = " ";
|
|
const string externalPartner = "Supplier / External partner / Not ENGEL";
|
|
const string logfile = @"C:\TEMP\Logfiles\NX-Installation.log";
|
|
public string Logfile { get; set; }
|
|
const int lenghtArrayListVersion = 3;
|
|
|
|
private string WindowsVersion { get; set; } //Windowsversion, z.B.: Windows 7
|
|
private string Platform { get; set; } //32- oder 64-bit
|
|
|
|
|
|
public string NxVersion { get; set; } //Transferparameter 1 (NX_LONG_VERSION)
|
|
public string NxDocumentation { get; set; } //Transferparameter 2 (DOKUMENTATION)
|
|
public string Location { get; set; } //Transferparameter 3 (LOCATION)
|
|
public string NxPortalGroup { get; set; } //Transferparameter 4 (NXPortalGroup)
|
|
public string StartupFolder { get; set; } //Transferparameter 5 (STARTUP_FOLDER)
|
|
public string ComputerType { get; set; } //Transferparameter 6 (COMPUTER_TYPE)
|
|
public string ConnectionType { get; set; } //Transferparameter 7 (CONNECTION_TYPE)
|
|
|
|
public string NxBaseVersion { get; set; } //Base version z.B.: 7
|
|
public string NxLongVersion { get; set; } //Base version z.B.: 7.5
|
|
public string NxShortVersion { get; set; } //Short version z.B: 75
|
|
public string NxShort0Version { get; set; } //Short 0 version z.B: 075
|
|
|
|
private string NxInstallDir { get; set; } //Installationsverzeichnis von NX, z.B.: 'UGS' oder 'Siemens'
|
|
private string NxMsi { get; set; } //NX Installationsdatei
|
|
private string NxDocMsi { get; set; } //NX Dokumentation Installationsdatei
|
|
private string NxUpdateTool { get; set; } //NX-Update-Tool
|
|
private string UgToolsDir { get; set; } //UG-Tools
|
|
private string NxPortalInstaller { get; set; } //NX-Portal
|
|
|
|
private string NxInstallLogFile { get; set; }
|
|
private string NxDocInstallLogFile { get; set; }
|
|
|
|
private string UgsLicenseServer { get; set; }
|
|
private string UgsLicenseBundle { get; set; }
|
|
private string UgiiBaseDir { get; set; }
|
|
private string UgiiRootDir { get; set; }
|
|
private string UgiiLang { get; set; }
|
|
private string JavaHome { get; set; }
|
|
const int MaxFitBoxSize = 900000;
|
|
private string UgiiTmpDir { get; set; }
|
|
|
|
private string NxOnline { get; set; }
|
|
private string NxOffline { get; set; }
|
|
|
|
public string MessageText { get; set; } //Text im Ausgabefenster
|
|
private bool Error { get; set; } //Wird gesetzt wenn ein Fehler auftritt
|
|
#endregion
|
|
|
|
Logfile log = new Logfile(logfile);
|
|
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FrmMain_Load(object sender, EventArgs e)
|
|
{
|
|
// Splash-Formular erzeugen und anzeigen
|
|
FrmSplash frmSplash = new FrmSplash();
|
|
frmSplash.Show();
|
|
Application.DoEvents();
|
|
|
|
try
|
|
{
|
|
// Wenn 'C:\TMP' nicht existiert, dann anlegen
|
|
TempFolderExist();
|
|
|
|
//Wenn Verzeichnis für Logfiles nicht existiert, dann anlegen
|
|
ExistLogfileDir(logfile);
|
|
|
|
//Logfile anlegen. Wenn Logfile schon vorher existiert, dann zuerst löschen
|
|
LogfileExist(logfile);
|
|
|
|
Thread.Sleep(1500);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Fatal("Initialization Error - Software will be stopped");
|
|
|
|
MessageBox.Show("Initialization error: " + ex.Message,
|
|
Application.ProductName, MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
Application.Exit();
|
|
}
|
|
|
|
// Splash-Formular wieder schließen
|
|
frmSplash.Close();
|
|
|
|
Start();
|
|
}
|
|
|
|
private void TempFolderExist()
|
|
{
|
|
if (!Directory.Exists("C:\\TEMP"))
|
|
{
|
|
Directory.CreateDirectory("C:\\TEMP");
|
|
}
|
|
}
|
|
|
|
private void ExistLogfileDir(string logfile)
|
|
{
|
|
//Wenn Verzeichnis für Logfiles nicht existiert, dann anlegen
|
|
string logfileDir = logfile.Remove(logfile.LastIndexOf("\\"));
|
|
if (!Directory.Exists(logfileDir)) Directory.CreateDirectory(logfileDir);
|
|
}
|
|
|
|
private void LogfileExist(string logfile)
|
|
{
|
|
if (File.Exists(logfile)) File.Delete(logfile);
|
|
|
|
//Kopf des Logfiles
|
|
log.Info(line);
|
|
log.Info("NX-Installation");
|
|
log.Info("Version " + programVersion);
|
|
log.Info(copyright);
|
|
log.Info(line);
|
|
}
|
|
|
|
# region Buttons
|
|
private void btnInstall_Click(object sender, EventArgs e)
|
|
{
|
|
log.Info("Button 'Install' is choosen");
|
|
|
|
//Cancel Button deaktivieren
|
|
this.btnCancel.Enabled = false;
|
|
this.cancelToolStripMenuItem.Enabled = false;
|
|
|
|
Install();
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
log.Info("Button 'Cancel' is choosen");
|
|
log.Warn("Exit: Stopped by User");
|
|
this.Close();
|
|
}
|
|
# endregion
|
|
|
|
#region Menüs
|
|
private void installToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
log.Info("Menu 'Action | Install' is choosen");
|
|
|
|
//Cancel Button deaktivieren
|
|
this.btnCancel.Enabled = false;
|
|
this.cancelToolStripMenuItem.Enabled = false;
|
|
|
|
Install();
|
|
}
|
|
|
|
private void cancelToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
log.Info("Menu 'Action | Cancel' is choosen");
|
|
this.Close();
|
|
}
|
|
|
|
private void helpToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
log.Info("Menu 'Help | Help' is choosen");
|
|
|
|
string help = "- Choose one option in each group.";
|
|
help += "\n\n- The botton 'Install' will start the\n installation process.";
|
|
help += "\n\n- The botton 'Cancel' will stop the\n programm without changes.";
|
|
MessageBox.Show(help,
|
|
"Help!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Question,
|
|
MessageBoxDefaultButton.Button1);
|
|
}
|
|
|
|
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
log.Info("Menu 'Help | About' is choosen");
|
|
|
|
MessageBox.Show("NX-Installation\n\n" + "Version " + programVersion + "\n\n" + copyright,
|
|
"Information!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information,
|
|
MessageBoxDefaultButton.Button1);
|
|
}
|
|
|
|
private void disclaimerToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
log.Info("Menu 'Help | Disclaimer' is choosen");
|
|
|
|
Disclaimer dis = new Disclaimer(logfile);
|
|
dis.Show();
|
|
dis.Update();
|
|
}
|
|
#endregion
|
|
|
|
#region Radio buttons
|
|
private void rdbVersion1_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
log.Info("Radio button 'Version 1' is choosen");
|
|
|
|
IsAllSelected();
|
|
SetNxVersion(rdbVersion1.Text); //%NX_LONG_VERSION% setzen
|
|
}
|
|
|
|
private void rdbVersion2_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
log.Info("Radio button 'Version 2' is choosen");
|
|
|
|
IsAllSelected();
|
|
SetNxVersion(rdbVersion2.Text); //%NX_LONG_VERSION% setzen
|
|
}
|
|
|
|
private void rdbVersion3_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
log.Info("Radio button 'Version 3' is choosen");
|
|
|
|
IsAllSelected();
|
|
SetNxVersion(rdbVersion3.Text); //%NX_LONG_VERSION% setzen
|
|
}
|
|
|
|
private void rdbDocumentationYes_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
log.Info("Radio button Documentation: 'Yes' is choosen");
|
|
|
|
IsAllSelected();
|
|
SetNxDocumentation("STANDALONE"); //%DOKUMENTATION% setzen
|
|
}
|
|
|
|
private void rdbDocumentationNo_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
log.Info("Radio button Documentation: 'No' is choosen");
|
|
|
|
WriteTextToSystemMessage(WriteSelectedOptionsToSystemMessage(), false);
|
|
SetNxDocumentation("NETWORK"); //%DOKUMENTATION% setzen
|
|
}
|
|
|
|
private void cbxLocation_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
log.Info("List box 'Location' is choosen");
|
|
|
|
IsAllSelected();
|
|
|
|
string location = cbxLocation.Text;
|
|
if (location == "Supplier / External partner / Not ENGEL")
|
|
{
|
|
location = "Supplier";
|
|
}
|
|
SetLocation(location); //%LOCATION% setzen
|
|
log.Info("Read avail NX version for " + Location);
|
|
ReadAvailVersion(StartupFolder);
|
|
if (!this.rdbVersion1.Enabled & (Location != "" || Location != null)) ChangeSelection(); //Wenn ausgeschaltet, dann wieder einschalten
|
|
}
|
|
|
|
private void rdbDesktop_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
log.Info("Radio button 'Computer type=Desktop' is choosen");
|
|
|
|
IsAllSelected();
|
|
SetComputerType("Desktop"); //%COMPUTER_TYPE% setzen
|
|
}
|
|
|
|
private void rdbLaptop_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
log.Info("Radio button 'Computer type=Laptop' is choosen");
|
|
|
|
IsAllSelected();
|
|
SetComputerType("Laptop"); //%COMPUTER_TYPE% setzen
|
|
}
|
|
#endregion
|
|
|
|
private void Install()
|
|
{
|
|
WriteTextToSystemMessage("Runing installation ...", false);
|
|
if (IsAllSelected()) StartInstallation();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
Error = false;
|
|
SetUncEnable();
|
|
|
|
//Windows Version ermitteln
|
|
WindowsVersion = GetWindowsVersion();
|
|
|
|
//Plattform ermitteln
|
|
Platform = GetPlatform(WindowsVersion);
|
|
|
|
//Startupverzeichnis ermitteln
|
|
GetPaths gp = new GetPaths(logfile);
|
|
StartupFolder = gp.GetStartupFolder();
|
|
if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("NX_ONLINE")))
|
|
{
|
|
StartupFolder = Environment.GetEnvironmentVariable("NX_ONLINE");
|
|
}
|
|
else
|
|
{
|
|
StartupFolder = StartupFolder.Remove(StartupFolder.LastIndexOf("\\"));
|
|
StartupFolder = StartupFolder.Remove(StartupFolder.LastIndexOf("\\"));
|
|
}
|
|
|
|
//Die Locations auslesen, welche installiert werden können
|
|
ReadAvailLocation(StartupFolder);
|
|
|
|
//Die NX-Versionen auslesen, welche installiert werden können
|
|
ReadAvailVersion(StartupFolder);
|
|
|
|
//Übergabeparameter auswerten
|
|
//NX_LONG_VERSION=%1, DOKUMENTATION=%2, LOCATION=%3, NXPortalGroup=%4, STARTUP_FOLDER=%5, COMPUTER_TYPE=%6, CONNECTION_TYPE=%7
|
|
GetTransferParameters gtp = new GetTransferParameters(logfile);
|
|
const int maxArrayLenght = 7;
|
|
string[] transferParameter = new string[DefineArrayLenght(maxArrayLenght)];
|
|
transferParameter = gtp.GetTransferParameter(maxArrayLenght);
|
|
|
|
//Maschinentype ermitteln
|
|
GetComputerType();
|
|
|
|
//Überprüfen ob alle Übergabeparameter einen Wert enthalten.
|
|
if (!gtp.ParametersAreEmpty(transferParameter, maxArrayLenght))
|
|
{
|
|
//JA: Installation Starten ohne die GUI zu öffnen
|
|
StartInstallationDirect();
|
|
if (!rdbVersion1.Enabled)
|
|
{
|
|
WriteTextToSystemMessage("Please select location first!", true);
|
|
this.Refresh();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Nein: Weitermachen
|
|
if (IsAllSelected()) StartInstallation(); //Installation nur starten, wenn alle Werte gesetzt (ausgewählt) sind
|
|
}
|
|
}
|
|
|
|
private void SetUncEnable()
|
|
{
|
|
//Registry setzten, damit UNC-Pfade sicher verwendet werden können
|
|
Process P = new Process();
|
|
P.StartInfo.FileName = "regedit.exe";
|
|
// hier kann z.B. eine Textdatei mit übergeben werden
|
|
P.StartInfo.Arguments = "/s UNCenable.reg";
|
|
P.Start();
|
|
log.Info("Set UNC enable");
|
|
}
|
|
|
|
private string GetWindowsVersion()
|
|
{
|
|
log.Info("Determine Windows version and platform");
|
|
|
|
// Windowsversion ermitteln
|
|
WindowsVersion winVersion = new WindowsVersion();
|
|
string windowsVersion = winVersion.GetWindowsVersion().ToString();
|
|
|
|
|
|
log.Info("Used Windows version: " + windowsVersion);
|
|
|
|
return windowsVersion;
|
|
}
|
|
|
|
private string GetPlatform(string windowsVersion)
|
|
{
|
|
if (windowsVersion.EndsWith("64"))
|
|
{
|
|
log.Info("Used platform: 64-bit");
|
|
return "64bit";
|
|
}
|
|
else
|
|
{
|
|
log.Info("Used platform: 32-bit");
|
|
return "32bit";
|
|
}
|
|
}
|
|
|
|
private void CancelUncEnable()
|
|
{
|
|
//Registry setzten, damit UNC-Pfade sicher verwendet werden können
|
|
Process P = new Process();
|
|
P.StartInfo.FileName = "regedit.exe";
|
|
// hier kann z.B. eine Textdatei mit übergeben werden
|
|
P.StartInfo.Arguments = "/s UNCdisable.reg";
|
|
P.Start();
|
|
log.Info("Set UNC disable");
|
|
}
|
|
|
|
private void ReadAvailVersion(string path)
|
|
{
|
|
log.Info("Determine avail NX version information");
|
|
|
|
if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("NX_ONLINE")))
|
|
{
|
|
path = Environment.GetEnvironmentVariable("NX_ONLINE");
|
|
}
|
|
else
|
|
{
|
|
StartupFolder = StartupFolder.Remove(StartupFolder.LastIndexOf("\\")); //Wenn noch keine Installation besteht, ...
|
|
StartupFolder = StartupFolder.Remove(StartupFolder.LastIndexOf("\\")); //... zwei Stufen im Verzeichnis hochgehen
|
|
}
|
|
|
|
//Die NX-Versionen auslesen, welche installiert werden können
|
|
string filenameVersion = "NX-Portal.ini";
|
|
if (Location == "Please select your location")
|
|
{
|
|
log.Info("Collect information from: No information available."); //Wenn noch keine Location existiert
|
|
WriteTextToSystemMessage("Please choose a location.", true);
|
|
}
|
|
else
|
|
{
|
|
log.Info("Collect information from: " + path + "\\" + Location + "\\" + filenameVersion);
|
|
}
|
|
|
|
if (ExistLocation())
|
|
{
|
|
ReadWriteINI rwi = new ReadWriteINI();
|
|
rwi.IniFile(path + "\\NX-Portal\\" + Location + "\\" + filenameVersion);
|
|
rdbVersion1.Text = rwi.IniReadValue("NX_VERSION", "Version1");
|
|
log.Info("Avail NX version: " + rdbVersion1.Text);
|
|
rdbVersion2.Text = rwi.IniReadValue("NX_VERSION", "Version2");
|
|
log.Info("Avail NX version: " + rdbVersion2.Text);
|
|
rdbVersion3.Text = rwi.IniReadValue("NX_VERSION", "Version3");
|
|
log.Info("Avail NX version: " + rdbVersion3.Text);
|
|
}
|
|
}
|
|
|
|
private bool ExistLocation()
|
|
{
|
|
if (Location == "" || Location == null)
|
|
{
|
|
//Existiert ein Eintrag in der Registy
|
|
if (ExistLocatonInRegistry() != null)
|
|
{
|
|
Location = ExistLocatonInRegistry();
|
|
this.cbxLocation.SelectedItem = Location;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
ChangeSelection();
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private string ExistLocatonInRegistry()
|
|
{
|
|
string location = null;
|
|
ReadWriteRegistry rwr = new ReadWriteRegistry();
|
|
|
|
try
|
|
{
|
|
location = rwr.ReadLocationFromRegistry();
|
|
}
|
|
catch
|
|
{
|
|
ChangeSelection();
|
|
}
|
|
if (location != "")
|
|
{
|
|
return location;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private void ChangeSelection()
|
|
{
|
|
this.rdbVersion1.Enabled = !this.rdbVersion1.Enabled;
|
|
this.rdbVersion2.Enabled = !this.rdbVersion2.Enabled;
|
|
this.rdbVersion3.Enabled = !this.rdbVersion3.Enabled;
|
|
this.rdbDocumentationYes.Enabled = !this.rdbDocumentationYes.Enabled;
|
|
this.rdbDocumentationNo.Enabled = !this.rdbDocumentationNo.Enabled;
|
|
this.rdbDesktop.Enabled = !this.rdbDesktop.Enabled;
|
|
this.rdbLaptop.Enabled = !this.rdbLaptop.Enabled;
|
|
}
|
|
|
|
private void ReadAvailLocation(string path)
|
|
{
|
|
log.Info("Determine avail locations information");
|
|
|
|
//Die Locations auslesen, welche installiert werden können
|
|
string fileLocation = "";
|
|
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NX_ONLINE")))
|
|
{
|
|
fileLocation = Environment.GetEnvironmentVariable("NX_ONLINE") + "\\NX-Portal";
|
|
}
|
|
else
|
|
{
|
|
fileLocation = path + "\\NX-Portal";
|
|
}
|
|
log.Info("Collect information from: " + fileLocation);
|
|
ArrayList valueLocation = new ArrayList();
|
|
DirectoryInfo ParentDirectory = new DirectoryInfo(fileLocation);
|
|
try
|
|
{
|
|
foreach (DirectoryInfo d in ParentDirectory.GetDirectories())
|
|
{
|
|
if (d.Name != "Supplier")
|
|
{
|
|
valueLocation.Add(d.Name);
|
|
log.Info("Avail location: " + d.Name);
|
|
}
|
|
}
|
|
log.Info("Avail location: Supplier");
|
|
}
|
|
catch
|
|
{
|
|
log.Error("Could not read location information");
|
|
MessageBox.Show("Directory missing!\n\nNecessary Directory can not be found.\nCan not read location information.\n\nPlease inform your administrator!",
|
|
"Error!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error,
|
|
MessageBoxDefaultButton.Button1);
|
|
}
|
|
int lenghtArrayListLocation = valueLocation.Count;
|
|
string[] location = new string[lenghtArrayListLocation];
|
|
location = CopyListArrayToStringArray(lenghtArrayListLocation, valueLocation, true);
|
|
SetComboBoxCollection(location); //ComboBox befüllen
|
|
log.Info("Fill ComboBox with values");
|
|
|
|
if (ExistLocatonInRegistry() != null)
|
|
{
|
|
Location = ExistLocatonInRegistry();
|
|
foreach (var item in location)
|
|
{
|
|
if (item == Location)
|
|
{
|
|
this.cbxLocation.SelectedItem = Location;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool IsAllSelected()
|
|
{
|
|
bool checkIt = false;
|
|
|
|
if (IsLocationSelected() != "OK")
|
|
{
|
|
WriteTextToSystemMessage(IsLocationSelected(), true);
|
|
return checkIt;
|
|
}
|
|
else if (IsVersionSelected() != "OK")
|
|
{
|
|
WriteTextToSystemMessage(IsVersionSelected(), true);
|
|
return checkIt;
|
|
}
|
|
else if (IsDocumentationSelected() != "OK")
|
|
{
|
|
WriteTextToSystemMessage(IsDocumentationSelected(), true);
|
|
return checkIt;
|
|
}
|
|
else if (IsComputerTypeSelected() != "OK")
|
|
{
|
|
WriteTextToSystemMessage(IsComputerTypeSelected(), true);
|
|
return checkIt;
|
|
}
|
|
else
|
|
{
|
|
checkIt = true;
|
|
return checkIt;
|
|
}
|
|
}
|
|
|
|
private string IsVersionSelected()
|
|
{
|
|
if (rdbVersion1.Checked | rdbVersion2.Checked | rdbVersion3.Checked)
|
|
{
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
if (ExistLocatonInRegistry() != null)
|
|
{
|
|
return "Please select a NX version!";
|
|
}
|
|
else
|
|
{
|
|
return "Please select Location first!";
|
|
}
|
|
}
|
|
}
|
|
|
|
private string IsDocumentationSelected()
|
|
{
|
|
if (rdbDocumentationYes.Checked | rdbDocumentationNo.Checked)
|
|
{
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
return "Please select whether Dokumentation is needed or not!";
|
|
}
|
|
}
|
|
|
|
private string IsLocationSelected()
|
|
{
|
|
if (cbxLocation.SelectedItem != null & (cbxLocation.SelectedText != "Please select your location" | cbxLocation.SelectedText != ""))
|
|
{
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
return "Please select your location!";
|
|
}
|
|
}
|
|
|
|
private string IsComputerTypeSelected()
|
|
{
|
|
if (rdbDesktop.Checked | rdbLaptop.Checked)
|
|
{
|
|
return "OK";
|
|
}
|
|
else
|
|
{
|
|
return "Please select the used computer type!";
|
|
}
|
|
}
|
|
|
|
private string WriteSelectedOptionsToSystemMessage()
|
|
{
|
|
return "Selected options:\n" + GetSelectedVersion() + "\n" + GetSelectedDocumentation() + "\n" + GetSelectedLocation() + "\n" + GetSelectedComputerType() + "\n" + GetSelectedConnectionType();
|
|
}
|
|
|
|
private string GetSelectedVersion()
|
|
{
|
|
if (rdbVersion1.Checked)
|
|
{
|
|
return " - Version is " + this.rdbVersion1.Text;
|
|
}
|
|
else if (rdbVersion2.Checked)
|
|
{
|
|
return " - Version is " + this.rdbVersion2.Text;
|
|
}
|
|
else if (rdbVersion3.Checked)
|
|
{
|
|
return " - Version is " + this.rdbVersion3.Text;
|
|
}
|
|
else
|
|
{
|
|
return " - No version is selected!";
|
|
}
|
|
}
|
|
|
|
private string GetSelectedDocumentation()
|
|
{
|
|
if (rdbDocumentationYes.Checked)
|
|
{
|
|
return " - With documentation";
|
|
}
|
|
else if (rdbDocumentationNo.Checked)
|
|
{
|
|
return " - Without documentation";
|
|
}
|
|
else
|
|
{
|
|
return " - No dokumentation option is selected!";
|
|
}
|
|
}
|
|
|
|
private string GetSelectedLocation()
|
|
{
|
|
if (cbxLocation.SelectedItem != null)
|
|
{
|
|
return " - Location is " + cbxLocation.Text;
|
|
}
|
|
else
|
|
{
|
|
return " - No Location is selected!";
|
|
}
|
|
}
|
|
|
|
private string GetSelectedComputerType()
|
|
{
|
|
if (rdbDesktop.Checked)
|
|
{
|
|
return " - Computertype is Desktop";
|
|
}
|
|
else if (rdbLaptop.Checked)
|
|
{
|
|
return " - Computertype is Laptop";
|
|
}
|
|
else
|
|
{
|
|
return " - No computer type is selected!";
|
|
}
|
|
}
|
|
|
|
private string GetSelectedConnectionType()
|
|
{
|
|
if (cbxLocation.Text == "Please select your location")
|
|
{
|
|
return " - No connection type is defined!";
|
|
}
|
|
else if (cbxLocation.Text == externalPartner)
|
|
{
|
|
return " - Not connected with ENGEL Network";
|
|
}
|
|
else
|
|
{
|
|
return " - Connected with ENGEL Network";
|
|
}
|
|
}
|
|
|
|
private void StartInstallationDirect()
|
|
{
|
|
log.Info("Start installation directly");
|
|
|
|
string messageText = "Runing installation ...";
|
|
//WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
|
|
// Übergabeparameter auswerten
|
|
String[] parameter = Environment.GetCommandLineArgs();
|
|
|
|
int zaehler = 0;
|
|
|
|
foreach (string strGruppe in parameter)
|
|
{
|
|
zaehler++;
|
|
}
|
|
|
|
if (zaehler == 8)
|
|
{
|
|
log.Info("7 transfer parameters are detected");
|
|
|
|
//Location Specific Datas setzen und in die Registry schreiben
|
|
SetLocationSpecificData(Location);
|
|
|
|
//Umgebungsvariablen setzen
|
|
SetPermanentEnvironmentDirect(parameter[3], parameter[4], parameter[6], parameter[7]);
|
|
SetRuntimeEnvironmentDirect(parameter[5], parameter[1], parameter[2], parameter[3], parameter[6], parameter[7]);
|
|
|
|
GetTransferParameters gtp = new GetTransferParameters(logfile);
|
|
if (!gtp.ParametersAreEmpty(parameter, 8))
|
|
{
|
|
messageText += "\n Installing NX ...";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
|
|
string argument = parameter[1] + " " + parameter[2] + " " + parameter[3] + " " + parameter[4] + " \"" + parameter[5] + "\" " + parameter[6] + " " + parameter[7];
|
|
|
|
StartInstallationProzess(messageText);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
log.Info("Could not detect 7 transfer parameters");
|
|
|
|
WriteTextToSystemMessage(WriteSelectedOptionsToSystemMessage(), false);
|
|
}
|
|
}
|
|
|
|
private void StartInstallation()
|
|
{
|
|
log.Info("Start installation");
|
|
|
|
string messageText = "Runing installation ...... Do not close this Window";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
|
|
NxPortalGroup = GetNxPortalGroup(); //Gruppe zuordnen
|
|
|
|
//Umgebungsvariablen setzen
|
|
messageText += "\n Setting environment ...";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
SetPermanetEnvironment();
|
|
SetRuntimeEnvironment();
|
|
|
|
//Location Specific Datas setzen und in die Registry schreiben//Umgebungsvariablen setzen
|
|
messageText += "... Done\n Setting locaton specific data ...";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
SetLocationSpecificData(Location);
|
|
|
|
//LocalSynchronizationSetup einrichten und ausführen, wenn Laptop in der ENGEL Umgebung
|
|
if (ComputerType == "Laptop" & ConnectionType == "internal")
|
|
{
|
|
//LocalSynchronizationSetup einrichten und ausführen
|
|
messageText += "... Done\n Installing local synchronization ...";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
InstallLocalSynchronization();
|
|
}
|
|
|
|
//Installation Starten
|
|
messageText += "... Done";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
|
|
int groupNumber = ChangeNxPortalGroupToNumber(NxPortalGroup);
|
|
|
|
string argument = NxVersion + " " + NxDocumentation + " " + Location + " " + groupNumber + " \"" + StartupFolder + "\" " + ComputerType + " " + ConnectionType;
|
|
|
|
StartInstallationProzess(messageText);
|
|
}
|
|
|
|
private int ChangeNxPortalGroupToNumber(string NxPortalGroup)
|
|
{
|
|
int groupNumber = 3;
|
|
switch (NxPortalGroup)
|
|
{
|
|
case "Administrator":
|
|
groupNumber = 0;
|
|
break;
|
|
case "Mainuser":
|
|
groupNumber = 1;
|
|
break;
|
|
case "User":
|
|
groupNumber = 2;
|
|
break;
|
|
case "Guest":
|
|
groupNumber = 3;
|
|
break;
|
|
}
|
|
return groupNumber;
|
|
}
|
|
|
|
private void SetLocationSpecificData(string location)
|
|
{
|
|
//Werte in die Registry schreiben
|
|
string regfile = StartupFolder + "\\NX-Portal\\" + Location + "\\AdjustNXenvironment.reg";
|
|
log.Info("Set location specific data");
|
|
log.Info("Used registry file: " + regfile);
|
|
Process P2 = new Process();
|
|
P2.StartInfo.FileName = "regedit.exe";
|
|
P2.StartInfo.Arguments = "/S \"" + StartupFolder + "\\NX-Portal\\" + Location + "AdjustNXenvironment.reg\"";
|
|
try
|
|
{
|
|
P2.Start();
|
|
P2.WaitForExit(); //Warten bis die Anwendung fertig ist
|
|
log.Info("Location specific data successfuly set");
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("File(s) could not be found!\n\nPlease contact your\nlocal administrator.",
|
|
"Error!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error,
|
|
MessageBoxDefaultButton.Button1);
|
|
|
|
log.Error("File(s) could not be found and written into registry file");
|
|
Error = true;
|
|
WriteTextToSystemMessage(WriteSelectedOptionsToSystemMessage(), false);
|
|
}
|
|
}
|
|
|
|
private void InstallLocalSynchronization()
|
|
{
|
|
//Wurde schon früher ein Synchronizationsprozess installiert, dann diesen löschen
|
|
DelExistingSyncLink();
|
|
|
|
//LocalSynchronization ausführen
|
|
CreateSyncLink(); //Ruft das Programm vom Server auf
|
|
}
|
|
|
|
private void CreateSyncLink()
|
|
{
|
|
string syncProgramFolder;
|
|
if (NxVersion.Contains("."))
|
|
{
|
|
syncProgramFolder = StartupFolder + @"\NX_ENVIRONMENT\NX" + NxVersion.Remove(NxVersion.IndexOf(".")) + @"\NX_APPS\COMPSOLV_TOOLS\tools\LocalSynchronizationSetup";
|
|
}
|
|
else
|
|
{
|
|
syncProgramFolder = StartupFolder + @"\NX_ENVIRONMENT\NX" + NxVersion + @"\NX_APPS\COMPSOLV_TOOLS\tools\LocalSynchronizationSetup";
|
|
}
|
|
log.Info("Install local synchronization");
|
|
|
|
if (ConnectionType != "")
|
|
{
|
|
string argument = "\"" + StartupFolder + "\"" + " -" + ComputerType + " -" + ConnectionType;
|
|
CreateSyncProcess(syncProgramFolder, argument);
|
|
}
|
|
else
|
|
{
|
|
string argument = StartupFolder + " -" + ComputerType;
|
|
CreateSyncProcess(syncProgramFolder, argument);
|
|
}
|
|
}
|
|
|
|
private void CreateSyncProcess(string folder, string arg)
|
|
{
|
|
Process P2 = new Process();
|
|
P2.StartInfo.FileName = folder + @"\LocalSynchronizationSetup.exe";
|
|
log.Info("Used file: " + folder + @"\LocalSynchronizationSetup.exe");
|
|
P2.StartInfo.Arguments = arg;
|
|
log.Info("Used argument: " + arg);
|
|
try
|
|
{
|
|
P2.Start();
|
|
P2.WaitForExit(); //Warten bis die Anwendung fertig ist
|
|
log.Info("Local synchronization prozess was installed successfully");
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("File(s) could not be found!\n\nPlease contact your\nlocal administrator.",
|
|
"Error!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error,
|
|
MessageBoxDefaultButton.Button1);
|
|
log.Error("File(s) could not be found");
|
|
|
|
Error = true;
|
|
WriteTextToSystemMessage(WriteSelectedOptionsToSystemMessage(), false);
|
|
}
|
|
}
|
|
|
|
private void DelExistingSyncLink()
|
|
{
|
|
log.Info("Delete old synchronization prozesses");
|
|
|
|
if (File.Exists(GetUserprofil() + @"\Start Menu\Programs\Startup\Sync_NX-Portal.lnk"))
|
|
{
|
|
File.Delete(GetUserprofil() + @"\Start Menu\Programs\Startup\Sync_NX-Portal.lnk");
|
|
if (File.Exists(GetUserprofil() + @"\Start Menu\Programs\Startup\Sync_NX-Portal.lnk"))
|
|
{
|
|
log.Warn("Could not delete old NX-Portal synchronizaton prozess.");
|
|
}
|
|
else
|
|
{
|
|
log.Info("Old NX-Portal synchronizaton prozess deleted successfully");
|
|
}
|
|
}
|
|
if (File.Exists(GetUserprofil() + @"\Start Menu\Programs\Startup\Sync_NX_ENVIRONMENT.lnk"))
|
|
{
|
|
File.Delete(GetUserprofil() + @"\Start Menu\Programs\Startup\Sync_NX_ENVIRONMENT.lnk");
|
|
if (File.Exists(GetUserprofil() + @"\Start Menu\Programs\Startup\Sync_NX_ENVIRONMENT.lnk"))
|
|
{
|
|
log.Warn("Coluld not delete old environment synchronizaton prozess");
|
|
}
|
|
else
|
|
{
|
|
log.Info("Old environment synchronizaton prozess deleted successfully");
|
|
}
|
|
}
|
|
}
|
|
|
|
private string GetUserprofil()
|
|
{
|
|
return System.Environment.GetEnvironmentVariable("USERPROFILE");
|
|
}
|
|
|
|
private int DefineArrayLenght(int maxArrayLenght)
|
|
{
|
|
GetTransferParameters gtp = new GetTransferParameters(logfile);
|
|
int arrayLenght = gtp.ArrayLenght() - 1; //Wert mit Aufrufpfad nicht mitrechnen.
|
|
if (maxArrayLenght <= arrayLenght)
|
|
{
|
|
return maxArrayLenght;
|
|
}
|
|
else
|
|
{
|
|
return arrayLenght;
|
|
}
|
|
}
|
|
|
|
private ArrayList TextToArraylist(string Pfad)
|
|
{
|
|
ArrayList Text = new ArrayList();
|
|
System.IO.StreamReader SR = new System.IO.StreamReader(Pfad);
|
|
while (SR.Peek() > -1)
|
|
{
|
|
Text.Add(SR.ReadLine());
|
|
}
|
|
SR.Close();
|
|
return Text;
|
|
}
|
|
|
|
private void WriteTextToSystemMessage(string message, bool warning)
|
|
{
|
|
if (warning)
|
|
{
|
|
this.lblSystemMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
this.lblSystemMessage.ForeColor = System.Drawing.Color.Red;
|
|
this.lblSystemMessage.Text = message;
|
|
log.Warn(message);
|
|
}
|
|
else
|
|
{
|
|
this.lblSystemMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
this.lblSystemMessage.ForeColor = System.Drawing.SystemColors.ControlText;
|
|
this.lblSystemMessage.Text = message;
|
|
}
|
|
}
|
|
|
|
private void SetRadioButtonText(string[] version, int lenghtArrayListVersion)
|
|
{
|
|
|
|
if (3 <= lenghtArrayListVersion)
|
|
{
|
|
this.rdbVersion3.Text = version[2];
|
|
this.rdbVersion3.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
this.rdbVersion3.Text = "";
|
|
this.rdbVersion3.Enabled = false;
|
|
}
|
|
|
|
if (2 <= lenghtArrayListVersion)
|
|
{
|
|
this.rdbVersion2.Text = version[1];
|
|
this.rdbVersion2.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
this.rdbVersion2.Text = "";
|
|
this.rdbVersion2.Enabled = false;
|
|
this.rdbVersion1.Checked = true;
|
|
}
|
|
|
|
if (1 <= lenghtArrayListVersion)
|
|
{
|
|
this.rdbVersion1.Text = version[0];
|
|
}
|
|
else
|
|
{
|
|
this.rdbVersion1.Text = "";
|
|
this.rdbVersion1.Enabled = false;
|
|
WriteTextToSystemMessage("Warning!\n No version information!\n No version information has been found.\n\n Please inform your administrator!", true);
|
|
log.Warn("No version information has been found.");
|
|
}
|
|
}
|
|
|
|
private void SetComboBoxCollection(string[] location)
|
|
{
|
|
this.cbxLocation.Items.AddRange(location);
|
|
this.cbxLocation.SelectedItem = 0;
|
|
Location = this.cbxLocation.Text;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copy an ArrayList to a string array without sorting
|
|
/// </summary>
|
|
/// <param name="lenghtArrayList">Lenght of the Array List</param>
|
|
/// <param name="value">Values in the Array List</param>
|
|
/// <returns></returns>
|
|
private string[] CopyListArrayToStringArray(int lenghtArrayList, ArrayList value)
|
|
{
|
|
string[] location = new string[lenghtArrayList];
|
|
//Daten werden unsortiert übergeben
|
|
//value.Sort();
|
|
value.CopyTo(location);
|
|
return location;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copy an ArrayList to a string array, sort the array and add the value 'Supplier' to the last array position
|
|
/// </summary>
|
|
/// <param name="lenghtArrayList">Lenght of the Array List</param>
|
|
/// <param name="value">Values in the Array List</param>
|
|
/// <param name="addCustomer">If true, then the value 'Customer' will be added at the array end</param>
|
|
/// <returns></returns>
|
|
private string[] CopyListArrayToStringArray(int lenghtArrayList, ArrayList value, bool addCustomer)
|
|
{
|
|
string[] location = new string[lenghtArrayList + 1];
|
|
value.Sort();
|
|
value.CopyTo(location);
|
|
location[lenghtArrayList] = externalPartner;
|
|
return location;
|
|
}
|
|
|
|
public void SetNxVersion(string nxVersion)
|
|
{
|
|
if (nxVersion.StartsWith("nx")) nxVersion = nxVersion.Remove(0, 2);
|
|
if (nxVersion.StartsWith("NX")) nxVersion = nxVersion.Remove(0, 2);
|
|
if (nxVersion.StartsWith(" ")) nxVersion = nxVersion.Remove(0, 1);
|
|
|
|
//'NX_VERSION' setzen
|
|
NxVersion = nxVersion;
|
|
log.Info("Selected NX-Version: " + nxVersion);
|
|
|
|
//'NX_LONG_VERSION' setzen. Wenn die Version keine Nachkommastellen hat, dann ".0" anhängen
|
|
if (nxVersion.Contains("."))
|
|
{
|
|
NxLongVersion = nxVersion;
|
|
}
|
|
else
|
|
{
|
|
NxLongVersion = nxVersion + ".0";
|
|
}
|
|
}
|
|
|
|
public void SetNxDocumentation(string nxDocumentation)
|
|
{
|
|
NxDocumentation = nxDocumentation;
|
|
log.Info("Selected documentaton option: " + nxDocumentation);
|
|
}
|
|
|
|
public void SetLocation(string location)
|
|
{
|
|
Location = location;
|
|
if (Location == externalPartner)
|
|
{
|
|
SetConnectionType("external"); //%CONNECTION_TYPE% setzen
|
|
}
|
|
else
|
|
{
|
|
SetConnectionType("internal"); //%CONNECTION_TYPE% setzen
|
|
}
|
|
log.Info("Selected location: " + Location);
|
|
}
|
|
|
|
private void GetComputerType()
|
|
{
|
|
if (SystemInformation.PowerStatus.BatteryChargeStatus == BatteryChargeStatus.NoSystemBattery)
|
|
{
|
|
//Desktop
|
|
rdbDesktop.Checked = true;
|
|
ComputerType = "Desktop";
|
|
}
|
|
else
|
|
{
|
|
//Laptop
|
|
rdbLaptop.Checked = true;
|
|
ComputerType = "Laptop";
|
|
}
|
|
}
|
|
|
|
public void SetComputerType(string computerType)
|
|
{
|
|
ComputerType = computerType;
|
|
log.Info("Selected computer type: " + computerType);
|
|
}
|
|
|
|
private void SetConnectionType(string connectionType)
|
|
{
|
|
ConnectionType = connectionType;
|
|
log.Info("Used connection type (calculated): " + connectionType);
|
|
}
|
|
|
|
private string GetNxPortalGroup()
|
|
{
|
|
ReadWriteRegistry rwr = new ReadWriteRegistry();
|
|
log.Info("Read NX-Portal Userprofile");
|
|
try
|
|
{
|
|
if (rwr.ReadUserprofileFromRegistry() == "" | rwr.ReadUserprofileFromRegistry() == null)
|
|
{
|
|
log.Info("Used Userprofile: User");
|
|
return "User";
|
|
}
|
|
else
|
|
{
|
|
log.Info("Used Userprofile: " + rwr.ReadUserprofileFromRegistry());
|
|
return rwr.ReadUserprofileFromRegistry();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
log.Info("Used Userprofile: User");
|
|
return "User";
|
|
}
|
|
}
|
|
|
|
private void SetPermanentEnvironmentDirect(string parameter3, string parameter4, string parameter6, string parameter7)
|
|
{
|
|
ReadWriteRegistry rwr = new ReadWriteRegistry();
|
|
log.Info("Set permanent environment");
|
|
rwr.SetLocationToRegistry(parameter3);
|
|
log.Info("Used value: Location=" + parameter3);
|
|
rwr.SetUserprofileToRegistry(parameter4);
|
|
log.Info("Used value: Userprofile=" + parameter4);
|
|
rwr.SetComputerTypeToRegistry(parameter6);
|
|
log.Info("Used value: ComputerType=" + parameter6);
|
|
rwr.SetConnectionTypeToRegistry(parameter7);
|
|
log.Info("Used value: ConnectionType=" + parameter7);
|
|
}
|
|
|
|
private void SetRuntimeEnvironmentDirect(string parameter5, string parameter1, string parameter2, string parameter3, string parameter6, string parameter7)
|
|
{
|
|
//Die folgenden Umgebungsvariablen setzen
|
|
log.Info("Set runtime environment");
|
|
Environment.SetEnvironmentVariable("STARTUP_FOLDER", parameter5);
|
|
log.Info("Used value: STARTUP_FOLDER=" + Environment.GetEnvironmentVariable("STARTUP_FOLDER"));
|
|
Environment.SetEnvironmentVariable("NX_LONG_VERSION", parameter1);
|
|
log.Info("Used value: NX_LONG_VERSION=" + Environment.GetEnvironmentVariable("NX_LONG_VERSION"));
|
|
if (parameter1.Contains("."))
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_VERSION", parameter1.Remove(parameter1.IndexOf(".")));
|
|
log.Info("Used value: NX_VERSION=" + Environment.GetEnvironmentVariable("NX_VERSION"));
|
|
}
|
|
else
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_VERSION", parameter1);
|
|
log.Info("Used value: NX_VERSION=" + Environment.GetEnvironmentVariable("NX_VERSION"));
|
|
}
|
|
Environment.SetEnvironmentVariable("DOKUMENTATION", parameter2);
|
|
log.Info("Used value: DOKUMENTATION=" + Environment.GetEnvironmentVariable("DOKUMENTATION"));
|
|
Environment.SetEnvironmentVariable("LOCATION", parameter3);
|
|
log.Info("Used value: LOCATION=" + Environment.GetEnvironmentVariable("LOCATION"));
|
|
Environment.SetEnvironmentVariable("COMPUTER_TYPE", parameter6);
|
|
log.Info("Used value: COMPUTER_TYPE=" + Environment.GetEnvironmentVariable("COMPUTER_TYPE"));
|
|
Environment.SetEnvironmentVariable("CONNECTION_TYPE", parameter7);
|
|
log.Info("Used value: CONNECTION_TYPE=" + Environment.GetEnvironmentVariable("CONNECTION_TYPE"));
|
|
Environment.SetEnvironmentVariable("COMPSOLV_MACHINE", Platform);
|
|
log.Info("Used value: COMPSOLV_MACHINE=" + Environment.GetEnvironmentVariable("COMPSOLV_MACHINE"));
|
|
}
|
|
|
|
private void SetPermanetEnvironment()
|
|
{
|
|
try
|
|
{
|
|
ReadWriteRegistry rwr = new ReadWriteRegistry();
|
|
log.Info("Set permanent environment");
|
|
rwr.SetLocationToRegistry(Location);
|
|
log.Info("Used value: Location=" + Location);
|
|
rwr.SetUserprofileToRegistry(NxPortalGroup);
|
|
log.Info("Used value: Userprofile=" + NxPortalGroup);
|
|
rwr.SetComputerTypeToRegistry(ComputerType);
|
|
log.Info("Used value: ComputerType=" + ComputerType);
|
|
rwr.SetConnectionTypeToRegistry(ConnectionType);
|
|
log.Info("Used value: ConnectionType=" + ConnectionType);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.Message);
|
|
|
|
MessageBox.Show(ex.Message,
|
|
"Registry error", MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
|
|
private void SetRuntimeEnvironment()
|
|
{
|
|
try
|
|
{
|
|
//Die folgenden Umgebungsvariablen setzen
|
|
log.Info("Set runtime environment");
|
|
Environment.SetEnvironmentVariable("STARTUP_FOLDER", StartupFolder);
|
|
log.Info("Used value: STARTUP_FOLDER=" + Environment.GetEnvironmentVariable("STARTUP_FOLDER"));
|
|
Environment.SetEnvironmentVariable("NX_LONG_VERSION", NxVersion);
|
|
log.Info("Used value: NX_LONG_VERSION=" + Environment.GetEnvironmentVariable("NX_LONG_VERSION")); //z.B.: 7.5
|
|
if (NxVersion.Contains("."))
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_VERSION", NxVersion.Remove(NxVersion.IndexOf(".")));
|
|
NxBaseVersion = Environment.GetEnvironmentVariable("NX_VERSION");
|
|
log.Info("Used value: NX_VERSION=" + Environment.GetEnvironmentVariable("NX_VERSION")); //z.B.: 7
|
|
}
|
|
else
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_VERSION", NxVersion);
|
|
NxBaseVersion = Environment.GetEnvironmentVariable("NX_VERSION");
|
|
log.Info("Used value: NX_VERSION=" + Environment.GetEnvironmentVariable("NX_VERSION"));
|
|
}
|
|
Environment.SetEnvironmentVariable("DOKUMENTATION", NxDocumentation); //'STANDALONE' oder 'NETWORK'
|
|
log.Info("Used value: DOKUMENTATION=" + Environment.GetEnvironmentVariable("DOKUMENTATION"));
|
|
Environment.SetEnvironmentVariable("LOCATION", Location);
|
|
log.Info("Used value: LOCATION=" + Environment.GetEnvironmentVariable("LOCATION"));
|
|
Environment.SetEnvironmentVariable("COMPUTER_TYPE", ComputerType); // 'Desktop' oder 'Laptop'
|
|
log.Info("Used value: COMPUTER_TYPE=" + Environment.GetEnvironmentVariable("COMPUTER_TYPE"));
|
|
Environment.SetEnvironmentVariable("CONNECTION_TYPE", ConnectionType); //'internal' oder 'external'
|
|
log.Info("Used value: CONNECTION_TYPE=" + Environment.GetEnvironmentVariable("CONNECTION_TYPE"));
|
|
Environment.SetEnvironmentVariable("COMPSOLV_MACHINE", Platform);
|
|
log.Info("Used value: COMPSOLV_MACHINE=" + Environment.GetEnvironmentVariable("COMPSOLV_MACHINE"));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.Message);
|
|
|
|
MessageBox.Show("Error: " + ex.Message,
|
|
Application.ProductName, MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
|
|
private void StartInstallationProzess(string messageText)
|
|
{
|
|
SetInstallationRelevantRuntimeEnvironment();
|
|
|
|
//Überprüfen ob genug Platz auf der Festplatte ist
|
|
EvaluateDiscSpace();
|
|
|
|
PerformInstallation(messageText);
|
|
}
|
|
|
|
private void SetInstallationRelevantRuntimeEnvironment()
|
|
{
|
|
//Beispielbelegung der Umgebungsvariablen
|
|
// STARTUP_FOLDER (%STARTUP_FOLDER%): \\EMSFILE1.ENGEL.INT\VOL1\IT-EC\homedir\001142709\NX_PRODUCTIVE
|
|
// NX Version (%NX_LONG_VERSION%): 7.5
|
|
// NX Version (Base version (%NX_VERSION%)): 7
|
|
// NX Verson (Short version (%NX_SHORT_VERSION%)): 75
|
|
// NX Version (Short 0 version (%NX_SHORT0_VERSION%)): 075
|
|
// Location (%LOCATION%)): Schwertberg
|
|
// NX_PRODUCTIVE folder location (%NX_ONLINE%): \\EMSFILE1.ENGEL.INT\VOL1\IT-EC\homedir\001142709\NX_PRODUCTIVE
|
|
// License server (%UGS_LICENSE_SERVER%): 28000@EMSCADLIC.engel.int
|
|
// License bundle (%UGS_LICENSE_BUNDLE%): NX Mach 1 Design (Floating), NX Mach 3 Design
|
|
// Default Regfile (%DEFAULT_REGFILE%): \\EMSFILE1.ENGEL.INT\VOL1\IT-EC\homedir\001142709\NX_PRODUCTIVE\NX-Portal\Schwertberg\SetDefault_NX10.reg
|
|
// UGII_BASE_DIR (%UGII_BASE_DIR%): C:\CAD\NX10
|
|
// UGII_ROOT_DIR (%UGII_ROOT_DIR%): C:\CAD\NX10\UGII\
|
|
// Language (%UGII_LANG%): english
|
|
// UGII_TMP_DIR (%UGII_TMP_DIR%): C:\TEMP
|
|
// NX Installation Logfile (%NX_INSTALL_LOGFILE%): C:\CAD\Logfiles\NX10_Install.log
|
|
// NX Doc Installation Logfile (%NX_INSTALL_DOC_LOGFILE%): C:\CAD\Logfiles\NX10_Doc_Install.log
|
|
// UG Tools Installation directory (%UGTOOLS_INSTALL_DIR%): "C:\CAD\UG-Tools"
|
|
|
|
//NX_SHORT_VERSION
|
|
if (Environment.GetEnvironmentVariable("NX_LONG_VERSION").Contains("."))
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_SHORT_VERSION", Environment.GetEnvironmentVariable("NX_LONG_VERSION").Replace(".", ""));
|
|
NxShortVersion = Environment.GetEnvironmentVariable("NX_SHORT_VERSION");
|
|
log.Info("Used value: NX_SHORT_VERSION=" + Environment.GetEnvironmentVariable("NX_SHORT_VERSION")); //z.B.: 75 bei Version 7.5
|
|
}
|
|
else if (Environment.GetEnvironmentVariable("NX_LONG_VERSION") == Environment.GetEnvironmentVariable("NX_VERSION"))
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_SHORT_VERSION", Environment.GetEnvironmentVariable("NX_LONG_VERSION") + "0");
|
|
NxShortVersion = Environment.GetEnvironmentVariable("NX_SHORT_VERSION");
|
|
log.Info("Used value: NX_SHORT_VERSION=" + Environment.GetEnvironmentVariable("NX_SHORT_VERSION")); //z.B.: 70
|
|
}
|
|
|
|
//NX_SHORT0_VERSION
|
|
if (Convert.ToInt32(Environment.GetEnvironmentVariable("NX_SHORT_VERSION")) < 100)
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_SHORT0_VERSION", "0" + Environment.GetEnvironmentVariable("NX_SHORT_VERSION"));
|
|
NxShort0Version = Environment.GetEnvironmentVariable("NX_SHORT0_VERSION");
|
|
log.Info("Used value: NX_SHORT0_VERSION=" + Environment.GetEnvironmentVariable("NX_SHORT0_VERSION")); //z.B.: 075 bei Version 7.5. Führende Null, wenn Vorkommastelle einstellig
|
|
}
|
|
else
|
|
{
|
|
Environment.SetEnvironmentVariable("NX_SHORT0_VERSION", Environment.GetEnvironmentVariable("NX_SHORT_VERSION"));
|
|
NxShort0Version = Environment.GetEnvironmentVariable("NX_SHORT0_VERSION");
|
|
log.Info("Used value: NX_SHORT0_VERSION=" + Environment.GetEnvironmentVariable("NX_SHORT0_VERSION")); //z.B.: 125
|
|
}
|
|
|
|
//NX_INSTALL_DIR
|
|
int pos = ReadNxVersionPosition(Location); //Position der NX Version in der 'NX-Portal.ini' ermitteln
|
|
|
|
if (pos != 0)
|
|
{
|
|
try
|
|
{
|
|
GetSystemEnvironmentValues();
|
|
GetUserEnvironmentValues(pos);
|
|
}
|
|
catch
|
|
{
|
|
log.Error("Was not able to create the necessary environment");
|
|
|
|
MessageBox.Show("Error:\n\nWas not able to create\nthe necessary environment.\n\nPlease inform your administrator!",
|
|
Application.ProductName, MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
try
|
|
{
|
|
SetSystemEnvironmentToRegistry();
|
|
SetUserEnvironmentToRegistry();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.Message);
|
|
|
|
MessageBox.Show("Error: " + ex.Message + "\n\nPlease inform your administrator!",
|
|
Application.ProductName, MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Information missing!\n\nCan not read necessary information.\n\nPlease inform your administrator!",
|
|
"Error!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error,
|
|
MessageBoxDefaultButton.Button1);
|
|
log.Error("Unable to read necessary position info (NX-Version) in file " + StartupFolder + @"\NX-Portal\" + Location + @"\NX-Portal.ini");
|
|
|
|
Environment.Exit(0);
|
|
}
|
|
|
|
SetLogFiles();
|
|
SetInstallationFiles();
|
|
}
|
|
|
|
private void EvaluateDiscSpace()
|
|
{
|
|
log.Info("Evaluate free disk space on drive C:");
|
|
|
|
//Pfad für NX-Installationsverzeichnisse ermitteln
|
|
log.Info("Determine NX installation files path");
|
|
|
|
string nxInstallFolder = NxMsi.Remove(NxMsi.LastIndexOf("\\"));
|
|
nxInstallFolder = nxInstallFolder.Remove(nxInstallFolder.LastIndexOf("\\"));
|
|
|
|
log.Info("Used value: " + nxInstallFolder);
|
|
|
|
//Pfad für NX-Documentation-Installationsverzeichnisse ermitteln
|
|
log.Info("Determine NX-Documentation installation files path");
|
|
|
|
string nxDocInstallFolder = NxDocMsi.Remove(NxDocMsi.LastIndexOf("\\"));
|
|
nxDocInstallFolder = nxDocInstallFolder.Remove(nxDocInstallFolder.LastIndexOf("\\"));
|
|
|
|
//Für NX Vesionen vor NX9 noch eine Stufe höher gehen
|
|
if (Convert.ToInt32(NxBaseVersion) < 9) nxDocInstallFolder = nxDocInstallFolder.Remove(nxDocInstallFolder.LastIndexOf("\\"));
|
|
|
|
log.Info("Used value: " + nxDocInstallFolder);
|
|
|
|
//Freien Platz evaluieren
|
|
EvaluateFreeDiskSpace efds = new EvaluateFreeDiskSpace(logfile);
|
|
|
|
if (efds.EvaluateDiskSpace(nxInstallFolder, nxDocInstallFolder, NxDocumentation == "STANDALONE"))
|
|
{
|
|
Environment.Exit(0); //Wenn zu wenig Speicher frei oder wenn ein Fehler aufgetreten ist dann beenden.
|
|
}
|
|
}
|
|
|
|
private void PerformInstallation(string messageText)
|
|
{
|
|
//Wenn Verzeichnis für Logfiles nicht existiert, dann anlegen
|
|
ExistLogfileDir(NxInstallLogFile);
|
|
|
|
//Spacemouse korrigieren
|
|
//CorrectSpacemouse();
|
|
|
|
//NX installieren
|
|
PerformNxInstallation(messageText);
|
|
|
|
//NX-Doku installieren
|
|
if (!Error)
|
|
{
|
|
if (NxDocumentation == "STANDALONE")
|
|
{
|
|
PerformNxDocuInstallation();
|
|
}
|
|
}
|
|
|
|
//NX-Update
|
|
if (!Error)
|
|
{
|
|
PerformNxUpdate();
|
|
}
|
|
|
|
//UG-Tools installiern
|
|
if (!Error)
|
|
{
|
|
PerformNxToolsInstallation();
|
|
}
|
|
|
|
//NX-Portal installiern
|
|
if (!Error)
|
|
{
|
|
PerformNxPortalInstallation(messageText);
|
|
}
|
|
|
|
//Zusätzliche NX-Tools installieren
|
|
if (!Error)
|
|
{
|
|
PerformAdditionalToolsInstallation();
|
|
}
|
|
|
|
CancelUncEnable(); //Registry Werte wieder zurücksetzen
|
|
|
|
//Erfolgreichen Installatiosprozess protokolliern
|
|
if (!Error)
|
|
{
|
|
MessageBox.Show("Installation finished!\n\nThank you for your patience.",
|
|
"Information!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information,
|
|
MessageBoxDefaultButton.Button1);
|
|
log.Info(line);
|
|
log.Info("Installation finished successfully");
|
|
log.Info(line);
|
|
}
|
|
this.Close(); //Programm beenden
|
|
}
|
|
|
|
private void ExistLogfileDirNX(string NxInstallLogFile)
|
|
{
|
|
//Wenn Verzeichnis für Logfiles nicht existiert, dann anlegen
|
|
string logfileDir = NxInstallLogFile.Remove(NxInstallLogFile.LastIndexOf("\\"));
|
|
if (!Directory.Exists(logfileDir)) Directory.CreateDirectory(logfileDir);
|
|
}
|
|
|
|
private void CorrectSpacemouse()
|
|
{
|
|
try
|
|
{
|
|
//Wenn Win Vista oder neuer, dann Spacemouse korrigieren
|
|
if (CheckWinVersion()) SpacemouseInstalled();
|
|
log.Info("Corrected 3D mouse installation");
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("Was not able to correct\n3D mouse installation!\n\nPlease contact your\nlocal administrator.",
|
|
"Warning!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Warning,
|
|
MessageBoxDefaultButton.Button1);
|
|
log.Warn("Was not able to correct 3D mouse installation");
|
|
}
|
|
}
|
|
|
|
private bool CheckWinVersion()
|
|
{
|
|
//Überprüfen ob Windows Vista oder neuer
|
|
bool newerThanXP = true;
|
|
|
|
switch (WindowsVersion)
|
|
{
|
|
case "WindowsXP":
|
|
newerThanXP = false;
|
|
break;
|
|
case "WindowsXP_64":
|
|
newerThanXP = false;
|
|
break;
|
|
case "WindowsServer2003":
|
|
newerThanXP = false;
|
|
break;
|
|
case "Unknown":
|
|
newerThanXP = false;
|
|
break;
|
|
}
|
|
|
|
return newerThanXP;
|
|
}
|
|
|
|
private void SpacemouseInstalled()
|
|
{
|
|
//Wenn eine Spacemouse installiert ist, dann wird ein Scheduled Task erzeugt, über den beim Login der Spacemouseserver mit Admin-Rechten gestartet wird
|
|
Task t = new Task();
|
|
t.CreateLoginTask(Platform);
|
|
}
|
|
|
|
private void PerformNxInstallation(string messageText)
|
|
{
|
|
messageText += "\n Installing NX...";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
|
|
string args = "/i \"" + NxMsi + "\" /qb /norestart /log \"" + NxInstallLogFile + "\" ADDLOCAL=\"all\" SETUPTYPE=\"typical\" LICENSESERVER=" + UgsLicenseServer + " LANGUAGE=ENGLISH INSTALLDIR=\"" + UgiiBaseDir + "\"";
|
|
InstallationProcess("msiexec.exe", args, "Run NX installation");
|
|
//InstallationProcess("msiexec.exe", args, messageText);
|
|
}
|
|
|
|
private void PerformNxDocuInstallation()
|
|
{
|
|
string args = "/i \"" + NxDocMsi + "\" /qb /norestart /log \"" + NxDocInstallLogFile + "\" INSTALLDIR=\"" + UgiiBaseDir + "\"";
|
|
InstallationProcess("msiexec.exe", args, "Run NX-Docu installation");
|
|
}
|
|
|
|
private void PerformNxUpdate()
|
|
{
|
|
string args = "-autorun -ugii_base_dir=\"" + UgiiBaseDir + "\"";
|
|
InstallationProcess(NxUpdateTool, args, "Run NX-Update");
|
|
}
|
|
|
|
private void PerformNxToolsInstallation()
|
|
{
|
|
//- Früher wurde das Verzeichnis 'UgToolsDir' ins Verzeichnis 'NxInstallDir' kopiert.
|
|
//- Heute wird, wenn es erlaubt ist, auf den Server gezeigt und von dort ausgeführt.
|
|
// Auf Laptops kann das Verzeichnis 'UgToolsDir' auch synchronisiert werden, dann stehen die UGtools auch offline zur Verfügung.
|
|
}
|
|
|
|
private void PerformNxPortalInstallation(string messageText)
|
|
{
|
|
messageText += " ... Done\n Installing NX-Portal...";
|
|
WriteTextToSystemMessage(messageText, false);
|
|
this.Refresh();
|
|
|
|
int groupNumber = 3;
|
|
|
|
switch (NxPortalGroup)
|
|
{
|
|
case "Administrator":
|
|
groupNumber = 0;
|
|
break;
|
|
case "Mainuser":
|
|
groupNumber = 1;
|
|
break;
|
|
case "User":
|
|
groupNumber = 2;
|
|
break;
|
|
case "Guest":
|
|
groupNumber = 3;
|
|
break;
|
|
}
|
|
|
|
string args = groupNumber + " /d";
|
|
InstallationProcess(NxPortalInstaller, args, "Run NX-Portal installation");
|
|
}
|
|
|
|
private void PerformAdditionalToolsInstallation()
|
|
{
|
|
string source = StartupFolder + @"\NX_ENVIRONMENT\NX" + NxBaseVersion + @"\NX_APPS\COMPSOLV_TOOLS\tools\ZipAssembly\Zip Assembly.lnk";
|
|
|
|
string destination = "";
|
|
if (WindowsVersion != "WindowsXP" & WindowsVersion != "WindowsServer2003" & WindowsVersion != "WindowsXP_64")
|
|
{
|
|
//neuer Pfad
|
|
destination = System.Environment.GetEnvironmentVariable("ALLUSERSPROFILE") + @"\Microsoft\Windows\Start Menu\Programs\" + NxInstallDir.Remove(0, NxInstallDir.LastIndexOf("\\") + 1) + " NX " + NxVersion + @"\NX Tools\Zip Assembly.lnk";
|
|
}
|
|
else
|
|
{
|
|
//alter Pfad
|
|
destination = System.Environment.GetEnvironmentVariable("ALLUSERSPROFILE") + @"\Start Menu\Programs\" + NxInstallDir.Remove(0, NxInstallDir.LastIndexOf("\\") + 1) + " NX " + NxVersion + @"\NX Tools\Zip Assembly.lnk";
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!Directory.Exists(destination.Remove(destination.LastIndexOf("\\"))))
|
|
{
|
|
Directory.CreateDirectory(destination.Remove(destination.LastIndexOf("\\")));
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
log.Error("Was not able to create a necessary directory");
|
|
}
|
|
|
|
try
|
|
{
|
|
File.Copy(source, destination, true);
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("Was not able to copy additional tools!\n\nPlease contact your\nlocal administrator.",
|
|
"Error!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error,
|
|
MessageBoxDefaultButton.Button1);
|
|
log.Error("Was not able to copy additional tools");
|
|
|
|
WriteTextToSystemMessage(WriteSelectedOptionsToSystemMessage(), false);
|
|
}
|
|
}
|
|
|
|
private void InstallationProcess(string program, string args, string messageText)
|
|
{
|
|
Process P2 = new Process();
|
|
ResolveMessage(messageText);
|
|
P2.StartInfo.FileName = "\"" + program + "\"";
|
|
P2.StartInfo.Arguments = args;
|
|
log.Info("Used command: " + program + " " + args);
|
|
if (System.Environment.OSVersion.Version.Major >= 6)
|
|
{
|
|
P2.StartInfo.Verb = "runas";
|
|
log.Info("Used Process verb: runas");
|
|
}
|
|
|
|
try
|
|
{
|
|
P2.Start();
|
|
P2.WaitForExit(); //Warten bis die Anwendung fertig ist
|
|
|
|
log.Info(messageText + " successfully");
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("Was not able to finish the installation!\n\nPlease contact your\nlocal administrator.",
|
|
"Error!",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error,
|
|
MessageBoxDefaultButton.Button1);
|
|
log.Error("Installation could not finished");
|
|
|
|
Error = true;
|
|
WriteTextToSystemMessage(WriteSelectedOptionsToSystemMessage(), false);
|
|
}
|
|
}
|
|
|
|
private void ResolveMessage(string messageText)
|
|
{
|
|
string tempMessage = messageText;
|
|
string partMessage = "";
|
|
while (tempMessage.Contains("\n"))
|
|
{
|
|
partMessage = tempMessage.Remove(tempMessage.IndexOf("\n"));
|
|
tempMessage = tempMessage.Remove(0, tempMessage.IndexOf("\n") + 4);
|
|
log.Info(partMessage);
|
|
}
|
|
log.Info(tempMessage);
|
|
}
|
|
|
|
private void GetSystemEnvironmentValues()
|
|
{
|
|
// NX_ONLINE --> SystemENV
|
|
NxOnline = ReadNxOnline(Location);
|
|
log.Info("Used value: NX_ONLINE=" + NxOnline);
|
|
|
|
// NX_OFFLINE --> SystemENV
|
|
NxOffline = ReadNxOffline(Location);
|
|
log.Info("Used value: NX_OFFLINE=" + NxOffline);
|
|
}
|
|
|
|
private void SetSystemEnvironmentToRegistry()
|
|
{
|
|
ReadWriteRegistry rwr = new ReadWriteRegistry();
|
|
|
|
rwr.SetNxOnlineToRegistry(NxOnline);
|
|
log.Info("Write values into Registry");
|
|
log.Info("Used value: NX_ONLINE=" + NxOnline);
|
|
|
|
rwr.SetNxOfflineToRegistry(NxOffline);
|
|
log.Info("Used value: NX_OFFLINE=" + NxOffline);
|
|
}
|
|
|
|
private void GetUserEnvironmentValues(int pos)
|
|
{
|
|
//NX_INSTALL_DIR
|
|
NxInstallDir = ReadInstallDir(Location, pos);
|
|
log.Info("Used value: NX_INSTALL_DIR=" + NxInstallDir);
|
|
|
|
//UGS_LICENSE_SERVER --> UserENV
|
|
UgsLicenseServer = ReadUgsLicenseServer(Location, pos);
|
|
log.Info("Used value: UGS_LICENSE_SERVER=" + UgsLicenseServer);
|
|
|
|
//UGS_LICENSE_BUNDLE --> UserENV
|
|
UgsLicenseBundle = ReadUgsLicenseBundle(Location, pos);
|
|
log.Info("Used value: UGS_LICENSE_BUNDLE=" + UgsLicenseBundle);
|
|
|
|
//UGII_BASE_DIR --> UserENV
|
|
UgiiBaseDir = ReadUgiiBaseDir(Location, pos);
|
|
log.Info("Used value: UGII_BASE_DIR=" + UgiiBaseDir);
|
|
|
|
//UGII_ROOT_DIR --> UserENV
|
|
UgiiRootDir = UgiiBaseDir + @"\UGII\";
|
|
log.Info("Used value: UGII_ROOT_DIR=" + UgiiRootDir);
|
|
|
|
//UGII_LANG --> UserENV
|
|
UgiiLang = ReadUgiiLang(Location, pos);
|
|
log.Info("Used value: UGII_LANG=" + UgiiLang);
|
|
|
|
//UGII_MAX_FIT_BOX_SIZE --> UserENV
|
|
log.Info("Used value: UGII_MAX_FIT_BOX_SIZE=" + MaxFitBoxSize); //Wird unter den globalen Variablen gesetzt
|
|
|
|
//JAVA_HOME
|
|
JavaHome = UgiiBaseDir + @"\NXJRE";
|
|
log.Info("Used value: JAVA_HOME=" + JavaHome);
|
|
|
|
//UGII_TMP_DIR --> UserENV
|
|
UgiiTmpDir = @"C:\TMP";
|
|
log.Info("Used value: UGII_TMP_DIR=" + UgiiTmpDir);
|
|
|
|
//UGTOOLS_INSTALL_DIR
|
|
UgToolsDir = NxInstallDir;
|
|
log.Info("Used value: UGTOOLS_INSTALL_DIR=" + UgToolsDir);
|
|
}
|
|
|
|
private void SetUserEnvironmentToRegistry()
|
|
{
|
|
ReadWriteRegistry rwr = new ReadWriteRegistry();
|
|
|
|
rwr.SetUgsLicenseServerToRegistry(UgsLicenseServer);
|
|
log.Info("Used value: UGS_LICENSE_SERVER=" + UgsLicenseServer);
|
|
|
|
rwr.SetUgsLicenseBundleToRegistry(UgsLicenseBundle);
|
|
log.Info("Used value: UGS_LICENSE_BUNDLE=" + UgsLicenseBundle);
|
|
|
|
rwr.SetUgiiBaseDirToRegistry(UgiiBaseDir);
|
|
log.Info("Used value: UGII_BASE_DIR=" + UgiiBaseDir);
|
|
|
|
rwr.SetUgiiRootDirToRegistry(UgiiRootDir);
|
|
log.Info("Used value: UGII_ROOT_DIR=" + UgiiRootDir);
|
|
|
|
rwr.SetUgiiLangToRegistry(UgiiLang);
|
|
log.Info("Used value: UGII_LANG=" + UgiiLang);
|
|
|
|
rwr.SetMaxFitBoxSizeToRegistry(Convert.ToString(MaxFitBoxSize));
|
|
log.Info("Used value: UGII_MAX_FIT_BOX_SIZE=" + MaxFitBoxSize);
|
|
|
|
rwr.SetJavaHomeToRegistry(JavaHome);
|
|
log.Info("Used value: JAVA_HOME=" + JavaHome);
|
|
|
|
rwr.SetUgiiTmpDirToRegistry(UgiiTmpDir);
|
|
log.Info("Used value: UGII_TMP_DIR=" + UgiiTmpDir);
|
|
}
|
|
|
|
private void SetLogFiles()
|
|
{
|
|
//NX_INSTALL_LOGFILE
|
|
NxInstallLogFile = @"C:\TEMP\Logfiles\NX" + NxVersion + "_Install.log";
|
|
log.Info("Set installation logfiles");
|
|
log.Info("Used value: NX_INSTALL_LOGFILE=" + NxInstallLogFile);
|
|
|
|
//NX_INSTALL_DOC_LOGFILE
|
|
NxDocInstallLogFile = @"C:\TEMP\Logfiles\NX" + NxVersion + "_Doc_Install.log";
|
|
log.Info("Used value: NX_INSTALL_DOC_LOGFILE=" + NxDocInstallLogFile);
|
|
}
|
|
|
|
private void SetInstallationFiles()
|
|
{
|
|
string factoryCode = "Siemens";
|
|
if ((Convert.ToInt32(NxBaseVersion)) < 8) factoryCode = "UGS";
|
|
|
|
//NX_MSI
|
|
NxMsi = StartupFolder + @"\NXupdate\NX" + NxLongVersion + @"\basis_nx";
|
|
if (NxShortVersion.EndsWith("0"))
|
|
{
|
|
NxMsi += NxShort0Version + @"\nx" + NxShort0Version + @"\" + factoryCode + " NX " + NxLongVersion + ".msi";
|
|
}
|
|
else
|
|
{
|
|
NxMsi += NxShortVersion + "-" + Platform + @"\nx" + NxShort0Version + @"\" + factoryCode + " NX " + NxLongVersion + ".msi";
|
|
}
|
|
log.Info("Used NX installation file: " + NxMsi);
|
|
|
|
//NX_DOC_MSI
|
|
if (Convert.ToInt32(NxBaseVersion) >= 9)
|
|
{
|
|
NxDocMsi = StartupFolder + @"\NXupdate\NX" + NxLongVersion + @"\basis_nx";
|
|
if (NxShortVersion.EndsWith("0"))
|
|
{
|
|
NxDocMsi += NxShort0Version + @"-ugdoc\win64\ugdoc" + NxShort0Version + @"\" + factoryCode + " NX " + NxLongVersion + " Documentation.msi";
|
|
}
|
|
else
|
|
{
|
|
NxDocMsi += NxShortVersion + @"-ugdoc\win64\ugdoc" + NxShort0Version + @"\" + factoryCode + " NX " + NxLongVersion + " Documentation.msi";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NxDocMsi = StartupFolder + @"\NXupdate\NX" + NxBaseVersion + @"_64bit-updates\basis_nx";
|
|
if (NxShortVersion.EndsWith("0"))
|
|
{
|
|
NxDocMsi += NxShortVersion.Remove(NxShortVersion.LastIndexOf("0")) + @"-ugdoc\win" + Platform.Replace("bit", "") + @"\ugdoc" + NxShort0Version + @"\" + factoryCode + " NX " + NxLongVersion + " Documentation.msi";
|
|
}
|
|
else
|
|
{
|
|
NxDocMsi += NxShortVersion + @"-ugdoc\win" + Platform.Replace("bit", "") + @"\ugdoc" + NxShort0Version + @"\" + factoryCode + " NX " + NxLongVersion + " Documentation.msi";
|
|
}
|
|
}
|
|
log.Info("Used NX documentation installation file: " + NxDocMsi);
|
|
|
|
//NX-Update-Tool
|
|
NxUpdateTool = StartupFolder + @"\NXupdate\NXupdate.exe";
|
|
log.Info("Used NX-Update installation file: " + NxUpdateTool);
|
|
|
|
//UG-Tools
|
|
UgToolsDir = StartupFolder + @"\UGTools\NX" + NxBaseVersion + "_" + Platform;
|
|
log.Info("Used UG-Tools installation directory: " + UgToolsDir);
|
|
|
|
//NX-Portal
|
|
NxPortalInstaller = StartupFolder + @"\NX-Portal\" + Location + @"\Install_NX-Portal.bat";
|
|
log.Info("Used NX-Portal installation file: " + NxPortalInstaller);
|
|
}
|
|
|
|
private int ReadNxVersionPosition(string location)
|
|
{
|
|
int position = 0;
|
|
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
for (int i = 1; i < 4; i++)
|
|
{
|
|
try
|
|
{
|
|
if (ri.IniReadValue("NX_VERSION", "Version" + i) == "NX " + NxVersion)
|
|
//if (ri.IniReadValue("NX_VERSION", "Version" + i) == Environment.GetEnvironmentVariable("NX_LONG_VERSION"))
|
|
{
|
|
position = i;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Error(ex.Message);
|
|
|
|
MessageBox.Show("Error: " + ex.Message,
|
|
Application.ProductName, MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
return position;
|
|
}
|
|
|
|
private string ReadInstallDir(string location, int pos)
|
|
{
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
string path = ri.IniReadValue("ENV_Version" + pos, "UGII_BASE_DIR");
|
|
return path.Remove(path.LastIndexOf("\\"));
|
|
}
|
|
|
|
private string ReadUgsLicenseServer(string location, int pos)
|
|
{
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
return ri.IniReadValue("ENV_Version" + pos, "UGS_LICENSE_SERVER");
|
|
}
|
|
|
|
private string ReadUgsLicenseBundle(string location, int pos)
|
|
{
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
return ri.IniReadValue("ENV_Version" + pos, "UGS_LICENSE_BUNDLE");
|
|
}
|
|
|
|
private string ReadUgiiBaseDir(string location, int pos)
|
|
{
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
return ri.IniReadValue("ENV_Version" + pos, "UGII_BASE_DIR");
|
|
}
|
|
|
|
private string ReadUgiiLang(string location, int pos)
|
|
{
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
return ri.IniReadValue("ENV_Version" + pos, "UGII_LANG");
|
|
}
|
|
|
|
private string ReadNxOnline(string location)
|
|
|
|
{
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
return ri.IniReadValue("NX_BASE_ENV", "NX_ONLINE");
|
|
}
|
|
|
|
private string ReadNxOffline(string location)
|
|
{
|
|
ReadWriteINI ri = new ReadWriteINI();
|
|
ri.IniFile(StartupFolder + @"\NX-Portal\" + location + @"\NX-Portal.ini");
|
|
|
|
return ri.IniReadValue("NX_BASE_ENV", "NX_OFFLINE");
|
|
}
|
|
}
|
|
}
|