]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_mono on Windows now looks for paths a bit better
authorMichael Giagnocavo <mgg@giagnocavo.net>
Thu, 18 Sep 2008 00:40:36 +0000 (00:40 +0000)
committerMichael Giagnocavo <mgg@giagnocavo.net>
Thu, 18 Sep 2008 00:40:36 +0000 (00:40 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9585 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_mono/mod_mono.cpp
src/mod/languages/mod_mono_managed/Loader.cs

index f1c9df101f1bcecf12a38b7752d82ef97f24e4c5..9fbb2985906ad1703fd242f846817a8df070d22b 100644 (file)
@@ -24,7 +24,8 @@
  * Contributor(s):\r
  * \r
  * Michael Giagnocavo <mgg@packetrino.com>\r
- * \r
+ * David Brazier <David.Brazier@360crm.co.uk>\r
+ *\r
  * mod_mono.cpp -- FreeSWITCH mod_mono main class\r
  *\r
  * Most of mod_mono is implmented in the mod_mono_managed Loader class. \r
@@ -88,44 +89,69 @@ SWITCH_MOD_DECLARE(void) InitMonoSession(MonoSession * session, MonoObject * dtm
 switch_status_t setMonoDirs() \r
 {\r
 #ifdef WIN32   \r
-       /* Win32 Mono installs can't figure out their own path\r
+       // Win32 Mono installs can't figure out their own path\r
        // Guys in #mono say we should just deploy all the libs we need\r
-       // I think it's much nicer to let the user deal with installing Mono\r
-       // and we'll just look for it in program files. */ \r
-       HANDLE hFind;\r
-       WIN32_FIND_DATA findData;\r
+       // We'll first check for Program Files\Mono to allow people to use the symlink dir for a specific version.\r
+       // Then we'll check HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Mono\2.0\FrameworkAssemblyDirectory and MonoConfigDir\r
+       // After that, we'll scan program files for a Mono-* dir.\r
        char progFilesPath[MAX_PATH];\r
+       char libPath[MAX_PATH];\r
+       char etcPath[MAX_PATH];\r
        char findPath[MAX_PATH];\r
+       bool found = false;\r
 \r
        SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, progFilesPath);\r
-       switch_snprintf(findPath, MAX_PATH, "%s\\Mono-*", progFilesPath);\r
-       hFind = FindFirstFile(findPath, &findData);\r
-       if (hFind == INVALID_HANDLE_VALUE) {\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error looking for Mono in Program Files.\n");\r
-               return SWITCH_STATUS_FALSE;\r
+\r
+       { // Check PF\Mono directly\r
+               DWORD attr;\r
+               switch_snprintf(findPath, MAX_PATH, "%s\\Mono", progFilesPath);\r
+               attr = GetFileAttributes(findPath);\r
+               found = (attr != INVALID_FILE_ATTRIBUTES && ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY));\r
+               if (found) {\r
+                       switch_snprintf(libPath, MAX_PATH, "%s\\lib", findPath);\r
+                       switch_snprintf(etcPath, MAX_PATH, "%s\\etc", findPath);\r
+               }\r
        }\r
 \r
-       while ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {\r
-               if (FindNextFile(hFind, &findData) == 0) {\r
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find Mono directory in Program Files.\n");\r
-                       FindClose(hFind);\r
-                       return SWITCH_STATUS_FALSE;\r
+       if(!found) \r
+       {   // Check registry\r
+               DWORD size = MAX_PATH;\r
+               if (ERROR_SUCCESS == RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Novell\\Mono\\2.0", "FrameworkAssemblyDirectory", RRF_RT_REG_SZ, NULL, &libPath, &size)) {\r
+                       size = MAX_PATH;\r
+                       if (ERROR_SUCCESS == RegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Novell\\Mono\\2.0", "MonoConfigDir", RRF_RT_REG_SZ, NULL, &etcPath, &size)) {\r
+                               found = true;\r
+                       }\r
                }\r
        }\r
 \r
-       /* Got it */ \r
-       {\r
-               char libPath[MAX_PATH];\r
-               char etcPath[MAX_PATH];\r
+       if (!found)\r
+       { // Scan program files for Mono-2something\r
+               HANDLE hFind;\r
+               WIN32_FIND_DATA findData;\r
+               switch_snprintf(findPath, MAX_PATH, "%s\\Mono-2*", progFilesPath);\r
+               hFind = FindFirstFile(findPath, &findData);\r
+               if (hFind == INVALID_HANDLE_VALUE) {\r
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error looking for Mono in Program Files.\n");\r
+                       return SWITCH_STATUS_FALSE;\r
+               }\r
 \r
+               while ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {\r
+                       if (FindNextFile(hFind, &findData) == 0) {\r
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find Mono directory in Program Files.\n");\r
+                               FindClose(hFind);\r
+                               return SWITCH_STATUS_FALSE;\r
+                       }\r
+               }\r
                switch_snprintf(libPath, MAX_PATH, "%s\\%s\\lib", progFilesPath, findData.cFileName);\r
                switch_snprintf(etcPath, MAX_PATH, "%s\\%s\\etc", progFilesPath, findData.cFileName);\r
                FindClose(hFind);\r
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Using Mono paths '%s' and '%s'.\n", libPath, etcPath);\r
-               mono_set_dirs(libPath, etcPath);\r
-               return SWITCH_STATUS_SUCCESS;\r
        }\r
 \r
+       /* Got it */ \r
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Using Mono paths '%s' and '%s'.\n", libPath, etcPath);\r
+       mono_set_dirs(libPath, etcPath);\r
+       return SWITCH_STATUS_SUCCESS;\r
+\r
 #else\r
        // On other platforms, it should just work if it hasn't been relocated\r
        mono_set_dirs(NULL, NULL);\r
index ade3509a94780645c08ca3f95ff315700a85597d..5d4ed5935ec82fd8c22c081b74867a254c7cb87f 100644 (file)
@@ -24,6 +24,7 @@
  * Contributor(s):\r
  * \r
  * Michael Giagnocavo <mgg@packetrino.com>\r
+ * David Brazier <David.Brazier@360crm.co.uk>\r
  * \r
  * Loader.cs -- mod_mono managed loader\r
  *\r