Back to index

lightning-sunbird  0.9+nobinonly
dialogs.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Sean Su <ssu@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "extern.h"
00041 #include "extra.h"
00042 #include "dialogs.h"
00043 #include "ifuncns.h"
00044 #include "parser.h"
00045 #include "rdi.h"
00046 
00047 void ParseAllUninstallLogs()
00048 {
00049   char  szFileInstallLog[MAX_BUF];
00050   char  szKey[MAX_BUF];
00051   sil   *silFile;
00052   ULONG ulFileFound;
00053   ULONG ulRv = 0;
00054 
00055   UndoDesktopIntegration();
00056   ulFileFound = GetLogFile(ugUninstall.szLogPath, ugUninstall.szLogFilename, szFileInstallLog, sizeof(szFileInstallLog));
00057   while(ulFileFound)
00058   {
00059     if((silFile = InitSilNodes(szFileInstallLog)) != NULL)
00060     {
00061       FileDelete(szFileInstallLog);
00062       ulRv = Uninstall(silFile);
00063       DeInitSilNodes(&silFile);
00064       if(ulRv == WTD_CANCEL)
00065         break;
00066     }
00067 
00068     ulFileFound = GetLogFile(ugUninstall.szLogPath, ugUninstall.szLogFilename, szFileInstallLog, sizeof(szFileInstallLog));
00069   }
00070 
00071   if(ulRv != WTD_CANCEL)
00072   {
00073     strcpy(szFileInstallLog, ugUninstall.szLogPath);
00074     AppendBackSlash(szFileInstallLog, MAX_BUF);
00075     strcat(szFileInstallLog, ugUninstall.szLogFilename);
00076     if(FileExists(szFileInstallLog))
00077     {
00078       if((silFile = InitSilNodes(szFileInstallLog)) != NULL)
00079       {
00080         FileDelete(szFileInstallLog);
00081         Uninstall(silFile);
00082         DeInitSilNodes(&silFile);
00083       }
00084     }
00085 
00086     /* update Wininit.ini to remove itself at reboot */
00087     RemoveUninstaller(ugUninstall.szUninstallFilename);
00088   }
00089 }
00090 
00091 MRESULT APIENTRY DlgProcUninstall(HWND hDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
00092 {
00093   char  szBuf[MAX_BUF];
00094   SWP   swpDlg;
00095 
00096   switch(msg)
00097   {
00098     case WM_INITDLG:
00099       WinSetPresParam(hDlg, PP_FONTNAMESIZE,
00100                       strlen(ugUninstall.szDefinedFont)+1, ugUninstall.szDefinedFont);
00101       WinSetWindowText(hDlg, diUninstall.szTitle);
00102       sprintf(szBuf, diUninstall.szMessage0, ugUninstall.szDescription);
00103       WinSetDlgItemText(hDlg, IDC_MESSAGE0, szBuf);
00104       GetPrivateProfileString("Dialog Uninstall", "Yes", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00105       WinSetDlgItemText(hDlg, IDWIZNEXT, szBuf);
00106       GetPrivateProfileString("Dialog Uninstall", "No", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00107       WinSetDlgItemText(hDlg, DID_CANCEL, szBuf);
00108 
00109       WinQueryWindowPos(hDlg, &swpDlg);
00110       WinSetWindowPos(hDlg,
00111                       HWND_TOP,
00112                       (ulScreenX/2)-(swpDlg.cx/2),
00113                       (ulScreenY/2)-(swpDlg.cy/2),
00114                       0,
00115                       0,
00116                       SWP_MOVE);
00117       break;
00118 
00119     case WM_COMMAND:
00120       switch ( SHORT1FROMMP( mp1 ) )
00121       {
00122         case IDWIZNEXT:
00123           WinEnableWindow(WinWindowFromID(hDlg, IDWIZNEXT), FALSE);
00124           WinEnableWindow(WinWindowFromID(hDlg, DID_CANCEL), FALSE);
00125           ParseAllUninstallLogs();
00126           WinDestroyWindow(hDlg);
00127           WinPostQueueMsg(0, WM_QUIT, 0, 0);
00128           break;
00129 
00130         case DID_CANCEL:
00131           WinDestroyWindow(hDlg);
00132           WinPostQueueMsg(0, WM_QUIT, 0, 0);
00133           break;
00134 
00135         default:
00136           break;
00137       }
00138       break;
00139   }
00140   return(WinDefDlgProc(hDlg, msg, mp1, mp2));
00141 }
00142 
00143 MRESULT APIENTRY DlgProcWhatToDo(HWND hDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
00144 {
00145   char  szBuf[MAX_BUF];
00146   SWP   swpDlg;
00147 
00148   switch(msg)
00149   {
00150     case WM_INITDLG:
00151       WinSetPresParam(hDlg, PP_FONTNAMESIZE,
00152                       strlen(ugUninstall.szDefinedFont)+1, ugUninstall.szDefinedFont);
00153       GetPrivateProfileString("Messages", "DLG_REMOVE_FILE_TITLE", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00154       WinSetWindowText(hDlg, szBuf);
00155 
00156       if((PSZ)mp2 != NULL)
00157         WinSetDlgItemText(hDlg, IDC_STATIC_SHARED_FILENAME, (PSZ)mp2);
00158 
00159       GetPrivateProfileString("Dialog Uninstall", "Message1", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00160       WinSetDlgItemText(hDlg, IDC_MESSAGE0, szBuf);
00161       GetPrivateProfileString("Dialog Uninstall", "Message2", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00162       WinSetDlgItemText(hDlg, IDC_MESSAGE1, szBuf);
00163       GetPrivateProfileString("Dialog Uninstall", "FileName", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00164       WinSetDlgItemText(hDlg, IDC_STATIC, szBuf);
00165       GetPrivateProfileString("Dialog Uninstall", "No", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00166       WinSetDlgItemText(hDlg, ID_NO, szBuf);
00167       GetPrivateProfileString("Dialog Uninstall", "NoToAll", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00168       WinSetDlgItemText(hDlg, ID_NO_TO_ALL, szBuf);
00169       GetPrivateProfileString("Dialog Uninstall", "Yes", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00170       WinSetDlgItemText(hDlg, ID_YES, szBuf);
00171       GetPrivateProfileString("Dialog Uninstall", "YesToAll", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00172       WinSetDlgItemText(hDlg, ID_YES_TO_ALL, szBuf);
00173 
00174       /* Center dialog */
00175       WinQueryWindowPos(hDlg, &swpDlg);
00176       WinSetWindowPos(hDlg,
00177                       HWND_TOP,
00178                       (ulScreenX/2)-(swpDlg.cx/2),
00179                       (ulScreenY/2)-(swpDlg.cy/2),
00180                       0,
00181                       0,
00182                       SWP_MOVE);
00183       break;
00184 
00185     case WM_COMMAND:
00186       switch ( SHORT1FROMMP( mp1 ) )
00187       {
00188         case ID_NO:
00189           WinDismissDlg(hDlg, WTD_NO);
00190           break;
00191 
00192         case ID_NO_TO_ALL:
00193           WinDismissDlg(hDlg, WTD_NO_TO_ALL);
00194           break;
00195 
00196         case ID_YES:
00197           WinDismissDlg(hDlg, WTD_YES);
00198           break;
00199 
00200         case ID_YES_TO_ALL:
00201           WinDismissDlg(hDlg, WTD_YES_TO_ALL);
00202           break;
00203 
00204         default:
00205           break;
00206       }
00207       break;
00208   }
00209   return(WinDefDlgProc(hDlg, msg, mp1, mp2));
00210 }
00211 
00212 MRESULT APIENTRY DlgProcMessage(HWND hDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
00213 {
00214   SWP       swpDlg;
00215   HWND      hSTMessage = WinWindowFromID(hDlg, IDC_MESSAGE); /* handle to the Static Text message window */
00216   HPS       hpsSTMessage;
00217   RECTL     rectlString;
00218   int       i;
00219 
00220   switch(msg)
00221   {
00222     case WM_INITDLG:
00223       WinSetPresParam(hDlg, PP_FONTNAMESIZE,
00224                       strlen(ugUninstall.szDefinedFont)+1, ugUninstall.szDefinedFont);
00225       break;
00226 
00227     case WM_COMMAND:
00228       switch ( SHORT1FROMMP( mp1 ) )
00229       {
00230         case IDC_MESSAGE:
00231           hpsSTMessage = WinGetPS(hSTMessage);
00232 
00233           rectlString.xLeft = 0;
00234           rectlString.xRight = 10000;
00235           rectlString.yTop = 10000;
00236           rectlString.yBottom = 0;
00237           WinDrawText(hpsSTMessage, strlen((char*)mp2), (char*)mp2,
00238                             &rectlString, 0, 0,
00239                             DT_BOTTOM | DT_QUERYEXTENT | DT_TEXTATTRS | DT_WORDBREAK);
00240           WinReleasePS(hpsSTMessage);
00241 
00242           WinSetWindowPos(hDlg, HWND_TOP,
00243                       (ulScreenX/2)-((rectlString.xRight + 55)/2),
00244                       (ulScreenY/2)-((rectlString.yTop + 50)/2),
00245                       rectlString.xRight + 55,
00246                       rectlString.yTop + 50,
00247                       SWP_SIZE | SWP_MOVE);
00248 
00249           WinQueryWindowPos(hDlg, &swpDlg);
00250 
00251           WinSetWindowPos(hSTMessage,
00252                          HWND_TOP,
00253                          ulDlgFrameX,
00254                          ulDlgFrameY,
00255                          swpDlg.cx-2*ulDlgFrameX,
00256                          swpDlg.cy-2*ulDlgFrameY-ulTitleBarY,
00257                          SWP_SIZE | SWP_MOVE);
00258 
00259           for(i = 0; i < strlen((PSZ)mp2); i++)
00260           {
00261             if((((PSZ)mp2)[i] == '\r') || (((PSZ)mp2)[i] == '\n')) 
00262               ((PSZ)mp2)[i] = ' ';
00263           }
00264 
00265           WinSetDlgItemText(hDlg, IDC_MESSAGE, (PSZ)mp2);
00266           return (MRESULT)TRUE;
00267       }
00268       break;
00269   }
00270   return(WinDefDlgProc(hDlg, msg, mp1, mp2));
00271 }
00272 
00273 void ProcessWindowsMessages()
00274 {
00275   QMSG qmsg;
00276 
00277   while(WinPeekMsg((HAB)0, &qmsg, 0, 0, 0, PM_REMOVE))
00278   {
00279     WinDispatchMsg((HAB)0, &qmsg );
00280   }
00281 }
00282 
00283 void ShowMessage(PSZ szMessage, BOOL bShow)
00284 {
00285   char szBuf[MAX_BUF];
00286 
00287   if(ugUninstall.ulMode != SILENT)
00288   {
00289     if((bShow) && (hDlgMessage == NULL))
00290     {
00291       memset(szBuf, 0, sizeof(szBuf));
00292       GetPrivateProfileString("Messages", "MB_MESSAGE_STR", "", szBuf, sizeof(szBuf), szFileIniUninstall);
00293       hDlgMessage = InstantiateDialog(hWndMain, DLG_MESSAGE, szBuf, DlgProcMessage);
00294       WinSendMsg(hDlgMessage, WM_COMMAND, IDC_MESSAGE, (MPARAM)szMessage);
00295     }
00296     else if(!bShow && hDlgMessage)
00297     {
00298       WinDestroyWindow(hDlgMessage);
00299       hDlgMessage = NULL;
00300     }
00301   }
00302 }
00303 
00304 HWND InstantiateDialog(HWND hParent, ULONG ulDlgID, PSZ szTitle, PFNWP pfnwpDlgProc)
00305 {
00306   char szBuf[MAX_BUF];
00307   HWND hDlg = NULL;
00308   ATOM atom;
00309 
00310   hDlg = WinLoadDlg(HWND_DESKTOP, hParent, pfnwpDlgProc, 0, ulDlgID, NULL);
00311 
00312   if (hDlg == NULL)
00313   {
00314     char szEDialogCreate[MAX_BUF];
00315 
00316     if(GetPrivateProfileString("Messages", "ERROR_DIALOG_CREATE", "", szEDialogCreate, sizeof(szEDialogCreate), szFileIniUninstall))
00317     {
00318       sprintf(szBuf, szEDialogCreate, szTitle);
00319       PrintError(szBuf, ERROR_CODE_SHOW);
00320     }
00321 
00322     WinPostQueueMsg(NULL, WM_QUIT, 1, 0);
00323   }
00324 
00325   atom = WinFindAtom(WinQuerySystemAtomTable(), CLASS_NAME);
00326   WinSetWindowULong(hDlg, QWL_USER, atom);
00327 
00328   return(hDlg);
00329 }