Esempio n. 1
0
void CPathFinder::SetPath(LPCTSTR szPath, BOOL bIsFolderPath, BOOL bHasArguments)
{
	TCHAR szParamPath[_MAX_PATH];
	TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR];
	TCHAR szName[_MAX_FNAME], szExt[_MAX_EXT];

	// Reset
	_sOriginalPath.Empty();
	_sDriveLabel.Empty();
	_bIsRelative = FALSE;
	_aDir.RemoveAll();
	_sExtName.Empty();
	_aArgs.RemoveAll();

	// Original path
	_sOriginalPath = szPath;

	// Get args and remove them from path
	szParamPath[0] = 0x0;
	_tcscpy(szParamPath, szPath);

	if (bHasArguments)
	{
		_sArgs = PathGetArgs(szParamPath);
		PathRemoveArgs(szParamPath);
	}

	PathUnquoteSpaces(szParamPath);
	if (szParamPath[0] == 0x0) return;

    _tsplitpath(szParamPath, szDrive, szDir, szName, szExt);

	// Drive
	_sDrive = szDrive;

	// Directory
	_sDir = szDir;
	_sDir.Replace('/', '\\');
	if (!_sDir.IsEmpty()) _bIsRelative = (_sDir[0] != '\\');
	
	// FileTitle
	if (bIsFolderPath)
	{
		_sDir = CPathFinder::AddBackSlash(_sDir);
		_sDir += szName;
		_sDir = CPathFinder::AddBackSlash(_sDir);
	}
	else
	{
		_sFileTitle = szName;
	}

	// Get extension name (e.g.: "txt")
	if (IsFilePath())
	{
		_sExtName = szExt;
		_sExtName.Remove('.');
	}
}
Esempio n. 2
0
int CPreviewApps::ReadAllApps()
{
	RemoveAllApps();

	CString strFilePath = GetDefaultAppsFile();
	FILE* readFile = _tfsopen(strFilePath, _T("r"), _SH_DENYWR);
	if (readFile != NULL)
	{
		CString name, url, sbuffer;
		while (!feof(readFile))
		{
			TCHAR buffer[1024];
			if (_fgetts(buffer, ARRSIZE(buffer), readFile) == NULL)
				break;
			sbuffer = buffer;

			// ignore comments & too short lines
			if (sbuffer.GetAt(0) == _T('#') || sbuffer.GetAt(0) == _T('/') || sbuffer.GetLength() < 5)
				continue;

			int iPos = 0;
			CString strTitle = sbuffer.Tokenize(_T("="), iPos);
			strTitle.Trim();
			if (!strTitle.IsEmpty())
			{
				CString strCommandLine = sbuffer.Tokenize(_T(";"), iPos);
				strCommandLine.Trim();
				if (!strCommandLine.IsEmpty())
				{
					LPCTSTR pszCommandLine = strCommandLine;
					LPTSTR pszCommandArgs = PathGetArgs(pszCommandLine);
					CString strCommand, strCommandArgs;
					if (pszCommandArgs)
						strCommand = strCommandLine.Left(pszCommandArgs - pszCommandLine);
					else
						strCommand = strCommandLine;
					strCommand.Trim(_T(" \t\""));
					if (!strCommand.IsEmpty())
					{
						UINT uMinCompletedSize = 0;
						UINT uMinStartOfFile = 0;
						CStringArray astrExtensions;
						CString strParams = sbuffer.Tokenize(_T(";"), iPos);
						while (!strParams.IsEmpty())
						{
							int iPosParam = 0;
							CString strId = strParams.Tokenize(_T("="), iPosParam);
							if (!strId.IsEmpty())
							{
								CString strValue = strParams.Tokenize(_T("="), iPosParam);
								if (strId.CompareNoCase(_T("Ext")) == 0)
								{
									if (!strValue.IsEmpty())
									{
										if (strValue[0] != _T('.'))
											strValue = _T('.') + strValue;
										astrExtensions.Add(strValue);
									}
								}
								else if (strId.CompareNoCase(_T("MinSize")) == 0)
								{
									if (!strValue.IsEmpty())
										_stscanf(strValue, _T("%u"), &uMinCompletedSize);
								}
								else if (strId.CompareNoCase(_T("MinStart")) == 0)
								{
									if (!strValue.IsEmpty())
										_stscanf(strValue, _T("%u"), &uMinStartOfFile);
								}
							}
							strParams = sbuffer.Tokenize(_T(";"), iPos);
						}

						SPreviewApp svc;
						svc.strTitle = strTitle;
						svc.strCommand = strCommand;
						svc.strCommandArgs = pszCommandArgs;
						svc.strCommandArgs.Trim();
						svc.astrExtensions.Append(astrExtensions);
						svc.uMinCompletedSize = uMinCompletedSize;
						svc.uMinStartOfFile = uMinStartOfFile;
						m_aApps.Add(svc);
					}
				}
			}
		}
		fclose(readFile);

		struct _stat st;
		if (_tstat(strFilePath, &st) == 0)
			m_tDefAppsFileLastModified = st.st_mtime;
	}

	return m_aApps.GetCount();
}
Esempio n. 3
0
//
// Do checking of the .exe type in the background so the UI doesn't
// get hung up while we scan.  This is particularly important with
// the .exe is over the network or on a floppy.
//
void CheckRunInSeparateThread( LPVOID lpVoid )
{
    LONG lBinaryType;
    DWORD cch;
    LPTSTR lpszFilePart;
    TCHAR szFile[MAX_PATH+1];
    TCHAR szFullFile[MAX_PATH+1];
    TCHAR szExp[MAX_PATH+1];
    HWND hDlg = (HWND)lpVoid;
    BOOL fCheck = TRUE, fEnable = FALSE;

    DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread created and running") );

    while( g_bCheckRunInSep )
    {

        WaitForSingleObject( g_hCheckNow, INFINITE );
        ResetEvent( g_hCheckNow );

        if (g_bCheckRunInSep)
        {
            LPRUNDLG_DATA lprd;
            LPTSTR pszT;
            BOOL f16bit = FALSE;

            szFile[0] = TEXT('\0');
            szFullFile[0] = TEXT('\0');
            cch = 0;
            GetWindowText( GetDlgItem( hDlg, IDD_COMMAND ), szFile, MAX_PATH );
            // Remove & throw away arguments
            PathRemoveBlanks(szFile);

            if (PathIsUNC(szFile) || IsRemoteDrive(DRIVEID(szFile)))
            {
                f16bit = TRUE;
                fCheck = FALSE;
                fEnable = TRUE;
                goto ChangeTheBox;
            }

            // if the unquoted sting exists as a file just use it

            if (!PathFileExists(szFile))
            {
                pszT = PathGetArgs(szFile);
                if (*pszT)
                    *(pszT - 1) = TEXT('\0');

                PathUnquoteSpaces(szFile);
            }



            if (szFile[0])
            {
                ExpandEnvironmentStrings( szFile, szExp, MAX_PATH );
                szExp[ MAX_PATH ] = TEXT('\0');

                if (PathIsUNC(szExp) || IsRemoteDrive(DRIVEID(szExp)))
                {
                    f16bit = TRUE;
                    fCheck = FALSE;
                    fEnable = TRUE;
                    goto ChangeTheBox;
                }

                cch = SearchPath(  NULL,
                                   szExp,
                                   TEXT(".EXE"),
                                   MAX_PATH+1,
                                   szFullFile,
                                   &lpszFilePart
                                  );
            }

            if ((cch != 0) && (cch <= MAX_PATH))
            {
                if ( (GetBinaryType( szFullFile, &lBinaryType) &&
                     (lBinaryType==SCS_WOW_BINARY))
                    )
                {
                    f16bit = TRUE;
                    fCheck = FALSE;
                    fEnable = TRUE;
                } else {
                    f16bit = FALSE;
                    fCheck = TRUE;
                    fEnable = FALSE;
                }

            } else {

                f16bit = FALSE;
                fCheck = TRUE;
                fEnable = FALSE;
            }

ChangeTheBox:
            CheckDlgButton( hDlg, IDD_RUNINSEPARATE, fCheck ? 1 : 0 );
            EnableWindow( GetDlgItem( hDlg, IDD_RUNINSEPARATE ), fEnable );

            ENTERCRITICAL;
            lprd = (LPRUNDLG_DATA)GetWindowLong(hDlg, DWL_USER);
            if (lprd)
            {
                if (f16bit)
                    lprd->dwFlags |= RFD_WOW_APP;
                else
                    lprd->dwFlags &= (~RFD_WOW_APP);
            }
            LEAVECRITICAL;

        }

    }

    CloseHandle( g_hCheckNow );
    g_hCheckNow = NULL;
    DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread exiting now...") );
    ExitThread( 0 );

}
Esempio n. 4
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	exitCode = ERROR_SUCCESS;

	LPTSTR cmdline = GetCommandLine();
	LPSTR *argv = __argv;
	int argc = __argc;
	if (argc < 2) {
		showUsage();
		return ERROR_INVALID_PARAMETER;
	}
	cmdline = PathGetArgs(cmdline);
	int index = 1;
	BOOL switchMatch;
	while (index < argc) {
		switchMatch = FALSE;
		LPSTR arg = argv[index];
		if (strlen(arg) >= 2) {
			switch (arg[0]) {
				case '-':
				case '/':
					switch (tolower(arg[1])) {
						case 's':
						case 'q':
							if (strlen(arg) == 2) {
								switchMatch = TRUE;
								silentFlag = TRUE;
							}
							break;
						case 'u':
							if (strlen(arg) == 2) {
								switchMatch = TRUE;
								uninstallFlag = TRUE;
							}
							break;
						case 't':
							if (strlen(arg) > 3 && arg[2] == '=') {
								switchMatch = TRUE;
								estTime = atoi(arg + 3);
							}
							break;
					}
					break;
			}
		}
		if (switchMatch) {
			cmdline = PathGetArgs(cmdline);
			index++;
		} else {
			index = argc;
		}
	}

	STARTUPINFO startInfo;
	PROCESS_INFORMATION procInfo;
	ZeroMemory(&startInfo, sizeof(startInfo));
	startInfo.cb = sizeof(startInfo);
	ZeroMemory(&procInfo, sizeof(procInfo));

	if (!CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &startInfo, &procInfo)) {
		exitCode = GetLastError();
		MessageBox(NULL, _tcserror(exitCode), NULL, MB_ICONERROR);
		return exitCode;
	}
	hChildProc = procInfo.hProcess;

	DialogBox(hInstance, MAKEINTRESOURCE(IDD_LOADER), 0, (DLGPROC)DlgProc);

	CloseHandle(procInfo.hProcess);
	CloseHandle(procInfo.hThread);

	return exitCode;
}