Пример #1
0
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;
}
Пример #2
0
Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
{
	Exec_errors t_error = EE_UNDEFINED;

	Meta::cstring_value t_prompt, t_initial;

	t_error = Meta::evaluate(ep,
											folder . prompt, t_prompt, EE_ANSWER_BADQUESTION,
											folder . initial, t_initial, EE_ANSWER_BADRESPONSE);

	MCresult -> clear(False);

	// Now we have checked all parameters, we check for access.
	if (!t_error && !MCSecureModeCanAccessDisk())
		t_error = EE_DISK_NOPERM;

	if (!t_error)
	{
		unsigned int t_options = 0;
		if (sheet)
			t_options |= MCA_OPTION_SHEET;
		if (mode == AT_FOLDERS)
			t_options |= MCA_OPTION_PLURAL;

		if (MCsystemFS)
			MCA_folder(ep, p_title, t_prompt, t_initial, t_options);
		else
			t_error = exec_custom(ep, MCfsnamestring, mode == AT_FOLDER ? "folder" : "folders", 4, p_title, *t_prompt, NULL, *t_initial);

		if (ep . getsvalue() == MCnullmcstring)
			MCresult -> sets(MCcancelstring);
	}

	return t_error;
}
Пример #3
0
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;
}
Пример #4
0
static int can_access_file(const char *p_file)
{
	return MCSecureModeCanAccessDisk();
}
Пример #5
0
Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
{
	Exec_errors t_error = EE_UNDEFINED;

	Meta::cstring_value t_prompt, t_initial, t_filter;
	Meta::cstring_value *t_types = NULL;
	char **t_type_strings = NULL;
	uint4 t_type_count = 0;
	
	
	
	t_error = Meta::evaluate(ep,
								file . prompt, t_prompt, EE_ANSWER_BADQUESTION,
								file . initial, t_initial, EE_ANSWER_BADRESPONSE,
								file . filter, t_filter, EE_ANSWER_BADRESPONSE);
	
	MCresult -> clear(False);

	if (!t_error && file . type_count > 0)
	{
		t_types = new Meta::cstring_value[file . type_count];
		for(uint4 t_type_index = 0; t_type_index < file . type_count && !t_error; ++t_type_index)
		{
			t_error = Meta::evaluate(ep, file . types[t_type_index], t_types[t_type_index], EE_ANSWER_BADRESPONSE);
			if (!t_error)
				for(char *t_type_string = strtok(*t_types[t_type_index], "\n"); t_type_string != NULL; t_type_string = strtok(NULL, "\n"))
				{
					MCU_realloc((char **)&t_type_strings, t_type_count, t_type_count + 1, sizeof(char *));
					t_type_strings[t_type_count++] = t_type_string;
				}
		}
	}

	// Now we have checked all parameters, we check for access.
	if (!t_error && !MCSecureModeCanAccessDisk())
		t_error = EE_DISK_NOPERM;

	if (!t_error)
	{
		if (MCsystemFS && MCscreen -> hasfeature ( PLATFORM_FEATURE_OS_FILE_DIALOGS ) )
		{
			unsigned int t_options = 0;
			if (sheet)
				t_options |= MCA_OPTION_SHEET;
			if (mode == AT_FILES)
				t_options |= MCA_OPTION_PLURAL;

			if (t_types != NULL)
				MCA_file_with_types(ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial, t_options);
			else
				MCA_file(ep, p_title, t_prompt, t_filter, t_initial, t_options);
		}
		else
		{
			MCExecPoint ep2(ep);
			ep2 . clear();
			for(uint4 t_type = 0; t_type < t_type_count; ++t_type)
				ep2 . concatcstring(t_type_strings[t_type], EC_RETURN, t_type == 0);
			t_error = exec_custom(ep, MCfsnamestring, mode == AT_FILE ? "file" : "files", 5, p_title, *t_prompt, *t_filter, *t_initial, ep2 . getsvalue() . getstring());
		}
		
		if (ep . getsvalue() == MCnullmcstring && t_types == NULL)
			MCresult -> sets(MCcancelstring);
	}

	delete[] t_types;
	delete t_type_strings;

	return t_error;
}