Ejemplo n.º 1
0
void fxWriteBreakpoints(txMachine* the)
{
	char *breakpoints;
	FskFile fref = NULL;
	txSlot *aBreakpoint = NULL;
	FskInt64 size = 0;

	FskECMAScriptGetDebug(NULL, &breakpoints, NULL);

	if ((NULL == breakpoints) || (0 == *breakpoints)) goto bail;

	FskFileCreate(breakpoints);

	if (kFskErrNone != FskFileOpen(breakpoints, kFskFilePermissionReadWrite, &fref))
		goto bail;

	if (kFskErrNone != FskFileSetSize(fref, &size))
		goto bail;

	while (true) {
		char aPath[1024], aLine[32];
		aBreakpoint = fxGetNextBreakpoint(the, aBreakpoint, aPath, aLine);
		if (NULL == aBreakpoint)
			break;
		FskFileWrite(fref, FskStrLen(aPath), (void *)aPath, NULL);
		FskFileWrite(fref, 1, (void *)"\t", NULL);
		FskFileWrite(fref, FskStrLen(aLine), (void *)aLine, NULL);
		FskFileWrite(fref, 1, (void *)"\n", NULL);
	}

bail:
	FskFileClose(fref);
}
Ejemplo n.º 2
0
FskErr FskCopyFile(char *src, char *dst) {
    char buf[4096];
    UInt32 amt, amtWrt;
    int doit=0;
    FskFileInfo info, infoSrc;
    FskFile srcFref = NULL, dstFref = NULL;
    FskErr err = kFskErrNone;

    if (kFskErrFileNotFound == FskFileGetFileInfo(dst, &info)) {
        FskAndroidFilesPrintfDebug("dst: %s not found\n", dst);
        doit = 1;
    }
    else if (kFskErrNone == FskFileGetFileInfo(src, &infoSrc)) {
        if (infoSrc.filesize != info.filesize) {
            FskAndroidFilesPrintfDebug("src size: %d, dstSize: %d\n", infoSrc.filesize, info.filesize);
            doit = 1;
        }
    }

    if (doit) {
        FskAndroidFilesPrintfDebug("Need to copy it over.\n");
        err = FskFileOpen(src, kFskFilePermissionReadOnly, &srcFref);
		BAIL_IF_ERR(err);
        err = FskFileCreate(dst);
		BAIL_IF_ERR(err);
        err = FskFileOpen(dst, kFskFilePermissionReadWrite, &dstFref);
		BAIL_IF_ERR(err);
        while (kFskErrNone == err) {
            err = FskFileRead(srcFref, 4096, buf, &amt);
            BAIL_IF_ERR(err);
            if (0 >= amt)
                break;
            while (amt) {
                err = FskFileWrite(dstFref, amt, buf, &amtWrt);
				BAIL_IF_ERR(err);
                amt -= amtWrt;
            }
        }
        err = FskFileClose(dstFref);
        BAIL_IF_ERR(err);
		dstFref = NULL;
        err = FskFileClose(srcFref);
        BAIL_IF_ERR(err);
		srcFref = NULL;
    }

bail:
	if(kFskErrEndOfFile == err){
		err = kFskErrNone;
	}
	if(dstFref)
		FskFileClose(dstFref);
	if(srcFref)
		FskFileClose(srcFref);
	return err;
}
Ejemplo n.º 3
0
void unpackAndroid() {
	char * src, *dst, buf[4096];
	int doit=0;
	UInt32 amt, amtWrt;
	FskFileInfo info, infoSrc;
	FskFile srcFref, dstFref;
	FskErr err;

	dst = FskStrDoCat(gAndroidCallbacks->getStaticDataDirCB(), "ca-bundle.crt");
	src = FskStrDoCat(gAndroidCallbacks->getStaticAppDirCB(), "/res/raw/kinoma.jet/ca-bundle.crt");
	if (kFskErrFileNotFound == FskFileGetFileInfo(dst, &info)) {
		fprintf(stderr, "dst: %s not found\n", dst);
		doit = 1;
	}
	else if (kFskErrNone == FskFileGetFileInfo(src, &infoSrc)) {
		if (infoSrc.filesize != info.filesize) {
			fprintf(stderr, "src size: %lld, dstSize: %lld\n", infoSrc.filesize, info.filesize);
			doit = 1;
		}
	}
	if (doit) {
		fprintf(stderr, "Need to copy it over.\n");
		err = FskFileOpen(src, kFskFilePermissionReadOnly, &srcFref);
		if (err) fprintf(stderr, "open %s failed %d\n", src, err);
		err = FskFileCreate(dst);
		if (err) fprintf(stderr, "create %s failed %d\n", dst, err);
		err = FskFileOpen(dst, kFskFilePermissionReadWrite, &dstFref);
		if (err) fprintf(stderr, "open %s failed %d\n", dst, err);
		while (kFskErrNone == err) {
			err = FskFileRead(srcFref, 4096, buf, &amt);
			if (err) fprintf(stderr, "read %s (%lu bytes) failed %d\n", src, amt, err);
			if (0 >= amt)
				break;
			while (amt) {
				err = FskFileWrite(dstFref, amt, buf, &amtWrt);
				if (err) fprintf(stderr, "write %s (%lu bytes) failed %d\n", dst, amt, err);
				amt -= amtWrt;
			}
		}
		err = FskFileClose(dstFref);
		if (err) fprintf(stderr, "close %s failed %d\n", src, err);
		err = FskFileClose(srcFref);
		if (err) fprintf(stderr, "close %s failed %d\n", src, err);
	}
	FskMemPtrDispose(src);
	FskMemPtrDispose(dst);
}
Ejemplo n.º 4
0
void KPR_system_set_backGesture(xsMachine *the)
{
	FskErr err = kFskErrNone;
	char* path = NULL;
	char* pathName = NULL;
	FskFile file = NULL;
	char* data = xsToString(xsArg(0));
	xsIntegerValue size = FskStrLen(data);
#if MINITV
	pathName = TOUCHD_CONF;
	// system("/etc/init.d/touchd.sh stop");
#else
	bailIfError(FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, true, NULL, &path));
	pathName = FskStrDoCat(path, "touchd.conf");
	bailIfNULL(pathName);
