Example #1
0
        private List <KeyValuePair <string, StringLine> > SortStringLinesAfterId(RCFileContent aRcFileContent)
        {
            var stringLines = aRcFileContent.GetStringLinesDictionary.ToList();

            stringLines.Sort((pair1, pair2) => pair1.Value.Id.CompareTo(pair2.Value.Id));
            return(stringLines);
        }
Example #2
0
        private void Write(StreamReader aReader, StreamWriter aWriter, RCFileContent aRcFileContent)
        {
            var  stringLines = SortStringLinesAfterId(aRcFileContent);
            var  iterator    = stringLines.GetEnumerator();
            bool hasNext     = iterator.MoveNext();

            while (!aReader.EndOfStream)
            {
                string        line         = aReader.ReadLine();
                List <string> lineElements = ParseUtility.BuildListOfStringsFromReadLine(line, Parse.kSplitResourceElementsChars);

                int numberPositionsToSkip = hasNext ? NumberPositionToSkip(aRcFileContent, iterator) : 0;
                while (numberPositionsToSkip-- > 0)
                {
                    hasNext = iterator.MoveNext();
                }

                if (LineRepresentString(lineElements.Count, hasNext) == false ||
                    !ParseUtility.TransformToDecimal(lineElements[2], out int stringId))
                {
                    aWriter.WriteLine(line);
                }
                else if (CheckForAddedStrings(aWriter, iterator, line, stringId, aRcFileContent))
                {
                    hasNext = iterator.MoveNext();
                }
            }
        }
Example #3
0
        private void SaveData(RCFileContent aRcFileContent, string aName, string aValue,
                              string aLine, int aStringTableOrder)
        {
            StringLine stringLine = new StringLine(aName, aValue, aLine);

            stringLine.RcOrder = aStringTableOrder;
            aRcFileContent.AddInStringLines(stringLine);
        }
Example #4
0
 private void ReadEndOfRcFile(RCFileContent aRcFileContent, StreamReader aReadFile, string aReadLine)
 {
     aRcFileContent.EndRcFile += aReadLine + "\r\n";
     do
     {
         aReadLine = aReadFile.ReadLine();
         aRcFileContent.EndRcFile += aReadLine + "\r\n";
     } while (!aReadFile.EndOfStream);
 }
Example #5
0
        private bool CheckForAddedStrings(StreamWriter aWriter, IEnumerator <KeyValuePair <string, StringLine> > aIterator,
                                          string aLine, int aStringId, RCFileContent aRcFileContent)
        {
            bool skipOnePosition = true;

            if (aStringId < aIterator.Current.Value.Id)
            {
                skipOnePosition = false;
            }
            else if (aStringId > aIterator.Current.Value.Id && aRcFileContent.NewStringWasAdded == false)
            {
                aRcFileContent.NewStringWasAdded = true;
                WriteAddedString(aWriter, aIterator);
            }
            aWriter.WriteLine(aLine);
            return(skipOnePosition);
        }
Example #6
0
        //skip strings that are not in Resource.h and are in another header
        private int NumberPositionToSkip(RCFileContent aRcFileContent,
                                         IEnumerator <KeyValuePair <string, StringLine> > aIterator)
        {
            int  countPositions = 0;
            bool hasEmptyFields;

            do
            {
                string name = aIterator.Current.Value.Name;
                hasEmptyFields = aRcFileContent.IsStringWithEmptyFields(name);
                if (hasEmptyFields)
                {
                    ++countPositions;
                }
            } while (hasEmptyFields && aIterator.MoveNext());

            return(countPositions);
        }
Example #7
0
        public void ReadData(RCFileContent aRcFileContent, string aPathRCFile, string aPathRCFileWiter)
        {
            int  stringTableOrder = 0;
            bool stringTableFound = false;

            if (!FileExists(aPathRCFile))
            {
                throw new FileNotFoundException(aPathRCFile);
            }

            aRcFileContent.CodePage = ExtractCodePage(aPathRCFile);
            using (StreamReader readFile = new StreamReader(aPathRCFile, aRcFileContent.RcEncoding))
            {
                using (StreamWriter streamWriter = new StreamWriter(aPathRCFileWiter, false, aRcFileContent.RcEncoding))
                {
                    string readLine;
                    while (!readFile.EndOfStream)
                    {
                        readLine = readFile.ReadLine();
                        // StringTable found
                        if (readLine.Trim() == TagConstants.kTagStringTable)
                        {
                            stringTableFound = true;
                            // skip BEGIN TAG
                            readLine = readFile.ReadLine();

                            ReadStringTableContent(aRcFileContent, readFile, stringTableOrder);
                            ++stringTableOrder;
                        }
                        //Read the informations after the last StringTable
                        if (stringTableFound && readLine.Contains(TagConstants.kTagEndif))
                        {
                            ReadEndOfRcFile(aRcFileContent, readFile, readLine);
                            break;
                        }
                        //Write all until the first StringTable
                        if (!stringTableFound)
                        {
                            streamWriter.WriteLine(readLine);
                        }
                    }
                }
            }
        }
Example #8
0
        public void WriteData(RCFileContent aContent, string aFilePath)
        {
            var stringTables = aContent.StringTablesDictionary.ToList();

            stringTables.Sort((pair1, pair2) => pair1.Value.RcOrder.CompareTo(pair2.Value.RcOrder));

            using (StreamWriter streamWriter = new StreamWriter(aFilePath, true, aContent.RcEncoding))
            {
                foreach (var stringTable in stringTables)
                {
                    streamWriter.WriteLine(TagConstants.kTagStringTable);
                    streamWriter.WriteLine(TagConstants.kTagBegin);

                    stringTable.Value.Write(streamWriter);

                    streamWriter.WriteLine(TagConstants.kTagEnd + "\r\n");
                }
                streamWriter.Write(aContent.EndRcFile);
            }
        }
Example #9
0
        private void ReadStringTableContent(RCFileContent aRcFileContent, StreamReader aReadFile, int aStringTableOrder)
        {
            string readLine = string.Empty;

            while ((readLine = aReadFile.ReadLine()) != TagConstants.kTagEnd)
            {
                string        line         = readLine;
                string        stringValue  = string.Empty;
                List <string> lineElements = ParseUtility.BuildListOfStringsFromReadLine(readLine, new char[] { ' ' });
                if (lineElements.Count == 0)
                {
                    continue;
                }

                ExtractStringValueLine(aReadFile, lineElements, ref stringValue, ref line);
                BuildStringValue(ref line, ref stringValue, aReadFile);

                stringValue = new EscapeSequences().Escape(stringValue);
                SaveData(aRcFileContent, lineElements[0], stringValue, line, aStringTableOrder);
            }
        }
Example #10
0
 public void WriteFile(RCFileContent aRcFileContent, string aPathHeaderFileRead, string aPathHeaderFileWrite)
 {
     using (StreamReader reader = new StreamReader(aPathHeaderFileRead))
         using (StreamWriter writer = new StreamWriter(aPathHeaderFileWrite))
             Write(reader, writer, aRcFileContent);
 }
Example #11
0
 public OperationsStringTable(RCFileContent aRcFileContent, EmptyRangeManager aEmptyRangeManager)
 {
     mRcFileContent     = aRcFileContent;
     mEmptyRangeManager = aEmptyRangeManager;
 }