Exemplo n.º 1
0
        public void DifferentDrives()
        {
            string path     = @"C:\Temp";
            string filename = @"D:\file.txt";

            Assert.That(RelativePaths.RelativeToAbsolutePath(path, filename), Is.EqualTo("D:\\file.txt"));
        }
Exemplo n.º 2
0
        public void Save(string file, IWorkbenchProject project)
        {
            XmlDocument doc      = new XmlDocument();
            XmlNode     rootNode = doc.CreateElement("appconfig");

            doc.AppendChild(rootNode);

            XmlNode node = doc.CreateElement("projectpath");

            node.InnerText = RelativePaths.GetRelativePath(Path.GetDirectoryName(project.ProjectFile), OutputPath);
            rootNode.AppendChild(node);

            node = doc.CreateElement("templatefilename");

            node.InnerText = project.GetPathRelativeToProjectFile(TemplateFileName);
            rootNode.AppendChild(node);

            node           = doc.CreateElement("guid");
            node.InnerText = ProjectGuid.ToString("B");
            rootNode.AppendChild(node);

            node           = doc.CreateElement("user-template-name");
            node.InnerText = UserTemplateName;
            rootNode.AppendChild(node);

            doc.Save(file);
        }
Exemplo n.º 3
0
        public void OneDirectoryDown()
        {
            string path     = @"C:\Temp";
            string filename = @"C:\Temp\T\file.txt";

            Assert.That(RelativePaths.RelativeToAbsolutePath(path, filename), Is.EqualTo(@"C:\Temp\T\file.txt"));
        }
Exemplo n.º 4
0
        public void OneDirectoryUp()
        {
            string path     = @"C:\Temp";
            string filename = @"C:\file.txt";

            Assert.That(RelativePaths.GetRelativePath(path, filename), Is.EqualTo("..\\file.txt"));
        }
Exemplo n.º 5
0
        public static string GetHelpFile(string helpFileName)
        {
#if DEBUG
            return(Path.Combine(RelativePaths.GetFullPath(Path.GetDirectoryName(Application.ExecutablePath), "../../../Help"), helpFileName));
#else
            return(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), helpFileName));
#endif
        }
