Пример #1
0
        private List <IncludedFile> GetAllFilesIncludedInProject(string csProjPath, List <string> extensionsToConsider, string fileNamePrefixToConsider)
        {
            List <IncludedFile> r = new List <IncludedFile>();

            XmlDocument doc = new XmlDocument();

            doc.Load(csProjPath);
            XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);

            manager.AddNamespace("ns", doc.DocumentElement.Attributes["xmlns"].Value);
            XmlNodeList list = doc.SelectNodes("//ns:Compile", manager);

            foreach (XmlNode node in list)
            {
                if (node.Attributes["Include"] != null)
                {
                    var newItem = new IncludedFile();
                    newItem.IsJustLink = node.HasChildNodes && node.ChildNodes[0].Name == "Link";
                    if (newItem.IsJustLink)
                    {
                        newItem.FilePath = node.Attributes["Include"].Value;
                        newItem.FileName = Path.GetFileName(newItem.FilePath);
                    }
                    else
                    {
                        newItem.FileName = node.Attributes["Include"].Value;
                        newItem.FilePath = Path.Combine(Path.GetDirectoryName(csProjPath), newItem.FileName);
                    }

                    if (
                        string.Compare(Path.GetDirectoryName(newItem.FilePath), Path.GetDirectoryName(this.csProjFilePath), StringComparison.OrdinalIgnoreCase) != 0 &&
                        string.Compare(Path.GetDirectoryName(newItem.FilePath), Path.GetDirectoryName(this.csProjFilePathInOriginalBB), StringComparison.OrdinalIgnoreCase) != 0
                        )
                    {
                        //this file is not is local folder nor BB folder -skip
                    }
                    else
                    {
                        bool matchExtension = false;
                        foreach (string ext in extensionsToConsider)
                        {
                            if (newItem.FileName.ToLower().EndsWith(ext.ToLower()) && newItem.FileName.ToLower().StartsWith(fileNamePrefixToConsider.ToLower()))
                            {
                                matchExtension = true;
                            }
                        }

                        if (matchExtension)
                        {
                            r.Add(newItem);
                        }
                    }
                }
            }

            return(r);
        }
