Windows: AFSTearDownExtents may experience active extents
[openafs.git] / src / WINNT / client_config / main.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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  */
9
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 #include <afs/fs_utils.h>
17 }
18
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"
26
27 /*
28  * DEFINITIONS ________________________________________________________________
29  *
30  */
31
32
33 /*
34  * VARIABLES __________________________________________________________________
35  *
36  */
37
38 GLOBALS g;
39
40 /*
41  * ROUTINES ___________________________________________________________________
42  *
43  */
44
45 static BOOL Main_ShowMountTab(void)
46 {
47     HKEY hk;
48     BOOL bShow = FALSE;
49     BOOL bSuccess = FALSE;
50
51     if (RegOpenKeyEx (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY, 0,
52                        (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk) == 0)
53     {
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);
58     }
59
60     if (!bSuccess &&
61         RegOpenKeyEx (HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY, 0,
62                       (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk) == 0)
63     {
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);
68     }
69
70     return bShow;
71 }
72
73 extern "C" int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
74 {
75    TaLocale_LoadCorrespondingModule (hInst);
76
77    // Initialize winsock etc
78    //
79    WSADATA Data;
80    WSAStartup (0x0101, &Data);
81
82    InitCommonControls();
83    RegisterCheckListClass();
84    RegisterFastListClass();
85    RegisterSockAddrClass();
86    RegisterSpinnerClass();
87    fs_utils_InitMountRoot();
88
89    // Initialize our global variables and window classes
90    //
91    memset (&g, 0x00, sizeof(g));
92    g.fIsWinNT = IsWindowsNT();
93    g.fIsAdmin = IsAdmin();
94
95    // Check our command-line options
96    //
97    while (pCmdLine && (*pCmdLine=='/' || *pCmdLine=='-'))
98       {
99       switch (*(++pCmdLine))
100          {
101          case 'c':
102          case 'C':
103             g.fIsCCenter = TRUE;
104             break;
105          }
106
107       while (*pCmdLine == ' ')
108          ++pCmdLine;
109       }
110
111    // Select an appropriate help file
112    //
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"));
119
120    // Our main window is actually a tabbed dialog.
121    //
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;
124
125    g.psh->sh.dwFlags |= PSH_NOAPPLYNOW;  // Remove the Apply button
126    g.psh->sh.dwFlags |= PSH_HASHELP;     // Add a Help button instead
127
128    if (g.fIsCCenter)
129       {
130       PropSheet_AddTab (g.psh, 0, IDD_HOSTS_CCENTER, (DLGPROC)HostsTab_DlgProc, 0, TRUE);
131       }
132    else
133       {
134       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_GENERAL_NT : IDD_GENERAL_95), (DLGPROC)GeneralTab_DlgProc, 0, TRUE);
135
136       if (Main_ShowMountTab())
137          PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_DRIVES_NT : IDD_DRIVES_95), (DLGPROC)DrivesTab_DlgProc, 0, TRUE);
138
139       if (g.fIsWinNT)
140          PropSheet_AddTab (g.psh, 0, IDD_PREFS_NT, (DLGPROC)PrefsTab_DlgProc, 0, TRUE);
141
142       PropSheet_AddTab (g.psh, 0, ((g.fIsWinNT) ? IDD_HOSTS_NT : IDD_HOSTS_95), (DLGPROC)HostsTab_DlgProc, 0, TRUE);
143
144       if (g.fIsWinNT)
145          PropSheet_AddTab (g.psh, 0, IDD_ADVANCED_NT, (DLGPROC)AdvancedTab_DlgProc, 0, TRUE);
146       }
147
148    PropSheet_ShowModal (g.psh);
149
150    return 0;
151 }
152
153
154 void Main_OnInitDialog (HWND hMain)
155 {
156    g.hMain = hMain;
157
158    // Center the window in the display
159    //
160    RECT rWindow;
161    GetWindowRect (g.hMain, &rWindow);
162
163    RECT rDesktop;
164    SystemParametersInfo (SPI_GETWORKAREA, 0, &rDesktop, 0);
165
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);
170
171    // Remove the Context Help [?] thing from the title bar
172    //
173    DWORD dwStyle = GetWindowLong (g.hMain, GWL_STYLE);
174    dwStyle &= ~DS_CONTEXTHELP;
175    SetWindowLong (g.hMain, GWL_STYLE, dwStyle);
176
177    dwStyle = GetWindowLong (hMain, GWL_EXSTYLE);
178    dwStyle &= ~WS_EX_CONTEXTHELP;
179    SetWindowLong (g.hMain, GWL_EXSTYLE, dwStyle);
180 }
181
182
183 void Main_RefreshAllTabs (void)
184 {
185    for (size_t ii = 0; ii < g.psh->cTabs; ++ii)
186       {
187       if (!g.psh->aTabs[ii].dlgproc)
188          continue;
189       if (!IsWindow (g.psh->aTabs[ii].hDlg))
190          continue;
191
192       CallWindowProc ((WNDPROC)(g.psh->aTabs[ii].dlgproc), g.psh->aTabs[ii].hDlg, WM_COMMAND, IDC_REFRESH, 0);
193       }
194 }
195
196
197 void Quit (void)
198 {
199    if (IsWindow (g.hMain))
200       {
201       DestroyWindow (g.hMain);
202       }
203    PostQuitMessage (0);
204 }
205
206
207 LPCTSTR GetCautionTitle (void)
208 {
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;
213 }
214
215
216 LPCTSTR GetErrorTitle (void)
217 {
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;
222 }
223