/// <summary>
        /// Creates a temporary qt project template file. It creates the filters 
        /// in the order specified by the array.
        /// </summary>
        /// <param name="filters">The filters to add to the project file</param>
        /// <returns></returns>
        public static string CreateProjectTemplateFile(FakeFilter[] filters, bool useKeyword, string platformName)
        {
            // just to be safe
            ReleaseProjectTemplateFile();

            StreamWriter sw;
            tmpFiles = new System.CodeDom.Compiler.TempFileCollection();
            tmpFiles.KeepFiles = false;

            string tmpFile = tmpFiles.AddExtension("vcproj");

            try
            {
                if (SR.LanguageName == "ja")
                    sw = new StreamWriter(tmpFile, false, System.Text.Encoding.GetEncoding(932));
                else
                    sw = new StreamWriter(tmpFile, false);
            }
            catch (System.Exception e)
            {
                Messages.DisplayErrorMessage(e, SR.GetString("HelperFunctions_TryCreatingNewProject"));
                return null;
            }

            if (SR.LanguageName == "ja")
                sw.WriteLine("<?xml version=\"1.0\" encoding = \"shift_jis\"?>");
            else
                sw.WriteLine("<?xml version=\"1.0\" encoding = \"Windows-1252\"?>");
            sw.WriteLine("<VisualStudioProject");
            sw.WriteLine("    ProjectType=\"Visual C++\"");
            #if VS2005
            sw.WriteLine("    Version=\"8.00\"");
            #elif VS2008
            sw.WriteLine("    Version=\"9.00\"");
            #else
            sw.WriteLine("    Version=\"7.10\"");
            #endif
            sw.WriteLine("    ProjectGUID=\"{B12702AD-ABFB-343A-A199-8E24837244A3}\"");
            if (useKeyword)
                sw.WriteLine("    Keyword=\"" + Resources.qtProjectKeyword + "\">");
            else
                sw.WriteLine(">");

            sw.WriteLine("    <Platforms>");
            sw.WriteLine("        <Platform");
            sw.WriteLine("            Name=\"" + platformName + "\"/>");
            sw.WriteLine("    </Platforms>");
            sw.WriteLine("    <Configurations>");
            sw.WriteLine("        <Configuration");
            sw.WriteLine("            Name=\"Release|" + platformName + "\">");
            sw.WriteLine("        </Configuration>");
            sw.WriteLine("        <Configuration");
            sw.WriteLine("            Name=\"Debug|" + platformName + "\">");
            sw.WriteLine("        </Configuration>");
            sw.WriteLine("    </Configurations>");
            sw.WriteLine("    <Files>");

            for (int i=0; i<filters.Length; i++)
            {
                sw.WriteLine("        <Filter");
                sw.WriteLine("            Name=\"" + filters[i].Name + "\"");
                sw.WriteLine("            Filter=\"" + filters[i].Filter + "\"");
                if (!filters[i].ParseFiles)
                    sw.WriteLine("            ParseFiles=\"FALSE\"");
                if (!filters[i].SCCFiles)
                    sw.WriteLine("            SourceControlFiles=\"FALSE\"");
                sw.WriteLine("            UniqueIdentifier=\"" + filters[i].UniqueIdentifier + "\">");
                sw.WriteLine("        </Filter>");
            }

            sw.WriteLine("    </Files>");
            sw.WriteLine("</VisualStudioProject>");

            sw.Close();

            return tmpFile;
        }
        /// <summary>
        /// Returns true if the filter specified by its guid is currently
        /// selected and the filter is part of a Qt project. Otherwise, this
        /// function returns false.
        /// </summary>
        /// <param name="filterguid">A FakeFilter object.</param>
        public static bool IsFilterSelected(EnvDTE.DTE dteObject, FakeFilter filter)
        {
            if (dteObject == null)
                return false;

            try
            {
                System.Guid guid = new Guid("{6bb5f8f0-4483-11d3-8bcf-00c04f8ec28c}");
                EnvDTE.SelectedItems itms = dteObject.SelectedItems;

                foreach (EnvDTE.SelectedItem selItem in itms)
                {
                    if (selItem.ProjectItem == null)
                        continue;
                    string kindGuid = selItem.ProjectItem.Kind.Substring(1, selItem.ProjectItem.Kind.Length - 2);
                    if (kindGuid.ToLower() == guid.ToString().ToLower())
                    {
                        VCFilter filt = (VCFilter)selItem.ProjectItem.Object;
                        if (filt != null && filt.UniqueIdentifier != null
                            && filt.UniqueIdentifier.ToLower() == filter.UniqueIdentifier.ToLower()
                            && HelperFunctions.IsQt5Project(GetSelectedQtProject(dteObject)))
                            return true;
                    }
                }
                return false;
            }
            catch
            {
            }

            return false;
        }
