Exemplo n.º 1
0
        public static bool AddFileLinkToCurrentLuaProjectOrCreate(EnvDTE.DTE dte, string file)
        {
            if (AddFileLinkToFirstLuaProject(dte, file))
            {
                return(true);
            }

            EnvDTE.Solution solution = dte.Solution;
            try
            {
                string templatePath = solution.get_TemplatePath(LuaProjectFactoryGuid);
                if (string.IsNullOrEmpty(templatePath))
                {
                    return(false);
                }

                templatePath += LuaProjectName;

                string projectName = "temp_";//System.IO.Path.GetRandomFileName();
                if (Babe.Lua.Package.BabePackage.Setting != null)
                {
                    projectName += Babe.Lua.Package.BabePackage.Setting.CurrentSetting;
                }
                string projectFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), SettingFolder, ProjectFolder);
                string projectPath   = System.IO.Path.Combine(projectFolder, projectName);

                string projectFullName = System.IO.Path.Combine(projectPath, projectName + ".luaproj");
                //只在temp工程不存在时创建
                if (/*(dte.Solution.Count == 0) ||*/ !System.IO.File.Exists(projectFullName))
                {
                    //创建LuaProject
                    EnvDTE.Project project = solution.AddFromTemplate(templatePath, projectPath, projectName, false);
                }
                else
                {
                    solution.AddFromFile(projectFullName, false);
                }
            }
            catch
            {
                //System.Windows.Forms.MessageBox.Show("Lua Template Path is null,make sure BabeLuaDebug has been installed.");
            }

            return(AddFileLinkToFirstLuaProject(dte, file));
        }