#endif
	err = FskFileOpen(pathName, kFskFilePermissionReadWrite, &file);
	if (kFskErrFileNotFound == err) {
		bailIfError(FskFileCreate(pathName));
		err = FskFileOpen(pathName, kFskFilePermissionReadWrite, &file);
	}
	else {
		FskInt64 zero = 0;
		err = FskFileSetSize(file, &zero);
	}
	bailIfError(err);
	bailIfError(FskFileWrite(file, size, data, NULL));
bail:
	FskFileClose(file);
#if MINITV
    int pipe = open(TOUCH_PIPE, O_WRONLY | O_NONBLOCK);
    if (pipe >= 0) {
    	char data = 1;
    	write(pipe, &data, 1);
        close(pipe);
    }
	// system("/etc/init.d/touchd.sh start");
#endif
	if (path) {
		FskMemPtrDispose(path);
		FskMemPtrDispose(pathName);
	}
	xsThrowIfFskErr(err);
}
Ejemplo n.º 5
0
FskErr FskTextFreeTypeInstallFonts(char* fontsPath, char* defaultFont)
{
	FskErr err = kFskErrNone;
	FskTextEngine fte;
	char *fromDirectory = NULL;
	char* fromPath = NULL;
	FskDirectoryIterator iterator = NULL;
	char *name = NULL;
	UInt32 type;
#if TARGET_OS_ANDROID
	char *toDirectory = NULL;
	char* toPath = NULL;
	FskFileInfo itemInfo;
	FskFileMapping map = NULL;
	unsigned char *data;
	FskInt64 dataSize;
	FskFile file = NULL;
#endif	
	err = FskTextEngineNew(&fte, NULL);
	if (err) goto bail;
	fromDirectory = FskEnvironmentDoApply(FskStrDoCopy(fontsPath));
	if (!fromDirectory) { err = kFskErrMemFull; goto bail; }
#if TARGET_OS_ANDROID
	if (!FskStrCompareWithLength(fromDirectory, "/data/app/", 10)) {
		err = FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, false, NULL, &toDirectory);
		if (err) goto bail;
	}
