lldir_windows.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @file lldir_windows.cpp
  3. * @brief Implementation of Windows-specific directory related methods
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #if LL_WINDOWS
  33. #include "linden_common.h"
  34. #include <shlobj.h>
  35. #include <direct.h>
  36. #include <errno.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include "lldir.h"
  40. void LLDir::init()
  41. {
  42. WCHAR w_str[MAX_PATH];
  43. // Application Data is where user settings go
  44. SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL,
  45. SHGFP_TYPE_DEFAULT, w_str);
  46. mOSBaseAppDir = ll_convert_wide_to_string(w_str);
  47. // This is the user's directory
  48. SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, w_str);
  49. mOSUserDir = ll_convert_wide_to_string(w_str);
  50. // We want cache files to go on the local disk, even if the user is on a
  51. // network with a "roaming profile": E.g. C:\Users\James\AppData\Local
  52. SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL,
  53. SHGFP_TYPE_DEFAULT, w_str);
  54. mOSCacheDir = ll_convert_wide_to_string(w_str);
  55. if (GetTempPath(MAX_PATH, w_str))
  56. {
  57. if (wcslen(w_str))
  58. {
  59. w_str[wcslen(w_str) - 1] = '\0'; // Remove trailing slash
  60. }
  61. mTempDir = ll_convert_wide_to_string(w_str);
  62. }
  63. else
  64. {
  65. mTempDir = mOSBaseAppDir;
  66. }
  67. #if 1
  68. // Do not use the real app path for now, as we will have to add parsing to
  69. // detect if we are in a developer tree, which has a different structure
  70. // from the installed product.
  71. S32 size = GetModuleFileName(NULL, w_str, MAX_PATH);
  72. if (size)
  73. {
  74. w_str[size] = '\0';
  75. mExecutablePathAndName = ll_convert_wide_to_string(w_str);
  76. size_t path_end = mExecutablePathAndName.find_last_of('\\');
  77. if (path_end != std::string::npos)
  78. {
  79. mExecutableDir = mExecutablePathAndName.substr(0, path_end);
  80. mExecutableFilename = mExecutablePathAndName.substr(path_end + 1);
  81. }
  82. else
  83. {
  84. mExecutableFilename = mExecutablePathAndName;
  85. }
  86. GetCurrentDirectory(MAX_PATH, w_str);
  87. mWorkingDir = ll_convert_wide_to_string(w_str);
  88. }
  89. else
  90. {
  91. fprintf(stderr,
  92. "Could not get APP path, assuming current directory !");
  93. GetCurrentDirectory(MAX_PATH, w_str);
  94. mExecutableDir = ll_convert_wide_to_string(w_str);
  95. // Assume it is the current directory
  96. }
  97. #else
  98. GetCurrentDirectory(MAX_PATH, w_str);
  99. mExecutableDir = utf16str_to_utf8str(llutf16string(w_str));
  100. #endif
  101. mAppRODataDir = mExecutableDir;
  102. // Build the default cache directory
  103. mDefaultCacheDir = buildSLOSCacheDir();
  104. // Make sure it exists
  105. if (!LLFile::mkdir(mDefaultCacheDir))
  106. {
  107. llwarns << "Could not create LL_PATH_CACHE dir " << mDefaultCacheDir
  108. << llendl;
  109. }
  110. mLLPluginDir = mExecutableDir + "\\llplugin";
  111. dumpCurrentDirectories();
  112. }
  113. void LLDir::initAppDirs(const std::string& app_name)
  114. {
  115. mAppName = app_name;
  116. mOSUserAppDir = mOSBaseAppDir;
  117. mOSUserAppDir += "\\";
  118. mOSUserAppDir += app_name;
  119. if (!LLFile::mkdir(mOSUserAppDir))
  120. {
  121. llwarns << "Could not create app user dir " << mOSUserAppDir
  122. << " - Default to base dir " << mOSBaseAppDir << llendl;
  123. mOSUserAppDir = mOSBaseAppDir;
  124. }
  125. if (!LLFile::mkdir(getFullPath(LL_PATH_LOGS)))
  126. {
  127. llwarns << "Could not create LL_PATH_LOGS dir "
  128. << getFullPath(LL_PATH_LOGS) << llendl;
  129. }
  130. if (!LLFile::mkdir(getFullPath(LL_PATH_USER_SETTINGS)))
  131. {
  132. llwarns << "Could not create LL_PATH_USER_SETTINGS dir "
  133. << getFullPath(LL_PATH_USER_SETTINGS) << llendl;
  134. }
  135. if (!LLFile::mkdir(getFullPath(LL_PATH_CACHE)))
  136. {
  137. llwarns << "Could not create LL_PATH_CACHE dir "
  138. << getFullPath(LL_PATH_CACHE) << llendl;
  139. }
  140. mCRTFile = getFullPath(LL_PATH_APP_SETTINGS, "ca-bundle.crt");
  141. dumpCurrentDirectories();
  142. }
  143. std::string LLDir::getCurPath()
  144. {
  145. WCHAR w_str[MAX_PATH];
  146. GetCurrentDirectory(MAX_PATH, w_str);
  147. return ll_convert_wide_to_string(w_str);
  148. }
  149. std::string LLDir::getLLPluginLauncher()
  150. {
  151. return mExecutableDir + "\\SLPlugin.exe";
  152. }
  153. std::string LLDir::getLLPluginFilename(std::string base_name)
  154. {
  155. return mLLPluginDir + "\\" + base_name + ".dll";
  156. }
  157. #endif // LL_WINDOWS