예제 #1
0
파일: ReadIni.cs 프로젝트: AcidCrash0/RPVN
        void init(byte[] data, string filename)
        {
            updated = false;

            lock (typeof(ReadIni))
            {
                string[] lines;
                string   srcstr;
                DateTime lastUpdate = new DateTime(0);

                if (filename != null)
                {
                    lastUpdate = IO.GetLastWriteTimeUtc(filename);

                    datas = IniCache.GetCache(filename, lastUpdate);
                }

                if (datas == null)
                {
                    if (data == null)
                    {
                        try
                        {
                            data = Buf.ReadFromFile(filename).ByteData;
                        }
                        catch
                        {
                            data  = new byte[0];
                            datas = IniCache.GetCache(filename, new DateTime());
                        }
                    }

                    if (datas == null)
                    {
                        datas = new Dictionary <string, string>();
                        Encoding currentEncoding = Str.Utf8Encoding;
                        srcstr = currentEncoding.GetString(data);

                        lines = Str.GetLines(srcstr);

                        foreach (string s in lines)
                        {
                            string line = s.Trim();

                            if (Str.IsEmptyStr(line) == false)
                            {
                                if (line.StartsWith("#") == false &&
                                    line.StartsWith("//") == false &&
                                    line.StartsWith(";") == false)
                                {
                                    string key, value;

                                    if (Str.GetKeyAndValue(line, out key, out value))
                                    {
                                        key = key.ToUpper();

                                        if (datas.ContainsKey(key) == false)
                                        {
                                            datas.Add(key, value);
                                        }
                                        else
                                        {
                                            int i;
                                            for (i = 1; ; i++)
                                            {
                                                string key2 = string.Format("{0}({1})", key, i).ToUpper();

                                                if (datas.ContainsKey(key2) == false)
                                                {
                                                    datas.Add(key2, value);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (filename != null)
                        {
                            IniCache.AddCache(filename, lastUpdate, datas);
                        }

                        updated = true;
                    }
                }
            }
        }
예제 #2
0
파일: Secure.cs 프로젝트: AcidCrash0/RPVN
        public Rsa(string filename)
        {
            Buf b = Buf.ReadFromFile(filename);

            init(b.ByteData);
        }
예제 #3
0
파일: Csv.cs 프로젝트: zeroyou/SoftEtherVPN
 public Csv(string filename, Encoding encoding)
 {
     init(Buf.ReadFromFile(filename), encoding);
 }
예제 #4
0
파일: Secure.cs 프로젝트: AcidCrash0/RPVN
 public CommonSign(string filename)
 {
     init(Buf.ReadFromFile(filename).ByteData);
 }
예제 #5
0
        public Buf ReadHamcore(string name)
        {
            if (name[0] == '|')
            {
                name = name.Substring(1);
            }
            if (name[0] == '/' || name[0] == '\\')
            {
                name = name.Substring(1);
            }

            string filename = name;

            filename = filename.Replace("/", "\\");

            Buf b;

            if (this.disableReadRawFile == false)
            {
                try
                {
                    b = Buf.ReadFromFile(HamcoreDirName + "\\" + filename);

                    return(b);
                }
                catch
                {
                }
            }

            lock (list)
            {
                HamCoreEntry c;
                string       key = filename.ToUpper();

                b = null;

                if (list.ContainsKey(key))
                {
                    c = list[key];

                    if (c.Buffer != null)
                    {
                        b = new Buf(c.Buffer);
                        b.SeekToBegin();
                        c.LastAccess = Time.Tick64;
                    }
                    else
                    {
                        if (hamcore_io.Seek(SeekOrigin.Begin, (int)c.Offset))
                        {
                            byte[] data = hamcore_io.Read((int)c.SizeCompressed);

                            int    dstSize = (int)c.Size;
                            byte[] buffer  = ZLib.Uncompress(data, dstSize);

                            c.Buffer = buffer;
                            b        = new Buf(buffer);
                            b.SeekToBegin();
                            c.LastAccess = Time.Tick64;
                        }
                    }
                }

                long now = Time.Tick64;
                foreach (HamCoreEntry cc in list.Values)
                {
                    if (cc.Buffer != null)
                    {
                        if (((cc.LastAccess + HamcoreCacheExpires) < now) ||
                            cc.FileName.StartsWith("Li", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cc.Buffer = null;
                        }
                    }
                }
            }

            return(b);
        }