summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-06-15 17:46:17 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-06-15 17:46:17 +0000
commit4b48deb0396fd25e6146d2bd5deec6e792722e4c (patch)
tree0d1fb911f9723a046c2525dfd6c31a193d2485a0 /plugins
parent784d212b194e228563936068e69bc1f0e553cee2 (diff)
MimCmd to set path to libs too
git-svn-id: http://svn.miranda-ng.org/main/trunk@14181 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CmdLine/src/mimcmd_ipc.cpp17
-rw-r--r--plugins/MimCmd/src/MimCmd.cpp28
-rw-r--r--plugins/MimCmd/src/commands.cpp87
3 files changed, 49 insertions, 83 deletions
diff --git a/plugins/CmdLine/src/mimcmd_ipc.cpp b/plugins/CmdLine/src/mimcmd_ipc.cpp
index 6cee3de54f..7ebbfc6cbf 100644
--- a/plugins/CmdLine/src/mimcmd_ipc.cpp
+++ b/plugins/CmdLine/src/mimcmd_ipc.cpp
@@ -71,7 +71,6 @@ int CreateSystemEvents()
int CreateMutexes()
{
hmClient = CreateMutexA(NULL, FALSE, MUTEX_CLIENT_NAME);
-
return (hmClient == NULL);
}
@@ -80,26 +79,20 @@ int CreateSharedMem()
hsmCmdLine = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(TSharedData), SHAREDMEM_NAME);
sdCmdLine = (PSharedData) MapViewOfFile(hsmCmdLine, FILE_MAP_WRITE, 0, 0, sizeof(TSharedData));
- return ((hsmCmdLine == NULL) || (sdCmdLine == NULL));
+ return (hsmCmdLine == NULL) || (sdCmdLine == NULL);
}
int DestroySystemEvents()
{
- int res = (!CloseHandle(heServerExec)) || (!CloseHandle(heServerDone)) || (!CloseHandle(heServerClose) || (!CloseHandle(heServerBufferFull)));
-
- return res;
+ return (!CloseHandle(heServerExec)) || (!CloseHandle(heServerDone)) || (!CloseHandle(heServerClose) || (!CloseHandle(heServerBufferFull)));
}
int DestroyMutexes()
{
- int res = !CloseHandle(hmClient);
-
- return res;
+ return !CloseHandle(hmClient);
}
int DestroySharedMem()
{
- int res = (!UnmapViewOfFile(sdCmdLine)) || (!CloseHandle(hsmCmdLine));
-
- return res;
-} \ No newline at end of file
+ return (!UnmapViewOfFile(sdCmdLine)) || (!CloseHandle(hsmCmdLine));
+}
diff --git a/plugins/MimCmd/src/MimCmd.cpp b/plugins/MimCmd/src/MimCmd.cpp
index 6bad9d81aa..38a6ce511a 100644
--- a/plugins/MimCmd/src/MimCmd.cpp
+++ b/plugins/MimCmd/src/MimCmd.cpp
@@ -27,13 +27,11 @@ int lpprintf(const char *format, ...)
va_list va;
va_start(va, format);
const int MAX_SIZE = 16192;
- char buffer[MAX_SIZE] = {0};
- int len = mir_vsnprintf(buffer, MAX_SIZE - 1, format, va);
- buffer[MAX_SIZE - 1] = 0;
+ char buffer[MAX_SIZE] = { 0 };
+ int len = mir_vsnprintf(buffer, MAX_SIZE, format, va);
va_end(va);
CharToOemBuffA(buffer, buffer, len);
printf("%s", buffer);
-
return len;
}
@@ -74,33 +72,25 @@ void ShowVersion()
int main(int argc, char *argv[])
{
int error = 0;
- if ((argc == 2) && (mir_strcmp(argv[1], "-v") == 0))
- {
+ if ((argc == 2) && (mir_strcmp(argv[1], "-v") == 0)) {
ShowVersion();
-
return 0;
}
- if ((InitClient()) || (ConnectToMiranda()) || (GetKnownCommands()) || (LoadLangPackModule()))
- {
+ if ((InitClient()) || (ConnectToMiranda()) || (GetKnownCommands()) || (LoadLangPackModule())) {
lpprintf("Could not create connection with Miranda or could not retrieve list of known commands.\n");
error = MIMRES_NOMIRANDA;
}
- else{
- if ((argc <= 1) || (argc > MAX_ARGUMENTS))
- {
+ else {
+ if (argc <= 1 || argc > MAX_ARGUMENTS)
PrintUsage();
- }
- else{
+ else {
PReply reply = ParseCommand(argv, argc);
- if (reply)
- {
+ if (reply) {
error = reply->code;
lpprintf("%s\n", reply->message);
}
- else{
- lpprintf(Translate("Unknown command '%s'.\n"), argv[1]);
- }
+ else lpprintf(Translate("Unknown command '%s'.\n"), argv[1]);
DestroyKnownCommands();
DisconnectFromMiranda();
diff --git a/plugins/MimCmd/src/commands.cpp b/plugins/MimCmd/src/commands.cpp
index 7d844e5a68..38b31da795 100644
--- a/plugins/MimCmd/src/commands.cpp
+++ b/plugins/MimCmd/src/commands.cpp
@@ -30,14 +30,26 @@ HMODULE hCmdLineDLL = NULL;
char *GetMirandaFolder(char *mimFolder, int size)
{
strncpy_s(mimFolder, size, sdCmdLine->mimFolder, _TRUNCATE);
- mimFolder[size - 1] = 0;
-
return mimFolder;
}
-
int ConnectToMiranda()
{
+ TCHAR tszPath[MAX_PATH];
+ GetModuleFileName(NULL, tszPath, _countof(tszPath));
+ TCHAR *p = _tcsrchr(tszPath, '\\');
+ if (p) p[1] = 0;
+
+ _tcsncat(tszPath, _T("libs"), _TRUNCATE);
+ DWORD cbPath = (DWORD)_tcslen(tszPath);
+
+ DWORD cbSize = GetEnvironmentVariable(_T("PATH"), NULL, 0);
+ TCHAR *ptszVal = new TCHAR[cbSize + MAX_PATH + 2];
+ _tcscpy(ptszVal, tszPath);
+ _tcscat(ptszVal, _T(";"));
+ GetEnvironmentVariable(_T("PATH"), ptszVal + cbPath + 1, cbSize);
+ SetEnvironmentVariable(_T("PATH"), ptszVal);
+
char pluginPath[1024];
GetMirandaFolder(pluginPath, sizeof(pluginPath));
mir_strcat(pluginPath, "\\plugins\\cmdline.dll");
@@ -48,14 +60,10 @@ int ConnectToMiranda()
int failure = 1;
if (hCmdLineDLL)
- {
ListCommands = (LISTCOMMANDS) GetProcAddress(hCmdLineDLL, "ListCommands");
- }
if (ListCommands)
- {
failure = 0;
- }
return failure;
}
@@ -68,14 +76,11 @@ int DisconnectFromMiranda()
int GetKnownCommands()
{
ListCommands(&knownCommands, &cKnownCommands);
-
return (knownCommands == NULL);
}
int DestroyKnownCommands()
{
-
-
return 0;
}
@@ -87,24 +92,14 @@ PCommand GetCommand(char *command)
_strlwr(lower);
for (i = 0; i < cKnownCommands; i++)
- {
if (mir_strcmp(knownCommands[i].command, lower) == 0)
- {
return &knownCommands[i];
- }
- }
//allow more parameters to trigger the help command - /h -h /? --help
if ((mir_strcmp(lower, "/h") == 0) || (mir_strcmp(lower, "-h") == 0) || (mir_strcmp(lower, "/?") == 0) || (mir_strcmp(lower, "--help") == 0))
- {
for (i = 0; i < cKnownCommands; i++)
- {
if (knownCommands[i].ID == MIMCMD_HELP)
- {
return &knownCommands[i];
- }
- }
- }
return NULL;
}
@@ -167,41 +162,30 @@ void FillSharedDataStruct(PCommand command, char *arguments[], int count)
void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PReply reply)
{
- const HANDLE events[] = {heServerDone, heServerClose, heServerBufferFull};
+ const HANDLE events[] = { heServerDone, heServerClose, heServerBufferFull };
const int cEvents = sizeof(events) / sizeof(events[0]);
- if (WaitForSingleObject(hmClient, INFINITE) == WAIT_OBJECT_0)
- {//got the mutex, we're the only one who can talk to miranda now
+ if (WaitForSingleObject(hmClient, INFINITE) == WAIT_OBJECT_0) {//got the mutex, we're the only one who can talk to miranda now
FillSharedDataStruct(command, arguments, count);
SetEvent(heServerExec); //tell Miranda to process the request
int done = FALSE;
- while (!done)
- {
- switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE)) //wait until server either finished processing or miranda was closed
- {
- case WAIT_OBJECT_0: //done event
- {
- done = TRUE;
-
- break; //nothing to do
- }
-
- case WAIT_OBJECT_0 + 1: //close event
- default:
- {
- mir_strcpy(sdCmdLine->reply.message, Translate("Miranda has been closed or an error has occurred while waiting for the result, could not process request."));
- done = TRUE;
-
- break;
- }
-
- case WAIT_OBJECT_0 + 2: //buffer full event
- {
- lpprintf("%s", reply->message);
-
- break;
- }
+ while (!done) {
+ // wait until server either finished processing or miranda was closed
+ switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE)) {
+ case WAIT_OBJECT_0: //done event
+ done = TRUE;
+ break; //nothing to do
+
+ case WAIT_OBJECT_0 + 1: //close event
+ default:
+ mir_strcpy(sdCmdLine->reply.message, Translate("Miranda has been closed or an error has occurred while waiting for the result, could not process request."));
+ done = TRUE;
+ break;
+
+ case WAIT_OBJECT_0 + 2: //buffer full event
+ lpprintf("%s", reply->message);
+ break;
}
}
@@ -210,9 +194,8 @@ void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PRepl
ReleaseMutex(hmClient); //let other possible clients talk to the server
}
- else{
+ else {
reply->code = -1;
*reply->message = 0;
}
-
-} \ No newline at end of file
+}