Exemplo n.º 1
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//config_backup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int config_backup(char *filename)
{
	char bakfile[MAX_PATH];
	sprintf(bakfile, "%s.bak", filename);

	char temp[MAX_PATH + 500];
	sprintf(temp,
		"%s"
		"\n"
		"\nPlease note that the script format in this version is not compatible "
		"\nto the previous version."
		"\n"
		"\nYour original script will be backed up as:"
		"\n%s"
		, szVersion, bakfile
	);
	BBMessageBox(NULL, temp, szAppName, MB_OK|MB_SYSTEMMODAL);

	if (!FileExists(bakfile) || IDYES == BBMessageBox(NULL,
			"Backup file already exists. Overwrite?",
			szAppName, MB_YESNO|MB_SYSTEMMODAL
			))
		CopyFile(filename, bakfile, FALSE);

	return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//controltype_button_startup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_networkmonitor_startup()
{
	//This code stolen from the bb4win SDK example

	//Initialize the usages to 0.0 to start
	for (int i = 0; i < AGENTTYPE_NETWORKMONITOR_NUMINTERFACES; i++)
	{
		for(int j = 0; j < AGENTTYPE_NETWORKMONITOR_NUMTYPES; j++)
		{
			agenttype_networkmonitor_previous_values[i][j] = -1.0;
			agenttype_networkmonitor_values[i][j] = 0.0;
			StrFormatByteSizeOrg(0,agenttype_networkmonitor_textvalues[i][j]);
		}
	}

	//Create the list
	agenttype_networkmonitor_agents = list_create();

	//Register the window class
	agenttype_networkmonitor_windowclassregistered = false;
	if (window_helper_register(agenttype_networkmonitor_timerclass, &agenttype_networkmonitor_event))
	{
		//Couldn't register the window
		BBMessageBox(NULL, "failed on register class", "test", MB_OK);
		return 1;
	}
	agenttype_networkmonitor_windowclassregistered = true;

	//Create the window
	agenttype_networkmonitor_window = window_helper_create(agenttype_networkmonitor_timerclass);
	if (!agenttype_networkmonitor_window)
	{
		//Couldn't create the window
		BBMessageBox(NULL, "failed on window", "test", MB_OK);
		return 1;
	}


		//If we got this far, we can successfully use this function
		//Register this type with the AgentMaster
	agent_registertype(
		"Network Monitor",                   //Friendly name of agent type
		"NetworkMonitor",                    //Name of agent type
		CONTROL_FORMAT_DOUBLE|CONTROL_FORMAT_TEXT,				//Control type
		false,
		&agenttype_networkmonitor_create,
		&agenttype_networkmonitor_destroy,
		&agenttype_networkmonitor_message,
		&agenttype_networkmonitor_notify,
		&agenttype_networkmonitor_getdata,
		&agenttype_networkmonitor_menu_set,
		&agenttype_networkmonitor_menu_context,
		&agenttype_networkmonitor_notifytype
		);

	//No errors
	return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//controltype_button_startup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_systeminfo_startup()
{
	//Create the list
	agenttype_systeminfo_agents = list_create();

	//Register the window class
	agenttype_systeminfo_windowclassregistered = false;
	if (window_helper_register(agenttype_systeminfo_timerclass, &agenttype_systeminfo_event))
	{
		//Couldn't register the window
		BBMessageBox(NULL, L"failed on register class", L"test", MB_OK);
		return 1;
	}
	agenttype_systeminfo_windowclassregistered = true;

	//Create the window
	agenttype_systeminfo_window = window_helper_create(agenttype_systeminfo_timerclass);
	if (!agenttype_systeminfo_window)
	{
		//Couldn't create the window
		BBMessageBox(NULL, L"failed on window", "test", MB_OK);
		return 1;
	}
	
	//initialize
	for (int i = 1; i < SYSTEMINFO_NUMTYPES; i++){
		agenttype_systeminfo_updatevalue(i);
	}

	//If we got this far, we can successfully use this function
	//Register this type with the AgentMaster
	agent_registertype(
		L"System Information",                   //Friendly name of agent type
		L"SystemInfo",                    //Name of agent type
		CONTROL_FORMAT_TEXT,				//Control type
		false,
		&agenttype_systeminfo_create,
		&agenttype_systeminfo_destroy,
		&agenttype_systeminfo_message,
		&agenttype_systeminfo_notify,
		&agenttype_systeminfo_getdata,
		&agenttype_systeminfo_menu_set,
		&agenttype_systeminfo_menu_context,
		&agenttype_systeminfo_notifytype
		);

	//No errors
	return 0;
}
Exemplo n.º 4
0
// --------------------------------------------
void Desk_Init(void)
{
    if (Settings_disableDesk)
        ;
    else
    if (Settings_desktopHook)
    {
        if (load_imp(&pSetHooks, deskhook_dll, "SetHooks"))
            pSetHooks(BBhwnd, g_underExplorer);
        else
            BBMessageBox(MB_OK, NLS2("$Error_DesktopHook$",
                "Error: %s not found!"), deskhook_dll);
    }
    else
    {
        BBRegisterClass(szDesktopName, Desk_WndProc, BBCS_VISIBLE);
        CreateWindowEx(
            WS_EX_TOOLWINDOW,
            szDesktopName,
            NULL,
            WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
            0,0,0,0,
            GetDesktopWindow(),
            NULL,
            hMainInstance,
            NULL
            );
    }
    Desk_new_background(NULL);
}
Exemplo n.º 5
0
BOOL BBRegisterClass (WNDCLASS *pWC)
{
	if (RegisterClass(pWC)) return 1;
	BBMessageBox(MB_OK, NLS2("$BBError_RegisterClass$",
							 "Error: Could not register \"%s\" window class."), pWC->lpszClassName);
	return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_networkmonitor_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_networkmonitor_create(agent *a, char *parameterstring)
{


	if (0 == * parameterstring)
		return 2; // no param, no agent

	//Find the monitor type
	int monitor_interface_number = AGENTTYPE_NETWORKMONITOR_NUMINTERFACES;
	for (int i = 0; i < AGENTTYPE_NETWORKMONITOR_NUMINTERFACES; i++)
	{
		if (stricmp(agenttype_networkmonitor_interface_numbers[i], parameterstring) == 0)
		{
			monitor_interface_number = i;
			break;
		}
	}

	//If we didn't find a correct monitor type
	if (monitor_interface_number == AGENTTYPE_NETWORKMONITOR_NUMINTERFACES)
	{
		//On an error
		if (!plugin_suppresserrors)
		{
			char buffer[1000];
			sprintf(buffer,	"There was an error setting the Network Monitor agent:\n\nType \"%s\" is not a valid type.", parameterstring);
			BBMessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
		}
		return 1;
	}

	//Create the details
	agenttype_networkmonitor_details *details = new agenttype_networkmonitor_details;
	details->monitor_interface_number = monitor_interface_number;

	//Create a unique string to assign to this (just a number from a counter)
	char identifierstring[64];
	sprintf(identifierstring, "%ul", agenttype_networkmonitor_counter);
	details->internal_identifier = new_string(identifierstring);
	details->monitor_types = NETWORKMONITOR_TYPE_TOTAL;

	//Set the details
	a->agentdetails = (void *)details;

	//Add this to our internal tracking list
	agent *oldagent; //Unused, but we have to pass it
	list_add(agenttype_networkmonitor_agents, details->internal_identifier, (void *) a, (void **) &oldagent);

	//Increment the counter
	agenttype_networkmonitor_counter++;

	if (!agenttype_networkmonitor_hastimer)
	{
		SetTimer(agenttype_networkmonitor_window, 0, 1000, agenttype_networkmonitor_timercall);
		agenttype_networkmonitor_hastimer = true;
	}

	//No errors
	return 0;
}
Exemplo n.º 7
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//config_save
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int config_save(char *filename)
{
	config_file_out = config_open(filename, "wt");
	if (config_file_out)
	{
		//Save plugin specific data
		plugin_save();

		//Save module data
		module_save_list();

		//Save agent type specific data
		agent_save();

		//Save control type data AND control data
		control_save();

		//Close the file
		fclose(config_file_out);

		if (0 == _stricmp(config_path_mainscript, filename))
			check_mainscript_filetime();

		//Save the other files, too
		module_save_all();
		return 0;
	}

	//Must have had an error
	if (!plugin_suppresserrors) BBMessageBox(NULL, "There was an error saving the configuration file.", szAppName, MB_OK|MB_SYSTEMMODAL);
	return 1;
}
Exemplo n.º 8
0
void ShowRecoverMenu(void)
{
    getWorkspaces().GatherWindows();
    if (Settings_altMethod) {
        ShowMenu(MakeRecoverMenu(true));
    } else {
        BBMessageBox(MB_OK, "Windows gathered in current workspace.");
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//controltype_button_startup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_diskspacemonitor_startup()
{
	//Create the list
	agenttype_diskspacemonitor_agents = list_create();

	//Register the window class
	agenttype_diskspacemonitor_windowclassregistered = false;
	if (window_helper_register(agenttype_diskspacemonitor_timerclass, &agenttype_diskspacemonitor_event))
	{
		//Couldn't register the window
		BBMessageBox(NULL, "failed on register class", "test", MB_OK);
		return 1;
	}
	agenttype_diskspacemonitor_windowclassregistered = true;

	//Create the window
	agenttype_diskspacemonitor_window = window_helper_create(agenttype_diskspacemonitor_timerclass);
	if (!agenttype_diskspacemonitor_window)
	{
		//Couldn't create the window
		BBMessageBox(NULL, "failed on window", "test", MB_OK);
		return 1;
	}

	//If we got this far, we can successfully use this function
	//Register this type with the AgentMaster
	agent_registertype(
		"DiskSpace Monitor",                   //Friendly name of agent type
		"DiskSpaceMonitor",                    //Name of agent type
		CONTROL_FORMAT_SCALE|CONTROL_FORMAT_TEXT,				//Control type
		false,
		&agenttype_diskspacemonitor_create,
		&agenttype_diskspacemonitor_destroy,
		&agenttype_diskspacemonitor_message,
		&agenttype_diskspacemonitor_notify,
		&agenttype_diskspacemonitor_getdata,
		&agenttype_diskspacemonitor_menu_set,
		&agenttype_diskspacemonitor_menu_context,
		&agenttype_diskspacemonitor_notifytype
		);

	//No errors
	return 0;
}
Exemplo n.º 10
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//controltype_button_startup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_bitmap_startup()
{
	//Register this type with the ControlMaster
	agent_registertype(
		L"Bitmap",                           //Friendly name of agent type
		L"Bitmap",                           //Name of agent type
		CONTROL_FORMAT_IMAGE,               //Control type
		true,
		&agenttype_bitmap_create,           
		&agenttype_bitmap_destroy,
		&agenttype_bitmap_message,
		&agenttype_bitmap_notify,
		&agenttype_bitmap_getdata,
		&agenttype_bitmap_menu_set,
		&agenttype_bitmap_menu_context,
		&agenttype_bitmap_notifytype
		);

	//Register this type with the ControlMaster
	agent_registertype(
		L"Icon",                             //Friendly name of agent type
		L"Icon",                             //Name of agent type
		CONTROL_FORMAT_IMAGE,               //Control type
		true,
		&agenttype_icon_create,         
		&agenttype_bitmap_destroy,
		&agenttype_bitmap_message,
		&agenttype_bitmap_notify,
		&agenttype_bitmap_getdata,
		&agenttype_icon_menu_set,
		&agenttype_bitmap_menu_context,
		&agenttype_bitmap_notifytype
		);

	// Initialize GDI+
	if(Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) != 0)
	{
		BBMessageBox(0, L"Error starting GdiPlus.dll", szAppName, MB_OK | MB_ICONERROR | MB_TOPMOST);
		return 1;
	}

	//No errors
	return 0;
}
Exemplo n.º 11
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);
		BBMessageBox(NULL, config_line, szAppName, MB_OK|MB_SYSTEMMODAL);
	}
	return 1;
}
Exemplo n.º 12
0
BOOL BBRegisterClass (const char *classname, WNDPROC wndproc, int flags)
{
    WNDCLASS wc;
    memset(&wc, 0, sizeof(wc));
    wc.hInstance = hMainInstance;
    wc.lpszClassName = classname;
    wc.lpfnWndProc = wndproc;
    if (flags & BBCS_VISIBLE) {
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.style |= CS_DBLCLKS;
    }
    if ((flags & BBCS_DROPSHADOW) && usingXP)
        wc.style |= CS_DROPSHADOW;
    if (flags & BBCS_EXTRA)
        wc.cbWndExtra = sizeof(void*);
    if (RegisterClass(&wc))
        return 1;
    BBMessageBox(MB_OK, NLS2("$Error_RegisterClass$",
        "Error: Could not register \"%s\" window class."), classname);
    return 0;
}
Exemplo n.º 13
0
// --------------------------------------------
void Desk_Init(void)
{
    set_focus_model(Settings_focusModel);

    if (Settings_desktopHook || dont_hide_explorer)
    {
        DestopHookInstance = LoadLibrary("DesktopHook");
        *(FARPROC*)&pSetDesktopMouseHook = GetProcAddress(DestopHookInstance, "SetDesktopMouseHook" );
        *(FARPROC*)&pUnsetDesktopMouseHook = GetProcAddress(DestopHookInstance, "UnsetDesktopMouseHook" );
        if (pSetDesktopMouseHook)
            pSetDesktopMouseHook(BBhwnd, underExplorer);
        else
            BBMessageBox(MB_OK, NLS2("$BBError_DesktopHook$",
                "Error: DesktopHook.dll not found!"));
    }
    else
    {
        WNDCLASS wc;
        ZeroMemory(&wc, sizeof(wc));
        wc.hInstance = hMainInstance;
        wc.lpfnWndProc = Desk_WndProc;
        wc.lpszClassName = szDesktopName;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.style = CS_DBLCLKS;

        BBRegisterClass(&wc);
        CreateWindowEx(
            WS_EX_TOOLWINDOW,
            szDesktopName,
            NULL,
            WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
            0,0,0,0,
            GetDesktopWindow(),
            NULL,
            hMainInstance,
            NULL
            );
    }
    Desk_new_background();
}
Exemplo n.º 14
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//beginPlugin
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int beginPlugin(HINSTANCE hMainInstance)
{
	if (plugin_hwnd_blackbox)
	{
		MessageBox(plugin_hwnd_blackbox, "Dont load me twice!", szAppName, MB_OK|MB_SETFOREGROUND);
		return 1;
	}

	//Deal with instances
	plugin_instance_plugin = hMainInstance;
	plugin_hwnd_blackbox = GetBBWnd();

	const char *bbv = GetBBVersion();
	if (0 == _memicmp(bbv, "bblean", 6)) BBVersion = BBVERSION_LEAN;
	else
	if (0 == _memicmp(bbv, "bb", 2)) BBVersion = BBVERSION_XOB;
	else BBVersion = BBVERSION_09X;

	//Deal with os info
	plugin_getosinfo();

#ifdef BBINTERFACE_ALPHA_SOFTWARE
	int result = BBMessageBox(plugin_hwnd_blackbox,
		"WARNING!\n\n"
		"This is ALPHA software! Use at your own risk!\n\n"
		"The authors are not responsible in the event that:\n - your configuration is lost,\n - your computer blows up,\n - you are hit by a truck, or\n - anything else at all.\n\n"
		"Do you wish to continue loading this ALPHA software?",
		"BBInterface ALPHA Warning",
		MB_ICONWARNING|MB_DEFBUTTON2|MB_YESNO);
	if (result != IDYES) return 0;
#endif

	//Startup
	plugin_load = true;
	plugin_startup();

	return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_systemmonitor_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_systemmonitor_create(agent *a, char *parameterstring)
{


	if (0 == * parameterstring)
		return 2; // no param, no agent

	//Find the monitor type
	int monitor_type = SYSTEMMONITOR_TYPE_NONE;
	for (int i = 1; i < SYSTEMMONITOR_NUMTYPES; i++)
	{
		if (_stricmp(agenttype_systemmonitor_types[i], parameterstring) == 0)
		{
			monitor_type = i;
			break;
		}
	}

	//If we didn't find a correct monitor type
	if (monitor_type == SYSTEMMONITOR_TYPE_NONE)
	{
		//On an error
		if (!plugin_suppresserrors)
		{
			char buffer[1000];
			sprintf(buffer,	"There was an error setting the System Monitor agent:\n\nType \"%s\" is not a valid type.", parameterstring);
			BBMessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
		}
		return 1;
	}

	//Is this the first?
	bool first = (agenttype_systemmonitor_agents->first == NULL ? true : false);

	//Create the details
	agenttype_systemmonitor_details *details = new agenttype_systemmonitor_details;
	details->monitor_type = monitor_type;

	//Create a unique string to assign to this (just a number from a counter)
	char identifierstring[64];
	sprintf(identifierstring, "%ul", agenttype_systemmonitor_counter);
	details->internal_identifier = new_string(identifierstring);

	//Set the details
	a->agentdetails = (void *)details;

	//Add this to our internal tracking list
	agent *oldagent; //Unused, but we have to pass it
	list_add(agenttype_systemmonitor_agents, details->internal_identifier, (void *) a, (void **) &oldagent);

	//Increment the counter
	agenttype_systemmonitor_counter++;

	//If this is the first one
	if (first)
	{
		SetTimer(agenttype_systemmonitor_window, 0, 1000, agenttype_systemmonitor_timercall);
	}

	//No errors
	return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//controltype_button_startup
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_systemmonitor_startup()
{
	//This code stolen from the bb4win SDK example


	OSVERSIONINFO osvinfo;
	ZeroMemory(&osvinfo, sizeof(osvinfo));
	osvinfo.dwOSVersionInfoSize = sizeof (osvinfo);
	GetVersionEx(&osvinfo);
	isnt2kxp =	osvinfo.dwPlatformId == VER_PLATFORM_WIN32_NT;

	//Initialize the usages to 0.0 to start
	for (int i = 0; i < SYSTEMMONITOR_NUMTYPES; i++)
	{
		agenttype_systemmonitor_previous_values[i] = -1.0;
		agenttype_systemmonitor_values[i] = 0.0;
		strcpy(agenttype_systemmonitor_textvalues[i], "0%");
	}

	//Create the list
	agenttype_systemmonitor_agents = list_create();

	//Register the window class
	agenttype_systemmonitor_windowclassregistered = false;
	if (window_helper_register(agenttype_systemmonitor_timerclass, &agenttype_systemmonitor_event))
	{
		//Couldn't register the window
		BBMessageBox(NULL, "failed on register class", "test", MB_OK);
		return 1;
	}
	agenttype_systemmonitor_windowclassregistered = true;

	//Create the window
	agenttype_systemmonitor_window = window_helper_create(agenttype_systemmonitor_timerclass);
	if (!agenttype_systemmonitor_window)
	{
		//Couldn't create the window
		BBMessageBox(NULL, "failed on window", "test", MB_OK);
		return 1;
	}

	//Load the library
	if(isnt2kxp)
	{
		agenttype_systemmonitor_ntdllmodule = NULL;
		agenttype_systemmonitor_ntdllmodule = LoadLibrary("ntdll.dll");

		//Check to make sure it loaded properly
		if (agenttype_systemmonitor_ntdllmodule == NULL)
		{
			//We couldn't load the NTDLL library
			//Return immediately
			return 1;
			BBMessageBox(NULL, "failed on ntdll", "test", MB_OK);
		}

		//Get the NtQuerySystemInformation function
		agenttype_systemmonitor_ntquerysysteminformation = NULL;
		agenttype_systemmonitor_ntquerysysteminformation = (agenttype_systemmonitor_NtQuerySystemInformation) GetProcAddress(agenttype_systemmonitor_ntdllmodule, "NtQuerySystemInformation");

		//Check to make sure we could get the function
		if (agenttype_systemmonitor_ntquerysysteminformation == NULL)
		{
			//Error - couldn't get the function call
			FreeLibrary(agenttype_systemmonitor_ntdllmodule);
			BBMessageBox(NULL, "failed on get proc address", "test", MB_OK);
			return 1;
		}


		// @NOTE: this uses undocumented nt api.  GetSystemInfo is the way to go
		//Get the number of processors
		/*BOOL status;
		SYSTEM_BASIC_INFORMATION basicinformation;
		status = agenttype_systemmonitor_ntquerysysteminformation(agenttype_systemmonitor_SystemBasicInformation, &basicinformation, sizeof(basicinformation), NULL);
		if (status != NO_ERROR)
		{
			//Couldn't get the number of processors
			FreeLibrary(agenttype_systemmonitor_ntdllmodule);
			BBMessageBox(NULL, "failed on processor", "test", MB_OK);
			return 1;
		}*/

		SYSTEM_INFO sysinfo;
		GetSystemInfo( &sysinfo );

		//Record the number of processors
		agenttype_systemmonitor_number_processors = sysinfo.dwNumberOfProcessors;

		//If it is less than 1 or more than 64... assume an error (I don't think any super clusters are running BBI)
		if (agenttype_systemmonitor_number_processors < 1 || agenttype_systemmonitor_number_processors > 64)
		{
			FreeLibrary(agenttype_systemmonitor_ntdllmodule);
			BBMessageBox(NULL, "failed on number of processors", "test", MB_OK);
			return 1;
		}
	}

		//If we got this far, we can successfully use this function
		//Register this type with the AgentMaster
	agent_registertype(
		"System Monitor",                   //Friendly name of agent type
		"SystemMonitor",                    //Name of agent type
		CONTROL_FORMAT_SCALE|CONTROL_FORMAT_TEXT,				//Control type
		false,
		&agenttype_systemmonitor_create,
		&agenttype_systemmonitor_destroy,
		&agenttype_systemmonitor_message,
		&agenttype_systemmonitor_notify,
		&agenttype_systemmonitor_getdata,
		&agenttype_systemmonitor_menu_set,
		&agenttype_systemmonitor_menu_context,
		&agenttype_systemmonitor_notifytype
		);

	//No errors
	return 0;
}
Exemplo n.º 17
0
void BBKeys_LoadHotkeys(HWND hwnd)
{
    FILE *fp;
    HotkeyType **ppHk, *h;
    int nID;
    unsigned linenum;
    int id, l;
    bool debug;

    if (false == FindRCFile(rcpath, "bbkeys", g_hInstance))
        return;

    fp = fopen(rcpath, "rb");
    if (NULL == fp)
        return;

    showlabel = true;
    debug = false;
    linenum = 0;
    nID = 1;
    ppHk = &g_hotKeys;

    for (;;)
    {
        char buffer[MAX_LINE_LENGTH];
        char keytograb[MAX_LINE_LENGTH];
        char action[MAX_LINE_LENGTH];
        char command[MAX_LINE_LENGTH];

        unsigned vkey;
        unsigned modifier;
        bool is_ExecCommand;
        char *k;

        if (false == read_line(buffer, sizeof buffer, fp)) {
            fclose(fp);
            break;
        }

        ++linenum;
        if (*buffer == '!' || *buffer == '#' || *buffer == 0)
            continue;

        if (*buffer == '-') {
            if (0 == stricmp("NOLABEL", buffer+1)) {
                showlabel = false;
                continue;
            }
            if (0 == stricmp("DEBUG", buffer+1)) {
                debug = true;
                continue;
            }
        }

        getparam(buffer, "KEYTOGRAB", keytograb, false);
        k = strchr(keytograb, 0);

        getparam(buffer, "WITHMODIFIER", k+1, false);
        if (k[1])
            k[0] = '+';

        getparam(buffer, "DOTHIS", command, true);
        is_ExecCommand = 0 != command[0];

        getparam(buffer, "WITHACTION", action, false == is_ExecCommand);
        if (0 == stricmp(action, "ExecCommand"))
            strcpy(action, command);

        if (0 == action[0])
            continue;

        vkey = getkey(keytograb, &modifier);
        if (0 == vkey) {
            BBMessageBox(MB_OK,
                "bbKeys.rc:%u: Invalid hotkey: %s -> %s",
                linenum, keytograb, action);
            continue;
        }

        id = nID;
        if (VK_LWIN == vkey || VK_RWIN == vkey) {
            if (GetUnderExplorer())
                continue;
            if (false == usingNT || set_kbdhook(true))
                id = 0;
            else
                modifier |= MOD_WIN;
        }

        for (h = g_hotKeys; h; h = h->next)
            if (h->vkey == vkey && h->modifier == modifier)
                break;

        if (h) {
            BBMessageBox(MB_OK,
                "bbKeys.rc:%u and %u: Hotkey defined twice: %s: '%s','%s'",
                h->linenum, linenum, keytograb, h->action, action);
            continue;
        }

        if (id) {
            if (0 == RegisterHotKey(hwnd, id, modifier, vkey)) {
                if (debug)
                    BBMessageBox(MB_OK,
                        "bbKeys.rc:%u: Unable to register hotkey: %s -> %s",
                        linenum, keytograb, action);
                continue;
            }
            ++nID;
        }

        l = strlen(action);
        h = (HotkeyType *)malloc(sizeof (HotkeyType) + l);
        h->id       = id;
        h->linenum  = linenum;
        h->modifier = modifier;
        h->vkey     = vkey;
        h->is_ExecCommand = is_ExecCommand;
        memcpy(h->action, action, 1+l);
        *(ppHk=&(*ppHk=h)->next)=NULL;

        //dbg_printf("hotkey: (%s) -> %s", keytograb, action);
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_systeminfo_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_systeminfo_create(agent *a, wchar_t *parameterstring)
{


	if (0 == * parameterstring)
		return 2; // no param, no agent

	//Find the monitor type
	int monitor_type = SYSTEMINFO_TYPE_NONE;
	for (int i = 1; i < SYSTEMINFO_NUMTYPES; i++)
	{
		if (_wcsicmp(agenttype_systeminfo_types[i], parameterstring) == 0)
		{
			monitor_type = i;
			break;
		}
	}

	//If we didn't find a correct monitor type
	if (monitor_type == SYSTEMINFO_TYPE_NONE)
	{
		//On an error
		if (!plugin_suppresserrors)
		{
			wchar_t buffer[1000];
			swprintf(buffer,1000, L"There was an error setting the System Information agent:\n\nType \"%s\" is not a valid type.", parameterstring);
			BBMessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
		}
		return 1;
	}
	
	//Create the details
	agenttype_systeminfo_details *details = new agenttype_systeminfo_details;
	details->monitor_type = monitor_type;
	
	//Create a unique string to assign to this (just a number from a counter)
	wchar_t identifierstring[64];
	swprintf(identifierstring, L"%ul", agenttype_systeminfo_counter);
	details->internal_identifier = new_string(identifierstring);

	//Set the details
	a->agentdetails = (void *)details;

	//Add this to our internal tracking list ( need update value only )
	if(details->monitor_type == SYSTEMINFO_TYPE_UPTIME || details->monitor_type == SYSTEMINFO_TYPE_STYLENAME){
		agent *oldagent;
		list_add(agenttype_systeminfo_agents, details->internal_identifier, (void *) a, (void **) &oldagent);
		agenttype_systeminfo_updatevalue(details->monitor_type);
		//Start Timer 
		if (!agenttype_systeminfo_hastimer)
		{
			SetTimer(agenttype_systeminfo_window, 0, 1000, agenttype_systeminfo_timercall);
			agenttype_systeminfo_hastimer = true;
		}
	}
	//Increment the counter
	agenttype_systeminfo_counter++;


	//No errors
	return 0;
}
Exemplo n.º 19
0
void notice (const char * message)
{
	if (!plugin_suppresserrors)
		BBMessageBox(NULL, message, szAppName, MB_OK | MB_SYSTEMMODAL);
}
Exemplo n.º 20
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//plugin_message
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int plugin_message(int tokencount, char *tokens[], bool from_core, module* caller)
{
	char *filename;

	if (tokencount == 3 && !_stricmp(tokens[2], szBActionSave))
	{
		config_save(config_path_mainscript);
		return 0;
	}
	else if (!_stricmp(tokens[2], szBActionSaveAs))
	{
		if (tokencount == 4)
		{
			config_save(tokens[3]);
		}
		else
		{       
			if ((filename = dialog_file(szFilterScript, "Save Configuration Script", ".rc", config_path_plugin, true)))
			{
				config_save(filename);
			}           
		}       
		return 0;
	}
	else if (tokencount == 3 && !_stricmp(tokens[2], szBActionRevert))
	{
		plugin_reconfigure(true);
		return 0;
	}
	else if (!_stricmp(tokens[2], szBActionLoad))
	{
		if (tokencount == 4)
		{
			config_load2(tokens[3], caller);
			return 0;
		}
		else if (tokencount == 3)
		{
			if ((filename = dialog_file(szFilterScript, "Load Configuration Script", ".rc", config_path_plugin, false)))
			{
				config_load2(filename, caller);
			}
			return 0;
		}
		else if (tokencount == 6)
		{
			if (0 == _stricmp(tokens[4], "from"))
			{
				config_load(tokens[5], caller, tokens[3]);
				return 0;
			} else if (0 == _stricmp(tokens[4], "into"))
			{
				config_load(tokens[3], module_get(tokens[5]));
				return 0;
			}
		}
		else if (tokencount == 8 && 0 == _stricmp(tokens[4], "from") && 0 == _stricmp(tokens[6], "into"))
		{
			config_load(tokens[5], module_get(tokens[7]), tokens[3]);
			return 0;
		}
	}
	else if (!_stricmp(tokens[2], szBActionAbout))
	{
		if (tokencount == 3)
		{
			BBMessageBox(NULL, szPluginAbout, szVersion, MB_OK|MB_SYSTEMMODAL);
			return 0;
		}
		else if (tokencount == 4 && !_stricmp(tokens[3], "LastControl"))
		{
			BBMessageBox(NULL, szPluginAboutLastControl, szAppName, MB_OK|MB_SYSTEMMODAL);
			return 0;
		}
		else if (tokencount == 4 && !_stricmp(tokens[3], "QuickHelp"))
		{
			BBMessageBox(NULL, szPluginAboutQuickRef, szAppName, MB_OK|MB_SYSTEMMODAL);
			return 0;
		}
	}
	else if (!_stricmp(tokens[2], szBActionEdit))
	{
		//SendMessage(plugin_hwnd_blackbox, BB_EDITFILE, (WPARAM)-1, (LPARAM) config_path_mainscript);
		//return 0;
		char temp[MAX_PATH]; GetBlackboxEditor(temp);
		BBExecute(NULL, "",temp , config_path_mainscript, NULL, SW_SHOWNORMAL, false);
		return 0;
	}
	else if (tokencount == 5 && !_stricmp(tokens[2], szBActionSetPluginProperty))
	{
		for (struct plugin_properties *p = plugin_properties; p->key; p++)
			if (p->data && 0 == _stricmp(tokens[3], p->key)) {
				switch (p->type) {
					case M_BOL:
						if (config_set_bool(tokens[4], (bool*)p->data)) break; return 1;
					case M_INT:
						if (config_set_int(tokens[4], (int*)p->data)) break; return 1;
					case M_STR:
						if (config_set_str(tokens[4], (char**)p->data)) break; return 1;
					default: return 1;
				}
				if (p->update) control_invalidate();
				if (from_core) menu_update_global();
				return 0;
			}
	}
	else if (tokencount == 4 && !_stricmp(tokens[2], szBActionOnLoad) )
	{
		config_set_str(tokens[3],&(globalmodule.actions[MODULE_ACTION_ONLOAD]));
		return 0;
	}
	else if (tokencount == 4 && !_stricmp(tokens[2], szBActionOnUnload) )
	{
		config_set_str(tokens[3],&(globalmodule.actions[MODULE_ACTION_ONUNLOAD]));
		return 0;
	}
	return 1;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_diskspacemonitor_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_diskspacemonitor_create(agent *a, char *parameterstring)
{


	if (0 == * parameterstring)
		return 2; // no param, no agent

	//Find the monitor type
	int monitor_type = DISKSPACEMONITOR_TYPE_NONE;
	for (int i = 1; i < DISKSPACEMONITOR_NUMTYPES; i++)
	{
		if (_stricmp(agenttype_diskspacemonitor_types[i], parameterstring) == 0)
		{
			monitor_type = i;
			break;
		}
	}

	//If we didn't find a correct monitor type
	if (monitor_type == DISKSPACEMONITOR_TYPE_NONE)
	{
		//On an error
		if (!plugin_suppresserrors)
		{
			char buffer[1000];
			sprintf(buffer,	"There was an error setting the Disk Space Monitor agent:\n\nType \"%s\" is not a valid type.", parameterstring);
			BBMessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
		}
		return 1;
	}

	//Is this the first?
	bool first = (agenttype_diskspacemonitor_agents->first == NULL ? true : false);

	//Create the details
	agenttype_diskspacemonitor_details *details = new agenttype_diskspacemonitor_details;
	details->monitor_type = monitor_type;
	details->value=-1.0;
	details->previous_value = 0;
	details->path=NULL;
	strcpy(details->str_value,"");
	
	//Create a unique string to assign to this (just a number from a counter)
	char identifierstring[64];
	sprintf(identifierstring, "%ul", agenttype_diskspacemonitor_counter);
	details->internal_identifier = new_string(identifierstring);

	//Set the details
	a->agentdetails = (void *)details;
	agenttype_diskspacemonitor_updatevalue(details);
	control_notify(a->controlptr,NOTIFY_NEEDUPDATE,NULL);
	
	//Add this to our internal tracking list
	agent *oldagent; //Unused, but we have to pass it
	list_add(agenttype_diskspacemonitor_agents, details->internal_identifier, (void *) a, (void **) &oldagent);

	//Increment the counter
	agenttype_diskspacemonitor_counter++;

	if (!agenttype_diskspacemonitor_hastimer)
	{
		SetTimer(agenttype_diskspacemonitor_window, 0, 10000, agenttype_diskspacemonitor_timercall);
		agenttype_diskspacemonitor_hastimer = true;
	}

	//No errors
	return 0;
}