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

Remove datatype content in FB,FC and UDT and disable quick edit #138

Merged
merged 4 commits into from
Aug 28, 2019
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions TiaGitHandler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -32,6 +33,24 @@ class Program
private static bool removeOnlyOneBlank = true;
private static bool removeNoBlanks = false;

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetConsoleMode(
IntPtr hConsoleHandle,
out int lpMode);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetConsoleMode(
IntPtr hConsoleHandle,
int ioMode);

public const int STD_INPUT_HANDLE = -10;

[DllImport("Kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);

const int ExtendedFlags = 128;
const int QuickEditMode = 64;

[STAThread]
static void Main(string[] args)
{
Expand All @@ -56,6 +75,8 @@ static void Main(string[] args)
removeOnlyOneBlank = ask.rbRemoveOnlyOneBlank.IsChecked == true;
removeNoBlanks = ask.rbRemoveNoBlanks.IsChecked == true;

DisableQuickEdit();

if (object.Equals(res, false))
{
OpenFileDialog op = new OpenFileDialog();
Expand Down Expand Up @@ -465,6 +486,18 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
{
}

try
{
var nodes = xmlDoc.SelectNodes("//*[local-name()='Member'][contains(@Datatype,'\"')]//*[local-name()='Sections']");
foreach (var node in nodes.Cast<XmlNode>())
{
node.ParentNode.RemoveChild(node);
}
}
catch
{
}

if (resetSetpoints)
{
try
Expand Down Expand Up @@ -729,6 +762,21 @@ private static void ParseFolder(ProjectFolder folder, string dir, List<string> s
}
}

if (projectBlockInfo.BlockTypeString == "Userdatatype" || projectBlockInfo.BlockTypeString == "Functionblock")
{
try
{
var nodes = xmlDoc2.SelectNodes("//*[local-name()='Member'][contains(@Datatype,'\"')]//*[local-name()='Sections']");
foreach (var node in nodes.Cast<XmlNode>())
{
node.ParentNode.RemoveChild(node);
}
}
catch
{
}
}

StringBuilder sb = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings
{
Expand Down Expand Up @@ -1008,5 +1056,26 @@ private static void DeleteDir(string dir)
DeleteDir(dir);
}
}

private static void DisableQuickEdit()
{
IntPtr conHandle = GetStdHandle(STD_INPUT_HANDLE);
int mode;

if (!GetConsoleMode(conHandle, out mode))
{
Console.WriteLine("err1");
// error getting the console mode. Exit.
return;
}

mode = mode & ~(QuickEditMode | ExtendedFlags);

if (!SetConsoleMode(conHandle, mode))
{
Console.WriteLine("err2");
// error setting console mode.
}
}
}
}
Loading