예제 #1
0
        /// <summary>
        /// Automatically loads the data from the RC file
        /// </summary>
        /// <param name="aRcFile"></param>
        /// <param name="aShowGhostFile"></param>
        public StringResourceContext(RcFile aRcFile, bool aShowGhostFile)
        {
            RcFile         = aRcFile;
            mShowGhostFile = aShowGhostFile;

            var rcFilePath = RcFile.FilePath;

            mCodePage = CodePageExtractor.GetCodePage(rcFilePath);

            mHeaderContentBuilder = new HeaderContentBuilder(rcFilePath, mCodePage);
            mHeaderContentBuilder.Build();
            mHeaderContent = mHeaderContentBuilder.GetResult();

            HeaderContent = mHeaderContent;

            mRCFileContentBuilder = new RCFileContentBuilder(rcFilePath, mCodePage, mHeaderContent);
            mRCFileContentBuilder.Build();
            mRCFileContent = mRCFileContentBuilder.GetResult();

            mWriteRCPath  = Path.GetTempFileName();
            mRCFileWriter = new RCFileWriter(mRCFileContent, rcFilePath, mShowGhostFile);

            var headerNames = HeaderNamesExtractor.ExtractHeaderNames(RcFile.FilePath, mCodePage);

            if (!headerNames.Any())
            {
                return;
            }

            var rcFileDirectory = Path.GetDirectoryName(RcFile.FilePath);
            var headerPath      = Path.Combine(rcFileDirectory, headerNames.FirstOrDefault(headerName => headerName.ToLower().Equals("resource.h") &&
                                                                                           File.Exists(Path.Combine(rcFileDirectory, headerName)))
                                               ?? headerNames.FirstOrDefault(
                                                   headerName => headerName.ToLower().Contains("resource") &&
                                                   File.Exists(Path.Combine(rcFileDirectory, headerName))
                                                   ) ?? headerNames.FirstOrDefault(
                                                   headerName => File.Exists(Path.Combine(rcFileDirectory, headerName))
                                                   ) ?? headerNames.First());

            if (!File.Exists(headerPath))
            {
                File.Create(headerPath);
            }
            DefaultHeaderFile = headerPath;

            mIDGenerator = new IDGenerator();
            mIDGenerator.RemoveExistingFromHeader(mHeaderContent, headerPath);

            mWriteHeaderPath = Path.GetTempFileName();
            mHeaderWriter    = new HeaderWriter(headerPath);
        }
예제 #2
0
        public void LoadStringResources(RcFile aRcFile)
        {
            RcFile          = aRcFile;
            mTempRcFile     = Path.GetTempFileName();
            mTempHeaderFile = Path.GetTempFileName();

            if (!File.Exists(mTempHeaderFile))
            {
                File.Create(mTempHeaderFile);
            }

            if (!File.Exists(mTempRcFile))
            {
                File.Create(mTempRcFile);
            }

            List <string> headersRelativePath = mRcFileParser.ExtractHeaders(RcFile.FilePath);
            List <string> headerFiles         = new List <string>();

            foreach (string hrp in headersRelativePath)
            {
                var newHrp = hrp.Replace("<", string.Empty);
                newHrp = newHrp.Replace(">", string.Empty);

                // Handle default header file
                if (newHrp.ToLower() == kDefaultResourceHeaderFileName)
                {
                    headerFiles.Add(DefaultHeaderFile);
                    continue;
                }

                foreach (string dir in RcFile.Project.AditionalIncludeDirectories)
                {
                    string headerFullPath    = Path.Combine(dir, newHrp);
                    string headerAbsolutPath = Path.GetFullPath((new Uri(headerFullPath)).LocalPath);
                    if (File.Exists(headerAbsolutPath))
                    {
                        headerFiles.Add(headerAbsolutPath);
                        break;
                    }
                }
            }
            mRcFileContent.Headers.AddRange(headerFiles);

            mRcFileParser.ReadData(mRcFileContent, aRcFile.FilePath, mTempRcFile);
            mHeaderParser.ReadData(mRcFileContent);
            mEmptyRangeManager.FindEmptyRanges(mHeaderContent);

            mOperationsStringTable = new OperationsStringTable(mRcFileContent, mEmptyRangeManager);
        }
예제 #3
0
        public string GenerateId(RcFile aSelectedRcFile, IEnumerable <RcFile> aRcFiles, bool aUniquePerProject)
        {
            List <string> rcPaths = (from rcFile in aRcFiles where rcFile.Project.ProjectName == aSelectedRcFile.Project.ProjectName select rcFile.FilePath).ToList();

            IDGenerator idGenerator = new IDGenerator();

            if (aUniquePerProject)
            {
                return(idGenerator.GenerateUniquePerProject(rcPaths).ToString());
            }
            else
            {
                return(mIDGenerator.Generate().ToString());
            }
        }
예제 #4
0
 /// <summary>
 /// Automatically loads the data from the RC file
 /// </summary>
 /// <param name="aRcFile"></param>
 public StringResourceContext(RcFile aRcFile)
 {
     mHeaderParser = new HeadersParser(mHeaderContent);
     LoadStringResources(aRcFile);
     mIdGenerator = new IdGenerator(mEmptyRangeManager.GetEmptyRanges, mRcFileContent.MaximumId);
 }