예제 #1
0
            public bool Add(string key, ISerializable serializableObj, bool yird, string recordName, bool saveFlagResetValue)
            {
                if (serializableObj == null)
                {
                    return(false);
                }

                if (FindByKey(key) != null)
                {
                    Debug.LogError("serialize obj existed: " + key);
                    return(false);
                }

                ArchiveObj obj = Get(recordName);

                if (obj == null)
                {
                    obj = new ArchiveObj(recordName, saveFlagResetValue);
                    mList.Add(obj);
                }
                else
                {
                    obj.SetSaveFlagResetValue(saveFlagResetValue);
                }
                obj.Add(key, serializableObj, yird);

                return(true);
            }
예제 #2
0
        public bool SaveMe(string key)
        {
            ArchiveObj record = mArchiveObjList.FindByKey(key);

            if (record == null)
            {
                return(false);
            }

            record.SetAllFlag(true);
            return(true);
        }
예제 #3
0
        void WriteRecord(ArchiveIndexFile indexFile, ArchiveObj serializeObj)
        {
            if (serializeObj.hasNonYird)
            {
                string filePath = GetFilePath(dir, serializeObj.recordName);

                using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                {
                    using (BinaryWriter writer = new BinaryWriter(fileStream))
                    {
                        indexFile.header.Write(writer);
                        indexFile.header.BeginWriteCheckSum(writer);

                        serializeObj.Foreach((obj) =>
                        {
                            if (!obj.yird)
                            {
                                Profiler.BeginSample("save:" + obj.key);
                                long beginPos = fileStream.Position;
                                obj.serialize.Serialize(new PeRecordWriter(obj.key, writer));
                                long endPos = fileStream.Position;

                                indexFile.Add(obj.key, new ArchiveIndex(serializeObj.recordName, obj.yird, beginPos, endPos));
                                Profiler.EndSample();
                            }
                        });

                        indexFile.header.EndWriteCheckSum(writer);
                    }
                }
            }

            if (serializeObj.hasYird)
            {
                string yirdDir      = indexFile.GetYirdDir(dir);
                string yirdFilePath = GetFilePath(yirdDir, serializeObj.recordName);

                if (!Directory.Exists(yirdDir))
                {
                    Directory.CreateDirectory(yirdDir);
                }

                using (FileStream yirdFileStream = new FileStream(yirdFilePath, FileMode.Create, FileAccess.Write))
                {
                    using (BinaryWriter yirdWriter = new BinaryWriter(yirdFileStream))
                    {
                        indexFile.header.Write(yirdWriter);
                        indexFile.header.BeginWriteCheckSum(yirdWriter);

                        serializeObj.Foreach((obj) =>
                        {
                            Profiler.BeginSample("save:" + obj.key);

                            if (obj.yird)
                            {
                                long beginPos = yirdFileStream.Position;

                                obj.serialize.Serialize(new PeRecordWriter(obj.key, yirdWriter));

                                long endPos = yirdFileStream.Position;

                                indexFile.Add(obj.key, new ArchiveIndex(serializeObj.recordName, obj.yird, beginPos, endPos));
                            }

                            Profiler.EndSample();
                        });

                        indexFile.header.EndWriteCheckSum(yirdWriter);
                    }
                }
            }
        }
예제 #4
0
        static void CopyIndex(ArchiveIndexFile indexFile, ArchiveIndexFile oldIndexFile, ArchiveObj serializeObj)
        {
            if (oldIndexFile == null)
            {
                return;
            }

            serializeObj.Foreach((obj) =>
            {
                Profiler.BeginSample("only copy index:" + obj.key);

                ArchiveIndex index = oldIndexFile.GetArchiveIndex(obj.key);
                if (index != null)
                {
                    indexFile.Add(obj.key, index);
                }

                Profiler.EndSample();
            });
        }