Exemplo n.º 6
0
        public static string GetRelativeFilenameForEntityCSharpFile(Entity entity, string csprojFullFilePath)
        {
            if (entity.MappedClass != null)
            {
                var filename = entity.EntitySet.MappingSet.CodeParseResults.GetFilenameForParsedClass(entity.MappedClass);

                // filename is absolute, reduce it to relative to the .csproj file path
                return(RelativePaths.GetRelativePath(Path.GetDirectoryName(csprojFullFilePath), filename, false));
            }

            return(Path.Combine("Model", entity.Name + ".cs"));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Builds a dictionary mapping game file paths to our own mods' file paths, if available.
        /// </summary>
        /// <param name="modConfigurations">Stores the individual modification details and configuration.</param>
        /// <param name="currentGameConfig">The current game configuration, used to let us know the base directory of the game.</param>
        private static void BuildFileRedirectionDictionary(List <ModConfig> modConfigurations, GameConfig currentGameConfig)
        {
            // Instance dictionary.
            // OrdinalIgnoreCase = Ignore capitals/smalls in paths, we later want no case sensitivity when mapping A to B.
            Dictionary <string, string> localRemapperDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // Enumerate over all mods, iterating over their directories.
            foreach (var modConfiguration in modConfigurations)
            {
                // The location of the folder for game files to be redirected to.
                string redirectonFolder = Path.GetDirectoryName(modConfiguration.ModLocation) + "\\Plugins\\Redirector";

                // Ignore mods not utilising this.
                if (Directory.Exists(redirectonFolder))
                {
                    // Retrieve a listing of all files relative to this directory.
                    List <string> allModFiles = RelativePaths.GetRelativeFilePaths(redirectonFolder);

                    // Process all files.
                    foreach (string modFile in allModFiles)
                    {
                        // Get the absolute location of the file as if it were in the game directory (file we are replacing)
                        // Get the absolute location of the file we will be replacing that file with.
                        string gameLocation    = currentGameConfig.GameDirectory + modFile;
                        string modFileLocation = redirectonFolder + modFile;

                        // Removes inconsistencies such as backslash direction, other formatting symantics to ensure matches.
                        gameLocation    = Path.GetFullPath(gameLocation);
                        modFileLocation = Path.GetFullPath(modFileLocation);

                        // Appends to the file path replacement dictionary.
                        localRemapperDictionary[gameLocation] = modFileLocation;
                    }

                    // Setup event based, realtime file addition/removal as new files are removed or added if not setup.
                    if (!_fileSystemWatcherDictionary.ContainsKey(modConfiguration)) // Ensure this is only done once.
                    {
                        FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(redirectonFolder);
                        fileSystemWatcher.EnableRaisingEvents   = true;
                        fileSystemWatcher.IncludeSubdirectories = true;
                        fileSystemWatcher.Created += (sender, args) => { BuildFileRedirectionDictionary(modConfigurations, currentGameConfig); };
                        fileSystemWatcher.Deleted += (sender, args) => { BuildFileRedirectionDictionary(modConfigurations, currentGameConfig); };
                        fileSystemWatcher.Renamed += (sender, args) => { BuildFileRedirectionDictionary(modConfigurations, currentGameConfig); };
                        _fileSystemWatcherDictionary.Add(modConfiguration, fileSystemWatcher);
                    }
                }
            }

            // Assign dictionary.
            _remapperDictionary = localRemapperDictionary;
        }
Exemplo n.º 8
0
        private RelativePaths Refine(string rootPath, string frameworkPath, string testSuiteFile)
        {
            if (!Path.IsPathRooted(rootPath))
            {
                throw new ArgumentException();
            }

            if (!rootPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                rootPath += Path.DirectorySeparatorChar.ToString();
            }

            if (!frameworkPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                frameworkPath += Path.DirectorySeparatorChar.ToString();
            }

            if (!testSuiteFile.StartsWith(rootPath) && !Path.IsPathRooted(testSuiteFile))
            {
                throw new ArgumentException();
            }

            if (!frameworkPath.StartsWith(rootPath) && !Path.IsPathRooted(frameworkPath))
            {
                throw new ArgumentException();
            }

            var testSuitePath = Path.GetDirectoryName(testSuiteFile) + Path.DirectorySeparatorChar.ToString();

            var relative = new RelativePaths();

            int upDirectory = testSuiteFile.Remove(0, rootPath.Length).Count(c => c == Path.DirectorySeparatorChar);

            for (int i = 0; i < upDirectory; i++)
            {
                relative.Root += ".." + Path.DirectorySeparatorChar;
            }

            if (relative.Root == null)
            {
                relative.Root = string.Empty;
            }

            relative.Framework = frameworkPath.Remove(0, rootPath.Length);
            relative.TestSuite = testSuitePath.Remove(0, rootPath.Length);
            relative.Base      = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(testSuiteFile), relative.Root));
            relative.Filename  = Path.GetFileNameWithoutExtension(testSuiteFile);

            return(relative);
        }
        /// <summary>
        /// Returns an array of relative paths of enabled items such that they can be
        /// stored in config files for later retrieval using <see cref="GetItems{TItem}(IEnumerable{Reloaded.Mod.Loader.IO.Structs.PathGenericTuple{TItem}})"/>.
        /// </summary>
        public List <string> GetRelativePaths <TItem>(IEnumerable <EnabledPathGenericTuple <TItem> > items)
        {
            var enabledModRelativePaths = new List <string>(items.Count());

            foreach (var item in items)
            {
                if (item.IsEnabled)
                {
                    string relativePath = RelativePaths.GetRelativePath(item.Path, ItemDirectory);
                    enabledModRelativePaths.Add(relativePath);
                }
            }

            return(enabledModRelativePaths);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generates a Reloaded Steam shim for the currently selected game.
        /// </summary>
        public static void GenerateShim()
        {
            // Get file names and paths.
            string shimExecutableName = Path.GetFileName(Global.CurrentGameConfig.ExecutableLocation);
            string shimOutputLocation = Path.GetTempPath() + "\\Reloaded-Temp-Steam-Shim";

            // Check if exe name is correct.
            if (shimExecutableName == "")
            {
                MessageBox.Show("Failed to generate Steam Shim\n" +
                                "Your executable name may be empty or profile not saved.");
                return;
            }

            // Generate instructions.
            string instructions = $"Using the pseudo-launcher as a game's basic launcher replacement (for some games that can only be launched via launcher):\r\n" +
                                  $"1. Rename the pseudo-launcher executable name \"{shimExecutableName}\" to the name of the game's default launcher (e.g. SteamLauncher.exe)\r\n" +
                                  $"2. Replace the game's launcher executable with the shim executable.\r\n" +
                                  $"3. Create (if you haven't already), individual game profiles for individual executables the default launcher would launch e.g. Shenmue.exe, Shenmue2.exe\r\n" +
                                  "Result: If done correctly, when launching the game, you will get a prompt asking\r\n" +
                                  "which game to launch via Reloaded if there is more than 1 game. Else the only game will be launched directly.\r\n\r\n" +
                                  $"-----------------------------------------------------------------------------------------\r\n\r\n" +
                                  $"Using the pseudo-launcher to trick Steam API:\r\n" +
                                  $"1. Rename {Global.CurrentGameConfig.ExecutableLocation} to a different name e.g. {Global.CurrentGameConfig.ExecutableLocation.Replace(".exe", "-Reloaded.exe")}\r\n" +
                                  $"2. Set the new executable path for the game to the changed path, e.g. {Global.CurrentGameConfig.ExecutableLocation.Replace(".exe", "-Reloaded.exe")} in Reloaded-Launcher.\r\n" +
                                  $"3. Copy Reloaded's Pseudo-launcher \"{shimExecutableName}\" to the place of the old executable {Global.CurrentGameConfig.ExecutableLocation}\r\n" +
                                  $"Result: You can now launch games directly through Steam and Reloaded mods still are applied.\r\n\r\n" +

                                  "With Steam games, note that after Steam updates, or verifying game files you may have to redo this process.\r\n" +
                                  "For more information refer to Reloaded's Github readme pages/wiki.\r\n" +
                                  "You should delete this folder when you are done.";

            // Output everything to disc.
            Directory.CreateDirectory(shimOutputLocation);
            File.WriteAllText($"{shimOutputLocation}\\Instructions.txt", instructions);
            RelativePaths.CopyByRelativePath($"{LoaderPaths.GetTemplatesDirectory()}\\Steam-Shim", shimOutputLocation, RelativePaths.FileCopyMethod.Copy, true);

            if (File.Exists($"{shimOutputLocation}\\{shimExecutableName}"))
            {
                File.Delete($"{shimOutputLocation}\\{shimExecutableName}");
            }
            File.Move($"{shimOutputLocation}\\Reloaded-Steam-Shim.exe", $"{shimOutputLocation}\\{shimExecutableName}");

            // Open directory in explorer.
            Process.Start($"{shimOutputLocation}");
        }
Exemplo n.º 11
0
        public void Open(string file, IWorkbenchProject project)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(file);

            string relativePath = doc.SelectSingleNode("appconfig/projectpath").InnerText;

            OutputPath = RelativePaths.GetFullPath(Path.GetDirectoryName(project.ProjectFile), relativePath);

            string templateFile = doc.SelectSingleNode("appconfig/templatefilename").InnerText;

            templateFile = project.GetPathAbsoluteFromProjectFile(templateFile);

            if (!File.Exists(templateFile))
            {
#if DEBUG
                templateFile = Slyce.Common.RelativePaths.RelativeToAbsolutePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace(@"file:///", "")), @"..\..\..\ArchAngel.Templates\NHibernate\Template\NHibernate.AAT.DLL");
