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

📄 jam_adaptation.c

📁 java 1.1 gemini 08_16
💻 C
📖 第 1 页 / 共 4 页
字号:
	size -= scanStrLen + 2;

	CRCCode = update_crc(0, (kal_uint8*)content, size - 4);
	content[size - 4] = (kal_uint8)(CRCCode >> 24);
	content[size - 3] = (kal_uint8)(CRCCode >> 16);
	content[size - 2] = (kal_uint8)(CRCCode >> 8);
	content[size - 1] = (kal_uint8)CRCCode;
	handle = Kopen("suites.utftmp", O_CREAT | O_TRUNC);
	java_total_used_space -= scanStrLen + 2;
	if (size > 4)
	{ /* threre is zero suite in the device */
		Kwrite(handle, content, size );
	}
	Kclose(handle);

	handle = Kopen("suites.utf", O_CREAT | O_TRUNC);
	java_total_used_space -= scanStrLen + 2;
	if (size > 4)
	{ /* threre is zero suite in the device */
		Kwrite(handle, content, size);
	}
	Kclose(handle);

	if(content != NULL) midpFree(content);
#ifdef __SUPPORT_MIDLETSUITE_HASH_VALUE__
	scanPos = record_index << 2;
	// Out of boundary
	if(scanPos > hash_content_size) 
	{
		kal_print("Fatal Error: suites.hash record number mismatch to suites.utf");
		return -1;
	}

	memcpy(hash_content + scanPos, hash_content + scanPos + 4, hash_content_size - scanPos - 4);
	hash_content_size -= 4;

	CRCCode = update_crc(0, (kal_uint8*)hash_content, hash_content_size);
	hash_content[hash_content_size] = (kal_uint8)(CRCCode >> 24);
	hash_content[hash_content_size + 1] = (kal_uint8)(CRCCode >> 16);
	hash_content[hash_content_size + 2] = (kal_uint8)(CRCCode >> 8);
	hash_content[hash_content_size + 3] = (kal_uint8)CRCCode;
	
	handle = Kopen(SUITE_HASH_FILENAME, O_CREAT | O_TRUNC);
	java_total_used_space -= 4;
	if (hash_content_size >= 4)
	{ /* threre is zero suite in the device */
		Kwrite(handle, hash_content, hash_content_size + 4 );
	}
	Kclose(handle);

	handle = Kopen(SUITE_HASH_BACKUP_FILENAME, O_CREAT | O_TRUNC);
	java_total_used_space -= 4;
	if (hash_content_size >= 4)
	{ /* threre is zero suite in the device */
		Kwrite(handle, hash_content, hash_content_size + 4 );
	}
	Kclose(handle);	
#endif		

	return 0;
}

