JBoolean GMessageTableDir::Create ( JXDirector* supervisor, JFileArray& fileArray, GMessageTableDir** dir, const JFileVersion& version ) { JFAID id = 1; std::string data; fileArray.GetElement(id, &data); std::istringstream is(data); JString mailfile; is >> mailfile; JString lockfile = JString(mailfile) + ".lock"; if (JFileExists(lockfile)) { JString report = "The mailbox \"" + JString(mailfile); report += "\" is locked. Do you want to forcibly remove the lock on mailbox"; JBoolean yes = JGetUserNotification()->AskUserYes(report); if (yes) { GUnlockFile(mailfile); } else { return kJFalse; } } *dir = new GMessageTableDir(supervisor, mailfile); assert(*dir != NULL); (*dir)->GetWindow()->ReadGeometry(is); JBoolean success = CreateX(supervisor, mailfile, dir); if (success) { (*dir)->ReadState(fileArray, version); (*dir)->ListenTo((*dir)->GetWindow()); } return success; }
JBoolean GMApp::OpenSession() { JBoolean success = kJFalse; JString homeDir; if (JGetHomeDirectory(&homeDir)) { JAppendDirSeparator(&homeDir); JString session = homeDir + kStateFileName; if (JFileExists(session) && JFileReadable(session)) { JFileArray* fileArray; JError err = JFileArray::Create(session, kStateFileSignature, &fileArray); if (err.OK()) { JFileVersion version = fileArray->GetVersion(); if (0 < version && version <= kCurrentSessionVersion) { JFAID id = 1; JSize count; { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); is >> count; id.SetID(id.GetID() + 1); } if (count == 0) { delete fileArray; JRemoveFile(session); return kJFalse; } for (JSize i = 1; i <= count; i++) { JFileArray* embed; err = JFileArray::Create(fileArray, id, &embed); GMessageTableDir* dir; if (GMessageTableDir::Create(this, *embed, &dir, version)) { itsTableDirs->Append(dir); } id.SetID(id.GetID() + 1); delete embed; } { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); is >> count; id.SetID(id.GetID() + 1); } for (JSize i = 1; i <= count; i++) { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); GMessageEditDir* dir = new GMessageEditDir(JXGetApplication()); assert(dir != NULL); dir->ReadState(is, version); dir->Activate(); id.SetID(id.GetID() + 1); } { std::string data; fileArray->GetElement(id, &data); std::istringstream is(data); GGetInboxMgr()->ReadState(is); } success = kJTrue; }
void GMApp::SaveState() { JString homeDir; if (JGetHomeDirectory(&homeDir)) { JAppendDirSeparator(&homeDir); JString session = homeDir + kStateFileName; if (JFileExists(session)) { JRemoveFile(session); } JFileArray* fileArray; JError err = JFileArray::Create(session, kStateFileSignature, &fileArray); if (!err.OK()) { if (JFileExists(session)) { JRemoveFile(session); } delete fileArray; return; } fileArray->SetVersion(kCurrentSessionVersion); JSize count; { std::ostringstream dataStream; count = itsTableDirs->GetElementCount(); dataStream << count; fileArray->AppendElement(dataStream); } JFAID_t id = 2; for (JSize i = 1; i <= count; i++) { JFileArray* embed; err = JFileArray::Create(fileArray, id, &embed); itsTableDirs->NthElement(i)->GetData()->Save(); itsTableDirs->NthElement(i)->SaveState(*embed); delete embed; id ++; } for (JSize i = itsEditDirs->GetElementCount(); i >= 1; i--) { itsEditDirs->NthElement(i)->CheckForPendingMessage(); } { std::ostringstream dataStream; count = itsEditDirs->GetElementCount(); dataStream << count; fileArray->AppendElement(dataStream); } for (JSize i = 1; i <= count; i++) { std::ostringstream dataStream; itsEditDirs->NthElement(i)->SaveState(dataStream); fileArray->AppendElement(dataStream); } { std::ostringstream dataStream; GGetInboxMgr()->SaveState(dataStream); fileArray->AppendElement(dataStream); } delete fileArray; } }