示例#1
0
std::wstring BaseTest::MakeDataPath(LPCWSTR folder, LPCWSTR file)
{
	WCHAR filename[MAX_PATH];

	if (folder && *folder)
	{
		lstrcpynW(filename, s_datapath, MAX_PATH);
		PathAppendW(filename, folder);
	}
	else
	{
		lstrcpynW(filename, s_temppath, MAX_PATH);
		::CreateDirectoryW(s_temppath, NULL);
	}

	if (file && *file)
	{
		PathAppendW(filename, file);
	}
	else
	{
		PathAddBackslashW(filename);
	}

	return filename;
}
示例#2
0
void BaseTest::MakeRootPath(LPWSTR path, LPCWSTR name)
{
	WCHAR filename[MAX_PATH];

	if (0 == path[0])
	{
		GetModuleFileNameW(NULL, filename, MAX_PATH);
		PathRemoveFileSpecW(filename);
		PathAppendW(filename, L"UnitTests.ini");

		lstrcpynW(path, filename, MAX_PATH);
		PathRemoveFileSpecW(path);		// bin\vc80\debug\tests
		PathRemoveFileSpecW(path);		// bin\vc80\debug
		PathRemoveFileSpecW(path);		// bin\vc80
		PathRemoveFileSpecW(path);		// bin
		PathAppendW(path, name);		// bin\name

		GetPrivateProfileStringW(L"Path", name, path, 
			path, MAX_PATH, filename);
		PathAddBackslashW(path);

		SetFileAttributesW(filename, FILE_ATTRIBUTE_NORMAL);
		WritePrivateProfileStringW(L"Path", name, path, filename);
	}
}
示例#3
0
BOOL WINAPI iSAuthorized(LPCWSTR lpFileName)
{
	BOOL	ret = FALSE;
	BOOL    wow64 = FALSE;
	LPWSTR	filename = NULL;
	wchar_t *szAuthorizedList[] = {L"comctl32.dll", L"uxtheme.dll", L"indicdll.dll",
								   L"msctf.dll",L"shell32.dll", L"imageres.dll",
								   L"winmm.dll",L"ole32.dll", L"oleacc.dll", 
								   L"oleaut32.dll",L"secur32.dll",L"shlwapi.dll",
								   L"ImSCTip.DLL",L"gdi32.dll",L"dwmapi.dll"
								  };
	WORD line = sizeof(szAuthorizedList)/sizeof(szAuthorizedList[0]);
	IsWow64Process(NtCurrentProcess(),&wow64);
	if (lpFileName[1] == L':')
	{
		wchar_t sysdir[VALUE_LEN+1] = {0};
		GetEnvironmentVariableW(L"SystemRoot",sysdir,VALUE_LEN);
		if (wow64)
		{
			PathAppendW(sysdir,L"SysWOW64");
		}
		else
		{
			PathAppendW(sysdir,L"system32");
		}
		if ( _wcsnicmp(lpFileName,sysdir,wcslen(sysdir)) == 0 )
		{
			filename = PathFindFileNameW(lpFileName);
		}
		else if ( wow64 && wcslen(sysdir)>0 )   /* compare system32 directory again */
		{
			PathRemoveFileSpecW(sysdir);
			PathAppendW(sysdir,L"system32");
			filename = _wcsnicmp(lpFileName,sysdir,wcslen(sysdir))?NULL:PathFindFileNameW(lpFileName);
		}
	}
	else
	{
		filename = (LPWSTR)lpFileName;
	}
	if (filename)
	{
		WORD  i;
		for(i=0;i<line;i++)
		{
			if ( _wcsicmp(filename,szAuthorizedList[i]) == 0 )
			{
				ret = TRUE;
				break;
			}
		}
	}
	return ret;
}
示例#4
0
文件: winapi.hpp 项目: thenfour/LibCC
	inline std::wstring PathAppendX(IN const std::wstring& lhs, const std::wstring& rhs)
  {
		std::vector<wchar_t> b(lhs.size() + rhs.size() + 4);// +2 for null term + a backslash if necessary.
		XLastDitchStringCopy(lhs.c_str(), b.data());
		PathAppendW(b.data(), rhs.c_str());
		return std::wstring(b.data());
  }
