Ejemplo n.º 1
0
        public static MemoryStream ReadGameData(Stream stream)
        {
            logger.Info(inst, "Loading GameFile... ResourceFile dir = " + dataPackageDir);
            if (File.Exists(dataPackageDir))
            {
                BinaryReader reader = new BinaryReader(stream);

                byte[] UUID = _readUUID(reader.BaseStream);
                byteBoundaryWork(reader.BaseStream, false);

                long headerLen = reader.ReadInt64();
                byteBoundaryWork(reader.BaseStream, false);

                byte[] encHeaderData = new byte[headerLen];

                readBytes(encHeaderData, reader.BaseStream.Position, reader.BaseStream);
                byte[] headerData = AES256Manager.decodeToByteArray(Encoding.UTF8.GetString(encHeaderData), UUID);

                MemoryStream ms = new MemoryStream(headerData);

                byteBoundaryWork(stream, false);

                logger.Info(inst, "Loading GameFileHeader Success!");
                return(ms);
            }
            else
            {
                logger.Warning(inst, "Loading GameFile Fail... File not found ");
                throw new FileNotFoundException();
            }
        }
Ejemplo n.º 2
0
        public static string ReadSettingData()
        {
            logger.Info(inst, "Loading SaveFile... SaveFile dir = " + saveFileDir);
            if (File.Exists(saveFileDir))
            {
                StreamReader reader = new StreamReader(saveFileDir);

                byte[] UUID = _readUUID(reader.BaseStream);

                byteBoundaryWork(reader.BaseStream, false);

                string rawData = reader.ReadToEnd();

                reader.Close();

                string result = AES256Manager.decode(rawData, UUID);
                logger.Info(inst, "Loading SaveFile Success!");

                return(result);
            }
            else
            {
                logger.Warning(inst, "Loading SaveFile Fail... File not found ");
                throw new FileNotFoundException();
            }
        }
Ejemplo n.º 3
0
        private long _getHeaderLen(Dictionary <string, short> nameInfo)
        {
            int nameHeaderLen = nameInfo.Count * (FileManagerCore.shortSize + (2 * FileManagerCore.longSize) + FileManagerCore.byteGardSize);
            int dirHeaderLen  = resFileListReader.dirList.Count * ((3 * FileManagerCore.shortSize) + FileManagerCore.byteGardSize);
            int fileHeaderLen = resFileListReader.fileList.Count * ((3 * FileManagerCore.shortSize) + (2 * FileManagerCore.longSize) + FileManagerCore.byteGardSize);
            int lenDatalen    = 3 * (FileManagerCore.longSize + FileManagerCore.byteGardSize);

            int realHeaderSize = nameHeaderLen + dirHeaderLen + fileHeaderLen + lenDatalen;

            byte[] dumyArr = new byte[realHeaderSize];

            string encData      = AES256Manager.encode(dumyArr, UUID);
            long   encHeaderLen = Encoding.UTF8.GetByteCount(encData);

            return(encHeaderLen);
        }
Ejemplo n.º 4
0
        public static void SaveSettingData(string data)
        {
            logger.Info(inst, "Saving SaveFile... SaveFile dir = " + saveFileDir);
            byte[] fakeUUID = UUIDManager.MakeUUID();

            byte[] UUID = UUIDManager.ConvertUUID(fakeUUID);

            string rawData = AES256Manager.encode(data, UUID);

            if (File.Exists(saveFileDir))
            {
                File.Delete(saveFileDir);
            }

            StreamWriter writer = new StreamWriter(saveFileDir);

            writer.Write(fakeUUID);
            byteBoundaryWork(writer.BaseStream, true);
            writer.Write(rawData);

            writer.Close();
            logger.Info(inst, "Loading SaveFile Success!");
        }
