Example #1
0
const std::string  LLDir::getCacheDir(bool get_default) const
{
	if (mCacheDir.empty() || get_default)
	{
		if (!mDefaultCacheDir.empty())
		{	// Set at startup - can't set here due to const API
			return mDefaultCacheDir;
		}
		
		std::string res = buildSLOSCacheDir();
		return res;
	}
	else
	{
		return mCacheDir;
	}
}
Example #2
0
LLDir_Win32::LLDir_Win32()
{
	mDirDelimiter = "\\";

	WCHAR w_str[MAX_PATH];

	WCHAR* pPath = NULL;
	if(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &pPath) == S_OK)
		wcscpy_s(w_str, pPath);

	CoTaskMemFree(pPath);
	pPath = NULL;

	mOSUserDir = utf16str_to_utf8str(llutf16string(w_str));

	// We want cache files to go on the local disk, even if the
	// user is on a network with a "roaming profile".
	//
	// On Vista and above this is:
	//   C:\Users\<USERNAME>\AppData\Local
	//
	// We used to store the cache in AppData\Roaming, and the installer
	// cleans up that version on upgrade.  JC
	if(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &pPath) == S_OK)
		wcscpy_s(w_str, pPath);

	CoTaskMemFree(pPath);
	pPath = NULL;

	mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str));

	if (GetTempPath(MAX_PATH, w_str))
	{
		if (wcslen(w_str))	/* Flawfinder: ignore */ 
		{
			w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash
		}
		mTempDir = utf16str_to_utf8str(llutf16string(w_str));
	}
	else
	{
		mTempDir = mOSUserDir;
	}

//	fprintf(stderr, "mTempDir = <%s>",mTempDir);

	// Set working directory, for LLDir::getWorkingDir()
	GetCurrentDirectory(MAX_PATH, w_str);
	mWorkingDir = utf16str_to_utf8str(llutf16string(w_str));

	// Set the executable directory
	S32 size = GetModuleFileName(NULL, w_str, MAX_PATH);
	if (size)
	{
		w_str[size] = '\0';
		mExecutablePathAndName = utf16str_to_utf8str(llutf16string(w_str));
		size_t path_end = mExecutablePathAndName.find_last_of('\\');
		if (path_end != std::string::npos)
		{
			mExecutableDir = mExecutablePathAndName.substr(0, path_end);
			mExecutableFilename = mExecutablePathAndName.substr(path_end+1, std::string::npos);
		}
		else
		{
			mExecutableFilename = mExecutablePathAndName;
		}

	}
	else
	{
		fprintf(stderr, "Couldn't get APP path, assuming current directory!\n");
		mExecutableDir = mWorkingDir;
		// Assume it's the current directory
	}

	// mAppRODataDir = ".";	

	// Determine the location of the App-Read-Only-Data
	// Try the working directory then the exe's dir.
	mAppRODataDir = mWorkingDir;	


//	if (mExecutableDir.find("indra") == std::string::npos)

	// *NOTE:Mani - It is a mistake to put viewer specific code in
	// the LLDir implementation. The references to 'skins' and 
	// 'llplugin' need to go somewhere else.
	// alas... this also gets called during static initialization 
	// time due to the construction of gDirUtil in lldir.cpp.
	if(! LLFile::isdir(mAppRODataDir + mDirDelimiter + "skins"))
	{
		// What? No skins in the working dir?
		// Try the executable's directory.
		mAppRODataDir = mExecutableDir;
	}

//	LL_INFOS() << "mAppRODataDir = " << mAppRODataDir << LL_ENDL;

	mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins";

	// Build the default cache directory
	mDefaultCacheDir = buildSLOSCacheDir();
	
	// Make sure it exists
	int res = LLFile::mkdir(mDefaultCacheDir);
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			LL_WARNS() << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << LL_ENDL;
		}
	}

	mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin";
}
LLDir_Win32::LLDir_Win32()
{
	mDirDelimiter = "\\";

	WCHAR w_str[MAX_PATH];

	// Application Data is where user settings go
	SHGetSpecialFolderPath(NULL, w_str, CSIDL_APPDATA, TRUE);

	mOSUserDir = utf16str_to_utf8str(llutf16string(w_str));

	// We want cache files to go on the local disk, even if the
	// user is on a network with a "roaming profile".
	//
	// On XP this is:
	//   C:\Docments and Settings\James\Local Settings\Application Data
	// On Vista this is:
	//   C:\Users\James\AppData\Local
	//
	// We used to store the cache in AppData\Roaming, and the installer
	// cleans up that version on upgrade.  JC

	if(HMODULE shell = LoadLibrary(L"shell32"))	//SHGetSpecialFolderPath is deprecated from Vista an onwards. Try to use SHGetSpecialFolderPath if it's available
	{
		HRESULT (WINAPI* pSHGetKnownFolderPath)(REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
		pSHGetKnownFolderPath = (HRESULT (WINAPI *)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR *))GetProcAddress(shell, "SHGetKnownFolderPath");
		WCHAR* pPath = NULL;
		if(pSHGetKnownFolderPath && (*pSHGetKnownFolderPath)(FOLDERID_LocalAppData, 0, NULL, &pPath) == S_OK)
			wcscpy_s(w_str,pPath);
		else
			SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE);

		FreeLibrary(shell);
		if(pPath)
			CoTaskMemFree(pPath);
	}
	else	//XP doesn't support SHGetKnownFolderPath
	{
		SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE);
	}
	mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str));

	if (GetTempPath(MAX_PATH, w_str))
	{
		if (wcslen(w_str))	/* Flawfinder: ignore */ 
		{
			w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash
		}
		mTempDir = utf16str_to_utf8str(llutf16string(w_str));
	}
	else
	{
		mTempDir = mOSUserDir;
	}