#else
                templateFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace(@"file:///", "")), Path.GetFileName(templateFile));
#endif
            }
            TemplateFileName = templateFile;

            XmlNode node = doc.SelectSingleNode("appconfig/guid");
            if (node != null)
            {
                ProjectGuid = new Guid(node.InnerText);
            }
            else
            {
                ProjectGuid = Guid.NewGuid();
            }

            XmlNode userTemplateNode = doc.SelectSingleNode("appconfig/user-template-name");
            if (userTemplateNode != null)
            {
                UserTemplateName = userTemplateNode.InnerText;
            }
            else
            {
                UserTemplateName = "Default NHibernate";
            }
        }
        /* Setup the dictionary of file redirections. */
        private void SetupFileRedirects()
        {
            if (Directory.Exists(RedirectFolder))
            {
                var redirects   = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                var allModFiles = RelativePaths.GetRelativeFilePaths(RedirectFolder);
                var appConfig   = Program.ModLoader.GetAppConfig();

                foreach (string modFile in allModFiles)
                {
                    string applicationFileLocation = GetSourceFolderPath(appConfig, SourceFolder) + modFile;
                    string modFileLocation         = RedirectFolder + modFile;
                    applicationFileLocation = Path.GetFullPath(applicationFileLocation);
                    modFileLocation         = Path.GetFullPath(modFileLocation);

                    redirects[applicationFileLocation] = modFileLocation;
                }

                FileRedirects = redirects;
            }
        }
