Example #1
1
BOOL InitApp (LPSTR pszCmdLineA)
{
   BOOL fShow = FALSE;
   BOOL fQuiet = FALSE;
   BOOL fExit = FALSE;
   BOOL fInstall = FALSE;
   BOOL fUninstall = FALSE;
   BOOL fAutoInit = FALSE;
   BOOL fNetDetect = FALSE;
   BOOL fRenewMaps = FALSE;

   // Initialize our global variables and window classes
   //
   memset (&g, 0x00, sizeof(g));
   g.fStartup = TRUE;

   // Parse the command-line
   //
   while (pszCmdLineA && *pszCmdLineA)
      {
      if ((*pszCmdLineA != '-') && (*pszCmdLineA != '/'))
         break;

      switch (*(++pszCmdLineA))
         {
         case 'a':
         case 'A':
            fAutoInit = TRUE;
            break;

         case 'm':
         case 'M':
            fRenewMaps = TRUE;
            break;

         case 'n':
         case 'N':
            fNetDetect = TRUE;
            break;

         case 's':
         case 'S':
            fShow = TRUE;
            break;

         case 'q':
         case 'Q':
            fQuiet = TRUE;
            break;

         case 'e':
         case 'E':
            fExit = TRUE;
            break;

         case 'i':
         case 'I':
            fInstall = TRUE;
            break;

         case 'u':
         case 'U':
            fUninstall = TRUE;
            break;

         case ':':
             CopyAnsiToString(g.SmbName,pszCmdLineA);
			 MapShareName(pszCmdLineA);
			 break;

         case 'z':
         case 'Z':
             DoUnMapShare(TRUE);
             return(0);

         case 'x':
         case 'X':
             TestAndDoMapShare(SERVICE_START_PENDING);
             TestAndDoMapShare(SERVICE_RUNNING);
             return 0;
         }

      while (*pszCmdLineA && (*pszCmdLineA != ' '))
         ++pszCmdLineA;
	  if (*pszCmdLineA==' ') ++pszCmdLineA;
      }

   if (fInstall)
      Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = TRUE);
   else if (fUninstall)
      Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE);

   if (fInstall || fUninstall)
      {
      HKEY hk;
      if (RegCreateKeyEx (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY, 0, NULL, 0,
                         (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE, NULL, &hk, NULL) == 0)
         {
         DWORD dwSize = sizeof(g.fStartup);
         DWORD dwType = REG_DWORD;
         RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
         RegCloseKey (hk);
         }
      }

   // Only show up if there's not another version of this app around already.
   //
   for (HWND hSearch = GetWindow (GetDesktopWindow(), GW_CHILD);
        hSearch && IsWindow(hSearch);
        hSearch = GetWindow (hSearch, GW_HWNDNEXT))
      {
      TCHAR szClassName[ cchRESOURCE ];
      if (GetClassName (hSearch, szClassName, cchRESOURCE))
         {
         if (!lstrcmpi (szClassName, cszCLASSNAME))
            {
            if (fShow)
               PostMessage (hSearch, WM_COMMAND, M_ACTIVATE, 0);
            else if (fExit)
               PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
            else if (fUninstall)
               PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
            return FALSE;
            }
         }
      }

   if (fExit || fUninstall || fInstall)
      return FALSE;

   HKEY hk;
    if (RegOpenKeyEx (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY, 0,
                       (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk) == 0)
    {
        DWORD dwSize = sizeof(g.fStartup);
        DWORD dwType = REG_DWORD;
        RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
        RegCloseKey (hk);
    }
    else if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY, 0,
                            (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk) == 0)
      {
      DWORD dwSize = sizeof(g.fStartup);
      DWORD dwType = REG_DWORD;
      RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
      RegCloseKey (hk);
      }

   Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);

   // Is this Windows NT?
   //
   OSVERSIONINFO Version;
   memset (&Version, 0x00, sizeof(Version));
   Version.dwOSVersionInfoSize = sizeof(Version);
   if (GetVersionEx (&Version))
      g.fIsWinNT = (Version.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TRUE : FALSE;

   if (!g.fIsWinNT)
      lstrcpy (g.szHelpFile, TEXT("afs-light.hlp"));
   else
      lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp"));

   // Initialize winsock etc
   //
   WSADATA Data;
   WSAStartup (0x0101, &Data);

   InitCommonControls();
   RegisterCheckListClass();
   osi_Init();
   lock_InitializeMutex(&g.expirationCheckLock, "expiration check lock", 0);
   lock_InitializeMutex(&g.credsLock, "global creds lock", 0);

   KFW_AFS_wait_for_service_start();

   if ( IsDebuggerPresent() ) {
       if ( !g.fIsWinNT )
           OutputDebugString("No Service Present on non-NT systems\n");
       else {
           if ( IsServiceRunning() )
               OutputDebugString("AFSD Service started\n");
           else {
               OutputDebugString("AFSD Service stopped\n");
               if ( !IsServiceConfigured() )
                   OutputDebugString("AFSD Service not configured\n");
               else if ( fAutoInit )
                   OutputDebugString("AFSD Service will be started\n");
           }
       }
   }

    // If the service isn't started yet, and autoInit start the service
    if ( g.fIsWinNT && !IsServiceRunning() && IsServiceConfigured() && fAutoInit ) {
        SC_HANDLE hManager;

        if ((hManager = OpenSCManager( NULL, NULL,
                                       SC_MANAGER_CONNECT |
                                       SC_MANAGER_ENUMERATE_SERVICE |
                                       SC_MANAGER_QUERY_LOCK_STATUS)) != NULL )
        {
            SC_HANDLE hService;
            if ((hService = OpenService( hManager, TEXT("TransarcAFSDaemon"),
                                         SERVICE_QUERY_STATUS | SERVICE_START) ) != NULL)
            {
                if (StartService(hService, 0, 0)) {
                    if ( IsDebuggerPresent() )
                        OutputDebugString("AFSD Service start successful\n");
                    fRenewMaps = TRUE;
                } else if ( IsDebuggerPresent() )
                    OutputDebugString("AFSD Service start failed\n");

                CloseServiceHandle (hService);
            }

            CloseServiceHandle (hManager);
        }
        KFW_AFS_wait_for_service_start();
    }

    KFW_initialize();

   // Create a main window. All further initialization will be done during
   // processing of WM_INITDIALOG.
   //
   WNDCLASS wc;
   if (!GetClassInfo (NULL, WC_DIALOG, &wc))   // Get dialog class info
      return FALSE;
   wc.hInstance = THIS_HINST;
   wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
   wc.lpszClassName = cszCLASSNAME;
   wc.style |= CS_GLOBALCLASS;
   RegisterClass(&wc);

   g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DlgProc);
   if (g.hMain == NULL)
      return FALSE;

   // If the service isn't started yet, show our startup wizard.
   //
   if (!IsServiceRunning() && !fQuiet)
      {
      if (!g.fIsWinNT)
         Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95);
      else if (IsServiceConfigured())
         ShowStartupWizard();
      else if (!IsServerInstalled())
         Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
      }
   if (IsServiceRunning()) {
      if ( fRenewMaps )
      {
          if ( IsDebuggerPresent() )
              OutputDebugString("Renewing Drive Maps\n");
          DoMapShareChange(FALSE);
      }
      if (fShow)
      {
      if ( IsDebuggerPresent() )
          OutputDebugString("Displaying Main window\n");
      Main_Show (TRUE);
      }
      // If the root cell is reachable and we have no tokens
      // display the Obtain Tokens dialog to the user
      if ( fAutoInit ) {
          if ( IsDebuggerPresent() )
              OutputDebugString("Obtaining Tokens (if needed)\n");
          ObtainTokensFromUserIfNeeded(g.hMain);
      }
   } else if ( IsDebuggerPresent() )
       OutputDebugString("AFSD Service Stopped\n");

    if ( fNetDetect ) {
        // Start IP Address Change Monitor
        if ( IsDebuggerPresent() )
            OutputDebugString("Activating Network Change Monitor\n");
        IpAddrChangeMonitorInit(g.hMain);
    }
    Main_EnableRemindTimer(TRUE);
    return TRUE;
}
Example #2
0
HWND Main_CreateTabDialog (HWND hTab, size_t iTab)
{
   HWND hDlg = NULL;
   LPTSTR psz = NULL;

   TC_ITEM Item;
   memset (&Item, 0x00, sizeof(Item));
   Item.mask = TCIF_PARAM;
   if (TabCtrl_GetItem (hTab, iTab, &Item))
      {
      psz = (LPTSTR)(Item.lParam);
      }

   if (psz == dwTABPARAM_ADVANCED)    // Advanced tab
      {
      hDlg = ModelessDialog (IDD_TAB_ADVANCED, hTab, (DLGPROC)Advanced_DlgProc);
      }
   else if (psz == dwTABPARAM_MOUNT)  // Mount Points tab
      {
      hDlg = ModelessDialog (IDD_TAB_MOUNT, hTab, (DLGPROC)Mount_DlgProc);
      }
   else if (ISCELLTAB(psz) && !*psz)  // No Creds tab
      {
      hDlg = ModelessDialogParam (IDD_TAB_NOCREDS, hTab, (DLGPROC)Creds_DlgProc, (LPARAM)psz);
      }
   else if (ISCELLTAB(psz) && *psz)   // Creds tab for a particular cell
      {
      hDlg = ModelessDialogParam (IDD_TAB_CREDS, hTab, (DLGPROC)Creds_DlgProc, (LPARAM)psz);
      }

   return hDlg;
}
Example #3
0
void GeneralTab_OnTimer (HWND hDlg)
{
   DWORD CurrentState = Config_GetServiceState();
   DWORD DisplayState = GeneralTab_GetDisplayState(hDlg);
   TestAndDoMapShare(CurrentState);		//Re map mounted drives if necessary

   BOOL fInEndState = ((CurrentState == SERVICE_RUNNING) || (CurrentState == SERVICE_STOPPED));
   if (fInEndState && l.hStatus)
      {
      if (IsWindow (l.hStatus))
         DestroyWindow (l.hStatus);
      l.hStatus = NULL;
      }
   else if (!fInEndState && !l.hStatus)
      {
      l.hStatus = ModelessDialog (IDD_STARTSTOP, GetParent (hDlg), (DLGPROC)Status_DlgProc);
      }

   if (CurrentState != DisplayState)
      {
      GeneralTab_OnRefresh (hDlg, FALSE);
      Main_RefreshAllTabs();

      if (l.hStatus && IsWindow (l.hStatus))
         PostMessage (l.hStatus, WM_COMMAND, IDINIT, 0);
      }

   BOOL fNeedFastRefresh = ((CurrentState == SERVICE_STOPPED) || (CurrentState == SERVICE_RUNNING)) ? FALSE : TRUE;
   BOOL fHaveFastRefresh = ((DisplayState == SERVICE_STOPPED) || (DisplayState == SERVICE_RUNNING)) ? FALSE : TRUE;

   if (fNeedFastRefresh != fHaveFastRefresh)
      {
      GeneralTab_FixRefreshTimer (hDlg, ((fNeedFastRefresh) ? cmsecFAST_REFRESH : cmsecIDLE_REFRESH));
      }
}
Example #4
0
void Main_PrepareTabChild (size_t iTabNew)
{
   HWND hTab = GetDlgItem (g.hMain, IDC_TAB);
   int iTabOld = TabCtrl_GetCurSel (hTab);
   if (iTabNew == -1)
      iTabNew = iTabOld;

   HWND hDlg;
   if ((hDlg = GetTabChild (hTab)) != NULL)
      DestroyWindow (hDlg);
   if ((hDlg = ModelessDialog (aTABS[ iTabNew ].iddChild, hTab, aTABS[ iTabNew ].procChild)) != NULL)
      {
      if (iTabNew != iTabOld)
         TabCtrl_SetCurSel (hTab, iTabNew);
      ShowWindow (hDlg, SW_SHOW);
      }

   // Remember this tab as the last one the user saw, so that if the app gets
   // closed we can re-open it to the same tab.
   //
   gr.iTabLast = iTabNew;

   // Check/uncheck/enable/disable our dialog's menu items as appropriate.
   // We do this whenever the current tab changes, because some of the
   // menu items will change state depending on which tab is visible.
   //
   Main_SetMenus();
}
Example #5
0
void Actions_OpenWindow (void)
{
   if (!IsWindow (l.hAction))
      {
      l.hAction = ModelessDialog (IDD_ACTIONS, NULL, (DLGPROC)Actions_DlgProc);
      ShowWindow (l.hAction, SW_SHOW);
      Actions_WindowToTop (TRUE);
      }
}
Example #6
0
void Server_DisplayTab (HWND hDlg, CHILDTAB iTab)
{
   HWND hTab = GetDlgItem (hDlg, IDC_TABS);
   int idd = -1;
   DLGPROC dlgproc = NULL;

   switch (iTab)
      {
      case tabSERVICES:
         idd = IDD_SERVICES;
         dlgproc = (DLGPROC)Services_DlgProc;
         break;
      case tabAGGREGATES:
         idd = IDD_AGGREGATES;
         dlgproc = (DLGPROC)Aggregates_DlgProc;
         break;
      case tabFILESETS:
         idd = IDD_FILESETS;
         dlgproc = (DLGPROC)Filesets_DlgProc;
         break;
      }

   if (idd != -1)
      {
      HWND hDialogOld = GetTabChild (hTab);
      HWND hDialogNew = ModelessDialog (idd, hTab, dlgproc);

      if (hDialogNew != NULL)
         {
         TabCtrl_SetCurSel (hTab, iTab);
         ShowWindow (hDialogNew, SW_SHOW);

         if (hDialogOld != NULL)
            {
            DestroyWindow (hDialogOld);
            }

         Server_ForceRedraw (hDlg);
         }
      }
}
Example #7
0
BOOL InitApplication (HINSTANCE hInst, LPTSTR pszCmdLine, int nCmdShow)
{
   TaLocale_LoadCorrespondingModule (hInst);

   memset (&g, 0x00, sizeof(g));
   g.hInst = hInst;
   g.hAccel = TaLocale_LoadAccelerators (ACCEL_MAIN);

   HWND hPrevious;
   TCHAR szTitle[ cchRESOURCE ];
   GetString (szTitle, IDS_APP_TITLE);
   if ((hPrevious = FindWindow (TEXT("AFSAccountManagerClass"), szTitle)) != NULL)
      {
      SetFocus (hPrevious);
      SendMessage (hPrevious, WM_SHOW_YOURSELF, 0, 0);
      return FALSE;
      }

   AfsAppLib_SetAppName(szTitle);
   AfsAppLib_SetPumpRoutine(PumpMessage);

   TASKQUEUE_PARAMS tqp;
   memset (&tqp, 0x00, sizeof(tqp));
   tqp.nThreadsMax = 10;
   tqp.fnCreateTaskPacket = CreateTaskPacket;
   tqp.fnPerformTask = PerformTask;
   tqp.fnFreeTaskPacket = FreeTaskPacket;
   AfsAppLib_InitTaskQueue (&tqp);

   Main_ConfigureHelp();

   // Determine how the app is supposed to look--that is, remember what it
   // looked like last time, and if there was no "last time", pick some
   // decent defaults.
   //
   if (!RestoreSettings (REGSTR_SETTINGS_BASE, REGSTR_SETTINGS_PATH, REGVAL_SETTINGS, &gr, sizeof(gr), wVerGLOBALS_RESTORED))
      {
      memset (&gr, 0x00, sizeof(gr));
      SetRectEmpty (&gr.rMain);
      gr.cminRefreshRate = 60; // 1 hour default refresh rate

      User_SetDefaultCreateParams (&gr.CreateUser);
      Group_SetDefaultCreateParams (&gr.CreateGroup);
      Machine_SetDefaultCreateParams (&gr.CreateMachine);
      Actions_SetDefaultView (&gr.viewAct);
      User_SetDefaultView (&gr.viewUsr, &gr.ivUsr);
      Group_SetDefaultView (&gr.viewGrp, &gr.ivGrp);
      Machine_SetDefaultView (&gr.viewMch, &gr.ivMch);
      Users_SetDefaultSearchParams (&gr.SearchUsers);
      }

   // Create a variation on WC_DIALOG, so we get appropriate icons on
   // our windows.
   //
   WNDCLASS wc;
   GetClassInfo (THIS_HINST, MAKEINTRESOURCE( WC_DIALOG ), &wc);
   wc.hInstance = THIS_HINST;
   wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
   wc.lpszClassName = TEXT("AFSAccountManagerClass");
   wc.style |= CS_GLOBALCLASS;
   RegisterClass (&wc);

   // Okay, the big step: create the main window.  Note that it doesn't
   // get shown yet!
   //
   CMDLINEOP op = ParseCommandLine (pszCmdLine);
   if (op == opCLOSEAPP)
      return FALSE;

   // Okay, the big step: create the main window.
   // Note that it doesn't get shown yet!
   //
   g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DialogProc);
   if (g.hMain == NULL)
      return FALSE;

   if (op != opNOCELLDIALOG)
      {
      if (OpenCellDialog() != IDOK)
         return FALSE;
      }

   return TRUE;
}
Example #8
0
BOOL InitApplication (HINSTANCE hInst, LPTSTR pszCmdLine, int nCmdShow)
{
   TaLocale_LoadCorrespondingModule (hInst);

   memset (&g, 0x00, sizeof(g));
   g.hInst = hInst;
   g.hAccel = TaLocale_LoadAccelerators (ACCEL_MAIN);

   HWND hPrevious;
   TCHAR szTitle[ cchRESOURCE ];
   GetString (szTitle, IDS_APP_TITLE);
   if ((hPrevious = FindWindow (TEXT("AFSManagerClass"), szTitle)) != NULL)
      {
      SetFocus (hPrevious);
      SendMessage (hPrevious, WM_SHOW_YOURSELF, 0, 0);
      return FALSE;
      }

   AfsAppLib_SetAppName(szTitle);
   AfsAppLib_SetPumpRoutine(PumpMessage);

   TASKQUEUE_PARAMS tqp;
   memset (&tqp, 0x00, sizeof(tqp));
   tqp.nThreadsMax = 10;
   tqp.fnCreateTaskPacket = CreateTaskPacket;
   tqp.fnPerformTask = PerformTask;
   tqp.fnFreeTaskPacket = FreeTaskPacket;
   AfsAppLib_InitTaskQueue (&tqp);

   Main_ConfigureHelp();

   // Determine how the app is supposed to look--that is, remember what it
   // looked like last time, and if there was no "last time", pick some
   // decent defaults.
   //
   if (!RestoreSettings (REGSTR_SETTINGS_BASE, REGSTR_SETTINGS_PATH, REGVAL_SETTINGS, &gr, sizeof(gr), wVerGLOBALS_RESTORED))
      {
      memset (&gr, 0x00, sizeof(gr));
      SetRectEmpty (&gr.rMain);
      SetRectEmpty (&gr.rMainPreview);
      SetRectEmpty (&gr.rServerLast);
      SetRectEmpty (&gr.rViewLog);
      SetRectEmpty (&gr.rActions);

      gr.fPreview = TRUE;
      gr.fVert = TRUE;
      gr.fActions = FALSE;

      gr.tabLast = tabFILESETS;

      Server_SetDefaultView_Horz (&gr.diHorz.viewSvr);
      Server_SetDefaultView_Vert (&gr.diVert.viewSvr);
      Services_SetDefaultView (&gr.viewSvc);
      Aggregates_SetDefaultView (&gr.viewAgg);
      Filesets_SetDefaultView (&gr.viewSet);
      Replicas_SetDefaultView (&gr.viewRep);
      Action_SetDefaultView (&gr.viewAct);
      Server_Key_SetDefaultView (&gr.viewKey);

      gr.diHorz.cSplitter = -100;
      gr.diVert.cSplitter = -89;

      gr.cbQuotaUnits = cb1KB;

      gr.fOpenMonitors = TRUE;
      gr.fCloseUnmonitors = TRUE;
      gr.fServerLongNames = FALSE;
      gr.fDoubleClickOpens = 2;
      gr.fWarnBadCreds = TRUE;

      gr.ivSvr = ivSTATUS;
      gr.ivAgg = ivSTATUS;
      gr.ivSet = ivSTATUS;
      gr.ivSvc = ivSTATUS;
      }

   ULONG status;
   if (!AfsClass_Initialize (&status))
      {
      if (status == ADMCLIENTCANTINITAFSLOCATION)
         ImmediateErrorDialog (status, IDS_ERROR_CANT_INIT_AFSCLASS_INSTALL);
      else
         ImmediateErrorDialog (status, IDS_ERROR_CANT_INIT_AFSCLASS_UNKNOWN);
      return FALSE;
      }

   AfsClass_RequestLongServerNames (gr.fServerLongNames);
   AfsClass_SpecifyRefreshDomain (AFSCLASS_WANT_VOLUMES);

   // Create a notification object for the AFSClass library, so that it can
   // let us know when anything changes.  The notification handler we'll
   // install will take requests from the rest of the SVRMGR package and
   // forward notifications around to whichever windows are actually
   // interested.
   //
   CreateNotificationDispatch();

   // Create a few variations on WC_DIALOG, so we get appropriate icons on
   // our windows.
   //
   WNDCLASS wc;
   GetClassInfo (THIS_HINST, MAKEINTRESOURCE( WC_DIALOG ), &wc);
   wc.hInstance = THIS_HINST;
   wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
   wc.lpszClassName = TEXT("AFSManagerClass");
   wc.style |= CS_GLOBALCLASS;
   RegisterClass (&wc);

   GetClassInfo (THIS_HINST, MAKEINTRESOURCE( WC_DIALOG ), &wc);
   wc.hInstance = THIS_HINST;
   wc.hIcon = TaLocale_LoadIcon (IDI_SERVER);
   wc.lpszClassName = TEXT("ServerWindowClass");
   wc.style |= CS_GLOBALCLASS;
   RegisterClass (&wc);

   // Okay, the big step: create the main window (ie, the servers list).
   // Note that it doesn't get shown yet!
   //
   CMDLINEOP op = ParseCommandLine (pszCmdLine);
   if (op == opCLOSEAPP)
      return FALSE;

   if (op == opLOOKUPERRORCODE)
      {
      Help_FindError();
      return FALSE;
      }

   g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DialogProc);
   if (g.hMain == NULL)
      return FALSE;

   if (op != opNOCELLDIALOG)
      {
      if (OpenCellDialog() != IDOK)
         return FALSE;
      }

   return TRUE;
}