コード例 #1
0
ファイル: nsinstall.cpp プロジェクト: rn10950/RetroZilla
void ParseCommandLine(LPSTR lpszCmdLine)
{
  char  szArgVBuf[MAX_BUF];
  int   i;
  int   iArgC;

  *szCmdLineToSetup = '\0';
  *gszFileToUncompress = '\0';
  dwMode = NORMAL;
  gbUncompressOnly = FALSE;
  iArgC  = GetArgC(lpszCmdLine);
  i      = 0;
  while(i < iArgC)
  {
    GetArgV(lpszCmdLine, i, szArgVBuf, sizeof(szArgVBuf));
    if((lstrcmpi(szArgVBuf, "-ms") == 0) || (lstrcmpi(szArgVBuf, "/ms") == 0))
    {
      dwMode = SILENT;
    }
    else if((lstrcmpi(szArgVBuf, "-u") == 0) || (lstrcmpi(szArgVBuf, "/u") == 0))
    {
      gbUncompressOnly = TRUE;
      GetArgV(lpszCmdLine, i + 1, szArgVBuf, sizeof(szArgVBuf));
      if((*szArgVBuf != '\0') && (*szArgVBuf != '-'))
      {
        lstrcpy(gszFileToUncompress, szArgVBuf);
        ++i; // found filename to uncompress, update 'i' for the next iteration
      }
    }
    else if((lstrcmpi(szArgVBuf, "-mmi") == 0) || (lstrcmpi(szArgVBuf, "/mmi") == 0))
    {
      gbAllowMultipleInstalls = TRUE;
    }

    ++i;
  }

  lstrcpy(szCmdLineToSetup, " ");
  lstrcat(szCmdLineToSetup, lpszCmdLine);
}
コード例 #2
0
ファイル: nsztool.c プロジェクト: rn10950/RetroZilla
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
  int               i;
  int               iArgC;
  char              szBuf[MAX_BUF];
  char              szArgVBuf[MAX_BUF];
  char              szFileFullPath[MAX_BUF];
  char              szSeaExe[MAX_BUF];
  char              szNsZipName[MAX_BUF];
  char              szAppName[MAX_BUF];
  char              szAppPath[MAX_BUF];

#ifdef SSU_DEBUG
  char              szOutputStr[MAX_BUF];
#endif

  WIN32_FIND_DATA   findFileData;
  HANDLE            hExe;
  HANDLE            hFindFile;
  BOOL              bSelfUpdate;

  if(GetModuleFileName(NULL, szAppName, sizeof(szAppName)) == 0L)
  {
    PrintError("GetModuleFileName() failed", ERROR_CODE_SHOW);
    exit(1);
  }
  ParsePath(szAppName, szBuf, sizeof(szBuf), PP_FILENAME_ONLY);
  ParsePath(szAppPath, szBuf, sizeof(szBuf), PP_PATH_ONLY);

  if(*lpszCmdLine == '\0')
  {
    ShowUsage(szBuf);
    exit(1);
  }

  iArgC = GetArgC(lpszCmdLine);
  bSelfUpdate = FALSE;

#ifdef SSU_DEBUG
  wsprintf(szOutputStr, "ArgC: %d\n", iArgC);
  for(i = 0; i < iArgC; i++)
  {
    GetArgV(lpszCmdLine, i, szArgVBuf, sizeof(szArgVBuf));
    itoa(i, szBuf, 10);
    lstrcat(szOutputStr, "    ");
    lstrcat(szOutputStr, szBuf);
    lstrcat(szOutputStr, ": ");
    lstrcat(szOutputStr, szArgVBuf);
    lstrcat(szOutputStr, "\n");
  }
  MessageBox(NULL, szOutputStr, "Output", MB_OK);
