bool MCReferencedImageRep::GetDataStream(IO_handle &r_stream) { IO_handle t_stream = nil; if (MCSecureModeCanAccessDisk()) t_stream = MCS_open(m_file_name, IO_READ_MODE, false, false, 0); // MW-2013-09-25: [[ Bug 10983 ]] Only ever try to load the rep as a url once. if (t_stream == nil && !m_url_load_attempted) { // MW-2013-09-25: [[ Bug 10983 ]] Mark the rep has having attempted url load. m_url_load_attempted = true; MCExecPoint ep(MCdefaultstackptr, nil, nil); ep.setsvalue(m_file_name); MCU_geturl(ep); if (ep.getsvalue().getlength() == 0) return false; /* UNCHECKED */ MCMemoryAllocateCopy(ep.getsvalue().getstring(), ep.getsvalue().getlength(), m_url_data); m_url_data_size = ep.getsvalue().getlength(); t_stream = MCS_fakeopen(MCString((char*)m_url_data, m_url_data_size)); } if (t_stream != nil) r_stream = t_stream; return t_stream != nil; }
bool MCVectorImageRep::CalculateGeometry(uindex_t &r_width, uindex_t &r_height) { bool t_success = true; IO_handle t_stream = nil; t_success = nil != (t_stream = MCS_fakeopen(MCString((char*)m_data, m_size))); if (t_success) t_success = MCImageGetMetafileGeometry(t_stream, r_width, r_height); if (t_stream != nil) MCS_close(t_stream); return t_success; }
bool MCImageDecode(const uint8_t *p_data, uindex_t p_size, MCImageFrame *&r_frames, uindex_t &r_frame_count) { bool t_success = true; IO_handle t_stream = nil; t_success = nil != (t_stream = MCS_fakeopen(MCString((const char*)p_data, p_size))); if (t_success) t_success = MCImageDecode(t_stream, r_frames, r_frame_count); if (t_stream != nil) MCS_close(t_stream); return t_success; }
bool MCVectorImageRep::LoadHeader(uindex_t &r_width, uindex_t &r_height, uint32_t &r_frame_count) { bool t_success = true; MCAutoDataRef t_data; IO_handle t_stream = nil; if (t_success) t_success = nil != (t_stream = MCS_fakeopen((const char *)m_data, m_size)); if (t_success) t_success = MCImageGetMetafileGeometry(t_stream, r_width, r_height); if (t_success) r_frame_count = 1; if (t_stream != nil) MCS_close(t_stream); return t_success; }
bool MCReferencedImageRep::GetDataStream(IO_handle &r_stream) { IO_handle t_stream = nil; if (MCSecureModeCanAccessDisk()) t_stream = MCS_open(m_file_name, kMCOpenFileModeRead, false, false, 0); if (t_stream == nil) { // MW-2013-09-25: [[ Bug 10983 ]] Only ever try to load the rep as a url once. if (!m_url_load_attempted) { // MW-2013-09-25: [[ Bug 10983 ]] Mark the rep has having attempted url load. m_url_load_attempted = true; MCExecContext ctxt(MCdefaultstackptr, nil, nil); MCAutoValueRef t_data; MCU_geturl(ctxt, m_file_name, &t_data); if (ctxt.HasError() || MCValueIsEmpty(*t_data)) return false; MCAutoDataRef t_dataref; /* UNCHECKED */ ctxt . ConvertToData(*t_data, &t_dataref); /* UNCHECKED */ MCMemoryAllocateCopy(MCDataGetBytePtr(*t_dataref), MCDataGetLength(*t_dataref), m_url_data); m_url_data_size = MCDataGetLength(*t_dataref); } // IM-2014-09-30: [[ Bug 13501 ]] If we already have the url data then make sure we use it. if (m_url_data != nil) t_stream = MCS_fakeopen((const char *)m_url_data, m_url_data_size); } if (t_stream != nil) r_stream = t_stream; return t_stream != nil; }
bool MCVariableValue::decode(const MCString& p_value) { IO_handle t_stream_handle; t_stream_handle = MCS_fakeopen(p_value); if (t_stream_handle == NULL) return false; MCObjectInputStream *t_stream = nil; t_stream = new MCObjectInputStream(t_stream_handle, p_value . getlength()); if (t_stream == NULL) { MCS_close(t_stream_handle); return false; } IO_stat t_stat; t_stat = IO_NORMAL; uint8_t t_type; t_stat = t_stream -> ReadU8(t_type); if (t_stat == IO_NORMAL) { switch(t_type) { case kMCEncodedValueTypeUndefined: clear(); break; case kMCEncodedValueTypeEmpty: assign_empty(); break; case kMCEncodedValueTypeString: { uint32_t t_length; t_stat = t_stream -> ReadU32(t_length); if (t_stat == IO_NORMAL) { char *t_value; t_value = new char[t_length]; if (t_value != NULL) assign_buffer(t_value, t_length); else t_stat = IO_ERROR; } } break; case kMCEncodedValueTypeNumber: { double t_value; t_stat = t_stream -> ReadFloat64(t_value); if (t_stat == IO_NORMAL) assign_real(t_value); } break; case kMCEncodedValueTypeArray: t_stat = loadarray(*t_stream, false); break; default: t_stat = IO_ERROR; break; } } delete t_stream; MCS_close(t_stream_handle); set_dbg_changed(true); return t_stat == IO_NORMAL; }
void MCArraysEvalArrayDecode(MCExecContext& ctxt, MCDataRef p_encoding, MCArrayRef& r_array) { bool t_success; t_success = true; IO_handle t_stream_handle; t_stream_handle = nil; if (t_success) { t_stream_handle = MCS_fakeopen(MCDataGetBytePtr(p_encoding), MCDataGetLength(p_encoding)); if (t_stream_handle == nil) t_success = false; } uint8_t t_type; if (t_success) if (IO_read_uint1(&t_type, t_stream_handle) != IO_NORMAL) t_success = false; // AL-2014-05-01: [[ Bug 11989 ]] If the type is 'empty' then just return the empty array. if (t_success && t_type == kMCEncodedValueTypeEmpty) { r_array = MCValueRetain(kMCEmptyArray); return; } // AL-2014-05-15: [[ Bug 12203 ]] Check initial byte for version 7.0 encoded array. bool t_legacy; t_legacy = t_type < kMCEncodedValueTypeArray; MCArrayRef t_array; t_array = nil; if (t_success) t_success = MCArrayCreateMutable(t_array); if (t_legacy) { if (t_success) if (MCS_putback(t_type, t_stream_handle) != IO_NORMAL) t_success = false; MCObjectInputStream *t_stream; t_stream = nil; if (t_success) { t_stream = new MCObjectInputStream(t_stream_handle, MCDataGetLength(p_encoding), false); if (t_stream == nil) t_success = false; } if (t_success) if (t_stream -> ReadU8(t_type) != IO_NORMAL) t_success = false; if (t_success) if (MCArrayLoadFromStreamLegacy(t_array, *t_stream) != IO_NORMAL) t_success = false; delete t_stream; } else { if (t_success) if (IO_read_valueref_new((MCValueRef &)t_array, t_stream_handle) != IO_NORMAL) t_success = false; } MCS_close(t_stream_handle); if (t_success) { r_array = t_array; return; } MCValueRelease(t_array); ctxt . Throw(); }
bool MCDispatch::isolatedsend(const char *p_stack_data, uint32_t p_stack_data_length, const char *p_message, MCParameter *p_parameters) { Boolean t_old_allow_interrupts; MCStack *t_old_stacks; MCObjectList *t_old_frontscripts, *t_old_backscripts; MCStack **t_old_using; uint2 t_old_nusing; MCStack *t_old_defaultstack; MCStack *t_old_staticdefaultstack; MCStack *t_old_topstackptr; t_old_allow_interrupts = MCallowinterrupts; t_old_stacks = stacks; t_old_frontscripts = MCfrontscripts; t_old_backscripts = MCbackscripts; t_old_using = MCusing; t_old_nusing = MCnusing; t_old_defaultstack = MCdefaultstackptr; t_old_staticdefaultstack = MCstaticdefaultstackptr; t_old_topstackptr = MCtopstackptr; MCallowinterrupts = False; stacks = nil; MCnusing = 0; MCusing = nil; MCbackscripts = nil; MCfrontscripts = nil; // Load the stack MCExecPoint ep; ep . setstaticbytes(p_stack_data, p_stack_data_length); MCDecompress::do_decompress(ep, 0, 0); bool t_success; MCStack *t_stack; IO_handle t_stream; t_success = false; t_stack = nil; t_stream = MCS_fakeopen(ep . getsvalue()); if (MCdispatcher -> readfile(NULL, NULL, t_stream, t_stack) == IO_NORMAL) { MCdefaultstackptr = MCstaticdefaultstackptr = MCtopstackptr = stacks; MCAutoNameRef t_message_name; /* UNCHECKED */ t_message_name . CreateWithCString(p_message); if (t_stack -> message(t_message_name, p_parameters, True, True, False) == ES_NORMAL) t_success = true; destroystack(t_stack, True); } MCS_close(t_stream); memset((void *)ep . getsvalue() . getstring(), 0, ep . getsvalue() . getlength()); ep . clear(); MCtopstackptr = t_old_topstackptr; MCstaticdefaultstackptr = t_old_staticdefaultstack; MCdefaultstackptr = t_old_defaultstack; MCnusing = t_old_nusing; MCusing = t_old_using; MCbackscripts = t_old_backscripts; MCfrontscripts = t_old_frontscripts; stacks = t_old_stacks; MCallowinterrupts = t_old_allow_interrupts; return t_success; }
IO_stat MCDispatch::startup(void) { IO_stat stat; MCStack *sptr; // set up image cache before the first stack is opened MCCachedImageRep::init(); startdir = MCS_getcurdir(); enginedir = strclone(MCcmd); char *eptr; eptr = strrchr(enginedir, PATH_SEPARATOR); if (eptr != NULL) *eptr = '\0'; else *enginedir = '\0'; MCExecPoint ep; ep . setstaticbytes(MCstartupstack, MCstartupstack_length); MCDecompress::do_decompress(ep, 0, 0); IO_handle stream = MCS_fakeopen(ep . getsvalue()); if ((stat = MCdispatcher -> readfile(NULL, NULL, stream, sptr)) != IO_NORMAL) { MCS_close(stream); return stat; } MCS_close(stream); memset((void *)ep . getsvalue() . getstring(), 0, ep . getsvalue() . getlength()); ep . clear(); // Temporary fix to make sure environment stack doesn't get lost behind everything. #if defined(_MACOSX) ProcessSerialNumber t_psn = { 0, kCurrentProcess }; SetFrontProcess(&t_psn); #elif defined(_WINDOWS) SetForegroundWindow(((MCScreenDC *)MCscreen) -> getinvisiblewindow()); #endif MCenvironmentactive = True; sptr -> setfilename(strclone(MCcmd)); MCdefaultstackptr = MCstaticdefaultstackptr = stacks; { MCdefaultstackptr -> setextendedstate(true, ECS_DURING_STARTUP); MCdefaultstackptr -> message(MCM_start_up, nil, False, True); MCdefaultstackptr -> setextendedstate(false, ECS_DURING_STARTUP); } if (!MCquit) { MCresult -> fetch(ep); ep . appendchar('\0'); if (ep . getsvalue() . getlength() == 1) { sptr -> open(); MCImage::init(); X_main_loop(); MCresult -> fetch(ep); ep . appendchar('\0'); if (ep . getsvalue() . getlength() == 1) return IO_NORMAL; } if (sptr -> getscript() != NULL) memset(sptr -> getscript(), 0, strlen(sptr -> getscript())); destroystack(sptr, True); MCtopstackptr = NULL; MCquit = False; MCenvironmentactive = False; send_relaunch(); sptr = findstackname(ep . getsvalue() . getstring()); if (sptr == NULL && (stat = loadfile(ep . getsvalue() . getstring(), sptr)) != IO_NORMAL) return stat; } if (!MCquit) { // OK-2007-11-13 : Bug 5525, after opening the IDE engine, the allowInterrupts should always default to false, // regardless of what the environment stack may have set it to. MCallowinterrupts = true; sptr -> setparent(this); MCdefaultstackptr = MCstaticdefaultstackptr = stacks; send_startup_message(false); if (!MCquit) sptr -> open(); } return IO_NORMAL; }
bool MCResidentImageRep::GetDataStream(IO_handle &r_stream) { r_stream = MCS_fakeopen(MCString((char*)m_data, m_size)); return r_stream != nil; }