kal_int32 removeSuiteFromMIDSLIST(game_type_enum type, kal_char* storageName)
{
	kal_uint32 scanPosition = 0;
	kal_int32 mids;
	kal_int32 size;
	kal_uint8 * myBuffer;
	kal_char * myError = NULL;
	kal_uint32 CRCCode;
	kal_int32 strLen = strlen(storageName);
	kal_int32 returnValue = -1;
	mids = storageOpen(&myError, "MIDSLIST.save", OPEN_READ);
	if (myError == NULL)
	{
		size = storageSizeOf(&myError, mids);
		if (size != 0)
		{
			kal_int32 i;
			kal_int32 midsCount = 0;
			kal_int32 midsLength = 0;
			kal_int32 stringLength = 0;
			kal_char* string = NULL;
			storageRead(&myError, mids, (char*)&midsCount, 4);

			midsCount = traslateInt(midsCount);
			midsCount --;
			/* assume that the MIDlet suite indicated by storageName
			   will be removed */
			midsCount = traslateInt(midsCount);
			CRCCode = update_crc(0, (unsigned char *)&midsCount, 4);
			midsCount = traslateInt(midsCount);

			midsCount ++;

#ifdef __J2ME_SUPPORT_INDEX_STORAGE_NAME__
			storageRead(&myError, mids, (char*)&midsLength, 4);
			scanPosition = 8;
#else
			scanPosition = 4;
#endif

			for (i = 0; i < midsCount; i++)
			{
				kal_int32 MIDSPosition = 0;
				storageRead(&myError, mids, (char*)&midsLength, 4);
				midsLength = traslateInt(midsLength);
				storagePosition(&myError, mids, scanPosition);

				if (midsLength >= size)
				{ /* the MIDSLIST.save is not valid */
					storageClose(&myError, mids); /* Rex - fix to close file before */
					javaFileRemoveAll(type);
					javaFileRecovery(type);
					return returnValue;
				}

				myBuffer = (kal_uint8 *)midpMalloc(midsLength + 4);
				ASSERT(myBuffer != NULL);

				storageRead(&myError, mids, (char*)myBuffer, midsLength + 4);

				MIDSPosition = 4;
				MIDSPosition = skipOneStringField(myBuffer, MIDSPosition);

				stringLength = getMIDSInt(myBuffer, MIDSPosition);

				if (stringLength >= midsLength)
				{ /* the MIDSLIST.save is not valid */
					storageClose(&myError, mids); /* Rex - fix to close file before */
					javaFileRemoveAll(type);
					javaFileRecovery(type);
					return returnValue;
				}

				MIDSPosition += 4;
				if (stringLength != 0)
				{
					string = midpMalloc(stringLength);
					UCS2ToUTF8(string, myBuffer, MIDSPosition, stringLength);
				} else
					string = NULL;

				if ((strLen == stringLength - 1 || strLen == stringLength - 2) 
				      && strncmp(string, storageName, strLen) == 0)
				{
					kal_int32 nextMIDSPosition = scanPosition + midsLength + 4;
					kal_int32 copyPosition;
					kal_int32 copymids;
					/* use the latest allocated myBuffer to do the file copying */
					kal_int32 bufferLength = midsLength;
					storageClose(&myError, mids);
					midsCount --;
					midsCount = traslateInt(midsCount);
					midpFree(string);
					mids = storageOpen(&myError, "MIDSLIST.save", OPEN_WRITE);
					storageWrite(&myError, mids, (char *)&midsCount, 4);
					storageClose(&myError, mids);

					copyPosition = nextMIDSPosition;
					mids = storageOpen(&myError, "MIDSLIST.save", OPEN_READ_WRITE);
					while (copyPosition + bufferLength <= size - 4)
					{
						storagePosition(&myError, mids, copyPosition);
						storageRead(&myError, mids, (char*)myBuffer, bufferLength);
						CRCCode = update_crc(CRCCode, myBuffer, midsLength);
						storagePosition(&myError, mids, scanPosition);
						storageWrite(&myError, mids, (char*)myBuffer, bufferLength);
						copyPosition += bufferLength;
						scanPosition += bufferLength;
					}

					storagePosition(&myError, mids, copyPosition);
					storageRead(&myError, mids, (char*)myBuffer, size - 4 - copyPosition);
					CRCCode = update_crc(CRCCode, myBuffer, size - 4 - copyPosition);
					storagePosition(&myError, mids, scanPosition);
					storageWrite(&myError, mids, (char*)myBuffer, size - 4 - copyPosition);
					CRCCode = traslateInt(CRCCode);
					scanPosition += size - 4 - copyPosition;
					storageWrite(&myError, mids, (char*)&CRCCode, 4);

					storageClose(&myError,mids);

					mids = storageOpen(&myError, "MIDSLIST.save", OPEN_READ);
					copymids = storageOpen(&myError, "MIDSLIST.savetmp", OPEN_READ_WRITE_TRUNCATE);

					copyPosition = 0;
					while (copyPosition + bufferLength< scanPosition + 4)
					{
						storageRead(&myError, mids, (char*)myBuffer, bufferLength);
						storageWrite(&myError, copymids, (char*)myBuffer, bufferLength);
						copyPosition += bufferLength;
					}

					storageRead(&myError, mids, (char*)myBuffer, scanPosition + 4 - copyPosition);
					storageWrite(&myError, copymids, (char*)myBuffer, scanPosition + 4 - copyPosition);

					storageClose(&myError, mids);
					storageClose(&myError, copymids);

					mids = storageOpen(&myError, "MIDSLIST.savetmp", OPEN_READ);
					copymids = storageOpen(&myError, "MIDSLIST.save", OPEN_READ_WRITE_TRUNCATE);

					copyPosition = 0;
					while (copyPosition + bufferLength < scanPosition + 4)
					{
						storageRead(&myError, mids, (char*)myBuffer, bufferLength);
						storageWrite(&myError, copymids, (char*)myBuffer, bufferLength);
						copyPosition += bufferLength;
					}

					storageRead(&myError, mids, (char*)myBuffer, scanPosition + 4 - copyPosition);
					storageWrite(&myError, copymids, (char*)myBuffer, scanPosition + 4 - copyPosition);

					storageClose(&myError, mids);
					storageClose(&myError, copymids);
					returnValue = 0;

					break;
				} else
				{
					/* move to the next MIDlet suite */
					scanPosition += midsLength + 4;
					CRCCode = update_crc(CRCCode, myBuffer, midsLength + 4);
					midpFree(string);
					midpFree(myBuffer);
					if (i == midsCount - 1)
					{
						storageClose(&myError, mids);
					}
				}
			}
		}
	}
	return returnValue;
}

