Inheritance: RequiredBase
        private void AddObjFile(RequiredObject reqobj)
        {
            string DefaultWorkingDir = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(reqobj.CurrentDir);
            foreach (string file in reqobj.InputFiles)
            {
                string path = Path.GetFullPath(ExpandPath(file));
                if (!System.IO.File.Exists(path))
                {
                    throw new FileNotFoundException(KeilWizardStrings.IDS_FILE + " \"" + path + "\" " + KeilWizardStrings.IDS_MISSING, path);
                }

                if (!uVisionProject.ContainsFile(path))
                {
                    List<BuildFileWrapper> source_list = new List<BuildFileWrapper>();

                    object obj = GetMFObjectFromProjectFile(reqobj.BuildList[reqobj.BuildList.Count - 1]);

                    string group = Path.GetFileNameWithoutExtension(reqobj.Parent.Name);

                    if (obj == null)
                    {
                        uVisionProject.AddFile(path, group);
                        continue;
                    }
                    else
                    {

                        if (obj.GetType() == typeof(SolutionWrapper))
                        {
                            //MFSolution sol = (MFSolution)obj;
                        }
                        else if (obj.GetType() == typeof(ProjectWrapper))
                        {
                            ProjectWrapper proj = (ProjectWrapper)obj;
                            source_list.AddRange(proj.FastCompileFiles);
                            source_list.AddRange(proj.HeaderFiles);
                            source_list.AddRange(proj.SourceFiles);
                        }
                        else if (obj.GetType() == typeof(LibraryWrapper))
                        {
                            LibraryWrapper lib = (LibraryWrapper)obj;
                            source_list.AddRange(lib.FastCompileFiles);
                            source_list.AddRange(lib.HeaderFiles);
                            source_list.AddRange(lib.SourceFiles);
                        }
                    }

                    if (CheckFile(path, source_list))
                    {
                        AddHFiles(group, source_list, uVisionProject);
                        uVisionProject.AddFile(path, group);
                        continue;
                    }
                    else
                    {
                        uVisionProject.AddFile(path, group);
                    }
                }
            }
            Directory.SetCurrentDirectory(DefaultWorkingDir);
        }
        private void CheckSocketsLibs(SortedList<int, RequiredLibrary> Libraryes, IList<LogQueueItem> LogMessages)
        {
            //PKParser.Arg.PKArgParser ArgParser = new PKParser.Arg.PKArgParser();

            foreach (RequiredLibrary lib in Libraryes.Values)
            {
                #region sockets_hal.lib
                if (lib.Name.ToLower() == "sockets_hal.lib")
                {
                    if (lib.ParamCollection != null) return;

                    //foreach (LogQueueItem item in LogMessages)
                    //{
                    //    string util = ArgParser.GetUtil(item.Message);
                    //    if (util == null) continue;
                    //    if (String.Compare(ARMARPath, util, StringComparison.InvariantCultureIgnoreCase) == 0)
                    //if (item.Message.ToLower().Contains(ARMARPath))
                    //{
                    //ParamCollection par = ArgParser.Add(item.Message);
                    foreach (ParCollContainer container in ARMAR.Values)
                    {
                        ParamCollection par = container.ParamCollection;
                        if (par == null) continue;

                        bool Found = false;

                        foreach (ArgCollection arg in par.Values)
                        {
                            if (arg.Tag == "archive")
                            {
                                if (Path.GetFileName(arg.Name).ToLower() == "sockets_hal_stubs.lib") Found = true;
                            }
                        }

                        if (!Found) continue;

                        lib.ConsoleString = container.Message;
                        lib.ParamCollection = par;
                        lib.BuildList.AddRange(container.ProjectBuildContext);
                        lib.OutputFileuVision = uVisionProjectPath + "\\" + uVisionTargetsPath + "\\" + Path.GetFileNameWithoutExtension(lib.Name) + "\\" + Path.GetFileName(lib.Name);

                        string LIB_EXT = string.Empty;
                        string OBJ_EXT = string.Empty;

                        using (ProjectCollection LocalProjColl = new ProjectCollection())
                        {
                            Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);
                            LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                            OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
                        }


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

                            if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                            {
                                obj = new RequiredObject(file, lib);
                                lib.InputObjects.Add(lib.InputObjects.Count + 1, obj);
                            }
                            if (libr != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, libr);
                            if (obj != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, obj);
                        }


                        foreach (ArgCollection arg in par.Values)
                        {
                            switch (arg.Tag)
                            {
                                case "options":
                                    if (arg.Count > 0)
                                        foreach (string s in arg)
                                        {
                                            lib.OptionsString.Add(arg.Name + " " + s);
                                        }
                                    else
                                        lib.OptionsString.Add(arg.Name);
                                    break;
                                case "archive":
                                    lib.OutputFileMSBuild = arg.Name;
                                    break;
                            }
                        }
                        //}
                    }
                    if (lib.InputLibraries.Count > 0) this.AnalizeInputLibraries(lib.InputLibraries, LogMessages);
                }
                #endregion
                #region sockets_dhcp.lib
                if (lib.Name.ToLower() == "sockets_dhcp.lib")
                {
                    if (lib.ParamCollection != null) return;

                    //foreach (LogQueueItem item in LogMessages)
                    //{
                    //    string util = ArgParser.GetUtil(item.Message);
                    //    if (util == null) continue;
                    //    if (String.Compare(ARMARPath, util, StringComparison.InvariantCultureIgnoreCase) == 0)
                    //if (item.Message.ToLower().Contains(ARMARPath))
                    //{
                    //ParamCollection par = ArgParser.Add(item.Message);
                    foreach (ParCollContainer container in ARMAR.Values)
                    {
                        ParamCollection par = container.ParamCollection;
                        if (par == null) continue;

                        bool Found = false;

                        foreach (ArgCollection arg in par.Values)
                        {
                            if (arg.Tag == "archive")
                            {
                                if (Path.GetFileName(arg.Name).ToLower() == "sockets_dhcp_stubs.lib") Found = true;
                            }
                        }

                        if (!Found) continue;

                        lib.ConsoleString = container.Message;
                        lib.ParamCollection = par;
                        lib.BuildList.AddRange(container.ProjectBuildContext);
                        lib.OutputFileuVision = uVisionProjectPath + "\\" + uVisionTargetsPath + "\\" + Path.GetFileNameWithoutExtension(lib.Name) + "\\" + Path.GetFileName(lib.Name);

                        string LIB_EXT = string.Empty;
                        string OBJ_EXT = string.Empty;

                        using (ProjectCollection LocalProjColl = new ProjectCollection())
                        {
                            Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);
                            LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                            OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
                        }


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

                            if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                            {
                                obj = new RequiredObject(file, lib);
                                lib.InputObjects.Add(lib.InputObjects.Count + 1, obj);
                            }
                            if (libr != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, libr);
                            if (obj != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, obj);
                        }


                        foreach (ArgCollection arg in par.Values)
                        {
                            switch (arg.Tag)
                            {
                                case "options":
                                    if (arg.Count > 0)
                                        foreach (string s in arg)
                                        {
                                            lib.OptionsString.Add(arg.Name + " " + s);
                                        }
                                    else
                                        lib.OptionsString.Add(arg.Name);
                                    break;
                                case "archive":
                                    lib.OutputFileMSBuild = arg.Name;
                                    break;
                            }
                        }
                        //}
                    }
                    if (lib.InputLibraries.Count > 0) this.AnalizeInputLibraries(lib.InputLibraries, LogMessages);
                }
                #endregion
                #region sockets_hal_udp.lib
                if (lib.Name.ToLower() == "sockets_hal_udp.lib")
                {
                    if (lib.ParamCollection != null) return;

                    //foreach (LogQueueItem item in LogMessages)
                    //{
                    //    string util = ArgParser.GetUtil(item.Message);
                    //    if (util == null) continue;
                    //    if (String.Compare(ARMARPath, util, StringComparison.InvariantCultureIgnoreCase) == 0)
                    //if (item.Message.ToLower().Contains(ARMARPath))
                    //{
                    //ParamCollection par = ArgParser.Add(item.Message);
                    foreach (ParCollContainer container in ARMAR.Values)
                    {
                        ParamCollection par = container.ParamCollection;
                        if (par == null) continue;

                        bool Found = false;

                        foreach (ArgCollection arg in par.Values)
                        {
                            if (arg.Tag == "archive")
                            {
                                if (Path.GetFileName(arg.Name).ToLower() == "sockets_hal_udp_stubs.lib") Found = true;
                            }
                        }

                        if (!Found) continue;

                        lib.ConsoleString = container.Message;
                        lib.ParamCollection = par;
                        lib.BuildList.AddRange(container.ProjectBuildContext);
                        lib.OutputFileuVision = uVisionProjectPath + "\\" + uVisionTargetsPath + "\\" + Path.GetFileNameWithoutExtension(lib.Name) + "\\" + Path.GetFileName(lib.Name);

                        string LIB_EXT = string.Empty;
                        string OBJ_EXT = string.Empty;

                        using (ProjectCollection LocalProjColl = new ProjectCollection())
                        {
                            Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);
                            LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                            OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
                        }


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

                            if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                            {
                                obj = new RequiredObject(file, lib);
                                lib.InputObjects.Add(lib.InputObjects.Count + 1, obj);
                            }
                            if (libr != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, libr);
                            if (obj != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, obj);
                        }


                        foreach (ArgCollection arg in par.Values)
                        {
                            switch (arg.Tag)
                            {
                                case "options":
                                    if (arg.Count > 0)
                                        foreach (string s in arg)
                                        {
                                            lib.OptionsString.Add(arg.Name + " " + s);
                                        }
                                    else
                                        lib.OptionsString.Add(arg.Name);
                                    break;
                                case "archive":
                                    lib.OutputFileMSBuild = arg.Name;
                                    break;
                            }
                        }
                        //}
                    }
                    if (lib.InputLibraries.Count > 0) this.AnalizeInputLibraries(lib.InputLibraries, LogMessages);
                }
                #endregion
                #region sockets_ssl.lib
                if (lib.Name.ToLower() == "sockets_ssl.lib")
                {
                    if (lib.ParamCollection != null) return;

                    //foreach (LogQueueItem item in LogMessages)
                    //{
                    //    string util = ArgParser.GetUtil(item.Message);
                    //    if (util == null) continue;
                    //    if (String.Compare(ARMARPath, util, StringComparison.InvariantCultureIgnoreCase) == 0)
                    //if (item.Message.ToLower().Contains(ARMARPath))
                    //{
                    //ParamCollection par = ArgParser.Add(item.Message);
                    foreach (ParCollContainer container in ARMAR.Values)
                    {
                        ParamCollection par = container.ParamCollection;
                        if (par == null) continue;

                        bool Found = false;

                        foreach (ArgCollection arg in par.Values)
                        {
                            if (arg.Tag == "archive")
                            {
                                if (Path.GetFileName(arg.Name).ToLower() == "sockets_ssl_stubs.lib") Found = true;
                            }
                        }

                        if (!Found) continue;

                        lib.ConsoleString = container.Message;
                        lib.ParamCollection = par;
                        lib.BuildList.AddRange(container.ProjectBuildContext);
                        lib.OutputFileuVision = uVisionProjectPath + "\\" + uVisionTargetsPath + "\\" + Path.GetFileNameWithoutExtension(lib.Name) + "\\" + Path.GetFileName(lib.Name);

                        string LIB_EXT = string.Empty;
                        string OBJ_EXT = string.Empty;

                        using (ProjectCollection LocalProjColl = new ProjectCollection())
                        {
                            Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);
                            LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                            OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
                        }


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

                            if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                            {
                                obj = new RequiredObject(file, lib);
                                lib.InputObjects.Add(lib.InputObjects.Count + 1, obj);
                            }
                            if (libr != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, libr);
                            if (obj != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, obj);
                        }


                        foreach (ArgCollection arg in par.Values)
                        {
                            switch (arg.Tag)
                            {
                                case "options":
                                    if (arg.Count > 0)
                                        foreach (string s in arg)
                                        {
                                            lib.OptionsString.Add(arg.Name + " " + s);
                                        }
                                    else
                                        lib.OptionsString.Add(arg.Name);
                                    break;
                                case "archive":
                                    lib.OutputFileMSBuild = arg.Name;
                                    break;
                            }
                        }
                        //}
                    }
                    if (lib.InputLibraries.Count > 0) this.AnalizeInputLibraries(lib.InputLibraries, LogMessages);
                }
                #endregion
                #region sockets_sntp.lib
                if (lib.Name.ToLower() == "sockets_sntp.lib")
                {
                    if (lib.ParamCollection != null) return;

                    //foreach (LogQueueItem item in LogMessages)
                    //{
                    //    string util = ArgParser.GetUtil(item.Message);
                    //    if (util == null) continue;
                    //    if (String.Compare(ARMARPath, util, StringComparison.InvariantCultureIgnoreCase) == 0)
                    //if (item.Message.ToLower().Contains(ARMARPath))
                    //{
                    //ParamCollection par = ArgParser.Add(item.Message);
                    foreach (ParCollContainer container in ARMAR.Values)
                    {
                        ParamCollection par = container.ParamCollection;
                        if (par == null) continue;

                        bool Found = false;

                        foreach (ArgCollection arg in par.Values)
                        {
                            if (arg.Tag == "archive")
                            {
                                if (Path.GetFileName(arg.Name).ToLower() == "sockets_sntp_stubs.lib") Found = true;
                            }
                        }

                        if (!Found) continue;

                        lib.ConsoleString = container.Message;
                        lib.ParamCollection = par;
                        lib.BuildList.AddRange(container.ProjectBuildContext);
                        lib.OutputFileuVision = uVisionProjectPath + "\\" + uVisionTargetsPath + "\\" + Path.GetFileNameWithoutExtension(lib.Name) + "\\" + Path.GetFileName(lib.Name);

                        string LIB_EXT = string.Empty;
                        string OBJ_EXT = string.Empty;

                        using (ProjectCollection LocalProjColl = new ProjectCollection())
                        {
                            Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);
                            LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                            OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
                        }


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

                            if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                            {
                                obj = new RequiredObject(file, lib);
                                lib.InputObjects.Add(lib.InputObjects.Count + 1, obj);
                            }
                            if (libr != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, libr);
                            if (obj != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, obj);
                        }


                        foreach (ArgCollection arg in par.Values)
                        {
                            switch (arg.Tag)
                            {
                                case "options":
                                    if (arg.Count > 0)
                                        foreach (string s in arg)
                                        {
                                            lib.OptionsString.Add(arg.Name + " " + s);
                                        }
                                    else
                                        lib.OptionsString.Add(arg.Name);
                                    break;
                                case "archive":
                                    lib.OutputFileMSBuild = arg.Name;
                                    break;
                            }
                        }
                        //}
                    }
                    if (lib.InputLibraries.Count > 0) this.AnalizeInputLibraries(lib.InputLibraries, LogMessages);
                }
                #endregion
                #region sockets_hal_tcp.lib
                if (lib.Name.ToLower() == "sockets_hal_tcp.lib")
                {
                    if (lib.ParamCollection != null) return;

                    //foreach (LogQueueItem item in LogMessages)
                    //{
                    //    string util = ArgParser.GetUtil(item.Message);
                    //    if (util == null) continue;
                    //    if (String.Compare(ARMARPath, util, StringComparison.InvariantCultureIgnoreCase) == 0)
                    //if (item.Message.ToLower().Contains(ARMARPath))
                    //{
                    //ParamCollection par = ArgParser.Add(item.Message);
                    foreach (ParCollContainer container in ARMAR.Values)
                    {
                        ParamCollection par = container.ParamCollection;
                        if (par == null) continue;

                        bool Found = false;

                        foreach (ArgCollection arg in par.Values)
                        {
                            if (arg.Tag == "archive")
                            {
                                if (Path.GetFileName(arg.Name).ToLower() == "sockets_hal_tcp_stubs.lib") Found = true;
                            }
                        }

                        if (!Found) continue;

                        lib.ConsoleString = container.Message;
                        lib.ParamCollection = par;
                        lib.BuildList.AddRange(container.ProjectBuildContext);
                        lib.OutputFileuVision = uVisionProjectPath + "\\" + uVisionTargetsPath + "\\" + Path.GetFileNameWithoutExtension(lib.Name) + "\\" + Path.GetFileName(lib.Name);

                        string LIB_EXT = string.Empty;
                        string OBJ_EXT = string.Empty;

                        using (ProjectCollection LocalProjColl = new ProjectCollection())
                        {
                            Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);
                            LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                            OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
                        }


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

                            if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                            {
                                obj = new RequiredObject(file, lib);
                                lib.InputObjects.Add(lib.InputObjects.Count + 1, obj);
                            }
                            if (libr != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, libr);
                            if (obj != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, obj);
                        }


                        foreach (ArgCollection arg in par.Values)
                        {
                            switch (arg.Tag)
                            {
                                case "options":
                                    if (arg.Count > 0)
                                        foreach (string s in arg)
                                        {
                                            lib.OptionsString.Add(arg.Name + " " + s);
                                        }
                                    else
                                        lib.OptionsString.Add(arg.Name);
                                    break;
                                case "archive":
                                    lib.OutputFileMSBuild = arg.Name;
                                    break;
                            }
                        }
                        //}
                    }
                    if (lib.InputLibraries.Count > 0) this.AnalizeInputLibraries(lib.InputLibraries, LogMessages);
                }
                #endregion
            }
        }
        public void Convert(string ProjectPath)
        {
            using (ProjectCollection LocalProjColl = new ProjectCollection())
            {
                Project MSBProj = LocalProjColl.LoadProject(PK.Wrapper.ExpandEnvVars(ProjectPath, ""));

                ARMCCPath = MSBProj.GetPropertyValue("CC").ToLower();
                ARMASMPath = MSBProj.GetPropertyValue("AS").ToLower();
                ARMLINKPath = MSBProj.GetPropertyValue("LINK").ToLower();
                ARMARPath = MSBProj.GetPropertyValue("AR").ToLower();
                ARMFROMELFPath = MSBProj.GetPropertyValue("FromELF").ToLower();
            }

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

            int index = 0;

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

            Link.LogEvent += new MessagesParsesHelper.Link.LogEventDelegate(Link_LogEvent);

            OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.START));

            foreach (LogQueueItem item in LogQueue.Values)
            {
                index++;
                OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_ANALYSE_LINKS, GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / LogQueue.Values.Count)));

                string s = ArgParser.GetUtil(item.Message);
                if (s == null) continue;
                if (String.Compare(ARMLINKPath, s, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    //ArmLink
                    ARMLink.Add(ARMLink.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir));
                }
                else if (String.Compare(ARMCCPath, s, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    //ArmCC 
                    ARMCCandARMASM.Add(ARMCCandARMASM.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir));
                }
                else if (String.Compare(ARMASMPath, s, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    //ArmAsm
                    ARMCCandARMASM.Add(ARMCCandARMASM.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir));
                }
                else if (String.Compare(ARMARPath, s, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    //ArmAr
                    ARMAR.Add(ARMAR.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir));
                }
                else if (String.Compare(ARMFROMELFPath, s, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    //FROMElf
                    FROMELF.Add(FROMELF.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir));
                }
            }

            ArgParser.Clear();

            //Construct project tree

            ParCollContainer container = ARMLink.Values[ARMLink.Values.Count - 1];
            if (container.ParamCollection == null) throw new MessagesParserException(KeilWizardStrings.IDS_ERROR_CANT_PASRSE_LINK);
            Link.ParamCollection = container.ParamCollection;

            string LIB_EXT = string.Empty;
            string OBJ_EXT = string.Empty;

            using (ProjectCollection LocalProjColl = new ProjectCollection())
            {
                Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);

                LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
            }

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

            foreach (string file in container.ParamCollection.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);
            }
            OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_ANALYSE_LINKS, GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.WORKING, 100));
            System.Threading.Thread.Sleep(sleeptime);



            //using (StreamWriter outfile =
            //            new StreamWriter(Path.GetFileNameWithoutExtension(Link.Name) + ".input"))
            //{
            //    outfile.WriteLine(PK.Wrapper.Solution.ProjectPath);
            //    outfile.WriteLine(uVisionProjectPath);
            //    outfile.WriteLine(ProjectPath);                

            //    foreach (ArgCollection arg in Link.ParamCollection.Values)
            //    {
            //        if (arg.Name == "--scatter")
            //            outfile.WriteLine(arg[0]);
            //    }
            //    outfile.WriteLine(LogQueue.Values.Count);
            //    foreach (LogQueueItem item in LogQueue.Values)
            //    {
            //        outfile.WriteLine(item.Message);
            //        outfile.WriteLine(item.CurrentDir);
            //        outfile.WriteLine(item.ProjectBuildContext.Count);
            //        foreach (string s in item.ProjectBuildContext)
            //        {
            //            outfile.WriteLine(s);
            //        }
            //    }
            //}



            ArgParser.Clear();
            //Analysing libraries
            this.AnalizeInputLibraries(Link.InputLibraries, LogQueue.Values);

            //Checking Crypto.Lib
            this.CheckCryptoLib(Link.InputLibraries, LogQueue.Values);

            //Checking Sockets Libs
            this.CheckSocketsLibs(Link.InputLibraries, LogQueue.Values);            

            //Analysing Files
            SortedList<int, RequiredObject> ReqObjs = Link.GetAllRequiredObjects();
            this.AnalizeInputObjects(ReqObjs);//, LogQueue.Values);

            if (!Link.CheckItems())
            {
                throw new MessagesParserException(KeilWizardStrings.IDS_ERROR_FAIL_LINK_ANALYSE);
            }

            OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.DONE));
            OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.START));
            index = 0;
            //Collects required files
            List<RequiredLibrary> ReqLib = Link.GetAllSubRequiredLibraries();

            foreach (RequiredObject obj in ReqObjs.Values)
            {
                index++;
                OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_FILE_LIST, GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / (ReqObjs.Values.Count + ReqLib.Count))));
                this.AddObjFile(obj);
            }
            foreach (RequiredLibrary lib in ReqLib)
            {
                index++;
                OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_FILE_LIST, GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / (ReqObjs.Values.Count + ReqLib.Count))));
                uVisionProject.AddFile(lib.OutputFileuVision, Path.GetFileNameWithoutExtension(lib.Parent.Name));
            }

            //Sorting groups
            uVisionProject.SortGroups();

            foreach (RequiredLibrary lib in Link.InputLibraries.Values)
            {
                uVisionProject.AddFile(lib.OutputFileuVision, Path.GetFileNameWithoutExtension(Link.Name));
            }
            OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_FILE_LIST, GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.WORKING, 100));
            System.Threading.Thread.Sleep(sleeptime);
            OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.DONE));
            OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.START));
            //Create targets
            index = 0;
            foreach (RequiredLibrary lib in Link.InputLibraries.Values)
            {
                index++;
                OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_TARGETS, GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / (Link.InputLibraries.Count))));

                this.CreateLibraryTartet(lib);
            }

            this.CreateLinkTarget(Link);//, LogQueue.Values);

            OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_TARGETS, GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.WORKING, 100));
            System.Threading.Thread.Sleep(sleeptime);
            OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.DONE));

            //using (StreamWriter outfile = new StreamWriter(Path.GetFileNameWithoutExtension(Link.Name) + ".result"))
            //{
            //    List<string> strs = uVisionProject.GetAllProjectStrings();
            //    foreach (string s in strs)
            //    {
            //        outfile.WriteLine(s);
            //    }
            //}
        }
        private void AddCompileFile(RequiredObject obj, Target target)
        {
            string DefaultWorkingDir = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(obj.CurrentDir);
            foreach (string path in obj.ParamCollection.Files.Values)
            {
                PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.FileOptions fileOpt = target.FindFileOptions(Path.GetFullPath(ExpandPath(path)));
                if (fileOpt == null) throw new MessagesParserException(KeilWizardStrings.IDS_ERROR_INTERNAL + " " + path + ": " + KeilWizardStrings.IDS_ERROR_CANT_FIND_COMPILE_FILE_OPTIONS);


                fileOpt.IncBld = THREE_STATE_BOOL.ENABLED;

                foreach (ArgCollection arg in obj.ParamCollection.Values)
                {
                    if (arg.Tag != "options") continue;
                    switch (arg.Name)
                    {
                        case "-I":
                            foreach (string include in arg)
                            {
                                fileOpt.Include.Add(include);
                            }
                            break;
                        case "-D":

                            foreach (string def in arg)
                            {
                                if (!def.Contains("="))
                                    fileOpt.Define.Add(def);
                                else
                                    fileOpt.Misc.Add("-D" + def);
                            }

                            break;
                        case "--PD":
                            foreach (string def in arg)
                            {
                                if (fileOpt.File.Type == PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.File.FILE_TYPE.ASM_FILE)
                                    fileOpt.Misc.Add("--PD " + def);
                            }
                            break;
                        case "--split_sections":
                            fileOpt.ADSCCFLG.One_EFL_Section_per_Function = THREE_STATE_BOOL.ENABLED;
                            break;
                        //case "--fpu":
                        //    fileOpt.Misc.Add("--fpu " + arg[0]);
                        //    break;
                        case "--littleend":
                            fileOpt.Misc.Add("--littleend");
                            break;
                        case "-c":
                            break;
                        case "--cpp":
                            fileOpt.Misc.Add("--cpp");
                            break;
                        case "-O":
                            OPTIMIZATION tmp = OPTIMIZATION.Default;
                            switch (arg[0])
                            {
                                case "0":
                                    tmp = OPTIMIZATION.Level0;
                                    break;
                                case "1":
                                    tmp = OPTIMIZATION.Level1;
                                    break;
                                case "2":
                                    tmp = OPTIMIZATION.Level2;
                                    break;
                                case "3":
                                    tmp = OPTIMIZATION.Level3;
                                    break;
                                default:
                                    break;
                            }
                            fileOpt.ADSCCFLG.Optimisation = tmp;
                            break;
                        case "--diag_suppress":
                            foreach (string item in arg)
                            {
                                //if (!target.Options.ADSCMISC.Contains("--diag_suppress " + item))
                                //{
                                fileOpt.Misc.Add("--diag_suppress " + item);
                                //}
                            }

                            break;
                        //Ignored. uVision IDE sets it by default
                        case "--device":
                            break;
                        //Special process for this param
                        case "-o":
                            //obj.OutputFileuVision = uVisionProjectPath + target.Options.OutDir.Replace(".", "") + Path.GetFileNameWithoutExtension(arg[0]) + ".o ";
                            break;
                        case "--LIST":
                        case "--list":
                            //s = "IF NOT EXIST " + Path.GetDirectoryName(arg[0]) + " md " + Path.GetDirectoryName(arg[0]);
                            //if (!target.BeforeBuild.Contains(s))
                            //    target.BeforeBuild.Add(s);
                            break;
                        default:
                            string str = arg.Name;
                            foreach (string item in arg)
                            {
                                str += " " + item;
                            }
                            fileOpt.Misc.Add(str);
                            break;
                    }
                }
            }
            Directory.SetCurrentDirectory(DefaultWorkingDir);
        }
        private void AnalizeInputLibraries(SortedList<int, RequiredLibrary> Libraryes, IList<LogQueueItem> LogMessages)
        {
            //PKParser.Arg.PKArgParser ArgParser = new PKParser.Arg.PKArgParser();
            int index = 0;
            foreach (RequiredLibrary lib in Libraryes.Values)
            {
                index++;
                OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_ANALYSE_LYBRARIES_LINKS, GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / Libraryes.Values.Count)));

                foreach (ParCollContainer container in ARMAR.Values)
                {
                    ParamCollection par = container.ParamCollection;
                    if (par == null) continue;

                    bool Found = false;

                    foreach (ArgCollection arg in par.Values)
                    {
                        if (arg.Tag == "archive")
                        {
                            if (String.Compare(Path.GetFileName(arg.Name), lib.Name, StringComparison.InvariantCultureIgnoreCase) == 0) Found = true;
                        }
                    }

                    if (!Found) continue;

                    lib.ConsoleString = container.Message;
                    lib.ParamCollection = par;
                    lib.BuildList.AddRange(container.ProjectBuildContext);
                    lib.OutputFileuVision = uVisionProjectPath + "\\" + uVisionTargetsPath + "\\" + Path.GetFileNameWithoutExtension(lib.Name) + "\\" + Path.GetFileName(lib.Name);

                    string LIB_EXT = string.Empty;
                    string OBJ_EXT = string.Empty;

                    using (ProjectCollection LocalProjColl = new ProjectCollection())
                    {
                        Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]);
                        LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT");
                        OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT");
                    }

                    foreach (string file in par.Files.Values)
                    {
                        RequiredLibrary libr = null;
                        RequiredObject obj = null;

                        if (Path.GetExtension(file).ToLower() == "." + LIB_EXT.ToLower())
                        {
                            libr = new RequiredLibrary(file, lib);
                            lib.InputLibraries.Add(lib.InputLibraries.Count + 1, libr);
                        }

                        if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower())
                        {
                            obj = new RequiredObject(file, lib);
                            lib.InputObjects.Add(lib.InputObjects.Count + 1, obj);
                        }
                        if (libr != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, libr);
                        if (obj != null) lib.AllInputs.Add(lib.AllInputs.Count + 1, obj);
                    }

                    foreach (ArgCollection arg in par.Values)
                    {
                        switch (arg.Tag)
                        {
                            case "options":
                                if (arg.Count > 0)
                                    foreach (string s in arg)
                                    {
                                        lib.OptionsString.Add(arg.Name + " " + s);
                                    }
                                else
                                    lib.OptionsString.Add(arg.Name);
                                break;
                            case "archive":
                                lib.OutputFileMSBuild = arg.Name;
                                break;
                        }
                    }
                }
                if (lib.InputLibraries.Count > 0) this.AnalizeInputLibraries(lib.InputLibraries, LogMessages);
            }
            OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_ANALYSE_LYBRARIES_LINKS, GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.WORKING, 100));
            System.Threading.Thread.Sleep(sleeptime);
        }
        private void CreateObjectTartet(RequiredObject obj)
        {
            Target target = new Target(uVisionProject.DefaultOptions);
            //Setting default options
            //target.SeTLPC2478DefaultOptions();

            target.Name = Path.GetFileNameWithoutExtension(obj.Name);
            target.Options.OutDir += uVisionTargetsPath + "\\" + target.Name + "\\";
            target.Options.OutName = Path.GetFileNameWithoutExtension(obj.Name);

            target.Options.GenApp = TWO_STATE_BOOL.DISABLED;
            target.Options.GenLib = TWO_STATE_BOOL.ENABLED;

            target.Options.ADSFLGA = "226,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0";

            target.Options.ADSCCFLG.ARM_Thumb_Interworking = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.Optimisation = OPTIMIZATION.Level0;
            target.Options.ADSCCFLG.Optimize_for_time = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.Split_Load_and_Store_Multiple = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.One_EFL_Section_per_Function = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.Strict_ANSI_C = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.Enum_Container_always_int = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.Plain_Char_is_Signed = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.ReadOnly_Position_Independent = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.ReadWrite_Position_Independent = THREE_STATE_BOOL.DISABLED;
            target.Options.ADSCCFLG.Thumb_Mode = THREE_STATE_BOOL.DISABLED;

            target.Options.ADSASFLG = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0";

            target.Options.Debug = "1";
            target.Options.Browse = "1";

            //Exclude files from building
            foreach (PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.File f in uVisionProject.FileList.Values)
            {
                PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.FileOptions fileopt = new PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.FileOptions(f);
                fileopt.IncBld = THREE_STATE_BOOL.DISABLED;
                target.FilesOpton.Add(fileopt);
            }

            this.AddCompileFile(obj, target);


            target.Num = uVisionProject.TargetList.Count + 1;
            uVisionProject.TargetList.Add(target.Num, target);

            if (target.BeforeBuild.Count > 0)
            {
                target.Options.BrunUsr_0.Run = TWO_STATE_BOOL.ENABLED;
                target.Options.BrunUsr_0.Command = ".\\BatFiles\\Prebuild" + @"\" + target.Name + ".bat";
            }

            if (target.AfterBuild.Count > 0)
            {
                target.Options.RunUsr_0.Run = TWO_STATE_BOOL.ENABLED;
                target.Options.RunUsr_0.Command = ".\\BatFiles\\Postbuild" + @"\" + target.Name + ".bat";
            }
        }