Beispiel #3
0
        public VCFilter AddFilterToProject(FakeFilter filter)
        {
            try
            {
                VCFilter vfilt = FindFilterFromGuid(filter.UniqueIdentifier);
                if (vfilt == null)
                {
                    if (!vcPro.CanAddFilter(filter.Name))
                    {
                        vfilt = FindFilterFromName(filter.Name);
                        if (vfilt == null)
                            throw new Qt5VSException(SR.GetString("QtProject_ProjectCannotAddFilter", filter.Name));
                    }
                    else
                    {
                        vfilt = (VCFilter)vcPro.AddFilter(filter.Name);
                    }

                    vfilt.UniqueIdentifier = filter.UniqueIdentifier;
                    vfilt.Filter = filter.Filter;
                    vfilt.ParseFiles = filter.ParseFiles;
                }
                return vfilt;
            }
            catch
            {
                throw new Qt5VSException(SR.GetString("QtProject_ProjectCannotAddResourceFilter"));
            }
        }
        public static bool IsInFilter(VCFile vcfile, FakeFilter filter)
        {
            VCProjectItem item = (VCProjectItem)vcfile;

            while((item.Parent != null) && (item.Kind != "VCProject"))
            {
                item = (VCProjectItem)item.Parent;

                if (item.Kind == "VCFilter")
                {
                    VCFilter f = (VCFilter)item;
                    if (f.UniqueIdentifier != null
                        && f.UniqueIdentifier.ToLower() == filter.UniqueIdentifier.ToLower())
                        return true;
                }
            }
            return false;
        }