#ifndef __SUPPORT_NATIVE_INSTALLER__
static int deleteNotifyURLList(kal_char* storageName)
{
	/*read MIDlet-Delete-Notify: in jad file */
	kal_char *JadFileName = (kal_char*)midpMalloc(strlen(storageName) + 1  + strlen("suite.jad"));
	kal_int32 size;
	kal_char *myError = NULL;
	kal_int32 handle;
	kal_char *jadContent;
	kal_int32 scanPos = 0;
	kal_char* deleteNotifyURL;
	kal_char* deleteContent;
	kal_int32 deleteLen;
	kal_int32 deleteURLLen;
	strcpy(JadFileName, storageName);
	strcat(JadFileName, "suite.jad");
	handle = storageOpen(&myError, JadFileName, OPEN_READ);
	midpFree(JadFileName);
	if (myError == NULL)
	{
		size = storageSizeOf(&myError, handle);
		jadContent = midpMalloc(size + 1);
		storageRead(&myError, handle, jadContent, size);
		storageClose(&myError, handle);
		while (strncmp(jadContent + scanPos, "MIDlet-Delete-Notify:", 21) && scanPos < size)
		{
			while (jadContent[scanPos] != '\n' && scanPos < size)
			{
				scanPos ++;
			}
			if (jadContent[scanPos] == 0x0d || jadContent[scanPos] == 0x0a)
				scanPos ++;
		}

		if (scanPos >= size) /* the JAD does not have the MIDlet-Delete-Notify attribute */
			return 0;

		scanPos += 21; /* MIDlet-Delete-Notify: */
		while (jadContent[scanPos] == 0x20 && scanPos < size) /* delete space */
			scanPos ++;

		deleteNotifyURL = jadContent + scanPos;

		while (jadContent[scanPos] != 0x0d && jadContent[scanPos] != 0x0a && scanPos < size)
			scanPos ++;

		jadContent[scanPos] = 0; /* add NULL terminator */
		deleteURLLen = strlen(deleteNotifyURL);
		handle = storageOpen(&myError, "_delete_notify.utf", OPEN_READ);
		if (handle == -1)
		{
			deleteLen = deleteURLLen + 2;
			deleteContent = (kal_char*) midpMalloc(deleteLen);
		} else
		{
			int tempSize = storageSizeOf(&myError, handle);
			deleteLen = tempSize + deleteURLLen + 2;
			deleteContent = (kal_char*) midpMalloc(deleteLen);
			storageRead(&myError, handle, deleteContent, tempSize);
			storageClose(&myError, handle);
		}

		memcpy(deleteContent + deleteLen - deleteURLLen, deleteNotifyURL, deleteURLLen);

		deleteContent[deleteLen - deleteURLLen - 2] = deleteURLLen >> 8;
		deleteContent[deleteLen - deleteURLLen - 1] = deleteURLLen;

		handle = storageOpen(&myError, "_delete_notify.utf", OPEN_WRITE);
		/* set the Position to EOF */
		storagePosition(&myError, handle, storageSizeOf(&myError, handle));
		storageWrite(&myError, handle, deleteContent, deleteLen);
		storageClose(&myError, handle);
		midpFree(deleteContent);
		midpFree(jadContent);
	}
	return 0;
}
#endif