Пример #2
0
        public void BuildMinimalVersion()
        {
            try
            {
                if (!this._shouldPerform)
                {
                    LogError(new Exception("CRAFTSYNTH_BUILDING_BLOCKS_FOLDER_PATH not found in Windows Environment Variables. This is OK if you are not developing BuildingBlocks."));
                }
                else
                {
                    //get files that are required from .ini
                    this.filesRequiredForMinimalVersion = new List <string>();
                    if (GetVersionFromIniFile() >= 3)
                    {
                        this.filesRequiredForMinimalVersion = this.GetFileNamesFromSectionInIniFile("FilesRequiredForMinimalVersion");
                    }
                    else
                    {
                        var lines = File.ReadAllLines(Path.Combine(ApplicationPhysicalPath, "Regenerator.ini"));
                        foreach (string line in lines)
                        {
                            if (!string.IsNullOrEmpty(line) && !line.StartsWith("//") && !line.StartsWith("["))
                            {
                                this.filesRequiredForMinimalVersion.Add(line.Trim());
                            }
                        }
                    }

                    //check existance of each in original BB project
                    foreach (string f in this.filesRequiredForMinimalVersion)
                    {
                        if (
                            !this.IncludedItemsInOriginalBB.Exists(
                                i => i.IsJustLink == false && string.Compare(i.FileName, f.Trim(), StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            throw new Exception(
                                      string.Format(
                                          "File '{0}' is specified as required in .ini but it is not included in original BB project '{1}' or file is specified in [FilesNeverToInclude] section in ini.",
                                          f.Trim(), this.csProjFilePathInOriginalBB));
                        }
                    }


                    //first exclude all non-required files that have one of considered extensions
                    for (int j = this.IncludedItems.Count - 1; j >= 0; j--)
                    {
                        IncludedFile includedFile = this.IncludedItems[j];
                        if (filesRequiredForMinimalVersion.Exists(f => string.Compare(f, includedFile.FileName, StringComparison.OrdinalIgnoreCase) == 0))
                        {                        //this is required file and already included
                            if (!includedFile.IsJustLink)
                            {
                                string originalFilePath = Path.Combine(Path.GetDirectoryName(this.csProjFilePathInOriginalBB),
                                                                       includedFile.FileName);
                                if (!File.Exists(includedFile.FilePath) || !FilesContentsAreEqual(includedFile.FilePath, originalFilePath))
                                {                                //this is real file but has different content -overwrite it with original
                                    File.Copy(originalFilePath, includedFile.FilePath, true);
                                }
                                else
                                {                                //this is real file and is same as original -that is what we need -do nothing
                                }
                            }
                            else
                            {                            //this is link to file -remove it
                                if (!ExcludeFromProject(csProjFilePath, includedFile.FileName))
                                {
                                    ExcludeFromProject(csProjFilePath, includedFile.FilePath);
                                }
                                this.IncludedItems.RemoveAt(j);
                            }
                        }
                        else
                        {
                            if (!extensionsToConsider.Exists(e => includedFile.FileName.ToLower().EndsWith(e.ToLower())) || !includedFile.FileName.ToLower().StartsWith(fileNamePrefixToConsider.ToLower()))
                            {                            //this is non-required file but also has strange extension
                                //leave it
                            }
                            else
                            {                            //this is non-required file and has one of extensions we consider - exclude it
                                if (!this.ExcludeFromProject(this.csProjFilePath, includedFile.FileName))
                                {
                                    this.ExcludeFromProject(this.csProjFilePath, includedFile.FilePath);
                                }
                                this.IncludedItems.RemoveAt(j);
                            }
                        }
                    }

                    //then delete  all non-reqired files that have one of considered extensions
                    var localFilePaths = GetFilePaths(ApplicationPhysicalPath, extensionsToConsider, fileNamePrefixToConsider);
                    for (int i = localFilePaths.Count - 1; i >= 0; i--)
                    {
                        if (this.filesRequiredForMinimalVersion.Exists(r => string.Compare(Path.GetFileName(localFilePaths[i]), r.Trim(), StringComparison.OrdinalIgnoreCase) == 0))
                        {                        //this local file is required -do nothing
                        }
                        else
                        {                        //this local file is not required - delete it
                            File.Delete(localFilePaths[i]);
                        }
                    }

                    //lastly insure that each required file exist and is same as original one or perform copy from original file
                    //and also insure it is included in project
                    foreach (string requiredFile in filesRequiredForMinimalVersion)
                    {
                        var    fileAtOriginalBB = this.IncludedItemsInOriginalBB.SingleOrDefault(i => i.IsJustLink == false && string.Compare(i.FileName, requiredFile, StringComparison.OrdinalIgnoreCase) == 0);
                        String filePathLocal    = Path.Combine(ApplicationPhysicalPath, fileAtOriginalBB.FileName);

                        if (
                            !this.IncludedItems.Exists(
                                i => i.IsJustLink == false && string.Compare(i.FileName, requiredFile, StringComparison.OrdinalIgnoreCase) == 0))
                        {                        //not included
                            File.Copy(fileAtOriginalBB.FilePath, filePathLocal, true);
                            IncludeInProject(this.csProjFilePath, fileAtOriginalBB.FileName, false);
                            this.IncludedItems.Add(new IncludedFile(fileAtOriginalBB.FileName, filePathLocal, false));
                        }
                        else
                        {                        //included allready
                            if (File.Exists(filePathLocal))
                            {
                                if (FilesContentsAreEqual(filePathLocal, fileAtOriginalBB.FilePath))
                                {
                                    //do nothing
                                }
                                else
                                {
                                    File.Copy(fileAtOriginalBB.FilePath, filePathLocal, true);
                                }
                            }
                        }
                    }

                    ClearErrorLog();
                }
            }
            catch (Exception e)
            {
                LogError(e);
            }
        }
Пример #3
0
        public void LinkFullVersion()
        {
            try
            {
                if (!this._shouldPerform)
                {
                    LogError(new Exception("CRAFTSYNTH_BUILDING_BLOCKS_FOLDER_PATH not found in Windows Environment Variables. This is OK if you are not developing BuildingBlocks."));
                }
                else
                {
                    //first exclude all files that has one of extension we consider but are not part of original BB
                    for (int j = this.IncludedItems.Count - 1; j >= 0; j--)
                    {
                        IncludedFile includedFile = this.IncludedItems[j];
                        if (this.IncludedItemsInOriginalBB.Exists(f => string.Compare(f.FilePath, includedFile.FilePath, StringComparison.OrdinalIgnoreCase) == 0))
                        {                        //this is required file and already included
                            if (includedFile.IsJustLink)
                            {
                                //and is just link -that is what we need -do nothing
                            }
                            else
                            {                            //and is not link - reinclude as link
                                if (!ExcludeFromProject(csProjFilePath, includedFile.FilePath))
                                {
                                    ExcludeFromProject(csProjFilePath, includedFile.FileName);
                                }
                                IncludeInProject(csProjFilePath, includedFile.FilePath, true);
                                includedFile.IsJustLink = true;
                            }
                        }
                        else
                        {
                            if (!extensionsToConsider.Exists(e => includedFile.FileName.ToLower().EndsWith(e.ToLower())) || !includedFile.FileName.ToLower().StartsWith(fileNamePrefixToConsider.ToLower()))
                            {                            //this is non-required file but also has strange extension
                                //leave it
                            }
                            else
                            {                            //this is non-required file and has one of extensions we consider - exclude it
                                if (!this.ExcludeFromProject(this.csProjFilePath, includedFile.FilePath))
                                {
                                    this.ExcludeFromProject(this.csProjFilePath, includedFile.FileName);
                                }
                                this.IncludedItems.RemoveAt(j);
                            }
                        }
                    }

                    //second insure that all files included in original BB are linked
                    foreach (IncludedFile includedFileInOriginalBB in IncludedItemsInOriginalBB)
                    {
                        if (!this.IncludedItems.Exists(
                                ii => string.Compare(ii.FilePath, includedFileInOriginalBB.FilePath, StringComparison.OrdinalIgnoreCase) == 0 &&
                                ii.IsJustLink == true)
                            )
                        {
                            this.IncludeInProject(this.csProjFilePath,
                                                  Path.Combine(Path.GetDirectoryName(includedFileInOriginalBB.FilePath), includedFileInOriginalBB.FileName), true);
                        }
                    }

                    ClearErrorLog();
                }
            }
            catch (Exception e)
            {
                LogError(e);
            }
        }