void VJSStream::do_BinaryStream(VJSParms_callStaticFunction& ioParms) { VFile* file = ioParms.RetainFileParam( 1); bool forwrite = ioParms.GetBoolParam( 2, L"Write", L"Read"); if (file != NULL) { VError err = VE_OK; if (forwrite) { if (!file->Exists()) err = file->Create(); } VFileStream* stream = new VFileStream(file); if (err == VE_OK) { if (forwrite) err = stream->OpenWriting(); else err = stream->OpenReading(); } if (err == VE_OK) { ioParms.ReturnValue(VJSStream::CreateInstance(ioParms.GetContextRef(), stream)); } else { delete stream; } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); ReleaseRefCountable( &file); }
void VJSDirectory::_save(VJSParms_callStaticFunction& ioParms, CUAGDirectory* inDirectory) { VFile* dest = ioParms.RetainFileParam(1); if (dest != nil || ioParms.CountParams() == 0) ioParms.ReturnBool(inDirectory->Save(dest) == VE_OK); else { XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); ioParms.ReturnBool(false); } QuickReleaseRefCountable(dest); }
void VJSGlobalClass::do_LoadText(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { bool okloaded = false; VFile* file = ioParms.RetainFileParam(1); if (file != nil) { if (file->Exists()) { VFileStream inp(file); VError err = inp.OpenReading(); if (err == VE_OK) { CharSet defaultCharSet = VTC_UTF_8; sLONG xcharset = 0; if (ioParms.GetLongParam(2, &xcharset) && xcharset != 0) defaultCharSet = (CharSet)xcharset; inp.GuessCharSetFromLeadingBytes(defaultCharSet ); inp.SetCarriageReturnMode( eCRM_NATIVE ); VString s; err = inp.GetText(s); if (err == VE_OK) { ioParms.ReturnString(s); okloaded = true; } inp.CloseReading(); } } file->Release(); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); if (!okloaded) ioParms.ReturnNullValue(); }
void VJSGlobalClass::do_include( VJSParms_callStaticFunction& inParms, VJSGlobalObject *inGlobalObject) { // EvaluateScript() uses NULL (this is default) as inThisObject argument. // This works fine currently, but would it be better (if any problem) to pass global (application) object instead? // See WAK0074064. VFile* file = inParms.RetainFileParam(1, false); if (file != NULL) { bool newlyRegistered = inGlobalObject->RegisterIncludedFile( file); // sc 15/06/2010 the file must be registered if (inParms.GetBoolParam(2,"refresh","auto") || newlyRegistered) { inParms.GetContext().EvaluateScript( file, NULL, inParms.GetExceptionRefPointer()); } file->Release(); } else { VString pathname; if (inParms.IsStringParam(1) && inParms.GetStringParam( 1, pathname)) { VFolder* folder = inGlobalObject->GetRuntimeDelegate()->RetainScriptsFolder(); if (folder != NULL) { file = new VFile( *folder, pathname, FPS_POSIX); bool newlyRegistered = inGlobalObject->RegisterIncludedFile( file); // sc 15/06/2010 the file must be registered if (inParms.GetBoolParam(2,"refresh","auto") || newlyRegistered) { inParms.GetContext().EvaluateScript( file, NULL, inParms.GetExceptionRefPointer()); } ReleaseRefCountable( &file); } ReleaseRefCountable( &folder); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); } }
void VJSGlobalClass::do_SaveText(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { VString s; if (ioParms.IsStringParam(1)) { if (ioParms.GetStringParam(1, s)) { VFile* file = ioParms.RetainFileParam(2); if (file != nil) { VError err = VE_OK; if (file->Exists()) err = file->Delete(); if (err == VE_OK) err = file->Create(); if (err == VE_OK) { CharSet defaultCharSet = VTC_UTF_8; sLONG xcharset = 0; if (ioParms.GetLongParam(3, &xcharset) && xcharset != 0) defaultCharSet = (CharSet)xcharset; VFileStream inp(file); err = inp.OpenWriting(); if (err == VE_OK) { inp.SetCharSet(defaultCharSet); inp.PutText(s); inp.CloseWriting(); } } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "2"); } } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1"); }
void VJSGlobalClass::do_loadImage(VJSParms_callStaticFunction& ioParms, VJSGlobalObject*) { bool okloaded = false; #if !VERSION_LINUX // Postponed Linux Implementation ! VFile* file = ioParms.RetainFileParam(1); if (file != nil) { if (file->Exists()) { XBOX::VPicture* pict = new XBOX::VPicture(*file, false); /* VJSPictureContainer* pictContains = new VJSPictureContainer(pict, true, ioParms.GetContextRef()); ioParms.ReturnValue(VJSImage::CreateInstance(ioParms.GetContextRef(), pictContains)); pictContains->Release(); */ if (pict != NULL) { okloaded = true; ioParms.ReturnVValue(*pict); delete pict; } } file->Release(); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); #endif if (!okloaded) ioParms.ReturnNullValue(); }