Ejemplo n.º 5
0
        public byte[] getPackedData()
        {
            FileManagerCore.logger.Info(this, "start Packing... target Dir = " + targetDir);
            resFileListReader.searchDir(targetDir, targetDir, null);

            Dictionary <string, short> nameInfo = _getNameDataList();

            MemoryStream ms = new MemoryStream();

            ms.Write(fakeUUID, 0, fakeUUID.Length);
            FileManagerCore.byteBoundaryWork(ms, true);

            long encHeaderLen = _getHeaderLen(nameInfo);

            byte[] headerLenData = BitConverter.GetBytes(encHeaderLen);

            ms.Write(headerLenData, 0, headerLenData.Length);
            FileManagerCore.byteBoundaryWork(ms, true);

            long resumePosition = ms.Position;

            long nameDataStartPoint = fakeUUID.Length + FileManagerCore.byteGardSize + FileManagerCore.longSize + FileManagerCore.byteGardSize + (encHeaderLen + FileManagerCore.byteGardSize);

            ms.Position = nameDataStartPoint;

            MemoryStream headerMaker = new MemoryStream();

            byte[] vOut = BitConverter.GetBytes((long)nameInfo.Count);
            headerMaker.Write(vOut, 0, vOut.Length);
            FileManagerCore.byteBoundaryWork(headerMaker, true);

            foreach (string name in nameInfo.Keys)
            {
                vOut = BitConverter.GetBytes(nameInfo[name]);
                headerMaker.Write(vOut, 0, vOut.Length);

                vOut = BitConverter.GetBytes(ms.Position);
                headerMaker.Write(vOut, 0, vOut.Length);

                byte[] data = Encoding.UTF8.GetBytes(name);
                ms.Write(data, 0, data.Length);

                vOut = BitConverter.GetBytes((long)data.Length);
                headerMaker.Write(vOut, 0, vOut.Length);
                FileManagerCore.byteBoundaryWork(headerMaker, true);

                FileManagerCore.byteBoundaryWork(ms, true);
            }

            vOut = BitConverter.GetBytes((long)resFileListReader.dirList.Count);
            headerMaker.Write(vOut, 0, vOut.Length);
            FileManagerCore.byteBoundaryWork(headerMaker, true);

            foreach (Dir dir in resFileListReader.dirList)
            {
                vOut = BitConverter.GetBytes(dir.id);
                headerMaker.Write(vOut, 0, vOut.Length);

                if (dir.parentDir != null)
                {
                    vOut = BitConverter.GetBytes(dir.parentDir.id);
                }
                else
                {
                    vOut = BitConverter.GetBytes((short)0);
                }

                headerMaker.Write(vOut, 0, vOut.Length);

                vOut = BitConverter.GetBytes(dir.nameId);
                headerMaker.Write(vOut, 0, vOut.Length);

                FileManagerCore.byteBoundaryWork(headerMaker, true);
            }

            vOut = BitConverter.GetBytes((long)resFileListReader.fileList.Count);
            headerMaker.Write(vOut, 0, vOut.Length);
            FileManagerCore.byteBoundaryWork(headerMaker, true);

            foreach (ResFile file in resFileListReader.fileList)
            {
                vOut = BitConverter.GetBytes(file.id);
                headerMaker.Write(vOut, 0, vOut.Length);

                vOut = BitConverter.GetBytes(file.parentDir.id);
                headerMaker.Write(vOut, 0, vOut.Length);

                vOut = BitConverter.GetBytes(file.nameId);
                headerMaker.Write(vOut, 0, vOut.Length);

                vOut = BitConverter.GetBytes(ms.Position);
                headerMaker.Write(vOut, 0, vOut.Length);

                file.rawData.WriteTo(ms);

                vOut = BitConverter.GetBytes(file.rawData.Length);
                headerMaker.Write(vOut, 0, vOut.Length);

                FileManagerCore.byteBoundaryWork(ms, true);
                FileManagerCore.byteBoundaryWork(headerMaker, true);
            }

            FileManagerCore.logger.Info(this, "file packing done!");

            ms.Position = resumePosition;

            string encData = AES256Manager.encode(headerMaker.ToArray(), UUID);

            headerMaker.Close();

            byte[] encHeader = Encoding.UTF8.GetBytes(encData);

            ms.Write(encHeader, 0, encHeader.Length);

            byte[] result = ms.ToArray();
            ms.Close();

            FileManagerCore.logger.Info(this, "header Write done!");

            return(result);
        }