Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Generates a human-readable summary of this system definition for display to
        /// the user.
        /// </summary>
        /// <returns>Multi-line string</returns>
        public string GetSummaryString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Description);
            sb.Append("\r\n\r\n");

            sb.AppendFormat(Properties.Resources.SETUP_SYSTEM_SUMMARY, Name, Cpu, Speed);

            if (SymbolFiles.Length > 0)
            {
                sb.Append("\r\n\r\n");
                sb.Append(Properties.Resources.INITIAL_SYMBOL_FILES);
                foreach (string str in SymbolFiles)
                {
                    sb.Append("\r\n  ");
                    ExternalFile ef = ExternalFile.CreateFromIdent(str);
                    if (ef == null)
                    {
                        // Shouldn't happen unless somebody botches an edit.
                        sb.Append("[INVALID] " + str);
                    }
                    else
                    {
                        sb.Append(ef.GetInnards());
                    }
                }
            }

            if (ExtensionScripts.Length > 0)
            {
                sb.Append("\r\n\r\n");
                sb.Append(Properties.Resources.INITIAL_EXTENSION_SCRIPTS);
                foreach (string str in ExtensionScripts)
                {
                    sb.Append("\r\n  ");
                    ExternalFile ef = ExternalFile.CreateFromIdent(str);
                    if (ef == null)
                    {
                        // Shouldn't happen unless somebody botches an edit.
                        sb.Append("[INVALID] " + str);
                    }
                    else
                    {
                        sb.Append(ef.GetInnards());
                    }
                }
            }

            if (Parameters.Count > 0)
            {
                sb.Append("\r\n\r\n");
                sb.Append(Properties.Resources.INITIAL_PARAMETERS);
                foreach (KeyValuePair <string, string> kvp in Parameters)
                {
                    sb.Append("\r\n  ");
                    sb.Append(kvp.Key);
                    sb.Append(" = ");
                    sb.Append(kvp.Value);
                }
            }

            return(sb.ToString());
        }
Beispiel #3
0
        /// <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);
        }