Esempio n. 1
0
        public static void LoadDefault(string strDirPath, PlgxPluginInfo plgxOutInfo)
        {
            if (plgxOutInfo == null)
            {
                throw new ArgumentNullException("plgxOutInfo");
            }

            List <string> lCsproj = UrlUtil.GetFilePaths(strDirPath, "*.csproj",
                                                         SearchOption.AllDirectories);

            if (lCsproj.Count == 1)
            {
                plgxOutInfo.ProjectType = PlgxProjectType.CSharp;
                PlgxCsprojLoader.Load(lCsproj[0], plgxOutInfo);
                return;
            }

            // List<string> lVbproj = UrlUtil.GetFilePaths(strDirPath, "*.vbproj",
            //	SearchOption.AllDirectories);
            // if(lVbproj.Count == 1)
            // {
            //	plgxOutInfo.ProjectType = PlgxProjectType.VisualBasic;
            //	PlgxCsprojLoader.Load(lVbproj[0], plgxOutInfo);
            //	return;
            // }

            throw new InvalidOperationException(KPRes.CsprojCountError);
        }
Esempio n. 2
0
        public static void LoadDefault(string strDirPath, PlgxPluginInfo plgxOutInfo)
        {
            if (plgxOutInfo == null)
            {
                throw new ArgumentNullException("plgxOutInfo");
            }

            string[] vCsproj = Directory.GetFiles(strDirPath, "*.csproj",
                                                  SearchOption.AllDirectories);
            if ((vCsproj != null) && (vCsproj.Length == 1))
            {
                plgxOutInfo.ProjectType = PlgxProjectType.CSharp;
                PlgxCsprojLoader.Load(vCsproj[0], plgxOutInfo);
                return;
            }

            // string[] vVbproj = Directory.GetFiles(strDirPath, "*.vbproj",
            //	SearchOption.AllDirectories);
            // if((vVbproj != null) && (vVbproj.Length == 1))
            // {
            //	plgxOutInfo.ProjectType = PlgxProjectType.VisualBasic;
            //	PlgxCsprojLoader.Load(vVbproj[0], plgxOutInfo);
            //	return;
            // }

            throw new InvalidOperationException(KPRes.CsprojCountError);
        }
