<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Ticket search results</title><link>https://forge.codesys.com/tol/cforge/tickets/</link><description>You searched for labels:"region"</description><language>en</language><lastBuildDate>Tue, 03 Dec 2019 04:19:15 -0000</lastBuildDate><item><title>Draft for better bootstrapping and checking prerequisits</title><link>https://forge.codesys.com/tol/cforge/tickets/9/</link><description>I extended cForge helper class with a bootstrapper to detect SVN installation and to add the LibDoc.exe to the PATH environmentvariables. Offcourse its written in similair style to the excisting code.

Here are my code snippets;

In Program.cs edit case setup to call the bootstrapper;

~~~
case "--setup":
                        if (!Helper.IsUserElevated())
                        {
                            Console.WriteLine("[INFO] Setup URL Handler and add tool to path. ");
                            Helper.RunElevated("--setup");

                        }
                        else
                        {
                            /// bootstrapper 
                            Helper.bootstrap(bDebug);
                            Helper.RegisterProtocol(bDebug);
                            Helper.AddToSystemPath(bDebug);
                        }
                        break;
~~~


And extend SystemPath region in Helper.cs with Bootstrapper;
~~~

        #region SystemPath

        public static void AddToSystemPath(bool bVerbose)
        {
            string strPath = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
            string[] split = strPath.Split(new Char[] { ';' });
            string path = Path.GetDirectoryName(GetCFORGEAssemblyPath());
            string strNewSystemPath = strPath + ";" + path;

            if (!split.Contains(path))
            {
                System.Environment.SetEnvironmentVariable("Path", strNewSystemPath, EnvironmentVariableTarget.Machine);
            }

 
        }


        public static void bootstrap(bool bVerbose)
        {
            /// bootstrapper 
            /// warning for svn.exe if not present
            string exepath = Helper.FindExePath("svn.exe");
            if (exepath == String.Empty)
            {
                Console.WriteLine("[WARNING] Please install Turtoise SVN with command line client option!");
            }
            else
            {
                Console.WriteLine("[INFO] Turtoise SVN detected. \r\n\tPath is: " + exepath);
                exepath = String.Empty;
            }

            /// add libdoc.exe to path to enable CODESYS libdocscripting (TODO expand this section)
            exepath = Helper.FindExePath("libdoc.exe");
            string strPath = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
            string path = String.Empty;
            string strNewSystemPath = String.Empty;
            if (exepath == String.Empty)
            {
                /// add path to: "C:\Program Files\CODESYS 3.5.14.0\CODESYS\DocScripting\3.5.14.0"
                /// for now quick and dirty =&gt; should become dynamic 
                path = "C:\\Program Files\\CODESYS 3.5.14.0\\CODESYS\\DocScripting\\3.5.14.0";
                strNewSystemPath = strPath + ";" + path;
                System.Environment.SetEnvironmentVariable("Path", strNewSystemPath, EnvironmentVariableTarget.Machine);
                Console.WriteLine("[INFO] Environmentvariable for DocScripting added:  \r\n\tPath is: " + path);
            }
            else
            {
                Console.WriteLine("[INFO] DocScripting detected. \r\n\tPath is: " + exepath);
                exepath = String.Empty;
            }


        }


            /// &lt;summary&gt;
            /// Expands environment variables and, if unqualified, locates the exe in the working directory
            /// or the evironment's path.
            /// &lt;/summary&gt;
            /// &lt;param name="exe"&gt;The name of the executable file&lt;/param&gt;
            /// &lt;returns&gt;The fully-qualified path to the file&lt;/returns&gt;
            /// &lt;exception cref="System.IO.FileNotFoundException"&gt;Raised when the exe was not found&lt;/exception&gt;
            public static string FindExePath(string exe)
        {
            exe = Environment.ExpandEnvironmentVariables(exe);
            if (!File.Exists(exe))
            {
                if (Path.GetDirectoryName(exe) == String.Empty)
                {
                    foreach (string test in (Environment.GetEnvironmentVariable("PATH") ?? "").Split(';'))
                    {
                        string path = test.Trim();
                        if (!String.IsNullOrEmpty(path) &amp;&amp; File.Exists(path = Path.Combine(path, exe)))
                            return Path.GetFullPath(path);
                    }
                }
                return String.Empty;
                /// throw new FileNotFoundException(new FileNotFoundException().Message, exe);
            }
            return Path.GetFullPath(exe);
        }

        #endregion
~~~



</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">aliazzz</dc:creator><pubDate>Tue, 03 Dec 2019 04:19:15 -0000</pubDate><guid isPermaLink="false">https://forge.codesys.com/tol/cforge/tickets/9/</guid></item></channel></rss>