////////////////////////////////////////////////////////////////////////// WriteObject -- template class that writes an object to disk (ie -- report, db, etc) either encrypted or unencrypted. The only requrement on the object is that it is typed serializable. errorMsg is a number that can be passed to iUserString to indicate an appropriate error message if the object fails to load 10/30 -- this f
| 154 | // none is desired. |
| 155 | /////////////////////////////////////////////////////////////////////////////// |
| 156 | static void WriteObject(const TCHAR* filename, |
| 157 | const iTypedSerializable* pObjHeader, |
| 158 | const iTypedSerializable& obj, |
| 159 | cFileHeader& fileHeader, |
| 160 | bool bEncrypt, |
| 161 | const cElGamalSigPrivateKey* pPrivateKey) |
| 162 | { |
| 163 | cDebug d("WriteObject"); |
| 164 | d.TraceDebug(_T("Writing %s to file %s\n"), obj.GetType().AsString(), filename); |
| 165 | |
| 166 | ASSERT(pPrivateKey || (!bEncrypt)); |
| 167 | |
| 168 | cFileArchive arch; |
| 169 | |
| 170 | if (!cFileUtil::IsRegularFile(filename) && cFileUtil::FileExists(filename)) |
| 171 | throw eArchiveNotRegularFile(filename); |
| 172 | |
| 173 | try |
| 174 | { |
| 175 | arch.OpenReadWrite(filename); |
| 176 | } |
| 177 | catch (eArchive&) |
| 178 | { |
| 179 | // probably better to rethrow this as a write failed exception |
| 180 | throw eArchiveWrite(filename, iFSServices::GetInstance()->GetErrString()); |
| 181 | } |
| 182 | |
| 183 | WriteObjectToArchive(arch, filename, pObjHeader, obj, fileHeader, bEncrypt, pPrivateKey); |
| 184 | |
| 185 | arch.Close(); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /////////////////////////////////////////////////////////////////////////////// |
no test coverage detected