Пример #1
0
        void m_worker_DoWork(object sender, DoWorkEventArgs e)
        {

            //if (Directory.Exists(uVisionProjectPath)) Directory.Delete(uVisionProjectPath, true);

            OnLogText("start analize");

            //ObjectList.Clear();

            Directory.CreateDirectory(uVisionProjectPath);

            WorkerParams pars = (WorkerParams)e.Argument;

            PKParser.Arg.PKArgParser ArgParser = new PKParser.Arg.PKArgParser();

            //string DefaultWorkingDir = Directory.GetCurrentDirectory();

            //List<UsedItem> LibList = new List<UsedItem>();
            //List<UsedItem> SourceList = new List<UsedItem>();

            Link Link = new Link("Link", null);

            //Собираем дерево проекта

            foreach (LogQueueItem item in pars.messages.Values)
            {
                if (item.Message.ToLower().Contains(ARMLINKPath))
                {
                    Link.ConsoleString = item.Message;
                    ParamCollection par = ArgParser.Add(item.Message);
                    if (par == null) throw new Exception(KeilWizardStrings);
                    Link.ParamCollection = par;

                    ProjectCollection LocalProjColl = new ProjectCollection();
                    Project MSBProj = LocalProjColl.LoadProject(item.ProjectBuildContext[item.ProjectBuildContext.Count - 1]);
                    string LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                    string OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");

                    foreach (ArgCollection arg in par.Values)
                    {
                        if (arg.Name == "--output")
                        {
                            Link.Name = arg[0];
                        }
                    }

                    foreach (string file in par.Files.Values)
                    {
                        RequiredLibrary lib = null;
                        RequiredObject obj = null;
                        if (Path.GetExtension(file).ToLower() == "." + LIB_EXT.ToLower())
                        {
                            lib =new RequiredLibrary(file, Link);
                            Link.InputLibraries.Add(Link.InputLibraries.Count + 1, lib);
                        }

                        if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                        {
                            obj = new RequiredObject(file, Link);
                            Link.InputObjects.Add(Link.InputObjects.Count + 1, obj);
                        }
                        if (lib != null) Link.AllInputs.Add(Link.AllInputs.Count + 1, lib);
                        if (obj != null) Link.AllInputs.Add(Link.AllInputs.Count + 1, obj);
                    }
                }
            }
            ArgParser.Clear();
            //Идем по требуемым библиотекам
            this.AnalizeInputLibraries(Link.InputLibraries, pars.messages.Values);

            //Проверка Crypto.Lib
            this.CheckCryptoLib(Link.InputLibraries, pars.messages.Values);

            //Идем по всем требуемым файлам
            SortedList<int, RequiredObject> ReqObjs = Link.GetAllRequiredObjects();
            this.AnalizeInputObjects(ReqObjs, pars.messages.Values);

            if (!Link.CheckItems())
            {
                throw new Exception("Not all Link Items founded");
            }


            //Собираем необходимые для проекта файлы
            List<RequiredLibrary> ReqLib = Link.GetAllSubRequiredLibraries();

            foreach (RequiredObject obj in ReqObjs.Values)
            {
                this.AddObjFile(obj);
            }
            foreach (RequiredLibrary lib in ReqLib)
            {
                uVisionProject.AddFile(lib.OutputFileuVision, Path.GetFileNameWithoutExtension(lib.Parent.Name));
            }

            //Сортируем группы
            uVisionProject.SortGroups();

            foreach (RequiredLibrary lib in Link.InputLibraries.Values)
            {
                uVisionProject.AddFile(lib.OutputFileuVision,Path.GetFileNameWithoutExtension(Link.Name));
            }

            //Создаем таргеты
            foreach (RequiredLibrary lib in Link.InputLibraries.Values)
            {
                if (lib.Name.ToLower().Contains("crypto"))
                {
                }
                this.CreateLibraryTartet(lib);
            }

            //foreach (RequiredObject obj in Link.InputObjects.Values)
            //{
            //    this.CreateObjectTartet(obj);
            //}

            this.CreateLinkTarget(Link, pars.messages.Values);

            //this.CreateBrowseTarget(Link);

            OnLogText("Writing files");
            ///ProjectFile
            List<string> resultstrings = uVisionProject.GetAllProjectStrings();

            using (StreamWriter outfile =
                    new StreamWriter(uVisionProjectPath + @"\generated.Uv2"))
            {
                foreach (string s in resultstrings)
                {
                    outfile.WriteLine(s);
                }

            }

            ///MultiProjectFile
            using (StreamWriter outfile =
                    new StreamWriter(uVisionProjectPath + @"\project.mpw"))
            {
                outfile.WriteLine("[WORKSPACE]\r");
                outfile.WriteLine(" MPW_NAME=\"WorkSpace\"\r");
                outfile.WriteLine(" Project=\".\\generated.Uv2\",A,X,B\r\r");
            }

            ///BatFiles
            //try
            //{
                if (Directory.Exists(uVisionProjectPath + "\\BatFiles\\Prebuild\\"))
                    Directory.Delete(uVisionProjectPath + "\\BatFiles\\Prebuild\\", true);

                if (Directory.Exists(uVisionProjectPath + "\\BatFiles\\Postbuild\\"))
                    Directory.Delete(uVisionProjectPath + "\\BatFiles\\Postbuild\\", true);

                Directory.CreateDirectory(uVisionProjectPath + "\\BatFiles\\Prebuild\\");

                Directory.CreateDirectory(uVisionProjectPath + "\\BatFiles\\Postbuild\\");
            //}
           // catch
            //{
            //}



            foreach (Target t in uVisionProject.TargetList.Values)
            {
                //PreBuild
                if (t.BeforeBuild.Count > 0)
                {
                    using (StreamWriter outfile =
                        new StreamWriter(uVisionProjectPath + "\\BatFiles\\Prebuild" + @"\" + t.Name + ".bat"))
                    {
                        foreach (string s in t.BeforeBuild)
                        {
                            outfile.WriteLine(s);
                        }

                    }
                }

                if (t.AfterBuild.Count > 0)
                {
                    using (StreamWriter outfile =
                        new StreamWriter(uVisionProjectPath + "\\BatFiles\\Postbuild" + @"\" + t.Name + ".bat"))
                    {
                        foreach (string s in t.AfterBuild)
                        {
                            outfile.WriteLine(s);
                        }

                    }
                }
            }

            OnLogText("Done");

            e.Result = resultstrings;
        }