Esempio n. 3
0
        private static string Compile(string strTmpRoot, PlgxPluginInfo plgx,
                                      string strBuildPre, string strBuildPost)
        {
            if (strTmpRoot == null)
            {
                Debug.Assert(false); return(null);
            }

            RunBuildCommand(strBuildPre, UrlUtil.EnsureTerminatingSeparator(
                                strTmpRoot, false), null);

            PlgxCsprojLoader.LoadDefault(strTmpRoot, plgx);

            List <string> vCustomRefs = new List <string>();

            foreach (string strIncRefAsm in plgx.IncludedReferencedAssemblies)
            {
                string strSrcAsm = plgx.GetAbsPath(UrlUtil.ConvertSeparators(
                                                       strIncRefAsm));
                string strCached = PlgxCache.AddCacheFile(strSrcAsm, plgx);
                if (string.IsNullOrEmpty(strCached))
                {
                    throw new InvalidOperationException();
                }
                vCustomRefs.Add(strCached);
            }

            CompilerParameters cp = plgx.CompilerParameters;

            cp.OutputAssembly = UrlUtil.EnsureTerminatingSeparator(strTmpRoot, false) +
                                UrlUtil.GetFileName(PlgxCache.GetCacheFile(plgx, false, false));
            cp.GenerateExecutable      = false;
            cp.GenerateInMemory        = false;
            cp.IncludeDebugInformation = false;
            cp.TreatWarningsAsErrors   = false;
            cp.ReferencedAssemblies.Add(WinUtil.GetExecutable());
            foreach (string strCustomRef in vCustomRefs)
            {
                cp.ReferencedAssemblies.Add(strCustomRef);
            }

            cp.CompilerOptions = "-define:" + GetDefines();

            CompileEmbeddedRes(plgx);
            PrepareSourceFiles(plgx);

            string[] vCompilers;
            Version  vClr = Environment.Version;
            int      iClrMajor = vClr.Major, iClrMinor = vClr.Minor;

            if ((iClrMajor >= 5) || ((iClrMajor == 4) && (iClrMinor >= 5)))
            {
                vCompilers = new string[] {
                    null,
                    "v4.5",
                    "v4",                     // Suggested in CodeDomProvider.CreateProvider doc
                    "v4.0",                   // Suggested in community content of the above
                    "v4.0.30319",             // Deduced from file system
                    "v3.5"
                };
            }
            else if (iClrMajor == 4)            // 4.0
            {
                vCompilers = new string[] {
                    null,
                    "v4",                     // Suggested in CodeDomProvider.CreateProvider doc
                    "v4.0",                   // Suggested in community content of the above
                    "v4.0.30319",             // Deduced from file system
                    "v4.5",
                    "v3.5"
                };
            }
            else             // <= 3.5
            {
                vCompilers = new string[] {
                    null,
                    "v3.5",
                    "v4",                     // Suggested in CodeDomProvider.CreateProvider doc
                    "v4.0",                   // Suggested in community content of the above
                    "v4.0.30319",             // Deduced from file system
                    "v4.5"
                };
            }

            CompilerResults cr            = null;
            StringBuilder   sbCompilerLog = new StringBuilder();
            bool            bCompiled     = false;

            for (int iCmp = 0; iCmp < vCompilers.Length; ++iCmp)
            {
                if (CompileAssembly(plgx, out cr, vCompilers[iCmp]))
                {
                    bCompiled = true;
                    break;
                }

                if (cr != null)
                {
                    AppendCompilerResults(sbCompilerLog, vCompilers[iCmp], cr);
                }
            }

            if (!bCompiled)
            {
                if (Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null)
                {
                    SaveCompilerResults(plgx, sbCompilerLog);
                }

                throw new InvalidOperationException();
            }

            Program.TempFilesPool.Add(cr.PathToAssembly);

            Debug.Assert(cr.PathToAssembly == cp.OutputAssembly);
            string strCacheAsm = PlgxCache.AddCacheAssembly(cr.PathToAssembly, plgx);

            RunBuildCommand(strBuildPost, UrlUtil.EnsureTerminatingSeparator(
                                strTmpRoot, false), UrlUtil.GetFileDirectory(strCacheAsm, true, false));

            return(strCacheAsm);
        }
Esempio n. 4
0
        private static void CreateFromDirectory(string strDirPath)
        {
            string strPlgx = strDirPath + "." + PlgxExtension;

            PlgxPluginInfo plgx = new PlgxPluginInfo(false, true, true);

            PlgxCsprojLoader.LoadDefault(strDirPath, plgx);

            FileStream fs = new FileStream(strPlgx, FileMode.Create,
                                           FileAccess.Write, FileShare.None);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(PlgxSignature1);
            bw.Write(PlgxSignature2);
            bw.Write(PlgxVersion);
            WriteObject(bw, PlgxFileUuid, (new PwUuid(true)).UuidBytes);
            WriteObject(bw, PlgxBaseFileName, StrUtil.Utf8.GetBytes(
                            plgx.BaseFileName));
            WriteObject(bw, PlgxCreationTime, StrUtil.Utf8.GetBytes(
                            TimeUtil.SerializeUtc(DateTime.UtcNow)));
            WriteObject(bw, PlgxGeneratorName, StrUtil.Utf8.GetBytes(
                            PwDefs.ShortProductName));
            WriteObject(bw, PlgxGeneratorVersion, MemUtil.UInt64ToBytes(
                            PwDefs.FileVersion64));

            string strKP = Program.CommandLineArgs[AppDefs.CommandLineOptions.PlgxPrereqKP];

            if (!string.IsNullOrEmpty(strKP))
            {
                ulong uKP = StrUtil.ParseVersion(strKP);
                if (uKP != 0)
                {
                    WriteObject(bw, PlgxPrereqKP, MemUtil.UInt64ToBytes(uKP));
                }
            }

            string strNet = Program.CommandLineArgs[AppDefs.CommandLineOptions.PlgxPrereqNet];

            if (!string.IsNullOrEmpty(strNet))
            {
                ulong uNet = StrUtil.ParseVersion(strNet);
                if (uNet != 0)
                {
                    WriteObject(bw, PlgxPrereqNet, MemUtil.UInt64ToBytes(uNet));
                }
            }

            string strOS = Program.CommandLineArgs[AppDefs.CommandLineOptions.PlgxPrereqOS];

            if (!string.IsNullOrEmpty(strOS))
            {
                WriteObject(bw, PlgxPrereqOS, StrUtil.Utf8.GetBytes(strOS));
            }

            string strPtr = Program.CommandLineArgs[AppDefs.CommandLineOptions.PlgxPrereqPtr];

            if (!string.IsNullOrEmpty(strPtr))
            {
                uint uPtr;
                if (uint.TryParse(strPtr, out uPtr))
                {
                    WriteObject(bw, PlgxPrereqPtr, MemUtil.UInt32ToBytes(uPtr));
                }
            }

            string strBuildPre = Program.CommandLineArgs[AppDefs.CommandLineOptions.PlgxBuildPre];

            if (!string.IsNullOrEmpty(strBuildPre))
            {
                WriteObject(bw, PlgxBuildPre, StrUtil.Utf8.GetBytes(strBuildPre));
            }

            string strBuildPost = Program.CommandLineArgs[AppDefs.CommandLineOptions.PlgxBuildPost];

            if (!string.IsNullOrEmpty(strBuildPost))
            {
                WriteObject(bw, PlgxBuildPost, StrUtil.Utf8.GetBytes(strBuildPost));
            }

            WriteObject(bw, PlgxBeginContent, null);

            RecursiveFileAdd(bw, strDirPath, new DirectoryInfo(strDirPath));

            WriteObject(bw, PlgxEndContent, null);
            WriteObject(bw, PlgxEOF, null);

            bw.Close();
            fs.Close();

            // Test loading not possible, because MainForm not available
            // PlgxPlugin.Load(strPlgx);
        }