//	fprintf(stderr, "mTempDir = <%s>",mTempDir);

	// Set working directory, for LLDir::getWorkingDir()
	GetCurrentDirectory(MAX_PATH, w_str);
	mWorkingDir = utf16str_to_utf8str(llutf16string(w_str));

	// Set the executable directory
	S32 size = GetModuleFileName(NULL, w_str, MAX_PATH);
	if (size)
	{
		w_str[size] = '\0';
		mExecutablePathAndName = utf16str_to_utf8str(llutf16string(w_str));
		S32 path_end = mExecutablePathAndName.find_last_of('\\');
		if (path_end != std::string::npos)
		{
			mExecutableDir = mExecutablePathAndName.substr(0, path_end);
			mExecutableFilename = mExecutablePathAndName.substr(path_end+1, std::string::npos);
		}
		else
		{
			mExecutableFilename = mExecutablePathAndName;
		}

	}
	else
	{
		fprintf(stderr, "Couldn't get APP path, assuming current directory!\n");
		mExecutableDir = mWorkingDir;
		// Assume it's the current directory
	}

	// mAppRODataDir = ".";	

	// Determine the location of the App-Read-Only-Data
	// Try the working directory then the exe's dir.
	mAppRODataDir = mWorkingDir;	


//	if (mExecutableDir.find("indra") == std::string::npos)
	
	// *NOTE:Mani - It is a mistake to put viewer specific code in
	// the LLDir implementation. The references to 'skins' and 
	// 'llplugin' need to go somewhere else.
	// alas... this also gets called during static initialization 
	// time due to the construction of gDirUtil in lldir.cpp.
	if(! LLFile::isdir(mAppRODataDir + mDirDelimiter + "skins"))
	{
		// What? No skins in the working dir?
		// Try the executable's directory.
		mAppRODataDir = mExecutableDir;
	}

	llinfos << "mAppRODataDir = " << mAppRODataDir << llendl;

	mSkinBaseDir = mAppRODataDir + mDirDelimiter + "skins";

	// Build the default cache directory
	mDefaultCacheDir = buildSLOSCacheDir();
	
	// Make sure it exists
	int res = LLFile::mkdir(mDefaultCacheDir);
	if (res == -1)
	{
		if (errno != EEXIST)
		{
			llwarns << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << llendl;
		}
	}

	mLLPluginDir = mExecutableDir + mDirDelimiter + "llplugin";
}
LLDir_Win32::LLDir_Win32()
{
    mDirDelimiter = "\\";

    WCHAR w_str[MAX_PATH];

    // Application Data is where user settings go
    SHGetSpecialFolderPath(NULL, w_str, CSIDL_APPDATA, TRUE);

    mOSUserDir = utf16str_to_utf8str(llutf16string(w_str));

    // We want cache files to go on the local disk, even if the
    // user is on a network with a "roaming profile".
    //
    // On XP this is:
    //   C:\Docments and Settings\James\Local Settings\Application Data
    // On Vista this is:
    //   C:\Users\James\AppData\Local
    //
    // We used to store the cache in AppData\Roaming, and the installer
    // cleans up that version on upgrade.  JC
    SHGetSpecialFolderPath(NULL, w_str, CSIDL_LOCAL_APPDATA, TRUE);
    mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str));

    if (GetTempPath(MAX_PATH, w_str))
    {
        if (wcslen(w_str))	/* Flawfinder: ignore */
        {
            w_str[wcslen(w_str)-1] = '\0'; /* Flawfinder: ignore */ // remove trailing slash
        }
        mTempDir = utf16str_to_utf8str(llutf16string(w_str));
    }
    else
    {
        mTempDir = mOSUserDir;
    }

//	fprintf(stderr, "mTempDir = <%s>",mTempDir);

#if 1
    // Don't use the real app path for now, as we'll have to add parsing to detect if
    // we're in a developer tree, which has a different structure from the installed product.

    S32 size = GetModuleFileName(NULL, w_str, MAX_PATH);
    if (size)
    {
        w_str[size] = '\0';
        mExecutablePathAndName = utf16str_to_utf8str(llutf16string(w_str));
        S32 path_end = mExecutablePathAndName.find_last_of('\\');
        if (path_end != std::string::npos)
        {
            mExecutableDir = mExecutablePathAndName.substr(0, path_end);
            mExecutableFilename = mExecutablePathAndName.substr(path_end+1, std::string::npos);
        }
        else
        {
            mExecutableFilename = mExecutablePathAndName;
        }
        GetCurrentDirectory(MAX_PATH, w_str);
        mWorkingDir = utf16str_to_utf8str(llutf16string(w_str));

    }
    else
    {
        fprintf(stderr, "Couldn't get APP path, assuming current directory!");
        GetCurrentDirectory(MAX_PATH, w_str);
        mExecutableDir = utf16str_to_utf8str(llutf16string(w_str));
        // Assume it's the current directory
    }
#else
    GetCurrentDirectory(MAX_PATH, w_str);
    mExecutableDir = utf16str_to_utf8str(llutf16string(w_str));
#endif

    // When running in a dev tree, app_settings is under indra/newview/
    // but in production it is under Program Files/meta7/
    // Attempt to detect which one we're using. JC
    if (mExecutableDir.find("indra") != std::string::npos)
        mAppRODataDir = getCurPath();
    else
        mAppRODataDir = mExecutableDir;


    // Build the default cache directory
    mDefaultCacheDir = buildSLOSCacheDir();

    // Make sure it exists
    int res = LLFile::mkdir(mDefaultCacheDir);
    if (res == -1)
    {
        if (errno != EEXIST)
        {
            llwarns << "Couldn't create LL_PATH_CACHE dir " << mDefaultCacheDir << llendl;
        }
    }
}