Пример #1
0
void KPR_system_saveFile(xsMachine* the)
{
	FskErr err;
	xsIntegerValue argc = xsToInteger(xsArgc);
	xsStringValue name = NULL;
	xsStringValue prompt = NULL;
	xsStringValue initialPath = NULL;
	xsStringValue path = NULL;
	xsStringValue url = NULL;
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindResult(xsArg(0), xsID_name))
			name = xsToStringCopy(xsResult);
		if (xsFindResult(xsArg(0), xsID_prompt))
			prompt = xsToStringCopy(xsResult);
		if (xsFindResult(xsArg(0), xsID_url))
			KprURLToPath(xsToString(xsResult), &initialPath);
	}
	err = FskFileChooseSave(name, prompt, initialPath, &path);
	if ((kFskErrNone == err) && (NULL != path)) {
		KprPathToURL(path, &url);
		(void)xsCallFunction1(xsArg(1), xsNull, xsString(url));
	}
	FskMemPtrDispose(url);
	FskMemPtrDispose(path);
	FskMemPtrDispose(initialPath);
	FskMemPtrDispose(prompt);
	FskMemPtrDispose(name);
}
Пример #2
0
void KPR_system_alert(xsMachine* the)
{
	int argc = xsToInteger(xsArgc);
	MSGBOXPARAMSW params;
	xsStringValue string;
	xsIntegerValue result;
	xsVars(1);
	params.cbSize = sizeof(params);
	params.hwndOwner = NULL;
	params.hInstance = FskMainGetHInstance();
	params.lpszText = NULL;
	params.lpszCaption = xsStringToWideString("Kinoma Code");
	params.dwStyle = MB_ICONSTOP;
	params.dwContextHelpId = 0;
	params.lpfnMsgBoxCallback = NULL;
	params.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindString(xsArg(0), xsID_type, &string)) {
			if (!FskStrCompare(string, "about"))
				params.dwStyle = MB_ICONINFORMATION;
			else if (!FskStrCompare(string, "stop"))
				params.dwStyle = MB_ICONSTOP;
			else if (!FskStrCompare(string, "note"))
				params.dwStyle = MB_ICONEXCLAMATION;
		}
		if (xsFindResult(xsArg(0), xsID_prompt)) {
			xsVar(0) = xsResult;
		}
		if (xsFindResult(xsArg(0), xsID_info)) {
			xsVar(0) = xsCall1(xsVar(0), xsID("concat"), xsString("\n\n"));
			xsVar(0) = xsCall1(xsVar(0), xsID("concat"), xsResult);
		}
		params.lpszText = xsStringToWideString(xsToString(xsVar(0)));
		if (xsFindResult(xsArg(0), xsID_buttons)) {
			if (xsIsInstanceOf(xsResult, xsArrayPrototype)) {
				xsIntegerValue c = xsToInteger(xsGet(xsResult, xsID_length));
				if (c == 3)
					params.dwStyle |= MB_YESNOCANCEL;
				else if (c == 2)
					params.dwStyle |= MB_OKCANCEL;
				else
					params.dwStyle |= MB_OK;
			}
		}
	}
	result = MessageBoxIndirectW(&params);
	if (params.lpszText)
		CoTaskMemFree((LPVOID *)params.lpszText);
	if (params.lpszCaption)
		CoTaskMemFree((LPVOID *)params.lpszCaption);
	if ((argc > 1) && xsTest(xsArg(1)))
		(void)xsCallFunction1(xsArg(1), xsNull, ((result == IDYES) || (result == IDOK)) ? xsTrue : (result == IDNO) ? xsFalse : xsUndefined);
}
Пример #3
0
void KprDebugMachineEchoItem(KprDebugMachine self, int theView, char* path, int line, char* name, char* value)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			if (path)
				xsNewHostProperty(xsVar(2), xsID("path"), xsString(path), xsDefault, xsDontScript);
			if (line >= 0)
				xsNewHostProperty(xsVar(2), xsID("line"), xsInteger(line), xsDefault, xsDontScript);
			if (name)
				xsNewHostProperty(xsVar(2), xsID("name"), xsString(name), xsDefault, xsDontScript);
			if (value)
				xsNewHostProperty(xsVar(2), xsID("value"), xsString(value), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #4
0
void KprDebugMachineLoadView(KprDebugMachine self, int theView, char* thePath, int theLine)
{
	FskErr err = kFskErrNone;
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;
//	FskFileInfo info;
//	FskFileMapping map = NULL;
//	FskDebugStr("%s: %d - %s:%d", __FUNCTION__, theView, thePath, theLine);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	xsVar(0) = xsAccess(debug->behavior);
	
	if (xsFindResult(xsVar(0), xsID("onMachineFileChanged"))) {
		(void)xsCallFunction5(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsNull, thePath ? xsString(thePath) : xsNull, xsInteger(theLine));
	}
//	if (kFskErrNone == FskFileGetFileInfo(thePath, &info) && (kFskDirectoryItemIsFile == info.filetype)) {
//		unsigned char *data;
//		FskInt64 size;
//		BAIL_IF_ERR(err = FskFileMap(thePath, &data, &size, 0, &map));
//		xsVar(0) = xsAccess(debug->behavior);
//		
//		if (xsFindResult(xsVar(0), xsID("onMachineFileChanged"))) {
//			(void)xsCallFunction5(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsNull, xsString(thePath), xsInteger(theLine));
//		}
//	}
bail:
//	FskFileDisposeMap(map);
	xsThrowIfFskErr(err);
}
Пример #5
0
void Zeroconf_browser_callback(KprZeroconfBrowser self, char* function, KprZeroconfServiceInfo service)
{
	xsBeginHostSandboxCode(self->the, self->code);
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	xsVars(3);
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			xsVar(1) = xsNewInstanceOf(xsObjectPrototype);
			xsSet(xsVar(1), xsID("name"), xsString(service->name));
			xsSet(xsVar(1), xsID("type"), xsString(service->type));
			if (service->host)
				xsSet(xsVar(1), xsID("host"), xsString(service->host));
			if (service->ip) {
				xsSet(xsVar(1), xsID("ip"), xsString(service->ip));
				xsSet(xsVar(1), xsID("port"), xsInteger(service->port));
			}
			if (service->txt) {
				char* txt = service->txt;
				UInt32 position = 0, size = FskStrLen(txt);
				UInt32 length = 0;
				xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
				xsSet(xsVar(1), xsID("txt"), xsVar(2));
				length = txt[position++] & 0xFF;
				while ((position + length) <= size) {
					char end;
					char* equal;
					if (!length) break;
					end = txt[position + length];
					txt[position + length] = 0;
					equal = FskStrChr(txt + position, '=');
					if (equal) {
						*equal = 0;
						xsSet(xsVar(2), xsID(txt + position), xsString(equal + 1));
						*equal = '=';
					}
					txt[position + length] = end;
					position += length;
					length = txt[position++] & 0xFF;
				}
			}
			if (xsFindResult(xsVar(0), xsID(function))) {
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
		}
		xsCatch {
		}
	}
bail:
	xsEndHostSandboxCode();
}
Пример #6
0
void Zeroconf_advertisement_callback(KprZeroconfAdvertisement self, char* function)
{
	xsBeginHostSandboxCode(self->the, self->code);
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	xsVars(2);
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			xsVar(1) = xsAccess(self->slot);
			if (xsFindResult(xsVar(0), xsID(function))) {
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
		}
		xsCatch {
		}
	}