Esempio n. 5
0
        private static string Compile(string strTmpRoot, PlgxPluginInfo plgx,
                                      string strBuildPre, string strBuildPost)
        {
            if (strTmpRoot == null)
            {
                Debug.Assert(false); return(null);
            }

            RunBuildCommand(strBuildPre, UrlUtil.EnsureTerminatingSeparator(
                                strTmpRoot, false), null);

            PlgxCsprojLoader.LoadDefault(strTmpRoot, plgx);

            List <string> vCustomRefs = new List <string>();

            foreach (string strIncRefAsm in plgx.IncludedReferencedAssemblies)
            {
                string strSrcAsm = plgx.GetAbsPath(UrlUtil.ConvertSeparators(
                                                       strIncRefAsm));
                string strCached = PlgxCache.AddCacheFile(strSrcAsm, plgx);
                if (string.IsNullOrEmpty(strCached))
                {
                    throw new InvalidOperationException();
                }
                vCustomRefs.Add(strCached);
            }

            CompilerParameters cp = plgx.CompilerParameters;

            cp.OutputAssembly = UrlUtil.EnsureTerminatingSeparator(strTmpRoot,
                                                                   false) + UrlUtil.GetFileName(PlgxCache.GetCacheFile(plgx.FileUuid,
                                                                                                                       false, false));
            cp.GenerateExecutable      = false;
            cp.GenerateInMemory        = false;
            cp.IncludeDebugInformation = false;
            cp.TreatWarningsAsErrors   = false;
            cp.ReferencedAssemblies.Add(WinUtil.GetExecutable());
            foreach (string strCustomRef in vCustomRefs)
            {
                cp.ReferencedAssemblies.Add(strCustomRef);
            }

            CompileEmbeddedRes(plgx);
            PrepareSourceFiles(plgx);

            CompilerResults cr;

            if (!CompileAssembly(plgx, out cr, null))
            {
                if (!CompileAssembly(plgx, out cr, "v3.5"))
                {
                    throw new InvalidOperationException();
                }
            }

            Program.TempFilesPool.Add(cr.PathToAssembly);

            Debug.Assert(cr.PathToAssembly == cp.OutputAssembly);
            string strCacheAsm = PlgxCache.AddCacheAssembly(cr.PathToAssembly, plgx);

            RunBuildCommand(strBuildPost, UrlUtil.EnsureTerminatingSeparator(
                                strTmpRoot, false), UrlUtil.GetFileDirectory(strCacheAsm, true, false));

            return(strCacheAsm);
        }