#endif
	err = FskDirectoryIteratorNew(fromDirectory, &iterator, 0);
	if (err) goto bail;
	while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &type)) {
		if (type == kFskDirectoryItemIsFile) {
			fromPath = FskStrDoCat(fromDirectory, name);
			if (!fromPath) { err = kFskErrMemFull; goto bail; }
			FskDebugStr("from %s", fromPath);
#if TARGET_OS_ANDROID
			if (toDirectory) {
				toPath = FskStrDoCat(toDirectory, name);
				FskDebugStr("to %s", toPath);
				if (kFskErrNone != FskFileGetFileInfo(toPath, &itemInfo)) {
					err = FskFileMap(fromPath, &data, &dataSize, 0, &map);
					if (err) goto bail;
					err = FskFileCreate(toPath);
					if (err) goto bail;
					err = FskFileOpen(toPath, kFskFilePermissionReadWrite, &file);
					if (err) goto bail;
					err = FskFileWrite(file, dataSize, data, NULL);
					if (err) goto bail;
					FskFileClose(file);
					file = NULL;
					FskFileDisposeMap(map);
					map = NULL;
				}
				FskDebugStr("add %s", toPath);
				FskTextAddFontFile(fte, toPath);
				FskMemPtrDisposeAt(&toPath);
			}
			else
#endif
				FskTextAddFontFile(fte, fromPath);
			FskMemPtrDisposeAt(&fromPath);
		}
		FskMemPtrDisposeAt(&name);
	}
#if TARGET_OS_ANDROID
	if (gAndroidCallbacks->getModelInfoCB) {
		char* osVersion;
		gAndroidCallbacks->getModelInfoCB(NULL, &osVersion, NULL, NULL, NULL);
		if ((FskStrStr(osVersion, "android.5") == osVersion) // for KPR applications
			|| (FskStrStr(osVersion, "5.") == osVersion)) {  // for tests
			BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fonts.xml"));
		}
		if ((FskStrStr(osVersion, "android.4") == osVersion) // for KPR applications
			|| (FskStrStr(osVersion, "4.") == osVersion)) {  // for tests
			BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/system_fonts.xml"));
			err = FskFTAddMapping("/vendor/etc/fallback_fonts.xml");
			if (err != kFskErrFileNotFound) BAIL(err);
			BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fallback_fonts.xml"));
		}
		else {
			defaultFont = "Droid Sans";
			BAIL_IF_ERR(err = FskFTAddMapping(NULL));
		}
	}
#endif
	if (defaultFont)
		FskTextDefaultFontSet(fte, defaultFont);
bail:
#if TARGET_OS_ANDROID
	if (file)
		FskFileClose(file);
	if (map)
		FskFileDisposeMap(map);
	FskMemPtrDispose(toPath);
	FskMemPtrDispose(toDirectory);
