Exemplo n.º 1
0
int MCA_folder(MCExecPoint& ep, const char *p_title, const char *p_prompt, const char *p_initial, unsigned int p_options)
{
	if (!MCModeMakeLocalWindows())
	{
		char *t_resolved_initial_path = MCS_resolvepath(p_initial);
		
		MCRemoteFolderDialog(ep, p_title, p_prompt, t_resolved_initial_path);
		if (t_resolved_initial_path != NULL)
			free(t_resolved_initial_path);
		return 0;
	}
	
	//////////

	GtkWidget *dialog ;
	
	
	dialog = create_open_dialog( p_title == NULL  ? p_prompt : p_title, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );

	if ( p_initial != NULL ) 
		gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( dialog ) , MCS_resolvepath(p_initial) );
	
	run_dialog ( dialog, ep) ;
	close_dialog ( dialog ) ;
        
        return (1);
	
}
Exemplo n.º 2
0
Boolean MCS_rename(const char *p_old_name, const char *p_new_name)
{
	char *t_old_resolved_path, *t_new_resolved_path;
	t_old_resolved_path = MCS_resolvepath(p_old_name);
	t_new_resolved_path = MCS_resolvepath(p_new_name);
	
	bool t_result;
	t_result = MCsystem -> RenameFileOrFolder(t_old_resolved_path, t_new_resolved_path);
	
	delete t_old_resolved_path;
	delete t_new_resolved_path;
	
	return t_result;
}
Exemplo n.º 3
0
// This call simply checks to see if this user has 'write' privilege on the
// folder containing the file as this is what determines whether a file can
// be deleted.
bool MCSystemCanDeleteFile(MCStringRef p_file)
{
    MCAutoStringRef t_resolved_file_str;
    /* UNCHECKED */ MCS_resolvepath(p_file, &t_resolved_file_str);
    
    MCAutoStringRefAsSysString t_resolved_file;
    /* UNCHECKED */ t_resolved_file.Lock(*t_resolved_file_str);

	// Now get the folder.
    const char *t_terminator = strrchr(*t_resolved_file, '/');
	if (t_terminator == nil)
		return false;
	
    // This is evil but the AutoStringRefAsSysString owns the string it holds
	*((char*)*t_terminator) = '\0';
	
	struct stat64 t_stat;
	if (stat64(*t_resolved_file, &t_stat) != 0)
		return false;
	
	// Check for user 'write' bit.
	if (t_stat . st_uid == getuid() && (t_stat . st_mode & S_IWUSR) != 0)
		return true;
	
	// Check for same group and group 'write' bit
	if (t_stat . st_gid == getgid() && (t_stat . st_mode & S_IWGRP) != 0)
		return true;
	
	// Check for other
	if ((t_stat . st_mode & S_IWOTH) != 0)
		return true;

	return false;
}
Exemplo n.º 4
0
bool MCSystemPlaySound(const char *p_file, bool p_looping)
{
	//MCLog("MCSystemPlaySound(%s, %s)", p_file, p_looping?"true":"false");
	bool t_success;
	if (s_sound_file != nil)
	{
		MCCStringFree(s_sound_file);
		s_sound_file = nil;
	}
    
	s_sound_file = MCS_resolvepath(p_file);
    
	const char *t_apk_file = nil;
	if (path_to_apk_path(s_sound_file, t_apk_file))
		MCAndroidEngineCall("playSound", "bsbb", &t_success, t_apk_file, true, p_looping);
	else
		MCAndroidEngineCall("playSound", "bsbb", &t_success, s_sound_file, false, p_looping);
	if (!t_success)
	{
		MCCStringFree(s_sound_file);
		s_sound_file = nil;
	}
    
	return t_success;
}
Exemplo n.º 5
0
// This call simply checks to see if this user has 'write' privilege on the
// folder containing the file as this is what determines whether a file can
// be deleted.
bool MCSystemCanDeleteFile(MCStringRef p_file)
{
	MCAutoStringRef t_resolved_file_str;
	MCS_resolvepath(p_file, &t_resolved_file_str);
    
    MCAutoStringRefAsUTF8String t_resolved_file;
    /* UNCHECKED */ t_resolved_file.Lock(*t_resolved_file_str);
	
	// Now get the folder.
	if (strrchr(*t_resolved_file, '/') == nil)
		return false;
	
	strrchr(*t_resolved_file, '/')[0] = '\0';
	
	struct stat t_stat;
	if (stat(*t_resolved_file, &t_stat) != 0)
		return false;
	
	// Check for user 'write' bit.
	if (t_stat . st_uid == getuid() && (t_stat . st_mode & S_IWUSR) != 0)
		return true;
	
	// Check for same group and group 'write' bit
	if (t_stat . st_gid == getgid() && (t_stat . st_mode & S_IWGRP) != 0)
		return true;
	
	// Check for other
	if ((t_stat . st_mode & S_IWOTH) != 0)
		return true;
	
	return false;
}
Exemplo n.º 6
0
void MCS_savefile(const MCString& p_filename, MCExecPoint& p_data, Boolean p_binary)
{
	char *t_filename;
	t_filename = p_filename . clone();
	
	char *t_resolved_path;
	t_resolved_path = MCS_resolvepath(t_filename);
	delete t_filename;
	
	MCSystemFileHandle *t_file;
	t_file = MCsystem -> OpenFile(t_resolved_path, kMCSystemFileModeWrite, false);
	delete t_resolved_path;
	if (t_file == NULL)
	{
		MCresult -> sets("can't open file");
		return;
	}
	
	if (!p_binary)
		p_data . binarytotext();
	
	uint32_t t_written;
	if (!t_file -> Write(p_data . getsvalue() . getstring(), p_data . getsvalue() . getlength(), t_written) ||
		p_data . getsvalue() . getlength() != t_written)
		MCresult -> sets("error writing file");
	else
		MCresult -> clear();
	
	t_file -> Close();
}
Exemplo n.º 7
0
IO_handle MCS_open(const char *p_path, const char *p_mode, Boolean p_map, Boolean p_driver, uint4 p_offset)
{
	char *t_resolved_path;
	t_resolved_path = MCS_resolvepath(p_path);
	
	uint32_t t_mode;
	if (strequal(p_mode, IO_READ_MODE))
		t_mode = kMCSystemFileModeRead;
	else if (strequal(p_mode, IO_WRITE_MODE))
		t_mode = kMCSystemFileModeWrite;
	else if (strequal(p_mode, IO_UPDATE_MODE))
		t_mode = kMCSystemFileModeUpdate;
	else if (strequal(p_mode, IO_APPEND_MODE))
		t_mode = kMCSystemFileModeAppend;
	
	MCSystemFileHandle *t_handle;
	if (!p_driver)
		t_handle = MCsystem -> OpenFile(t_resolved_path, t_mode, p_map && MCmmap);
	else
		t_handle = MCsystem -> OpenDevice(t_resolved_path, t_mode, MCserialcontrolsettings);
	
	// MW-2011-06-12: Fix memory leak - make sure we delete the resolved path.
	delete t_resolved_path;
	
	if (t_handle == NULL)
		return NULL;
	
	if (p_offset != 0)
		t_handle -> Seek(p_offset, 1);
	
	return new IO_header(t_handle, 0);;
}
Exemplo n.º 8
0
void set_initial_file ( GtkWidget *dialog, const char * p_initial, char * p_last_path ) 
{
	char *t_filename ;

	if ( p_initial != NULL ) 
	{
		if ( file_has_path (p_initial)  )
			t_filename =  MCS_resolvepath ( p_initial );
		else
			t_filename = strcat ( strcat(MCS_resolvepath ( NULL ), "/") , p_initial );
			
		gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( dialog ) , MCS_resolvepath ( t_filename ) );
	}
	else
		if ( p_last_path != NULL )
		  gtk_file_chooser_set_current_folder  ( GTK_FILE_CHOOSER ( dialog ) , p_last_path );
}
Exemplo n.º 9
0
char *MCS_get_canonical_path(const char *p_path)
{
	char *t_path = NULL;
	
	t_path = MCS_resolvepath(p_path);
	MCU_fix_path(t_path);
	
	return t_path;
}
Exemplo n.º 10
0
Boolean MCS_setcurdir(const char *p_folder)
{
	char *t_resolved_folder;
	t_resolved_folder = MCS_resolvepath(p_folder);
	
	bool t_success;
	t_success = MCsystem -> SetCurrentFolder(t_resolved_folder);
	delete t_resolved_folder;
	return t_success;
}
Exemplo n.º 11
0
static Exec_stat fetch_opt_filepath(MCExecPoint& ep, MCVariableValue *array, const char *key, char*& r_result)
{
	if (array -> fetch_element(ep, key) != ES_NORMAL)
		return ES_ERROR;
	if (ep . getsvalue() == MCnullmcstring)
		r_result = NULL;
	else
		r_result = MCS_resolvepath(ep . getcstring());
	return ES_NORMAL;
}
Exemplo n.º 12
0
Boolean MCS_rmdir(const char *p_path)
{
	char *t_resolved_path;
	t_resolved_path = MCS_resolvepath(p_path);
	
	bool t_result;
	t_result = MCsystem -> DeleteFolder(t_resolved_path);
	
	delete t_resolved_path;
	
	return t_result;
}
Exemplo n.º 13
0
Boolean MCS_unlink(const char *p_path)
{
	char *t_resolved_path;
	t_resolved_path = MCS_resolvepath(p_path);
	
	bool t_result;
	t_result = MCsystem -> DeleteFile(t_resolved_path);
	
	delete t_resolved_path;
	
	return t_result;
}
Exemplo n.º 14
0
int MCA_file_with_types(MCExecPoint& ep, const char *p_title, const char *p_prompt, char * const p_types[], uint4 p_type_count, const char *p_initial, unsigned int p_options)