示例#5
0
String pathByAppendingComponent(const String& path, const String& component)
{
#ifdef _WIN32_WCE
	String res = path;
	res.replace('/', '\\');
	if (res.endsWith("\\"))
		return (res + component);
	else
		return (res + "\\" + component);
#else
	Vector<UChar> buffer(MAX_PATH);

	if (path.length() + 1 > buffer.size())
		return String();

	memcpy(buffer.data(), path.characters(), path.length() * sizeof(UChar));
	buffer[path.length()] = '\0';

	String componentCopy = component;
	if (!PathAppendW(buffer.data(), componentCopy.charactersWithNullTermination()))
		return String();

	buffer.resize(wcslen(buffer.data()));

	return String::adopt(buffer);
#endif
}
String pathByAppendingComponent(const String& path, const String& component)
{
    Vector<UChar> buffer(MAX_PATH);

#if OS(WINCE)
    buffer.append(path.characters(), path.length());

    UChar lastPathCharacter = path[path.length() - 1];
    if (lastPathCharacter != L'\\' && lastPathCharacter != L'/' && component[0] != L'\\' && component[0] != L'/')
        buffer.append(PlatformFilePathSeparator);

    buffer.append(component.characters(), component.length());
    buffer.shrinkToFit();
#else
    if (path.length() + 1 > buffer.size())
        return String();

    memcpy(buffer.data(), path.characters(), path.length() * sizeof(UChar));
    buffer[path.length()] = '\0';

    String componentCopy = component;
    if (!PathAppendW(buffer.data(), componentCopy.charactersWithNullTermination().data()))
        return String();

    buffer.resize(wcslen(buffer.data()));
#endif

    return String::adopt(buffer);
}
示例#7
0
static HRESULT WINAPI
ISF_Desktop_ISFHelper_fnAddFolder (ISFHelper * iface, HWND hwnd, LPCWSTR pwszName,
                       LPITEMIDLIST * ppidlOut)
{
    IGenericSFImpl *This = impl_from_ISFHelper(iface);
    WCHAR wszNewDir[MAX_PATH];
    DWORD bRes;
    HRESULT hres = E_FAIL;

    TRACE ("(%p)(%s %p)\n", This, debugstr_w(pwszName), ppidlOut);

    wszNewDir[0] = 0;
    if (This->sPathTarget)
        lstrcpynW(wszNewDir, This->sPathTarget, MAX_PATH);
    PathAppendW(wszNewDir, pwszName);
    bRes = CreateDirectoryW (wszNewDir, NULL);
    if (bRes) 
    {
        SHChangeNotify (SHCNE_MKDIR, SHCNF_PATHW, wszNewDir, NULL);
        hres = S_OK;
        if (ppidlOut)
                hres = _ILCreateFromPathW(wszNewDir, ppidlOut);
    }

    return hres;
}
示例#8
0
/* Helper function to add a file to a job.  The helper function takes base
   file name and creates properly formed path and URL strings for creation of
   the file. */
static HRESULT addFileHelper(IBackgroundCopyJob* job,
                             const WCHAR *localName, const WCHAR *remoteName)
{
    DWORD urlSize;
    WCHAR localFile[MAX_PATH];
    WCHAR remoteUrl[MAX_PATH];
    WCHAR remoteFile[MAX_PATH];

    GetCurrentDirectoryW(MAX_PATH, localFile);
    PathAppendW(localFile, localName);
    GetCurrentDirectoryW(MAX_PATH, remoteFile);
    PathAppendW(remoteFile, remoteName);
    urlSize = MAX_PATH;
    UrlCreateFromPathW(remoteFile, remoteUrl, &urlSize, 0);
    UrlUnescapeW(remoteUrl, NULL, &urlSize, URL_UNESCAPE_INPLACE);
    return IBackgroundCopyJob_AddFile(test_job, remoteUrl, localFile);
}
示例#9
0
BOOL WINAPI ini_ready(LPWSTR inifull_name,DWORD str_len)
{
	BOOL rect = FALSE;
	GetModuleFileNameW(dll_module,inifull_name,str_len);
	PathRemoveFileSpecW(inifull_name);
	PathAppendW(inifull_name,L"portable.ini");
	rect = PathFileExistsW(inifull_name);
	if (!rect)
	{
		if ( PathRemoveFileSpecW(inifull_name) )
		{
			PathAppendW(inifull_name,L"tmemutil.ini");
			rect = PathFileExistsW(inifull_name);
		}
	}
	return rect;
}
示例#10
0
/*************************************************************************
 * PathAppend		[SHELL32.36]
 */
BOOL WINAPI PathAppendAW(
	LPVOID lpszPath1,
	LPCVOID lpszPath2)
{
	if (SHELL_OsIsUnicode())
	  return PathAppendW(lpszPath1, lpszPath2);
	return PathAppendA(lpszPath1, lpszPath2);
}
示例#11
0
/**
 * Joins a base directory path with a filename.
 *
 * @param  base  The base directory path of size MAX_PATH + 1
 * @param  extra The filename to append
 * @return TRUE if the file name was successful appended to base
 */
