00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __STORE2_H
00012 #define __STORE2_H
00013
00014 #include "Gdc2.h"
00015 #include "GContainers.h"
00016 #include "Progress.h"
00017 #include "StoreCommon.h"
00018
00019 class WriterItem;
00020 class GSubFilePtr;
00021
00022 namespace Storage2
00023 {
00024 #define STORAGE2_ITEM_MAGIC 0x123400AB
00025 #define STORAGE2_MAGIC 0x123400FE
00026
00027 class StorageKitImpl;
00028 class StorageItemImpl;
00029 class StorageKitImplPrivate;
00030
00031 struct StorageItemHeader
00032 {
00033 uint32 Magic;
00034
00035
00036 uint32 Type;
00037 uint32 DataLoc;
00038 uint32 DataSize;
00039
00040
00041 uint32 ParentLoc;
00042 uint32 DirLoc;
00043 uint32 DirCount;
00044 uint32 DirAlloc;
00045
00046
00047 StorageItemHeader();
00048 bool Serialize(GFile &f, bool Write);
00049 };
00050
00051 class StorageItemImpl : public StorageItem
00052 {
00053 friend class StorageKitImpl;
00054 friend class StorageKitImplPrivate;
00055 friend class StorageObj;
00056
00057 friend class WriterItem;
00058
00059 private:
00060 uint32 StoreLoc;
00061 bool HeaderDirty;
00062 StorageItemHeader *Header;
00063 StorageItemHeader *Dir;
00064 StorageItemHeader *Temp;
00065
00066 StorageItemImpl *Next;
00067 StorageItemImpl *Prev;
00068 StorageItemImpl *Parent;
00069 StorageItemImpl *Child;
00070
00071 StorageKitImpl *Tree;
00072
00073 bool IncDirSize();
00074 bool DirChange();
00075
00076 bool SetDirty(bool Dirty);
00077 bool SerializeHeader(GFile &f, bool Write);
00078 bool SerializeObject(GSubFilePtr &f, bool Write);
00079
00081 void CleanAll();
00082
00083 public:
00084 StorageItemImpl(StorageItemHeader *header);
00085 ~StorageItemImpl();
00086
00087
00088 StorageItem *GetNext();
00089 StorageItem *GetPrev();
00090 StorageItem *GetParent();
00091 StorageItem *GetChild();
00092
00093 StorageItem *CreateNext(StorageObj *Obj);
00094 StorageItem *CreateChild(StorageObj *Obj);
00095 StorageItem *CreateSub(StorageObj *Obj);
00096 bool InsertSub(StorageItem *Obj, int At = -1);
00097 bool DeleteChild(StorageItem *Obj);
00098 bool DeleteAllChildren();
00099
00100
00101 int GetType();
00102 void SetType(int i);
00103 int GetTotalSize();
00104 int GetObjectSize();
00105 StorageKit *GetTree();
00106
00107
00108 GFile *GotoObject(char *file, int line);
00109 bool EndOfObj(GFile &f);
00110 bool Save();
00111
00112
00113 int GetStoreLoc() { return StoreLoc; }
00114 };
00115
00116 struct StorageHeader {
00117
00118 int Magic;
00119 int Version;
00120 int Reserved1;
00121 int Reserved2;
00122 char Password[32];
00123 int Reserved3[4];
00124 };
00125
00126 class StorageKitImpl :
00127 public GObject,
00128 public StorageKit,
00129 public GSemaphore
00130 {
00131 friend class StorageItemImpl;
00132 friend class StorageKitImplPrivate;
00133
00134 protected:
00135 StorageKitImplPrivate *d;
00136
00137
00138 char *FileName;
00139 bool Status;
00140 int StoreLoc;
00141 int Version;
00142 bool ReadOnly;
00143 GPassword Password;
00144
00145 class GSubFile *File;
00146 class GSubFilePtr *CreateFilePtr(char *file, int line);
00147
00148
00149 StorageItemHeader RootHeader;
00150 StorageItemImpl *Root;
00151
00152 bool _ValidLoc(uint64 Loc);
00153 bool _Serialize(GFile &f, bool Write);
00154
00155 public:
00156 StorageKitImpl(char *FileName);
00157 ~StorageKitImpl();
00158
00159 bool IsOk();
00160 int GetStatus() { return Status; }
00161 bool GetReadOnly() { return ReadOnly; }
00162 int GetVersion() { return Version; }
00163 uint64 GetFileSize();
00164 bool GetPassword(GPassword *p);
00165 bool SetPassword(GPassword *p);
00166 GSemaphore *GetLock();
00167 char *GetFileName() { return FileName; }
00168
00169 StorageItem *GetRoot();
00170 StorageItem *CreateRoot(StorageObj *Obj);
00171
00172 bool Compact(Progress *p, bool Interactive, StorageValidator *Validator = 0);
00173 bool DeleteItem(StorageItem *Item);
00174 bool SeparateItem(StorageItem *Item);
00175 bool AttachItem(StorageItem *Item, StorageItem *To, NodeRelation Relationship = NodeChild);
00176 };
00177
00178 }
00179
00180 #endif