Windows: conditionally set tray icon state
[openafs.git] / src / WINNT / client_config / tab_general.cpp
index 450ad7d..4994c2b 100644 (file)
@@ -7,9 +7,15 @@
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
+#include <winsock2.h>
+#include <ws2tcpip.h>
+
 extern "C" {
+#include <afsconfig.h>
 #include <afs/param.h>
+#include <roken.h>
 #include <afs/stds.h>
+#include <afs/cm.h>
 #include <rx/rxkad.h>
 #include <afs/cm_config.h>
 }
@@ -101,9 +107,9 @@ BOOL CALLBACK GeneralTab_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
             {
             case IDAPPLY:
                if (!GeneralTab_OnApply (hDlg, FALSE, TRUE))
-                  SetWindowLong (hDlg, DWL_MSGRESULT, TRUE);
+                  SetWindowLongPtr (hDlg, DWLP_MSGRESULT, TRUE);
                else if (g.fIsWinNT && !GeneralTab_AskIfStopped (hDlg))
-                  SetWindowLong (hDlg, DWL_MSGRESULT, TRUE);
+                  SetWindowLongPtr (hDlg, DWLP_MSGRESULT, TRUE);
                break;
 
             case IDC_REFRESH:
@@ -228,7 +234,7 @@ BOOL GeneralTab_OnApply (HWND hDlg, BOOL fForce, BOOL fComplainIfInvalid)
    if (!fForce)
       {
       // Don't try to do anything if we've already failed the apply
-      if (GetWindowLong (hDlg, DWL_MSGRESULT))
+      if (GetWindowLongPtr (hDlg, DWLP_MSGRESULT))
          return FALSE;
       }
 
@@ -262,11 +268,12 @@ BOOL GeneralTab_OnApply (HWND hDlg, BOOL fForce, BOOL fComplainIfInvalid)
    BOOL fLogonAuthent = IsDlgButtonChecked (hDlg, IDC_LOGON);
    if (fLogonAuthent != g.Configuration.fLogonAuthent)
       {
-          SetBitLogonOption(fLogonAuthent,LOGON_OPTION_INTEGRATED);
+      SetBitLogonOption(fLogonAuthent,LOGON_OPTION_INTEGRATED);
       g.Configuration.fLogonAuthent = fLogonAuthent;
       }
 
-   Config_SetTrayIconFlag (IsDlgButtonChecked (hDlg, IDC_TRAYICON));
+  if (GetDlgItem(hDlg, IDC_TRAYICON) != NULL)
+      Config_SetTrayIconFlag (IsDlgButtonChecked(hDlg, IDC_TRAYICON));
 
    if (g.fIsWinNT)
       {
@@ -659,26 +666,30 @@ BOOL fIsCellInCellServDB (LPCTSTR pszCell)
 {
    BOOL fFound = FALSE;
    CELLSERVDB CellServDB;
-
-   if (CSDB_ReadFile (&CellServDB, NULL))
+   char cellname[256], i;
+
+   /* we pray for all ascii cellnames */
+   for ( i=0 ; pszCell[i] && i < (sizeof(cellname)-1) ; i++ )
+       cellname[i] = pszCell[i];
+   cellname[i] = '\0';
+
+   ULONG code = cm_SearchCellRegistry(1, cellname, NULL, NULL, NULL, NULL);
+   if (code == 0)
+      fFound = TRUE;
+   if (!fFound && 
+       (code != CM_ERROR_FORCE_DNS_LOOKUP) && 
+       CSDB_ReadFile (&CellServDB, NULL))
    {
        if (CSDB_FindCell (&CellServDB, pszCell))
            fFound = TRUE;
        CSDB_FreeFile (&CellServDB);
    }
-#ifdef AFS_AFSDB_ENV
-    if ( fFound == FALSE ) {
-        int ttl;
-        char cellname[128], i;
-
-        /* we pray for all ascii cellnames */
-        for ( i=0 ; pszCell[i] && i < (sizeof(cellname)-1) ; i++ )
-            cellname[i] = pszCell[i];
-        cellname[i] = '\0';
-
-        fFound = !cm_SearchCellByDNS(cellname, NULL, &ttl, NULL, NULL);
-    }
-#endif
+   if ( fFound == FALSE ) {
+       int ttl;
+       fFound = !cm_SearchCellByDNS(cellname, NULL, &ttl, NULL, NULL);
+   }
+   done:
+
    return fFound;
 }