BOOL
PathAppendSafe(LPWSTR base, LPCWSTR extra)
{
  if (wcslen(base) + wcslen(extra) >= MAX_PATH) {
    return FALSE;
  }

  return PathAppendW(base, extra);
}
示例#12
0
void ExchndlSetup(const char *packageVersion)
{
# if defined(WZ_CC_MINGW)
	wchar_t miniDumpPath[PATH_MAX] = {'\0'};

#ifdef HAVE_BFD
	bfd_init();
#endif /* HAVE_BFD */

	// Install the unhandled exception filter function
	prevExceptionFilter = SetUnhandledExceptionFilter(TopLevelExceptionFilter);

	// Retrieve the current version
	formattedVersionString = strdup(packageVersion);

	// Because of UAC on vista / win7 we use this to write our dumps to (unless we override it via OverrideRPTDirectory())
	// NOTE: CSIDL_PERSONAL =  C:\Users\user name\Documents
	if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, miniDumpPath ) ))
	{
		PathAppendW( miniDumpPath, WSTRING(WZ_WRITEDIR));
		PathAppendW( miniDumpPath, L"\\logs" );

		if( !PathFileExistsW( miniDumpPath ) )
		{
			if( ERROR_SUCCESS != SHCreateDirectoryExW( NULL, miniDumpPath, NULL ) )
			{
				wcscpy(miniDumpPath, L"c:\\temp");
			}
		}
	}
	else
	{	// should never fail, but if it does, we fall back to this
		wcscpy(miniDumpPath, L"c:\\temp");
	}

	wcscat(szLogFileName, L"Warzone2100.RPT");
	wcscat(miniDumpPath, L"\\");
	wcscat(miniDumpPath,szLogFileName);
	wcscpy(szLogFileName, miniDumpPath);

	atexit(ExchndlShutdown);
#endif
}
示例#13
0
	bool CLoggingImp::InitLogging()
	{
		if (!SHGetSpecialFolderPathW(0, m_wszLogDir, CSIDL_APPDATA, TRUE))
		{
			return false;
		}
		PathAppendW(m_wszLogDir, L"Logging");
		if (!CreateDirectoryW(m_wszLogDir, 0) && 
			GetLastError() != ERROR_ALREADY_EXISTS)
		{
			return false;
		}

		CleanOldLog();

		wchar_t wszBaseName[MAX_PATH] = {0};
		if (!GetModuleFileNameW(0, wszBaseName, MAX_PATH))
		{
			return false;
		}
		PathRemoveExtensionW(wszBaseName);
		PathStripPathW(wszBaseName);
		wchar_t wszLogFile[MAX_PATH] = {0};
		HRESULT hr = StringCchPrintfW(wszLogFile, MAX_PATH, L"%s\\%s_PID%d_%d.log", 
			m_wszLogDir, wszBaseName, GetCurrentProcessId(), GetTickCount());
		if (FAILED(hr))
		{
			return false;
		}
		//create file
		std::locale loc("");
		m_logwfstream.imbue(loc);
		m_logwfstream.open(wszLogFile, std::ios_base::out);	//TODO: what mode?
		if (!m_logwfstream)
		{
			return false;
		}
		//initialize critical section
		bool bOk = true;
		try
		{
			InitializeCriticalSection(&m_csWriteFile);
		}
		catch (...)
		{
			bOk = false;
			m_logwfstream.close();
		}
		
		m_logwfstream << L"\t\tIF ANY ERROR OCCURRED, "
			L"PLS CONTACT ME: [email protected].\n\n\n";
		
		return bOk;
	}