#endif
	FskMemPtrDispose(name);
	FskDirectoryIteratorDispose(iterator);
	FskMemPtrDispose(fromPath);
	FskMemPtrDispose(fromDirectory);
	FskTextEngineDispose(fte);
	return err;
}
Ejemplo n.º 6
0
FskErr mp3ReaderExtract(FskMediaReader reader, void *readerState, FskMediaReaderTrack *track, UInt32 *infoCount, FskMediaReaderSampleInfo *info, unsigned char **dataOut)
{
	mp3Reader state = readerState;
	FskErr err = kFskErrNone;
	UInt32 spaceInOutput;
	unsigned char *data;
	FskMediaReaderSampleInfo lastInfo = NULL;
	UInt32 infoCountFree;
#if SUPPORT_MP3_LOG_TO_FILE
	UInt32 outputSize;
#endif

	spaceInOutput = (state->mi.bitrate * 128)  / 2;		// about half a second
	if (spaceInOutput < 4096)
		spaceInOutput = 4096;
#if SUPPORT_MP3_LOG_TO_FILE
	outputSize = spaceInOutput;
#endif

	*track = &state->track;
	*infoCount = 0;
	*info = NULL;

	infoCountFree = state->mi.frequency >> 11;		// quick divide by 2048... allocate enough entries for about half a second of frames
	err = FskMemPtrNew(infoCountFree * sizeof(FskMediaReaderSampleInfoRecord), (FskMemPtr*)(void*)info);
	if (err) return err;

	err = FskMemPtrNew(spaceInOutput + kFskDecompressorSlop, (FskMemPtr *)&data);
	if (err) {
		FskMemPtrDisposeAt((void **)info);
		return err;
	}

	*dataOut = data;

	while (0 != infoCountFree) {
		if (state->hasEndTime && (state->atTime >= state->endTime)) {
			if (0 == *infoCount )
				err = kFskErrEndOfFile;
			goto bail;
		}

		if ((state->readBufferEnd - state->readBufferPtr) < 6) {
			err = mp3RefillReadBuffer(state, 6);
			if (err) goto bail;
		}

		if ((0xff == state->readBufferPtr[0]) && (0xe0 == (state->readBufferPtr[1] & 0xe0))) {
			DIDLMusicItemRecord mi;

			mi.doExtendedParsing = 0;
			if (true == (state->doHeaderParse)(state->readBufferPtr, &mi)) {
				if (spaceInOutput < mi.frameLength)
					goto bail;

				if ((state->readBufferEnd - state->readBufferPtr) < (SInt32)mi.frameLength) {
					err = mp3RefillReadBuffer(state, mi.frameLength);
					if (err) goto bail;
				}

				// When starting from a new location, make extra sure we're really sitting on a valid frame,
				// by validating the next frame.
				if (state->resync) {
					if (state->readBufferEnd - (state->readBufferPtr + mi.frameLength) > 6) {
						DIDLMusicItemRecord mi2;
						UInt8 *nextFramePtr = state->readBufferPtr + mi.frameLength;
						if ((0xff != nextFramePtr[0]) || (0xe0 != (nextFramePtr[1] & 0xe0))) {
							state->readBufferPtr += 1;
							continue;
						}

						mi2.doExtendedParsing = 0;
						if (false == (state->doHeaderParse)(nextFramePtr, &mi2)) {
							state->readBufferPtr += 1;
							continue;
						}
					}

					state->resync = false;
				}

				if (kFskAudioFormatAACADTS == mi.codec) {	// skip adts header to get to raw aac frame. @@ if frame Count != 1 this isn't going to work
					mi.frameLength -= 7;
					state->readBufferPtr += 7;
				}

				if ((NULL != lastInfo) && (lastInfo->sampleDuration = mi.samplesPerFrame) && (lastInfo->sampleSize == mi.frameLength))
					lastInfo->samples += 1;
				else {
					lastInfo = &(*info)[*infoCount];
					*infoCount += 1;
					infoCountFree -= 1;

					FskMemSet(lastInfo, 0, sizeof(FskMediaReaderSampleInfoRecord));
					lastInfo->samples = 1;
					lastInfo->sampleSize = mi.frameLength;
					lastInfo->flags = kFskImageFrameTypeSync;
					lastInfo->decodeTime = state->atTime;
					lastInfo->sampleDuration = mi.samplesPerFrame;
					lastInfo->compositionTime = -1;
				}

				FskMemMove(data, state->readBufferPtr, mi.frameLength);
				data += mi.frameLength;
				state->readBufferPtr += mi.frameLength;
				spaceInOutput -= mi.frameLength;

				state->atTime += mi.samplesPerFrame;

				continue;
			}
		}

		state->readBufferPtr += 1;
		state->resync = true;
	}

bail:
	if (kFskErrNone != err) {
		if ((kFskErrNeedMoreTime == err) || (kFskErrEndOfFile == err)) {
			if (0 != *infoCount)
				err = kFskErrNone;
		}

		if (kFskErrNone != err) {
			FskMemPtrDisposeAt((void **)info);
			FskMemPtrDisposeAt((void **)dataOut);
			*infoCount = 0;
		}
	}

#if SUPPORT_MP3_LOG_TO_FILE
	if (kFskErrNone == err) {
		if (NULL == gFref) {
			FskFileDelete("c:/dump.mp3");
			FskFileCreate("c:/dump.mp3");
			FskFileOpen("c:/dump.mp3", kFskFilePermissionReadWrite, &gFref);
		}
		FskFileWrite(gFref, outputSize - spaceInOutput, *dataOut, NULL);
	}
#endif

	return err;
}
Ejemplo n.º 7
0
void fxWriteProfileFile(txMachine* the, void* theBuffer, txInteger theSize)
{
	if (the->profileFile)
		FskFileWrite(the->profileFile, theSize, theBuffer, NULL);
}
Ejemplo n.º 8
0
void fxWriteAddressAutomatic(txMachine* the)
{
	/* write debugAddress and debugAutomatic to a file... */
#if TARGET_OS_ANDROID
	char *folder = NULL;
	char *file = FskStrDoCat(folder, "/sdcard/debug.txt");
	{
#else
	char *folder;
	if (kFskErrNone == FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, true, NULL, &folder)) {
		char *file = FskStrDoCat(folder, "debug.txt");
#endif
		FskFile fref;

		FskFileDelete(file);
		FskFileCreate(file);
		if (kFskErrNone == FskFileOpen(file, kFskFilePermissionReadWrite, &fref)) {
			char *data = FskStrDoCat(debugAddress, debugAutomatic ? "\n1\n" : "\n0\n");
			if (data) {
				FskFileWrite(fref, FskStrLen(data), data, NULL);
				FskFileClose(fref);
				FskMemPtrDispose(data);
			}
		}
	}
}

