/// <summary> /// Prepares the DLL for the specified script, compiling it if necessary. /// </summary> /// <param name="scriptIdent">Script identifier.</param> /// <param name="projectPathName">Project file name, used for naming project-local /// files. May be empty if the project hasn't been named yet (in which case /// project-local files will cause a failure).</param> /// <param name="report">Report with errors and warnings.</param> /// <returns>Full path to DLL, or null if compilation failed.</returns> public static string GenerateScriptDll(string scriptIdent, string projectPathName, out FileLoadReport report) { ExternalFile ef = ExternalFile.CreateFromIdent(scriptIdent); if (ef == null) { Debug.Assert(false); report = new FileLoadReport("CreateFromIdent failed"); return(null); } string projectDir = string.Empty; if (!string.IsNullOrEmpty(projectPathName)) { projectDir = Path.GetDirectoryName(projectPathName); } string srcPathName = ef.GetPathName(projectDir); // Fail if the source script doesn't exist. If a previously-compiled DLL is present // we could just continue to use it, but that seems contrary to expectation, and // means that you won't notice that your project is broken until you clear out // the DLL directory. if (!File.Exists(srcPathName)) { report = new FileLoadReport(srcPathName); report.Add(FileLoadItem.Type.Error, string.Format(Properties.Resources.ERR_FILE_NOT_FOUND, srcPathName)); return(null); } string destFileName = ef.GenerateDllName(projectPathName); string destPathName = Path.Combine(GetPluginDirPath(), destFileName); // Compile if necessary. if (FileUtil.FileMissingOrOlder(destPathName, srcPathName)) { Debug.WriteLine("Compiling " + srcPathName + " to " + destPathName); Assembly asm = CompileCode(srcPathName, destPathName, out report); if (asm == null) { return(null); } } else { Debug.WriteLine("NOT recompiling " + srcPathName); report = new FileLoadReport(srcPathName); } return(destPathName); }
/// <summary> /// Prepares the DLL for the specified script, compiling it if necessary. /// </summary> /// <param name="scriptIdent">Script identifier.</param> /// <param name="projectPathName">Project file name, used for naming project-local /// files. May be empty if the project hasn't been named yet (in which case /// project-local files will cause a failure).</param> /// <param name="report">Report with errors and warnings.</param> /// <returns>Full path to DLL, or null if compilation failed.</returns> public static string GenerateScriptDll(string scriptIdent, string projectPathName, out FileLoadReport report) { ExternalFile ef = ExternalFile.CreateFromIdent(scriptIdent); if (ef == null) { Debug.Assert(false); report = new FileLoadReport("CreateFromIdent failed"); return(null); } string projectDir = string.Empty; if (!string.IsNullOrEmpty(projectPathName)) { projectDir = Path.GetDirectoryName(projectPathName); } string srcPathName = ef.GetPathName(projectDir); // Fail if the source script doesn't exist. If a previously-compiled DLL is present // we could just continue to use it, but that seems contrary to expectation, and // means that you won't notice that your project is broken until you clear out // the DLL directory. if (!File.Exists(srcPathName)) { report = new FileLoadReport(srcPathName); report.Add(FileLoadItem.Type.Error, string.Format(Res.Strings.ERR_FILE_NOT_FOUND_FMT, srcPathName)); return(null); } string destFileName = ef.GenerateDllName(projectPathName); string destPathName = Path.Combine(GetPluginDirPath(), destFileName); // Compile if necessary. We do this if the source code is newer, or if the // DLLs that plugins depend on have been updated. (We're checking the dates on // the DLLs the app uses, not the copy the plugins use, but earlier we made sure // that they were the same. This test doesn't handle the case where the DLLs // get rolled back, but that's probably not interesting for us.) bool needCompile = FileUtil.IsFileMissingOrOlder(destPathName, srcPathName) || FileUtil.IsFileMissingOrOlder(destPathName, typeof(PluginCommon.PluginManager).Assembly.Location) || FileUtil.IsFileMissingOrOlder(destPathName, typeof(CommonUtil.CRC32).Assembly.Location); if (needCompile) { Debug.WriteLine("Compiling " + srcPathName + " to " + destPathName); Assembly asm = CompileCode(srcPathName, destPathName, out report); if (asm == null) { return(null); } } else { Debug.WriteLine("NOT recompiling " + srcPathName); report = new FileLoadReport(srcPathName); } return(destPathName); }