Ejemplo n.º 1
0
        public MOG_IniKey KeyFind(string section, string key)
        {
            MOG_IniSection pSection = SectionFind(section);

            if (string.Compare(key, mKeyCache.mKey, true) == 0)
            {
                return(mKeyCache);
            }

            // Located the section?
            if (pSection != null)
            {
                for (int k = 0; k < pSection.mKeys.Count; k++)
                {
                    MOG_IniKey pKey = (MOG_IniKey)(pSection.mKeys[k]);

                    if (string.Compare(key, pKey.mKey, true) == 0)                    //MOG_StringCompare(key, pKey.mKey))
                    {
                        mKeyCache = pKey;
                        return(mKeyCache);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public int      PutSectionString(string section, string str)
        {
            MOG_IniKey     keyHolder     = new MOG_IniKey();
            MOG_IniSection sectionHolder = new MOG_IniSection();

            MOG_IniSection pSection = SectionFind(section);

            // Section found, now check for key
            if (pSection != null)
            {
                MOG_IniKey pKey = KeyFind(section, str);
                // Key not found, add key and value
                if (pKey == null)
                {
                    keyHolder.mKey = str;
                    pSection.mKeys.Add(keyHolder);
                }
            }
            // No section, Add new section, key and value
            else
            {
                string upperSection = section.ToUpper();

                keyHolder.mKey = str;

                sectionHolder.mSection = upperSection;
                sectionHolder.mKeys.Add(keyHolder);
                mSections.Add(sectionHolder);
            }

            mChanged = true;

            return(1);
        }
Ejemplo n.º 3
0
        public int PutString(string section, string key, string str)
        {
            MOG_IniKey     keyHolder     = new MOG_IniKey();
            MOG_IniSection sectionHolder = new MOG_IniSection();

            //MOG_ASSERT_RETURN_null(section.Length, "MOG_INI - PutString requires a valid section");
            //MOG_ASSERT_RETURN_null(key.Length || str.Length, "MOG_INI - PutString requires either a valid key or str");
            if (str == null)
            {
                return(0);
            }
            // Let's be somewhat helpful in identifying this problem and fix it.
            if (str.Length == 0)
            {
                return(PutSectionString(section, key));
            }
            else if (key.Length == 0)
            {
                return(PutSectionString(section, str));
            }

            MOG_IniSection pSection = SectionFind(section);

            // Section found, now check for key
            if (pSection != null)
            {
                MOG_IniKey pKey = KeyFind(pSection, key);
                // Found key, now replace value
                if (pKey != null)
                {
                    pKey.mValue = str;
                }
                // Key not found, add key and value
                else
                {
                    keyHolder.mKey   = key;
                    keyHolder.mValue = str;
                    pSection.mKeys.Add(keyHolder);
                }
            }
            // No section, Add new section, key and value
            else
            {
                string upperSection = section.ToUpper();

                keyHolder.mKey   = key;
                keyHolder.mValue = str;

                sectionHolder.mSection = upperSection;
                sectionHolder.mKeys.Add(keyHolder);
                mSections.Add(sectionHolder);
            }

            mChanged = true;
            return(1);
        }
Ejemplo n.º 4
0
 public MOG_Ini()
 {
     mSections         = new ArrayList();
     mFullFilename     = "";
     mSectionCache     = new MOG_IniSection();
     mKeyCache         = new MOG_IniKey();
     mChanged          = false;
     mHandle           = IniHandle.ClearHandle;
     mLockedFileStream = null;
 }
Ejemplo n.º 5
0
        public bool RenameKey(string section, string key, string newKey)
        {
            MOG_IniKey pKey = KeyFind(section, key);

            // Section found, now check for key
            if (pKey != null)
            {
                pKey.mKey = newKey;
                mChanged  = true;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        public bool Load(string fullFilename)
        {
            Close();

            // Clear previous member data
            if (mSections.Count != 0)
            {
                mSections.Clear();
            }

            mSectionCache = new MOG_IniSection();
            mKeyCache     = new MOG_IniKey();

            mFullFilename = fullFilename;

            return(LoadFile(mFullFilename, FileAccess.Read, FileShare.Read));
        }
Ejemplo n.º 7
0
        public MOG_IniKey KeyFind(MOG_IniSection pSection, string key)
        {
            if (pSection != null)
            {
                for (int k = 0; k < pSection.mKeys.Count; k++)
                {
                    MOG_IniKey pKey = (MOG_IniKey)(pSection.mKeys[k]);

                    if (string.Compare(key, pKey.mKey, true) == 0)                    //MOG_StringCompare(key, pKey.mKey))
                    {
                        return(pKey);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 8
0
        public bool Open(string fullFilename, FileShare shareLevel)
        {
            Close();

            // Clear previous member data
            if (mSections.Count != 0)
            {
                mSections.Clear();
            }

            mSectionCache = new MOG_IniSection();
            mKeyCache     = new MOG_IniKey();

            mFullFilename = fullFilename;

            mHandle = IniHandle.HoldHandle;

            return(LoadFile(fullFilename, FileAccess.ReadWrite, shareLevel));
        }
Ejemplo n.º 9
0
        public bool RemoveString(string section, string key)
        {
            MOG_IniSection pSection = SectionFind(section);

            // Section found, now check for key
            if (pSection != null)
            {
                MOG_IniKey pKey = KeyFind(section, key);
                // Found key, now replace value
                if (pKey != null)
                {
                    pSection.mKeys.Remove(pKey);
                }
            }

            mChanged = true;

            return(true);
        }
Ejemplo n.º 10
0
        public string GetString(string section, string key)
        {
            MOG_IniKey pKey = KeyFind(section, key);

            if (pKey != null)
            {
                return(pKey.mValue);
            }

            if (section != null)
            {
                MessageBox.Show(string.Concat(mFullFilename, "\nSection - ", section, "\nKey - ", key, " not found!"), " GetString ", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show(string.Concat(mFullFilename, "\nSection - ", section, "\nKey - ", key, "\n\nSection not found!"), " GetString ", MessageBoxButtons.OK);
            }

            return("");
        }
Ejemplo n.º 11
0
        public MOG_IniSection SectionFind(string section)
        {
            if (string.Compare(section, mSectionCache.mSection, true) == 0)
            {
                return(mSectionCache);
            }

            for (int s = 0; s < mSections.Count; s++)
            {
                MOG_IniSection pSection = (MOG_IniSection)(mSections[s]);

                if (string.Compare(section, pSection.mSection, true) == 0)                //MOG_StringCompare(section, pSection.mSection))
                {
                    mKeyCache     = new MOG_IniKey();
                    mSectionCache = pSection;
                    return(mSectionCache);
                }
            }

            return(null);
        }
Ejemplo n.º 12
0
        private bool ParseFile(string fileBuffer)
        {
            ParseState     state    = ParseState.STATE_PARSE_BEGIN;
            CharEnumerator thisChar = fileBuffer.GetEnumerator();
            //	char thisChar;
            string         thisString = "";
            MOG_IniKey     key        = new MOG_IniKey();
            MOG_IniSection section    = new MOG_IniSection();

            // FIX FOR [=] parsing incorrectly

            // Scan every character in the file
            while (thisChar.MoveNext())
            {
                // Check for parsing characters
                // End of Keyname?
                if ((thisChar.Current == '=') && (state == ParseState.STATE_PARSE_BEGIN))
                {
                    // Extra check to make sure the key we are going to write is actually valid
                    if (thisString.Length != 0)
                    {
                        // Set this Key name
                        key.mKey = thisString;
                        // Clear thisString
                        thisString = "";
                        state      = ParseState.STATE_PARSE_KEY;
                    }
                }
                // carriage return
                else if (thisChar.Current == 13)
                {
                    // just eat this byte of the stream -
                }
                // End of line?
                else if (thisChar.Current == 10)
                {
                    // Only bother to do something on the end of a line if we have buffered up a string
                    if (thisString.Length != 0 && key.mKey.Length != 0)
                    {
                        key.mValue = thisString;

                        MOG_IniKey kHolder = new MOG_IniKey();
                        kHolder.mKey   = key.mKey;
                        kHolder.mValue = key.mValue;
                        // Push this key into the current section
                        section.mKeys.Add(kHolder);
                        // Erase both the key & value
                        key.mKey   = "";
                        key.mValue = "";
                    }
                    // If we have a key without a value then we must save it as a key only.
                    else
                    {
                        if (thisString.Length != 0)
                        {
                            key.mKey = thisString;

                            MOG_IniKey kHolder = new MOG_IniKey();
                            kHolder.mKey   = key.mKey;
                            kHolder.mValue = "";

                            // Push this key into the current section
                            section.mKeys.Add(kHolder);
                            // Erase both the key & value
                            key.mKey   = "";
                            key.mValue = "";
                        }
                    }
                    // Clear thisString
                    thisString = "";
                    state      = ParseState.STATE_PARSE_BEGIN;
                }
                // New Section?
                else if ((thisChar.Current == '[') && (state == ParseState.STATE_PARSE_BEGIN))
                {
                    // Only push if we previously had a section name
                    if (section.mSection.Length != 0)
                    {
                        MOG_IniSection sHolder = new MOG_IniSection();
                        sHolder.mSection = section.mSection;
                        sHolder.mKeys    = (ArrayList)(section.mKeys.Clone());

                        // Push this section and all of it's keys
                        mSections.Add(sHolder);
                        // Clean up the section variables
                        section.mSection = "";
                        section.mKeys.RemoveRange(0, section.mKeys.Count);
                        // Clear the SectionKey
                        section.mSection = "";
                    }
                    // Clear thisString
                    thisString = "";
                    state      = ParseState.STATE_PARSE_SECTION;
                }
                // End Section?
                else if ((thisChar.Current == ']') && (state == ParseState.STATE_PARSE_SECTION))
                {
                    // Set the section name to the current string
                    section.mSection = thisString;
                    // Clear thisString
                    thisString = "";
                    state      = ParseState.STATE_PARSE_END;
                }
                else
                {
                    thisString = string.Concat(thisString, Convert.ToString(thisChar.Current));
                }
            }

            // Push the final key into the section?
            if (thisString.Length != 0)
            {
                // Key names must get filled in first...then the key values
                if (key.mKey.Length == 0)
                {
                    key.mKey = thisString;
                }
                else
                {
                    key.mValue = thisString;
                }

                MOG_IniKey kHolder = new MOG_IniKey();
                kHolder.mKey   = key.mKey;
                kHolder.mValue = key.mValue;

                // Push this key into the current section
                section.mKeys.Add(kHolder);
                // Push this key into the current section
                //section.mKeys.Add(key.MemberwiseClone());
                // Erase both the key & value
                key.mKey   = "";
                key.mValue = "";
            }

            // Push the final section?
            if (section.mSection.Length != 0)
            {
                // Push this section and all of it's keys
                mSections.Add(section);
            }

            return(true);
        }