Exemple #1
0
        public static IEnumerable <string> GetAllSection(string path)
        {
            List <string> sections = new List <string>();
            int           len      = FileAuxiliary.GetFileLength(path);

            if (len > 0)
            {
                char[] buffer = new char[len];
                if ((len = GetPrivateProfileSectionNames(buffer, len, path)) > 0)
                {
                    unsafe
                    {
                        fixed(char *str = buffer)
                        {
                            char *ptr = str; int index = 0, last = 0;

                            while (index < len)
                            {
                                if (*ptr++ == '\0')
                                {
                                    int    size = index - last;
                                    char[] name = new char[size];
                                    global::System.Array.Copy(buffer, last, name, 0, size);
                                    sections.Add(new string(name));
                                    last = index + 1;
                                }
                                index++;
                            }
                        }
                    }
                }
            }
            return(sections);
        }
Exemple #2
0
 private void SetContentLengthByFile(string path)
 {
     try
     {
         response.StatusCode = 500;
         if (File.Exists(path))
         {
             response.StatusCode    = 200;
             response.ContentLength = FileAuxiliary.GetFileLength(path);
         }
     }
     catch (Exception) { /*--A--*/ }
 }
Exemple #3
0
        public static IEnumerable <KeyValuePair <string, string> > GetAllKeyValue(string path, string section)
        {
            List <KeyValuePair <string, string> > keyValues = new List <KeyValuePair <string, string> >();
            int len = FileAuxiliary.GetFileLength(path);

            if (len > 0)
            {
                string buffer = new string('\0', len);
                if (GetPrivateProfileSection(section, ref buffer, len, path) > 0)
                {
                    string[] items = buffer.Split('\0');
                    foreach (string str in items)
                    {
                        int i;
                        if (str.Length > 0 && (i = str.IndexOf('=')) > -1)
                        {
                            keyValues.Add(new KeyValuePair <string, string>(str.Substring(0, i), str.Substring(i + 1)));
                        }
                    }
                }
            }
            return(keyValues);
        }