コード例 #1
0
ファイル: CurrentIDs.cs プロジェクト: jefth/sinawler
        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
ファイル: AppSettings.cs プロジェクト: jefth/sinawler
        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);
        }