public static bool ValidateCheckSum(string path)
        {
            CheckSumValidator current  = new CheckSumValidator(path);
            CheckSumValidator original = GetInfo(path);

            if (original == null)
            {
                //There is no pre-computed check-sum.
                return(true);
            }
            return(!current.HasEdits(original));
        }
        private static CheckSumValidator GetInfo(string path)
        {
            if (!File.Exists(path + "\\checksum"))
            {
                return(null);
            }
            BinaryFormatter   formatter = new BinaryFormatter();
            FileStream        stream    = new FileStream(path + "\\checksum", FileMode.Open);
            CheckSumValidator result    = (CheckSumValidator)formatter.Deserialize(stream);

            stream.Close();
            return(result);
        }
        /// <summary>
        /// Checks for edit and return true if there were edits.
        /// </summary>
        /// <param name="original"></param>
        /// <returns></returns>
        private bool HasEdits(CheckSumValidator original)
        {
            foreach (string s in original._files.Keys)
            {
                byte[] currentHash;
                if (!_files.TryGetValue(s, out currentHash))
                {
                    continue;
                }

                byte[] originalHash = original._files[s];

                if (currentHash.Length == originalHash.Length &&
                    originalHash.AllTrue((index, currByte) => currentHash[index].Equals(currByte)))
                {
                    continue;
                }

                if (MessageBox.Show(string.Format(
                                        "File has been edited and left in the ''Generated Files'' folder. Would you like "
                                        + "to overwrite it? File: {0}.", s),
                                    "Edited file in generated folder",
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    continue;     // continue checking, ignore this file.
                }

                return(true);
            }

            foreach (var s in _files.Keys)
            {
                if (original._files.ContainsKey(s))
                {
                    continue;
                }

                if (MessageBox.Show(string.Format(
                                        "File has been added to the \"Generated Files\" folder manually. "
                                        + "Would you like to overwrite it? File: {0}.", s),
                                    "Added file in generated folder",
                                    MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    continue;     // continue checking, ignore this file.
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// This function generated the project corresponding to the passed pipelineComponent.
        /// </summary>
        /// <param name="destPath">The destination path of the projects.</param>
        /// <param name="pipelineComponent">Which component to generate the project for.</param>
        /// <returns>The project generated.</returns>
        private Project createAddInProject(string destPath, PipelineSegmentSource pipelineComponent, PipelineConfiguration config)
        {
            // dest path will be the root of the project where we have addins,
            // so we need to select the correct project for this specific segment, if there is
            // one and take its path, otherwise do destPath.Combine(pipelineComponent.Name);
            string name;

            destPath = destPath.Combine(getSubPath(config, pipelineComponent, destPath, out name));
            var generatedDestPath = destPath.Combine(GENERETED_FILES_DIRECTORY);

            // the getSubPath will use the configuration to get the correct project,
            // if one was selected, and otherwise will return the name of the pipeline segment
            // so that getProjByName will return null if it's not existing and otherwise the correct
            // and selected project.
            Project proj = getProjByName(name);

            if (proj == null)
            {
                if (Directory.Exists(destPath))
                {
                    if (DialogResult.Yes == MessageBox.Show(string.Format("The directory {0} already exists, " +
                                                                          " would you like to delete it and use it for the generated files for the segment named {1}?",
                                                                          destPath, name), "Already existing directory", MessageBoxButtons.YesNoCancel))
                    {
                        Directory.Delete(destPath, true);
                    }
                    else
                    {
                        return(null);
                    }
                }

                Directory.CreateDirectory(destPath);

                string connectPath = Path.GetDirectoryName(typeof(PipelineBuilderCommand).Assembly.Location);

                proj = dte.Solution.AddFromTemplate(connectPath.Combine("Template.csproj"),
                                                    destPath,
                                                    pipelineComponent.Name + ".csproj",
                                                    false);
            }

            if (proj == null)
            {
                throw new InvalidOperationException("Problem in adding from template. "
                                                    + "You installation files for the pipeline builder may be corrupted.");
            }

            if (Directory.Exists(generatedDestPath))
            {
                CheckSumValidator.ValidateCheckSum(generatedDestPath);
            }

            deleteGeneratedFiles(proj);
            assertHasDirectory(proj, generatedDestPath);
            generateSourceFiles(pipelineComponent, generatedDestPath);
            addGeneratedFiles(proj, generatedDestPath);

            CheckSumValidator.StoreCheckSum(generatedDestPath);

            return(proj);
        }