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; }
Boolean MCDispatch::openenv(const char *sname, const char *env, char **outpath, IO_handle &stream, uint4 offset) { if ((env = MCS_getenv(env)) != NULL) { char *pathstring = strclone(env); char *fullpath = new char[strlen(env) + strlen(sname) + 2]; char *eptr = pathstring; while (eptr != NULL) { char *path = eptr; eptr = strchr(eptr, ENV_SEPARATOR); if (eptr != NULL) *eptr++ = '\0'; #ifdef _WIN32 sprintf(fullpath, "%s\\%s", path, sname); #else sprintf(fullpath, "%s/%s", path, sname); #endif if ((stream = MCS_open(fullpath, IO_READ_MODE, True, False, offset)) != NULL) { delete pathstring; *outpath = fullpath; return True; } } delete pathstring; delete fullpath; } return False; }
static bool load_custom_font_file_into_buffer_from_path(const char *p_path, char *&r_buffer, uint32_t &r_size) { bool t_success; t_success = true; char *t_font_path; t_font_path = nil; if (t_success) t_success = MCCStringFormat(t_font_path, "%s/%s%s", MCcmd, s_font_folder, p_path); if (t_success) t_success = MCS_exists(t_font_path, true); IO_handle t_font_file_handle; t_font_file_handle = nil; if (t_success) { t_font_file_handle = MCS_open(t_font_path, IO_READ_MODE, false, false, 0); t_success = t_font_file_handle != nil; } uint32_t t_file_size; t_file_size = 0; char *t_buffer; t_buffer = nil; if (t_success) { t_file_size = MCS_fsize(t_font_file_handle); t_success = MCMemoryAllocate(t_file_size + 1, t_buffer); } if (t_success) { IO_stat t_read_stat; uint32_t t_bytes_read; t_bytes_read = 0; while (t_success && t_bytes_read < t_file_size) { uint32_t t_count; t_count = t_file_size - t_bytes_read; t_read_stat = MCS_read(t_buffer + t_bytes_read, 1, t_count, t_font_file_handle); t_bytes_read += t_count; t_success = (t_read_stat == IO_NORMAL || (t_read_stat == IO_EOF && t_bytes_read == t_file_size)); } } if (t_success) { r_buffer = t_buffer; r_size = t_file_size; } else /*UNCHECKED */ MCMemoryDelete(t_buffer); /*UNCHECKED */ MCCStringFree(t_font_path); return t_success; }
Boolean MCDispatch::openstartup(const char *sname, char **outpath, IO_handle &stream) { if (enginedir == nil) return False; uint4 l = MCU_max((uint4)strlen(enginedir), (uint4)strlen(startdir)) + strlen(sname) + 11; char *fullpath = new char[l]; sprintf(fullpath, "%s/%s", startdir, sname); if ((stream = MCS_open(fullpath, IO_READ_MODE, True, False, 0)) != NULL) { *outpath = fullpath; return True; } sprintf(fullpath, "%s/%s", enginedir, sname); if ((stream = MCS_open(fullpath, IO_READ_MODE, True, False, 0)) != NULL) { *outpath = fullpath; return True; } delete fullpath; return False; }
void MCS_downloadurl(MCObject *p_target, const char *p_url, const char *p_file) { bool t_success = true; char *t_processed = nil; MCObjectHandle *t_obj = nil; IO_handle t_output = nil; MCSDownloadUrlState t_state; t_output = MCS_open(p_file, IO_WRITE_MODE, False, False, 0); if (t_output == nil) { MCresult -> sets("can't open that file"); return; } t_success = MCSystemProcessUrl(p_url, kMCSystemUrlOperationStrip, t_processed); if (t_success) t_success = nil != (t_obj = p_target->gethandle()); if (t_success) { t_state . url = t_processed; t_state . status = kMCSystemUrlStatusNone; t_state . object = t_obj; t_state . output = t_output; t_state . length = 0; t_state . total = 0; t_success = MCSystemLoadUrl(t_processed, MCS_downloadurl_callback, &t_state); } if (t_success) { while(t_state . status != kMCSystemUrlStatusFinished && t_state . status != kMCSystemUrlStatusError) MCscreen -> wait(60.0, True, True); if (t_state . status == kMCSystemUrlStatusFinished) MCresult -> clear(); } MCCStringFree(t_processed); if (t_output != nil) MCS_close(t_output); if (t_obj != nil) t_obj->Release(); }
char *MCVideoClip::getfile() { if (frames != NULL) { char *tmpfile = strclone(MCS_tmpnam()); IO_handle tstream; if ((tstream = MCS_open(tmpfile, IO_WRITE_MODE, False, False, 0)) == NULL) { delete tmpfile; return NULL; } IO_stat stat = IO_write(frames, sizeof(int1), size, tstream); MCS_close(tstream); if (stat != IO_NORMAL) { MCS_unlink(tmpfile); delete tmpfile; return NULL; } return tmpfile; } return NULL; }
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; }
Exec_stat exec(MCExecPoint& ep) { bool t_success; t_success = true; char *t_old_filename; t_old_filename = nil; if (t_success && m_old_file -> eval(ep) == ES_NORMAL) t_old_filename = ep . getsvalue() . clone(); else t_success = false; char *t_new_filename; t_new_filename = nil; if (t_success && m_new_file -> eval(ep) == ES_NORMAL) t_new_filename = ep . getsvalue() . clone(); else t_success = false; char *t_patch_filename; t_patch_filename = nil; if (t_success && m_patch_file -> eval(ep) == ES_NORMAL) t_patch_filename = ep . getsvalue() . clone(); else t_success = false; IO_handle t_old_handle; t_old_handle = nil; if (t_success) { t_old_handle = MCS_open(t_old_filename, IO_READ_MODE, False, False, 0); if (t_old_handle == nil) t_success = false; } IO_handle t_new_handle; t_new_handle = nil; if (t_success) { t_new_handle = MCS_open(t_new_filename, IO_READ_MODE, False, False, 0); if (t_new_handle == nil) t_success = false; } IO_handle t_patch_handle; t_patch_handle = nil; if (t_success) { t_patch_handle = MCS_open(t_patch_filename, IO_WRITE_MODE, False, False, 0); if (t_patch_handle == nil) t_success = false; } if (t_success) { InputStream t_new_stream, t_old_stream; OutputStream t_patch_stream; t_new_stream . handle = t_new_handle; t_old_stream . handle = t_old_handle; t_patch_stream . handle = t_patch_handle; t_success = MCBsDiffBuild(&t_old_stream, &t_new_stream, &t_patch_stream); } if (t_success) MCresult -> clear(); else MCresult -> sets("patch building failed"); if (t_patch_handle != nil) MCS_close(t_patch_handle); if (t_new_handle != nil) MCS_close(t_new_handle); if (t_old_handle != nil) MCS_close(t_old_handle); delete t_patch_filename; delete t_new_filename; delete t_old_filename; return ES_NORMAL; }
void exec_ctxt(MCExecContext &ctxt) { bool t_success; t_success = true; MCAutoStringRef t_old_filename; if (!ctxt . EvalExprAsStringRef(m_old_file, EE_INTERNAL_BSDIFF_BADOLD, &t_old_filename)) return; MCAutoStringRef t_new_filename; if (!ctxt . EvalExprAsStringRef(m_new_file, EE_INTERNAL_BSDIFF_BADNEW, &t_new_filename)) return; MCAutoStringRef t_patch_filename; if (!ctxt . EvalExprAsStringRef(m_patch_file, EE_INTERNAL_BSDIFF_BADPATCH, &t_patch_filename)) return; IO_handle t_old_handle; t_old_handle = nil; if (t_success) { t_old_handle = MCS_open(*t_old_filename, kMCOpenFileModeRead, False, False, 0); if (t_old_handle == nil) t_success = false; } IO_handle t_new_handle; t_new_handle = nil; if (t_success) { t_new_handle = MCS_open(*t_new_filename, kMCOpenFileModeRead, False, False, 0); if (t_new_handle == nil) t_success = false; } IO_handle t_patch_handle; t_patch_handle = nil; if (t_success) { t_patch_handle = MCS_open(*t_patch_filename, kMCOpenFileModeWrite, False, False, 0); if (t_patch_handle == nil) t_success = false; } if (t_success) { InputStream t_new_stream, t_old_stream; OutputStream t_patch_stream; t_new_stream . handle = t_new_handle; t_old_stream . handle = t_old_handle; t_patch_stream . handle = t_patch_handle; t_success = MCBsDiffBuild(&t_old_stream, &t_new_stream, &t_patch_stream); } if (t_success) ctxt . SetTheResultToEmpty(); else ctxt . SetTheResultToCString("patch building failed"); if (t_patch_handle != nil) MCS_close(t_patch_handle); if (t_new_handle != nil) MCS_close(t_new_handle); if (t_old_handle != nil) MCS_close(t_old_handle); }
void MCStack::effectrect(const MCRectangle& p_area, Boolean& r_abort) { // Get the list of effects. MCEffectList *t_effects = MCcur_effects; MCcur_effects = NULL; // If the window isn't opened or hasn't been attached (plugin) or if we have no // snapshot to use, this is a no-op. if (!opened || !haswindow() || m_snapshot == nil) { while(t_effects != NULL) { MCEffectList *t_effect; t_effect = t_effects; t_effects = t_effects -> next; delete t_effect; } return; } // Mark the stack as being in an effect. state |= CS_EFFECT; // Lock messages while the effect is happening. Boolean t_old_lockmessages; t_old_lockmessages = MClockmessages; MClockmessages = True; // Calculate the area of interest. MCRectangle t_effect_area; t_effect_area = curcard -> getrect(); t_effect_area . y = getscroll(); t_effect_area . height -= t_effect_area . y; t_effect_area = MCU_intersect_rect(t_effect_area, p_area); // IM-2013-08-21: [[ ResIndependence ]] Scale effect area to device coords // Align snapshot rect to device pixels // IM-2013-09-30: [[ FullscreenMode ]] Use stack transform to get device coords MCGAffineTransform t_transform; t_transform = getdevicetransform(); // MW-2013-10-29: [[ Bug 11330 ]] Make sure the effect area is cropped to the visible // area. t_effect_area = MCRectangleGetTransformedBounds(t_effect_area, getviewtransform()); t_effect_area = MCU_intersect_rect(t_effect_area, MCU_make_rect(0, 0, view_getrect() . width, view_getrect() . height)); // IM-2014-01-24: [[ HiDPI ]] scale effect region to backing surface coords MCGFloat t_scale; t_scale = view_getbackingscale(); MCRectangle t_device_rect, t_user_rect; t_device_rect = MCRectangleGetScaledBounds(t_effect_area, t_scale); t_user_rect = MCRectangleGetTransformedBounds(t_device_rect, MCGAffineTransformInvert(t_transform)); // IM-2013-08-29: [[ RefactorGraphics ]] get device height for CoreImage effects // IM-2013-09-30: [[ FullscreenMode ]] Use view rect to get device height uint32_t t_device_height; t_device_height = floor(view_getrect().height * t_scale); // Make a region of the effect area // IM-2013-08-29: [[ ResIndependence ]] scale effect region to device coords MCRegionRef t_effect_region; t_effect_region = nil; /* UNCHECKED */ MCRegionCreate(t_effect_region); /* UNCHECKED */ MCRegionSetRect(t_effect_region, t_effect_area); #ifndef FEATURE_PLATFORM_PLAYER #if defined(FEATURE_QUICKTIME) // MW-2010-07-07: Make sure QT is only loaded if we actually are doing an effect if (t_effects != nil) if (!MCdontuseQTeffects) if (!MCtemplateplayer -> isQTinitted()) MCtemplateplayer -> initqt(); #endif #endif // Lock the screen to prevent any updates occuring until we want them. MCRedrawLockScreen(); // By default, we have not aborted. r_abort = False; MCGImageRef t_initial_image; t_initial_image = MCGImageRetain(m_snapshot); while(t_effects != nil) { uint32_t t_duration; t_duration = MCU_max(1, MCeffectrate / (t_effects -> speed - VE_VERY)); if (t_effects -> type == VE_DISSOLVE) t_duration *= 2; uint32_t t_delta; t_delta = 0; // Create surface at effect_area size. // Render into surface based on t_effects -> image MCGImageRef t_final_image = nil; // If this isn't a plain effect, then we must fetch first and last images. if (t_effects -> type != VE_PLAIN) { // Render the final image. MCGContextRef t_context = nil; // IM-2014-05-20: [[ GraphicsPerformance ]] Create opaque context for snapshot /* UNCHECKED */ MCGContextCreate(t_device_rect.width, t_device_rect.height, false, t_context); MCGContextTranslateCTM(t_context, -t_device_rect.x, -t_device_rect.y); // IM-2013-10-03: [[ FullscreenMode ]] Apply device transform to context MCGContextConcatCTM(t_context, t_transform); // Configure the context. MCGContextClipToRect(t_context, MCRectangleToMCGRectangle(t_user_rect)); // Render an appropriate image switch(t_effects -> image) { case VE_INVERSE: { MCContext *t_old_context = nil; /* UNCHECKED */ t_old_context = new MCGraphicsContext(t_context); curcard->draw(t_old_context, t_user_rect, false); delete t_old_context; MCGContextSetFillRGBAColor(t_context, 1.0, 1.0, 1.0, 1.0); MCGContextSetBlendMode(t_context, kMCGBlendModeDifference); MCGContextAddRectangle(t_context, MCRectangleToMCGRectangle(t_user_rect)); MCGContextFill(t_context); } break; case VE_BLACK: MCGContextSetFillRGBAColor(t_context, 0.0, 0.0, 0.0, 1.0); MCGContextAddRectangle(t_context, MCRectangleToMCGRectangle(t_user_rect)); MCGContextFill(t_context); break; case VE_WHITE: MCGContextSetFillRGBAColor(t_context, 1.0, 1.0, 1.0, 1.0); MCGContextAddRectangle(t_context, MCRectangleToMCGRectangle(t_user_rect)); MCGContextFill(t_context); break; case VE_GRAY: MCGContextSetFillRGBAColor(t_context, 0.5, 0.5, 0.5, 1.0); MCGContextAddRectangle(t_context, MCRectangleToMCGRectangle(t_user_rect)); MCGContextFill(t_context); break; default: { MCContext *t_old_context = nil; /* UNCHECKED */ t_old_context = new MCGraphicsContext(t_context); curcard->draw(t_old_context, t_user_rect, false); delete t_old_context; } } /* UNCHECKED */ MCGContextCopyImage(t_context, t_final_image); MCGContextRelease(t_context); } MCStackEffectContext t_context; t_context.delta = t_delta; t_context.duration = t_duration; t_context.effect = t_effects; t_context.effect_area = t_device_rect; t_context.initial_image = t_initial_image; t_context.final_image = t_final_image; // MW-2011-10-20: [[ Bug 9824 ]] Make sure dst point is correct. // Initialize the destination with the start image. view_platform_updatewindowwithcallback(t_effect_region, MCStackRenderInitial, &t_context); // If there is a sound, then start playing it. if (t_effects -> sound != NULL) { MCAudioClip *acptr; MCNewAutoNameRef t_sound; /* UNCHECKED */ MCNameCreate(t_effects->sound, &t_sound); if ((acptr = (MCAudioClip *)getobjname(CT_AUDIO_CLIP, *t_sound)) == NULL) { IO_handle stream; if ((stream = MCS_open(t_effects->sound, kMCOpenFileModeRead, True, False, 0)) != NULL) { acptr = new MCAudioClip; acptr->setdisposable(); if (!acptr->import(t_effects->sound, stream)) { delete acptr; acptr = NULL; } MCS_close(stream); } } if (acptr != NULL) { MCU_play_stop(); MCacptr = acptr; MCU_play(); #ifndef FEATURE_PLATFORM_AUDIO if (MCacptr != NULL) MCscreen->addtimer(MCacptr, MCM_internal, PLAY_RATE); #endif } if (MCscreen->wait((real8)MCsyncrate / 1000.0, False, True)) { r_abort = True; break; } } // Initialize CoreImage of QTEffects if needed. if (t_effects -> type != VE_PLAIN) { MCAutoPointer<char> t_name; /* UNCHECKED */ MCStringConvertToCString(t_effects -> name, &t_name); #ifdef _MAC_DESKTOP // IM-2013-08-29: [[ ResIndependence ]] use scaled effect rect for CI effects if (t_effects -> type == VE_UNDEFINED && MCCoreImageEffectBegin(*t_name, t_initial_image, t_final_image, t_device_rect, t_device_height, t_effects -> arguments)) t_effects -> type = VE_CIEFFECT; else #endif #ifdef FEATURE_QUICKTIME_EFFECTS // IM-2013-08-29: [[ ResIndependence ]] use scaled effect rect for QT effects if (t_effects -> type == VE_UNDEFINED && MCQTEffectBegin(t_effects -> type, *t_name, t_effects -> direction, t_initial_image, t_final_image, t_device_rect)) t_effects -> type = VE_QTEFFECT; #else ; #endif } // Run effect // Now perform the effect loop, but only if there is something to do. if (t_effects -> type != VE_PLAIN || old_blendlevel != blendlevel) { // Calculate timing parameters. double t_start_time; t_start_time = 0.0; for(;;) { t_context.delta = t_delta; Boolean t_drawn = False; view_platform_updatewindowwithcallback(t_effect_region, MCStackRenderEffect, &t_context); // Now redraw the window with the new image. // if (t_drawn) { MCscreen -> sync(getw()); } // Update the window's blendlevel (if needed) if (old_blendlevel != blendlevel) { float t_fraction = float(t_delta) / t_duration; setopacity(uint1((old_blendlevel * 255 + (float(blendlevel) - old_blendlevel) * 255 * t_fraction) / 100)); } // If the start time is zero, then start counting from here. if (t_start_time == 0.0) t_start_time = MCS_time(); // If we've reached the end of the transition, we are done. if (t_delta == t_duration) { #ifdef _ANDROID_MOBILE // MW-2011-12-12: [[ Bug 9907 ]] Make sure we let the screen sync at this point MCscreen -> wait(0.01, False, False); #endif break; } // Get the time now. double t_now; t_now = MCS_time(); // Compute the new delta value. uint32_t t_new_delta; t_new_delta = (uint32_t)ceil((t_now - t_start_time) * 1000.0); // If the new value is same as the old, then advance one step. if (t_new_delta == t_delta) t_delta = t_new_delta + 1; else t_delta = t_new_delta; // If the new delta is beyond the end point, set it to the end. if (t_delta > t_duration) t_delta = t_duration; // Wait until the next boundary, making sure we break for no reason // other than abort. if (MCscreen -> wait((t_start_time + (t_delta / 1000.0)) - t_now, False, False)) r_abort = True; // If we aborted, we render the final step and are thus done. if (r_abort) t_delta = t_duration; } } #ifdef _MAC_DESKTOP if (t_effects -> type == VE_CIEFFECT) MCCoreImageEffectEnd(); else #endif #ifdef FEATURE_QUICKTIME_EFFECTS if (t_effects -> type == VE_QTEFFECT) MCQTEffectEnd(); #endif // Free initial surface. MCGImageRelease(t_initial_image); // initial surface becomes final surface. t_initial_image = t_final_image; t_final_image = nil; // Move to the next effect. MCEffectList *t_current_effect; t_current_effect = t_effects; t_effects = t_effects -> next; delete t_current_effect; } // Make sure the pixmaps are freed and any dangling effects // are cleaned up. if (t_effects != NULL) { /* OVERHAUL - REVISIT: error cleanup needs revised */ MCGImageRelease(t_initial_image); // MCGSurfaceRelease(t_final_image); while(t_effects != NULL) { MCEffectList *t_current_effect; t_current_effect = t_effects; t_effects = t_effects -> next; delete t_current_effect; } } MCRegionDestroy(t_effect_region); MCGImageRelease(m_snapshot); m_snapshot = nil; m_snapshot = t_initial_image; // Unlock the screen. MCRedrawUnlockScreen(); // Unlock messages. MClockmessages = t_old_lockmessages; // Turn off effect mode. state &= ~CS_EFFECT; // The stack's blendlevel is now the new one. old_blendlevel = blendlevel; // Finally, mark the affected area of the stack for a redraw. dirtyrect(p_area); }
IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCString &fname) { if (MCModeCheckSaveStack(sptr, fname) != IO_NORMAL) return IO_ERROR; char *linkname; if (fname.getlength() != 0) linkname = fname.clone(); else if ((linkname = strclone(sptr->getfilename())) == NULL) { MCresult->sets("stack does not have a filename"); return IO_ERROR; } if (linkname == NULL) { MCresult->sets("can't open stack file, bad path"); return IO_ERROR; } if (MCS_noperm(linkname)) { MCresult->sets("can't open stack file, no permission"); delete linkname; return IO_ERROR; } char *oldfiletype = MCfiletype; MCfiletype = MCstackfiletype; char *backup = new char[strlen(linkname) + 2]; strcpy(backup, linkname); strcat(backup, "~"); MCS_unlink(backup); if (MCS_exists(linkname, True) && !MCS_backup(linkname, backup)) { MCresult->sets("can't open stack backup file"); MCfiletype = oldfiletype; delete linkname; delete backup; return IO_ERROR; } IO_handle stream; if ((stream = MCS_open(linkname, IO_WRITE_MODE, True, False, 0)) == NULL) { MCresult->sets("can't open stack file"); cleanup(stream, linkname, backup); MCfiletype = oldfiletype; return IO_ERROR; } MCfiletype = oldfiletype; MCString errstring = "Error writing stack (disk full?)"; // MW-2012-03-04: [[ StackFile5500 ]] Work out what header to emit, and the size. const char *t_header; uint32_t t_header_size; if (MCstackfileversion >= 5500) t_header = newheader5500, t_header_size = 8; else if (MCstackfileversion >= 2700) t_header = newheader, t_header_size = 8; else t_header = header, t_header_size = HEADERSIZE; if (IO_write(t_header, sizeof(char), t_header_size, stream) != IO_NORMAL || IO_write_uint1(CHARSET, stream) != IO_NORMAL) { MCresult->sets(errstring); cleanup(stream, linkname, backup); return IO_ERROR; } if (IO_write_uint1(OT_NOTHOME, stream) != IO_NORMAL || IO_write_string(NULL, stream) != IO_NORMAL) { // was stackfiles MCresult->sets(errstring); cleanup(stream, linkname, backup); return IO_ERROR; } // MW-2012-02-22; [[ NoScrollSave ]] Adjust the rect by the current group offset. MCgroupedobjectoffset . x = 0; MCgroupedobjectoffset . y = 0; MCresult -> clear(); if (sptr->save(stream, 0, false) != IO_NORMAL || IO_write_uint1(OT_END, stream) != IO_NORMAL) { if (MCresult -> isclear()) MCresult->sets(errstring); cleanup(stream, linkname, backup); return IO_ERROR; } MCS_close(stream); uint2 oldmask = MCS_umask(0); uint2 newmask = ~oldmask & 00777; if (oldmask & 00400) newmask &= ~00100; if (oldmask & 00040) newmask &= ~00010; if (oldmask & 00004) newmask &= ~00001; MCS_umask(oldmask); MCS_chmod(linkname, newmask); if (sptr->getfilename() != NULL && !strequal(linkname, sptr->getfilename())) MCS_copyresourcefork(sptr->getfilename(), linkname); else if (sptr -> getfilename() != NULL) MCS_copyresourcefork(backup, linkname); sptr->setfilename(linkname); if (backup != NULL) { MCS_unlink(backup); delete backup; } return IO_NORMAL; }
IO_stat MCDispatch::loadfile(const char *inname, MCStack *&sptr) { IO_handle stream; char *openpath = NULL; char *fname = strclone(inname); if ((stream = MCS_open(fname, IO_READ_MODE, True, False, 0)) != NULL) if (fname[0] != PATH_SEPARATOR && fname[1] != ':') { char *curpath = MCS_getcurdir(); if (curpath[strlen(curpath) - 1] == '/') curpath[strlen(curpath) - 1] = '\0'; openpath = new char[strlen(curpath) + strlen(fname) + 2]; sprintf(openpath, "%s/%s", curpath, fname); delete curpath; } else openpath = strclone(fname); else { char *tmparray = new char[strlen(fname) + 1]; strcpy(tmparray, fname); char *tname = strrchr(tmparray, PATH_SEPARATOR); if (tname == NULL) tname = tmparray; else tname++; if ((stream = MCS_open(tname, IO_READ_MODE, True, False, 0)) != NULL) { char *curpath = MCS_getcurdir(); openpath = new char[strlen(curpath) + strlen(tname) + 2]; sprintf(openpath, "%s/%s", curpath, tname); delete curpath; } else { if (!openstartup(tname, &openpath, stream) && !openenv(tname, "MCPATH", &openpath, stream, 0) && !openenv(tname, "PATH", &openpath, stream, 0)) { char *homename; if ((homename = MCS_getenv("HOME")) != NULL) { openpath = new char[strlen(homename) + strlen(tname) + 13]; if (homename[strlen(homename) - 1] == '/') homename[strlen(homename) - 1] = '\0'; sprintf(openpath, "%s/%s", homename, tname); if ((stream = MCS_open(openpath, IO_READ_MODE, True, False, 0)) == NULL) { sprintf(openpath, "%s/stacks/%s", homename, tname); if ((stream = MCS_open(openpath, IO_READ_MODE, True, False, 0)) == NULL) { sprintf(openpath, "%s/components/%s", homename, tname); if ((stream = MCS_open(openpath, IO_READ_MODE, True, False, 0)) == NULL) { delete openpath; openpath = NULL; } } } } } } delete tmparray; } if (stream == NULL) { if (openpath != NULL) delete openpath; delete fname; return IO_ERROR; } delete fname; IO_stat stat = readfile(openpath, inname, stream, sptr); delete openpath; MCS_close(stream); return stat; }