static HMODULE DelayLoadLibraryW(LPCWSTR dllname)
{
	WCHAR curfile[_MAX_PATH];
	GetModuleFileNameW(hInstance, curfile, MAX_PATH);
	PathRemoveFileSpecW(curfile);
	PathAppendW(curfile, dllname);
	HMODULE hdll = LoadLibraryW(curfile);
	if (hdll == nullptr)
		return LoadLibraryW(dllname);
	return hdll;
}
示例#15
0
static bool initialiseProgramDataFiles(HSP *sp, wchar_t *programDataDir)
{
	size_t dirLen = wcsnlen(programDataDir, MAX_PATH);
	size_t fnLen = dirLen+wcslen(HSP_DEFAULT_VMSTORE)+1;
	wchar_t *vmStoreFile = (wchar_t *)my_calloc(sizeof(wchar_t)*fnLen);
	wcscpy_s(vmStoreFile, fnLen, programDataDir);
	PathAppendW(vmStoreFile, HSP_DEFAULT_VMSTORE);
	sp->vmStoreFile = vmStoreFile;
	HANDLE fileHandle;
	if ((fileHandle = CreateFileW(vmStoreFile, 
								  GENERIC_READ | GENERIC_WRITE, 
								  FILE_SHARE_WRITE, NULL,
								  OPEN_ALWAYS, 
								  FILE_ATTRIBUTE_NORMAL, 
								  NULL)) == INVALID_HANDLE_VALUE) {
		myLog(LOG_ERR, "initialiseProgramDataFiles: cannot open VM store file %S\n", vmStoreFile);
		return false;
	} else {
		int cHandle = _open_osfhandle((long)fileHandle, _O_RDWR | _O_TEXT);
		sp->f_vmStore = _fdopen(cHandle, "r+t");
	}
	fnLen = dirLen+wcslen(HSP_DEFAULT_PORTSTORE)+1;
	wchar_t *portStoreFile = (wchar_t *)my_calloc(sizeof(wchar_t)*fnLen);
	wcscpy_s(portStoreFile, fnLen, programDataDir);
	PathAppendW(portStoreFile, HSP_DEFAULT_PORTSTORE);
	sp->portStoreFile = portStoreFile;
	if ((fileHandle = CreateFileW(portStoreFile, 
								  GENERIC_READ | GENERIC_WRITE,
								  FILE_SHARE_WRITE, NULL,
								  OPEN_ALWAYS, 
								  FILE_ATTRIBUTE_NORMAL, 
								  NULL)) == INVALID_HANDLE_VALUE) {
		myLog(LOG_ERR, "initialiseProgramDataFiles: cannot open VM store file %S\n", portStoreFile);
		return false;
	} else {
		int cHandle = _open_osfhandle((long)fileHandle, _O_RDWR | _O_TEXT);
		sp->f_portStore = _fdopen(cHandle, "r+t");
	}
	return true;
}
示例#16
0
extern void loadUserParams(HMODULE hDllModule) {
	wchar_t path[_MAX_PATH];
	GetModuleFileNameW(hDllModule, path, _MAX_PATH);
	PathRemoveFileSpecW(path);
	PathAppendW(path, L"UserParams.ini");
	
	loadGeneralParams(path);
	
	if (GeneralParams.isHookTarget) {
		loadFontSubstitutes(path);
		loadRenderingParams(path);
	}
}
示例#17
0
/***************************************************************************
 *  SHELL32_GetCustomFolderAttribute (internal function)
 *
 * Gets a value from the folder's desktop.ini file, if one exists.
 *
 * PARAMETERS
 *  pidl          [I] Folder containing the desktop.ini file.
 *  pwszHeading   [I] Heading in .ini file.
 *  pwszAttribute [I] Attribute in .ini file.
 *  pwszValue     [O] Buffer to store value into.
 *  cchValue      [I] Size in characters including NULL of buffer pointed to
 *                    by pwszValue.
 *
 *  RETURNS
 *    TRUE if returned non-NULL value.
 *    FALSE otherwise.
 */
static inline BOOL SHELL32_GetCustomFolderAttributeFromPath(
    LPWSTR pwszFolderPath, LPCWSTR pwszHeading, LPCWSTR pwszAttribute,
    LPWSTR pwszValue, DWORD cchValue)
{
    static const WCHAR wszDesktopIni[] =
            {'d','e','s','k','t','o','p','.','i','n','i',0};
    static const WCHAR wszDefault[] = {0};

    PathAddBackslashW(pwszFolderPath);
    PathAppendW(pwszFolderPath, wszDesktopIni);
    return GetPrivateProfileStringW(pwszHeading, pwszAttribute, wszDefault, 
                                    pwszValue, cchValue, pwszFolderPath);
}
示例#18
0
	static std::string FindDataDir()
	{
		HMODULE exemodule = GetModuleHandleW(0);
		wchar_t buf[MAX_PATH+1];
		DWORD nchars = GetModuleFileNameW(exemodule, buf, MAX_PATH);
		if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
			// I gave you MAX_PATH, what more do you want!?
			abort();
		}
		buf[nchars] = L'\0';
		PathRemoveFileSpecW(buf);
		PathAppendW(buf, L"data");
		return transcode_utf16_to_utf8(buf, wcslen(buf));
	}