{
	if (!MCModeMakeLocalWindows())
	{
		bool t_plural = (p_options & MCA_OPTION_PLURAL) != 0;
		char *t_resolved_path = MCS_resolvepath(p_initial);
		char **t_rtypes;
		if (types_to_remote_types(p_types, p_type_count, t_rtypes))
		{
			MCRemoteFileDialog(ep, p_title, p_prompt, t_rtypes, p_type_count * 2, NULL, t_resolved_path, false, t_plural);
			MCCStringArrayFree(t_rtypes, p_type_count * 2);
		}
		delete t_resolved_path;
		return 1;
	}

	//////////

	GtkWidget *dialog ;
	
	
	// Create the file dialog with the correct prompt
	dialog = create_open_dialog ( p_title == NULL  ? p_prompt : p_title, GTK_FILE_CHOOSER_ACTION_OPEN );
	
	// If we have any filters, add them.
	if ( p_type_count > 0 ) 
		add_dialog_filters ( dialog, p_types , p_type_count );

	
	if ( p_options & MCA_OPTION_PLURAL ) 
		gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER ( dialog ) ,true );
	
	// If we have an initial file/folder then set it.
	set_initial_file ( dialog, p_initial, G_last_opened_path ) ;

	// Run the dialog ... this will be replaced with our own loop which will call the REV event handler too.

	run_dialog ( dialog, ep) ;
	
	
	MCresult -> clear();
	MCresult -> copysvalue(get_current_filter_name ( dialog ) );
	
	if (G_last_opened_path != nil)
		g_free(G_last_opened_path);
	G_last_opened_path = gtk_file_chooser_get_current_folder ( GTK_FILE_CHOOSER ( dialog ) ) ;
	
	// All done, close the dialog.
	close_dialog ( dialog ) ;
        return(1);
}
Exemplo n.º 15
0
Boolean MCS_exists(const char *p_path, Boolean p_file)
{
	char *t_resolved_path;
	t_resolved_path = MCS_resolvepath(p_path);
	
	Bool t_found;
	if (p_file)
		t_found = MCsystem -> FileExists(t_resolved_path);
	else
		t_found = MCsystem -> FolderExists(t_resolved_path);
	
	delete t_resolved_path;
	
	return t_found;
}
Exemplo n.º 16
0
void MCS_loadfile(MCExecPoint& ep, Boolean p_binary)
{
	const char *t_filename;
	t_filename = ep . getcstring();
	
	char *t_resolved_path;
	t_resolved_path = MCS_resolvepath(t_filename);
	
	MCSystemFileHandle *t_file;
	t_file = MCsystem -> OpenFile(t_resolved_path, kMCSystemFileModeRead, false);
	delete t_resolved_path;
	if (t_file == NULL)
	{
		// MW-2011-05-23: [[ Bug 9549 ]] Make sure we empty the result if opening the file
		//   failed.
		ep . clear();
		MCresult -> sets("can't open file");
		return;
	}
	
	uint32_t t_size;
	t_size = (uint32_t)t_file -> GetFileSize();
	
	char *t_buffer;
	t_buffer = ep . getbuffer(t_size);
	
	uint32_t t_read;
	if (t_buffer != NULL &&
		t_file -> Read(t_buffer, t_size, t_read) &&
		t_read == t_size)
	{
		ep . setlength(t_size);
		if (!p_binary)
			ep . texttobinary();
		MCresult -> clear(False);
	}
	else
	{
		ep . clear();
		MCresult -> sets("error reading file");
	}

	t_file -> Close();
}
Exemplo n.º 17
0
LONG WINAPI unhandled_exception_filter(struct _EXCEPTION_POINTERS *p_exception_info)
{
	if (MCcrashreportfilename == NULL)
		return EXCEPTION_EXECUTE_HANDLER;

	HMODULE t_dbg_help_module = NULL;
	t_dbg_help_module = LoadLibraryA("dbghelp.dll");

	MiniDumpWriteDumpPtr t_write_minidump;
	if (t_dbg_help_module != NULL)
		t_write_minidump = (MiniDumpWriteDumpPtr)GetProcAddress(t_dbg_help_module, "MiniDumpWriteDump");

	char *t_path = NULL;
	if (t_write_minidump != NULL)
		t_path = MCS_resolvepath(MCcrashreportfilename);

	HANDLE t_file = NULL;
	if (t_path != NULL)
		t_file = CreateFileA(t_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);

	BOOL t_minidump_written = FALSE;
	if (t_file != NULL)
	{
		MINIDUMP_EXCEPTION_INFORMATION t_info;
		t_info . ThreadId = GetCurrentThreadId();
		t_info . ExceptionPointers = p_exception_info;
		t_info . ClientPointers = FALSE;
		t_minidump_written = t_write_minidump(GetCurrentProcess(), GetCurrentProcessId(), t_file, MCcrashreportverbose ? MiniDumpWithDataSegs : MiniDumpNormal, &t_info, NULL, NULL);
	}

	if (t_file != NULL)
		CloseHandle(t_file);

	if (t_path != NULL)
		delete t_path;
	
	if (t_dbg_help_module != NULL)
		FreeLibrary(t_dbg_help_module);

	return EXCEPTION_EXECUTE_HANDLER;
}
Exemplo n.º 18
0
Exec_stat MCRevRelicense::exec(MCExecPoint& ep)
{
	switch(MCdefaultstackptr -> getcard() -> message(MCM_shut_down_request))
	{
	case ES_PASS:
	case ES_NOT_HANDLED:
		break;
		
	default:
		MCresult -> sets("cancelled");
		
		return ES_NORMAL;
	}
	
	if (MClicenseparameters . license_token == NULL || strlen(MClicenseparameters . license_token) == 0)
	{
		MCresult -> sets("no token");
		return ES_NORMAL;
	}
	
	if (!MCS_unlink(MClicenseparameters . license_token))
	{
		MCresult -> sets("token deletion failed");
		return ES_NORMAL;
	}

	MCretcode = 0;
	MCquit = True;
	MCexitall = True;
	MCtracestackptr = NULL;
	MCtraceabort = True;
	MCtracereturn = True;
	
	s_command_path = MCS_resolvepath(MCcmd);

	atexit(restart_revolution);
	
	return ES_NORMAL;
}
Exemplo n.º 19
0
static Exec_stat fetch_filepath_array(MCExecPoint& ep, MCVariableValue *array, const char *key, char**& r_filepaths, uint32_t& r_filepath_count)
{
	bool t_success;
	t_success = true;
	
	char *t_paths_string;
	t_paths_string = nil;
	if (t_success)
		if (fetch_opt_cstring(ep, array, key, t_paths_string) == ES_ERROR)
			t_success = false;
	
	char **t_paths;
	uint32_t t_path_count;
	t_paths = nil;
	t_path_count = 0;
	if (t_success)
		t_success = MCCStringSplit(t_paths_string, '\n', t_paths, t_path_count);
	
	if (t_success)
		for(uint32_t i = 0; i < t_path_count; i++)
		{
			char *t_unresolved_path;
			t_unresolved_path = t_paths[i];
			t_paths[i] = MCS_resolvepath(t_unresolved_path);
			MCCStringFree(t_unresolved_path);
		}
	
	if (t_success)
	{
		r_filepaths = t_paths;
		r_filepath_count = t_path_count;
	}
	else
		MCCStringArrayFree(t_paths, t_path_count);
	
	MCCStringFree(t_paths_string);
	
	return t_success ? ES_NORMAL : ES_ERROR;
}
Exemplo n.º 20
0
bool MCSystemPlaySoundOnChannel(const char *p_channel, const char *p_file, MCSoundChannelPlayType p_type, MCObjectHandle *p_object)
{
    bool t_success;
    t_success = true;    
    const char *t_apk_file = nil;;
	
	// IM-2013-11-13: [[ Bug 11428 ]] Resolve path to make sure asset paths are valid
	char *t_resolved_path;
	t_resolved_path = nil;
	
	if (t_success)
		t_success = nil != (t_resolved_path = MCS_resolvepath(p_file));
	
    if (t_success)
        if (path_to_apk_path(t_resolved_path, t_apk_file))
            MCAndroidEngineRemoteCall("playSoundOnChannel", "bsssibj", &t_success, p_channel, t_apk_file, p_file, (int32_t) p_type, true, (long) p_object);
        else
            MCAndroidEngineRemoteCall("playSoundOnChannel", "bsssibj", &t_success, p_channel, t_resolved_path, p_file, (int32_t) p_type, false, (long) p_object);
	
	MCCStringFree(t_resolved_path);
	
    return t_success;
}
Exemplo n.º 21
0
static int MCA_do_file_dialog(MCExecPoint& ep, const char *p_title, const char *p_prompt, const char *p_filter, const char *p_initial, unsigned int p_options)
{
	int t_result = 0;

	char *t_initial_file;
	t_initial_file = NULL;

	char *t_initial_folder;
	t_initial_folder = NULL;

	ep . clear();

	if (*p_initial != '\0')
	{
		char *t_initial_clone;
		t_initial_clone = strdup(p_initial);
		MCU_w32path2std(t_initial_clone);
		MCU_fix_path(t_initial_clone);

		if (MCS_exists(t_initial_clone, False))
			t_initial_folder = t_initial_clone;
		else if ((p_options & MCA_OPTION_SAVE_DIALOG) != 0)
		{
			t_initial_file = strrchr(t_initial_clone, '/');
			if (t_initial_file == NULL)
			{
				if (strlen(t_initial_clone) != 0)
					t_initial_file = t_initial_clone;
			}
			else
			{
				*t_initial_file = '\0';
				t_initial_file++;
				
				if (t_initial_file[0] == '\0')
					t_initial_file = NULL;

				if (MCS_exists(t_initial_clone, False))
					t_initial_folder = t_initial_clone;
			}
		}
		else
		{
			char *t_leaf;
			t_leaf = strrchr(t_initial_clone, '/');
			if (t_leaf != NULL)
			{
				*t_leaf = '\0';
				if (MCS_exists(t_initial_clone, False))
					t_initial_folder = t_initial_clone;
			}
		}

		t_initial_file = strdup(t_initial_file);
		t_initial_folder = MCS_resolvepath(t_initial_folder);

		delete t_initial_clone;
	}

	if (!MCModeMakeLocalWindows())
	{
		char ** t_filters = NULL;
		uint32_t t_filter_count = 0;

		if (p_filter != NULL)
		{
			const char *t_strptr = p_filter;
			while (t_strptr[0] != '\0')
			{
				t_filter_count++;
				t_filters = (char**)realloc(t_filters, t_filter_count * sizeof(char*));
				t_filters[t_filter_count - 1] = (char *)t_strptr;
				t_strptr += strlen(t_strptr) + 1;
			}
		}

		MCRemoteFileDialog(ep, p_title, p_prompt, t_filters, t_filter_count, t_initial_folder, t_initial_file, (p_options & MCA_OPTION_SAVE_DIALOG) != 0, (p_options & MCA_OPTION_PLURAL) != 0);

		free(t_filters);
		return 0;
	}

	Window t_window;
	t_window = MCModeGetParentWindow();

	bool t_succeeded;
	int t_filter_index;

	if (MCmajorosversion >= 0x0600)
	{
		static SHCreateItemFromParsingNamePtr  s_shcreateitemfromparsingname = NULL;
		if (s_shcreateitemfromparsingname == NULL)
		{
			static HMODULE s_shell32_module = NULL;
			s_shell32_module = LoadLibraryA("shell32.dll");
			s_shcreateitemfromparsingname = (SHCreateItemFromParsingNamePtr)GetProcAddress(s_shell32_module, "SHCreateItemFromParsingName");
		}

		IFileSaveDialog *t_file_save_dialog;
		IFileOpenDialog *t_file_open_dialog;
		IFileDialog *t_file_dialog;

		t_file_dialog = NULL;

		HRESULT t_hresult;

		if ((p_options & MCA_OPTION_SAVE_DIALOG) == 0)
		{
			t_hresult = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, __uuidof(IFileOpenDialog), (LPVOID *)&t_file_open_dialog);
			t_succeeded = SUCCEEDED(t_hresult);

			t_file_dialog = t_file_open_dialog;
		}
		else
		{
			t_hresult = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, __uuidof(IFileSaveDialog), (LPVOID *)&t_file_save_dialog);
			t_succeeded = SUCCEEDED(t_hresult);

			t_file_dialog = t_file_save_dialog;
		}

		if (t_succeeded)
		{
			DWORD t_options;

			t_options = FOS_FORCEFILESYSTEM | FOS_NOCHANGEDIR | FOS_PATHMUSTEXIST;
			if (p_options & MCA_OPTION_PLURAL)
				t_options |= FOS_ALLOWMULTISELECT;
			if (p_options & MCA_OPTION_SAVE_DIALOG)
				t_options |= FOS_OVERWRITEPROMPT;
			if (p_options & MCA_OPTION_FOLDER_DIALOG)
				t_options |= FOS_PICKFOLDERS;
			else
				t_options |= FOS_FILEMUSTEXIST;

			t_hresult = t_file_dialog -> SetOptions(t_options);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && t_initial_folder != NULL)
		{
			IShellItem *t_initial_folder_shellitem;
			t_initial_folder_shellitem = NULL;
			t_hresult = s_shcreateitemfromparsingname(WideCString(t_initial_folder), NULL, __uuidof(IShellItem), (LPVOID *)&t_initial_folder_shellitem);
			if (SUCCEEDED(t_hresult))
				t_file_dialog -> SetFolder(t_initial_folder_shellitem);
			if (t_initial_folder_shellitem != NULL)
				t_initial_folder_shellitem -> Release();
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && t_initial_file != NULL)
		{
			t_hresult = t_file_dialog -> SetFileName(WideCString(t_initial_file));
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && p_filter != NULL && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			uint4 t_filter_length, t_filter_count;
			measure_filter(p_filter, t_filter_length, t_filter_count);

			WideCString t_filters(p_filter, t_filter_length);
			COMDLG_FILTERSPEC *t_filter_spec;

			filter_to_spec(t_filters, t_filter_count, t_filter_spec);

			t_hresult = t_file_dialog -> SetFileTypes(t_filter_count, t_filter_spec);
			t_succeeded = SUCCEEDED(t_hresult);

			delete t_filter_spec;
		}

		if (t_succeeded && p_filter != NULL && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			t_hresult = t_file_dialog -> SetFileTypeIndex(1);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded)
			t_hresult = t_file_dialog -> SetTitle(WideCString(p_prompt));

		if (t_succeeded)
		{
			t_hresult = t_file_dialog -> Show(t_window != NULL ? (HWND)t_window -> handle . window : NULL);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if ((p_options & MCA_OPTION_SAVE_DIALOG) == 0)
		{
			IShellItemArray *t_file_items;
			t_file_items = NULL;
			if (t_succeeded)
			{
				t_hresult = t_file_open_dialog -> GetResults(&t_file_items);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			DWORD t_file_item_count;
			if (t_succeeded)
			{
				t_hresult = t_file_items -> GetCount(&t_file_item_count);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			if (t_succeeded)
			{
				ep . clear();
				for(uint4 t_index = 0; t_index < t_file_item_count && t_succeeded; ++t_index)
				{
					IShellItem *t_file_item;
					t_file_item = NULL;
					if (t_succeeded)
					{
						t_hresult = t_file_items -> GetItemAt(t_index, &t_file_item);
						t_succeeded = SUCCEEDED(t_hresult);
					}

					if (t_succeeded)
					{
						t_hresult = append_shellitem_path_and_release(ep, t_file_item, t_index == 0);
						t_succeeded = SUCCEEDED(t_hresult);
					}
				}
			}

			if (t_file_items != NULL)
				t_file_items -> Release();
		}
		else
		{
			IShellItem *t_file_item;
			t_file_item = NULL;
			if (t_succeeded)
			{
				t_hresult = t_file_dialog -> GetResult(&t_file_item);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			if (t_succeeded)
			{
				ep . clear();
				t_hresult = append_shellitem_path_and_release(ep, t_file_item, true);
				t_succeeded = SUCCEEDED(t_hresult);
			}
		}

		t_filter_index = 0;
		if (t_succeeded && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			UINT t_index;
			t_hresult = t_file_dialog -> GetFileTypeIndex(&t_index);
			t_succeeded = SUCCEEDED(t_hresult);
			if (t_succeeded)
				t_filter_index = (int)t_index;
		}

		if (t_file_dialog != NULL)
			t_file_dialog -> Release();

		if (!t_succeeded)
			t_result = t_hresult;
		else
			t_result = 0;
	}
	else
	{
		OPENFILENAMEA t_open_dialog;
		memset(&t_open_dialog, 0, sizeof(OPENFILENAMEA));
		t_open_dialog . lStructSize = sizeof(OPENFILENAMEA);

		char *t_initial_file_buffer = new char[MAX_PATH];
		if (t_initial_file != NULL)
			strcpy(t_initial_file_buffer, t_initial_file);
		else
			*t_initial_file_buffer = '\0';

		t_open_dialog . lpstrFilter = p_filter;
		t_open_dialog . nFilterIndex = 1;
		t_open_dialog . lpstrFile = t_initial_file_buffer;
		t_open_dialog . nMaxFile = MAX_PATH;
		t_open_dialog . lpstrInitialDir = t_initial_folder;
		t_open_dialog . lpstrTitle = p_prompt;
		t_open_dialog . Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR |
														OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_EXPLORER |
														OFN_ENABLEHOOK | OFN_ENABLESIZING;

		if (p_options & MCA_OPTION_PLURAL)
			t_open_dialog . Flags |= OFN_ALLOWMULTISELECT;

		if (p_options & MCA_OPTION_SAVE_DIALOG)
			t_open_dialog . Flags |= OFN_OVERWRITEPROMPT;

		t_open_dialog . lpstrFilter = p_filter;
		t_open_dialog . lpfnHook = open_dialog_hook;
		t_open_dialog . hwndOwner = t_window != NULL ? (HWND)t_window -> handle . window : NULL;

		if (p_options & MCA_OPTION_SAVE_DIALOG)
			t_succeeded = GetSaveFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;
		else
		{
			*t_open_dialog . lpstrFile = '\0';
			t_succeeded = GetOpenFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;
		}

		if (!t_succeeded)
			t_result = CommDlgExtendedError();

		// MW-2005-07-26: Try again without the specified filename if it was invalid
		if (t_result == FNERR_INVALIDFILENAME)
		{
			*t_open_dialog . lpstrFile = '\0';
			if (p_options & MCA_OPTION_SAVE_DIALOG)
				t_succeeded = GetSaveFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;
			else
				t_succeeded = GetOpenFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;

			if (!t_succeeded)
				t_result = CommDlgExtendedError();	
		}

		if (t_result == FNERR_BUFFERTOOSMALL)
			t_succeeded = true;

		if (t_succeeded)
		{
			build_paths(ep);
			t_filter_index = t_open_dialog . nFilterIndex;
		}

		delete t_initial_file_buffer;
	}

	if (t_succeeded)
	{
		if (p_options & MCA_OPTION_RETURN_FILTER)
		{
			const char *t_type = p_filter;
			const char *t_types = p_filter;
			for(int t_index = t_filter_index * 2 - 1; t_index > 1; t_types += 1)
				if (*t_types == '\0')
					t_type = t_types + 1, t_index -= 1;
			MCresult -> copysvalue(t_type);
		}

		t_result = 0;
	}

	waitonbutton();

	if (t_initial_folder != NULL)
		delete t_initial_folder;

	if (t_initial_file != NULL)
		delete t_initial_file;

	return t_result;
}
Exemplo n.º 22
0
static int MCA_do_file_dialog(MCStringRef p_title, MCStringRef p_prompt, MCStringRef p_filter, MCStringRef p_initial, unsigned int p_options, MCStringRef &r_value, MCStringRef &r_result)
{
	int t_result = 0;

	MCAutoStringRef t_initial_file;
	MCAutoStringRef t_initial_folder;
    MCAutoStringRef t_initial_native_folder;

	if (p_initial != nil && !MCStringIsEmpty(p_initial))
	{
		MCAutoStringRef t_fixed_path;
		/* UNCHECKED */ MCU_fix_path(p_initial, &t_fixed_path);

		if (MCS_exists(*t_fixed_path, False))
			t_initial_folder = *t_fixed_path;
		else if ((p_options & MCA_OPTION_SAVE_DIALOG) != 0)
		{
			uindex_t t_last_slash;
			if (!MCStringLastIndexOfChar(*t_fixed_path, '/', UINDEX_MAX, kMCStringOptionCompareExact, t_last_slash))
			{
				if (MCStringGetLength(*t_fixed_path) != 0)
					t_initial_file = *t_fixed_path;
			}
			else
			{
				if (t_last_slash < MCStringGetLength(*t_fixed_path) - 1)
					/* UNCHECKED */ MCStringCopySubstring(*t_fixed_path, MCRangeMake(t_last_slash + 1, MCStringGetLength(*t_fixed_path) - (t_last_slash + 1)), &t_initial_file);

				MCAutoStringRef t_folder_split;
				/* UNCHECKED */ MCStringCopySubstring(*t_fixed_path, MCRangeMake(0, t_last_slash - 1), &t_folder_split);
				if (MCS_exists(*t_folder_split, False))
					t_initial_folder = *t_folder_split;
			}
		}
		else
		{
			uindex_t t_last_slash;

			if (MCStringLastIndexOfChar(*t_fixed_path, '/', UINDEX_MAX, kMCStringOptionCompareExact, t_last_slash))
			{
				MCAutoStringRef t_folder_split;
				/* UNCHECKED */ MCStringCopySubstring(*t_fixed_path, MCRangeMake(0, t_last_slash - 1), &t_folder_split);
				
				if (MCS_exists(*t_folder_split, False))
					t_initial_folder = *t_folder_split;
			}
		}
        
        MCAutoStringRef t_resolved_folder;
        /* UNCHECKED */ MCS_resolvepath(*t_initial_folder != nil ? *t_initial_folder : kMCEmptyString, &t_resolved_folder);
        /* UNCHECKED */ MCS_pathtonative(*t_resolved_folder, &t_initial_native_folder);
	}
    
	if (!MCModeMakeLocalWindows())
	{
		MCAutoStringRefArray t_filters;

		if (p_filter != NULL)
		{
			/* UNCHECKED */ MCStringsSplit(p_filter, '\0', t_filters.PtrRef(), t_filters.CountRef());
		}

		MCRemoteFileDialog(p_title, p_prompt, *t_filters, t_filters.Count(), *t_initial_native_folder, *t_initial_file, (p_options & MCA_OPTION_SAVE_DIALOG) != 0, (p_options & MCA_OPTION_PLURAL) != 0, r_value);

		return 0;
	}

	Window t_window;
	t_window = MCModeGetParentWindow();

	MCAutoStringRef t_value;
	bool t_succeeded;
	int t_filter_index;

	if (MCmajorosversion >= 0x0600)
	{
		static SHCreateItemFromParsingNamePtr  s_shcreateitemfromparsingname = NULL;
		if (s_shcreateitemfromparsingname == NULL)
		{
			static HMODULE s_shell32_module = NULL;
			s_shell32_module = LoadLibraryW(L"shell32.dll");
			s_shcreateitemfromparsingname = (SHCreateItemFromParsingNamePtr)GetProcAddress(s_shell32_module, "SHCreateItemFromParsingName");
		}

		IFileSaveDialog *t_file_save_dialog;
		IFileOpenDialog *t_file_open_dialog;
		IFileDialog *t_file_dialog;

		t_file_dialog = NULL;

		HRESULT t_hresult;

		if ((p_options & MCA_OPTION_SAVE_DIALOG) == 0)
		{
			t_hresult = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, __uuidof(IFileOpenDialog), (LPVOID *)&t_file_open_dialog);
			t_succeeded = SUCCEEDED(t_hresult);

			t_file_dialog = t_file_open_dialog;
		}
		else
		{
			t_hresult = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, __uuidof(IFileSaveDialog), (LPVOID *)&t_file_save_dialog);
			t_succeeded = SUCCEEDED(t_hresult);

			t_file_dialog = t_file_save_dialog;
		}

		if (t_succeeded)
		{
			DWORD t_options;

			t_options = FOS_FORCEFILESYSTEM | FOS_NOCHANGEDIR | FOS_PATHMUSTEXIST;
			if (p_options & MCA_OPTION_PLURAL)
				t_options |= FOS_ALLOWMULTISELECT;
			if (p_options & MCA_OPTION_SAVE_DIALOG)
				t_options |= FOS_OVERWRITEPROMPT;
			if (p_options & MCA_OPTION_FOLDER_DIALOG)
				t_options |= FOS_PICKFOLDERS;
			else
				t_options |= FOS_FILEMUSTEXIST;

			t_hresult = t_file_dialog -> SetOptions(t_options);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && *t_initial_native_folder != NULL)
		{
			IShellItem *t_initial_folder_shellitem;
			t_initial_folder_shellitem = NULL;

			MCAutoStringRefAsWString t_initial_folder_wstr;
			/* UNCHECKED */ t_initial_folder_wstr.Lock(*t_initial_native_folder);

			t_hresult = s_shcreateitemfromparsingname(*t_initial_folder_wstr, NULL, __uuidof(IShellItem), (LPVOID *)&t_initial_folder_shellitem);
			if (SUCCEEDED(t_hresult))
				t_file_dialog -> SetFolder(t_initial_folder_shellitem);
			if (t_initial_folder_shellitem != NULL)
				t_initial_folder_shellitem -> Release();
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && *t_initial_file != NULL)
		{
			MCAutoStringRefAsWString t_initial_file_wstr;
			/* UNCHECKED */ t_initial_file_wstr.Lock(*t_initial_file);
			
			t_hresult = t_file_dialog -> SetFileName(*t_initial_file_wstr);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && p_filter != NULL && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			uint4 t_filter_length, t_filter_count;
			measure_filter(p_filter, t_filter_length, t_filter_count);

			MCAutoStringRefAsWString t_filter_wstr;
			/* UNCHECKED */ t_filter_wstr.Lock(p_filter);

			COMDLG_FILTERSPEC *t_filter_spec;

			filter_to_spec(*t_filter_wstr, t_filter_count, t_filter_spec);

			t_hresult = t_file_dialog -> SetFileTypes(t_filter_count, t_filter_spec);
			t_succeeded = SUCCEEDED(t_hresult);

			delete t_filter_spec;
		}

		if (t_succeeded && p_filter != NULL && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			t_hresult = t_file_dialog -> SetFileTypeIndex(1);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded)
		{
			MCAutoStringRefAsWString t_prompt_wstr;
			/* UNCHECKED */ t_prompt_wstr.Lock(p_prompt);
			t_hresult = t_file_dialog -> SetTitle(*t_prompt_wstr);
		}

		if (t_succeeded)
		{
			t_hresult = t_file_dialog -> Show(t_window != NULL ? (HWND)t_window -> handle . window : NULL);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if ((p_options & MCA_OPTION_SAVE_DIALOG) == 0)
		{
			IShellItemArray *t_file_items;
			t_file_items = NULL;
			if (t_succeeded)
			{
				t_hresult = t_file_open_dialog -> GetResults(&t_file_items);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			DWORD t_file_item_count;
			if (t_succeeded)
			{
				t_hresult = t_file_items -> GetCount(&t_file_item_count);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			if (t_succeeded)
			{
				for(uint4 t_index = 0; t_index < t_file_item_count && t_succeeded; ++t_index)
				{
					IShellItem *t_file_item;
					t_file_item = NULL;
					if (t_succeeded)
					{
						t_hresult = t_file_items -> GetItemAt(t_index, &t_file_item);
						t_succeeded = SUCCEEDED(t_hresult);
					}

					if (t_succeeded)
					{
						t_hresult = append_shellitem_path_and_release(t_file_item, t_index == 0, &t_value);
						t_succeeded = SUCCEEDED(t_hresult);
					}
				}
			}

			if (t_file_items != NULL)
				t_file_items -> Release();
		}
		else
		{
			IShellItem *t_file_item;
			t_file_item = NULL;
			if (t_succeeded)
			{
				t_hresult = t_file_dialog -> GetResult(&t_file_item);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			if (t_succeeded)
			{
				t_hresult = append_shellitem_path_and_release(t_file_item, true, &t_value);
				t_succeeded = SUCCEEDED(t_hresult);
			}
		}

		t_filter_index = 0;
		if (t_succeeded && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			UINT t_index;
			t_hresult = t_file_dialog -> GetFileTypeIndex(&t_index);
			t_succeeded = SUCCEEDED(t_hresult);
			if (t_succeeded)
				t_filter_index = (int)t_index;
		}

		if (t_file_dialog != NULL)
			t_file_dialog -> Release();

		if (!t_succeeded)
			t_result = t_hresult;
		else
			t_result = 0;
	}
	else
	{
		OPENFILENAMEW t_open_dialog;
		memset(&t_open_dialog, 0, sizeof(OPENFILENAMEW));
		t_open_dialog . lStructSize = sizeof(OPENFILENAMEW);

		MCAutoStringRefAsWString t_initial_folder_wstr;
		MCAutoStringRefAsWString t_prompt_wstr;
		MCAutoStringRefAsWString t_filter_wstr;
		/* UNCHECKED */ t_filter_wstr.Lock(p_filter);
		/* UNCHECKED */ t_initial_folder_wstr.Lock(*t_initial_native_folder);
		/* UNCHECKED */ t_prompt_wstr.Lock(p_prompt);

		MCAutoArray<unichar_t> t_buffer;
		/* UNCHECKED */ t_buffer.New(MAX_PATH);

		if (!MCStringIsEmpty(*t_initial_file))
			/* UNCHECKED */ MCStringGetChars(*t_initial_file, MCRangeMake(0, t_buffer.Size()), t_buffer.Ptr());
		else
			t_buffer[0] = '\0';

		t_open_dialog . lpstrFilter = *t_filter_wstr;
		t_open_dialog . nFilterIndex = 1;
		t_open_dialog . lpstrFile = t_buffer.Ptr();
		t_open_dialog . nMaxFile = t_buffer.Size();
		t_open_dialog . lpstrInitialDir = *t_initial_folder_wstr;
		t_open_dialog . lpstrTitle = *t_prompt_wstr;
		t_open_dialog . Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR |
														OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_EXPLORER |
														OFN_ENABLEHOOK | OFN_ENABLESIZING;

		if (p_options & MCA_OPTION_PLURAL)
			t_open_dialog . Flags |= OFN_ALLOWMULTISELECT;

		if (p_options & MCA_OPTION_SAVE_DIALOG)
			t_open_dialog . Flags |= OFN_OVERWRITEPROMPT;

		t_open_dialog . lpstrFilter = *t_filter_wstr;
		t_open_dialog . lpfnHook = open_dialog_hook;
		t_open_dialog . hwndOwner = t_window != NULL ? (HWND)t_window -> handle . window : NULL;

		if (p_options & MCA_OPTION_SAVE_DIALOG)
			t_succeeded = GetSaveFileNameW(&t_open_dialog) == TRUE;
		else
		{
			*t_open_dialog . lpstrFile = '\0';
			t_succeeded = GetOpenFileNameW(&t_open_dialog) == TRUE;
		}

		if (!t_succeeded)
			t_result = CommDlgExtendedError();

		// MW-2005-07-26: Try again without the specified filename if it was invalid
		if (t_result == FNERR_INVALIDFILENAME)
		{
			*t_open_dialog . lpstrFile = '\0';
			if (p_options & MCA_OPTION_SAVE_DIALOG)
				t_succeeded = GetSaveFileNameW(&t_open_dialog) == TRUE;
			else
				t_succeeded = GetOpenFileNameW(&t_open_dialog) == TRUE;

			if (!t_succeeded)
				t_result = CommDlgExtendedError();	
		}

		if (t_result == FNERR_BUFFERTOOSMALL)
			t_succeeded = true;

		if (t_succeeded)
		{
			build_paths(&t_value);
			t_filter_index = t_open_dialog . nFilterIndex;
		}
	}

	if (t_succeeded)
	{
		if (p_options & MCA_OPTION_RETURN_FILTER)
		{
			// The filter string has the following format:
			// "<description0>\0<extensions0>\0<description1>\0...\0<extensionsN>\0"
			// so the n'th filter comes after the 2(n - 1)'th null character
			uindex_t t_index = 2 * (t_filter_index - 1);
			uindex_t t_offset = 0;
			while (t_index--)
			{
				/* UNCHECKED */ MCStringFirstIndexOfChar(p_filter, '\0', t_offset, kMCStringOptionCompareExact, t_offset);
				t_offset++;
			}
			
			uindex_t t_end;
			t_end = UINDEX_MAX;
			/* UNCHECKED */ MCStringFirstIndexOfChar(p_filter, '\0', t_offset, kMCStringOptionCompareExact, t_end);
            
			/* UNCHECKED */ MCStringCopySubstring(p_filter, MCRangeMake(t_offset, t_end-t_offset), r_result);
		}

		t_result = 0;
		r_value = MCValueRetain(*t_value);
	}
	else
		r_result = MCValueRetain(MCNameGetString(MCN_cancel));

	waitonbutton();

	return t_result;
}
Exemplo n.º 23
0
int MCA_ask_file_with_types(MCExecPoint& ep, const char *p_title, const char *p_prompt, char * const p_types[], uint4 p_type_count, const char *p_initial, unsigned int p_options)
{
	if (!MCModeMakeLocalWindows())
	{
		bool t_plural = (p_options & MCA_OPTION_PLURAL) != 0;
		char *t_resolved_path = MCS_resolvepath(p_initial);
		char **t_rtypes;
		if (types_to_remote_types(p_types, p_type_count, t_rtypes))
		{
			MCRemoteFileDialog(ep, p_title, p_prompt, t_rtypes, p_type_count * 2, NULL, t_resolved_path, true, t_plural);
			MCCStringArrayFree(t_rtypes, p_type_count * 2);
		}
		delete t_resolved_path;
		return 1;
	}

	GtkWidget *dialog ;
	
	dialog = create_open_dialog( p_title == NULL  ? p_prompt : p_title, GTK_FILE_CHOOSER_ACTION_SAVE );

	if ( p_type_count > 0 ) 
		add_dialog_filters ( dialog, p_types , p_type_count );

	// If we are given an initial
	if (p_initial != nil)
	{
		if (MCS_exists(p_initial, True))
		{
			char *t_path;
			t_path = MCS_resolvepath(p_initial);
			gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), t_path);
			delete t_path;
		}
		else
		{
			char *t_folder;
			const char *t_name;
			if (strchr(p_initial, '/') == NULL)
			{
				t_folder = NULL;
				t_name = p_initial;
			}
			else
			{
				t_folder = strdup(p_initial);
				strrchr(t_folder, '/')[0] = '\0';
				t_name = strrchr(p_initial, '/') + 1;
				if (MCS_exists(t_folder, False))
				{
					char *t_new_folder;
					t_new_folder = MCS_resolvepath(t_folder);
					delete t_folder;
					t_folder = t_new_folder;
				}
				else
					t_folder = NULL;
			}
			gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), t_folder == NULL ? G_last_saved_path : t_folder);
			gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), t_name);
			delete t_folder;
		}
	}
	else
	{
		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), G_last_saved_path);
	}
	
	run_dialog ( dialog, ep) ;

	MCresult -> clear();
	MCresult -> copysvalue(get_current_filter_name ( dialog ) );
	

	if (G_last_saved_path != NULL)
		g_free(G_last_saved_path);
	G_last_saved_path = gtk_file_chooser_get_current_folder ( GTK_FILE_CHOOSER ( dialog ) ) ;

	close_dialog ( dialog ) ;
        
        return(1);
	
}
Exemplo n.º 24
0
// This call is primarily designed to be used by the plugin installer. As this
// is generally installed 'per-user', we simply scan '/proc' for processes owned
// by the calling user.
bool MCSystemListProcesses(MCSystemListProcessesCallback p_callback, void* p_context)
{
	bool t_success;
	t_success = true;

	DIR *t_dir;
	t_dir = nil;
	if (t_success)
	{
		t_dir = opendir("/proc");
		if (t_dir == nil)
			t_success = false;
	}

	if (t_success)
	{
		dirent *t_entry;
		while(t_success)
		{
			// Fetch the next entry
			t_entry = readdir(t_dir);
			if (t_entry == nil)
				break;

			// Work out if the entry is a process id
			int32_t t_pid;
            MCAutoStringRef t_dname;
            /* UNCHECKED */ MCStringCreateWithCString(t_entry -> d_name, &t_dname);
			if (!MCU_strtol(*t_dname, t_pid))
				continue;

			// Work out the full path ("/proc/<int>") and stat so we can
			// check ownership.
			char t_path[6 + I4L + 1];
			struct stat64 t_stat;
			sprintf(t_path, "/proc/%u", t_pid);
			stat64(t_path, &t_stat);
			if (t_stat . st_uid != getuid())
				continue;

			// We have a viable process to report. First fetch its path
            MCAutoStringRef t_exe_link, t_exe_path;
            /* UNCHECKED */ MCStringFormat(&t_exe_link, "/proc/%u/exe", t_pid);
			if (!MCS_resolvepath(*t_exe_link, &t_exe_path))
			{
				t_success = false;
				break;
			}

			// Next fetch its 'description' from the first line of the status
			// file.
			char t_status_file[6 + I4L + 7 + 1];
			char t_status[256];
			FILE *t_stream;
			sprintf(t_status_file, "/proc/%u/status", t_pid);
			t_stream = fopen(t_status_file, "r");
			if (t_stream != nil)
			{
				if (fgets(t_status, 256, t_stream) != nil)
				{
					char *t_tab;
					t_tab = strchr(t_status, '\t');
					if (t_tab != nil)
						MCMemoryMove(t_status, t_tab + 1, MCCStringLength(t_tab + 1));
				}
				else
					t_status[0] = '\0';
				fclose(t_stream);
			}
			else
				t_status[0] = '\0';

            MCAutoStringRef t_status_str;
            /* UNCHECKED */ MCStringCreateWithSysString(t_status, &t_status_str);
			t_success = p_callback(p_context, t_pid, *t_exe_path, *t_status_str);
		}
	}

	if (t_dir != nil)
		closedir(t_dir);

	return t_success;
}
Exemplo n.º 25
0
Exec_stat MCAndroidPlayerControl::Set(MCNativeControlProperty p_property, MCExecPoint &ep)
{
    bool t_bool = false;
    int32_t t_integer;
    
    jobject t_view;
    t_view = GetView();
    
    switch (p_property)
    {
        case kMCNativeControlPropertyContent:
        {
            bool t_success = true;
            MCCStringFree(m_path);
            t_success = MCCStringClone(ep.getcstring(), m_path);
            if (MCCStringBeginsWith(m_path, "http://") || MCCStringBeginsWith(m_path, "https://"))
            {
                MCAndroidObjectRemoteCall(t_view, "setUrl", "bs", &t_success, m_path);
            }
            else
            {
                char *t_resolved_path = nil;
                bool t_is_asset = false;
                const char *t_asset_path = nil;
                
                t_resolved_path = MCS_resolvepath(m_path);
                t_is_asset = path_to_apk_path(t_resolved_path, t_asset_path);
                
                MCAndroidObjectRemoteCall(t_view, "setFile", "bsb", &t_success, t_is_asset ? t_asset_path : t_resolved_path, t_is_asset);
                
                MCCStringFree(t_resolved_path);
            }
            return ES_NORMAL;
        }
            
        case kMCNativeControlPropertyShowController:
        {
            if (!ParseBoolean(ep, t_bool))
                return ES_ERROR;
            MCAndroidObjectRemoteCall(t_view, "setShowController", "vb", nil, t_bool);
            return ES_NORMAL;
        }
            
        case kMCNativeControlPropertyCurrentTime:
        {
            if (!ParseInteger(ep, t_integer))
                return ES_ERROR;
            MCAndroidObjectRemoteCall(t_view, "setCurrentTime", "vi", nil, t_integer);
            return ES_NORMAL;
        }
            
        case kMCNativeControlPropertyLooping:
        {
            if (!ParseBoolean(ep, t_bool))
                return ES_ERROR;
            MCAndroidObjectRemoteCall(t_view, "setLooping", "vb", nil, t_bool);
            return ES_NORMAL;
        }
            
        default:
            break;
    }
    
    return MCAndroidControl::Set(p_property, ep);
}