static void deletMIDletFile(kal_char* storageName)
{
	int pos; // add by jeff liu 20061026
	kal_bool pass = KAL_FALSE; 	// add by jeff liu 20061026
	kal_char *deleteFile;
	kal_char *myError = NULL;
	kal_char *allFiles = NULL;
	kal_int32 storage_len = strlen(storageName);
	int scanPos = 0;
	kal_char* j2me_save_path = work_dir_path;
	/* delete all files of the suite */
	allFiles = (kal_char*)getAllFilesInDir(storageName);
	if (allFiles != NULL)
	{
		deleteFile = allFiles;
		while (allFiles[scanPos] != 0)
		{
			if (allFiles[scanPos] == ',' || allFiles[scanPos + 1] == 0)
			{
				if(allFiles[scanPos + 1] == 0)
				{
					scanPos ++;
				}
				else
				{
					allFiles[scanPos] = 0;
				}
				if (deleteFile[0] != 0)
				{
					int i = 10;
					myError = NULL;
					pass = KAL_FALSE;
					for (pos = storage_len; deleteFile[pos] != 0; pos++)
					{
						if (deleteFile[pos]=='_')
						{
							pass = KAL_TRUE;
							break;
						}
					}
					if (pass)
					{
						if(strcmp(deleteFile + strlen(deleteFile) - 3, ".db") == 0)
						{
							pass = KAL_FALSE;
						}
					}
					if (!pass)
					{
						do
						{
							/* unable to delete the file cause the file system is busy */
							storageDeleteFile(&myError, deleteFile);
							kal_sleep_task(10);
							i --;
						}while (i > 0 && myError != NULL);
					}
					/*ASSERT(myError == NULL);*/
				}
				deleteFile = allFiles + scanPos + 1;
			}
			scanPos ++;
		}

		if (deleteFile[0] != 0)
		{
			int i = 10;
			myError = NULL;
			pass = KAL_FALSE;
			for (pos = storage_len; deleteFile[pos] != 0; pos++)
			{
				if (deleteFile[pos]=='_')
				{
					pass = KAL_TRUE;
					break;
				}
			}
			if (!pass)
			{
				do
				{
					/* unable to delete the file cause the file system is busy */
					storageDeleteFile(&myError, deleteFile);
					kal_sleep_task(10);
					i --;
				}while (i > 0 && myError != NULL);
			}
		}
	}
	/* Very important!!! Fix garbage files bugs */
	scanPos = 0;
	work_dir_path = work_sys_dir_path;
	allFiles = (kal_char*)getAllFilesInDir(storageName);
	if (allFiles == NULL)
		return;
	deleteFile = allFiles;
	while (allFiles[scanPos] != 0)
	{
		if (allFiles[scanPos] == ',' || allFiles[scanPos + 1] == 0)
		{
			if(allFiles[scanPos + 1] == 0)
			{
				scanPos ++;
			}
			else
			{
				allFiles[scanPos] = 0;
			}

			if (deleteFile[0] != 0)
			{

⌨️ 快捷键说明

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