Ejemplo n.º 1
0
        /// <summary>
        /// IAR项目转VS工程
        /// </summary>
        /// <param name="projectName"></param>
        public bool IARToVisualStudio(string projectName)
        {
            //---判断文件是否存在
            if (!File.Exists(projectName))
            {
                return(false);
            }

            //---变量定义
            CProjectConfig       prjcfg   = new CProjectConfig();
            List <CProjectGroup> prjgroup = new List <CProjectGroup>();

            //---读取设备的文件---创建XmlReader对象的实例并将其返回给调用程序
            XmlReader xmlRead = XmlReader.Create(new StringReader(File.ReadAllText(projectName)));

            //---读取配置文件---不断读取直至找到指定的元素
            xmlRead.ReadToFollowing("configuration");
            do
            {
                //---读取子节点---而是用于创建 XML 元素周围的边界
                XmlReader subXmlRead = xmlRead.ReadSubtree();

                //---移动读取器至下一个匹配子孙元素的节点
                subXmlRead.ReadToDescendant("name");

                //---从流中读取下一个节点
                subXmlRead.Read();
                prjcfg.mName = subXmlRead.Value;

                //---获取设置
                subXmlRead.ReadToFollowing("settings");

                //---
                subXmlRead.ReadToDescendant("archiveVersion");

                //---从流中读取下一个节点
                subXmlRead.Read();

                //---判断数据值
                if (int.Parse(subXmlRead.Value) > 0)
                {
                    prjcfg.mCMSIS = true;
                }
                else
                {
                    prjcfg.mCMSIS = false;
                }

                //---读取下一个节点
                subXmlRead.ReadToFollowing("settings");
                prjcfg.mDefine = this.FindIARSubNodeValue(subXmlRead, "CCDefines");

                //---IAR中增加的信息
                prjcfg.mDefine.Add("_IAR_");
                prjcfg.mDefine.Add("__ICCARM__");
                prjcfg.mDefine.Add("_Pragma(x)=");
                prjcfg.mDefine.Add("__interrupt=");

                //prjcfg._define.Add("__packed=");
                //prjcfg._define.Add("__weak=");
                prjcfg.mDefine.Add("__packed=__attribute__((__packed__))");
                prjcfg.mDefine.Add("__weak=__attribute__((weak))");

                //prjcfg._define.Add("__attribute__((x))=");
                //prjcfg._define.Add("__STATIC_INLINE=");
                //---获取预包含的头文件
                prjcfg.mPreInclude = this.FindIARSubNodeValue(subXmlRead, "PreInclude");

                //---获取包含文件的路径
                prjcfg.mIncludePath = this.FindIARSubNodeValue(subXmlRead, "CCIncludePath2");
            }while (xmlRead.ReadToNextSibling("configuration"));
            xmlRead.Close();

            xmlRead = XmlReader.Create(new StringReader(File.ReadAllText(projectName)));

            //---读取配置文件---不断读取直至找到指定的元素
            //---获取组文件
            xmlRead.ReadToFollowing("group");
            do
            {
                CProjectGroup _return = FindIARSubNodeGroup(xmlRead, "group");
                if (_return != null)
                {
                    prjgroup.Add(_return);
                }
            }while (xmlRead.ReadToNextSibling("group"));
            xmlRead.Close();

            //---获取C文件
            xmlRead = XmlReader.Create(new StringReader(File.ReadAllText(projectName)));
            do
            {
                xmlRead.ReadToFollowing("file");
                if (xmlRead.Depth == 1 && xmlRead.NodeType == XmlNodeType.Element)
                {
                    CProjectGroup _return = FindIARSubNodeFile(xmlRead, "file");
                    if (_return != null)
                    {
                        prjgroup.Add(_return);
                    }
                }
            }while (!xmlRead.EOF);
            xmlRead.Close();

            //string configurations = "Debug" + "\", \"" + "Release";
            //StreamWriter file =new StreamWriter(Path.GetDirectoryName(projectName) + "\\IARToVS.lua");
            StreamWriter file = new StreamWriter(Path.GetDirectoryName(projectName) + "\\premake5.lua");

            //StreamWriter file = new StreamWriter(Directory.GetParent(Path.GetDirectoryName(projectName)).FullName + "\\premake5.lua");
            {
                //
                file.WriteLine("  solution \"" + Path.GetFileNameWithoutExtension(projectName) + "\"");
                file.WriteLine("  configurations { \"" + string.Join("\", \"", prjcfg.mName) + "\" }");

                //file.WriteLine("  configurations { \"" + configurations + "\" }");
                file.WriteLine("  project\"" + Path.GetFileNameWithoutExtension(projectName) + "\"");
                file.WriteLine("  kind \"ConsoleApp\"");
                file.WriteLine("  language \"C\"");
                file.WriteLine("  filter \"configurations:" + prjcfg.mName + "\"");
                file.WriteLine("  sysincludedirs  {\"$(VC_IncludePath)\"}");
                file.WriteLine("  defines { \"" + string.Join("\", \"", prjcfg.mDefine) + "\" }");
                file.WriteLine("  forceincludes { \"" + string.Join("\", \"", prjcfg.mPreInclude) + "\" }");
                file.WriteLine("  includedirs { \"" + string.Join("\", \"", prjcfg.mIncludePath) + "\" }");
                List <string> srcFiles = new CProjectGroup().GetFile(prjgroup, prjcfg.mName);
                file.WriteLine("  files { \"" + string.Join("\", \"", srcFiles) + "\" }");
                List <string> vGroups = new CProjectGroup().GetPath(prjgroup, prjcfg.mName);
                file.WriteLine("  vpaths {" + string.Join(" , ", vGroups) + " }");

                //file.Write(IncOverride);
                file.Close();
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="projectName"></param>
        /// <returns></returns>
        public bool MDKToVisualStudio(string projectName)
        {
            //---判断文件是否存在
            if (!File.Exists(projectName))
            {
                return(false);
            }

            //---变量定义
            CProjectConfig       prjcfg   = new CProjectConfig();
            List <CProjectGroup> prjgroup = new List <CProjectGroup>();

            //---读取设备的文件---创建XmlReader对象的实例并将其返回给调用程序
            XmlReader xmlRead = XmlReader.Create(new StringReader(File.ReadAllText(projectName)));

            //---读取配置文件---不断读取直至找到指定的元素
            xmlRead.ReadToFollowing("TargetOption");
            do
            {
                //---读取子节点---而是用于创建 XML 元素周围的边界
                XmlReader subXmlRead = xmlRead.ReadSubtree();

                //---移动读取器至下一个匹配子孙元素的节点
                subXmlRead.ReadToDescendant("OutputName");

                //---从流中读取下一个节点
                subXmlRead.Read();
                prjcfg.mName = subXmlRead.Value;

                //---获取设置
                subXmlRead.ReadToFollowing("Cads");

                //---
                subXmlRead.ReadToDescendant("Optim");

                //---从流中读取下一个节点
                subXmlRead.Read();

                //---判断数据值
                if (int.Parse(subXmlRead.Value) > 0)
                {
                    prjcfg.mCMSIS = true;
                }
                else
                {
                    prjcfg.mCMSIS = false;
                }

                //---读取下一个节点
                subXmlRead.ReadToFollowing("VariousControls");
                subXmlRead.ReadToFollowing("Define");
                prjcfg.mDefine = this.FindMDKSubNodeValue(subXmlRead.ReadSubtree());

                //----Keil工程的生成中借用了IAR的一些文件,用于避免一些数据类型报错的问题
                //---IAR中增加的信息
                prjcfg.mDefine.Add("_IAR_");
                prjcfg.mDefine.Add("__ICCARM__");
                prjcfg.mDefine.Add("__CC_ARM");
                prjcfg.mDefine.Add("_Pragma(x)=");
                prjcfg.mDefine.Add("__interrupt=");

                //prjcfg._define.Add("__packed=");
                //prjcfg._define.Add("__weak=");
                prjcfg.mDefine.Add("__packed=__attribute__((__packed__))");
                prjcfg.mDefine.Add("__weak=__attribute__((weak))");

                //prjcfg._define.Add("__attribute__((x))=");
                //prjcfg._define.Add("__STATIC_INLINE=");
                //---获取预包含的头文件
                //subXmlRead.ReadToFollowing("PreInclude");
                //prjcfg._preInclude = this.GetKeilSubNodeValue(subXmlRead,';');
                //---获取包含文件的路径
                subXmlRead.ReadToFollowing("IncludePath");
                prjcfg.mIncludePath = this.FindMDKSubNodeValue(subXmlRead.ReadSubtree(), ';');
            }while (xmlRead.ReadToNextSibling("TargetOption"));
            xmlRead.Close();

            xmlRead = XmlReader.Create(new StringReader(File.ReadAllText(projectName)));

            //---读取配置文件---不断读取直至找到指定的元素
            //---获取组文件

            do
            {
                xmlRead.ReadToFollowing("Group");
                if (xmlRead.Depth == 4 && xmlRead.NodeType == XmlNodeType.Element)
                {
                    CProjectGroup _return = FindMDKSubNodeGroup(xmlRead, "Group");
                    if (_return != null)
                    {
                        prjgroup.Add(_return);
                    }
                }
            }while (!xmlRead.EOF);
            xmlRead.Close();

            //---处理MDK文档
            //foreach (var temp in prjgroup)
            //{
            //	if (temp._name.Contains("MDK"))
            //	{
            //		temp._name = temp._name.Substring(temp._name.IndexOf("/MDK") + 1);
            //	}
            //	else
            //	{
            //		continue;
            //	}
            //}

            //---获取C文件
            xmlRead = XmlReader.Create(new StringReader(File.ReadAllText(projectName)));
            do
            {
                xmlRead.ReadToFollowing("Files");
                if (xmlRead.Depth == 3 && xmlRead.NodeType == XmlNodeType.Element)
                {
                    CProjectGroup _return = FindMDKSubNodeFile(xmlRead, "Files");
                    if (_return != null)
                    {
                        prjgroup.Add(_return);
                    }
                }
            }while (!xmlRead.EOF);
            xmlRead.Close();

            //---获取Keil的执行路径
            //---Keil5

            /*
             * string keilPath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetProcessesByName("UV4")[0].MainModule.FileName);
             * if (keilPath == null)
             * {
             *      //---keil4
             *      keilPath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetProcessesByName("UV3")[0].MainModule.FileName);
             * }
             * if (keilPath == null)
             * {
             *      //---keil2
             *      keilPath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetProcessesByName("UV2")[0].MainModule.FileName);
             * }
             */
            string keilPath    = this.GetMDKPatch();
            string includedirs = string.Join("\", \"", prjcfg.mIncludePath);

            if (keilPath != null)
            {
                keilPath    += @"\RV31";
                keilPath     = keilPath.Replace("\\", "/");
                includedirs += "\", \"" + keilPath;
            }

            //string configurations = "Debug" + "\", \"" + "Release";
            //StreamWriter file = new StreamWriter(Path.GetDirectoryName(projectName) + "\\KeilToVS.lua");
            StreamWriter file = new StreamWriter(Path.GetDirectoryName(projectName) + "\\premake5.lua");

            //StreamWriter file = new StreamWriter(Directory.GetParent(Path.GetDirectoryName(projectName)).FullName + "\\premake5.lua");
            {
                //
                file.WriteLine("  solution \"" + Path.GetFileNameWithoutExtension(projectName) + "\"");
                file.WriteLine("  configurations { \"" + string.Join("\", \"", prjcfg.mName) + "\" }");

                //file.WriteLine("  configurations { \"" + configurations + "\" }");
                file.WriteLine("  project\"" + Path.GetFileNameWithoutExtension(projectName) + "\"");
                file.WriteLine("  kind \"ConsoleApp\"");
                file.WriteLine("  language \"C\"");
                file.WriteLine("  filter \"configurations:" + prjcfg.mName + "\"");
                file.WriteLine("  sysincludedirs  {\"$(VC_IncludePath)\"}");
                file.WriteLine("  defines { \"" + string.Join("\", \"", prjcfg.mDefine) + "\" }");
                file.WriteLine("  forceincludes { \"" + string.Join("\", \"", prjcfg.mPreInclude) + "\" }");
                file.WriteLine("  includedirs { \"" + includedirs + "\" }");
                List <string> srcFiles = new CProjectGroup().GetFile(prjgroup, prjcfg.mName);
                file.WriteLine("  files { \"" + string.Join("\", \"", srcFiles) + "\"}");
                List <string> vGroups = new CProjectGroup().GetPath(prjgroup, prjcfg.mName);
                file.WriteLine("  vpaths {" + string.Join(" , ", vGroups) + " }");

                //file.Write(IncOverride);
                file.Close();
            }

            return(true);
        }