Ejemplo n.º 1
0
/**
 * Write the current checksum to file.
 */
void HybridMoblet::writeChecksum()
{
	// Get checksum of the file system bundle.
	int checksum = getFileUtil()->getFileSystemChecksum(1);

	// Checksum file path.
	MAUtil::String filePath = getFileUtil()->getLocalPath();
	filePath += "MoSyncFileBundleChecksum";

	// Save checksum value.
	if (checksum != 0)
	{
		char checksumBuf[128];
		sprintf(checksumBuf, "%d", checksum);
		getFileUtil()->writeTextToFile(filePath, checksumBuf);
	}
}
Ejemplo n.º 2
0
/**
 * @return true if the checksum has changed (or if the old
 * value did not exist, such as on first time load).
 */
bool HybridMoblet::checksumHasChanged()
{
	// Assume checksum has changed (or does not exist).
	bool hasChanged = true;

	// Checksum file path.
	MAUtil::String filePath = getFileUtil()->getLocalPath();
	filePath += "MoSyncFileBundleChecksum";

	// Read checksum of the file system bundle.
	int checksum = getFileUtil()->getFileSystemChecksum(1);

	// REad checksum from file and compare.
	MAUtil::String data;
	if (getFileUtil()->readTextFromFile(filePath, data))
	{
		// Read from file succeeded. Compate values.
		int existingChecksum = (int)strtol(data.c_str(), NULL, 10);
		hasChanged = checksum != existingChecksum;
	}

	return hasChanged;
}
Ejemplo n.º 3
0
	/**
	 * Loads an image from a file and returns the handle to it.
	 *
	 * @param imagePath relative path to the image file.
	 */
	MAHandle ResourceMessageHandler::loadImageResource(const char* imagePath)
	{
		if (!getFileUtil())
		{
			return 0;
		}

		// Get the current apllication directory path.
		String appPath = getFileUtil()->getAppPath();

		// Construct image path.
		char completePath[2048];
		sprintf(completePath,
				"%s%s",
				appPath.c_str(),
				imagePath);

		// Load the image and create a data handle from it.
		MAHandle imageFile = maFileOpen(completePath, MA_ACCESS_READ);
		if (imageFile < 0)
		{
			return 0;
		}

		int fileSize = maFileSize(imageFile);
		if (fileSize < 1)
		{
			return 0;
		}

		// Create buffer to hold file data.
		MAHandle fileData = maCreatePlaceholder();
		int result = maCreateData(fileData, fileSize);
		if (RES_OK != result)
		{
			maDestroyPlaceholder(fileData);
			return 0;
		}

		// Read data from file.
		result = maFileReadToData(imageFile, fileData, 0, fileSize);
		maFileClose(imageFile);
		if (result < 0)
		{
			maDestroyPlaceholder(fileData);
			return 0;
		}

		// Create image.
		MAHandle imageHandle = maCreatePlaceholder();
		result = maCreateImageFromData(
				imageHandle,
				fileData,
				0,
				maGetDataSize(fileData));
		maDestroyPlaceholder(fileData);
		if (RES_OK != result)
		{
			maDestroyPlaceholder(imageHandle);
			return 0;
		}

		// Return the handle to the loaded image.
		return imageHandle;
	}