示例#1
0
BOOL WINAPIV LSLogPrintf(int nLevel, LPCSTR pszModule, LPCSTR pszFormat, ...)
{
#if defined(LS_COMPAT_LOGGING)
    if (!pszModule || !pszFormat)
    {
        return FALSE;
    }
    
    BOOL bReturn = FALSE;
    char szMessage[MAX_LINE_LENGTH];
    
    va_list argList;
    va_start(argList, pszFormat);
    
    if (SUCCEEDED(StringCchVPrintf(szMessage, MAX_LINE_LENGTH,
        pszFormat, argList)))
    {
        bReturn = LSLog(nLevel, pszModule, szMessage);
    }
    
    va_end(argList);
    
    return bReturn;
#else
    return TRUE;
#endif // LS_COMPAT_LOGGING
}
示例#2
0
static void lsr_deletedmanagederror(lua_State *L)
{
    lua_Debug ar;

    lua_getstack(L, 1, &ar);
    lua_getinfo(L, "nSl", &ar);
    LSLog(LSLogError, "Access deleted managed native at: %s %i", ar.source, ar.currentline);
    lua_pushstring(L, "Fatal Error");
    lua_error(L);
}
示例#3
0
/*
This function is called when new value should be measured.
The function returns the new value.
*/
UINT Update(UINT id)
{
	if (!CoInitialized || !InstanceCreated)
	{
		// Check if the iTunes window has appeared
		if (FindWindow(L"iTunesApp", L"iTunes") || FindWindow(L"iTunes", L"iTunes"))
		{
			if (!iTunesAboutToPromptUserToQuit && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, nullptr, CLSCTX_LOCAL_SERVER)))
			{
				InstanceCreated = true;
				initEventHandler();
			}
			else
			{
				LSLog(LOG_ERROR, nullptr, L"iTunesPlugin.dll: Unable to create instance");
				return 0;
			}
		}
		else
		{
			iTunesAboutToPromptUserToQuit = false;
			return 0;
		}
	}

	CCommandIdMap::const_iterator it = CommandIdMap.find(id);
	COMMAND_TYPE command = (it != CommandIdMap.end()) ? it->second : COMMAND_COUNT;

	switch (command)
	{
		case COMMAND_GETSOUNDVOLUME: // value: 0 ~ 100
		{
			long volume;
			iTunes->get_SoundVolume(&volume);
			return volume;
		}
		case COMMAND_GETPLAYERPOSITIONPERCENT: // value: 0 ~ 100
		{
			long pos;
			iTunes->get_PlayerPosition(&pos);
			if (!updateCurrentTrack())
				return 0;
			long duration;
			CurrentTrack->get_Duration(&duration);
			return duration ? pos * 100 / duration : 0;
		}
		case COMMAND_GETPLAYERPOSITION: // value: seconds
		{
			long pos;
			iTunes->get_PlayerPosition(&pos);
			return pos;
		}
	}
	return 0;
}
示例#4
0
void NativeInterface::dumpManagedNatives(lua_State *L)
{
    utHashTable<utPointerHashKey, int> count;

    lua_rawgeti(L, LUA_GLOBALSINDEX, LSINDEXMANAGEDNATIVESCRIPT);

    int tidx = lua_gettop(L);

    lua_pushnil(L); /* first key */
    while (lua_next(L, tidx) != 0)
    {
        lua_rawgeti(L, -1, LSINDEXTYPE);
        Type *type = (Type *)lua_topointer(L, -1);
        lua_pop(L, 1);

        if (count.find(type) == UT_NPOS)
        {
            count.insert(type, 1);
        }
        else
        {
            int *v = count.get(type);
            (*v)++;
        }

        /* removes 'value'; keeps 'key' for next iteration */
        lua_pop(L, 1);
    }

    lua_settop(L, tidx - 1);

    LSLog(LSLogInfo, "Dumping Managed Natives:");

    for (UTsize i = 0; i < count.size(); i++)
    {
        Type *type = (Type *)count.keyAt(i).key();
        int  v     = count.at(i);

        LSLog(LSLogInfo, "%s : %i", type->getFullName().c_str(), v);
    }
}
示例#5
0
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
	MeasureData* measure = new MeasureData;
	*data = measure;

	if (!g_Initialized)
	{
		if (GetSystemMetrics(SM_CMONITORS) > 32)
		{
			LSLog(LOG_ERROR, NULL, L"SysInfo.dll: Max amount of monitors supported is 32.");
		}

		m_Monitors.count = 0;
		EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, (LPARAM)(&m_Monitors));
		g_Initialized = true;
	}
}
示例#6
0
void LSLuaState::triggerRuntimeError(const char *format, ...)
{
    LSLog(LSLogError, "=====================");
    LSLog(LSLogError, "=   RUNTIME ERROR   =");
    LSLog(LSLogError, "=====================\n");

    char    buff[2048];
    va_list args;
    va_start(args, format);
#ifdef _MSC_VER
    vsprintf_s(buff, 2046, format, args);
#else
    vsnprintf(buff, 2046, format, args);
#endif
    va_end(args);

    if (buff)
    {
        LSLog(LSLogError, "%s", buff);
    }

    if (_tracemessage[0])
    {
        LSLog(LSLogError, "%s\n", _tracemessage);
    }

    _tracemessage[0] = 0;

    // coming from a native assert?
    if (!_tracestack.size())
    {
        _getCurrentStack(L, _tracestack);
    }

    LSLog(LSLogError, "Stacktrace:", buff);

    for (UTsize i = 0; i < _tracestack.size(); i++)
    {
        const stackinfo& s = _tracestack.peek(_tracestack.size() - i - 1);

        LSLog(LSLogError, "%s : %s : %i", s.methodBase->getFullMemberName(),
              s.source ? s.source : NULL, s.linenumber);
    }


    LSError("\nFatal Runtime Error\n\n");
}
示例#7
0
/*
This function is called when the measure is initialized.
The function must return the maximum value that can be measured.
The return value can also be 0, which means that Rainmeter will
track the maximum value automatically. The parameters for this
function are:

instance  The instance of this DLL
iniFile   The name of the ini-file (usually Rainmeter.ini)
section   The name of the section in the ini-file for this measure
id		The identifier for the measure. This is used to identify the measures that use the same plugin.
*/
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{
	if (!CoInitialized)
	{
		::CoInitialize(nullptr);
		wcsncpy(BaseDir, iniFile, MAX_PATH);
		BaseDir[MAX_PATH - 1] = 0;
		wchar_t* lastBackslash = wcsrchr(BaseDir, L'\\');
		if (lastBackslash)
			lastBackslash[1] = 0;
		CoInitialized = true;
	}

	if (CoInitialized && !InstanceCreated && (FindWindow(L"iTunesApp", L"iTunes") || FindWindow(L"iTunes", L"iTunes")))
	{
		if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, nullptr, CLSCTX_LOCAL_SERVER)))
		{
			InstanceCreated = true;
			initEventHandler();
		}
		else
		{
			LSLog(LOG_ERROR, nullptr, L"iTunesPlugin.dll: Unable to create instance");
		}
	}

	const wchar_t* type = ReadConfigString(section, L"Command", L"");
	for (int i = 0; i < COMMAND_COUNT; i++)
	{
		if (CommandName[i] && type && _wcsicmp(CommandName[i], type) == 0)
		{
			CommandIdMap[id] = (COMMAND_TYPE)i;

			if (COMMAND_GETCURRENTTRACK_ARTWORK == (COMMAND_TYPE)i)
			{
				const wchar_t* defaultArtwork = ReadConfigString(section, L"DefaultArtwork", L"");
				wcscpy(DefaultTrackArtworkPath, defaultArtwork);
			}
		}
	}

	return 0;
}
示例#8
0
void ExecuteBang(LPCTSTR args, UINT id)
{
	if (!CoInitialized)
	{
		return;
	}

	COMMAND_TYPE command;

	if (wcslen(args) == 0)
	{
		CCommandIdMap::const_iterator it = CommandIdMap.find(id);
		command = (it != CommandIdMap.end()) ? it->second : COMMAND_COUNT;
	}
	else
	{
		if (_wcsicmp(args, L"Backtrack") == 0)
		{
			command = COMMAND_BACKTRACK;
		}
		else if (_wcsicmp(args, L"FastForward") == 0)
		{
			command = COMMAND_FASTFORWARD;
		}
		else if (_wcsicmp(args, L"NextTrack") == 0)
		{
			command = COMMAND_NEXTTRACK;
		}
		else if (_wcsicmp(args, L"Pause") == 0)
		{
			command = COMMAND_PAUSE;
		}
		else if (_wcsicmp(args, L"Play") == 0)
		{
			command = COMMAND_PLAY;
		}
		else if (_wcsicmp(args, L"PlayPause") == 0)
		{
			command = COMMAND_PLAYPAUSE;
		}
		else if (_wcsicmp(args, L"Power") == 0)
		{
			command = COMMAND_POWER;
		}
		else if (_wcsicmp(args, L"PreviousTrack") == 0)
		{
			command = COMMAND_PREVIOUSTRACK;
		}
		else if (_wcsicmp(args, L"Resume") == 0)
		{
			command = COMMAND_RESUME;
		}
		else if (_wcsicmp(args, L"Rewind") == 0)
		{
			command = COMMAND_REWIND;
		}
		else if (_wcsicmp(args, L"Stop") == 0)
		{
			command = COMMAND_STOP;
		}
		else if (_wcsicmp(args, L"SoundVolumeUp") == 0)
		{
			command = COMMAND_SOUNDVOLUMEUP;
		}
		else if (_wcsicmp(args, L"SoundVolumeDown") == 0)
		{
			command = COMMAND_SOUNDVOLUMEDOWN;
		}
		else if (_wcsicmp(args, L"ToggleiTunes") == 0)
		{
			command = COMMAND_TOGGLEITUNES;
		}
		else if (_wcsicmp(args, L"ToggleVisuals") == 0)
		{
			command = COMMAND_TOGGLEVISUALS;
		}
		else if (_wcsicmp(args, L"UpdateiPod") == 0)
		{
			command = COMMAND_UPDATEIPOD;
		}
		else if (_wcsicmp(args, L"UpdatePodcastFeeds") == 0)
		{
			command = COMMAND_UPDATEPODCASTFEEDS;
		}
		else if (_wcsicmp(args, L"GotoMusicStoreHomePage") == 0)
		{
			command = COMMAND_GOTOMUSICSTOREHOMEPAGE;
		}
		else if (_wcsicmp(args, L"Quit") == 0)
		{
			command = COMMAND_QUIT;
		}
		else
		{
			LSLog(LOG_NOTICE, nullptr, L"iTunesPlugin.dll: Invalid Command");
			return;
		}
	}

	if (!InstanceCreated)
	{
		if (COMMAND_POWER == command && CoInitialized && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, nullptr, CLSCTX_LOCAL_SERVER)))
		{
			IITBrowserWindowPtr browserWindow;
			if (SUCCEEDED(iTunes->get_BrowserWindow(&browserWindow)))
			{
				browserWindow->put_Minimized(VARIANT_TRUE);
			}
			InstanceCreated = true;
		}
		return;
	}

	switch (command)
	{
		case COMMAND_POWER:
		{
			iTunes->Quit();
			iTunes.Release();
			InstanceCreated = false;
			break;
		}
		case COMMAND_TOGGLEITUNES:
		{
			IITBrowserWindowPtr browserWindow;
			if (FAILED(iTunes->get_BrowserWindow(&browserWindow)))
			{
				break;
			}
			VARIANT_BOOL minimized;
			if (SUCCEEDED(browserWindow->get_Minimized(&minimized)))
			{
				browserWindow->put_Minimized((VARIANT_TRUE == minimized) ? VARIANT_FALSE : VARIANT_TRUE);
			}
			break;
		}
		case COMMAND_TOGGLEVISUALS:
		{
			VARIANT_BOOL visualsEnabled;
			if (SUCCEEDED(iTunes->get_VisualsEnabled(&visualsEnabled)))
			{
				iTunes->put_VisualsEnabled((VARIANT_TRUE == visualsEnabled) ? VARIANT_FALSE : VARIANT_TRUE);
			}
			break;
		}
		case COMMAND_SOUNDVOLUMEUP:
		{
			long volume;
			iTunes->get_SoundVolume(&volume);
			volume += VOLUME_STEP;
			(volume > 100) ? volume = 100 : 0;
			iTunes->put_SoundVolume(volume);
			break;
		}
		case COMMAND_SOUNDVOLUMEDOWN:
		{
			long volume;
			iTunes->get_SoundVolume(&volume);
			volume -= VOLUME_STEP;
			(volume < 0) ? volume = 0 : 0;
			iTunes->put_SoundVolume(volume);
			break;
		}

		// Player Controls
		case COMMAND_BACKTRACK:
			iTunes->BackTrack();
			break;
		case COMMAND_FASTFORWARD:
			iTunes->FastForward();
			break;
		case COMMAND_NEXTTRACK:
			iTunes->NextTrack();
			break;
		case COMMAND_PAUSE:
			iTunes->Pause();
			break;
		case COMMAND_PLAY:
			iTunes->Pause();
			iTunes->Play();
			break;
		case COMMAND_PLAYFILE:
			//TODO:
			break;
		case COMMAND_PLAYPAUSE:
			iTunes->PlayPause();
			break;
		case COMMAND_PREVIOUSTRACK:
			iTunes->PreviousTrack();
			break;
		case COMMAND_RESUME:
			iTunes->Resume();
			break;
		case COMMAND_REWIND:
			iTunes->Rewind();
			break;
		case COMMAND_STOP:
			iTunes->Stop();
			break;
		case COMMAND_GETPLAYERBUTTONSSTATE:
			//TODO:
			break;
		case COMMAND_PLAYERBUTTONCLICKED:
			//TODO:
			break;

		// Conversion Methods
		case COMMAND_CONVERTFILE:
			//TODO:
			break;
		case COMMAND_CONVERTFILES:
			//TODO:
			break;
		case COMMAND_TRACK:
			//TODO:
			break;
		case COMMAND_TRACKS:
			//TODO:
			break;
		case COMMAND_FILE2:
			//TODO:
			break;
		case COMMAND_FILES2:
			//TODO:
			break;
		case COMMAND_TRACK2:
			//TODO:
			break;
		case COMMAND_TRACKS2:
			//TODO:
			break;

		// Miscellaneous Methods
		case COMMAND_CHECKVERSION:
			//TODO:
			break;
		case COMMAND_GETITOBJECTBYID:
			//TODO:
			break;
		case COMMAND_CREATEPLAYLIST:
			//TODO:
			break;
		case COMMAND_OPENURL:
			//TODO:
			break;
		case COMMAND_GOTOMUSICSTOREHOMEPAGE:
			iTunes->GotoMusicStoreHomePage();
			break;
		case COMMAND_UPDATEIPOD:
			iTunes->UpdateIPod();
			break;
		case COMMAND_QUIT:
			iTunes->Quit();
			break;
		case COMMAND_CREATEEQPRESET:
			//TODO:
			break;
		case COMMAND_CREATEPLAYLISTINSOURCE:
			//TODO:
			break;
		case COMMAND_SUBSCRIBETOPODCAST:
			//TODO:
			break;
		case COMMAND_UPDATEPODCASTFEEDS:
			iTunes->UpdatePodcastFeeds();
			break;
		case COMMAND_CREATEFOLDER:
			//TODO:
			break;
		case COMMAND_CREATEFOLDERINSOURCE:
			//TODO:
			break;
		case COMMAND_GETITOBJECTPERSISTENTIDS:
			//TODO:
			break;
	}
}