Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to tia v19 #8

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion src/tia2ax/V18_0/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//"commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\AX_Plc1518V3_CognexDataman\\AX_Plc1518V3_CognexDataman.ap18 -o D:\\github\\ix-ax\\TiaProjects\\Export"
//"commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\AX_Plc1518V3_CmmtAs\\AX_Plc1518V3_CmmtAs.ap18 -o D:\\github\\ix-ax\\TiaProjects\\Export"
//"commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\AX_Plc1518V3_IndraDrive\\AX_Plc1518V3_IndraDrive.ap18 -o D:\\github\\ix-ax\\TiaProjects\\Export"
"commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\AX_Plc1518V3_Desoutter\\AX_Plc1518V3_Desoutter.ap18 -o D:\\github\\ix-ax\\TiaProjects\\Export"
"commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\AX_Plc1518V3_Desoutter\\AX_Plc1518V3_Desoutter.ap18 -o D:\\github\\ix-ax\\Export"
//"commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\HW_Plc1518V3_Desoutter\\HW_Plc1518V3_IndraDrive.ap19 -o D:\\github\\ix-ax\\TiaProjects\\Export"
}
}
}
132 changes: 132 additions & 0 deletions src/tia2ax/V19_0/ApiResolver/ApiResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Security.AccessControl;

namespace Tia2Ax.Utils
{
/// <summary>
/// Definition of helper functionality to resolve api dll, modules and options
/// </summary>
public static class ApiResolver
{
/// <summary>
/// Required min version of engineering dll
/// </summary>
public const string StrRequiredVersion = "V19.0";
private const string BasePath = "SOFTWARE\\Siemens\\Automation\\Openness\\";
private const string LibraryKey = "SOFTWARE\\Siemens\\Automation\\Openness\\19.0\\PublicAPI\\19.0.0.0";
private const string LibraryName = "Siemens.Engineering";

/// <summary>
/// Get version info from registry key
/// </summary>
/// <returns></returns>
public static List<string> GetEngineeringVersions()
{
RegistryKey key = GetRegistryKey(BasePath);

if (key != null)
{
try
{
var names = key.GetSubKeyNames().OrderBy(x => x).ToList();

var result = (from item in names
where Convert.ToDecimal(item.Substring(0, 4)) >= Convert.ToDecimal(StrRequiredVersion.Substring(1, 4))
select item.Substring(0, 4)).ToList();

key.Dispose();

return result;
}
finally
{
key.Dispose();
}
}

return new List<string>();
}

private static RegistryKey GetRegistryKey(string keyName)
{
RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey key = baseKey.OpenSubKey(keyName);
if (key == null)
{
baseKey.Dispose();
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
key = baseKey.OpenSubKey(keyName);
}
if (key == null)
{
baseKey.Dispose();
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
key = baseKey.OpenSubKey(keyName);
}
baseKey.Dispose();

return key;
}


/// <summary>
/// Check if openness api is installed
/// </summary>
/// <returns></returns>
public static bool IsOpennessInstalled()
{
return !string.IsNullOrEmpty(GetLibraryFilePath());
}

private static string GetLibraryFilePath()
{
using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
using (var registryKey = baseKey.OpenSubKey(LibraryKey, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey))
{
var libraryFilePath = registryKey?.GetValue(LibraryName) as string;
if (!string.IsNullOrWhiteSpace(libraryFilePath) && File.Exists(libraryFilePath))
{
return libraryFilePath;
}
}
}
return null;
}


/// <summary>
/// Check if required TiaVersion is installed
/// </summary>
/// <returns></returns>
public static bool IsTiaInstalled()
{
try
{
ObservableCollection<string> EngineeringVersions = new ObservableCollection<string>(GetEngineeringVersions());
if (EngineeringVersions != null && EngineeringVersions.Count > 0)
{
foreach (var version in EngineeringVersions)
{
if(version == StrRequiredVersion.Substring(1, 4))
{
return true;
}
}
return false;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return false;
}
return false;
}
}
}
Loading