bail:
	xsEndHostSandboxCode();
}
Пример #7
0
void KprDebugMachineCallbackView(KprDebugMachine machine, char* function, int view)
{
	KprDebug self = machine->debug;
	xsMachine* the = self->the;
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			if (xsFindResult(xsVar(0), xsID(function))) {
				xsVar(1) = xsGet(xsVar(0), xsID(machine->address));
				xsDelete(xsVar(0), xsID(machine->address));
				(void)xsCallFunction3(xsResult, xsVar(0), xsString(machine->address), xsInteger(view), xsVar(1));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #8
0
void KprDebugMachineSetViewTitle(KprDebugMachine self, int theView, char* theTitle)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

//	FskDebugStr("%s: %d - %s", __FUNCTION__, theView, theTitle);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			if (xsFindResult(xsVar(0), xsID("onMachineViewTitle")))
				(void)xsCallFunction3(xsResult, xsVar(0), xsString(self->address), xsInteger(theView), xsString(theTitle));
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #9
0
void KPR_host_quitting(xsMachine* the)
{
	KprContainer container = xsGetHostData(xsThis);
	KprContent content = container->first;
	KprScriptBehavior self = (KprScriptBehavior)content->behavior;
#if SUPPORT_INSTRUMENTATION
	void* params[2] = { self, "xsID_onQuitting" };
	FskInstrumentedItemSendMessageDebug(content, kprInstrumentedContentCallBehavior, params);
#endif
    if (self) {
        xsBeginHostSandboxCode(self->the, self->code);
        {
 			xsVars(2);
			xsVar(0) = xsAccess(self->slot);
			if (xsFindResult(xsVar(0), xsID_onQuitting)) {
				xsVar(1) = kprContentGetter(content);
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
        }
        xsEndHostSandboxCode();
    }
}
Пример #10
0
void KprDebugMachineCallbackText(KprDebugMachine machine, char* function, int view, char* text)
{
	KprDebug self = machine->debug;
	xsMachine* the = self->the;
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			if (xsFindResult(xsVar(0), xsID(function))) {
				if (view >= 0)
					(void)xsCallFunction3(xsResult, xsVar(0), xsString(machine->address), xsInteger(view), xsString(text));
				else if (text)
					(void)xsCallFunction2(xsResult, xsVar(0), xsString(machine->address), xsString(text));
				else
					(void)xsCallFunction1(xsResult, xsVar(0), xsString(machine->address));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #11
0
void KprDebugMachineEchoProperty(KprDebugMachine self, int theView, int column, char* flags, char* name, char* value)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			xsNewHostProperty(xsVar(2), xsID("column"), xsInteger(column), xsDefault, xsDontScript);
			flags[4] = 0;
			xsNewHostProperty(xsVar(2), xsID("flags"), xsString(flags + 1), xsDefault, xsDontScript);
			if (flags[0] == ' ')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), xsDefault, xsDontScript);
			else if (flags[0] == '+')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(1), xsDefault, xsDontScript);
			else if (flags[0] == '-')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(2), xsDefault, xsDontScript);
			else
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), xsDefault, xsDontScript);
			if (name)
				xsNewHostProperty(xsVar(2), xsID("name"), xsString(name), xsDefault, xsDontScript);
			if (value)
				xsNewHostProperty(xsVar(2), xsID("value"), xsString(value), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #12
0
void KprDebugMachineEchoView(KprDebugMachine self, int theView, char* theName, char* theValue)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			xsNewHostProperty(xsVar(2), xsID("name"), xsString(theName), xsDefault, xsDontScript);
			xsNewHostProperty(xsVar(2), xsID("value"), xsString(theValue), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Пример #13
0
void KPR_shell_execute(xsMachine* the)
{
	xsStringValue application = NULL;
	xsStringValue command = NULL;
	xsStringValue directory = NULL;
	xsStringValue environment = NULL;
	xsStringValue string;
	xsIntegerValue length;
	KprShellExec exec = NULL;
	STARTUPINFO si;
	SECURITY_ATTRIBUTES sa; 
	xsVars(5);
	xsTry {
		application = getenv("COMSPEC");
		if (!application)
			xsThrowIfFskErr(kFskErrOperationFailed);
		
		string = xsToString(xsArg(0));
		length = FskStrLen(string) + 1;
		xsThrowIfFskErr(FskMemPtrNew(3 + length, &command));
		memcpy(command, "/c ", 3);
		memcpy(command + 3, string, length);

		if (xsFindString(xsArg(1), xsID_directory, &string)) {
			length = FskStrLen(string) + 1;
			xsThrowIfFskErr(FskMemPtrNew(length, &directory));
			memcpy(directory, string, length);
		}
		if (xsFindResult(xsArg(1), xsID_environment)) {
			xsIntegerValue total = 0, length;
			xsVar(1) = xsEnumerate(xsResult);
			for (;;) {
				xsVar(2) = xsCall0(xsVar(1), xsID("next"));
				xsVar(3) = xsGet(xsVar(2), xsID("done"));
				if (xsTest(xsVar(3)))
					break;
				xsVar(3) = xsGet(xsVar(2), xsID("value"));
				xsVar(4) = xsGetAt(xsResult, xsVar(3));
				total += FskStrLen(xsToString(xsVar(3)));
				total++;
				total += FskStrLen(xsToString(xsVar(4)));
				total++;
			}
			total++;
			xsThrowIfFskErr(FskMemPtrNew(total, &environment));
			total = 0;
			xsVar(1) = xsEnumerate(xsResult);
			for (;;) {
				xsVar(2) = xsCall0(xsVar(1), xsID("next"));
				xsVar(3) = xsGet(xsVar(2), xsID("done"));
				if (xsTest(xsVar(3)))
					break;
				xsVar(3) = xsGet(xsVar(2), xsID("value"));
				xsVar(4) = xsGetAt(xsResult, xsVar(3));
				string = xsToString(xsVar(3));
				length = FskStrLen(string);
				memcpy(environment + total, string, length);
				total += length;
				environment[total++] = '=';
				string = xsToString(xsVar(4));
				length = FskStrLen(string);
				memcpy(environment + total, string, length);
				total += length;
				environment[total++] = 0;
			}
			environment[total++] = 0;
		}
		
		xsThrowIfFskErr(FskMemPtrNewClear(sizeof(KprShellExecRecord), &exec));
		xsVar(0) = xsNewHostObject(KPR_shell_execute_destructor);
		exec->the = the;
		exec->slot = xsVar(0);
		xsSetHostData(xsVar(0), exec);
		
		xsResult = xsNewHostFunction(KPR_shell_execute_cancel, 0);
		xsNewHostProperty(xsVar(0), xsID_cancel, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		if (xsFindResult(xsArg(1), xsID_callback)) {
			xsNewHostProperty(xsVar(0), xsID_callback, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		else {
			xsNewHostProperty(xsVar(0), xsID_callback, xsNull, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		if (xsFindResult(xsArg(1), xsID_stderr)) {
			xsNewHostProperty(xsVar(0), xsID_stderr, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		else {
			xsNewHostProperty(xsVar(0), xsID_stderr, xsNull, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		if (xsFindResult(xsArg(1), xsID_stdout)) {
			xsNewHostProperty(xsVar(0), xsID_stdout, xsResult, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		else {
			xsNewHostProperty(xsVar(0), xsID_stdout, xsNull, xsDefault, xsDontDelete | xsDontEnum | xsDontSet);
		}
		
		sa.nLength = sizeof(SECURITY_ATTRIBUTES); 
		sa.bInheritHandle = TRUE; 
		sa.lpSecurityDescriptor = NULL; 
		if (!CreatePipe(&(exec->hReadPipe), &(exec->hWritePipe), &sa, 0))
			xsThrowIfFskErr(kFskErrOperationFailed);
		if (!SetHandleInformation(exec->hReadPipe, HANDLE_FLAG_INHERIT, 0))
			xsThrowIfFskErr(kFskErrOperationFailed);
		ZeroMemory(&si, sizeof(si));
		si.cb = sizeof(STARTUPINFO); 
		si.hStdError = exec->hWritePipe;
		si.hStdOutput = exec->hWritePipe;
		si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
		si.dwFlags = STARTF_USESTDHANDLES;
		if (!CreateProcess(application, command, NULL, NULL, TRUE, CREATE_NO_WINDOW, environment, directory, &si, &(exec->pi)))
			xsThrowIfFskErr(kFskErrOperationFailed);
			
		xsRemember(exec->slot);
		exec->usage++;
		FskThreadPostCallback(KprHTTPGetThread(), (FskThreadCallback)KPR_shell_execute_async, exec, NULL, NULL, NULL);
		FskMemPtrDispose(environment);
		FskMemPtrDispose(directory);
		FskMemPtrDispose(command);
	}
	xsCatch {
		if (exec) {
			if (exec->pi.hProcess)
				CloseHandle(exec->pi.hProcess);
			if (exec->pi.hThread)
				CloseHandle(exec->pi.hThread);
			if (exec->hWritePipe)
				CloseHandle(exec->hWritePipe);
			if (exec->hReadPipe)
				CloseHandle(exec->hReadPipe);
			FskMemPtrDispose(exec);
		}
		FskMemPtrDispose(environment);
		FskMemPtrDispose(directory);
		FskMemPtrDispose(command);
		xsThrow(xsException);
	}
}