Пример #1
0
        public static CurrentIDs Load()
        {
            CurrentIDs currentIDs = new CurrentIDs();

            if (!File.Exists(Application.StartupPath + "\\current_ids.cid"))
            {
                return(null);
            }
            byte[]     arrByte = new byte[1024];
            FileStream fs      = new FileStream(Application.StartupPath + "\\current_ids.cid", FileMode.Open, FileAccess.Read);

            fs.Read(arrByte, 0, 1024);
            fs.Close();
            int nLength = PubHelper.byteToInt(arrByte);

            //下面这个判断,是为了防止文件中记录的长度被改写导致溢出
            if (nLength >= 1020)
            {
                nLength = 1020;
            }

            byte[] arrEncryptByte = new byte[nLength];
            for (int i = 0; i < nLength; i++)
            {
                arrEncryptByte[i] = arrByte[i + 4];
            }

            currentIDs = (CurrentIDs)(Serialize.DecryptToObject(arrEncryptByte));
            return(currentIDs);
        }
Пример #2
0
        public static SettingItems Load()
        {
            SettingItems settings = new SettingItems();

            if (!File.Exists(Application.StartupPath + "\\config.ini"))
            {
                return(null);
            }
            byte[]     arrByte = new byte[1024];
            FileStream fs      = new FileStream(Application.StartupPath + "\\config.ini", FileMode.Open, FileAccess.Read);

            fs.Read(arrByte, 0, 1024);
            fs.Close();
            int nLength = PubHelper.byteToInt(arrByte);

            //下面这个判断,是为了防止文件中记录的长度被改写导致溢出
            if (nLength >= 1020)
            {
                nLength = 1020;
            }

            byte[] arrEncryptByte = new byte[nLength];
            for (int i = 0; i < nLength; i++)
            {
                arrEncryptByte[i] = arrByte[i + 4];
            }

            settings = (SettingItems)(Serialize.DecryptToObject(arrEncryptByte));
            return(settings);
        }