#endif /* !KPR_CONFIG */ 

void fxReadBreakpoints(txMachine* the)
{
	char *breakpoints;
	FskMemPtr file = NULL;
	FskInt64 fileSize;
	char *p;

	FskECMAScriptGetDebug(NULL, &breakpoints, NULL);

	if ((NULL == breakpoints) || (0 == *breakpoints)) goto bail;

	if (kFskErrNone != FskFileLoad(breakpoints, &file, &fileSize))
		goto bail;

	p = (char *)file;
	while (true) {
		char *path = p;
		char *line = FskStrChr(p, '\t');
		char *cr;

		if (NULL == line)
			break;
		cr = FskStrChr(line, '\n');
		if (NULL == cr)
			break;
		*line++ = 0;
		*cr = 0;

		fxSetBreakpoint(the, path, line);

		p = cr + 1;
	}

bail:
	FskMemPtrDispose(file);
}
Ejemplo n.º 9
0
char *FskUUIDGetForKey(const char *key)
{
	char *uuidStr;
	FskUUIDRecord uuid;
	char *uuidCachePath = NULL, *prefFolder;
	FskFile fref;

	if (kFskErrNone == FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, true, NULL, &prefFolder)) {
		uuidCachePath = FskStrDoCat(prefFolder, "fskuuidcache.txt");
		FskMemPtrDispose(prefFolder);
	}

	// load the cache
	if (NULL == gUUIDCache) {
		char *uuidCache;
		FskInt64 cacheSize;

		gUUIDCache = FskAssociativeArrayNew();

		if ((NULL != uuidCachePath) && (kFskErrNone == FskFileLoad(uuidCachePath, (unsigned char **)(void *)&uuidCache, &cacheSize))) {
			char *p = uuidCache;
			while (true) {
				char *uuid = p;
				char *mykey = FskStrChr(p, '\t');
				char *cr;

				if (NULL == mykey)
					break;
				cr = FskStrChr(mykey, '\n');
				if (NULL == cr)
					break;
				*mykey++ = 0;
				*cr = 0;

				FskAssociativeArrayElementSetString(gUUIDCache, mykey, uuid);

				p = cr + 1;
			}
			FskMemPtrDispose(uuidCache);
		}
	}

	// check the cache
	uuidStr = FskAssociativeArrayElementGetString(gUUIDCache, key);
	if (uuidStr) {
		FskMemPtrDispose(uuidCachePath);
		return uuidStr;
	}

	// not in cache
	FskUUIDCreate(&uuid);
	uuidStr = FskUUIDtoString_844412(&uuid);

	FskAssociativeArrayElementSetString(gUUIDCache, key, uuidStr);

	FskMemPtrDispose(uuidStr);

	// flush cache
	FskFileDelete(uuidCachePath);
	FskFileCreate(uuidCachePath);
	if (kFskErrNone == FskFileOpen(uuidCachePath, kFskFilePermissionReadWrite, &fref)) {
		FskAssociativeArrayIterator iterate = FskAssociativeArrayIteratorNew(gUUIDCache);
		char tab = '\t', cr = '\n';

		while (iterate) {
			FskFileWrite(fref, FskStrLen(iterate->value), iterate->value, NULL);
			FskFileWrite(fref, 1, &tab, NULL);
			FskFileWrite(fref, FskStrLen(iterate->name), iterate->name, NULL);
			FskFileWrite(fref, 1, &cr, NULL);

			iterate = FskAssociativeArrayIteratorNext(iterate);
		}
		FskFileClose(fref);
	}

	FskMemPtrDispose(uuidCachePath);

	return FskAssociativeArrayElementGetString(gUUIDCache, key);	// caller doesn't have to dispose
}