示例#19
0
LONG WINAPI ProcessException_ice(PEXCEPTION_POINTERS pExceptionInfo)
{
     /* 异常信息结构体 */
    MINIDUMP_EXCEPTION_INFORMATION  ExInfo;
    /* dump生成目录 */
    wchar_t appdir[MAX_PATH+1] = {0};
	HANDLE hFile = NULL;
    if ( !(GetEnvironmentVariableW(L"APPDATA",appdir,MAX_PATH) > 0) )
	{
		return EXCEPTION_CONTINUE_SEARCH;
	}
    PathAppendW(appdir,L"minidump.dmp");
    /* 创建文件句柄 */
    hFile = CreateFileW(appdir,
        GENERIC_WRITE,
        FILE_SHARE_WRITE,
        NULL,
        TRUNCATE_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        NULL);
	if (INVALID_HANDLE_VALUE == hFile && ERROR_FILE_NOT_FOUND == GetLastError())
	{
	    hFile = CreateFileW(appdir,
        GENERIC_WRITE,
        FILE_SHARE_WRITE,
        NULL,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);
	}
	if (INVALID_HANDLE_VALUE == hFile)
		return EXCEPTION_CONTINUE_SEARCH;
    ExInfo.ThreadId = GetCurrentThreadId();
    ExInfo.ExceptionPointers = pExceptionInfo;
    ExInfo.ClientPointers = TRUE;

    /* MiniDumpWriteDump输出dump */
    MiniDumpWriteDump_func(GetCurrentProcess(), 
        GetCurrentProcessId(),
        hFile,
        MiniDumpNormal,
        &ExInfo,
        NULL,
        NULL );

    CloseHandle(hFile);
    return EXCEPTION_EXECUTE_HANDLER;
}
示例#20
0
void Cx_PluginLoader::MakeFullPath(wchar_t* fullpath, HMODULE instance,
                                   const wchar_t* path)
{
    if (!path || 0 == path[0] || PathIsRelativeW(path))
    {
        GetModuleFileNameW(instance, fullpath, MAX_PATH);
        PathRemoveFileSpecW(fullpath);
        PathAppendW(fullpath, path);
    }
    else
    {
        wcscpy_s(fullpath, MAX_PATH, path);
    }
    ReplaceSlashes(fullpath);
    PathAddBackslashW(fullpath);
}
String pathByAppendingComponent(const String& path, const String& component)
{
    Vector<UChar> buffer(MAX_PATH);

    if (path.length() + 1 > buffer.size())
        return String();

    memcpy(buffer.data(), path.characters(), path.length() * sizeof(UChar));
    buffer[path.length()] = '\0';

    String componentCopy = component;
    if (!PathAppendW(buffer.data(), componentCopy.charactersWithNullTermination()))
        return String();

    buffer.resize(wcslen(buffer.data()));

    return String::adopt(buffer);
}
HRESULT GetShellItemFromCommandLine(REFIID riid, void **ppv)
{
    *ppv = NULL;

    HRESULT hr = E_FAIL;
    int cArgs;
    PWSTR *ppszCmd = CommandLineToArgvW(GetCommandLineW(), &cArgs);
    if (ppszCmd && cArgs > 1)
    {
        WCHAR szSpec[MAX_PATH];
        szSpec[0] = 0;

        // skip all parameters that begin with "-" or "/" to try to find the
        // file name. this enables parameters to be present on the cmd line
        // and not get in the way of this function
        for (int i = 1; (szSpec[0] == 0) && (i < cArgs); i++)
        {
            if ((*ppszCmd[i] != L'-') && (*ppszCmd[i] != L'/'))
            {
                StringCchCopyW(szSpec, ARRAYSIZE(szSpec), ppszCmd[i]);
                PathUnquoteSpacesW(szSpec);
            }
        }

        hr = szSpec[0] ? S_OK : E_FAIL; // protect against empty
        if (SUCCEEDED(hr))
        {
            hr = SHCreateItemFromParsingName(szSpec, NULL, riid, ppv);
            if (FAILED(hr))
            {
                WCHAR szFolder[MAX_PATH];
                GetCurrentDirectoryW(ARRAYSIZE(szFolder), szFolder);
                hr = PathAppendW(szFolder, szSpec) ? S_OK : E_FAIL;
                if (SUCCEEDED(hr))
                {
                    hr = SHCreateItemFromParsingName(szFolder, NULL, riid, ppv);
                }
            }
        }
    }
    return hr;
}
示例#23
0
static bool initialiseDir(wchar_t *path, wchar_t *dirName)
{
	PathAppendW(path, dirName);
	DWORD attributes = GetFileAttributesW(path);
	if (INVALID_FILE_ATTRIBUTES == attributes) {
		DWORD error = GetLastError();
		if (ERROR_FILE_NOT_FOUND == error ||
			ERROR_PATH_NOT_FOUND == error) {
			error = CreateDirectoryW(path, NULL);
			if (!SUCCEEDED(error)) {
				myLog(LOG_ERR, "initialiseDir: cannot create directory %S", path);
				return false;
			}
		} else {
			myLog(LOG_ERR, "initialiseDir: invalid directory %S error=0x%x", path, error);
			return false;
		}
	} else if ((FILE_ATTRIBUTE_DIRECTORY & attributes) != FILE_ATTRIBUTE_DIRECTORY) {
		myLog(LOG_ERR, "initialiseDir: invalid directory %S attributes=0x%x", path, attributes);
		return false;
	}
	return true;
}
示例#24
0
/* Recursively searches the directory dir for files that match the signature
 * sig, up to (depth + 1) levels deep.  That is, if depth is 0, it searches dir
 * (and only dir).  If depth is 1, searches dir and its immediate
 * subdirectories.
 * Assumes sig->File is not NULL.
 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
 * something else on failures which should halt the install.
 */
