Example #1
0
        /// <summary>
        /// upb CSection by Changes
        /// </summary>
        protected static List <CSection> ChangeInSection(CWhatIsChange Changes, List <CSection> Sections)
        {
            List <CSection> OUTSection = new List <CSection>();

            foreach (CSection C in Sections)
            {
                CSection Section = new CSection();

                if (C.SectionName == Changes.Section)
                {
                    Section.SectionName = Changes.ModifiedSection;
                    Section.KeyValue    = new List <CKeyValue>();
                    Section.KeyValue    = ChangeKeyValue(Changes, C.KeyValue);
                }
                else
                {
                    Section = C;
                }
                OUTSection.Add(Section);
            }
            return(OUTSection);
        }
Example #2
0
        // メソッド

        public void t読み込み(string strファイル名)
        {
            this.strファイル名 = strファイル名;

            StreamReader sr      = null;
            CSection     section = null;

            try
            {
                sr = new StreamReader(this.strファイル名, Encoding.GetEncoding("Shift_JIS"));                        // ファイルが存在しない場合は例外発生。

                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    line = line.Replace('\t', ' ').TrimStart(new char[] { '\t', ' ' });
                    if (string.IsNullOrEmpty(line) || line[0] == ';')                           // ';'以降はコメントとして無視
                    {
                        continue;
                    }

                    if (line[0] == '[')
                    {
                        #region [ セクションの変更 ]
                        //-----------------------------
                        var builder = new StringBuilder(32);
                        int num     = 1;
                        while ((num < line.Length) && (line[num] != ']'))
                        {
                            builder.Append(line[num++]);
                        }

                        // 変数 section が使用中の場合は、List<CSection> に追加して新しい section を作成する。
                        if (section != null)
                        {
                            this.Sections.Add(section);
                        }

                        section           = new CSection();
                        section.strセクション名 = builder.ToString();
                        //-----------------------------
                        #endregion

                        continue;
                    }

                    string[] strArray = line.Split(new char[] { '=' });
                    if (strArray.Length != 2)
                    {
                        continue;
                    }

                    string key   = strArray[0].Trim();
                    string value = strArray[1].Trim();

                    if (section != null && !string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                    {
                        section.listパラメータリスト.Add(new KeyValuePair <string, string>(key, value));
                    }
                }

                if (section != null)
                {
                    this.Sections.Add(section);
                }
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }
Example #3
0
        /// <summary>
        /// read full date from ini
        /// </summary>
        protected static CFile LoadDataFrominiFile(string fileName)
        {
            CFile Fileini = new CFile();

            Fileini.Filename = fileName;
            Fileini.Sections = new List <CSection>();

            Encoding enc = Encoding.GetEncoding(1251);

            string[] lines = File.ReadAllLines(fileName, enc);

            int i = 0;

            while (i < lines.Count())
            {
                string dataString = lines[i].Trim();
                if (string.IsNullOrEmpty(dataString))
                {
                    continue;
                }
                if ((dataString.StartsWith("[")) && (dataString.EndsWith("]")))
                {
                    CSection Cection = new CSection();
                    Cection.SectionName = dataString;
                    i++;
                    dataString       = lines[i].Trim();
                    Cection.KeyValue = new List <CKeyValue>();
                    while (!dataString.StartsWith("["))
                    {
                        CKeyValue KeyValue = new CKeyValue();

                        if (dataString.StartsWith(";"))
                        {
                            KeyValue.Description = dataString;
                            i++;
                            dataString = lines[i].Trim();
                        }

                        if (dataString.Contains("="))
                        {
                            int    pos   = dataString.IndexOf("=");
                            string key   = dataString.Substring(0, pos).Trim();
                            string value = "";
                            if ((pos + 1) < dataString.Length)
                            {
                                value = dataString.Substring(pos + 1, dataString.Length - pos - 1).Trim();
                            }

                            // save date to colection
                            KeyValue.Key   = key;
                            KeyValue.Value = value;
                        }


                        Cection.KeyValue.Add(KeyValue);
                        i++;

                        if (i < lines.Count())
                        {
                            dataString = lines[i].Trim();
                        }
                        else
                        {
                            break;
                        }
                    }
                    Fileini.Sections.Add(Cection);
                }
            }
            return(Fileini);
        }
Example #4
0
        public void Load(byte[] buf)
        {
            int nPos = 0xb;

            Version = buf[nPos];

            //загружаем
            nPos            = 0xd;
            nAllColumnCount = BitConverter.ToInt32(buf, nPos);

            nPos         = 0x11;
            nAllRowCount = BitConverter.ToInt32(buf, nPos);
            //memcpy(&nAllColumnCount, &buf[nPos], 8);//количество колонок и строк всего

            nPos             = 0x15;
            nAllObjectsCount = BitConverter.ToInt32(buf, nPos);

            nPos = 0x37;
            //шрифты
            nFontCount = GetNumberArray(buf, out aFontNumber, ref nPos);
            nPos      += 2;
            if (nFontCount > 0)
            {
                aFont = new string[nFontCount];

                for (int i = 0; i < nFontCount; i++)
                {
                    nPos += 28;
                    int nLength = 0x20;
                    aFont[i] = Encoding.GetEncoding(1251).GetString(buf, nPos, nLength);
                    //memcpy(aFont[i].GetBuffer(nLength), &buf[nPos], nLength);
                    //aFont[i].ReleaseBuffer();
                    nPos += nLength;
                }
            }
            nPos += 0x40;

            //ширина столбцов
            nWidthCount = GetNumberArray(buf, out aWidthNumber, ref nPos);
            //nPos += 2;
            if (nWidthCount > 0)
            {
                aWidth = new int[nWidthCount];
                for (int i = 0; i < nWidthCount; i++)
                {
                    nPos     += 6;
                    aWidth[i] = BitConverter.ToInt32(buf, nPos);
                    nPos     += 24;
                }
            }

            //строки
            nRowCount = GetNumberArray(buf, out aRowNumber, ref nPos);
            nPos     += 2;
            if (nRowCount > 0)
            {
                pRow = new CRow[nRowCount];

                for (int i = 0; i < nRowCount - 1; i++)
                {
                    //byte pArray[100];
                    //memcpy(pArray,&buf[nPos],sizeof(pArray));
                    pRow[i]            = new CRow();
                    pRow[i].Version    = Version;
                    pRow[i].nRowHeight = BitConverter.ToInt16(buf, nPos + 4);
                    //memcpy(&pRow[i].nRowHeight, &buf[nPos + 4], 2);
                    pRow[i].nRowHeight = pRow[i].nRowHeight / 3;
                    nPos += 0x20;
                    pRow[i].Load(buf, nPos);
                }
            }


            //byte pArray[100];
            //buf[nPos] - количество доп. объектов типа Прямоугольник, Картинка, Диаграмма, OLE-объект
            //загрузка доп объектов

            int nCount = BitConverter.ToInt16(buf, nPos);

            //memcpy(&nCount, &buf[nPos], 2);

            nPos += 2;

            int nOLEDelta = 18; //дельта только для первого ОЛЕ объекта (почему не знаю, но это так)

            for (int i = 0; i < nCount; i++)
            {
                //memcpy(pArray,&buf[nPos],sizeof(pArray));

                int nType = buf[nPos + 2];//тип объекта
                //0-простой объект (линия, квадрат, блок с текстом)
                //8-сложный объект (картинка, диаграмма 1С, ОЛЕ обьект)

                bool bText    = (buf[nPos + 3] & 0x80) == 1; //признак блока с текстом
                bool bFormula = (buf[nPos + 3] & 0x40) == 1; //признак блока с расшифровкой

                //if(bText)
                //    bText = 1;
                //if(bFormula)
                //    bFormula = 1;


                nPos += 30;
                string csText;
                if (bText)
                {
                    GetText(buf, out csText, ref nPos);//текст
                }
                if (bFormula)
                {
                    GetText(buf, out csText, ref nPos);//расшифровка
                }
                int nKind = buf[nPos];
                //вид объекта
                //1-линия
                //2-квадрат
                //3-блок текста (но без текста)
                //4-ОЛЕ обьект (в т.ч. диаграмма 1С)
                //5-картинка

                if (nKind <= 3 || nType == 0)
                {
                    nPos += 40;
                }
                else

                if (nKind == 4)    //ОЛЕ объект
                {
                    int nLength = BitConverter.ToInt32(buf, nPos + 60 + nOLEDelta);
                    //			memcpy(&nLength,&buf[nPos+60+nOLEDelta],4);
                    nPos     += 64 + nOLEDelta + nLength;
                    nOLEDelta = 0;
                }
                else    //картинка
                if (nKind == 5)
                {
                    int nPictureType = buf[nPos + 16];        //тип картинки
                    int nLength      = BitConverter.ToInt32(buf, nPos + 44);
                    nPos += nLength + 48;
                }
                //else//неизвестный объект
                //{
                //    string Str;
                //    Str = string.Format("Встретился неизвестный объект N {0d}", nKind);
                //    throw new Exception(Str);
                //    //return;
                //}
            }

            //buf[nPos] - количество объединенных ячеек
            nCount = BitConverter.ToInt16(buf, nPos);;
            //memcpy(&nCount, &buf[nPos], 2);
            //загружаем объединенные ячейки
            nMergeCells = GetNumberArray(buf, out aMergeCells, ref nPos, 4) / 4;

            //загружаем секции:
            //вертикальные
            //memcpy(pArray,&buf[nPos],sizeof(pArray));
            nCount = BitConverter.ToInt16(buf, nPos);
            //memcpy(&nCount, &buf[nPos], 2);
            nPos += 2;
            for (int i = 0; i < nCount; i++)
            {
                CSection data = new CSection();
                data.nRange1 = BitConverter.ToInt32(buf, nPos);
                nPos        += 4;
                data.nRange2 = BitConverter.ToInt32(buf, nPos);;
                nPos        += 4;
                nPos        += 4;
                GetText(buf, out data.csName, ref nPos);
                VertSection.Add(data.csName, data);
            }

            nCount = BitConverter.ToInt16(buf, nPos);
            nPos  += 2;
            for (int i = 0; i < nCount; i++)
            {
                CSection data = new CSection();
                data.nRange1 = BitConverter.ToInt32(buf, nPos);
                nPos        += 4;
                data.nRange2 = BitConverter.ToInt32(buf, nPos);;
                nPos        += 4;
                nPos        += 4;
                GetText(buf, out data.csName, ref nPos);
                HorizSection.Add(data.csName, data);
            }
        }