#endif

  /* Get the first parameter */
  GetArgV(lpszCmdLine, 0, szSeaExe, sizeof(szSeaExe));
  if(lstrcmpi(szSeaExe, "-g") == 0)
  {
    /* The first parameter is "-g".
     * Create a new nszip that contains nsinstall.exe in itself */

    GetArgV(lpszCmdLine, 1, szNsZipName, sizeof(szNsZipName));
    GetArgV(lpszCmdLine, 2, szSeaExe, sizeof(szSeaExe));
    if(!FileExists(szSeaExe))
    {
      wsprintf(szBuf, "file not found: %s", szSeaExe);
      PrintError(szBuf, ERROR_CODE_HIDE);
      exit(1);
    }

    if(GetModuleFileName(NULL, szAppName, sizeof(szAppName)) == 0L)
    {
      PrintError("GetModuleFileName() failed", ERROR_CODE_SHOW);
      exit(1);
    }
    if(!FileExists(szAppName))
    {
      wsprintf(szBuf, "File not found: %s", szAppName);
      PrintError(szBuf, ERROR_CODE_HIDE);
      exit(1);
    }

    if(CopyFile(szAppName, szNsZipName, FALSE) == FALSE)
    {
      wsprintf(szBuf, "Error creating %s", szNsZipName);
      PrintError(szBuf, ERROR_CODE_SHOW);
      exit(1);
    }

    hExe = InitResource(szNsZipName);
    AddFile(hExe, szSeaExe);
    DeInitResource(hExe);
    return(0);
  }
  else
  {
    /* The first parameter is not "-g".  Assume that it's the name of the
     * self-extracting .exe to be saved as.  So lets create it only if it does not exist. */

    if(!FileExists(szSeaExe))
    {
      EnumResourceNames(NULL, "FILE", (ENUMRESNAMEPROC)ExtractFilesProc, (LONG)szSeaExe);

      // if still does not exist, copy nsinstall.exe to szSeaExe
      if(!FileExists(szSeaExe))
      {
        if(FileExists(DEFAULT_SEA_FILE))
          CopyFile(DEFAULT_SEA_FILE, szSeaExe, FALSE);
        else
        {
          wsprintf(szBuf, "file not found: %s", DEFAULT_SEA_FILE);
          PrintError(szBuf, ERROR_CODE_HIDE);
          exit(1);
        }
      }
    }

    if(!FileExists(szSeaExe))
    {
      wsprintf(szBuf, "file not found: %s", szSeaExe);
      PrintError(szBuf, ERROR_CODE_HIDE);
      exit(1);
    }
  }

  hExe = InitResource(szSeaExe);
  for(i = 1; i < iArgC; i++)
  {
    GetArgV(lpszCmdLine, i, szArgVBuf, sizeof(szArgVBuf));
    GetFullPathName(szArgVBuf, sizeof(szFileFullPath), szFileFullPath, NULL);
    hFindFile = FindFirstFile(szFileFullPath, &findFileData);

    if(hFindFile == INVALID_HANDLE_VALUE)
    {
      wsprintf(szBuf, "file not found: %s", szArgVBuf);
      PrintError(szBuf, ERROR_CODE_HIDE);
      exit(1);
    }

    do
    {
      char szFile[MAX_BUF];

      if(!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
      {
        // We need to pass to AddFile() whatever kind of path we were passed,
        // e.g. simple, relative, full
        strcpy(szFile, szFileFullPath);
        strcpy(strrchr(szFile, '\\') + 1, findFileData.cFileName);
        AddFile(hExe, szFile);
      }
    } while(FindNextFile(hFindFile, &findFileData));

    FindClose(hFindFile);
  }

  DeInitResource(hExe);
  return(0);
}
コード例 #3
0
//+----------------------------------------------------------------------------
//
// Function:  SetProxyUsingTunnelAddress
//
// Synopsis:  Entry point for changing the proxy file settings using a tunnel
//            address. The parameters to the dll are passed via a string which 
//			  contains parameters.
//
// Arguments: HWND hWnd         - Window handle of caller
//            HINSTANCE hInst   - Instance handle of caller
//            LPSTR pszArgs     - Argument string
//            DWORD nShow       - Reserved for future use
//
// Returns:   HRESULT           - S_OK or S_FALSE
//
//+----------------------------------------------------------------------------
HRESULT WINAPI SetProxyUsingTunnelAddress(HWND hWnd, HINSTANCE hInst, 
                                          LPSTR pszArgs, DWORD nShow)
{
    // If we wanted to fail the connection we would return E_FAIL, since we  
    // still want to connect even if this custom action fails, we just return S_FALSE (by default)
    // or S_OK in a successful case
    HRESULT hr = S_FALSE;		
    LPSTR* ArgV = NULL;
    LPSTR pszServiceDir = NULL;
    LPSTR pszTunnelAddress = NULL;
    LPSTR pszProxyFile = NULL;
    LPSTR pszTunnelFile = NULL;
    LPSTR pszTunnelSettingFilePath = NULL;
    LPSTR pszProxyFilePath = NULL;
    LPSTR pszProxyServer = NULL;
    DWORD dwTunnelPathLen = 0;
    DWORD dwProxyPathLen = 0;
    HANDLE hCurrentHeap = GetProcessHeap();
    int i = 0;
    DWORD lcid = 0;

	//  Parse out the command line parameters
	//  command line is of the form: 
    //      /ServiceDir %SERVICEDIR% /TunnelAddress %TUNNELADDRESS% /ProxyFile 
    //          <PROXYFILE> /TunnelFile <TUNNELFILE>

	// Check if we have any arguments
    if (!pszArgs)
    {
		goto exit;
    }

	// Separate each argument in the string by '\0' and return a list of 
    // pointers to each argument
    ArgV = GetArgV(pszArgs);
    
	// Check if we have any valid parsed arguments
    if (!ArgV)
    {
        goto exit;
    }

	// Search the command line arguments for the following switches and their
	// corresponding values. Since actual paramter value is at i+1, make sure i 
    // is less than the maximum allowed parameters - 1. 
    
    
    lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);

    while (ArgV[i] && ((MAX_CMD_ARGS-1) > i))
    {
        if ((CSTR_EQUAL == CompareString(lcid, NORM_IGNORECASE,  ArgV[i], -1, "/ServiceDir", -1)) && ArgV[i+1])
        {
			pszServiceDir = (ArgV[i+1]);
			i = i+2;
        }
		else if ((CSTR_EQUAL == CompareString(lcid, NORM_IGNORECASE,  ArgV[i], -1, "/TunnelAddress", -1)) && ArgV[i+1])
        {
			pszTunnelAddress = ArgV[i+1];
			i = i+2;            
        }
		else if ((CSTR_EQUAL == CompareString(lcid, NORM_IGNORECASE,  ArgV[i], -1, "/ProxyFile", -1)) && ArgV[i+1])
        {
			pszProxyFile = ArgV[i+1];
			i = i+2;            
        }
		else if ((CSTR_EQUAL == CompareString(lcid, NORM_IGNORECASE,  ArgV[i], -1, "/TunnelFile", -1)) && ArgV[i+1])
        {
			pszTunnelFile = ArgV[i+1];
			i = i+2;            
        }
        else
        {
            //  Unknown option.  
            i++;
        }
    }	

	// Make sure we have values for the arguments
	if (!pszServiceDir || !pszTunnelAddress || !pszProxyFile || !pszTunnelFile)
	{
        goto exit;
	}

	// Check to see if we got zero length string values from the command line
    // arguments. Exit if that is the case.
	if (!(*pszServiceDir) || !(*pszTunnelAddress) ||	
		!(*pszProxyFile) || !(*pszTunnelFile))
	{
        goto exit;
	}

	// Calculate the string size for the two paths that need to be created
	// Add 2 for the NULL and backslash
    dwTunnelPathLen = lstrlen(pszServiceDir) +  lstrlen(pszTunnelFile) + 2; 
	dwProxyPathLen = lstrlen(pszServiceDir) +  lstrlen(pszProxyFile) + 2;	

	// Allocate the memory
	pszTunnelSettingFilePath = (LPSTR)HeapAlloc(hCurrentHeap, HEAP_ZERO_MEMORY,
                                dwTunnelPathLen);	// ANSI - char == byte
	if (!pszTunnelSettingFilePath)
	{
        goto exit;
	}

	pszProxyFilePath = (LPSTR)HeapAlloc(hCurrentHeap, HEAP_ZERO_MEMORY, 
                                dwProxyPathLen);	// ANSI - char == byte
	if (!pszProxyFilePath)
	{
        goto exit;
	}
	
	// Since we allocated pszTunnelSettingFilePath, we know that it has enough
    // room to fit the path. Otherwise we would have to use _snprintf or wnsprintf.
    // Copy the Service directory to create the full path.
	StringCchPrintf(pszTunnelSettingFilePath, dwTunnelPathLen, "%s\\%s", pszServiceDir, pszTunnelFile);
    
    // Since we allocated pszTunnelSettingFilePath, we know that it has enough
    // room to fit the path. Otherwise we would have to use _snprintf or wnsprintf.
    //Create the full path to the Proxy file.
	StringCchPrintf(pszProxyFilePath, dwProxyPathLen, "%s\\%s", pszServiceDir, pszProxyFile);
	
	if (ReadProxyServerByTunnelAddressFromFile(pszTunnelSettingFilePath, 
                                               pszTunnelAddress, 
                                               &pszProxyServer))
	{
		// Call WriteProxyServerSettingToFile - the function checks for empty 
        // strings
		if(WriteProxyServerSettingToFile(pszProxyFilePath, pszProxyServer))
		{
			hr = S_OK;
		}
	}
	
exit:
	// Clean up allocated memory
	// Delete the argument pointers, Tunnel Server path, Proxy file path and 
    // ProxyServer name pointers
    if (ArgV)
	    HeapFree(hCurrentHeap, 0, (LPVOID)ArgV);	
    
    if (pszTunnelSettingFilePath)
	    HeapFree(hCurrentHeap, 0, (LPVOID)pszTunnelSettingFilePath);
	
    if (pszProxyFilePath)
        HeapFree(hCurrentHeap, 0, (LPVOID)pszProxyFilePath);
	
    if (pszProxyServer)
        HeapFree(hCurrentHeap, 0, (LPVOID)pszProxyServer);

	return hr;
}