2 * Copyright 2000, International Business Machines Corporation and others.
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
14 #include <afs/param.h>
23 #include "svr_security.h"
25 #include "propcache.h"
32 #include <afs/afs_AdminErrors.h>
37 * DEFINITIONS ________________________________________________________________
43 * VARIABLES __________________________________________________________________
52 * PROTOTYPES _________________________________________________________________
56 BOOL InitApplication (HINSTANCE hInst, LPTSTR pszCmdLine, int nCmdShow);
57 void ExitApplication (void);
61 * ROUTINES ___________________________________________________________________
65 extern "C" int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pszCmdLineA, int nCmdShow)
67 LPTSTR pszCmdLine = AnsiToString (pszCmdLineA);
69 if (InitApplication (hInst, pszCmdLine, nCmdShow))
76 FreeString (pszCmdLine, pszCmdLineA);
81 BOOL InitApplication (HINSTANCE hInst, LPTSTR pszCmdLine, int nCmdShow)
83 TaLocale_LoadCorrespondingModule (hInst);
85 memset (&g, 0x00, sizeof(g));
87 g.hAccel = TaLocale_LoadAccelerators (ACCEL_MAIN);
90 TCHAR szTitle[ cchRESOURCE ];
91 GetString (szTitle, IDS_APP_TITLE);
92 if ((hPrevious = FindWindow (TEXT("AFSManagerClass"), szTitle)) != NULL)
95 SendMessage (hPrevious, WM_SHOW_YOURSELF, 0, 0);
99 AfsAppLib_SetAppName(szTitle);
100 AfsAppLib_SetPumpRoutine(PumpMessage);
102 TASKQUEUE_PARAMS tqp;
103 memset (&tqp, 0x00, sizeof(tqp));
104 tqp.nThreadsMax = 10;
105 tqp.fnCreateTaskPacket = CreateTaskPacket;
106 tqp.fnPerformTask = PerformTask;
107 tqp.fnFreeTaskPacket = FreeTaskPacket;
108 AfsAppLib_InitTaskQueue (&tqp);
110 Main_ConfigureHelp();
112 // Determine how the app is supposed to look--that is, remember what it
113 // looked like last time, and if there was no "last time", pick some
116 if (!RestoreSettings (REGSTR_SETTINGS_BASE, REGSTR_SETTINGS_PATH, REGVAL_SETTINGS, &gr, sizeof(gr), wVerGLOBALS_RESTORED))
118 memset (&gr, 0x00, sizeof(gr));
119 SetRectEmpty (&gr.rMain);
120 SetRectEmpty (&gr.rMainPreview);
121 SetRectEmpty (&gr.rServerLast);
122 SetRectEmpty (&gr.rViewLog);
123 SetRectEmpty (&gr.rActions);
129 gr.tabLast = tabFILESETS;
131 Server_SetDefaultView_Horz (&gr.diHorz.viewSvr);
132 Server_SetDefaultView_Vert (&gr.diVert.viewSvr);
133 Services_SetDefaultView (&gr.viewSvc);
134 Aggregates_SetDefaultView (&gr.viewAgg);
135 Filesets_SetDefaultView (&gr.viewSet);
136 Replicas_SetDefaultView (&gr.viewRep);
137 Action_SetDefaultView (&gr.viewAct);
138 Server_Key_SetDefaultView (&gr.viewKey);
140 gr.diHorz.cSplitter = -100;
141 gr.diVert.cSplitter = -89;
143 gr.cbQuotaUnits = cb1KB;
145 gr.fOpenMonitors = TRUE;
146 gr.fCloseUnmonitors = TRUE;
147 gr.fServerLongNames = FALSE;
148 gr.fDoubleClickOpens = 2;
149 gr.fWarnBadCreds = TRUE;
158 if (!AfsClass_Initialize (&status))
160 if (status == ADMCLIENTCANTINITAFSLOCATION)
161 ImmediateErrorDialog (status, IDS_ERROR_CANT_INIT_AFSCLASS_INSTALL);
163 ImmediateErrorDialog (status, IDS_ERROR_CANT_INIT_AFSCLASS_UNKNOWN);
167 AfsClass_RequestLongServerNames (gr.fServerLongNames);
168 AfsClass_SpecifyRefreshDomain (AFSCLASS_WANT_VOLUMES);
170 // Create a notification object for the AFSClass library, so that it can
171 // let us know when anything changes. The notification handler we'll
172 // install will take requests from the rest of the SVRMGR package and
173 // forward notifications around to whichever windows are actually
176 CreateNotificationDispatch();
178 // Create a few variations on WC_DIALOG, so we get appropriate icons on
182 GetClassInfo (THIS_HINST, MAKEINTRESOURCE( WC_DIALOG ), &wc);
183 wc.hInstance = THIS_HINST;
184 wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
185 wc.lpszClassName = TEXT("AFSManagerClass");
186 wc.style |= CS_GLOBALCLASS;
189 GetClassInfo (THIS_HINST, MAKEINTRESOURCE( WC_DIALOG ), &wc);
190 wc.hInstance = THIS_HINST;
191 wc.hIcon = TaLocale_LoadIcon (IDI_SERVER);
192 wc.lpszClassName = TEXT("ServerWindowClass");
193 wc.style |= CS_GLOBALCLASS;
196 // Okay, the big step: create the main window (ie, the servers list).
197 // Note that it doesn't get shown yet!
199 CMDLINEOP op = ParseCommandLine (pszCmdLine);
200 if (op == opCLOSEAPP)
203 if (op == opLOOKUPERRORCODE)
209 g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DialogProc);
213 if (op != opNOCELLDIALOG)
215 if (OpenCellDialog() != IDOK)
223 void ExitApplication (void)
230 if (g.hMain && IsWindow(g.hMain))
232 if (gr.fPreview && !gr.fVert)
233 FL_StoreView (GetDlgItem (g.hMain, IDC_SERVERS), &gr.diHorz.viewSvr);
235 FL_StoreView (GetDlgItem (g.hMain, IDC_SERVERS), &gr.diVert.viewSvr);
238 wpl.length = sizeof(wpl);
239 if (GetWindowPlacement (g.hMain, &wpl))
242 gr.rMainPreview = wpl.rcNormalPosition;
244 gr.rMain = wpl.rcNormalPosition;
248 StoreSettings (REGSTR_SETTINGS_BASE, REGSTR_SETTINGS_PATH, REGVAL_SETTINGS, &gr, sizeof(gr), wVerGLOBALS_RESTORED);
250 if (Subsets_SaveIfDirty (g.sub))
252 if (Action_fAnyActive()) // just *pretend* to close the app
254 Action_WindowToTop (FALSE);
255 ShowWindow (g.hMain, SW_HIDE);
260 PostQuitMessage (g.rc);
266 void PumpMessage (MSG *lpm)
268 if (g.hMain && IsWindow (g.hMain))
270 if (GetActiveWindow())
272 if (TranslateAccelerator (GetActiveWindow(), g.hAccel, lpm))
277 if (!IsMemoryManagerMessage (lpm))
279 TranslateMessage (lpm);
280 DispatchMessage (lpm);
285 BOOL cdecl StartThread (DWORD (WINAPI *lpfnStart)(PVOID lp), ...)
288 va_start (arg, lpfnStart);
289 PVOID lp = va_arg (arg, PVOID);
294 if ((hThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)lpfnStart, lp, 0, &dwThreadID)) == NULL)
297 SetThreadPriority (hThread, THREAD_PRIORITY_BELOW_NORMAL);