Пример #1
0
        }//method: PopulateSolutionInfo()

        /// <summary>
        /// Loads the appropriate version of Visual Studio
        /// available for conversion to display in the listbox
        /// </summary>
        /// <param name="version">double indicating the current version number
        /// of the selected Visual Studio project/solution file</param>
        private void LoadChoices(double version)
        {
            Dictionary <double, string> dictVSVersion        = new Dictionary <double, string>();
            Dictionary <double, string> dictVSCurrentVersion = new Dictionary <double, string>();
            string vsCurrentVersion = string.Empty;

            //Clear out the current contents of the listbox
            lbVersion.Items.Clear();

            //Initialize the possible existing versions of Visual Studio
            dictVSCurrentVersion = VSUtils.PopulateVSExistingVersion();

            //Initialize the possible supported versions of Visual Studio
            dictVSVersion = VSUtils.PopulateVSSupportedVersion();


            //Check if the existing element already exists in the collection
            if (dictVSCurrentVersion.ContainsKey(version))
            {
                vsCurrentVersion = dictVSCurrentVersion[version];
            }//if

            //Remove any elements which are invalid conversion options
            dictVSVersion.Remove(version);

            //Loop through the available valid conversion options
            //and add the items to the listbox for display
            foreach (var vsVersion in dictVSVersion.Keys)
            {
                lbVersion.Items.Add(dictVSVersion[vsVersion]);
            }//foreach

            //Set the label text to display the currently selected version Visual Studio project/solution file
            lbMessage.Text = vsCurrentVersion;
        }
Пример #2
0
        /// <summary>
        /// Makes a backup copy of the existing Visual Studio project file
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="ExistingVersion"></param>
        public static void MakeBackup(string FileName, double ExistingVersion)
        {
            string Backup = string.Empty;

            Dictionary <double, string> dictVSVersionString = new Dictionary <double, string>();

            //Get the list of available Visual Studio version numbers
            dictVSVersionString = VSUtils.PopulateVSVersionString();

            if (dictVSVersionString.ContainsKey(ExistingVersion))
            {
                string strVSVersion = dictVSVersionString[ExistingVersion];
                Backup = Path.Combine(Path.GetDirectoryName(FileName), string.Format("{0}{1}{2}", Path.GetFileNameWithoutExtension(FileName), strVSVersion, Path.GetExtension(FileName)));
            }//if
            else
            {
                // not likely
                MessageBox.Show("Not a supported version", "Internal Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            File.Copy(FileName, Backup, true);
        }
        }//method: CheckValidSolution

        /// <summary>
        /// Parses through the Visual Studio Solution file
        /// to populate all of the required properties
        /// </summary>
        public void ParseVSSolutionFile()
        {
            FileStream   fs  = null;
            StreamReader sr  = null;
            BinaryReader br  = null;
            string       buf = null;

            byte[] bom = null;

            // First we read the solution file and build a list of
            // project files that we find inside.  We need both a binary
            // reader and stream reader.
            using (fs = new FileStream(this.SolnFilePath, FileMode.Open))
            {
                sr = new StreamReader(fs);
                br = new BinaryReader(fs);

                // There is not need to handle Unicode Byte Order Mark,
                // it has been handled by StreamReader.

/*
 *                              // let's read Unicode Byte Order Mark (with CRLF)
 *              bom = br.ReadBytes(5);
 *
 *              // if we don't have a BOM, we create a default one
 *              if (bom[0] != 0XEF)
 *              {
 *                  bom[0] = 0XEF;
 *                  bom[1] = 0XBB;
 *                  bom[2] = 0XBF;
 *                  bom[3] = 0XD;
 *                  bom[4] = 0XA;
 *
 *                  // rewind the streamreaders
 *                  fs.Seek(0, SeekOrigin.Begin);
 *              }
 */
                while (sr.Peek() >= 0)
                {
                    buf = sr.ReadLine();

                    // no need for any fancy parsing routines
                    if (buf.StartsWith("Microsoft Visual Studio Solution File, Format Version"))
                    {
                        //int intFormatIdx = buf.IndexOf("Format");
                        //this.SolnFileFormatHeader = buf.Substring(intFormatIdx);
                        this.SolnFileFormatHeader = buf;
                        this.FormatVersion        = double.Parse(buf.Substring(VSSolutionFormat.Format_Header.Length), System.Globalization.CultureInfo.GetCultureInfo("en-US"));

                        continue;
                    }//if

                    if (buf.StartsWith("# Visual"))
                    {
                        //const string starting_Chars = "# ";
                        //this.SolnFileVersionHeader = buf.Remove(0, starting_Chars.Length);
                        this.SolnFileVersionHeader = buf;
                        continue;
                    }//if


                    // parse the project files
                    if (buf.StartsWith("Project("))
                    {
                        string[] ProjLine  = null;
                        string[] ProjParts = null;
                        //Create a new instance of the class to store the Project File information
                        VSProjectFileInfo vsProjFileInfo = new VSProjectFileInfo();

                        //Split the entire project string using the equal separator
                        ProjLine = buf.Split('=');

                        //Split the second part of the project string using the comma separator
                        ProjParts = ProjLine[1].Split(',');

                        //TODO: Is there ever a scenario where there are more or less than 3 parts??
                        vsProjFileInfo.ProjectID           = VSUtils.GetProjectPart(ProjLine[0]);
                        vsProjFileInfo.Name                = VSUtils.GetProjectPart(ProjParts[0]);
                        vsProjFileInfo.ProjectRelativePath = VSUtils.GetProjectPart(ProjParts[1]);
                        vsProjFileInfo.Guid                = VSUtils.GetProjectPart(ProjParts[2]);

                        vsProjFileInfo.ProjectFullPath  = Path.Combine(this.SolnDirectory, vsProjFileInfo.ProjectRelativePath);
                        vsProjFileInfo.ProjectDirectory = Path.GetDirectoryName(vsProjFileInfo.ProjectFullPath);
                        vsProjFileInfo.ProjectExtension = Path.GetExtension(vsProjFileInfo.ProjectFullPath);
                        vsProjFileInfo.ProjectFileName  = string.Concat(vsProjFileInfo.Name, vsProjFileInfo.ProjectExtension);

                        //Add the project file info to the collection
                        m_projList.Add(vsProjFileInfo);

                        // we only support VB.Net and C# project files
                        if (vsProjFileInfo.ProjectExtension.Equals(VBProjExt) || vsProjFileInfo.ProjectExtension.Equals(CSharpProjExt))
                        {
                            //Add all of the supported project conversions to the List
                            this.SupportedProjectConvList.Add(vsProjFileInfo.ProjectFullPath);
                        }//if
                    }
                }
                fs.Close();
            }//using
        }