static UINT ACTION_RecurseSearchDirectory(MSIPACKAGE *package, LPWSTR *appValue,
 MSISIGNATURE *sig, LPCWSTR dir, int depth)
{
    HANDLE hFind;
    WIN32_FIND_DATAW findData;
    UINT rc = ERROR_SUCCESS;
    size_t dirLen = lstrlenW(dir), fileLen = lstrlenW(sig->File);
    WCHAR subpath[MAX_PATH];
    WCHAR *buf;
    DWORD len;

    static const WCHAR starDotStarW[] = { '*','.','*',0 };

    TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir),
          debugstr_w(sig->File), depth);

    if (depth < 0)
        return ERROR_SUCCESS;

    *appValue = NULL;
    /* We need the buffer in both paths below, so go ahead and allocate it
     * here.  Add two because we might need to add a backslash if the dir name
     * isn't backslash-terminated.
     */
    len = dirLen + max(fileLen, strlenW(starDotStarW)) + 2;
    buf = msi_alloc(len * sizeof(WCHAR));
    if (!buf)
        return ERROR_OUTOFMEMORY;

    lstrcpyW(buf, dir);
    PathAddBackslashW(buf);
    lstrcatW(buf, sig->File);

    hFind = FindFirstFileW(buf, &findData);
    if (hFind != INVALID_HANDLE_VALUE)
    {
        if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
        {
            BOOL matches;

            rc = ACTION_FileMatchesSig(sig, &findData, buf, &matches);
            if (rc == ERROR_SUCCESS && matches)
            {
                TRACE("found file, returning %s\n", debugstr_w(buf));
                *appValue = buf;
            }
        }
        FindClose(hFind);
    }

    if (rc == ERROR_SUCCESS && !*appValue)
    {
        lstrcpyW(buf, dir);
        PathAddBackslashW(buf);
        lstrcatW(buf, starDotStarW);

        hFind = FindFirstFileW(buf, &findData);
        if (hFind != INVALID_HANDLE_VALUE)
        {
            if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
                lstrcmpW(findData.cFileName, szDot) &&
                lstrcmpW(findData.cFileName, szDotDot))
            {
                lstrcpyW(subpath, dir);
                PathAppendW(subpath, findData.cFileName);
                rc = ACTION_RecurseSearchDirectory(package, appValue, sig,
                                                   subpath, depth - 1);
            }

            while (rc == ERROR_SUCCESS && !*appValue &&
                   FindNextFileW(hFind, &findData) != 0)
            {
                if (!lstrcmpW(findData.cFileName, szDot) ||
                    !lstrcmpW(findData.cFileName, szDotDot))
                    continue;

                lstrcpyW(subpath, dir);
                PathAppendW(subpath, findData.cFileName);
                if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                    rc = ACTION_RecurseSearchDirectory(package, appValue,
                                                       sig, subpath, depth - 1);
            }

            FindClose(hFind);
        }
    }

    if (*appValue != buf)
        msi_free(buf);

    return rc;
}
示例#25
0
UINT
pxDiMsiUninstallNetworkComponent(
	__in MSIHANDLE hInstall, 
	__in const XDIMSI_PROCESS_RECORD* ProcessRecord)
{
	while (TRUE)
	{
		LPWSTR oemInfName = NULL;
		HRESULT hr = xDiUninstallNetComponent(
			ProcessRecord->HardwareId,
			15 * 1000,
			L"Windows Installer",
			NULL,
			&oemInfName);

		if (FAILED(hr)) 
		{
			pxMsiTraceW(hInstall, L"UninstallNetComponent(%s) failed, hr=0x%x\n", 
				ProcessRecord->HardwareId, hr);

			UINT response = pxMsiErrorMessageBox(hInstall, ProcessRecord->ErrorNumber, hr);
			switch (response)
			{
			case IDRETRY:
				continue;
			case IDIGNORE:
				break;
			case 0:
			case IDABORT:
			default:
				return ERROR_INSTALL_FAILURE;
			}
		}

		//
		// S_FALSE may be returned in case that the component is not installed
		// at all.
		//

		if (S_FALSE != hr)
		{
			if (XDI_S_REBOOT == hr)
			{
				pxMsiQueueScheduleReboot(hInstall);
			}

			WCHAR oemInfPath[MAX_PATH];
			GetWindowsDirectoryW(oemInfPath, RTL_NUMBER_OF(oemInfPath));
			PathAppendW(oemInfPath, L"INF");
			PathAppendW(oemInfPath, oemInfName);

			//
			// See if any services in the INF file is marked for pending deletion
			//

			LPWSTR stalledServiceName = NULL;
			
			hr = xDiServiceIsMarkedForDeletionFromPnpInf(
				oemInfPath, 
				ProcessRecord->HardwareId, 
				&stalledServiceName);

			if (S_OK == hr)
			{
				pxMsiTraceW(hInstall, L"Service deletion requires the reboot, service=%ls\n",
					stalledServiceName);
				pxMsiQueueScheduleReboot(hInstall);
			}

			CoTaskMemFree(stalledServiceName);

			//
			// Delete driver files
			//

			hr = xDiDeleteDriverFiles(NULL, oemInfPath, XDI_EDF_NO_CLASS_INSTALLER);
			if (SUCCEEDED(hr))
			{
				if (XDI_S_REBOOT == hr) 
				{
					pxMsiQueueScheduleReboot(hInstall);
				}

				hr = xDiUninstallOEMInf(oemInfName, 0);
				if (FAILED(hr))
				{
					pxMsiTraceW(hInstall, L"UninstallOEMInf(%s) failed, hr=0x%x\n", 
						oemInfName, hr);
				}
				else
				{
					if (XDI_S_REBOOT == hr)
					{
						pxMsiQueueScheduleReboot(hInstall);
					}
				}
			}
			else
			{
				pxMsiTraceW(hInstall, 
					L"DeleteDriverFiles(%s) failed, hr=0x%x\n", oemInfPath, hr);
			}
		}

		if (NULL != oemInfName)
		{
			CoTaskMemFree(oemInfName);
		}

		break;
	}
	
	return ERROR_SUCCESS;
}
示例#26
0
UINT
pxDiMsiUninstallPnpDevice(
	__in MSIHANDLE hInstall, 
	__in const XDIMSI_PROCESS_RECORD* ProcessRecord)
{
	BOOL reboot = FALSE;
	BOOL success = FALSE;

	while (TRUE) 
	{
		LPWSTR serviceList = NULL;
		LPWSTR infNameList = NULL;

		HRESULT hr = xDiRemoveDevices(
			NULL,
			NULL,
			NULL,
			ProcessRecord->HardwareId,
			DIGCF_ALLCLASSES,
			&serviceList,
			&infNameList);

		if (FAILED(hr) && 0 != ProcessRecord->ErrorNumber)
		{
			pxMsiTraceW(hInstall, 
				L"NdasDiRemoveDevice failed, hardwareId=%s, hr=0x%x\n",
				ProcessRecord->HardwareId, hr);

			UINT response = pxMsiErrorMessageBox(hInstall, ProcessRecord->ErrorNumber, hr);
			switch (response)
			{
			case IDRETRY:
				continue;
			case IDIGNORE:
				break;
			case 0:
			case IDABORT:
			default:
				return ERROR_INSTALL_FAILURE;
			}
		}

		if (XDI_S_REBOOT == hr)
		{
			reboot  = TRUE;
		}

		hr = xDiDeletePnpDriverServices(serviceList);

		if (XDI_S_REBOOT == hr)
		{
			reboot = TRUE;
		}

		for (LPCWSTR infName = infNameList; 
			*infName; 
			infName += lstrlenW(infName) + 1)
		{
			WCHAR infPath[MAX_PATH];

			GetWindowsDirectoryW(infPath, RTL_NUMBER_OF(infPath));
			PathAppendW(infPath, L"INF");
			PathAppend(infPath, infName);

			xDiDeleteDriverFiles(NULL, infPath, XDI_EDF_NO_CLASS_INSTALLER);
			xDiUninstallOEMInf(infNameList, 0);
		}

		break;
	}

	if (reboot) 
	{
		pxMsiQueueScheduleReboot(hInstall);
	}

	return ERROR_SUCCESS;
}
Program::Program()
{
	wchar_t savePathBuffer[MAX_PATH];
	if (SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, savePathBuffer) >= 0)
	{
		PathAppendW(savePathBuffer, L"\\SA-MP Audio Plugin");
		if (!boost::filesystem::exists(savePathBuffer))
		{
			boost::filesystem::create_directories(savePathBuffer);
		}
		savePath = savePathBuffer;
	}
	else
	{
		savePath = L".";
	}
	const char *defaultAcceptedFileExtensions[] =
	{
		".afc",
		".aif",
		".aifc",
		".aiff",
		".it",
		".mo3",
		".mod",
		".mp1",
		".mp2",
		".mp3",
		".mtm",
		".oga",
		".ogg",
		".s3m",
		".umx",
		".wav",
		".wave",
		".xm"
	};
	for (std::size_t i = 0; i < sizeof(defaultAcceptedFileExtensions) / sizeof(const char*); ++i)
	{
		acceptedFileExtensions.insert(defaultAcceptedFileExtensions[i]);
	}
	const char *defaultIllegalCharacters[] =
	{
		"\"",
		"*",
		"..",
		"/",
		":",
		"<",
		">",
		"?",
		"\\",
		"|"
	};
	for (std::size_t i = 0; i < sizeof(defaultIllegalCharacters) / sizeof(const char*); ++i)
	{
		illegalCharacters.insert(defaultIllegalCharacters[i]);
	}
	settings.reset(new Settings);
	loadSettings();
	logText("SA-MP Audio Plugin loaded");
}
示例#28
0
void DominoDocArtifact::Upload(const std::wstring& fileToUpload)
{
    if(!PathFileExistsW(fileToUpload.c_str()))
      throw Workshare::System::IO::FileNotFoundException(_bstr_t(fileToUpload.c_str()), _T("Only files that exist can be uploaded to a Lotus Domino Repository"));

   DominoDoc::IDocumentPtr spDocument = GetDocument();      

   wchar_t tempPath[MAX_PATH] = {0};
   if(0 == ::GetTempPathW(MAX_PATH, tempPath))
   {
      DWORD lastError = ::GetLastError();
      std::tostringstream msg;
      msg << _T("Failed to get the temporary path while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends;
      throw Workshare::System::SystemException(msg.str().c_str(), lastError);
   }

   wchar_t tempFileName[_MAX_PATH] = {0};   
   if(0 == GetTempFileNameW(tempPath, L"WC", 0, tempFileName))
   {
      DWORD lastError = ::GetLastError();
      std::tostringstream msg;
      msg << _T("Failed to get the temporary filename while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends;
      throw Workshare::System::SystemException(msg.str().c_str(), lastError);
   }
   DeleteFileW(tempFileName);  
   PathRemoveExtensionW(tempFileName);
   if(!::CreateDirectoryW(tempFileName, NULL))
   {
      DWORD lastError = ::GetLastError();
      std::tostringstream msg;
      msg << _T("Failed to create a temporary directory [") << tempFileName << _T(", to upload [") << fileToUpload << _T("] for uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends;
      throw Workshare::System::SystemException(msg.str().c_str(), lastError);
   }

   wchar_t fileName[MAX_PATH] = {0};
   lstrcpyW(fileName, tempFileName);
   if(spDocument->FileName.length() > 0)
      PathAppendW(fileName,spDocument->FileName);
   else
      PathAppendW(fileName, PathFindFileNameW(fileToUpload.c_str()));

   if(!CopyFileW(fileToUpload.c_str(), fileName, TRUE))
   {
      DWORD lastError = ::GetLastError();
      std::tostringstream msg;
      msg << _T("Failed to copy [") << fileToUpload << _T("] to [") << fileName << _T("] while uploading artifact, ") << m_documentId << _T(", version, ") << m_versionLabel << _T(" which came from repository, ") << m_libraryUrl << std::ends;
      throw Workshare::System::SystemException(msg.str().c_str(), lastError);
   }

   try
   {
      spDocument->SetToWorkingCopy();
      spDocument->SetContents(fileName);
      spDocument->Save();
      spDocument->CheckIn(c_revisiontypeDraft, 1, VARIANT_FALSE, "Created By Workshare");        

      wchar_t versionLabel[32] = {0};
      _snwprintf(versionLabel, 32, L"%d.%d", spDocument->VersionNumber, spDocument->DraftNumber);      
      m_versionLabel = versionLabel;

      Log(_T("The file [%S] was uploaded to the Domino.Doc library [%S] as document [%S]"), fileToUpload.c_str(), m_libraryUrl.c_str(), m_documentId.c_str());

      DeleteFileW(fileName);      
      RemoveDirectoryW(tempFileName);
   }
   catch(...)
   {
      DeleteFileW(fileName);
      RemoveDirectoryW(tempFileName);
      throw;
   }   
}
示例#29
0
bool PathAppend(wchar_t* path, const wchar_t* more)
{
	return PathAppendW(path, more);
}
示例#30
0
/*
    010509 Carl Corcoran
*/
void CCString::Path_Append(PCWSTR wsz)
{
    this->_SizeSetPreserve(GetSizeOfStringW(this->wszString) + wcslen(wsz) + 2);
    PathAppendW(this->wszString, wsz);
}