diff --git a/NxVersion/Form1.Designer.cs b/NxVersion/Form1.Designer.cs
index 5179d20..8d99227 100644
--- a/NxVersion/Form1.Designer.cs
+++ b/NxVersion/Form1.Designer.cs
@@ -28,13 +28,102 @@
///
private void InitializeComponent()
{
- this.components = new System.ComponentModel.Container();
+ this.buttonStart = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.groupBoxBaseDir = new System.Windows.Forms.GroupBox();
+ this.textBoxBaseDir = new System.Windows.Forms.TextBox();
+ this.groupBoxVerInfo = new System.Windows.Forms.GroupBox();
+ this.labelVerInfo = new System.Windows.Forms.Label();
+ this.groupBoxBaseDir.SuspendLayout();
+ this.groupBoxVerInfo.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // buttonStart
+ //
+ this.buttonStart.Location = new System.Drawing.Point(12, 484);
+ this.buttonStart.Name = "buttonStart";
+ this.buttonStart.Size = new System.Drawing.Size(75, 23);
+ this.buttonStart.TabIndex = 0;
+ this.buttonStart.Text = "Start";
+ this.buttonStart.UseVisualStyleBackColor = true;
+ this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(505, 484);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 1;
+ this.buttonCancel.Text = "Cancel";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // groupBoxBaseDir
+ //
+ this.groupBoxBaseDir.Controls.Add(this.textBoxBaseDir);
+ this.groupBoxBaseDir.Location = new System.Drawing.Point(12, 13);
+ this.groupBoxBaseDir.Name = "groupBoxBaseDir";
+ this.groupBoxBaseDir.Size = new System.Drawing.Size(568, 49);
+ this.groupBoxBaseDir.TabIndex = 2;
+ this.groupBoxBaseDir.TabStop = false;
+ this.groupBoxBaseDir.Text = "UGII_BASE_DIR";
+ //
+ // textBoxBaseDir
+ //
+ this.textBoxBaseDir.Location = new System.Drawing.Point(7, 20);
+ this.textBoxBaseDir.Name = "textBoxBaseDir";
+ this.textBoxBaseDir.Size = new System.Drawing.Size(555, 20);
+ this.textBoxBaseDir.TabIndex = 0;
+ this.textBoxBaseDir.Text = "C:\\CAD\\NX";
+ this.textBoxBaseDir.TextChanged += new System.EventHandler(this.textBoxBaseDir_TextChanged);
+ //
+ // groupBoxVerInfo
+ //
+ this.groupBoxVerInfo.Controls.Add(this.labelVerInfo);
+ this.groupBoxVerInfo.Location = new System.Drawing.Point(12, 69);
+ this.groupBoxVerInfo.Name = "groupBoxVerInfo";
+ this.groupBoxVerInfo.Size = new System.Drawing.Size(568, 409);
+ this.groupBoxVerInfo.TabIndex = 3;
+ this.groupBoxVerInfo.TabStop = false;
+ this.groupBoxVerInfo.Text = "Versionsinformationen";
+ //
+ // labelVerInfo
+ //
+ this.labelVerInfo.AutoSize = true;
+ this.labelVerInfo.Location = new System.Drawing.Point(7, 20);
+ this.labelVerInfo.Name = "labelVerInfo";
+ this.labelVerInfo.Size = new System.Drawing.Size(16, 13);
+ this.labelVerInfo.TabIndex = 0;
+ this.labelVerInfo.Text = "...";
+ //
+ // Form1
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
+ this.ClientSize = new System.Drawing.Size(592, 519);
+ this.Controls.Add(this.groupBoxVerInfo);
+ this.Controls.Add(this.groupBoxBaseDir);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonStart);
+ this.Name = "Form1";
this.Text = "Form1";
+ this.Load += new System.EventHandler(this.Form1_Load);
+ this.groupBoxBaseDir.ResumeLayout(false);
+ this.groupBoxBaseDir.PerformLayout();
+ this.groupBoxVerInfo.ResumeLayout(false);
+ this.groupBoxVerInfo.PerformLayout();
+ this.ResumeLayout(false);
+
}
#endregion
+
+ private System.Windows.Forms.Button buttonStart;
+ private System.Windows.Forms.Button buttonCancel;
+ private System.Windows.Forms.GroupBox groupBoxBaseDir;
+ private System.Windows.Forms.TextBox textBoxBaseDir;
+ private System.Windows.Forms.GroupBox groupBoxVerInfo;
+ private System.Windows.Forms.Label labelVerInfo;
}
}
diff --git a/NxVersion/Form1.cs b/NxVersion/Form1.cs
index 854df18..1d80480 100644
--- a/NxVersion/Form1.cs
+++ b/NxVersion/Form1.cs
@@ -1,11 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.IO;
using System.Windows.Forms;
namespace NxVersion
@@ -16,5 +10,146 @@ namespace NxVersion
{
InitializeComponent();
}
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+ if (Directory.Exists(textBoxBaseDir.Text))
+ {
+ UgiiBaseDir = textBoxBaseDir.Text;
+ UgiiRootDir = String.Concat(UgiiBaseDir, "\\UGII\\");
+ }
+ else
+ {
+ labelVerInfo.Text = "ACHTUNG:\nDas angegebene NX Installationsverzeichnis ist ungültig!";
+ }
+ }
+
+ string UgiiBaseDir { set; get; }
+ string UgiiRootDir { set; get; }
+
+ private void buttonStart_Click(object sender, EventArgs e)
+ {
+ Start(UgiiBaseDir);
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+ private void textBoxBaseDir_TextChanged(object sender, EventArgs e)
+ {
+ UgiiBaseDir = textBoxBaseDir.Text;
+ }
+
+ private void Start(string ugiiBaseDir)
+ {
+ ShowInfo(ugiiBaseDir);
+ }
+
+ private void ShowInfo(string ugiiBaseDir)
+ {
+ try
+ {
+ var nxVersion = new NxVersion(ugiiBaseDir);
+
+ labelVerInfo.Text = String.Concat("UGII_BASE_DIR: ", ugiiBaseDir, "\n", "UGII_ROOT_DIR: ", UgiiRootDir, "\n\n");
+
+ if (nxVersion.PostNX12)
+ {
+ //Nach NX12
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "Version: ", nxVersion.UgiiProductName, " ", nxVersion.UgiiMajorVersion, ".", nxVersion.UgiiMinorVersion);
+ }
+ else
+ {
+ //Vor NX
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "Version: ", nxVersion.UgiiProductName, " ", nxVersion.UgiiMajorVersion, ".", nxVersion.UgiiMinorVersion, ".", nxVersion.UgiiSubminorVersion, ".", nxVersion.NXphase, " ", nxVersion.MaintenancePack);
+ }
+
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\nPostNX12: ", nxVersion.PostNX12.ToString());
+
+ var nxVersion1 = new NxVersion();
+ nxVersion1.UgiiProductName = "NX";
+ nxVersion1.UgiiMajorVersion = 1847;
+ nxVersion1.UgiiMinorVersion = 2400;
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\n\nVergleich mit NX 1847.2400 ergibt: ", nxVersion.Compare(nxVersion1));
+
+ var nxVersion2 = new NxVersion();
+ nxVersion2.UgiiProductName = "NX";
+ nxVersion2.UgiiMajorVersion = 1847;
+ nxVersion2.UgiiMinorVersion = 1200;
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 1847.1200 ergibt: ", nxVersion.Compare(nxVersion2));
+
+ var nxVersion3 = new NxVersion();
+ nxVersion3.UgiiProductName = "NX";
+ nxVersion3.UgiiMajorVersion = 1847;
+ nxVersion3.UgiiMinorVersion = 4800;
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 1847.4800 ergibt: ", nxVersion.Compare(nxVersion3));
+
+ var nxVersion4 = new NxVersion();
+ nxVersion4.UgiiProductName = "NX";
+ nxVersion4.UgiiMajorVersion = 10;
+ nxVersion4.UgiiMinorVersion = 0;
+ nxVersion4.UgiiSubminorVersion = 3;
+ nxVersion4.NXphase = 5;
+ nxVersion4.MaintenancePack = "MP10";
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 10.0.3.5 MP10 ergibt: ", nxVersion.Compare(nxVersion4));
+
+ var nxVersion5 = new NxVersion();
+ nxVersion5.UgiiProductName = "NX";
+ nxVersion5.UgiiMajorVersion = 10;
+ nxVersion5.UgiiMinorVersion = 0;
+ nxVersion5.UgiiSubminorVersion = 3;
+ nxVersion5.NXphase = 5;
+ nxVersion5.MaintenancePack = "MP19";
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 10.0.3.5 MP19 ergibt: ", nxVersion.Compare(nxVersion5));
+
+ var nxVersion6 = new NxVersion();
+ nxVersion6.UgiiProductName = "NX";
+ nxVersion6.UgiiMajorVersion = 10;
+ nxVersion6.UgiiMinorVersion = 0;
+ nxVersion6.UgiiSubminorVersion = 3;
+ nxVersion6.NXphase = 6;
+ nxVersion6.MaintenancePack = "MP19";
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 10.0.3.6 MP19 ergibt: ", nxVersion.Compare(nxVersion6));
+
+ var nxVersion7 = new NxVersion();
+ nxVersion7.UgiiProductName = "NX";
+ nxVersion7.UgiiMajorVersion = 12;
+ nxVersion7.UgiiMinorVersion = 4;
+ nxVersion7.UgiiSubminorVersion = 2;
+ nxVersion7.NXphase = 1;
+ nxVersion7.MaintenancePack = "MP2";
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 12.4.2.1 MP2 ergibt: ", nxVersion.Compare(nxVersion7));
+
+ var nxVersion8 = new NxVersion();
+ nxVersion8.UgiiProductName = "NX";
+ nxVersion8.UgiiMajorVersion = 12;
+ nxVersion8.UgiiMinorVersion = 0;
+ nxVersion8.UgiiSubminorVersion = 2;
+ nxVersion8.NXphase = 9;
+ nxVersion8.MaintenancePack = "MP5";
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 12.0.2.9 MP5 ergibt: ", nxVersion.Compare(nxVersion8));
+
+ var nxVersion9 = new NxVersion();
+ nxVersion9.UgiiProductName = "NX";
+ nxVersion9.UgiiMajorVersion = 12;
+ nxVersion9.UgiiMinorVersion = 4;
+ nxVersion9.UgiiSubminorVersion = 2;
+ nxVersion9.NXphase = 1;
+ nxVersion9.MaintenancePack = "MP1";
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 12.4.2.1 MP1 ergibt: ", nxVersion.Compare(nxVersion9));
+
+ var nxVersion10 = new NxVersion();
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 10.0.3.5 MP19 ergibt: ", nxVersion.Compare("NX", 10, 0, 3, 5, 19));
+
+ var nxVersion11 = new NxVersion();
+ labelVerInfo.Text = String.Concat(labelVerInfo.Text, "\n\nVergleich mit NX 12.0.2.9 MP5 ergibt: ", nxVersion.Compare("NX", 12, 0, 2, 9, 5));
+ }
+ catch (Exception ex)
+ {
+ labelVerInfo.Text = String.Concat("ACHTUNG:\n", ex.Message);
+ }
+ }
}
}
diff --git a/NxVersion/Form1.resx b/NxVersion/Form1.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/NxVersion/Form1.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/NxVersion/NxVersion.cs b/NxVersion/NxVersion.cs
new file mode 100644
index 0000000..c6f9612
--- /dev/null
+++ b/NxVersion/NxVersion.cs
@@ -0,0 +1,783 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+
+namespace NxVersion
+{
+ class NxVersion
+ {
+ #region Base value
+ ///
+ /// UGII_BASE_DIR. E.g.: C:\Program Files\Siemens\NX 12.0
+ ///
+ public string UgiiBaseDir { set; get; }
+
+ ///
+ /// UGII_ROOT_DIR. E.g.: C:\Program Files\Siemens\NX 12.0\UGII\
+ ///
+ public string UgiiRootDir { set; get; }
+
+ ///
+ /// Defines whether NX is newer than NX12. Yes=true, No=false
+ ///
+ public bool PostNX12 { set; get; }
+ #endregion
+
+ #region Define Type
+ ///
+ /// NX Version. E.g.: NX 10.0.3.5
+ ///
+ public string NXversion { get; set; }
+
+ ///
+ /// NX Patch. E.g.: NX 10.0.3.5 MP4
+ ///
+ public string NXpatch { get; set; }
+
+
+ ///
+ /// UGII_PRODUCT_NAME. E.g.: NX of NX 10.0.3.5
+ ///
+ public string UgiiProductName { get; set; }
+
+ ///
+ /// UGII_MAJOR_VERSION. E.g.: 10 of NX 10.0.3.5
+ ///
+ public int UgiiMajorVersion { get; set; }
+
+ ///
+ /// UGII_MINOR_VERSION. E.g.: 0 of NX 10.0.3.5
+ ///
+ public int UgiiMinorVersion { get; set; }
+
+ ///
+ /// UGII_SUBMINOR_VERSION. E.g.: 3 of NX 10.0.3.5
+ ///
+ public int UgiiSubminorVersion { get; set; }
+
+ ///
+ /// NX Phase. E.g.: 5 of NX 10.0.3.5
+ ///
+ public int NXphase { get; set; }
+
+
+ ///
+ /// UGII_FULL_VERSION. E.g.: v10.0.3.5 instead of NX 10.0.3.5
+ ///
+ public string UgiiFullVersion { get; set; }
+
+ ///
+ /// UGII_VERSION. E.g.: v10 of v10.0.3.5
+ ///
+ public string UgiiVersion { get; set; }
+
+
+ ///
+ /// NX_VERSION_STRING. E.g.: V28.0.3.5 instead of NX 10.0.3.5 MP4
+ ///
+ public string NxVersionString { get; set; }
+
+ ///
+ /// NX_MAJOR_STRING. E.g.: V28 of V28.0.3.5
+ ///
+ public string NxMajorVersionString { get; set; }
+
+ ///
+ /// NX_MINOR_STRING. E.g.: 0 of V28.0.3.5
+ ///
+ public string NxMinorVersionString { get; set; }
+
+ ///
+ /// NX_SUBMINOR_STRING. E.g.: 3 of V28.0.3.5
+ ///
+ public string NxSubminorVersionString { get; set; }
+
+ ///
+ /// NX_PHASE_STRING. E.g.: 5 of V28.0.3.5
+ ///
+ public string NxPhaseString { get; set; }
+
+
+ ///
+ /// Maintenance Release. E.g.: 10.0.3.5 of NX 10.0.3.5 MP4
+ ///
+ public string MaintenanceRelease { get; set; }
+
+ ///
+ /// Maintenance Pack. E.g.: MP4 of NX 10.0.3.5 MP4
+ ///
+ public string MaintenancePack { get; set; }
+
+ ///
+ /// Maintenance Pack Number. E.g.: 4 of NX 10.0.3.5 MP4
+ ///
+ public int MaintenancePackNumber { get; set; }
+ #endregion
+
+ public NxVersion()
+ { }
+
+ public NxVersion(string ugiiBaseDir)
+ {
+ if (Directory.Exists(ugiiBaseDir))
+ {
+ UgiiBaseDir = ugiiBaseDir;
+ UgiiRootDir = String.Concat(UgiiBaseDir, "\\UGII\\");
+ }
+ else
+ {
+ throw new DirectoryNotFoundException();
+ }
+
+ string nxVersionNo = ReadNxEnvValues(UgiiRootDir, "-n").Replace("\r\n", "");
+
+ if (IsPostNX12(UgiiRootDir))
+ {
+ //Nach NX12
+ AlignCode(nxVersionNo);
+ }
+ else
+ {
+ //Bis einschliesslich NX12
+ string tempPatchText = ReadNxEnvValues(UgiiRootDir, "-m");
+ tempPatchText = tempPatchText.Remove(tempPatchText.IndexOf(","));
+
+ AlignCode(nxVersionNo, tempPatchText);
+ }
+ }
+
+ #region CommonMethodes
+ private bool IsPostNX12(string ugiiRootDir)
+ {
+ if (NxVersionNumber(ugiiRootDir) <= 12)
+ {
+ //Bis einschliesslich NX12
+ PostNX12 = false;
+ }
+ else
+ {
+ //Nach NX12
+ PostNX12 = true;
+ }
+ return PostNX12;
+ }
+
+ private bool IsPostNX12(NxVersion version)
+ {
+ if (version.UgiiMajorVersion <= 12)
+ {
+ //Bis einschliesslich NX12
+ PostNX12 = false;
+ }
+ else
+ {
+ //Nach NX12
+ PostNX12 = true;
+ }
+ return PostNX12;
+ }
+
+ private int NxVersionNumber(string ugiiRootDir)
+ {
+ string nxVersion = ReadNxEnvValues(UgiiRootDir, "-n").Replace("\r\n", "");
+ nxVersion = nxVersion.Remove(nxVersion.IndexOf(".")).Replace("NX ","");
+ return Convert.ToInt16(nxVersion);
+ }
+
+ private string ReadNxEnvValues(string ugiiRootDir, string envPrintArg)
+ {
+ string envPrint = String.Concat(ugiiRootDir, "env_print.exe");
+ return ProcessOutput(envPrint, envPrintArg); //Prozess mit env_print.exe aufrufen
+ }
+
+ private string ReadProcessOutput(string ugii_base_dir, string arguments)
+ {
+ // Liest die Daten nach beenden der Prozess-Ausgabe aus
+ // Tritt ein Fehler auf, liefert die Funktion null zurück
+
+ //Wenn UGII_BASE_DIR mit '\\' endet, dann diese entfernen
+ if (ugii_base_dir.EndsWith("\\"))
+ {
+ ugii_base_dir = ugii_base_dir.Remove(ugii_base_dir.Length - 2);
+ }
+
+ //Überprüfen ob auf alle notwendigen Dateien (env_print.exe, libpatch.dll, libsyss.dll) zugegriffen werden kann
+ ExecutablesExists(ugii_base_dir);
+
+ //Wenn 'ugii_base_dir' existiert, dann die Werte ermitteln}
+ return ProcessOutput(ugii_base_dir, arguments);
+ }
+
+ private void ExecutablesExists(string ugii_base_dir)
+ {
+ //Wenn eine der drei Dateien nicht existiert, dann eine Exception werfen
+ if (!File.Exists(String.Concat(ugii_base_dir, "\\UGII\\env_print.exe"))) throw new NoEnvPrintExeException("Unable to find EnvPrint.exe");
+ //Nur vor 'NX 1847' ausführen, weil es nur vorher diese Biblithek gibt
+ if (!ugii_base_dir.ToLower().Contains("nx 1847") & !ugii_base_dir.ToLower().Contains("beta") & ugii_base_dir.Remove(0, ugii_base_dir.LastIndexOf("\\") + 1).Length != 2)
+ {
+ if (!File.Exists(String.Concat(ugii_base_dir, "\\UGII\\libpatch.dll")) & !File.Exists(String.Concat(ugii_base_dir, "\\NXBIN\\libpatch.dll"))) throw new NoLibPatchDllException("Unable to find LibPatch.dll");
+ }
+ if (!File.Exists(String.Concat(ugii_base_dir, "\\UGII\\libsyss.dll"))) throw new NoLibSysDllException("Unable to find LibSys.dll");
+ }
+
+ private string ProcessOutput(string envPrint, string envPrintArg)
+ {
+ try
+ {
+ Process process = new Process();
+
+ process.StartInfo.FileName = envPrint;
+ process.StartInfo.Arguments = envPrintArg;
+ process.StartInfo.UseShellExecute = false;
+ process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.CreateNoWindow = true;
+
+ process.Start();
+ process.WaitForExit();
+
+ return process.StandardOutput.ReadToEnd();
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ private void AlignCode(string nxVersionNo)
+ {
+ //Neue NX Versionen auflösen
+
+ //NX Version zerlegen
+ string[] versionSegments = new string[3];
+ string[] temp = new string[2];
+ temp = SeperateVersionCode(nxVersionNo);
+ for (int i = 0; i < 3; i++)
+ {
+ versionSegments[i] = temp[i];
+ }
+
+ //Patch Text zerlegen
+ //versionSegments[5] = SeperatePatchText(nxVersionNo);
+
+ UgiiProductName = versionSegments[0]; //Produkt Name
+ UgiiMajorVersion = Convert.ToInt32(versionSegments[1]); //Major Version
+ UgiiMinorVersion = Convert.ToInt32(versionSegments[2]); //Minor Version
+ }
+
+ private void AlignCode(string nxVersionNo, string tempPatchText)
+ {
+ //NX Version zerlegen
+ string[] versionSegments = new string[6];
+ string[] temp = new string[5];
+ temp = SeperateVersionCode(nxVersionNo);
+ for (int i = 0; i < 5; i++)
+ {
+ versionSegments[i] = temp[i];
+ }
+
+ //Patch Text zerlegen
+ versionSegments[5] = SeperatePatchText(tempPatchText);
+
+ //Werte zuordnen
+ NXpatch = String.Concat(versionSegments[0], " ", versionSegments[1], ".", versionSegments[2], ".", versionSegments[3], ".", versionSegments[4], " ", versionSegments[5]); //NX Patch
+ NXversion = String.Concat(versionSegments[0], " ", versionSegments[1], ".", versionSegments[2], ".", versionSegments[3], ".", versionSegments[4]); //NX Version
+ MaintenanceRelease = String.Concat(versionSegments[1], ".", versionSegments[2], ".", versionSegments[3], ".", versionSegments[4]); //Maintenance Release
+ UgiiProductName = versionSegments[0]; //Produkt Name
+ UgiiMajorVersion = Convert.ToInt32(versionSegments[1]); //Major Version
+ UgiiMinorVersion = Convert.ToInt32(versionSegments[2]); //Minor Version
+ UgiiSubminorVersion = Convert.ToInt32(versionSegments[3]); //Subminor Version
+ NXphase = Convert.ToInt32(versionSegments[4]); //NX Phase
+ MaintenancePack = versionSegments[5]; //Maintenance Pack
+ MaintenancePackNumber = Convert.ToInt32(versionSegments[5].Replace("MP", ""));
+ NxVersionString = String.Concat("V", (Convert.ToInt32(versionSegments[1]) + 18).ToString(), ".", versionSegments[2], ".", versionSegments[3], ".", versionSegments[4]); //NX Version String
+ NxMajorVersionString = String.Concat("V", (Convert.ToInt32(versionSegments[1]) + 18).ToString()); //Major Version String
+ NxMinorVersionString = versionSegments[2].ToString(); //Minor Version String
+ NxSubminorVersionString = versionSegments[3].ToString(); //Subminor Version String
+ NxPhaseString = versionSegments[4].ToString(); //NX Phase String
+ UgiiFullVersion = String.Concat("v", versionSegments[1], ".", versionSegments[2], ".", versionSegments[3], ".", versionSegments[4]); //NX Full Version
+ UgiiVersion = String.Concat("v", versionSegments[1]);
+ }
+
+ private void AlignCode(string ugiiProductName, int majorVersion, int minorVersion, int subminorVersion, int phase, int mp)
+ {
+ //Werte zuordnen
+ NXpatch = String.Concat(ugiiProductName, " ", majorVersion, ".", minorVersion, ".", subminorVersion, ".", phase, " MP", mp); //NX Patch
+ NXversion = String.Concat(ugiiProductName, " ", majorVersion, ".", minorVersion, ".", subminorVersion, ".", phase); //NX Version
+ MaintenanceRelease = String.Concat(majorVersion, ".", minorVersion, ".", subminorVersion, ".", phase); //Maintenance Release
+ UgiiProductName = ugiiProductName; //Produkt Name
+ UgiiMajorVersion = majorVersion; //Major Version
+ UgiiMinorVersion = minorVersion; //Minor Version
+ UgiiSubminorVersion = subminorVersion; //Subminor Version
+ NXphase = phase; //NX Phase
+ MaintenancePack = String.Concat("MP", mp); //Maintenance Pack
+ MaintenancePackNumber = mp;
+ NxVersionString = String.Concat("V", (Convert.ToInt32(majorVersion) + 18).ToString(), ".", minorVersion, ".", subminorVersion, ".", phase); //NX Version String
+ NxMajorVersionString = String.Concat("V", (Convert.ToInt32(majorVersion) + 18).ToString()); //Major Version String
+ NxMinorVersionString = minorVersion.ToString(); //Minor Version String
+ NxSubminorVersionString = subminorVersion.ToString(); //Subminor Version String
+ NxPhaseString = phase.ToString(); //NX Phase String
+ UgiiFullVersion = String.Concat("v", majorVersion, ".", minorVersion, ".", subminorVersion, ".", phase); //NX Full Version
+ UgiiVersion = String.Concat("v", majorVersion);
+ }
+
+ private string[] SeperateVersionCode(string versionNumber)
+ {
+ //Wert auflösen und in den Variablen ablegen
+ if (versionNumber == "\n\r" || versionNumber == null)
+ {
+ versionNumber = "NX 00.0.0.00 MP0"; //Wenn kein Wert zurückgeliefert wird, dann mit Null vorbelegen
+ }
+
+ if (versionNumber.EndsWith("\r\n"))
+ {
+ versionNumber = versionNumber.Replace("\r\n", ""); //Zeilenvorschub und Wagenrücklauf entfernen
+ }
+ else if (versionNumber.EndsWith("\n\r"))
+ {
+ versionNumber = versionNumber.Replace("\n\r", ""); //Zeilenvorschub und Wagenrücklauf entfernen
+ }
+
+ string[] versionSegments = new string[6];
+
+ if (versionNumber.Contains("MP"))
+ {
+ versionSegments[5] = versionNumber.Remove(0, versionNumber.IndexOf("MP"));
+ versionNumber = versionNumber.Remove(versionNumber.IndexOf("MP") - 1); //Wenn ' MP' vorkommt, dann abschneiden
+ }
+ else
+ {
+ versionSegments[5] = "MP0";
+ }
+ versionSegments[0] = versionNumber.Remove(versionNumber.IndexOf(" ")); //Produktnamen zuordnen. Z.B.: NX of NX 10.0.3.5
+ versionNumber = versionNumber.Remove(0, versionNumber.IndexOf(" ") + 1); //Den Produktnamen entfernen
+
+ //Die einzelnen Segmente herauslösen
+ string[] tempVersionSegments = versionNumber.Split(new Char[] { '.' });
+
+
+ if (tempVersionSegments.Length != 4)
+ {
+ if (tempVersionSegments.Length == 3)
+ {
+ //NX Phase fehlt
+ versionSegments[1] = tempVersionSegments[0];
+ versionSegments[2] = tempVersionSegments[1];
+ versionSegments[3] = tempVersionSegments[2];
+ versionSegments[4] = "0";
+ }
+ else if (tempVersionSegments.Length == 2)
+ {
+ //Sub Minor Version und NX Phase fehlen
+ versionSegments[1] = tempVersionSegments[0];
+ versionSegments[2] = tempVersionSegments[1];
+ versionSegments[3] = "0";
+ versionSegments[4] = "0";
+ }
+ else if (tempVersionSegments.Length == 1)
+ {
+ //Minor Version, Sub Minor Version und NX Phase fehlen
+ versionSegments[1] = tempVersionSegments[0];
+ versionSegments[2] = "0";
+ versionSegments[3] = "0";
+ versionSegments[4] = "0";
+ }
+ else
+ {
+ //Major Version, Minor Version, Sub Minor Version und NX Phase fehlen
+ versionSegments[1] = "0";
+ versionSegments[2] = "0";
+ versionSegments[3] = "0";
+ versionSegments[4] = "0";
+ }
+ }
+ else
+ {
+ versionSegments[1] = tempVersionSegments[0];
+ versionSegments[2] = tempVersionSegments[1];
+ versionSegments[3] = tempVersionSegments[2];
+ versionSegments[4] = tempVersionSegments[3];
+ }
+ return versionSegments;
+ }
+
+ private string SeperatePatchText(string patchText)
+ {
+ if (patchText.Contains("MP"))
+ {
+ patchText = patchText.Remove(0, patchText.IndexOf("MP")); //Alles vor MP abschneiden
+ return patchText;
+ }
+ else
+ {
+ return "MP0"; //Es wurde kein gültiger Text gefunden, darum einen Wert zuweisen
+ }
+ }
+
+ private NxVersion AssignVersion()
+ {
+ NxVersion nxVersion = new NxVersion();
+
+ nxVersion.NXpatch = NXpatch; //NX Patch. E.g.: NX 10.0.3.5 MP4
+ nxVersion.NXversion = NXversion; //NX Version. E.g.: NX 10.0.3.5
+ nxVersion.MaintenanceRelease = MaintenanceRelease; //Maintenance Release. E.g.: 10.0.3.5 of NX 10.0.3.5 MP4
+ nxVersion.UgiiProductName = UgiiProductName; //UGII_PRODUCT_NAME. E.g.: NX of NX 10.0.3.5
+ nxVersion.UgiiMajorVersion = UgiiMajorVersion; //UGII_MAJOR_VERSION. E.g.: 10 of NX 10.0.3.5
+ nxVersion.UgiiMinorVersion = UgiiMinorVersion; //UGII_MINOR_VERSION. E.g.: 0 of NX 10.0.3.5
+ nxVersion.UgiiSubminorVersion = UgiiSubminorVersion; //UGII_SUBMINOR_VERSION. E.g.: 3 of NX 10.0.3.5
+ nxVersion.NXphase = NXphase; //NX Phase. E.g.: 5 of NX 10.0.3.
+ nxVersion.MaintenancePack = MaintenancePack; //Maintenance Pack. E.g.: MP4 of NX 10.0.3.5 MP4
+ nxVersion.MaintenancePackNumber = MaintenancePackNumber; //Maintenance Pack Number. E.g.: 4 of NX 10.0.3.5 MP4
+ nxVersion.NxVersionString = NxVersionString; //NX_VERSION_STRING. E.g.: V28.0.3.5 instead of NX 10.0.3.5 MP4
+ nxVersion.NxMajorVersionString = NxMajorVersionString; //NX_MAJOR_STRING. E.g.: V28 of V28.0.3.5
+ nxVersion.NxMinorVersionString = NxMinorVersionString; //NX_MINOR_STRING. E.g.: 0 of V28.0.3.5
+ nxVersion.NxSubminorVersionString = NxSubminorVersionString; //NX_SUBMINOR_STRING. E.g.: 3 of V28.0.3.5
+ nxVersion.NxPhaseString = NxPhaseString; //NX_PHASE_STRING. E.g.: 5 of V28.0.3.5
+ nxVersion.UgiiFullVersion = UgiiFullVersion; //UGII_FULL_VERSION. E.g.: v10.0.3.5 instead of NX 10.0.3.5
+ nxVersion.UgiiVersion = UgiiVersion; //UGII_VERSION. E.g.: v10 of v10.0.3.5
+
+ return nxVersion;
+ }
+
+ /////
+ // /// Assign values to a NX Version.
+ // ///
+ // /// A valid UGII_BASE_DIR.
+ // /// A full defined NX Version.
+ //private NxVersion GetNxVersion(string ugii_base_dir)
+ //{
+ // NxVersion nxVersion = new NxVersion();
+
+ // string tempVersion = "";
+ // string tempPatchText = "";
+
+
+ // if (Directory.Exists(ugii_base_dir))
+ // {
+ // tempVersion = ReadProcessOutput(ugii_base_dir, "-n"); //Prozess mit env_print.exe -n aufrufen
+ // tempPatchText = ReadProcessOutput(ugii_base_dir, "-m"); //Prozess mit env_print.exe -m aufrufen
+
+ // //Wert auflösen und in den Variablen ablegen
+ // AlignCode(tempVersion, tempPatchText);
+
+ // return AssignVersion(); //Werte zuordnen
+ // }
+ // else
+ // {
+ // return null; //Wenn 'ugii_base_dir' nicht existiert, dann 'null' zurückgeben
+ // }
+ //}
+
+ /////
+ ///// Assign values to a NX Version.
+ /////
+ ///// A valid product name. E.g.: NX
+ ///// A valid UGII_MAJOR_VERSION. E.g.: 10 of NX 10.0.3.5
+ ///// A valid UGII_MINOR_VERSION. E.g.: 0 of NX 10.0.3.5
+ ///// A full defined NX Version.
+ //private NxVersion GetNxVersion(string ugiiProductName, int majorVersion, int minorVersion)
+ //{
+ // NxVersion nxVersion = new NxVersion();
+
+ // //Wert auflösen und in den Variablen ablegen
+ // AlignCode(ugiiProductName, majorVersion, minorVersion, 0, 0, 0);
+
+ // return AssignVersion(); //Werte zuordnen
+ //}
+
+ ///
+ /// Assign values to a NX Version.
+ ///
+ /// A valid product name. E.g.: NX
+ /// A valid UGII_MAJOR_VERSION. E.g.: 10 of NX 10.0.3.5
+ /// A valid UGII_MINOR_VERSION. E.g.: 0 of NX 10.0.3.5
+ /// A valid UGII_SUBMINOR_VERSION. E.g.: 3 of NX 10.0.3.5
+ /// A valid NX Phase. E.g.: 5 of NX 10.0.3.5
+ /// A valid Maintenance Pack. E.g.: MP4 of NX 10.0.3.5 MP4
+ /// A full defined NX Version.
+ private NxVersion GetNxVersion(string ugiiProductName, int majorVersion, int minorVersion, int subminorVersion, int phase, int mp)
+ {
+ NxVersion nxVersion = new NxVersion();
+
+ //Wert auflösen und in den Variablen ablegen
+ AlignCode(ugiiProductName, majorVersion, minorVersion, subminorVersion, phase, mp);
+
+ return AssignVersion(); //Werte zuordnen
+ }
+ #endregion
+
+ #region Compare
+ ///
+ /// Compares two NX-Versions.
+ ///
+ /// A valid NX-Version.
+ /// 0 = equal, 1 = first version newer, 2 = second version newer, -1 = An error is happened.
+ public int Compare(NxVersion version)
+ {
+ //version.PostNX12 = IsPostNX12(version);
+ return Compare(this, version);
+ }
+
+ ///
+ /// Compares two NX-Versions.
+ ///
+ /// A valid NX Version.
+ /// A valid NX Version.
+ /// 0 = equal, 1 = first version newer, 2 = second version newer, -1 = An error is happened.
+ public int Compare(NxVersion version1, NxVersion version2)
+ {
+ if (IsPostNX12(version1) & IsPostNX12(version2))
+ {
+ return ComparePostNX12(version1, version2);
+ }
+ if (!IsPostNX12(version1) & !IsPostNX12(version2))
+ {
+ return CompareUpToNX12(version1, version2);
+ }
+ if ((IsPostNX12(version1) & !IsPostNX12(version2)) || (!IsPostNX12(version1) & IsPostNX12(version2)))
+ {
+ return CompareDiffVersions(version1, version2);
+ }
+ return -1;
+ }
+
+ ///
+ /// Compares two NX-Versions.
+ ///
+ /// A valid product name. E.g.: NX
+ /// A valid UGII_MAJOR_VERSION. E.g.: 10 of NX 10.0.3.5
+ /// A valid UGII_MINOR_VERSION. E.g.: 0 of NX 10.0.3.5
+ /// A valid UGII_SUBMINOR_VERSION. E.g.: 3 of NX 10.0.3.5
+ /// A valid NX Phase. E.g.: 5 of NX 10.0.3.5
+ /// A valid Maintenance Pack. E.g.: MP4 of NX 10.0.3.5 MP4
+ /// 0 = equal, 1 = first version newer, 2 = second version newer, -1 = An error is happened.
+ public int Compare(string ugiiProductName, int majorVersion, int minorVersion, int subminorVersion, int phase, int mp)
+ {
+ NxVersion nxVersion = new NxVersion();
+ nxVersion.UgiiProductName = ugiiProductName;
+ nxVersion.UgiiMajorVersion = majorVersion;
+ nxVersion.UgiiMinorVersion = minorVersion;
+ nxVersion.UgiiSubminorVersion = subminorVersion;
+ nxVersion.NXphase = phase;
+ nxVersion.MaintenancePackNumber = mp;
+
+ //NX-Version vergleichen
+ return Compare(this, nxVersion);
+ }
+
+ private int CompareUpToNX12(NxVersion version1, NxVersion version2)
+ {
+ //Nummer setzen wenn noch nicht geschehen
+ if (!String.IsNullOrEmpty(version2.MaintenancePack))
+ {
+ if (version2.MaintenancePackNumber != Convert.ToInt32(version2.MaintenancePack.Remove(0, 2)))
+ {
+ version2.MaintenancePackNumber = Convert.ToInt32(version2.MaintenancePack.Remove(0, 2));
+ }
+ }
+
+ //if (version1.NXpatch == version2.NXpatch)
+ if (version1.UgiiMajorVersion == version2.UgiiMajorVersion & version1.UgiiMinorVersion == version2.UgiiMinorVersion & version1.UgiiSubminorVersion == version2.UgiiSubminorVersion & version1.NXphase == version2.NXphase & version1.MaintenancePackNumber == version2.MaintenancePackNumber)
+ {
+ return 0; //Versionen gleich
+ }
+ if (version1.UgiiMajorVersion < version2.UgiiMajorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiMajorVersion > version2.UgiiMajorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.UgiiMinorVersion < version2.UgiiMinorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiMinorVersion > version2.UgiiMinorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.UgiiSubminorVersion < version2.UgiiSubminorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiSubminorVersion > version2.UgiiSubminorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.NXphase < version2.NXphase)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.NXphase > version2.NXphase)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.MaintenancePackNumber < version2.MaintenancePackNumber)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.MaintenancePackNumber > version2.MaintenancePackNumber)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+
+ return -1; //Fehler passiert
+ }
+
+ private int ComparePostNX12(NxVersion version1, NxVersion version2)
+ {
+ if (version1.UgiiMajorVersion == version2.UgiiMajorVersion & version1.UgiiMinorVersion == version2.UgiiMinorVersion)
+ {
+ return 0; //Versionen gleich
+ }
+ if (version1.UgiiMajorVersion < version2.UgiiMajorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiMajorVersion > version2.UgiiMajorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.UgiiMinorVersion < version2.UgiiMinorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiMinorVersion > version2.UgiiMinorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+
+ return -1; //Fehler passiert
+ }
+
+ private int CompareDiffVersions(NxVersion version1, NxVersion version2)
+ {
+ if (version1.UgiiMajorVersion > version2.UgiiMajorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.UgiiMajorVersion < version2.UgiiMajorVersion)
+ {
+ return 2; //Version 1 ist neuer als Version 2
+ }
+
+ return -1; //Fehler passiert
+ }
+
+ private int CompareMethode(NxVersion version)
+ {
+ return CompareMethode(this, version);
+ }
+
+ private int CompareMethode(NxVersion version1, NxVersion version2)
+ {
+ if (version1.NXpatch == version2.NXpatch)
+ {
+ return 0; //Versionen gleich
+ }
+ if (version1.UgiiMajorVersion < version2.UgiiMajorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiMajorVersion > version2.UgiiMajorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.UgiiMinorVersion < version2.UgiiMinorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiMinorVersion > version2.UgiiMinorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.UgiiSubminorVersion < version2.UgiiSubminorVersion)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.UgiiSubminorVersion > version2.UgiiSubminorVersion)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.NXphase < version2.NXphase)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.NXphase > version2.NXphase)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+ if (version1.MaintenancePackNumber < version2.MaintenancePackNumber)
+ {
+ return 2; //Version 1 ist älter als Version 2
+ }
+ if (version1.MaintenancePackNumber > version2.MaintenancePackNumber)
+ {
+ return 1; //Version 1 ist neuer als Version 2
+ }
+
+ return -1; //Fehler passiert
+ }
+
+ private int CompareMethode(string ugiiProductName, int majorVersion, int minorVersion, int subminorVersion, int phase, int mp)
+ {
+ //NxVersion nxVersion = new NxVersion();
+
+ NxVersion nxVersion = GetNxVersion(ugiiProductName, majorVersion, minorVersion, subminorVersion, phase, mp);
+
+ //NX-Version vergleichen
+ return CompareMethode(this, nxVersion);
+ }
+ #endregion
+ }
+
+ #region Exception
+ class NoNXversionException : ApplicationException
+ {
+ public NoNXversionException()
+ { }
+
+ public NoNXversionException(string message) : base(message)
+ { }
+
+ public NoNXversionException(string message, Exception inner) : base(message, inner)
+ { }
+ }
+
+ class NoEnvPrintExeException : ApplicationException
+ {
+ public NoEnvPrintExeException()
+ { }
+
+ public NoEnvPrintExeException(string message) : base(message)
+ { }
+
+ public NoEnvPrintExeException(string message, Exception inner) : base(message, inner)
+ { }
+ }
+
+ class NoLibPatchDllException : ApplicationException
+ {
+ public NoLibPatchDllException()
+ { }
+
+ public NoLibPatchDllException(string message) : base(message)
+ { }
+
+ public NoLibPatchDllException(string message, Exception inner) : base(message, inner)
+ { }
+ }
+
+ class NoLibSysDllException : ApplicationException
+ {
+ public NoLibSysDllException()
+ { }
+
+ public NoLibSysDllException(string message) : base(message)
+ { }
+
+ public NoLibSysDllException(string message, Exception inner) : base(message, inner)
+ { }
+ }
+ #endregion
+}
diff --git a/NxVersion/NxVersion.csproj b/NxVersion/NxVersion.csproj
index 85a3541..adf9859 100644
--- a/NxVersion/NxVersion.csproj
+++ b/NxVersion/NxVersion.csproj
@@ -52,8 +52,12 @@
Form1.cs
+
+
+ Form1.cs
+
ResXFileCodeGenerator
Resources.Designer.cs