Exemplo n.º 13
0
        public static string GetProjectFilesFolder(string projectFilename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(projectFilename);

            string folder = GetProjectFilesDirectoryName(projectFilename);

            if (!Directory.Exists(RelativePaths.RelativeToAbsolutePath(Path.GetDirectoryName(projectFilename), folder)))
            {
                try
                {
                    NodeProcessor proc = new NodeProcessor(doc.DocumentElement);
                    folder = proc.GetString("Folder");
                }
                catch
                {
                    throw new Exception("Files folder not found for this project.\nIf your project file is called 'xyz.wbproj' then the files folder should be called 'xyz_files'.");
                }
            }
            return(RelativePaths.RelativeToAbsolutePath(Path.GetDirectoryName(projectFilename), folder));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Copies the default Mod Loader configuration and theme files upon first launch.
        /// </summary>
        private void CopyDefaultFiles()
        {
            // Copy without replacement.
            // Source directory = App Directory
            string sourceDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Files";
            string targetDirectory = LoaderPaths.GetModLoaderDirectory();

            // Copy without replacement.
            // Source directory = App Directory
            string sourceDirectoryDefaultMods = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Default-Mods";
            string targetDirectoryDefaultMods = LoaderPaths.GetGlobalModDirectory();

            try
            {
                RelativePaths.CopyByRelativePath(sourceDirectory, targetDirectory, RelativePaths.FileCopyMethod.Copy, false);
                RelativePaths.CopyByRelativePath(sourceDirectoryDefaultMods, targetDirectoryDefaultMods, RelativePaths.FileCopyMethod.Copy, true);

                // Nuke remaining files.
                Directory.Delete(sourceDirectory, true);
                Directory.Delete(sourceDirectoryDefaultMods, true);
            }
            catch (Exception)
            { /* ¯\_(ツ)_/¯ */ }
        }
Exemplo n.º 15
0
 public string GetRelativeDebugProjectFile()
 {
     return(RelativePaths.GetRelativePath(Path.GetDirectoryName(ProjectFileName), DebugProjectFile));
 }
Exemplo n.º 16
0
 public string GetFullPath(string pathRelativeToProjectFile)
 {
     return(RelativePaths.GetFullPath(ProjectFileName, pathRelativeToProjectFile));
 }
Exemplo n.º 17
0
        /// <summary>
        /// Copies the default Mod Loader configuration and theme files upon first launch.
        /// </summary>
        private void CopyDefaultFiles()
        {
            // Copy without replacement.
            // Source directory = App Directory
            string sourceDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultConfigFolder}";
            string targetDirectory = LoaderPaths.GetModLoaderDirectory();

            // Copy without replacement.
            // Source directory = App Directory
            string sourceDirectoryDefaultPlugins = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultPluginsFolder}";
            string targetDirectoryDefaultPlugins = LoaderPaths.GetPluginsDirectory();

            string sourceDirectoryDefaultMods = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultModsFolder}";
            string targetDirectoryDefaultMods = LoaderPaths.GetGlobalModDirectory();

            string sourceDirectoryDefaultTemplates = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + $"\\{Strings.Launcher.CopyOnLaunchFolders.DefaultTemplatesFolder}";
            string targetDirectoryDefaultTemplates = LoaderPaths.GetTemplatesDirectory();

            // Files
            try
            {
                RelativePaths.CopyByRelativePath(sourceDirectory, targetDirectory, RelativePaths.FileCopyMethod.Copy, false, true);
                Directory.Delete(sourceDirectory, true);
            }
            catch (Exception)
            { /* ¯\_(ツ)_/¯ */ }

            // Mods
            try
            {
                RelativePaths.CopyByRelativePath(sourceDirectoryDefaultMods, targetDirectoryDefaultMods, RelativePaths.FileCopyMethod.Copy, true, true);

                // We want to avoid deleting symbols.
                #if DEBUG
                // Do nothing.
                #else
                // Delete default mods directory.
                Directory.Delete(sourceDirectoryDefaultMods, true);
                #endif
            }
            catch (Exception)
            { /* ¯\_(ツ)_/¯ */ }

            // Plugins
            try
            {
                RelativePaths.CopyByRelativePath(sourceDirectoryDefaultPlugins, targetDirectoryDefaultPlugins, RelativePaths.FileCopyMethod.Copy, true, true);

                #if DEBUG
                // Do nothing.
                #else
                // Delete default plugins directory.
                Directory.Delete(sourceDirectoryDefaultPlugins, true);
                #endif
            }
            catch (Exception)
            { /* ¯\_(ツ)_/¯ */ }

            // Templates
            try
            {
                RelativePaths.CopyByRelativePath(sourceDirectoryDefaultTemplates, targetDirectoryDefaultTemplates, RelativePaths.FileCopyMethod.Copy, true, true);

                #if DEBUG
                // Do nothing.
                #else
                // Delete default plugins directory.
                Directory.Delete(sourceDirectoryDefaultPlugins, true);
                #endif
            }
            catch (Exception)
            { /* ¯\_(ツ)_/¯ */ }
        }
