~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/wizard/os2/setup/logging.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 * 
 
12
 * The Original Code is Mozilla Navigator.
 
13
 * 
 
14
 * The Initial Developer of the Original Code is Netscape Communications
 
15
 * Corp.  Portions created by Netscape Communications Corp. are
 
16
 * Copyright (C) 2001 Netscape Communications Corp.  All Rights
 
17
 * Reserved.
 
18
 * 
 
19
 * Contributor(s): 
 
20
 *   Sean Su <ssu@netscape.com>
 
21
 */
 
22
 
 
23
#include "extern.h"
 
24
#include "logging.h"
 
25
#include "extra.h"
 
26
#include "ifuncns.h"
 
27
#include "xpi.h"
 
28
 
 
29
#define E_USER_CANCEL         -813
 
30
 
 
31
int AppendToGlobalMessageStream(char *szInfo)
 
32
{
 
33
  DWORD dwInfoLen = strlen(szInfo);
 
34
  DWORD dwMessageLen;
 
35
 
 
36
  if(gErrorMessageStream.bEnabled && gErrorMessageStream.szMessage)
 
37
  {
 
38
    dwMessageLen = strlen(gErrorMessageStream.szMessage);
 
39
    if((dwInfoLen + dwMessageLen) >= gErrorMessageStream.dwMessageBufSize)
 
40
    {
 
41
      if(NS_GlobalReAlloc(&gErrorMessageStream.szMessage,
 
42
                          gErrorMessageStream.dwMessageBufSize,
 
43
                          dwInfoLen + dwMessageLen + MAX_BUF_TINY) == NULL)
 
44
        return(WIZ_OUT_OF_MEMORY);
 
45
 
 
46
      gErrorMessageStream.dwMessageBufSize = dwInfoLen +
 
47
                                             dwMessageLen +
 
48
                                             MAX_BUF_TINY;
 
49
    }
 
50
 
 
51
    strcat(gErrorMessageStream.szMessage, szInfo);
 
52
  }
 
53
 
 
54
  return(WIZ_OK);
 
55
}
 
56
 
 
57
void LogISTime(int iType)
 
58
{
 
59
  char       szBuf[MAX_BUF];
 
60
  time_t     rawtime;
 
61
  struct tm* timeinfo;
 
62
 
 
63
  time ( &rawtime );
 
64
  timeinfo = localtime ( &rawtime );
 
65
 
 
66
  if(iType == W_START)
 
67
    sprintf(szBuf, "Start Log: %s\n", asctime (timeinfo));
 
68
  else
 
69
    sprintf(szBuf, "End Log: %s\n", asctime (timeinfo));
 
70
 
 
71
  UpdateInstallStatusLog(szBuf);
 
72
}
 
73
 
 
74
void LogISProductInfo(void)
 
75
{
 
76
  char szBuf[MAX_BUF];
 
77
 
 
78
  sprintf(szBuf, "\n    Product Info:\n");
 
79
  UpdateInstallStatusLog(szBuf);
 
80
 
 
81
  switch(sgProduct.ulMode)
 
82
  {
 
83
    case SILENT:
 
84
      sprintf(szBuf, "        Install mode: Silent\n");
 
85
      break;
 
86
    case AUTO:
 
87
      sprintf(szBuf, "        Install mode: Auto\n");
 
88
      break;
 
89
    default:
 
90
      sprintf(szBuf, "        Install mode: Normal\n");
 
91
      break;
 
92
  }
 
93
  UpdateInstallStatusLog(szBuf);
 
94
 
 
95
  sprintf(szBuf, "        Company name: %s\n        Product name (external): %s\n        Product name (internal): %s\n        Uninstall Filename: %s\n        UserAgent: %s\n        Alternate search path: %s\n",
 
96
           sgProduct.szCompanyName,
 
97
           sgProduct.szProductName,
 
98
           sgProduct.szProductNameInternal,
 
99
           sgProduct.szUninstallFilename,
 
100
           sgProduct.szUserAgent,
 
101
           sgProduct.szAlternateArchiveSearchPath);
 
102
  UpdateInstallStatusLog(szBuf);
 
103
}
 
104
 
 
105
void LogISDestinationPath(void)
 
106
{
 
107
  char szBuf[MAX_BUF];
 
108
 
 
109
  sprintf(szBuf,
 
110
           "\n    Destination Path:\n        Main: %s\n        SubPath: %s\n",
 
111
           sgProduct.szPath,
 
112
           sgProduct.szSubPath);
 
113
  UpdateInstallStatusLog(szBuf);
 
114
}
 
115
 
 
116
void LogISSetupType(void)
 
117
{
 
118
  char szBuf[MAX_BUF_TINY];
 
119
 
 
120
  switch(ulSetupType)
 
121
  {
 
122
    case ST_RADIO3:
 
123
      sprintf(szBuf, "\n    Setup Type: %s\n",
 
124
               diSetupType.stSetupType3.szDescriptionShort);
 
125
      break;
 
126
 
 
127
    case ST_RADIO2:
 
128
      sprintf(szBuf, "\n    Setup Type: %s\n",
 
129
               diSetupType.stSetupType2.szDescriptionShort);
 
130
      break;
 
131
 
 
132
    case ST_RADIO1:
 
133
      sprintf(szBuf, "\n    Setup Type: %s\n",
 
134
               diSetupType.stSetupType1.szDescriptionShort);
 
135
      break;
 
136
 
 
137
    default:
 
138
      sprintf(szBuf, "\n    Setup Type: %s\n",
 
139
               diSetupType.stSetupType0.szDescriptionShort);
 
140
      break;
 
141
  }
 
142
 
 
143
  UpdateInstallStatusLog(szBuf);
 
144
}
 
145
 
 
146
void LogISComponentsSelected(void)
 
147
{
 
148
  char szBuf[MAX_BUF_TINY];
 
149
  siC  *siCNode;
 
150
  BOOL bFoundComponentSelected;
 
151
 
 
152
  sprintf(szBuf, "\n    Components selected:\n");
 
153
  UpdateInstallStatusLog(szBuf);
 
154
 
 
155
  bFoundComponentSelected = FALSE;
 
156
  siCNode = siComponents;
 
157
  do
 
158
  {
 
159
    if(siCNode == NULL)
 
160
      break;
 
161
 
 
162
    if(siCNode->dwAttributes & SIC_SELECTED)
 
163
    {
 
164
      if(!siCNode->bForceUpgrade)
 
165
        sprintf(szBuf,
 
166
                 "        %s\n",
 
167
                 siCNode->szDescriptionShort);
 
168
      else
 
169
        sprintf(szBuf,
 
170
                 "        %s (Required)\n",
 
171
                 siCNode->szDescriptionShort);
 
172
 
 
173
      UpdateInstallStatusLog(szBuf);
 
174
      bFoundComponentSelected = TRUE;
 
175
    }
 
176
 
 
177
    siCNode = siCNode->Next;
 
178
  } while((siCNode != NULL) && (siCNode != siComponents));
 
179
 
 
180
  if(!bFoundComponentSelected)
 
181
  {
 
182
    sprintf(szBuf, "        none\n");
 
183
    UpdateInstallStatusLog(szBuf);
 
184
  }
 
185
}
 
186
 
 
187
void LogISComponentsToDownload(void)
 
188
{
 
189
  char szBuf[MAX_BUF_TINY];
 
190
  char szArchivePath[MAX_BUF_MEDIUM];
 
191
  siC  *siCNode;
 
192
  BOOL bFoundComponentSelected;
 
193
  BOOL bFoundComponentsToDownload;
 
194
 
 
195
  sprintf(szBuf, "\n    Components to download:\n");
 
196
  UpdateInstallStatusLog(szBuf);
 
197
 
 
198
  bFoundComponentSelected = FALSE;
 
199
  bFoundComponentsToDownload = FALSE;
 
200
  siCNode = siComponents;
 
201
  do
 
202
  {
 
203
    if(siCNode == NULL)
 
204
      break;
 
205
 
 
206
    if(siCNode->dwAttributes & SIC_SELECTED)
 
207
    {
 
208
 
 
209
      if(LocateJar(siCNode,
 
210
                   szArchivePath,
 
211
                   sizeof(szArchivePath),
 
212
                   gbPreviousUnfinishedDownload) == AP_NOT_FOUND)
 
213
      {
 
214
        sprintf(szBuf,
 
215
                 "        %s will be downloaded\n",
 
216
                 siCNode->szDescriptionShort);
 
217
        bFoundComponentsToDownload = TRUE;
 
218
      }
 
219
      else
 
220
        sprintf(szBuf,
 
221
                 "        %s found: %s\n",
 
222
                 siCNode->szDescriptionShort,
 
223
                 szArchivePath);
 
224
 
 
225
      UpdateInstallStatusLog(szBuf);
 
226
      bFoundComponentSelected = TRUE;
 
227
    }
 
228
 
 
229
    siCNode = siCNode->Next;
 
230
  } while((siCNode != NULL) && (siCNode != siComponents));
 
231
 
 
232
  if(!bFoundComponentSelected)
 
233
  {
 
234
    sprintf(szBuf, "        none\n");
 
235
    UpdateInstallStatusLog(szBuf);
 
236
  }
 
237
  if(!bFoundComponentsToDownload)
 
238
  {
 
239
    sprintf(szBuf, "        **\n        ** All components have been found locally.  No components will be downloaded.\n        **\n");
 
240
    UpdateInstallStatusLog(szBuf);
 
241
  }
 
242
}
 
243
 
 
244
void LogISDownloadProtocol(DWORD dwProtocolType)
 
245
{
 
246
  char szBuf[MAX_BUF];
 
247
  char szProtocolType[MAX_BUF];
 
248
 
 
249
  switch(dwProtocolType)
 
250
  {
 
251
    case UP_HTTP:
 
252
      strcpy(szProtocolType, "HTTP");
 
253
      break;
 
254
 
 
255
    default:
 
256
      strcpy(szProtocolType, "FTP");
 
257
      break;
 
258
  }
 
259
 
 
260
  sprintf(szBuf, "\n    Download protocol: %s\n", szProtocolType);
 
261
  UpdateInstallStatusLog(szBuf);
 
262
}
 
263
 
 
264
void LogISDownloadStatus(char *szStatus, char *szFailedFile)
 
265
{
 
266
  char szBuf[MAX_BUF];
 
267
  siC   *siCObject = NULL;
 
268
  DWORD dwIndex;
 
269
 
 
270
  if(szFailedFile)
 
271
    sprintf(szBuf,
 
272
             "\n    Download status: %s\n          file: %s\n\n",
 
273
             szStatus,
 
274
             szFailedFile);
 
275
  else
 
276
    sprintf(szBuf,
 
277
             "\n    Download status: %s\n",
 
278
             szStatus);
 
279
  UpdateInstallStatusLog(szBuf);
 
280
 
 
281
  dwIndex = 0;
 
282
  siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
 
283
  while(siCObject)
 
284
  {
 
285
    if(siCObject->dwAttributes & SIC_SELECTED)
 
286
    {
 
287
      sprintf(szBuf, "        %s: NetRetries:%d, CRCRetries:%d, NetTimeOuts:%d\n",
 
288
               siCObject->szDescriptionShort,
 
289
               siCObject->iNetRetries,
 
290
               siCObject->iCRCRetries,
 
291
               siCObject->iNetTimeOuts);
 
292
      UpdateInstallStatusLog(szBuf);
 
293
    }
 
294
 
 
295
    ++dwIndex;
 
296
    siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
 
297
  }
 
298
}
 
299
 
 
300
void LogISComponentsFailedCRC(char *szList, int iWhen)
 
301
{
 
302
  char szBuf[MAX_BUF];
 
303
 
 
304
  if(iWhen == W_STARTUP)
 
305
  {
 
306
    if(szList && (*szList != '\0'))
 
307
      sprintf(szBuf,
 
308
               "\n    Components corrupted (startup):\n%s",
 
309
               szList);
 
310
    else
 
311
      sprintf(szBuf,
 
312
               "\n    Components corrupted (startup):\n        none\n");
 
313
  }
 
314
  else
 
315
  {
 
316
    if(szList && (*szList != '\0'))
 
317
      sprintf(szBuf,
 
318
               "\n    Components corrupted (download):\n%s",
 
319
               szList);
 
320
    else
 
321
      sprintf(szBuf,
 
322
               "\n    Components corrupted (download):\n        none\n");
 
323
  }
 
324
 
 
325
  UpdateInstallStatusLog(szBuf);
 
326
}
 
327
 
 
328
void LogISXPInstall(int iWhen)
 
329
{
 
330
  char szBuf[MAX_BUF];
 
331
 
 
332
  if(iWhen == W_START)
 
333
    sprintf(szBuf, "\n    XPInstall Start\n");
 
334
  else
 
335
    sprintf(szBuf, "    XPInstall End\n");
 
336
 
 
337
  UpdateInstallStatusLog(szBuf);
 
338
}
 
339
 
 
340
void LogISXPInstallComponent(char *szComponentName)
 
341
{
 
342
  char szBuf[MAX_BUF];
 
343
 
 
344
  sprintf(szBuf, "        %s", szComponentName);
 
345
  UpdateInstallStatusLog(szBuf);
 
346
}
 
347
 
 
348
void LogISXPInstallComponentResult(DWORD dwErrorNumber)
 
349
{
 
350
  char szBuf[MAX_BUF];
 
351
  char szErrorString[MAX_BUF];
 
352
 
 
353
//  GetErrorString(dwErrorNumber, szErrorString, sizeof(szErrorString));
 
354
  sprintf(szBuf, ": %d %s\n", dwErrorNumber, szErrorString);
 
355
  UpdateInstallStatusLog(szBuf);
 
356
}
 
357
 
 
358
void LogISLaunchApps(int iWhen)
 
359
{
 
360
  char szBuf[MAX_BUF];
 
361
 
 
362
  if(iWhen == W_START)
 
363
    sprintf(szBuf, "\n    Launch Apps Start\n");
 
364
  else
 
365
    sprintf(szBuf, "    Launch Apps End\n");
 
366
 
 
367
  UpdateInstallStatusLog(szBuf);
 
368
}
 
369
 
 
370
void LogISLaunchAppsComponent(char *szComponentName)
 
371
{
 
372
  char szBuf[MAX_BUF];
 
373
 
 
374
  sprintf(szBuf, "        launching %s\n", szComponentName);
 
375
  UpdateInstallStatusLog(szBuf);
 
376
}
 
377
 
 
378
void LogISLaunchAppsComponentUncompress(char *szComponentName, DWORD dwErr)
 
379
{
 
380
  char szBuf[MAX_BUF];
 
381
 
 
382
  sprintf(szBuf, "        uncompressing %s: %d\n", szComponentName, dwErr);
 
383
  UpdateInstallStatusLog(szBuf);
 
384
}
 
385
 
 
386
void LogISProcessXpcomFile(int iStatus, int iResult)
 
387
{
 
388
  char szBuf[MAX_BUF];
 
389
 
 
390
  if(iStatus == LIS_SUCCESS)
 
391
    sprintf(szBuf, "\n    Uncompressing Xpcom Succeeded: %d\n", iResult);
 
392
  else
 
393
    sprintf(szBuf, "\n    Uncompressing Xpcom Failed: %d\n", iResult);
 
394
 
 
395
  UpdateInstallStatusLog(szBuf);
 
396
}
 
397
 
 
398
void LogISDiskSpace(dsN *dsnComponentDSRequirement)
 
399
{
 
400
  ULONG     ulDSAvailable;
 
401
  dsN       *dsnTemp = NULL;
 
402
  char      szBuf[MAX_BUF];
 
403
  char      szDSRequired[MAX_BUF_TINY];
 
404
  char      szDSAvailable[MAX_BUF_TINY];
 
405
 
 
406
  if(dsnComponentDSRequirement != NULL)
 
407
  {
 
408
    sprintf(szBuf, "\n    Disk Space Info:\n");
 
409
    UpdateInstallStatusLog(szBuf);
 
410
    dsnTemp = dsnComponentDSRequirement;
 
411
    do
 
412
    {
 
413
      if(!dsnTemp)
 
414
        break;
 
415
 
 
416
      ulDSAvailable = GetDiskSpaceAvailable(dsnTemp->szVDSPath);
 
417
      _itoa(ulDSAvailable, szDSAvailable, 10);
 
418
      _itoa(dsnTemp->ulSpaceRequired, szDSRequired, 10);
 
419
      sprintf(szBuf,
 
420
               "             Path: %s\n         Required: %sKB\n        Available: %sKB\n",
 
421
               dsnTemp->szVDSPath,
 
422
               szDSRequired,
 
423
               szDSAvailable);
 
424
      UpdateInstallStatusLog(szBuf);
 
425
 
 
426
      dsnTemp = dsnTemp->Next;
 
427
    } while((dsnTemp != NULL) && (dsnTemp != dsnComponentDSRequirement));
 
428
  }
 
429
}
 
430
 
 
431
void LogISTurboMode(BOOL bTurboMode)
 
432
{
 
433
  char szBuf[MAX_BUF];
 
434
 
 
435
  if(bTurboMode)
 
436
    sprintf(szBuf, "\n    Turbo Mode: true\n");
 
437
  else
 
438
    sprintf(szBuf, "\n    Turbo Mode: false\n");
 
439
 
 
440
  UpdateInstallStatusLog(szBuf);
 
441
}
 
442
 
 
443
void LogMSProductInfo(void)
 
444
{
 
445
  char szBuf[MAX_BUF];
 
446
  char szOSType[MAX_BUF_TINY];
 
447
 
 
448
  GetOSTypeString(szOSType, sizeof(szOSType));
 
449
  if(*gSystemInfo.szExtraString != '\0')
 
450
    sprintf(szBuf, "UserAgent=%s/%s (%s,%d.%d.%d,%s)",
 
451
             sgProduct.szProductName,
 
452
             sgProduct.szUserAgent,
 
453
             szOSType,
 
454
             gSystemInfo.ulMajorVersion,
 
455
             gSystemInfo.ulMinorVersion,
 
456
             gSystemInfo.ulBuildNumber,
 
457
             gSystemInfo.szExtraString);
 
458
  else
 
459
    sprintf(szBuf, "UserAgent=%s/%s (%s,%d.%d.%d)",
 
460
             sgProduct.szProductName,
 
461
             sgProduct.szUserAgent,
 
462
             szOSType,
 
463
             gSystemInfo.ulMajorVersion,
 
464
             gSystemInfo.ulMinorVersion,
 
465
             gSystemInfo.ulBuildNumber);
 
466
 
 
467
  AppendToGlobalMessageStream(szBuf);
 
468
}
 
