summaryrefslogtreecommitdiff
path: root/plugins/Variables/src/parse_external.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Variables/src/parse_external.cpp')
-rw-r--r--plugins/Variables/src/parse_external.cpp116
1 files changed, 51 insertions, 65 deletions
diff --git a/plugins/Variables/src/parse_external.cpp b/plugins/Variables/src/parse_external.cpp
index 2a0ade2768..2cb408c777 100644
--- a/plugins/Variables/src/parse_external.cpp
+++ b/plugins/Variables/src/parse_external.cpp
@@ -26,7 +26,8 @@ static void (WINAPI *acUninit)() = NULL;
static unsigned int lastAMIPFailure = -1;
-static TCHAR *getFullWinampTitleText() {
+static TCHAR *getFullWinampTitleText()
+{
HWND hwndWinamp = FindWindow(_T("STUDIO"), NULL);
if (hwndWinamp == NULL)
hwndWinamp = FindWindow(_T("Winamp v1.x"),NULL);
@@ -54,16 +55,17 @@ static TCHAR *getFullWinampTitleText() {
return szTitle;
}
-static TCHAR *parseWinampSong(ARGUMENTSINFO *ai) {
- if (ai->argc != 1) {
+static TCHAR *parseWinampSong(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 1)
return NULL;
- }
+
TCHAR *res = NULL;
TCHAR *szTitle = getFullWinampTitleText();
- if (szTitle == NULL) {
+ if (szTitle == NULL)
return NULL;
- }
- TCHAR *scur = _tcschr(szTitle, _T('.'));
+
+ TCHAR *scur = _tcschr(szTitle, '.');
TCHAR *cur = _tcsstr(scur, _T(" - Winamp"));
if ((scur == NULL) || (cur == NULL) || (scur >= cur) || (scur > (szTitle + _tcslen(szTitle) - 2)) || (cur > (szTitle + _tcslen(szTitle)))) {
mir_free(szTitle);
@@ -79,16 +81,17 @@ static TCHAR *parseWinampSong(ARGUMENTSINFO *ai) {
return res;
}
-static TCHAR *parseWinampState(ARGUMENTSINFO *ai) {
- if (ai->argc != 1) {
+static TCHAR *parseWinampState(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 1)
return NULL;
- }
+
TCHAR *res = NULL;
TCHAR *szTitle = getFullWinampTitleText();
- if (szTitle == NULL) {
+ if (szTitle == NULL)
return NULL;
- }
- TCHAR *scur = _tcschr(szTitle, _T('.'));
+
+ TCHAR *scur = _tcschr(szTitle, '.');
TCHAR *cur = _tcsstr(scur, _T(" - Winamp"));
if ((scur == NULL) || (cur == NULL)) {
mir_free(szTitle);
@@ -106,8 +109,8 @@ static TCHAR *parseWinampState(ARGUMENTSINFO *ai) {
return mir_tstrdup(_T("Playing"));
}
-static unsigned int checkAMIP() {
-
+static unsigned int checkAMIP()
+{
if (lastAMIPFailure == 0) {
log_debugA("AMIP initialized");
return 0;
@@ -119,76 +122,63 @@ static unsigned int checkAMIP() {
if (acInitClient("127.0.0.1", 60333, 1000, 5, 1)) {
lastAMIPFailure = 0;
log_debugA("AMIP now initialized");
-
return 0; // success
}
log_debugA("AMIP failed to initialized");
- if (lastAMIPFailure == 0) {
- /* if this is the first failure after a succesful init, call uninit for a cleanup (maybe it'll help for the next try ;)) */
+
+ /* if this is the first failure after a succesful init, call uninit for a cleanup (maybe it'll help for the next try ;)) */
+ if (lastAMIPFailure == 0)
acUninit();
- }
+
lastAMIPFailure = GetTickCount();
-
return -1;
}
-static TCHAR *parseAMIPEval(ARGUMENTSINFO *ai) {
- char szRes[AC_BUFFER_SIZE];
-
- TCHAR *tszRes = NULL;
- if (ai->argc != 2) {
+static TCHAR *parseAMIPEval(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
char *cmd = mir_t2a(ai->targv[1]);
-
if (checkAMIP() != 0) {
log_debugA("checkAMIP failed");
-
return NULL;
}
- ZeroMemory(&szRes, sizeof(szRes));
- if (AC_ERR_NOERROR == acEval(cmd, szRes)) {
+ TCHAR *tszRes = NULL;
+ char szRes[AC_BUFFER_SIZE];
+ ZeroMemory(&szRes, sizeof(szRes));
+ if (AC_ERR_NOERROR == acEval(cmd, szRes))
tszRes = mir_a2t(szRes);
-
- }
- else {
+ else
lastAMIPFailure = GetTickCount();
- }
- mir_free(cmd);
+ mir_free(cmd);
return tszRes;
}
-static TCHAR *parseAMIPFormat(ARGUMENTSINFO *ai) {
- char szRes[AC_BUFFER_SIZE];
-
- TCHAR *tszRes = NULL;
- if (ai->argc != 2) {
+static TCHAR *parseAMIPFormat(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
- char *cmd = mir_t2a(ai->targv[1]);
-
- if (checkAMIP() != 0) {
-
+ char *cmd = mir_t2a(ai->targv[1]);
+ if (checkAMIP() != 0)
return NULL;
- }
- if (AC_ERR_NOERROR == acFormat(cmd, szRes)) {
+ TCHAR *tszRes = NULL;
+ char szRes[AC_BUFFER_SIZE];
+ if (AC_ERR_NOERROR == acFormat(cmd, szRes))
tszRes = mir_a2t(szRes);
-
- }
- else {
+ else
lastAMIPFailure = GetTickCount();
- }
- mir_free(cmd);
+ mir_free(cmd);
return tszRes;
}
-static int initAMIP() {
+static int initAMIP()
+{
HMODULE hModule = LoadLibrary(_T("ac.dll"));
if (hModule == NULL) {
TCHAR path[MAX_PATH];
@@ -200,37 +190,33 @@ static int initAMIP() {
_tcscpy(cur, _T("ac.dll"));
hModule = LoadLibrary(path);
}
- if (hModule == NULL) {
+ if (hModule == NULL)
return -1;
- }
+
acInitClient = (int (__stdcall *)(const char *,int ,int ,int ,int ))GetProcAddress(hModule, "ac_init_client");
acEval = (int (__stdcall *)(const char *,char *))GetProcAddress(hModule, "ac_eval");
acFormat = (int (__stdcall *)(const char *,char *))GetProcAddress(hModule, "ac_format");
acUninit = (void (__stdcall *)())GetProcAddress(hModule, "ac_uninit");
-
return 0;
}
-int registerExternalTokens() {
-
+int registerExternalTokens()
+{
registerIntToken(_T(WINAMPSONG), parseWinampSong, TRF_FIELD, LPGEN("External Applications")"\t"LPGEN("retrieves song name of the song currently playing in Winamp"));
registerIntToken(_T(WINAMPSTATE), parseWinampState, TRF_FIELD, LPGEN("External Applications")"\t"LPGEN("retrieves current Winamp state (Playing/Paused/Stopped)"));
if (!initAMIP()) {
registerIntToken(_T(AMIPEVAL), parseAMIPEval, TRF_FUNCTION, LPGEN("External Applications")"\t(x)\t"LPGEN("retrieves info from AMIP (x is var_<variable> with any AMIP variable)"));
registerIntToken(_T(AMIPFORMAT), parseAMIPFormat, TRF_FUNCTION|TRF_UNPARSEDARGS, LPGEN("External Applications")"\t(x)\t"LPGEN("retrieves info from AMIP (x is AMIP format string)"));
}
- else {
- log_infoA("Variables: ac.dll for AMIP not found");
- }
+ else log_infoA("Variables: ac.dll for AMIP not found");
return 0;
}
-int deInitExternal() {
-
- if (acUninit != NULL) {
+int deInitExternal()
+{
+ if (acUninit != NULL)
acUninit();
- }
return 0;
} \ No newline at end of file