Exemplo n.º 18
0
 public string GetPathRelativeToProjectFile(string absolutePath)
 {
     return(RelativePaths.GetRelativePath(Path.GetDirectoryName(ProjectFileName), absolutePath));
 }
Exemplo n.º 19
0
        private bool ProcessScriptObject(object scriptObject, string folderName, IScript script, ProjectFileTreeNode parentNode)
        {
            bool   success    = true;
            string scriptName = UpdateScriptName(scriptObject, script);
            string fileName   = Path.Combine(folderName, scriptName);

            _Loader.SetGeneratedFileNameOnTemplate(Path.Combine(_Project.ProjectSettings.OutputPath, fileName));

            if (scriptName.IndexOf("#") >= 0)
            {
                success = false;
            }
            if (success)
            {
                TextFileInformation fileInfo = new TextFileInformation();
                fileInfo.RelativeFilePath = fileName;

                try
                {
                    // Reset the SkipCurrentFile and CurrentFileName variable
                    _Loader.CallTemplateFunction(TemplateHelper.ResetSkipCurrentFileFunctionName);
                    _Loader.CallTemplateFunction(TemplateHelper.ResetCurrentFileNameFunctionName);
                    // Call the script file function to get the file text body
                    object[] parameters = new[] { scriptObject };
                    // Check whether we must skip the current file
                    string templateOutput = (string)_Loader.CallTemplateFunction(script.ScriptName, ref parameters);

                    if (_ProgressHelper.IsCancellationPending())
                    {
                        return(false);
                    }

                    bool skipCurrentFile = (bool)_Loader.CallTemplateFunction(TemplateHelper.GetSkipCurrentFileFunctionName);

                    if (!skipCurrentFile)
                    {
                        templateOutput = Utility.StandardizeLineBreaks(templateOutput, Utility.LineBreaks.Windows);

                        string codeInsertionFilename =
                            (string)_Loader.CallTemplateFunction(TemplateHelper.GetCurrentFileNameFunctionName);

                        if (string.IsNullOrEmpty(codeInsertionFilename))
                        {
                            string fullPath = Path.Combine(absoluteBasePath, fileName);
                            _FileController.WriteAllText(fullPath, templateOutput);

                            // The file has successfully been written - add it to the GeneratedFiles
                            _Project.AddGeneratedFile(new GeneratedFile(script.FileName, fullPath, fileName, script.ScriptName, script.IteratorName));

                            // Set the NewGen text to point to that file.
                            fileInfo.NewGenFile = new TextFile(fullPath, false);

                            string        versionNumberString = _Loader.GetAssemblyVersionNumber();
                            VersionNumber versionNumber;
                            if (VersionNumber.TryParse(versionNumberString, out versionNumber))
                            {
                                // Get the template language from the template function.
                                string templateLanguageString = _Loader.GetTemplateFunctionLanguage(script.ScriptName);
                                try
                                {
                                    fileInfo.TemplateLanguage = SyntaxEditorHelper.LanguageEnumFromName(templateLanguageString);
                                }
                                catch (NotImplementedException)
                                {
                                    fileInfo.TemplateLanguage = null;
                                }
                            }

                            if (addToProjectFileTree)
                            {
                                parentNode.AddChildNode(fileInfo, scriptName);
                            }
                        }
                        else
                        {
                            // Code insertions were performed. Need to update a node in the tree.
                            // expand the path
                            if (Path.IsPathRooted(codeInsertionFilename) == false)
                            {
                                codeInsertionFilename = RelativePaths.RelativeToAbsolutePath(absoluteBasePath, codeInsertionFilename);
                            }
                            codeInsertionFilename = _FileController.GetFullPath(codeInsertionFilename);

                            // Get the relative path
                            string relativeCodeInsertionFilename = RelativePaths.GetRelativePath(_Project.ProjectSettings.OutputPath, codeInsertionFilename);

                            // If the file is not under the output path, then reset it to the full path
                            if (relativeCodeInsertionFilename.StartsWith(".."))
                            {
                                relativeCodeInsertionFilename = codeInsertionFilename;

                                // We need to add its folder as a root node of the tree
                                if (!parentNode.IsTreeRoot)
                                {
                                    parentNode = parentNode.ParentTree;
                                }
                            }

                            fileInfo.RelativeFilePath = relativeCodeInsertionFilename;
                            string relPathStart = "." + Path.DirectorySeparatorChar;

                            if (fileInfo.RelativeFilePath.StartsWith(relPathStart))
                            {
                                fileInfo.RelativeFilePath = fileInfo.RelativeFilePath.Substring(2);
                            }

                            if (addToProjectFileTree)
                            {
                                ProjectFileTree tree;

                                if (!parentNode.IsTreeRoot)
                                {
                                    tree = parentNode.ParentTree;
                                }
                                else
                                {
                                    tree = (ProjectFileTree)parentNode;
                                }

                                var possibleNode = tree.GetNodeAtPath(codeInsertionFilename);

                                if (possibleNode == null)
                                {
                                    // Need to create this node.


                                    // Create the node and it's parent folders if need be
                                    var node = tree.CreateFileNodeForPath(relativeCodeInsertionFilename);
                                    node.AssociatedFile = fileInfo;
                                }
                                else
                                {
                                    // Update the NewGen text, don't add it to the generated files list.
                                    fileInfo = possibleNode.AssociatedFile as TextFileInformation;
                                    if (fileInfo == null)
                                    {
                                        throw new NotSupportedException("Cannot code merge a binary file");
                                    }
                                }
                            }
                            else
                            {
                                // Write the file to disk
                                _FileController.WriteAllText(codeInsertionFilename, templateOutput);
                            }

                            fileInfo.NewGenFile = new TextFile(templateOutput);
                        }

                        AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1);
                    }
                }
                catch (TemplateFunctionException ex)
                {
                    success = false;
                    string message = "<span class='error'>" + ex.Message + "</span>";

                    if (ex.InnerException != null)
                    {
                        message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" +
                                   Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) +
                                   Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite;
                    }
                    RaiseTemplateFunctionCallErrorEvent(ex);
                    // Do nothing, just skip the file because the error will get reported to the user.
                    if (addToProjectFileTree)
                    {
                        parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message);
                    }
                }
                catch (Exception ex)
                {
                    string message = "<span class='error'>" + ex.Message + "</span>";

                    if (ex.InnerException != null)
                    {
                        message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" +
                                   Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) +
                                   Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite;
                    }

                    if (addToProjectFileTree)
                    {
                        parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message);
                    }
                    // Make sure any other type of exception gets thrown
                    throw;
                }
            }
            return(success);
        }