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

📄 .#progectdb.c.1.21

📁 个人日程管理系统
💻 21
📖 第 1 页 / 共 3 页
字号:
 * 			<-> database reference * Out  : Err code * Auth : lb, 27.07.2000 * Mod  : lb, 14.08.2000 * 			to save app current state * 		  lb, 17.08.2000 * 		  	try to prepend * 		  lb, 24.08.2000 * 		  	fix without prepending mode that caused a crash after two * 		  	come backs ***************************************************************************/Err OpenDB(const char* nameP, DmOpenRef *dbP){	UInt16 cardNo = 0;	UInt16 mode = dmModeReadWrite;	UInt16 dbversion;	Err Err = 0;	Char dbname[dmDBNameLength];	DBGMSG((DBB, "In OpenDB"));	SafeCopy(dbname,nameP,dmDBNameLength);	Prepend(dbname);	// find the database	gdbID = DmFindDatabase(cardNo, dbname);	if (!gdbID)	{		// try without prepending (for databases before V0.10)		// find the database		SafeCopy(dbname,nameP,dmDBNameLength);		gdbID = DmFindDatabase(cardNo, dbname);		// if found		if (!gdbID)		{			return DmGetLastErr();		}	}	// Check version number	DmDatabaseInfo(cardNo, gdbID, NULL, NULL, &dbversion, NULL, NULL, NULL,		NULL, NULL, NULL, NULL, NULL);	if (dbversion > DBVERSION)	{		Char version[32];		Char* p;		StrIToA(version, dbversion/100);		p = version + StrLen(version);		*p = '.';		p++;		StrIToA(p, dbversion % 100);				DEBUG2("The project you are trying to open needs version ^1 of "			"Progect. Please upgrade at sf.net/projects/progect", version);		return 1;	}	// open it	*dbP = DmOpenDatabase(cardNo, gdbID, mode);	// if it failed	if (!*dbP)	{		// get error code		Err = DmGetLastErr();	}	else	{		SafeCopy(gCurrentPrefs.openDBName, dbname,dmDBNameLength);		gCurrentPrefs.openDB = true;		LoadDBPrefs(dbP);		//gNumDeleted = calcNumDeleted(*dbP);		//DBGMSG((DBB, "num deleted at opening : %hu", gNumDeleted));		if (gProjectPrefs.autoSyncToDo)		{			TaskSyncAll();			DBGMSG((DBB, "After task sync all"));		}		// save/restore the pointer have no meaning,		// and it will be crash program.		//   NOTE: fix BUG#115440		//             "Newly created task/note has garbage text in it"		MemMove((MemPtr)&gEmptyTask,				(MemPtr)&gProjectPrefs.taskDefaults,				(UInt8*)&(gEmptyTask.description) - (UInt8*)&gEmptyTask);//		gEmptyTask = gProjectPrefs.taskDefaults;		// needed by 0.23 to get rid of the deleted records	}	return Err;} // static Err OpenDB(const char* nameP, DmOpenRef *dbP)/**************************************************************************** * Name : OpenDBByID * Desc : open a database by cardNo and dbID * Prm  :  * 			->  card no * 			->  database id * 			<-> database reference * Out  : Err code * Mod  : lb, 2001-12-03 * 		fixed bug causing loss of categories when using history ***************************************************************************/Err OpenDBByID(UInt16 cardNo, LocalID dbID, DmOpenRef* dbP){	// Open 	Char* name;	DmOpenRef pDB = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);	if (! pDB)		return DmGetLastErr();	// close current opend DB	if (*dbP)		CloseDB(*dbP);	// setting up global status.	*dbP = pDB;	gdbID = dbID;	name = MemPtrNew(dmDBNameLength);	DmDatabaseInfo(cardNo, dbID, name, NULL, NULL, NULL, NULL, NULL,				   NULL, NULL, NULL, NULL, NULL);	SafeCopy(gCurrentPrefs.openDBName, name,dmDBNameLength);	MemPtrFree(name);	gCurrentPrefs.openDB = true;	LoadDBPrefs(dbP);	//gNumDeleted = calcNumDeleted(*dbP);	if (gProjectPrefs.autoSyncToDo)		TaskSyncAll();	return 0;} // Err OpenDBByID(UInt16 cardNo, LocalID dbID, DmOpenRef* dbP)/**************************************************************************** * Name : CloseDB * Desc : close the database * In   : pointer to the database to close * Out  : Err code * Auth : lb, 27.07.2000 * Mod  : lb, 14.08.2000 * 			to save app current state ***************************************************************************/Err CloseDB(DmOpenRef dbP){	Err Err;	SaveDBPrefs(dbP);	// close the database	Err = DmCloseDatabase(dbP);	gCurrentPrefs.openDB = false;	gCurrentPrefs.topTask = -1;	gdbID = 0;	gdbP = NULL;	return Err;} // static Err CloseDB(DmOpenRef dbP)/**************************************************************************** * Name : RenameDB * Desc : rename a database * In   : * 			-> old name (with or without prepending) * 			-> new name (with or without prepending) * Out  : - * Auth : lb, 23.08.2000 ***************************************************************************/Err RenameDB(Char* oldName, Char* newName){	UInt16 cardNo = 0;	LocalID dbID;	Prepend(newName);	// find the database (without prepending)	dbID = DmFindDatabase(cardNo, oldName);	if (!dbID)	{		// try with prepending		// find the database		Prepend(oldName);		dbID = DmFindDatabase(cardNo, oldName);		if (!dbID)			return DmGetLastErr();	}	return DmSetDatabaseInfo(cardNo, dbID, newName, NULL, NULL, NULL, NULL, 					NULL, NULL, NULL, NULL, NULL, NULL);} // static Err RenameDB(Char* oldName, Char* newName)/**************************************************************************** * Name : SaveDBPrefs * Desc : save the database preferences * In   : * Out  : - * Auth : lb, 17.08.2000 ***************************************************************************/void SaveDBPrefs(DmOpenRef dbP){	LocalID appInfoID;	DBInfoType* p;	MemHandle h;	appInfoID = DmGetAppInfoID(dbP);	// if there is no appInfoID, create it	if (! appInfoID)	{		h = DmNewHandle(dbP, sizeof(DBInfoType));		if (!h)			return;		appInfoID = MemHandleToLocalID(h);		DmSetDatabaseInfo(0, gdbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 			&appInfoID, NULL, NULL, NULL);		p = MemLocalIDToLockedPtr(appInfoID, 0);		DmSet(p, 0, sizeof(DBInfoType), 0);		CategoryInitialize(&p->appInfo, InitialCategory);	}	else		p = MemLocalIDToLockedPtr(appInfoID, 0);	// test the size	// if it's not good, the next LoadDBPrefs will correct it	if (MemPtrSize(p) == sizeof(DBInfoType))	{		// write the new prefs		DmWrite(p, OffsetOf(DBInfoType, pref),				&gProjectPrefs, sizeof(ProjectPrefsType));	}	// unlock	MemPtrUnlock(p);} // static void SaveDBPrefs(void)/**************************************************************************** * Name : LoadDBPrefs * Desc : load the database preferences * In   :	-> ptr to the DmOpenRef * Out  : false = no prefs * 		  true  = ok * 		  DmOpenRef is updated if the database has changed (conversion) * Auth : lb, 17.08.2000 * Mod  : lb, 17.08.2000 * 			- pass db, because when OpenDB calls, gdbp is not set ! *        hcc, 05.05.2001 *          - When resizing project preferences, preserve old prefs. ***************************************************************************/Boolean LoadDBPrefs(DmOpenRef *dbP){	DBInfoType *p;	LocalID appInfoID;	LocalID oldInfoID = 0;	UInt32 len;	DBGMSG((DBB, "In LoadDBPrefs"));	appInfoID = DmGetAppInfoID(*dbP);	if (appInfoID)	{		p = MemLocalIDToLockedPtr(appInfoID, 0);		if (MemPtrSize(p) < 30 && *(UInt8*)p < 11)		{			DEBUG1("Old database version (<=0.11) conversion, code removed...");			MemPtrUnlock(p);			/* TODO: Finish removing this logic...             * ConvertDB(11);*/		}		else if (p->pref.format < 23)		{			DEBUG1("Converting db to 0.23 format, please click OK and wait...");			MemPtrUnlock(p);			*dbP = ConvertDB(18);			oldInfoID = DmGetAppInfoID(*dbP);			appInfoID = 0;		}		else if (p->pref.format == 23)		{			// 0.23 database could have deleted records, we purge them since			// they're not needed at all			TaskRemoveDeletedRecords(*dbP);		}		else if (MemPtrSize(p) != sizeof(DBInfoType) )		{			MessageBox(StrPrefsHasBeenDeleted);			oldInfoID = appInfoID;			appInfoID = 0;			MemPtrUnlock(p);		}	}	if (! appInfoID)	{		// create new prefs		MemHandle h = DmNewHandle(*dbP, sizeof(DBInfoType));		if (! h)			return false;		DBGMSG((DBB,"need to reconstruct appinfoID"));		appInfoID = MemHandleToLocalID(h);		DmSetDatabaseInfo(0, gdbID, NULL, NULL, NULL, NULL, NULL, 						  NULL, NULL, &appInfoID, NULL, NULL, NULL);		// get a pointer		p = MemLocalIDToLockedPtr(appInfoID, 0);				// write the new prefs		DmSet(p, 0, sizeof(DBInfoType), 0);		// Init prefs to default. May be partially overwritten with		// newer prefs below.		DmWrite(p, OffsetOf(DBInfoType, pref),				&gProjectPrefs, sizeof(ProjectPrefsType));		CategoryInitialize(&p->appInfo, InitialCategory);		if (oldInfoID)		{   // copy original categories & preferences			AppInfoType* pp = MemLocalIDToLockedPtr(oldInfoID, 0);			DBGMSG((DBB,"Old appinfoID found, using it"));			if (MemPtrSize(pp) > sizeof(AppInfoType) + 20)			{				DmWrite(p, 0, pp, sizeof(AppInfoType));				// Calculate amount of old prefs to copy, based on				// the smaller set of prefs.				len = MemPtrSize(pp);				if(len > MemPtrSize(p))					len = MemPtrSize(p);				len -= sizeof(AppInfoType);								DmWrite(p, sizeof(AppInfoType),						((char *)pp) + sizeof(AppInfoType), len);			}			MemPtrUnlock(pp);		}		// set new DB format (+ copy reserved field)		DmWrite(p, 0, &gProjectPrefs, sizeof(UInt16));	}	// this produced an overlocked pointer => crash every 8th start	//else		//p = MemLocalIDToLockedPtr(appInfoID, 0);	MemMove(&gProjectPrefs, &p->pref, sizeof(ProjectPrefsType));	MemPtrUnlock(p);	if (oldInfoID)	{		// ... ??? how to delete old ID ???	}	return true;} // static Boolean LoadDBPrefs(DmOpenRef *dbP)/**************************************************************************** * Name : SaveAppPrefs * Desc : save the application preferences * In   : * 			-> saved : true for saved prefs, false for current prefs * Out  : - * Auth : lb, 14.08.2000 * Mod  : lb, 17.08.2000 * 			support for saved prefs ***************************************************************************/void SaveAppPrefs(Boolean saved){	PrefSetAppPreferences(CREATOR, 0, 1, 		saved ? (void*)&gSavedPrefs : (void*)&gCurrentPrefs, 		saved ? sizeof(SavedPrefsType) : sizeof(CurrentPrefsType), 		saved);} // static void SaveAppPrefs(Boolean saved)/**************************************************************************** * Name : LoadAppPrefs * Desc : load the application preferences * In   : * 			-> saved : true for saved prefs, false for current prefs * Out  : false = no prefs * 		  true  = ok * Auth : lb, 14.08.2000 * Mod  : lb, 17.08.2000 * 			support for saved prefs ***************************************************************************/Boolean LoadAppPrefs(Boolean saved){	UInt16 size = saved ? sizeof(SavedPrefsType) : sizeof(CurrentPrefsType);	UInt16 status;	status = PrefGetAppPreferences(CREATOR, 0, 		saved ? (void*)&gSavedPrefs : (void*)&gCurrentPrefs, &size, saved);	status = (size == 		(saved ? sizeof(SavedPrefsType) : sizeof(CurrentPrefsType))) ? status : noPreferenceFound;	return status == noPreferenceFound ? false : true;} // static Boolean LoadAppPrefs(Boolean saved)/**************************************************************************** * Name : ConvertDB * Desc : convert an old DB to the actual format * In   : * 			-> old format * Out  :   <- new DmOpenRef * Auth : lb, 22.08.2000 * Mod  : lb, 2001-10-16 : conversion 0.22 -> 0.23 ***************************************************************************/DmOpenRef ConvertDB(UInt8 dbformat){	Char dbname[dmDBNameLength];	UInt16 recNum;

⌨️ 快捷键说明

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