⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 .#progectdb.c.1.21

📁 个人日程管理系统
💻 21
📖 第 1 页 / 共 3 页
字号:
	Char* tmpName = "lbPG-tmpConvertProcess";	LocalID newID, oldID;	DmOpenRef newDB = 0, oldDB;	MemHandle hOld, hNew;	UInt16 i, descLen;	UInt16 fakeIndex;	UInt32 size, xbSize;	UInt16 cardNo = 0;	TaskFormatType format;	TaskAttrType attr;	UInt8 completed;	SafeCopy(dbname, gCurrentPrefs.openDBName,dmDBNameLength);	switch (dbformat)	{		/* Starting with 0.23, removed support for version 0.11 conversion. */		case 18: // old(0.18) -> 0.23			/* For this conversion, the following things must be done :			 * 		- replace changed bits of TaskAttrType			 * 		- update task type			 * 		- update progress status			 * 		- move XB			 */			DBGMSG((DBB, "Closing database"));			DmCloseDatabase(gdbP);			DBGMSG((DBB, "Renaming database"));			RenameDB(dbname, tmpName);			// prepend for opening			Prepend(dbname);			// create, pass the name without prepending			CreateDB(&dbname[5]);			// open (prepended name)			newID = DmFindDatabase(cardNo, dbname);			// open the databases			DBGMSG((DBB, "Searching old database"));			oldID = DmFindDatabase(cardNo, tmpName);			DBGMSG((DBB, "Opening new"));			newDB = DmOpenDatabase(cardNo, newID, dmModeReadWrite);			DBGMSG((DBB, "Opening old"));			oldDB = DmOpenDatabase(cardNo, oldID, dmModeReadOnly);						// get the number of records			recNum = DmNumRecords(oldDB);// - calcNumDeleted(oldDB);			DBGMSG((DBB, "%hu records found in old database", recNum));			// convert each record (except task0 and the deleted ones)			for (i = 1; i < recNum; i++)			{				TaskRecordType *pOld;				TaskRecordType *pNew;				// get the old one				DBGMSG((DBB, "Getting old record %hu", i));				hOld = DmQueryRecord(oldDB, i);				pOld = MemHandleLock(hOld);				fakeIndex = dmMaxRecordIndex;				DBGMSG((DBB, "Desc : %s", &pOld->description));				// calc the size of the new one				descLen = StrLen(&pOld->description) + 1; // with \0				size = TaskRecordTypeSize + StrLen(&pOld->description) +					StrLen(&pOld->description + descLen); 				DBGMSG((DBB, "Computed record size : %lu", size));				// create a record				hNew = DmNewRecord(newDB, &fakeIndex, size);								// reget the pointer				MemHandleUnlock(hOld);				pOld = MemHandleLock(hOld);				// convert attributes				attr.level = pOld->attr.bits.level;				attr.hasNext = pOld->attr.bits.hasNext;				attr.hasChild = pOld->attr.bits.hasChild;				attr.opened = pOld->attr.bits.opened;				attr.hasPrev = pOld->attr.bits.hasPrev;				pNew = MemHandleLock(hNew);				// write				// first, reset it (to have the note be \0)				DmSet(pNew, 0, size, 0);				// write attr, priority, dueDate				DBGMSG((DBB, "Writing attr, priority, duedate"));				DmWrite(pNew, OffsetOf(TaskRecordType, attr), &attr, 					sizeof(UInt16));				DmWrite(pNew, OffsetOf(TaskRecordType, priority), 					&pOld->priority, sizeof(UInt8));				DmWrite(pNew, OffsetOf(TaskRecordType, dueDate), 					&pOld->dueDate, sizeof(DateType));				// copy description				DBGMSG((DBB, "Writing description"));				DmStrCopy(pNew, OffsetOf(TaskRecordType, description), 					&pOld->description);				// copy note				DBGMSG((DBB, "Writing note"));				DmStrCopy(pNew, OffsetOf(TaskRecordType, description) + descLen,					&pOld->description + descLen);				// special cases, completed and format				format = pOld->format.bits;				completed = pOld->completed;				DBGMSG((DBB, "Completed = %hu", completed));				if (pOld->completed < CNV_ACTION)				{					format.itemType = progressType;					DBGMSG((DBB, "was a progress"));				}				else if (pOld->completed == CNV_ACTION_NO)				{					format.itemType = actionType;					completed = 0;					DBGMSG((DBB, "was an undone action"));				}				else if (pOld->completed == CNV_ACTION_OK)				{					format.itemType = actionType;					completed = 10;					DBGMSG((DBB, "was a done action"));				}				else if (pOld->completed == CNV_INFORMATIVE)				{					format.itemType = informativeType;					completed = 0;					DBGMSG((DBB, "was info"));				}				else if (pOld->completed >= CNV_NUMERIC)				{					format.itemType = numericType;					completed = completed - CNV_NUMERIC;					DBGMSG((DBB, "was numeric"));				}				DBGMSG((DBB, "writing completed and format"));				DmWrite(pNew, OffsetOf(TaskRecordType, completed), 					&completed, sizeof(UInt8));				DmWrite(pNew, OffsetOf(TaskRecordType, format), &format, 					sizeof(UInt16));				MemHandleUnlock(hOld);				MemHandleUnlock(hNew);				DmReleaseRecord(newDB, fakeIndex, true);				DBGMSG((DBB, "record released, getting extrablock"));				xbSize = TaskGetExtraBlockV022(oldDB, i, NULL);				DBGMSG((DBB, "xb size = %lu", xbSize));				if (xbSize > 8) // one data chunk, one null chunk				{					MemPtr xb;					xb = MemPtrNew(xbSize);					DBGMSG((DBB, "getting xb"));					TaskGetExtraBlockV022(oldDB, i, xb);					DBGMSG((DBB, "setting xb"));					TaskSetExtraBlock(newDB, i, xb, xbSize);				}				DBGMSG((DBB, "-------------------------"));			}			DmCloseDatabase(oldDB);			DBGMSG((DBB, "deleting old db"));			DmDeleteDatabase(cardNo, oldID);			gdbID = newID;			break;		default:			break;	}	return newDB;} // static void ConvertDB(UInt8 format)/**************************************************************************** * Name : Prepend * Desc : check if a name is prepended, if not, prepend it * In   : * 			<-> name * Out  : - * Auth : lb, 26.08.2000 ***************************************************************************/void Prepend(Char* name){	Char tmp[dmDBNameLength];	// if the name is not prepended	if (StrStr(name, gPrepend) != name)	{		// prepend the name		SafeCopy(tmp, gPrepend,dmDBNameLength);		StrNCat(tmp, name,dmDBNameLength);		StrCopy(name, tmp); // Safe to do a StrCopy, we know src size	}} // void Prepend(Char* name)/**************************************************************************** * Name : DuplicateDB * Desc : duplicate a project * In   : * 			-> source (with or without prepending) * 			-> dest   ( "         "      "       ) * Out  : - * Auth : lb, 27.08.2000 ***************************************************************************/Err DuplicateDB(Char* src, Char* dbname){	UInt16 recNum;	LocalID newID, oldID;	DmOpenRef newDB, oldDB;	MemHandle hOld, hNew;	TaskRecordType *pOld, *pNew;	UInt16 i;	UInt16 index;	UInt16 cardNo = 0;	UInt16 oldAttr, newAttr;	LocalID appInfoID;	Err err;	MemPtr oldP, newP;	// prepend _always_	Prepend(dbname);		// create, pass the name without the prepending	err = CreateDB(&dbname[5]);	// open (prepended name)	if (!err)		newID = DmFindDatabase(cardNo, dbname);	else		return err;	// prepend (if needed)	Prepend(src);	// open the databases	oldID = DmFindDatabase(cardNo, src);	newDB = DmOpenDatabase(cardNo, newID, dmModeReadWrite);	oldDB = DmOpenDatabase(cardNo, oldID, dmModeReadOnly);		// get the number of records	recNum = DmNumRecords(oldDB);// - calcNumDeleted(oldDB);	// copy each record (except task0)	for (i = 1; i < recNum; i++)	{		index = dmMaxRecordIndex;		hOld = DmQueryRecord(oldDB, i);		pOld = MemHandleLock(hOld);		hNew = DmNewRecord(newDB, &index, MemPtrSize(pOld));		if (!hNew)		{			MessageBox(StrNoMemorySpaces);			break;		}		pNew = MemHandleLock(hNew);		DmWrite(pNew, 0, pOld, MemPtrSize(pOld));		MemHandleUnlock(hNew);		MemHandleUnlock(hOld);		DmReleaseRecord(newDB, index, true);		// get category		DmRecordInfo(oldDB, i, &oldAttr, NULL, NULL);		DmRecordInfo(newDB, i, &newAttr, NULL, NULL);		newAttr &= ~dmRecAttrCategoryMask; // remove category info		oldAttr &= dmRecAttrCategoryMask; // keep only category info		newAttr |= oldAttr; // get old category		// set it to the new record		DmSetRecordInfo(newDB, index, &newAttr, NULL);	}	// copy appInfo block	appInfoID = DmGetAppInfoID(oldDB);	oldP = MemLocalIDToLockedPtr(appInfoID, 0);	hNew = DmNewHandle(newDB, MemPtrSize(oldP));	if (!hNew)	{		MessageBox(StrNoMemorySpaces);	}	else	{		appInfoID = MemHandleToLocalID(hNew);		DmSetDatabaseInfo(0, newID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 			&appInfoID, NULL, NULL, NULL);		newP = MemLocalIDToLockedPtr(appInfoID, 0);		DmWrite(newP, 0, oldP, MemPtrSize(oldP));		MemPtrUnlock(oldP);		MemPtrUnlock(newP);	}	DmCloseDatabase(oldDB);	DmCloseDatabase(newDB);	return errNone;} // void DuplicateDB(Char* src, Char* dbname)/**************************************************************************** * Name : OpenClipboard * Desc : open the clipboard, create it if it doesn't exist * In   : * Out  : - * Auth : lb, 04.09.2000 ***************************************************************************/pgErr OpenClipboard(void){	UInt16 cardNo = 0;	Err err = errNone;	LocalID dbID;	char dbname[] = "lbPG-Clipboard";	UInt16 index = 0;	dbID = DmFindDatabase(cardNo, dbname);	// if database doesn't exist, create it	if (!dbID)	{		err = DmCreateDatabase(cardNo, dbname, CREATOR, 'CLIP', false);		if (err)		{			DEBUG1("Cannot create a clipboard database.");			return pgError;		}		dbID = DmFindDatabase(cardNo, dbname);	}	gClip = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);	if (DmNumRecords(gClip) == 0)	{		DEBUG1("Adding task 0");		AddRecord(gClip, &gEmptyTask, &index);	}	return pgOK;} // pgErr OpenClipboard(void)/**************************************************************************** * Name : CloseClipboard * Desc : close the clipboard * In   : * Out  : - * Auth : lb, 04.09.2000 ***************************************************************************/pgErr CloseClipboard(void){	if (gClip)	{		DmCloseDatabase(gClip);		gClip = NULL;	}	return pgOK;} // pgErr CloseClipboard(void)/**************************************************************************** * Name : NewClipboard * Desc : close the clipboard, remove it, create a new one, open it * In   : * Out  : - * Auth : lb, 05.09.2000 ***************************************************************************/pgErr NewClipboard(void){	UInt16 cardNo = 0;	Err err = errNone;	LocalID dbID;	char dbname[] = "lbPG-Clipboard";	UInt16 index = 0;	CloseClipboard();	dbID = DmFindDatabase(cardNo, dbname);	// if database exists, remove it	if (dbID)	{		DmDeleteDatabase(cardNo, dbID);	}	err = DmCreateDatabase(cardNo, dbname, CREATOR, 'CLIP', false);	if (err)		return pgError;	dbID = DmFindDatabase(cardNo, dbname);	gClip = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);	AddRecord(gClip, &gEmptyTask, &index);	return pgOK;		} // pgErr NewClipboard(void)/**************************************************************************** * Name : SafeCopy * Desc : Do all the safe copy stuff, because StrNCopy is still stupid. * In   : dest, src (overwritten), size_of_buffer * Out  : - * Auth : rp, 03.08.2003****************************************************************************/void SafeCopy(Char* dest,const Char *src, UInt16 size){	// +++ FIX THIS +++	// Need to check for a size of zero, since that's invalid	// +++ FIX THIS +++	// StrnCopy can only take a UInt16 for size	StrNCopy(dest,src,size-1);	dest[size-1]=chrNull;} // void SafeCopy(Char* dest,const Char *src, UInt16 size)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -