Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsztool.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MAX_BUF   4096
#define ERROR_CODE_HIDE   0
#define ERROR_CODE_SHOW   1
#define PP_FILENAME_ONLY   1
#define PP_PATH_ONLY   2
#define PP_ROOT_ONLY   3

Functions

void PrintError (LPSTR szMsg, DWORD dwErrorCodeSH)
void RemoveQuotes (LPSTR lpszSrc, LPSTR lpszDest, int dwDestSize)
void RemoveBackSlash (LPSTR szInput)
void AppendBackSlash (LPSTR szInput, DWORD dwInputSize)
void ParsePath (LPSTR szInput, LPSTR szOutput, DWORD dwOutputSize, DWORD dwType)
long FileExists (LPSTR szFile)
int GetArgC (LPSTR lpszCommandLine)
LPSTR GetArgV (LPSTR lpszCommandLine, int iIndex, LPSTR lpszDest, int iDestSize)
void AddFile (HANDLE hExe, LPSTR lpszFile)
BOOL APIENTRY ExtractFilesProc (HANDLE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG lParam)

Define Documentation

Definition at line 45 of file nsztool.h.

Definition at line 46 of file nsztool.h.

#define MAX_BUF   4096

Definition at line 43 of file nsztool.h.

Definition at line 49 of file nsztool.h.

Definition at line 50 of file nsztool.h.

Definition at line 51 of file nsztool.h.


Function Documentation

void AddFile ( HANDLE  hExe,
LPSTR  lpszFile 
)

Definition at line 385 of file nsztool.c.

{
  char        szBuf[MAX_BUF];
  char        szResourceName[MAX_BUF];
  HANDLE      hInputFile;
  DWORD       dwBytesRead;
  DWORD       dwFileSize;
  DWORD       dwFileSizeCmp;
  LPBYTE      lpBuf;
  LPBYTE      lpBufCmp;

  if(!hExe)
    exit(1);

  ParsePath(lpszFile, szResourceName, sizeof(szResourceName), PP_FILENAME_ONLY);
  strupr(szResourceName);
  hInputFile = CreateFile(lpszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

  if(hInputFile == INVALID_HANDLE_VALUE)
  {
    PrintError("CreateFile() failed", ERROR_CODE_SHOW);
    exit(1);
  }

  dwFileSize    = GetFileSize(hInputFile, NULL);
  dwFileSizeCmp = ((long)ceil(dwFileSize * 0.001)) + dwFileSize + 12;
  lpBuf         = (LPBYTE)malloc(dwFileSize);
  lpBufCmp      = (LPBYTE)malloc(dwFileSizeCmp + (sizeof(DWORD) * 2));
  if((lpBuf == NULL) || (lpBufCmp == NULL))
  {
    PrintError("Out of memory", ERROR_CODE_HIDE);
    exit(1);
  }

  ReadFile(hInputFile, lpBuf, dwFileSize, &dwBytesRead, NULL);
  if(dwBytesRead != dwFileSize)
  {
    wsprintf(szBuf, "Error reading file: %s", lpszFile);
    PrintError(szBuf, ERROR_CODE_HIDE);
    exit(1);
  }

  if(compress((lpBufCmp + (sizeof(DWORD) * 2)), &dwFileSizeCmp, (const Bytef*)lpBuf, dwFileSize) != Z_OK)
  {
    PrintError("Error occurred during compression of archives!", ERROR_CODE_HIDE);
    exit(1);
  }

  *(LPDWORD)lpBufCmp = dwFileSizeCmp;
  *(LPDWORD)(lpBufCmp + sizeof(DWORD)) = dwFileSize;

  if(!UpdateResource(hExe, "FILE", szResourceName, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
                     lpBufCmp, dwFileSizeCmp + (sizeof(DWORD) * 2)))
  {
    PrintError("UpdateResource() failed", ERROR_CODE_SHOW);
    exit(1);
  }

  free(lpBuf);
  if(!CloseHandle(hInputFile))
  {
    PrintError("CloseHandle() failed", ERROR_CODE_SHOW);
    exit(1);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AppendBackSlash ( LPSTR  szInput,
DWORD  dwInputSize 
)

Definition at line 1973 of file extra.c.

{
  DWORD dwInputLen = lstrlen(szInput);

  if(szInput)
  {
    if(*szInput == '\0')
    {
      if((dwInputLen + 1) < dwInputSize)
      {
        lstrcat(szInput, "\\");
      }
    }
    else if(*CharPrev(szInput, &szInput[dwInputLen]) != '\\')
    {
      if((dwInputLen + 1) < dwInputSize)
      {
        lstrcat(szInput, "\\");
      }
    }
  }
}
BOOL APIENTRY ExtractFilesProc ( HANDLE  hModule,
LPCTSTR  lpszType,
LPTSTR  lpszName,
LONG  lParam 
)

Definition at line 652 of file nsinstall.cpp.

{
       char   szTmpFile[MAX_PATH];
       char   szArcLstFile[MAX_PATH];
       HRSRC  hResInfo;
       HGLOBAL       hGlobal;
       LPBYTE lpBytes;
       LPBYTE lptr;
       LPBYTE lpBytesUnCmp;
       HANDLE hFile;
       char   szStatus[128];
       char   szText[4096];
       
       // Update the UI
       LoadString(hInst, IDS_STATUS_EXTRACTING, szText, sizeof(szText));
       wsprintf(szStatus, szText, lpszName);
       SetStatusLine(szStatus);

  if(gbUncompressOnly == TRUE)
    lstrcpy(szTmpFile, lpszName);
  else
  {
         // Create a file in the temp directory
         GetFullTempPathName(lpszName, sizeof(szTmpFile), szTmpFile);
    CreateDirectoriesAll(szTmpFile);
  }

  if((*gszFileToUncompress != '\0') && (lstrcmpi(lpszName, gszFileToUncompress) != 0))
    // We have a file to uncompress, but the one found is not the one we want,
    // so return TRUE to continue looking for the right one.
    return TRUE;

       // Extract the file
       hResInfo = FindResource((HINSTANCE)hModule, lpszName, lpszType);
       hGlobal = LoadResource((HINSTANCE)hModule, hResInfo);
       lpBytes = (LPBYTE)LockResource(hGlobal);

       // Create the file
       hFile = CreateFile(szTmpFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL);

       if (hFile != INVALID_HANDLE_VALUE) {
              DWORD  dwSize;
              DWORD  dwSizeUnCmp;
    DWORD dwTemp;

         GetFullTempPathName("Archive.lst", sizeof(szArcLstFile), szArcLstFile);
    WritePrivateProfileString("Archives", lpszName, "TRUE", szArcLstFile);

    lptr = (LPBYTE)malloc((*(LPDWORD)(lpBytes + sizeof(DWORD))) + 1);
    if(!lptr)
    {
      char szBuf[512];

      LoadString(hInst, IDS_ERROR_OUT_OF_MEMORY, szBuf, sizeof(szBuf));
      MessageBox(NULL, szBuf, NULL, MB_OK | MB_ICONEXCLAMATION);
      return FALSE;
    }

    lpBytesUnCmp = lptr;
    dwSizeUnCmp  = *(LPDWORD)(lpBytes + sizeof(DWORD));

              // Copy the file. The first DWORD specifies the size of the file
              dwSize = *(LPDWORD)lpBytes;
              lpBytes += (sizeof(DWORD) * 2);

    dwTemp = uncompress(lpBytesUnCmp, &dwSizeUnCmp, lpBytes, dwSize);

    while (dwSizeUnCmp > 0)
    {
                     DWORD  dwBytesToWrite, dwBytesWritten;

      ProcessWindowsMessages();

                     dwBytesToWrite = dwSizeUnCmp > 4096 ? 4096 : dwSizeUnCmp;
                     if (!WriteFile(hFile, lpBytesUnCmp, dwBytesToWrite, &dwBytesWritten, NULL))
      {
                            char szBuf[512];

       LoadString(hInst, IDS_STATUS_EXTRACTING, szText, sizeof(szText));
                            wsprintf(szBuf, szText, szTmpFile);
                            MessageBox(NULL, szBuf, szTitle, MB_OK | MB_ICONEXCLAMATION);
                            FreeResource(hResInfo);
        if(lptr)
          free(lptr);

                            return FALSE;
                     }

                     dwSizeUnCmp -= dwBytesWritten;
                     lpBytesUnCmp += dwBytesWritten;

                     // Update the UI to reflect the total number of bytes written
                     static DWORD  nBytesWritten = 0;

                     nBytesWritten += dwBytesWritten;
                     UpdateProgressBar(nBytesWritten * 100 / nTotalBytes);
              }

              CloseHandle(hFile);
       }

       // Release the resource
       FreeResource(hResInfo);
  if(lptr)
    free(lptr);

  if((*gszFileToUncompress != '\0') && (lstrcmpi(lpszName, gszFileToUncompress) == 0))
    // We have a file to uncompress, and we have uncompressed it,
    // so return FALSE to stop uncompressing any other file.
    return FALSE;

       return TRUE;  // keep enumerating
}

Here is the call graph for this function:

Here is the caller graph for this function:

long FileExists ( LPSTR  szFile)

Definition at line 8786 of file extra.c.

{
  DWORD rv;

  if((rv = GetFileAttributes(szFile)) == -1)
  {
    return(FALSE);
  }
  else
  {
    return(rv);
  }
}
int GetArgC ( LPSTR  lpszCommandLine)

Definition at line 907 of file extra.c.

{
  int   i;
  int   iArgCount;
  int   iStrLength;
  LPSTR lpszBeginStr;
  BOOL  bFoundQuote;
  BOOL  bFoundSpace;

  iArgCount    = 0;
  lpszBeginStr = GetFirstNonSpace(lpszCommandLine);

  if(lpszBeginStr == NULL)
    return(iArgCount);

  iStrLength   = lstrlen(lpszBeginStr);
  bFoundQuote  = FALSE;
  bFoundSpace  = TRUE;

  for(i = 0; i < iStrLength; i++)
  {
    if(lpszCommandLine[i] == '\"')
    {
      if(bFoundQuote == FALSE)
      {
        ++iArgCount;
        bFoundQuote = TRUE;
      }
      else
      {
        bFoundQuote = FALSE;
      }
    }
    else if(bFoundQuote == FALSE)
    {
      if(!isspace(lpszCommandLine[i]) && (bFoundSpace == TRUE))
      {
        ++iArgCount;
        bFoundSpace = FALSE;
      }
      else if(isspace(lpszCommandLine[i]))
      {
        bFoundSpace = TRUE;
      }
    }
  }

  return(iArgCount);
}
LPSTR GetArgV ( LPSTR  lpszCommandLine,
int  iIndex,
LPSTR  lpszDest,
int  iDestSize 
)

Definition at line 959 of file extra.c.

{
  int   i;
  int   j;
  int   iArgCount;
  int   iStrLength;
  LPSTR lpszBeginStr;
  LPSTR lpszDestTemp;
  BOOL  bFoundQuote;
  BOOL  bFoundSpace;

  iArgCount    = 0;
  lpszBeginStr = GetFirstNonSpace(lpszCommandLine);

  if(lpszBeginStr == NULL)
    return(NULL);

  lpszDestTemp = (char *)calloc(iDestSize, sizeof(char));
  if(lpszDestTemp == NULL)
  {
    PrintError("Out of memory", ERROR_CODE_HIDE);
    exit(1);
  }

  ZeroMemory(lpszDest, iDestSize);
  iStrLength    = lstrlen(lpszBeginStr);
  bFoundQuote   = FALSE;
  bFoundSpace   = TRUE;
  j             = 0;

  for(i = 0; i < iStrLength; i++)
  {
    if(lpszCommandLine[i] == '\"')
    {
      if(bFoundQuote == FALSE)
      {
        ++iArgCount;
        bFoundQuote = TRUE;
      }
      else
      {
        bFoundQuote = FALSE;
      }
    }
    else if(bFoundQuote == FALSE)
    {
      if(!isspace(lpszCommandLine[i]) && (bFoundSpace == TRUE))
      {
        ++iArgCount;
        bFoundSpace = FALSE;
      }
      else if(isspace(lpszCommandLine[i]))
      {
        bFoundSpace = TRUE;
      }
    }

    if((iIndex == (iArgCount - 1)) &&
      ((bFoundQuote == TRUE) || (bFoundSpace == FALSE) ||
      ((bFoundQuote == FALSE) && (lpszCommandLine[i] == '\"'))))
    {
      if(j < iDestSize)
      {
        lpszDestTemp[j] = lpszCommandLine[i];
        ++j;
      }
      else
      {
        lpszDestTemp[j] = '\0';
      }
    }
  }

  RemoveQuotes(lpszDestTemp, lpszDest, iDestSize);
  free(lpszDestTemp);
  return(lpszDest);
}
void ParsePath ( LPSTR  szInput,
LPSTR  szOutput,
DWORD  dwOutputSize,
DWORD  dwType 
)

Definition at line 619 of file extra.c.

{
  int   iCounter;
  DWORD dwCounter;
  DWORD dwInputLen;
  BOOL  bFound;

  if((szInput != NULL) && (szOutput != NULL))
  {
    bFound        = FALSE;
    dwInputLen    = lstrlen(szInput);
    ZeroMemory(szOutput, dwOutputSize);

    if(dwInputLen < dwOutputSize)
    {
      switch(dwType)
      {
        case PP_FILENAME_ONLY:
          for(iCounter = dwInputLen - 1; iCounter >= 0; iCounter--)
          {
            if(szInput[iCounter] == '\\')
            {
              lstrcpy(szOutput, &szInput[iCounter + 1]);
              bFound = TRUE;
              break;
            }
          }
          if(bFound == FALSE)
            lstrcpy(szOutput, szInput);

          break;

        case PP_PATH_ONLY:
          for(iCounter = dwInputLen - 1; iCounter >= 0; iCounter--)
          {
            if(szInput[iCounter] == '\\')
            {
              lstrcpy(szOutput, szInput);
              szOutput[iCounter + 1] = '\0';
              bFound = TRUE;
              break;
            }
          }
          if(bFound == FALSE)
            lstrcpy(szOutput, szInput);

          break;

        case PP_ROOT_ONLY:
          if(szInput[1] == ':')
          {
            szOutput[0] = szInput[0];
            szOutput[1] = szInput[1];
            AppendBackSlash(szOutput, dwOutputSize);
          }
          else if(szInput[1] == '\\')
          {
            int iFoundBackSlash = 0;
            for(dwCounter = 0; dwCounter < dwInputLen; dwCounter++)
            {
              if(szInput[dwCounter] == '\\')
              {
                szOutput[dwCounter] = szInput[dwCounter];
                ++iFoundBackSlash;
              }

              if(iFoundBackSlash == 3)
                break;
            }

            if(iFoundBackSlash != 0)
              AppendBackSlash(szOutput, dwOutputSize);
          }
          break;
      }
    }
  }
}
void PrintError ( LPSTR  szMsg,
DWORD  dwErrorCodeSH 
)

Definition at line 193 of file extra.c.

{
  DWORD dwErr;
  char  szErrorString[MAX_BUF];

  if(dwErrorCodeSH == ERROR_CODE_SHOW)
  {
    dwErr = GetLastError();
    wsprintf(szErrorString, "%d : %s", dwErr, szMsg);
  }
  else
    wsprintf(szErrorString, "%s", szMsg);

  if((sgProduct.mode != SILENT) && (sgProduct.mode != AUTO))
  {
    MessageBox(hWndMain, szErrorString, NULL, MB_ICONEXCLAMATION);
  }
  else if(sgProduct.mode == AUTO)
  {
    ShowMessage(szErrorString, TRUE);
    Delay(5);
    ShowMessage(szErrorString, FALSE);
  }
}
void RemoveBackSlash ( LPSTR  szInput)

Definition at line 1951 of file extra.c.

{
  DWORD dwInputLen;
  BOOL  bDone;
  char  *ptrChar = NULL;

  if(szInput)
  {
    dwInputLen = lstrlen(szInput);
    bDone = FALSE;
    ptrChar = &szInput[dwInputLen];
    while(!bDone)
    {
      ptrChar = CharPrev(szInput, ptrChar);
      if(*ptrChar == '\\')
        *ptrChar = '\0';
      else
        bDone = TRUE;
    }
  }
}
void RemoveQuotes ( LPSTR  lpszSrc,
LPSTR  lpszDest,
int  dwDestSize 
)

Definition at line 830 of file extra.c.

{
  char *lpszBegin;

  if(lstrlen(lpszSrc) > iDestSize)
    return;

  if(*lpszSrc == '\"')
    lpszBegin = &lpszSrc[1];
  else
    lpszBegin = lpszSrc;

  lstrcpy(lpszDest, lpszBegin);

  if(lpszDest[lstrlen(lpszDest) - 1] == '\"')
    lpszDest[lstrlen(lpszDest) - 1] = '\0';
}