Beispiel #5
0
        public VCFile AddFileInSubfilter(FakeFilter filter, string platformFiliterName, string configFilterName, string fileName, bool checkForDuplicates)
        {
            try
            {
                VCFilter defaultFilter = FindFilterFromGuid(filter.UniqueIdentifier);
                if (defaultFilter == null)
                {
                    if (!vcPro.CanAddFilter(filter.Name))
                    {
                        // check if user already created this filter... then add guid
                        defaultFilter = FindFilterFromName(filter.Name);
                        if (defaultFilter == null)
                            throw new Qt5VSException(SR.GetString("QtProject_CannotAddFilter", filter.Name));
                    }
                    else
                    {
                        defaultFilter = (VCFilter)vcPro.AddFilter(filter.Name);
                    }

                    defaultFilter.UniqueIdentifier = filter.UniqueIdentifier;
                    defaultFilter.Filter = filter.Filter;
                    defaultFilter.ParseFiles = filter.ParseFiles;
                }
                VCFilter plaformFilter = null;
                if (!string.IsNullOrEmpty(platformFiliterName))
                {
                    string lowerSubFilterName = platformFiliterName.ToLower();
                    bool subfilterFound = false;
                    foreach (VCFilter subfilt in defaultFilter.Filters as IVCCollection)
                    {
                        if (subfilt.Name.ToLower() == lowerSubFilterName)
                        {
                            plaformFilter = subfilt;
                            subfilterFound = true;
                            break;
                        }
                    }
                    if (subfilterFound)
                    {
                        // Do filter names differ in upper/lower case?
                        if (platformFiliterName != plaformFilter.Name)
                        {
                            try
                            {
                                // Try to rename the filter for aesthetic reasons.
                                plaformFilter.Name = platformFiliterName;
                            }
                            catch
                            {
                                // Renaming didn't work. We don't care.
                            }
                        }
                    }
                    else
                    {
                        if (!defaultFilter.CanAddFilter(platformFiliterName))
                        {
                            throw new Qt5VSException(SR.GetString("QtProject_CannotAddFilter", filter.Name));
                        }
                        else
                        {
                            plaformFilter = (VCFilter)defaultFilter.AddFilter(platformFiliterName);
                        }

                        plaformFilter.Filter = "cpp;moc";
                        plaformFilter.SourceControlFiles = false;
                    }
                }
                VCFilter configFilter = null;
                if (!string.IsNullOrEmpty(configFilterName))
                {
                    VCFilter parentFilter = (plaformFilter == null) ? defaultFilter : plaformFilter;
                    string lowerSubFilterName = configFilterName.ToLower();
                    bool subfilterFound = false;
                    foreach (VCFilter subfilt in parentFilter.Filters as IVCCollection)
                    {
                        if (subfilt.Name.ToLower() == lowerSubFilterName)
                        {
                            configFilter = subfilt;
                            subfilterFound = true;
                            break;
                        }
                    }
                    if (subfilterFound)
                    {
                        // Do filter names differ in upper/lower case?
                        if (configFilterName != configFilter.Name)
                        {
                            try
                            {
                                // Try to rename the filter for aesthetic reasons.
                                configFilter.Name = configFilterName;
                            }
                            catch
                            {
                                // Renaming didn't work. We don't care.
                            }
                        }
                    }
                    else
                    {
                        if (!parentFilter.CanAddFilter(configFilterName))
                        {
                            throw new Qt5VSException(SR.GetString("QtProject_CannotAddFilter", filter.Name));
                        }
                        else
                        {
                            configFilter = (VCFilter)parentFilter.AddFilter(configFilterName);
                        }

                        configFilter.Filter = "cpp;moc";
                        configFilter.SourceControlFiles = false;
                    }
                }

                if (checkForDuplicates)
                {
                    // check if file exists in filter already
                    VCFile vcFile = GetFileFromFilter(filter, fileName);
                    if (vcFile != null)
                        return vcFile;
                }

                VCFilter targetFilter = defaultFilter;
                if (configFilter != null)
                    targetFilter = configFilter;
                else if (plaformFilter != null)
                    targetFilter = plaformFilter;

                string targetFilterGuid = targetFilter.UniqueIdentifier;

                try
                {
                    if (targetFilter.CanAddFile(fileName))
                    {
                        return (VCFile)(targetFilter.AddFile(fileName));
                    }
                }
                catch
                {

                }

                while ((targetFilter = FindFilterFromGuid(targetFilterGuid)) != null)
                {
                    try
                    {
                        if (targetFilter.CanAddFile(fileName))
                        {
                            return (VCFile)(targetFilter.AddFile(fileName));
                        }
                        else
                        {
                            return GetFileFromFilter(targetFilter, fileName);
                        }
                    }
                    catch
                    {
                    }
                }

                throw new Qt5VSException(SR.GetString("QtProject_CannotAddFile", fileName));
            }
            catch
            {
                throw new Qt5VSException(SR.GetString("QtProject_CannotAddFile", fileName));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Adds a file to a specified filter in a project.
        /// </summary>
        /// <param name="project">VCProject</param>
        /// <param name="srcFile">full name of the file to add</param>
        /// <param name="destName">name of the file in the project (relative to the project directory)</param>
        /// <param name="filter">filter</param>
        /// <returns>VCFile</returns>
        public VCFile AddFileToProject(string destName, FakeFilter filter)
        {
            VCFile file = null;
            if (filter != null)
                file = AddFileInFilter(filter, destName);
            else
                file = (VCFile)vcPro.AddFile(destName);

            if (file == null)
                return null;

            if (HelperFunctions.HasHeaderFileExtension(file.Name))
            {
                foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                    if (compiler == null)
                        continue;

                    string[] paths = compiler.GetAdditionalIncludeDirectoriesList();
                    FileInfo fi = new FileInfo(file.FullPath);
                    string relativePath = HelperFunctions.GetRelativePath(this.ProjectDir, fi.Directory.ToString());
                    string fixedRelativePath = FixFilePathForComparison(relativePath);
                    bool pathFound = false;
                    foreach (string p in paths) {
                        if (FixFilePathForComparison(p) == fixedRelativePath)
                        {
                            pathFound = true;
                            break;
                        }
                    }
                    if (!pathFound)
                        compiler.AddAdditionalIncludeDirectories(relativePath);
                }
            }
            return file;
        }
Beispiel #7
0
 /// <summary>
 /// Adds a file to a filter. If the filter doesn't exist yet, it
 /// will be created.
 /// </summary>
 /// <param name="filter">fake filter</param>
 /// <param name="fileName">relative file name</param>
 /// <param name="checkForDuplicates">true if we don't want duplicated files</param>
 /// <returns>A VCFile object of the added file.</returns>
 public VCFile AddFileInFilter(FakeFilter filter, string fileName, bool checkForDuplicates)
 {
     return AddFileInSubfilter(filter, null, null, fileName, checkForDuplicates);
 }
Beispiel #8
0
 public VCFile AddFileInSubfilter(FakeFilter filter, string platformFiliter, string configFilter, string fileName)
 {
     return AddFileInSubfilter(filter, platformFiliter, configFilter, fileName, false);
 }
Beispiel #9
0
        /// <summary>
        /// Removes a file from the filter.
        /// This file will be deleted!
        /// </summary>
        /// <param name="project">project</param>
        /// <param name="file">file</param>
        public void RemoveFileFromFilter(VCFile file, FakeFilter filter)
        {
            try
            {
                VCFilter vfilt = FindFilterFromGuid(filter.UniqueIdentifier);

                if (vfilt == null)
                    vfilt = FindFilterFromName(filter.Name);

                if (vfilt == null)
                    return;

                RemoveFileFromFilter(file, vfilt);
            }
            catch
            {
                throw new Qt5VSException(SR.GetString("QtProject_CannotRemoveFile", file.Name));
            }
        }
Beispiel #10
0
 /// <summary>
 /// Adds a file to a filter. If the filter doesn't exist yet, it
 /// will be created. (Doesn't check for duplicates)
 /// </summary>
 /// <param name="filter">fake filter</param>
 /// <param name="fileName">relative file name</param>
 /// <returns>A VCFile object of the added file.</returns>
 public VCFile AddFileInFilter(FakeFilter filter, string fileName)
 {
     return AddFileInFilter(filter, fileName, false);
 }
Beispiel #11
0
        /// <summary>
        /// Returns the file if it can be found, otherwise null.
        /// </summary>
        /// <param name="filter">filter name</param>
        /// <param name="fileName">relative file path to the project</param>
        /// <returns></returns>
        public VCFile GetFileFromFilter(FakeFilter filter, string fileName)
        {
            VCFilter vcfilter = FindFilterFromGuid(filter.UniqueIdentifier);

            // try with name as well
            if (vcfilter == null)
                vcfilter = FindFilterFromName(filter.Name);

            if (vcfilter == null)
                return null;

            return GetFileFromFilter(vcfilter, fileName);
        }
Beispiel #12
0
        private void CreateProject(EnvDTE.DTE app, string proName,
            string proPath, string slnName, bool exclusive, FakeFilter[] filters,
            string qtVersion, string platformName)
        {
            QtVersionManager versionManager = QtVersionManager.The();
            if (qtVersion == null)
                qtVersion = versionManager.GetDefaultVersion();

            if (qtVersion == null)
                throw new Qt5VSException("Unable to find a Qt build!\r\n"
                    + "To solve this problem specify a Qt build");

            string solutionPath = "";
            Solution newSolution = app.Solution;

            if (platformName == null)
            {
                string tmpQtVersion = versionManager.GetSolutionQtVersion(newSolution);
                qtVersion = tmpQtVersion != null ? tmpQtVersion : qtVersion;
                try
                {
                    VersionInformation vi = new VersionInformation(versionManager.GetInstallPath(qtVersion));
                    if (vi.is64Bit())
                        platformName = "x64";
                    else
                        platformName = "Win32";
                }
                catch (Exception e)
                {
                    Messages.DisplayErrorMessage(e);
                }
            }

            if (!string.IsNullOrEmpty(slnName) && (exclusive == true))
            {
                solutionPath = proPath.Substring(0, proPath.LastIndexOf("\\"));
                newSolution.Create(solutionPath, slnName);
            }

            System.IO.Directory.CreateDirectory(proPath);
            string templatePath = HelperFunctions.CreateProjectTemplateFile(filters, true, platformName);

            pro = newSolution.AddFromTemplate(templatePath, proPath, proName, exclusive);

            HelperFunctions.ReleaseProjectTemplateFile();

            qtPro = QtProject.Create(pro);
            QtVSIPSettings.SaveUicDirectory(pro, null);
            QtVSIPSettings.SaveMocDirectory(pro, null);
            QtVSIPSettings.SaveMocOptions(pro, null);
            QtVSIPSettings.SaveRccDirectory(pro, null);
            QtVSIPSettings.SaveLUpdateOnBuild(pro);
            QtVSIPSettings.SaveLUpdateOptions(pro, null);
            QtVSIPSettings.SaveLReleaseOptions(pro, null);

            foreach (string kPlatformName in (Array)pro.ConfigurationManager.PlatformNames)
            {
                versionManager.SaveProjectQtVersion(pro, "$(DefaultQtVersion)", kPlatformName);
            }
            
            qtPro.MarkAsQtProject("v1.0");
            qtPro.AddDirectories();
            qtPro.SelectSolutionPlatform(platformName);

            if (!string.IsNullOrEmpty(slnName) && (exclusive == true))
                newSolution.SaveAs(solutionPath + "\\" + slnName + ".sln");
        }
Beispiel #13
0
        public VCFile AddFileInSubfilter(FakeFilter filter, string subfilterName, string fileName, bool checkForDuplicates)
        {
            try
            {
                VCFilter vfilt = FindFilterFromGuid(filter.UniqueIdentifier);
                if (vfilt == null)
                {
                    if (!vcPro.CanAddFilter(filter.Name))
                    {
                        // check if user already created this filter... then add guid
                        vfilt = FindFilterFromName(filter.Name);
                        if (vfilt == null)
                            throw new QtVSException(SR.GetString("QtProject_CannotAddFilter", filter.Name));
                    }
                    else
                    {
                        vfilt = (VCFilter)vcPro.AddFilter(filter.Name);
                    }

                    vfilt.UniqueIdentifier = filter.UniqueIdentifier;
                    vfilt.Filter = filter.Filter;
                    vfilt.ParseFiles = filter.ParseFiles;
                }

                if (!string.IsNullOrEmpty(subfilterName))
                {
                    string lowerSubFilterName = subfilterName.ToLower();
                    bool subfilterFound = false;
                    foreach (VCFilter subfilt in vfilt.Filters as IVCCollection)
                    {
                        if (subfilt.Name.ToLower() == lowerSubFilterName)
                        {
                            vfilt = subfilt;
                            subfilterFound = true;
                            break;
                        }
                    }
                    if (subfilterFound)
                    {
                        // Do filter names differ in upper/lower case?
                        if (subfilterName != vfilt.Name)
                        {
                            try
                            {
                                // Try to rename the filter for aesthetic reasons.
                                vfilt.Name = subfilterName;
                            }
                            catch
                            {
                                // Renaming didn't work. We don't care.
                            }
                        }
                    }
                    if (!subfilterFound)
                    {
                        if (!vfilt.CanAddFilter(subfilterName))
                        {
                            throw new QtVSException(SR.GetString("QtProject_CannotAddFilter", filter.Name));
                        }
                        else
                        {
                            vfilt = (VCFilter)vfilt.AddFilter(subfilterName);
                        }

                        vfilt.Filter = "cpp;moc";
                        vfilt.SourceControlFiles = false;
                    }
                }

                if (checkForDuplicates)
                {
                    // check if file exists in filter already
                    VCFile vcFile = GetFileFromFilter(filter, fileName);
                    if (vcFile != null)
                        return vcFile;
                }

                if (vfilt.CanAddFile(fileName))
                    return (VCFile)(vfilt.AddFile(fileName));
                else
                    throw new QtVSException(SR.GetString("QtProject_CannotAddFile", fileName));
            }
            catch
            {
                throw new QtVSException(SR.GetString("QtProject_CannotAddFile", fileName));
            }
        }
Beispiel #14
0
        /// <summary>
        /// Returns the file if it can be found, otherwise null.
        /// </summary>
        /// <param name="filter">filter name</param>
        /// <param name="fileName">relative file path to the project</param>
        /// <returns></returns>
        public VCFile GetFileFromFilter(FakeFilter filter, string fileName)
        {
            VCFilter vcfilter = FindFilterFromGuid(filter.UniqueIdentifier);

            // try with name as well
            if (vcfilter == null)
                vcfilter = FindFilterFromName(filter.Name);

            if (vcfilter == null)
                return null;

            try
            {
                FileInfo fi = null;
                if (Path.IsPathRooted(fileName))
                    fi = new FileInfo(fileName);
                else
                    fi = new FileInfo(ProjectDir + "\\" + fileName);

                if (fi == null)
                    return null;

                foreach (VCFile file in (IVCCollection)vcfilter.Files)
                {
                    if (file.MatchName(fi.FullName, true))
                        return file;
                }
            }
            catch {}
            return null;
        }
Beispiel #15
0
        public static void SyncIncludeFiles(VCProject vcproj, List<string> priFiles,
            List<string> projFiles, EnvDTE.DTE dte, bool flat, FakeFilter fakeFilter)
        {
            List<string> cmpPriFiles = new List<string>(priFiles.Count);
            foreach (string s in priFiles)
                cmpPriFiles.Add(HelperFunctions.NormalizeFilePath(s).ToLower());
            cmpPriFiles.Sort();

            List<string> cmpProjFiles = new List<string>(projFiles.Count);
            foreach (string s in projFiles)
                cmpProjFiles.Add(HelperFunctions.NormalizeFilePath(s).ToLower());

            QtProject qtPro = QtProject.Create(vcproj);
            Hashtable filterPathTable = new Hashtable(17);
            Hashtable pathFilterTable = new Hashtable(17);
            if (!flat && fakeFilter != null)
            {
                VCFilter rootFilter = qtPro.FindFilterFromGuid(fakeFilter.UniqueIdentifier);
                if (rootFilter == null)
                    qtPro.AddFilterToProject(Filters.SourceFiles());

                CollectFilters(rootFilter, null, ref filterPathTable, ref pathFilterTable);
            }

            // first check for new files
            foreach(string file in cmpPriFiles)
            {
                if (cmpProjFiles.IndexOf(file) > -1)
                    continue;

                if (flat)
                {
                    vcproj.AddFile(file); // the file is not in the project
                }
                else
                {
                    string path = HelperFunctions.GetRelativePath(vcproj.ProjectDirectory, file);
                    if (path.StartsWith(".\\"))
                        path =  path.Substring(2);

                    int i = path.LastIndexOf('\\');
                    if (i > -1)
                        path = path.Substring(0, i);
                    else
                        path = ".";

                    if (pathFilterTable.Contains(path))
                    {
                        VCFilter f = pathFilterTable[path] as VCFilter;
                        f.AddFile(file);
                        continue;
                    }

                    VCFilter filter = BestMatch(path, pathFilterTable);

                    string filterDir = filterPathTable[filter] as string;
                    string name = path;
                    if (!name.StartsWith("..") && name.StartsWith(filterDir))
                        name = name.Substring(filterDir.Length + 1);

                    VCFilter newFilter = filter.AddFilter(name) as VCFilter;
                    newFilter.AddFile(file);

                    filterPathTable.Add(newFilter, path);
                    pathFilterTable.Add(path, newFilter);
                }
            }

            // then check for deleted files
            foreach (string file in cmpProjFiles)
            {
                if (cmpPriFiles.IndexOf(file) == -1)
                {
                    // the file is not in the pri file
                    // (only removes it from the project, does not del. the file)
                    FileInfo info = new FileInfo(file);
                    HelperFunctions.RemoveFileInProject(vcproj, file);
                    Messages.PaneMessage(dte, "--- (Importing .pri file) file: " + info.Name +
                        " does not exist in .pri file, move to " + vcproj.ProjectDirectory + "Deleted");
                }
            }
        }