Example #1
0
        /// <summary>
        /// Returns the path of the file
        /// </summary>
        /// <param name="pathOfInclude"></param>
        /// <param name="pathOfScript"></param>
        /// <returns></returns>
        private string GetFilePath(string pathOfInclude, string pathOfScript)
        {
            // Step 1 (optional). Search from include directories
            // Step 2. Search from relative path from script

            string pathOfIncludeOriginal = pathOfInclude;

            pathOfInclude = SearchFile(pathOfInclude);

            if (pathOfInclude == "")
            {
                // If path is relative and no includedirectories
                if (!Path.IsPathRooted(pathOfIncludeOriginal))
                {
                    pathOfInclude = LSLIPathHelper.GetRelativePath(pathOfScript, Environment.CurrentDirectory) + pathOfIncludeOriginal;
                }
                else if (this.implementedIncludes.Count > 0) // If there are already includes, the relative path is already correct
                {
                    pathOfInclude = Path.GetDirectoryName(this.implementedIncludes.LastOrDefault()) + '\\' + pathOfIncludeOriginal;
                }
                else
                {
                    pathOfInclude = pathOfIncludeOriginal;
                }

                // If path is absolute it will stay the pathOfInclude
                pathOfInclude = SearchFile(pathOfInclude);
            }

            return(pathOfInclude);
        }
Example #2
0
        /// <summary>
        /// Compares 2 paths and returns true if they are different, false if they're the same.
        /// Warning: This doesn't compare extensions.
        /// </summary>
        /// <param name="pathOfInclude"></param>
        /// <param name="pathOfScript"></param>
        /// <returns></returns>
        public static bool IsDifferentScript(string pathOfInclude, string pathOfScript)
        {
            string pathOfScriptNoExt  = LSLIPathHelper.RemoveExpandedSubExtension(Path.GetFileNameWithoutExtension(pathOfScript));
            string pathOfIncludeNoExt = LSLIPathHelper.RemoveExpandedSubExtension(Path.GetFileNameWithoutExtension(pathOfInclude));

            // Compare paths
            return(!pathOfScriptNoExt.EndsWith(pathOfIncludeNoExt));
        }
Example #3
0
        /// <summary>
        /// Call this to expand LSLI to LSL
        /// </summary>
        /// <param name="editForm"></param>
        /// <returns>LSL</returns>
        public string ExpandToLSL(EditForm editForm, bool ShowBeginEnd = true)
        {
            editForm.verboseQueue = new List <string>();
            this.editForm         = editForm;
            string strC         = editForm.SourceCode;
            string fullPathName = editForm.FullPathName;

            if (LSLIPathHelper.IsExpandedLSL(editForm.ScriptName))
            {
                // Collapse first, to ensure it is expanded showing or not showing begin/end.
                strC = CollapseToLSLI(strC);
                // Mimic LSLI file
                fullPathName = LSLIPathHelper.CreateCollapsedPathAndScriptName(fullPathName);
            }

            string sourceCode = ImportScripts(strC, fullPathName, ShowBeginEnd);

            return(sourceCode);
        }
Example #4
0
        /// <summary>
        /// Imports scripts from //#include statements
        /// </summary>
        /// <param name="strC">Sourcecode</param>
        /// <param name="pathOfScript">Path of the source code of the script</param>
        /// <returns>Sourcecode with imported scripts</returns>
        private string ImportScripts(string strC, string pathOfScript, bool ShowBeginEnd = true)
        {
            if (!LSLIPathHelper.IsLSLI(pathOfScript))
            {
                // If it's not an LSLI script, it can't import a script
                return(strC);
            }

            StringBuilder   sb        = new StringBuilder(strC);
            MatchCollection mIncludes = Regex.Matches(strC, INCLUDE_REGEX); // Find includes

            foreach (Match m in mIncludes)
            {
                if (this.includeDepth == 0)
                {
                    this.implementedIncludes = new List <string>();
                }
                includeDepth++;

                string line       = GetLineOfMatch(strC, m);
                int    lineNumber = strC.Take(m.Index + line.Length - 1).Count(c => c == '\n') + 1;

                string pathOfIncludeOriginal = Regex.Match(line, PATH_OF_INCLUDE_REGEX).Value.Trim('"');
                string pathOfInclude         = pathOfIncludeOriginal;
                string ext = Path.GetExtension(pathOfInclude).ToLower();

                if ((validExtensions.Contains(ext) || ext == "") && IsDifferentScript(pathOfInclude, pathOfScript))
                {
                    pathOfInclude = GetFilePath(pathOfInclude, pathOfScript);

                    if (pathOfInclude != "" && !this.implementedIncludes.Contains(Path.GetFullPath(pathOfInclude)))
                    {
                        if (!ShowBeginEnd)
                        {
                            sb = WriteExportScript(pathOfInclude, sb, line);
                        }
                        else
                        {
                            sb = WriteDebugScript(pathOfInclude, sb, line);
                        }
                    }
                    else if (pathOfInclude != "" && this.implementedIncludes.Contains(Path.GetFullPath(pathOfInclude)))
                    {
                        string message = "Error: Recursive include loop detected: \"" + Path.GetFullPath(pathOfInclude) +
                                         "\". In script \""
                                         + Path.GetFileName(pathOfScript) + "\". Line " + lineNumber + ".";

                        ShowError(message);
                    }
                    else
                    {
                        string relativeToPathOfScript = LSLIPathHelper.GetRelativePath(pathOfScript, Environment.CurrentDirectory);
                        string correctPath            = Path.GetFullPath(relativeToPathOfScript) + pathOfIncludeOriginal;
                        string message = "Error: Unable to find file \"" + correctPath +
                                         "\". In script \"" + Path.GetFileName(pathOfScript) + "\". Line " + lineNumber + ".";

                        ShowError(message);
                    }
                }
                includeDepth--;
                if (this.implementedIncludes.Count > 0)
                {
                    this.implementedIncludes.Remove(this.implementedIncludes.Last());
                }
            }

            return(sb.ToString());
        }