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;
}
Example #2
0
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;
					}