home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / confhook.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.1 KB  |  296 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. // confhook.cpp : implementation file
  19. //
  20.  
  21. #include "stdafx.h"
  22. #include <shellapi.h>
  23.  
  24. #include "confhook.h"
  25.  
  26. extern "C" {
  27. #include "xpgetstr.h"
  28. extern int MK_MSG_CANT_FIND_CALLPOINT;
  29. };
  30.  
  31.  
  32.  
  33. //
  34. // NEEDED STRINGS
  35. // ==============
  36. // MK_MSG_CANT_FIND_CONFAPP - Can't find the app to run
  37. // IDS_CONFAPP                - "Conferencing Application" type string, I think?
  38. //
  39.  
  40. // 
  41. // Other internal defines...
  42. //
  43. #define    CONFAPP_UNAVAILABLE        0
  44. #define    CONFAPP_CONFERENCE        1
  45. #define    CONFAPP_THIRDPARTY        2
  46.  
  47. //
  48. // Registry stuff:
  49. //
  50. #define    _MAX_ARG_LEN_                    128      
  51.  
  52. //
  53. // Sections for profile lookups...
  54. //
  55. static TCHAR    lpszWin32ConfAppBranch[] = _T("Software\\Netscape\\ConfApplication");
  56. static TCHAR    lpszWin16ConfAppSection[] = _T("ConfApplication");
  57. static int        confAppAvailibility = CONFAPP_UNAVAILABLE;
  58.  
  59. BOOL 
  60. FileExists(LPCSTR szFile) 
  61. {
  62.     struct _stat buf;
  63.     int result;
  64.  
  65.     result = _stat( szFile, &buf );
  66.     return (result == 0);
  67. }
  68.  
  69. //
  70. // This routine is specific to looking up values in the new ConfApp 
  71. // registry/ini file section.
  72. //
  73. CString 
  74. FEU_GetConfAppProfileString(const CString &queryString) 
  75.     char    argBuffer[_MAX_PATH + 1];
  76.     CString returnVal(""); 
  77.  
  78.     returnVal = "";
  79.     strcpy(argBuffer, "");
  80.  
  81.     //
  82.     // If the defined conference application on the system is
  83.     // still a leftover NSCP Conference, we should still use
  84.     // that setting. In this case, simply return the default
  85.     // value for Netscape Conference.
  86.     //
  87.     if (confAppAvailibility == CONFAPP_CONFERENCE)
  88.     {
  89.         //
  90.         // First, we will assign a value to argBuffer that corresponds
  91.         // to NSCP Conference's value for this particular argument.
  92.         //
  93.         if (queryString == IDS_CONFAPP_FULLPATHNAME)
  94.         {
  95.         CString installDirectory, executable;
  96.  
  97.     #ifdef WIN32
  98.             installDirectory = FEU_GetInstallationDirectory(szLoadString(IDS_CONFERENCE_REGISTRY), szLoadString(IDS_PATHNAME));
  99.             executable = "\\NSCONF32.EXE";
  100.     #else // XP_WIN16
  101.             installDirectory = FEU_GetInstallationDirectory(szLoadString(IDS_CONFERENCE),szLoadString(IDS_INSTALL_DIRECTORY));
  102.             executable = "\\NSCSTART.EXE";
  103.     #endif
  104.  
  105.             wsprintf(argBuffer, "%s%s", installDirectory, executable);
  106.         }
  107.         else if (queryString == IDS_CONFAPP_NOBANNER)
  108.         {
  109.             strcpy(argBuffer, "/b");
  110.         }
  111.         else if (queryString == IDS_CONFAPP_MIMEFILE)
  112.         {
  113.             strcpy(argBuffer, "/f");
  114.         }        
  115.         else if (queryString == IDS_CONFAPP_DIRECTIP)
  116.         {
  117.             strcpy(argBuffer, "/d");
  118.         }
  119.         else if (queryString == IDS_CONFAPP_EMAIL)
  120.         {
  121.             strcpy(argBuffer, "/i");
  122.         }
  123.         else if (queryString == IDS_CONFAPP_SERVER)
  124.         {
  125.             strcpy(argBuffer, "/s");
  126.         }
  127.         else if (queryString == IDS_CONFAPP_USERNAME)
  128.         {
  129.             strcpy(argBuffer, "");
  130.         }
  131.     
  132.         returnVal = argBuffer;
  133.         return returnVal;
  134.     }
  135.  
  136. #ifdef _WIN32 
  137.  
  138.     HKEY hKey; 
  139.     LONG lResult; 
  140.     char szVal[_MAX_PATH + 1]; 
  141.     
  142.     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpszWin32ConfAppBranch, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 
  143.     {     
  144.         unsigned long cbData = sizeof(szVal); 
  145.         lResult = RegQueryValueEx(hKey, queryString, NULL, NULL, (LPBYTE) szVal, &cbData); 
  146.         RegCloseKey(hKey); 
  147.  
  148.         if (lResult == ERROR_SUCCESS) 
  149.         {
  150.             returnVal = szVal;     
  151.         }
  152.     } 
  153. #else // XP_WIN16 
  154.  
  155.     char szPath[_MAX_PATH + 1]; 
  156.     const char *pOldProfile = theApp.m_pszProfileName; 
  157.     
  158.     UINT nSize = GetWindowsDirectory(szPath, _MAX_PATH + 1); 
  159.     XP_STRCPY(szPath + nSize, szLoadString(IDS_NSCPINI)); 
  160.     theApp.m_pszProfileName = szPath; 
  161.     
  162.     returnVal = theApp.GetProfileString(lpszWin16ConfAppSection, queryString, NULL); 
  163.  
  164.     theApp.m_pszProfileName = pOldProfile;     
  165. #endif
  166.  
  167.     return returnVal; 
  168.  
  169. //
  170. // This function is needed to see if a conferencing endpoint
  171. // is defined on the machine. Return true if there is or false
  172. // if it doesn't exist.
  173. //
  174. BOOL
  175. FEU_IsConfAppAvailable(void)
  176. {
  177.     //
  178.     // Check to see if a conf. app is defined on the local
  179.     // machine.
  180.     //
  181.     CString fileName = FEU_GetConfAppProfileString(IDS_CONFAPP_FULLPATHNAME); 
  182.     if (fileName.IsEmpty())
  183.     {
  184.         if (FEU_IsConferenceAvailable())
  185.         {
  186.             confAppAvailibility = CONFAPP_CONFERENCE;
  187.             return TRUE;
  188.         }
  189.         else
  190.         {
  191.             confAppAvailibility = CONFAPP_UNAVAILABLE;
  192.             return FALSE;
  193.         }
  194.     }
  195.  
  196.     // 
  197.     // We should really make sure there is something at the location 
  198.     // defined before we go further.
  199.     //
  200.     if (FileExists(fileName)) 
  201.     {
  202.         confAppAvailibility = CONFAPP_THIRDPARTY;
  203.         return TRUE;
  204.     }
  205.     else
  206.     {
  207.         confAppAvailibility = CONFAPP_UNAVAILABLE;
  208.         return FALSE;
  209.     }
  210. }
  211.  
  212. //
  213. // This will be the central function where we will do the launching
  214. // of Conference on this endpoint. 
  215. // 
  216. // Args: makeCall - true if this is going to make a call or false
  217. // if we are just launching the appliction.
  218. //
  219. void
  220. LaunchConfEndpoint(char *commandLine, HWND parent)
  221. {
  222.     CString executable;
  223.     char    *cline = commandLine;
  224.     char    cbuf[_MAX_ARG_LEN_];
  225.     
  226.     executable = FEU_GetConfAppProfileString(IDS_CONFAPP_FULLPATHNAME); 
  227.  
  228.     //
  229.     // Check to see if the executable is defined on the machine. If it is not, then
  230.     // show a message and return.
  231.     // 
  232.     if (executable.IsEmpty())
  233.     {
  234.         CString s;
  235.         if (s.LoadString( IDS_CONFERENCE ))
  236.         {
  237.             ::MessageBox(parent, XP_GetString(MK_MSG_CANT_FIND_CALLPOINT), s, MB_OK | MB_APPLMODAL);
  238.         }
  239.         return;
  240.     }
  241.  
  242.     //
  243.     // Check if the commandline is null...if so, we need to try to find the banner
  244.     // suppression flag and pass it to the executable.
  245.     //
  246.     if (!commandLine)
  247.     {
  248.         CString nobannerFlag = FEU_GetConfAppProfileString(IDS_CONFAPP_NOBANNER);
  249.         strcpy(cbuf, nobannerFlag);
  250.         cline = &(cbuf[0]);
  251.     }
  252.  
  253.     int uSpawn =  (int) ShellExecute(NULL, "open", executable, cline, ".", SW_SHOW);
  254.     if(uSpawn <= 32)    
  255.     {
  256.         char szMsg[80];
  257.         switch(uSpawn) 
  258.         {
  259.         case 0:
  260.         case 8:
  261.             sprintf(szMsg, szLoadString(IDS_WINEXEC_0_8));
  262.             break;
  263.         case 2:                                      
  264.         case 3:
  265.             sprintf(szMsg, szLoadString(IDS_WINEXEC_2_3));
  266.             break;
  267.         case 10:
  268.         case 11:
  269.         case 12:
  270.         case 13:
  271.         case 14:
  272.         case 15:
  273.             sprintf(szMsg, szLoadString(IDS_WINEXEC_10_THRU_15));
  274.             break;
  275.         case 16:
  276.             sprintf(szMsg, szLoadString(IDS_WINEXEC_16));
  277.             break;
  278.         case 21:
  279.             sprintf(szMsg, szLoadString(IDS_WINEXEC_21));
  280.             break;
  281.         default:
  282.             sprintf(szMsg, szLoadString(IDS_WINEXEC_XX), uSpawn);
  283.             break;
  284.         }        
  285.         
  286.         CString s;
  287.         if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  288.         {
  289.             ::MessageBox(parent, szMsg, s, MB_OK | MB_APPLMODAL);
  290.         }
  291.     }
  292. }
  293.  
  294.