コード例 #1
0
        private static void ReadReference(XmlNode xn, PlgxPluginInfo plgx)
        {
            XmlNode xnInc = xn.Attributes.GetNamedItem(XnnInclude);

            if ((xnInc == null) || string.IsNullOrEmpty(xnInc.Value))
            {
                Debug.Assert(false); return;
            }
            string str = xnInc.Value;

            if (UrlUtil.AssemblyEquals(str, PwDefs.ShortProductName))
            {
                return;                 // Ignore KeePass references
            }
            foreach (XmlNode xnSub in xn.ChildNodes)
            {
                if (xnSub.Name == XnnHintPath)
                {
                    plgx.IncludedReferencedAssemblies.Add(
                        UrlUtil.ConvertSeparators(xnSub.InnerText, '/'));
                    return;
                }
            }

            if (!str.EndsWith(".dll", StrUtil.CaseIgnoreCmp))
            {
                str += ".dll";
            }

            plgx.CompilerParameters.ReferencedAssemblies.Add(str);
        }
コード例 #2
0
ファイル: PlgxPlugin.cs プロジェクト: kkato233/KeePass
        private static bool CompileAssembly(PlgxPluginInfo plgx,
                                            out CompilerResults cr, string strCompilerVersion)
        {
            cr = null;

            const string StrCoreRef = "System.Core";
            const string StrCoreDll = "System.Core.dll";
            bool         bHasCore = false, bCoreAdded = false;

            foreach (string strAsm in plgx.CompilerParameters.ReferencedAssemblies)
            {
                if (UrlUtil.AssemblyEquals(strAsm, StrCoreRef))
                {
                    bHasCore = true;
                    break;
                }
            }
            if ((strCompilerVersion != null) && strCompilerVersion.StartsWith(
                    "v", StrUtil.CaseIgnoreCmp))
            {
                ulong v = StrUtil.ParseVersion(strCompilerVersion.Substring(1));
                if (!bHasCore && (v >= 0x0003000500000000UL))
                {
                    plgx.CompilerParameters.ReferencedAssemblies.Add(StrCoreDll);
                    bCoreAdded = true;
                }
            }

            bool bResult = false;

            try
            {
                Dictionary <string, string> dictOpt = new Dictionary <string, string>();
                if (!string.IsNullOrEmpty(strCompilerVersion))
                {
                    dictOpt.Add("CompilerVersion", strCompilerVersion);
                }

                // Windows 98 only supports the parameterless constructor;
                // check must be separate from the instantiation method
                if (WinUtil.IsWindows9x)
                {
                    dictOpt.Clear();
                }

                CodeDomProvider cdp = null;
                if (plgx.ProjectType == PlgxProjectType.CSharp)
                {
                    cdp = ((dictOpt.Count == 0) ? new CSharpCodeProvider() :
                           CreateCscProvider(dictOpt));
                }
                // else if(plgx.ProjectType == PlgxProjectType.VisualBasic)
                //	cdp = ((dictOpt.Count == 0) ? new VBCodeProvider() :
                //		new VBCodeProvider(dictOpt));
                else
                {
                    throw new InvalidOperationException();
                }

                cr = cdp.CompileAssemblyFromFile(plgx.CompilerParameters,
                                                 plgx.SourceFiles.ToArray());

                bResult = ((cr.Errors == null) || !cr.Errors.HasErrors);
            }
            catch (Exception) { }

            if (bCoreAdded)
            {
                plgx.CompilerParameters.ReferencedAssemblies.Remove(StrCoreDll);
            }

            return(bResult);
        }