Esempio n. 1
0
 public static bool INIEmptySection(string iniFile, string section)
 {
     if (string.IsNullOrEmpty(section))
     {
         throw new ArgumentException("The name of the node must be specified", "section");
     }
     return(IniHelper.WritePrivateProfileSection(section, string.Empty, iniFile));
 }
Esempio n. 2
0
 public static bool INIDeleteKey(string iniFile, string section, string key)
 {
     if (string.IsNullOrEmpty(section))
     {
         throw new ArgumentException("The name of the node must be specified", "section");
     }
     if (string.IsNullOrEmpty(key))
     {
         throw new ArgumentException("The key must be specified", "key");
     }
     return(IniHelper.WritePrivateProfileString(section, key, null, iniFile));
 }
Esempio n. 3
0
        public static bool INIWriteItems(string iniFile, string section, string items)
        {
            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("The name of the node must be specified", "section");
            }

            if (string.IsNullOrEmpty(items))
            {
                throw new ArgumentException("Key value pairs must be specified", "items");
            }

            return(IniHelper.WritePrivateProfileSection(section, items, iniFile));
        }
Esempio n. 4
0
        public static string[] INIGetAllItems(string iniFile, string section)
        {
            uint MAX_BUFFER = 32767;

            string[] items           = new string[0];
            IntPtr   pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));
            uint     bytesReturned   = IniHelper.GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, iniFile);

            if (!(bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0))
            {
                string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned);
                items = returnedString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            }
            Marshal.FreeCoTaskMem(pReturnedString);
            return(items);
        }
Esempio n. 5
0
        public static string[] INIGetAllSectionNames(string iniFile)
        {
            uint MAX_BUFFER = 32767;

            string[] sections        = new string[0];
            IntPtr   pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char));
            uint     bytesReturned   = IniHelper.GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, iniFile);

            if (bytesReturned != 0)
            {
                string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString();
                sections = local.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            }
            Marshal.FreeCoTaskMem(pReturnedString);
            return(sections);
        }
Esempio n. 6
0
 public static bool INIWriteValue(string iniFile, string section, string key, string value)
 {
     if (string.IsNullOrEmpty(section))
     {
         throw new ArgumentException("The name of the node must be specified", "section");
     }
     if (string.IsNullOrEmpty(key))
     {
         throw new ArgumentException("The key must be specified", "key");
     }
     if (value == null)
     {
         throw new ArgumentException("The value can not be null", "value");
     }
     return(IniHelper.WritePrivateProfileString(section, key, value, iniFile));
 }
Esempio n. 7
0
        public static string[] INIGetAllItemKeys(string iniFile, string section)
        {
            string[]  value = new string[0];
            const int SIZE  = 1024 * 10;

            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("The name of the node must be specified", "section");
            }
            char[] chars         = new char[SIZE];
            uint   bytesReturned = IniHelper.GetPrivateProfileString(section, null, null, chars, SIZE, iniFile);

            if (bytesReturned != 0)
            {
                value = new string(chars).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
            }
            chars = null;
            return(value);
        }
Esempio n. 8
0
        public static string INIGetStringValue(string iniFile, string section, string key, string defaultValue)
        {
            string    value = defaultValue;
            const int SIZE  = 1024 * 10;

            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentException("The name of the node must be specified", "section");
            }
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("You must specify the key", "key");
            }
            StringBuilder sb            = new StringBuilder(SIZE);
            uint          bytesReturned = IniHelper.GetPrivateProfileString(section, key, defaultValue, sb, SIZE, iniFile);

            if (bytesReturned != 0)
            {
                value = sb.ToString();
            }
            sb = null;

            return(value);
        }