LINUX: afs_create infinite fetchStatus loop
[pkg-k5-afs_openafs.git] / src / WINNT / client_config / main.cpp
blobd0451bf754a4eb3e69c530387ca5f550787540b1
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 #include <afs/fs_utils.h>
19 #include "afs_config.h"
20 #include "isadmin.h"
21 #include "tab_general.h"
22 #include "tab_prefs.h"
23 #include "tab_hosts.h"
24 #include "tab_drives.h"
25 #include "tab_advanced.h"
28 * DEFINITIONS ________________________________________________________________
34 * VARIABLES __________________________________________________________________
38 GLOBALS g;
41 * ROUTINES ___________________________________________________________________
45 static BOOL Main_ShowMountTab(void)
47 HKEY hk;
48 BOOL bShow = FALSE;
49 BOOL bSuccess = FALSE;
51 if (RegOpenKeyEx (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY, 0,
52 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk) == 0)
54 DWORD dwSize = sizeof(bShow);
55 DWORD dwType = REG_DWORD;
56 bSuccess = (RegQueryValueEx (hk, TEXT("ShowMountTab"), NULL, &dwType, (PBYTE)&bShow, &dwSize) == 0);
57 RegCloseKey (hk);
60 if (!bSuccess &&
61 RegOpenKeyEx (HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY, 0,
62 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk) == 0)
64 DWORD dwSize = sizeof(bShow);
65 DWORD dwType = REG_DWORD;
66 bSuccess = (RegQueryValueEx (hk, TEXT("ShowMountTab"), NULL, &dwType, (PBYTE)&bShow, &dwSize) == 0);
67 RegCloseKey (hk);
70 return bShow;
73 extern "C" int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
75 TaLocale_LoadCorrespondingModule (hInst);
77 // Initialize winsock etc
79 WSADATA Data;
80 WSAStartup (0x0101, &Data);
82 InitCommonControls();
83 RegisterCheckListClass();
84 RegisterFastListClass();
85 RegisterSockAddrClass();
86 RegisterSpinnerClass();
87 fs_utils_InitMountRoot();
89 // Initialize our global variables and window classes
91 memset (&g, 0x00, sizeof(g));
92 g.fIsWinNT = IsWindowsNT();
93 g.fIsAdmin = IsAdmin();
95 // Check our command-line options
97 while (pCmdLine && (*pCmdLine=='/' || *pCmdLine=='-'))
99 switch (*(++pCmdLine))
101 case 'c':
102 case 'C':
103 g.fIsCCenter = TRUE;
104 break;
107 while (*pCmdLine == ' ')
108 ++pCmdLine;
111 // Select an appropriate help file
113 if (g.fIsCCenter)
114 lstrcpy (g.szHelpFile, TEXT("afs-cc.hlp>dialog"));
115 else if (g.fIsWinNT)
116 lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp>dialog"));
117 else
118 lstrcpy (g.szHelpFile, TEXT("afs-light.hlp>dialog"));
120 // Our main window is actually a tabbed dialog.
122 if ((g.psh = PropSheet_Create (((g.fIsCCenter) ? IDS_TITLE_CCENTER : (g.fIsWinNT) ? IDS_TITLE_NT : IDS_TITLE_95), FALSE, NULL)) == NULL)
123 return FALSE;
125 g.psh->sh.dwFlags |= PSH_NOAPPLYNOW; // Remove the Apply button
126 g.psh->sh.dwFlags |= PSH_HASHELP; // Add a Help button instead
128 if (g.fIsCCenter)
130 PropSheet_AddTab (g.psh, 0, IDD_HOSTS_CCENTER, (DLGPROC)HostsTab_DlgProc, 0, TRUE);
132 else
134 PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_GENERAL_NT : IDD_GENERAL_95), (DLGPROC)GeneralTab_DlgProc, 0, TRUE);
136 if (Main_ShowMountTab())
137 PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_DRIVES_NT : IDD_DRIVES_95), (DLGPROC)DrivesTab_DlgProc, 0, TRUE);
139 if (g.fIsWinNT)
140 PropSheet_AddTab (g.psh, 0, IDD_PREFS_NT, (DLGPROC)PrefsTab_DlgProc, 0, TRUE);
142 PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_HOSTS_NT : IDD_HOSTS_95), (DLGPROC)HostsTab_DlgProc, 0, TRUE);
144 if (g.fIsWinNT)
145 PropSheet_AddTab (g.psh, 0, IDD_ADVANCED_NT, (DLGPROC)AdvancedTab_DlgProc, 0, TRUE);
148 PropSheet_ShowModal (g.psh);
150 return 0;
154 void Main_OnInitDialog (HWND hMain)
156 g.hMain = hMain;
158 // Center the window in the display
160 RECT rWindow;
161 GetWindowRect (g.hMain, &rWindow);
163 RECT rDesktop;
164 SystemParametersInfo (SPI_GETWORKAREA, 0, &rDesktop, 0);
166 SetWindowPos (g.hMain, NULL,
167 rDesktop.left + ((rDesktop.right - rDesktop.left) - (rWindow.right - rWindow.left)) / 2,
168 rDesktop.top + ((rDesktop.bottom - rDesktop.top) - (rWindow.bottom - rWindow.top)) / 2,
169 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
171 // Remove the Context Help [?] thing from the title bar
173 DWORD dwStyle = GetWindowLong (g.hMain, GWL_STYLE);
174 dwStyle &= ~DS_CONTEXTHELP;
175 SetWindowLong (g.hMain, GWL_STYLE, dwStyle);
177 dwStyle = GetWindowLong (hMain, GWL_EXSTYLE);
178 dwStyle &= ~WS_EX_CONTEXTHELP;
179 SetWindowLong (g.hMain, GWL_EXSTYLE, dwStyle);
183 void Main_RefreshAllTabs (void)
185 for (size_t ii = 0; ii < g.psh->cTabs; ++ii)
187 if (!g.psh->aTabs[ii].dlgproc)
188 continue;
189 if (!IsWindow (g.psh->aTabs[ii].hDlg))
190 continue;
192 CallWindowProc ((WNDPROC)(g.psh->aTabs[ii].dlgproc), g.psh->aTabs[ii].hDlg, WM_COMMAND, IDC_REFRESH, 0);
197 void Quit (void)
199 if (IsWindow (g.hMain))
201 DestroyWindow (g.hMain);
203 PostQuitMessage (0);
207 LPCTSTR GetCautionTitle (void)
209 static TCHAR szTitle[ cchRESOURCE ] = TEXT("");
210 if (!szTitle[0])
211 GetString (szTitle, (g.fIsCCenter) ? IDS_TITLE_CAUTION_CCENTER : (g.fIsWinNT) ? IDS_TITLE_CAUTION_NT : IDS_TITLE_CAUTION_95);
212 return szTitle;
216 LPCTSTR GetErrorTitle (void)
218 static TCHAR szTitle[ cchRESOURCE ] = TEXT("");
219 if (!szTitle[0])
220 GetString (szTitle, (g.fIsCCenter) ? IDS_TITLE_ERROR_CCENTER : (g.fIsWinNT) ? IDS_TITLE_ERROR_NT : IDS_TITLE_ERROR_95);
221 return szTitle;