469
 
 
470
void LogMSDownloadProtocol(DWORD dwProtocolType)
 
471
{
 
472
  char szMessageStream[MAX_BUF_TINY];
 
473
  char szProtocolType[MAX_BUF];
 
474
 
 
475
  switch(dwProtocolType)
 
476
  {
 
477
    case UP_HTTP:
 
478
      strcpy(szProtocolType, "HTTP");
 
479
      break;
 
480
 
 
481
    default:
 
482
      strcpy(szProtocolType, "FTP");
 
483
      break;
 
484
  }
 
485
 
 
486
  sprintf(szMessageStream, "&DownloadProtocol=%s", szProtocolType);
 
487
  AppendToGlobalMessageStream(szMessageStream);
 
488
}
 
489
 
 
490
void LogMSDownloadStatus(int iDownloadStatus)
 
491
{
 
492
  char szMessageStream[MAX_BUF_TINY];
 
493
 
 
494
  sprintf(szMessageStream, "&DownloadStatus=%d", iDownloadStatus);
 
495
  AppendToGlobalMessageStream(szMessageStream);
 
496
  gErrorMessageStream.bSendMessage = TRUE;
 
497
}
 
498
 
 
499
void LogMSDownloadFileStatus(void)
 
500
{
 
501
  siC   *siCObject = NULL;
 
502
  DWORD dwIndex;
 
503
  char  szMessageStream[MAX_BUF];
 
504
 
 
505
  memset(szMessageStream, 0, sizeof(szMessageStream));
 
506
  dwIndex = 0;
 
507
  siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
 
508
  while(siCObject)
 
509
  {
 
510
    if(siCObject->iNetRetries ||
 
511
       siCObject->iCRCRetries ||
 
512
       siCObject->iNetTimeOuts)
 
513
    {
 
514
      char szFileInfo[MAX_BUF_SMALL];
 
515
 
 
516
      sprintf(szFileInfo,
 
517
               "&%s=%d,%d,%d",
 
518
               siCObject->szArchiveName,
 
519
               siCObject->iNetRetries,
 
520
               siCObject->iCRCRetries,
 
521
               siCObject->iNetTimeOuts);
 
522
 
 
523
      strcat(szMessageStream, szFileInfo);
 
524
    }
 
525
    ++dwIndex;
 
526
    siCObject = SiCNodeGetObject(dwIndex, TRUE, AC_ALL);
 
527
  }
 
528
 
 
529
  if(*szMessageStream != '\0')
 
530
    AppendToGlobalMessageStream(szMessageStream);
 
531
}
 
532
 
 
533
void LogMSXPInstallStatus(char *szFile, int iErr)
 
534
{
 
535
  char szMessageStream[MAX_BUF];
 
536
  static BOOL bAlreadyLogged = FALSE;
 
537
 
 
538
  if(bAlreadyLogged)
 
539
    return;
 
540
 
 
541
  if(szFile)
 
542
    sprintf(szMessageStream, "&XPInstallStatus=%d&XPInstallFile=%s", iErr, szFile);
 
543
  else
 
544
    sprintf(szMessageStream, "&XPInstallStatus=%d", iErr);
 
545
 
 
546
  AppendToGlobalMessageStream(szMessageStream);
 
547
  bAlreadyLogged = TRUE;
 
548
  if((iErr != E_REBOOT) &&
 
549
    (((iErr == E_USER_CANCEL) &&
 
550
       !gErrorMessageStream.bShowConfirmation) ||
 
551
     ((iErr != E_USER_CANCEL) &&
 
552
      (iErr != WIZ_OK))))
 
553
    gErrorMessageStream.bSendMessage = TRUE;
 
554
}
 
555
 
 
556
void LogMSTurboMode(BOOL bTurboMode)
 
557
{
 
558
  char szMessageStream[MAX_BUF];
 
559
 
 
560
  sprintf(szMessageStream, "&TM=%d", bTurboMode);
 
561
  AppendToGlobalMessageStream(szMessageStream);
 
562
}
 
563