Ejemplo n.º 1
0
LRESULT CALLBACK message_event(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static const int message_blackboxmessages[] = {BB_RECONFIGURE, BB_BROADCAST, BB_DESKCLICK, BB_DRAGTODESKTOP, BB_HIDEMENU, BB_TASKSUPDATE,BB_WORKSPACE,0};

    switch(msg)
    {
    case WM_CREATE:
        //Register the window to recieve BlackBox events
        SendMessage(plugin_hwnd_blackbox, BB_REGISTERMESSAGE, (WPARAM)hwnd, (LPARAM)message_blackboxmessages);
        break;

    case WM_DESTROY:
        //Unregister to recieve BlackBox events
        SendMessage(plugin_hwnd_blackbox, BB_UNREGISTERMESSAGE, (WPARAM)hwnd, (LPARAM)message_blackboxmessages);
        break;

    case BB_DRAGTODESKTOP:
        if (NULL == plugin_desktop_drop_command) return false;
        if (!(wParam & 1))
        {
            variables_set(false,"DroppedFile", (const char *)lParam);
            message_interpret(plugin_desktop_drop_command, false, NULL);
        }
        return true;
    case BB_TASKSUPDATE:
        controls_updatetasks();
        break;
    case BBI_POSTCOMMAND:
        SendMessage(plugin_hwnd_blackbox, BB_BROADCAST, 0, lParam);
        delete (char *)lParam;
        break;

    case BB_RECONFIGURE:
        plugin_reconfigure(false);
        break;

    case BB_DESKCLICK:
        if (lParam == 0)
            controls_clickraise();
        break;

    case BB_BROADCAST:
        message_interpret((const char *)lParam, true, NULL);
        break;

    case WM_TIMER:
        KillTimer(hwnd, wParam);
        if (1 == wParam)
            config_backup(config_path_mainscript);
        break;

    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}
Ejemplo n.º 2
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//plugin_startup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void plugin_startup()
{
	//Startup the configuration system
	config_startup();

	//Startup style system
	style_startup();

	//Startup window system
	window_startup();

	menu_startup();

	//Startup controls and agents
	variables_startup();
	control_startup();
	agent_startup();

	//Startup message & dialog system
	message_startup();
	dialog_startup();

	//Startup control types
	plugin_controls_startup();

	//Startup agent types
	plugin_agents_startup();

	tooltip_startup();
	module_startup();

	//Load the config file
	if (0 == config_load(config_path_mainscript, &globalmodule))
	{
		check_mainscript_filetime();
		if (!check_mainscript_version())
			SetTimer(message_window, 1, 1000, NULL);
	}
	control_checklast();

	message_interpret(globalmodule.actions[MODULE_ACTION_ONLOAD], false, &globalmodule);

}
Ejemplo n.º 3
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int config_load(char *filename, module* caller, const char *section)
{
	//Open the file
	FILE *config_file_in = config_open(filename, "rt");

	char config_line[BBI_MAX_LINE_LENGTH];
	if (config_file_in)
	{
		bool wanted_section = NULL == section;
		while (config_read_line(config_line, config_file_in))
		{
			if (config_line[0] == '[')
			{
				if (wanted_section) break;
				if (0 == stricmp(config_line, section))
					wanted_section = true;
				continue;
			}

			if (false == wanted_section)
				continue;

			if (config_line[0] == '@')
			{
				//Interpret the message
				message_interpret(config_line, false, caller);
			}
		}
		//Close the file
		fclose(config_file_in);
		return 0;
	}

	//Must have been an error
	if (!plugin_suppresserrors)
	{
		sprintf(config_line, "%s:\nThere was an error loading the configuration file.", filename);
		MessageBox(NULL, config_line, szAppName, MB_OK|MB_SYSTEMMODAL);
	}
	return 1;
}
Ejemplo n.º 4
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//plugin_shutdown
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void plugin_shutdown(bool save)
{
	message_interpret(globalmodule.actions[MODULE_ACTION_ONUNLOAD], false, &globalmodule);

	//Save config settings
	if (save) config_save(config_path_mainscript);

	//Shutdown the message & dialog system
	message_shutdown();
	dialog_shutdown();

	//Shutdown agents and controls
	variables_shutdown();
	module_shutdown();
	control_shutdown();
	agent_shutdown();   

	//Shutdown the windowing system
	window_shutdown();
	
	//Shutdown the style system.
	style_shutdown();

	//Shutdown control types
	plugin_controls_shutdown();

	//Shutdown agents
	plugin_agents_shutdown();

	tooltip_shutdown();

	//Shutdown the configuration system
	config_shutdown();

	menu_shutdown();

}
Ejemplo n.º 5
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//message_interpret
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void message_interpret(const char *message, bool from_core, module* caller)
{
    if (!message || !(*message)) return; //If the message is invalid, or empty, don't bother
    if (caller == NULL) caller = currentmodule;

    char buffer[BBI_MAX_LINE_LENGTH];

    // Check, if the message is for us...
    if (memcmp(message, szBBroam, szBBroamLength))
    {
        //The standard BlackBox Messages
        if (!stricmp(message, "@BBShowPlugins"))
        {
            control_pluginsvisible(true);
            return;
        }
        if (!stricmp(message, "@BBHidePlugins"))
        {
            control_pluginsvisible(false);
            return;
        }
        if (!memicmp(message, "@Script",7))
        {
            char* buf = new char[strlen(message)+1]; // local buffer.
            strcpy(buf,message); //NOTE: possible alternate method would be copying out the messages one by one.
            char *start = strchr(buf,'[');
            char *end = strrchr(buf,']');
            if (start && end)
            {
                ++start;
                *end = 0; //terminate string here.
                while (end = strchr(start,'|'))
                {
                    *end = 0;
                    while (*start == ' ') ++start; // skip whitespace
                    message_interpret(start, from_core, caller);
                    start = end+1;
                }
                while (*start == ' ') ++start; // skip whitespace
                message_interpret(start, from_core, caller); // interpret message after last separator character
            }
            else if (!plugin_suppresserrors)
            {
                sprintf(buffer,"Invalid @Script syntax in line:\n\n%s",buf);
                MessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
            }
            delete[] buf;
            return;
        }

        if (from_core) return;
        message = message_preprocess(strcpy(buffer, message)); //NOTE: FIX, possibly should this use the caller argument as well?
        if ('@' == message[0])
        {
            SendMessage(plugin_hwnd_blackbox, BB_BROADCAST, 0, (LPARAM)buffer);
        }
        else
        {
            // bblean only: SendMessage(plugin_hwnd_blackbox, BB_EXECUTE, 0, (LPARAM)string);
            char command[MAX_PATH], arguments[MAX_PATH], *token = command;
            BBTokenize(message, &token, 1, arguments);
            shell_exec(command, arguments);
        }
        return;
    }
    //Tokenize the string
    char *message_tokenptrs[32];
    int tokensfound = tokenize_message(message, 32, message_tokenptrs, buffer, caller);

    //Token Check - we always need at least two tokens for all purposes
    if (tokensfound < 2) return;

    //Find someone to send the message to
    int result = 1;

    for (int i = 0; i < MESSAGE_ENTITY_COUNT; i++)
    {
        if (!strcmp(message_tokenptrs[1], message_entitynames[i]))
        {
            result = (message_functions[i])(tokensfound, message_tokenptrs, from_core, caller);
            break;
        }
    }

    if (1 == result) // 0=ok, 1=error, 2=error&dontcare
    {
        //On an error
        if (!plugin_suppresserrors)
        {
            sprintf(buffer,
                    "There was an error executing your Bro@m command:"
                    "\n"
                    "\n%s"
                    "\n"
                    "\nPossible reasons:"
                    "\n - An control or agent referenced may not exist"
                    "\n - The command may be malformed"
                    "\n - An error occurred while performing the requested action"
                    , message
                   );
            MessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
        }
    }
}