本文整理汇总了C++中SHGetFolderPath函数的典型用法代码示例。如果您正苦于以下问题:C++ SHGetFolderPath函数的具体用法?C++ SHGetFolderPath怎么用?C++ SHGetFolderPath使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SHGetFolderPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
return 2;
}
#ifdef USING_EGL
EGL_Init();
#endif
#ifdef PPSSPP
SDL_WM_SetCaption((app_name_nice + " " + PPSSPP_GIT_VERSION).c_str(), NULL);
#endif
#ifdef MOBILE_DEVICE
SDL_ShowCursor(SDL_DISABLE);
#endif
#ifndef USING_GLES2
if (GLEW_OK != glewInit()) {
printf("Failed to initialize glew!\n");
return 1;
}
if (GLEW_VERSION_2_0) {
printf("OpenGL 2.0 or higher.\n");
} else {
printf("Sorry, this program requires OpenGL 2.0.\n");
return 1;
}
#endif
#ifdef _MSC_VER
// VFSRegister("temp/", new DirectoryAssetReader("E:\\Temp\\"));
TCHAR path[MAX_PATH];
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, path);
PathAppend(path, (app_name + "\\").c_str());
#else
// Mac / Linux
char path[512];
const char *the_path = getenv("HOME");
if (!the_path) {
struct passwd* pwd = getpwuid(getuid());
if (pwd)
the_path = pwd->pw_dir;
}
strcpy(path, the_path);
if (path[strlen(path)-1] != '/')
strcat(path, "/");
#endif
#ifdef _WIN32
NativeInit(argc, (const char **)argv, path, "D:\\", "BADCOFFEE");
#else
NativeInit(argc, (const char **)argv, path, "/tmp", "BADCOFFEE");
#endif
pixel_in_dps = (float)pixel_xres / dp_xres;
g_dpi_scale = dp_xres / (float)pixel_xres;
printf("Pixels: %i x %i\n", pixel_xres, pixel_yres);
printf("Virtual pixels: %i x %i\n", dp_xres, dp_yres);
NativeInitGraphics();
NativeResized();
SDL_AudioSpec fmt, ret_fmt;
memset(&fmt, 0, sizeof(fmt));
示例2: ParseParam
void FFileManagerWindows::Init(UBOOL Startup)
{
// a shipped PC game will always run as if installed
#if SHIPPING_PC_GAME && !UDK
// shipping PC game
bIsRunningInstalled = TRUE;
#else
// for development, use a commandline param (-installed)
bIsRunningInstalled = ParseParam(appCmdLine(),TEXT("installed"));
#endif
// Allow overriding use of My Documents folder with -NOHOMEDIR
if( ParseParam(appCmdLine(),TEXT("NOHOMEDIR") ) )
{
bIsRunningInstalled = FALSE;
}
if (bIsRunningInstalled)
{
debugf( TEXT( " ... running in INSTALLED mode" ) );
TCHAR UserPath[MAX_PATH];
// get the My Documents directory
HRESULT Ret = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, UserPath);
// get the per-game directory name to use inside the My Documents directory
FString DefaultIniContents;
// load the DefaultEngine.ini config file into a string for later parsing (ConvertAbsolutePathToUserPath will use
// original location since WindowsUserDir hasn't been set yet)
// can't use GDefaultEngineIni, because that may be something that doesn't have the tag
if (!appLoadFileToString(DefaultIniContents, *(appGameConfigDir() + TEXT("DefaultEngine.ini")), this))
{
// appMsgf won't write to a log if GWarn is NULL, which it should be at this point
appMsgf(AMT_OK, TEXT("Failed to find default engine .ini file to retrieve My Documents subdirectory to use. Force quitting."));
exit(1);
return;
}
#define MYDOC_KEY_NAME TEXT("MyDocumentsSubDirName=")
// find special key in the .ini file (can't use GConfig because it can't be used yet until after filemanager is made)
INT KeyLocation = DefaultIniContents.InStr(MYDOC_KEY_NAME, FALSE, TRUE);
if (KeyLocation == INDEX_NONE)
{
// appMsgf won't write to a log if GWarn is NULL, which it should be at this point
appMsgf(AMT_OK, TEXT("Failed to find %s key in DefaultEngine.ini. Force quitting."), MYDOC_KEY_NAME);
exit(1);
return;
}
// skip over the key to get the value (skip key and = sign) and everything after it
FString ValueAndLeftover = DefaultIniContents.Mid(KeyLocation + appStrlen(MYDOC_KEY_NAME));
// now chop off this string at an end of line
TArray<FString> Tokens;
ValueAndLeftover.ParseIntoArray(&Tokens, TEXT("\r\n"), TRUE);
// make the base user dir path
WindowsUserDir = FString(UserPath)
+ TEXT("\\My Games\\")
+ Tokens(0)
#if DEMOVERSION
+ TEXT(" Demo")
#endif
+ TEXT("\\");
// find out our executable path
WindowsRootDir = appBaseDir();
// strip off the Binaries directory
WindowsRootDir = WindowsRootDir.Left(WindowsRootDir.InStr(TEXT("\\Binaries\\"), TRUE, TRUE) + 1);
// Now that the root directory has been set, create directories at startup.
// Note this must come after the above because MakeDirectory calls
// ConvertAbsolutePathToUserPath which uses WindowsRootDir and WindowsUserDir.
#define DIRSTOCREATATSTARTUP_KEY_NAME TEXT("DirsToCreateAtStartup=")
INT FindStartPos = INDEX_NONE;
while ( TRUE )
{
// find special key in the .ini file (can't use GConfig because it can't be used yet until after filemanager is made)
const INT KeyLocation = DefaultIniContents.InStr(DIRSTOCREATATSTARTUP_KEY_NAME, FALSE, TRUE, FindStartPos);
if (KeyLocation == INDEX_NONE)
{
break;
}
// Advance the find pos because we're doing a multi find.
FindStartPos = KeyLocation + appStrlen(DIRSTOCREATATSTARTUP_KEY_NAME);
// skip over the key to get the value (skip key and = sign) and everything after it
FString ValueAndLeftover = DefaultIniContents.Mid(KeyLocation + appStrlen(DIRSTOCREATATSTARTUP_KEY_NAME));
// now chop off this string at an end of line
TArray<FString> Tokens;
ValueAndLeftover.ParseIntoArray(&Tokens, TEXT("\r\n"), TRUE);
// Create the directory.
MakeDirectory( *Tokens(0), TRUE );
}
}
FFileManagerGeneric::Init(Startup);
//.........这里部分代码省略.........
示例3: SHGetFolderPath
Path System::GetUserDir()
{
Path p;
SHGetFolderPath(NULL, CSIDL_PROFILE, nullptr, SHGFP_TYPE_CURRENT, p.getBuffer());
return p;
}
示例4: GetDebugHelperDll
LONG CMiniDumper::TopLevelFilter(struct _EXCEPTION_POINTERS* pExceptionInfo)
{
LONG lRetValue = EXCEPTION_CONTINUE_SEARCH;
TCHAR szResult[_MAX_PATH + 1024] = {0};
MINIDUMPWRITEDUMP pfnMiniDumpWriteDump = NULL;
HMODULE hDll = GetDebugHelperDll((FARPROC*)&pfnMiniDumpWriteDump, true);
HINSTANCE hInstCrashReporter = NULL;
if (hDll)
{
if (pfnMiniDumpWriteDump)
{
{
// Create full path for BugReport.exe
TCHAR szSharkPath[_MAX_PATH] = {0};
TCHAR szDumpPath_no_time[_MAX_PATH] = {0};
GetModuleFileName(NULL, szSharkPath, wcslen(szSharkPath));
LPTSTR pszFileName = _tcsrchr(szSharkPath, _T('\\'));
if (pszFileName) {
pszFileName++;
*pszFileName = _T('\0');
}
TCHAR szCrashReport[MAX_PATH] = {0};
_tcsncat(szCrashReport,szSharkPath,wcslen(szCrashReport) - 1);
_tcsncat(szCrashReport,_T("BugReport.exe"),wcslen(szCrashReport) - 1);
// Create full path for DUMP file
TCHAR szDumpPath[MAX_PATH]={0};
SHGetFolderPath(NULL, CSIDL_APPDATA,NULL,SHGFP_TYPE_CURRENT,szDumpPath);
_tcsncat(szDumpPath,_T("\\XiaTing\\"),wcslen(szDumpPath) - 1);
// Replace spaces and dots in file name.
TCHAR szBaseName[_MAX_PATH] = {0};
_tcsncat(szBaseName, m_szAppName, wcslen(szBaseName) - 1);
LPTSTR psz = szBaseName;
while (*psz != _T('\0')) {
if (*psz == _T('.'))
*psz = _T('-');
else if (*psz == _T(' '))
*psz = _T('_');
psz++;
}
_tcsncat(szDumpPath, szBaseName, wcslen(szDumpPath) - 1);
_tcsncat(szDumpPath_no_time, szBaseName, wcslen(szDumpPath_no_time) - 1);
if (!theCrashDumper.mb_user_mode)
{
time_t n_now = time(NULL);
struct tm* p_time = localtime(&n_now);
if (p_time != NULL)
{
TCHAR s_format[256];
s_format[0] = 0x0;
_tcsftime(s_format, 255, _T("-%Y.%m.%d - %H-%M-%S"), p_time);
_tcsncat(szDumpPath, s_format, _tcslen(s_format) -1);
}
}
_tcsncat(szDumpPath, _T(".dmp"), wcslen(szDumpPath) - 1);
_tcsncat(szDumpPath_no_time, _T(".dmp"), wcslen(szDumpPath_no_time) - 1);
HANDLE hFile = CreateFile(szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
_MINIDUMP_EXCEPTION_INFORMATION ExInfo = {0};
ExInfo.ThreadId = GetCurrentThreadId();
ExInfo.ExceptionPointers = pExceptionInfo;
ExInfo.ClientPointers = NULL;
BOOL bOK = (*pfnMiniDumpWriteDump)(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL);
if (bOK)
{
_sntprintf(szResult, wcslen(szResult), _T("Saved dump file to \"%s\".\r\n\r\nPlease send this file together with a detailed bug report to [email protected] !\r\n\r\nThank you for helping to improve eMule."), szDumpPath);
lRetValue = EXCEPTION_EXECUTE_HANDLER;
CString cs_cmd_line;
cs_cmd_line.Format(_T("%s%s"),_T("Cmd|"),szDumpPath_no_time);
hInstCrashReporter = ShellExecuteW(NULL, _T("open"), szCrashReport, cs_cmd_line.GetBuffer(), NULL, SW_SHOW);
if (hInstCrashReporter <= (HINSTANCE)32)
lRetValue = EXCEPTION_CONTINUE_SEARCH;
}
else
{
_sntprintf(szResult, wcslen(szResult), _T("Failed to save dump file to \"%s\".\r\n\r\nError: %u"), szDumpPath, GetLastError());
}
CloseHandle(hFile);
}
else
{
_sntprintf(szResult, wcslen(szResult), _T("Failed to create dump file \"%s\".\r\n\r\nError: %u"), szDumpPath, GetLastError());
}
}
}
FreeLibrary(hDll);
hDll = NULL;
//.........这里部分代码省略.........
示例5: defined
Global::Global() {
mw = 0;
db = 0;
p = 0;
nam = 0;
uiSession = 0;
uiDoublePush = 1000000;
iPushToTalk = 0;
iTarget = 0;
iPrevTarget = 0;
bPushToMute = false;
bCenterPosition = false;
bPosTest = false;
bInAudioWizard = false;
iAudioPathTime = 0;
iAudioBandwidth = -1;
iMaxBandwidth = -1;
iCodecAlpha = 0;
iCodecBeta = 0;
bPreferAlpha = true;
bOpus = true;
bAttenuateOthers = false;
bAllowHTML = true;
uiMessageLength = 5000;
uiImageLength = 131072;
qs = NULL;
ocIntercept = NULL;
bc = NULL;
lcd = NULL;
o = NULL;
l = NULL;
bHappyEaster = false;
bQuit = false;
QStringList qsl;
qsl << QCoreApplication::instance()->applicationDirPath();
qsl << QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#if defined(Q_OS_WIN)
QString appdata;
wchar_t appData[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appData))) {
appdata = QDir::fromNativeSeparators(QString::fromWCharArray(appData));
if (!appdata.isEmpty()) {
appdata.append(QLatin1String("/Mumble"));
qsl << appdata;
}
}
#endif
foreach(const QString &dir, qsl) {
QFile inifile(QString::fromLatin1("%1/mumble.ini").arg(dir));
if (inifile.exists() && inifile.permissions().testFlag(QFile::WriteUser)) {
qdBasePath = dir;
qs = new QSettings(inifile.fileName(), QSettings::IniFormat);
break;
}
}
示例6: set_preferences_dir
void set_preferences_dir(std::string path)
{
#ifdef _WIN32
if(path.empty()) {
game_config::preferences_dir = get_cwd() + "/userdata";
} else if (path.size() > 2 && path[1] == ':') {
//allow absolute path override
game_config::preferences_dir = path;
} else {
char my_documents_path[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, my_documents_path))) {
std::string mygames_path = std::string(my_documents_path) + "/" + "My Games";
boost::algorithm::replace_all(mygames_path, std::string("\\"), std::string("/"));
create_directory_if_missing(mygames_path);
game_config::preferences_dir = mygames_path + "/" + path;
// unicode to utf8
WCHAR wc[MAX_PATH];
SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, wc);
WideCharToMultiByte(CP_UTF8, 0, wc, -1, my_documents_path, MAX_PATH, NULL, NULL);
mygames_path = std::string(my_documents_path) + "/" + "My Games";
boost::algorithm::replace_all(mygames_path, std::string("\\"), std::string("/"));
game_config::preferences_dir_utf8 = mygames_path + "/" + path;
} else {
game_config::preferences_dir = get_cwd() + "/" + path;
}
}
// conv_ansi_utf8(game_config::preferences_dir, true);
#elif defined(ANDROID)
game_config::preferences_dir = game_config::path + std::string("/") + path;
// non-win32, assume no tow-code character.
game_config::preferences_dir_utf8 = game_config::preferences_dir;
#elif defined(__APPLE__) && !TARGET_OS_IPHONE
game_config::preferences_dir = get_cwd() + std::string("/../") + path;
// non-win32, assume no tow-code character.
game_config::preferences_dir_utf8 = game_config::preferences_dir;
#else
#ifdef PREFERENCES_DIR
if (path.empty()) path = PREFERENCES_DIR;
#endif
std::string path2 = ".wesnoth" + game_config::version.substr(0,3);
#ifdef _X11
const char *home_str = getenv("HOME");
if (path.empty()) {
char const *xdg_data = getenv("XDG_DATA_HOME");
if (!xdg_data || xdg_data[0] == '\0') {
if (!home_str) {
path = path2;
goto other;
}
user_data_dir = home_str;
user_data_dir += "/.local/share";
} else user_data_dir = xdg_data;
user_data_dir += "/wesnoth/";
user_data_dir += game_config::version.substr(0,3);
create_directory_if_missing_recursive(user_data_dir);
game_config::preferences_dir = user_data_dir;
} else {
other:
std::string home = home_str ? home_str : ".";
if (path[0] == '/')
game_config::preferences_dir = path;
else
game_config::preferences_dir = home + "/" + path;
}
#else
if (path.empty()) path = path2;
#ifdef __AMIGAOS4__
game_config::preferences_dir = "PROGDIR:" + path;
#elif defined(__BEOS__)
if (be_path.InitCheck() != B_OK) {
BPath tpath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &be_path, true) == B_OK) {
be_path.Append("wesnoth");
} else {
be_path.SetTo("/boot/home/config/settings/wesnoth");
}
game_config::preferences_dir = be_path.Path();
}
#else
const char* home_str = getenv("HOME");
std::string home = home_str ? home_str : ".";
if (path[0] == '/')
game_config::preferences_dir = path;
else
game_config::preferences_dir = home + std::string("/") + path;
#endif
#endif
// non-win32, assume no tow-code character.
game_config::preferences_dir_utf8 = game_config::preferences_dir;
#endif /*_WIN32*/
user_data_dir = game_config::preferences_dir;
#ifdef ANDROID
//.........这里部分代码省略.........
示例7: SetUserDirectory
void SetUserDirectory(const std::string& custom_path)
{
if (!custom_path.empty())
{
File::CreateFullPath(custom_path + DIR_SEP);
File::SetUserPath(D_USER_IDX, custom_path + DIR_SEP);
return;
}
std::string user_path = "";
#ifdef _WIN32
// Detect where the User directory is. There are five different cases
// (on top of the command line flag, which overrides all this):
// 1. GetExeDirectory()\portable.txt exists
// -> Use GetExeDirectory()\User
// 2. HKCU\Software\Dolphin Emulator\LocalUserConfig exists and is true
// -> Use GetExeDirectory()\User
// 3. HKCU\Software\Dolphin Emulator\UserConfigPath exists
// -> Use this as the user directory path
// 4. My Documents exists
// -> Use My Documents\Dolphin Emulator as the User directory path
// 5. Default
// -> Use GetExeDirectory()\User
// Check our registry keys
HKEY hkey;
DWORD local = 0;
TCHAR configPath[MAX_PATH] = {0};
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE,
&hkey) == ERROR_SUCCESS)
{
DWORD size = 4;
if (RegQueryValueEx(hkey, TEXT("LocalUserConfig"), nullptr, nullptr,
reinterpret_cast<LPBYTE>(&local), &size) != ERROR_SUCCESS)
local = 0;
size = MAX_PATH;
if (RegQueryValueEx(hkey, TEXT("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath,
&size) != ERROR_SUCCESS)
configPath[0] = 0;
RegCloseKey(hkey);
}
local = local || File::Exists(File::GetExeDirectory() + DIR_SEP "portable.txt");
// Get Program Files path in case we need it.
TCHAR my_documents[MAX_PATH];
bool my_documents_found = SUCCEEDED(
SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
if (local) // Case 1-2
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
else if (configPath[0]) // Case 3
user_path = TStrToUTF8(configPath);
else if (my_documents_found) // Case 4
user_path = TStrToUTF8(my_documents) + DIR_SEP "Dolphin Emulator" DIR_SEP;
else // Case 5
user_path = File::GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
// Prettify the path: it will be displayed in some places, we don't want a mix
// of \ and /.
user_path = ReplaceAll(user_path, "\\", DIR_SEP);
// Make sure it ends in DIR_SEP.
if (*user_path.rbegin() != DIR_SEP_CHR)
user_path += DIR_SEP;
#else
if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
{
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
}
else
{
const char* env_path = getenv("DOLPHIN_EMU_USERPATH");
const char* home = getenv("HOME");
if (!home)
home = getenv("PWD");
if (!home)
home = "";
std::string home_path = std::string(home) + DIR_SEP;
#if defined(__APPLE__) || defined(ANDROID)
if (env_path)
{
user_path = env_path;
}
else
{
user_path = home_path + DOLPHIN_DATA_DIR DIR_SEP;
}
#else
// We are on a non-Apple and non-Android POSIX system, there are 4 cases:
// 1. GetExeDirectory()/portable.txt exists
// -> Use GetExeDirectory()/User
// 2. $DOLPHIN_EMU_USERPATH is set
// -> Use $DOLPHIN_EMU_USERPATH
// 3. ~/.dolphin-emu directory exists
// -> Use ~/.dolphin-emu
// 4. Default
//.........这里部分代码省略.........
示例8: initaltacast
// Here is the entry point for the Plugin..this gets called first.
int initaltacast(struct winampDSPModule *this_mod)
{
char filename[512],*p;
char directory[1024] = "";
char currentDir[1024] = "";
memset(filename, '\000', sizeof(filename));
GetModuleFileName(this_mod->hDllInstance,filename,sizeof(filename));
strcpy(currentDir, filename);
char *pend;
pend = strrchr(currentDir, '\\');
if (pend) {
*pend = '\000';
}
p = filename+lstrlen(filename);
while (p >= filename && *p != '\\') p--;
p++;
char logFile[1024] = "";
memset(logFile, '\000', sizeof(logFile));
char *p2 = strchr(p, '.');
if (p2) {
strncpy(logFile, p, p2-p);
}
else {
strcpy(logFile, p);
}
char tmpfile[MAX_PATH] = "";
sprintf(tmpfile, "%s\\.tmp", currentDir);
FILE *filep = fopen(tmpfile, "w");
if (filep == 0) {
char path[MAX_PATH] = "";
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
strcpy(currentDir, path);
}
else {
fclose(filep);
}
LoadConfigs(currentDir, logFile);
ghwnd_winamp = this_mod->hwndParent;
AfxWinInit( this_mod->hDllInstance, NULL, "", SW_HIDE);
mainWindow = new CMainWindow();
mainWindow->InitializeWindow();
strcpy(mainWindow->m_currentDir, currentDir);
mainWindow->Create((UINT)IDD_ALTACAST, AfxGetMainWnd());
int x = getLastX();
int y = getLastY();
if (x < 0) {
x = 0;
}
if (y < 0) {
y = 0;
}
mainWindow->SetWindowPos(NULL, (int)x, (int)y, -1, -1, SWP_NOSIZE | SWP_SHOWWINDOW);
mainWindow->SetIcon(mainApp.LoadIcon(IDR_MAINFRAME), TRUE);
mainWindow->ShowWindow(SW_SHOW);
initializealtacast();
timerId = SetTimer(NULL, 1, 1000, (TIMERPROC)getCurrentSongTitle);
return 0;
}
示例9: initialize_application
static void initialize_application(void)
{
#if defined(__WIN32__) && defined(__MINGW32__)
if (LoadLibrary("exchndl.dll")) option_debug = true;
#endif
// SDL_putenv(const_cast<char*>("SDL_VIDEO_ALLOW_SCREENSAVER=1"));
// Initialize SDL
int retval = SDL_Init(SDL_INIT_VIDEO |
(option_nosound ? 0 : SDL_INIT_AUDIO) |
(option_nojoystick ? 0 : SDL_INIT_JOYSTICK) |
(option_debug ? SDL_INIT_NOPARACHUTE : 0));
if (retval < 0)
{
const char *sdl_err = SDL_GetError();
if (sdl_err)
fprintf(stderr, "Couldn't initialize SDL (%s)\n", sdl_err);
else
fprintf(stderr, "Couldn't initialize SDL\n");
exit(1);
}
#if defined(HAVE_SDL_IMAGE)
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
#endif
// Find data directories, construct search path
InitDefaultStringSets();
#if defined(unix) || defined(__NetBSD__) || defined(__OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && !defined(HAVE_BUNDLE_NAME))
default_data_dir = PKGDATADIR;
const char *home = getenv("HOME");
if (home)
local_data_dir = home;
local_data_dir += ".alephone";
log_dir = local_data_dir;
#elif defined(__APPLE__) && defined(__MACH__)
bundle_data_dir = bundle_resource_path;
bundle_data_dir += "DataFiles";
data_search_path.push_back(bundle_data_dir);
#ifndef SCENARIO_IS_BUNDLED
{
char* buf = getcwd(0, 0);
default_data_dir = buf;
free(buf);
}
#endif
log_dir = app_log_directory;
preferences_dir = app_preferences_directory;
local_data_dir = app_support_directory;
#elif defined(__WIN32__)
char file_name[MAX_PATH];
GetModuleFileName(NULL, file_name, sizeof(file_name));
char *sep = strrchr(file_name, '\\');
*sep = '\0';
default_data_dir = file_name;
char login[17];
DWORD len = 17;
bool hasName = (GetUserName((LPSTR) login, &len) == TRUE);
if (!hasName || strpbrk(login, "\\/:*?\"<>|") != NULL)
strcpy(login, "Bob User");
DirectorySpecifier legacy_data_dir = file_name;
legacy_data_dir += "Prefs";
legacy_data_dir += login;
SHGetFolderPath(NULL,
CSIDL_PERSONAL | CSIDL_FLAG_CREATE,
NULL,
0,
file_name);
local_data_dir = file_name;
local_data_dir += "AlephOne";
log_dir = local_data_dir;
#else
default_data_dir = "";
local_data_dir = "";
//#error Data file paths must be set for this platform.
#endif
#if defined(__WIN32__)
#define LIST_SEP ';'
#else
#define LIST_SEP ':'
#endif
// in case we need to redo search path later:
size_t dsp_insert_pos = data_search_path.size();
//.........这里部分代码省略.........
示例10: load_vmd_library
static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin)
{
char pathname[GMX_PATH_MAX];
const char *pathenv;
const char *err;
int ret = 0;
char pathenv_buffer[GMX_PATH_MAX];
#ifndef GMX_NATIVE_WINDOWS
glob_t globbuf;
const char *defpath_suffix = "/plugins/*/molfile";
const char *defpathenv = GMX_VMD_PLUGIN_PATH;
#else
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
char progfolder[GMX_PATH_MAX];
char defpathenv[GMX_PATH_MAX];
const char *defpath_suffix = "\\plugins\\WIN32\\molfile";
SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, progfolder);
sprintf(defpathenv, "%s\\University of Illinois\\VMD\\plugins\\WIN32\\molfile", progfolder);
#endif
vmdplugin->api = NULL;
vmdplugin->filetype = strrchr(fn, '.');
if (!vmdplugin->filetype)
{
return 0;
}
vmdplugin->filetype++;
/* First look for an explicit path given at run time for the
* plugins, then an implicit run-time path, and finally for one
* given at configure time. This last might be hard-coded to the
* default for VMD installs. */
pathenv = getenv("VMD_PLUGIN_PATH");
if (pathenv == NULL)
{
pathenv = getenv("VMDDIR");
if (NULL == pathenv)
{
printf("\nNeither VMD_PLUGIN_PATH or VMDDIR set. ");
printf("Using default location:\n%s\n", defpathenv);
pathenv = defpathenv;
}
else
{
printf("\nVMD_PLUGIN_PATH no set, but VMDDIR is set. ");
#ifdef _MSC_VER
_snprintf_s(pathenv_buffer, sizeof(pathenv_buffer), _TRUNCATE, "%s%s", pathenv, defpath_suffix);
#else
snprintf(pathenv_buffer, sizeof(pathenv_buffer), "%s%s", pathenv, defpath_suffix);
#endif
printf("Using semi-default location:\n%s\n", pathenv_buffer);
pathenv = pathenv_buffer;
}
}
strncpy(pathname, pathenv, sizeof(pathname));
#ifndef GMX_NATIVE_WINDOWS
strcat(pathname, "/*.so");
glob(pathname, 0, NULL, &globbuf);
if (globbuf.gl_pathc == 0)
{
printf("\nNo VMD Plugins found\n"
"Set the environment variable VMD_PLUGIN_PATH to the molfile folder within the\n"
"VMD installation.\n"
"The architecture (e.g. 32bit versus 64bit) of GROMACS and VMD has to match.\n");
return 0;
}
for (size_t i = 0; i < globbuf.gl_pathc && vmdplugin->api == NULL; i++)
{
/* FIXME: Undefined which plugin is chosen if more than one plugin
can read a certain file ending. Requires some additional command
line option or enviroment variable to specify which plugin should
be picked.
*/
ret |= load_sharedlibrary_plugins(globbuf.gl_pathv[i], vmdplugin);
}
globfree(&globbuf);
#else
strcat(pathname, "\\*.so");
hFind = FindFirstFile(pathname, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
printf("\nNo VMD Plugins found\n");
return 0;
}
do
{
char filename[GMX_PATH_MAX];
sprintf(filename, "%s\\%s", pathenv, ffd.cFileName);
ret |= load_sharedlibrary_plugins(filename, vmdplugin);
}
while (FindNextFile(hFind, &ffd ) != 0 && vmdplugin->api == NULL);
FindClose(hFind);
#endif
if (!ret)
{
printf("\nCould not open any VMD library.\n");
err = vmddlerror();
if (!err)
//.........这里部分代码省略.........
示例11: GetSaveDumpName
bool GetSaveDumpName(DWORD dwProcessId, bool bFull, wchar_t* dmpfile, DWORD cchMaxDmpFile)
{
bool bRc = false;
HMODULE hCOMDLG32 = NULL;
typedef BOOL (WINAPI* GetSaveFileName_t)(LPOPENFILENAMEW lpofn);
GetSaveFileName_t _GetSaveFileName = NULL;
if (!gpSrv->DbgInfo.bDebugProcessTree)
{
if (!hCOMDLG32)
hCOMDLG32 = LoadLibraryW(L"COMDLG32.dll");
if (hCOMDLG32 && !_GetSaveFileName)
_GetSaveFileName = (GetSaveFileName_t)GetProcAddress(hCOMDLG32, "GetSaveFileNameW");
if (_GetSaveFileName)
{
OPENFILENAMEW ofn; memset(&ofn,0,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = L"Debug dumps (*.mdmp)\0*.mdmp;*.dmp\0Debug dumps (*.dmp)\0*.dmp;*.mdmp\0\0";
ofn.nFilterIndex = bFull ? 2 : 1;
ofn.lpstrFile = dmpfile;
ofn.nMaxFile = cchMaxDmpFile;
ofn.lpstrTitle = bFull ? L"Save debug full-dump" : L"Save debug mini-dump";
ofn.lpstrDefExt = bFull ? L"dmp" : L"mdmp";
ofn.Flags = OFN_ENABLESIZING|OFN_NOCHANGEDIR
| OFN_PATHMUSTEXIST|OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
if (_GetSaveFileName(&ofn))
{
bRc = true;
}
}
if (hCOMDLG32)
{
FreeLibrary(hCOMDLG32);
}
}
if (gpSrv->DbgInfo.bDebugProcessTree || !_GetSaveFileName)
{
HRESULT dwErr = SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0/*SHGFP_TYPE_CURRENT*/, dmpfile);
if (FAILED(dwErr))
{
memset(dmpfile, 0, cchMaxDmpFile*sizeof(*dmpfile));
if (GetTempPath(cchMaxDmpFile-32, dmpfile) && *dmpfile)
dwErr = S_OK;
}
if (FAILED(dwErr))
{
_printf("\nGetSaveDumpName called, get desktop folder failed, code=%u\n", (DWORD)dwErr);
}
else
{
if (*dmpfile && dmpfile[lstrlen(dmpfile)-1] != L'\\')
_wcscat_c(dmpfile, cchMaxDmpFile, L"\\");
_wcscat_c(dmpfile, cchMaxDmpFile, L"ConEmuTrap");
CreateDirectory(dmpfile, NULL);
INT_PTR nLen = lstrlen(dmpfile);
_wsprintf(dmpfile+nLen, SKIPLEN(cchMaxDmpFile-nLen) L"\\Trap-%02u%02u%02u%s-%u.%s",
MVV_1, MVV_2, MVV_3,_T(MVV_4a), dwProcessId,
bFull ? L"dmp" : L"mdmp");
bRc = true;
}
}
return bRc;
}
示例12: GetModuleHandle
bool MachineInstaller::ShouldSilentInstall()
{
// Figure out the package name from our own EXE name
wchar_t ourFile[MAX_PATH];
HMODULE hMod = GetModuleHandle(NULL);
GetModuleFileName(hMod, ourFile, _countof(ourFile));
CString fullPath = CString(ourFile);
CString pkgName = CString(ourFile + fullPath.ReverseFind(L'\\'));
pkgName.Replace(L".exe", L"");
wchar_t installFolder[MAX_PATH];
// C:\Users\Username\AppData\Local\$pkgName\packages
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, installFolder);
wcscat(installFolder, L"\\");
wcscat(installFolder, pkgName);
wcscat(installFolder, L"\\");
wcscat(installFolder, L"packages");
if (GetFileAttributes(installFolder) != INVALID_FILE_ATTRIBUTES) {
return false;
}
// C:\Users\Username\AppData\Local\$pkgName\.dead (was machine-installed but user uninstalled)
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, installFolder);
wcscat(installFolder, L"\\");
wcscat(installFolder, pkgName);
wcscat(installFolder, L"\\");
wcscat(installFolder, L".dead");
if (GetFileAttributes(installFolder) != INVALID_FILE_ATTRIBUTES) {
return false;
}
// C:\ProgramData\$pkgName\$username\packages
wchar_t username[512];
DWORD unamesize = _countof(username);
SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, installFolder);
GetUserName(username, &unamesize);
wcscat(installFolder, L"\\");
wcscat(installFolder, pkgName);
wcscat(installFolder, L"\\");
wcscat(installFolder, username);
wcscat(installFolder, L"\\");
wcscat(installFolder, L"packages");
if (GetFileAttributes(installFolder) != INVALID_FILE_ATTRIBUTES) {
return false;
}
// C:\ProgramData\$pkgName\$username\.dead
SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, installFolder);
wcscat(installFolder, L"\\");
wcscat(installFolder, pkgName);
wcscat(installFolder, L"\\");
wcscat(installFolder, username);
wcscat(installFolder, L"\\");
wcscat(installFolder, L".dead");
if (GetFileAttributes(installFolder) != INVALID_FILE_ATTRIBUTES) {
return false;
}
// None of these exist, we should install
return true;
}
示例13: RegOpenKeyEx
///
/// Determines where the BOINC data directory is.
///
void CBOINCGUIApp::DetectDataDirectory() {
#ifdef __WXMSW__
//
// Determine BOINCMgr Data Directory
//
LONG lReturnValue;
HKEY hkSetupHive;
LPTSTR lpszRegistryValue = NULL;
TCHAR szPath[MAX_PATH];
DWORD dwSize = 0;
// change the current directory to the boinc data directory if it exists
lReturnValue = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\Space Sciences Laboratory, U.C. Berkeley\\BOINC Setup"),
0,
KEY_READ,
&hkSetupHive
);
if (lReturnValue == ERROR_SUCCESS) {
// How large does our buffer need to be?
lReturnValue = RegQueryValueEx(
hkSetupHive,
_T("DATADIR"),
NULL,
NULL,
NULL,
&dwSize
);
if (lReturnValue != ERROR_FILE_NOT_FOUND) {
// Allocate the buffer space.
lpszRegistryValue = (LPTSTR) malloc(dwSize);
(*lpszRegistryValue) = NULL;
// Now get the data
lReturnValue = RegQueryValueEx(
hkSetupHive,
_T("DATADIR"),
NULL,
NULL,
(LPBYTE)lpszRegistryValue,
&dwSize
);
// Store the root directory for later use.
m_strBOINCMGRDataDirectory = lpszRegistryValue;
}
} else {
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, szPath))) {
_tcsncat(szPath, _T("\\boinc"), ((sizeof(szPath)/sizeof(TCHAR)) - _tcslen(szPath)));
if (wxDir::Exists(szPath)) {
// Store the root directory for later use.
m_strBOINCMGRDataDirectory = szPath;
}
}
}
// Cleanup
if (hkSetupHive) RegCloseKey(hkSetupHive);
if (lpszRegistryValue) free(lpszRegistryValue);
#endif
#ifdef __WXMAC__
m_strBOINCMGRDataDirectory = wxT("/Library/Application Support/BOINC Data");
#endif
}
示例14: CaptureThread
DWORD WINAPI CaptureThread(HANDLE hDllMainThread)
{
bool bSuccess = false;
//wait for dll initialization to finish before executing any initialization code
if(hDllMainThread)
{
WaitForSingleObject(hDllMainThread, INFINITE);
CloseHandle(hDllMainThread);
}
TCHAR lpLogPath[MAX_PATH];
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, lpLogPath);
wcscat_s(lpLogPath, MAX_PATH, TEXT("\\OBS\\pluginData\\captureHookLog.txt"));
dummyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(!logOutput.is_open())
logOutput.open(lpLogPath, ios_base::in | ios_base::out | ios_base::trunc, _SH_DENYNO);
wstringstream str;
str << OBS_KEEPALIVE_EVENT << UINT(GetCurrentProcessId());
strKeepAlive = str.str();
logOutput << CurrentDateTimeString() << "we're booting up: " << endl;
InitializeCriticalSection(&d3d9EndMutex);
InitializeCriticalSection(&glMutex);
DWORD procID = GetCurrentProcessId();
wstringstream strRestartEvent, strEndEvent, strReadyEvent, strExitEvent, strInfoMemory;
strRestartEvent << RESTART_CAPTURE_EVENT << procID;
strEndEvent << END_CAPTURE_EVENT << procID;
strReadyEvent << CAPTURE_READY_EVENT << procID;
strExitEvent << APP_EXIT_EVENT << procID;
strInfoMemory << INFO_MEMORY << procID;
hSignalRestart = GetEvent(strRestartEvent.str().c_str());
hSignalEnd = GetEvent(strEndEvent.str().c_str());
hSignalReady = GetEvent(strReadyEvent.str().c_str());
hSignalExit = GetEvent(strExitEvent.str().c_str());
DWORD bla;
HANDLE hWindowThread = CreateThread(NULL, 0, DummyWindowThread, NULL, 0, &bla);
if (!hWindowThread) {
logOutput << CurrentTimeString() << "CaptureThread: could not create window thread for some reason" << endl;
return 0;
}
CloseHandle(hWindowThread);
hInfoFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CaptureInfo), strInfoMemory.str().c_str());
if(!hInfoFileMap)
{
logOutput << CurrentTimeString() << "CaptureThread: could not info file mapping" << endl;
return 0;
}
infoMem = (CaptureInfo*)MapViewOfFile(hInfoFileMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(CaptureInfo));
if(!infoMem)
{
logOutput << CurrentTimeString() << "CaptureThread: could not map view of info shared memory" << endl;
CloseHandle(hInfoFileMap);
hInfoFileMap = NULL;
return 0;
}
hwndOBS = FindWindow(OBS_WINDOW_CLASS, NULL);
if(!hwndOBS)
{
logOutput << CurrentTimeString() << "CaptureThread: could not find main application window? wtf? seriously?" << endl;
return 0;
}
textureMutexes[0] = OpenMutex(MUTEX_ALL_ACCESS, FALSE, TEXTURE_MUTEX1);
if (textureMutexes[0]) {
textureMutexes[1] = OpenMutex(MUTEX_ALL_ACCESS, FALSE, TEXTURE_MUTEX2);
if (textureMutexes[1]) {
while(!AttemptToHookSomething())
Sleep(50);
logOutput << CurrentTimeString() << "(half life scientist) everything.. seems to be in order" << endl;
while (1) {
AttemptToHookSomething();
Sleep(4000);
}
CloseHandle(textureMutexes[1]);
textureMutexes[1] = NULL;
} else {
logOutput << CurrentTimeString() << "could not open texture mutex 2" << endl;
}
CloseHandle(textureMutexes[0]);
textureMutexes[0] = NULL;
} else {
logOutput << CurrentTimeString() << "could not open texture mutex 1" << endl;
}
//.........这里部分代码省略.........
示例15: defined
CL_String CL_Directory::get_appdata(const CL_StringRef &company_name, const CL_StringRef &application_name, const CL_StringRef &version, bool create_dirs_if_missing)
{
#if defined(WIN32)
TCHAR app_data[MAX_PATH];
if (FAILED(SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_DEFAULT, app_data)))
throw CL_Exception("SHGetFolderPath failed!");
CL_String configuration_path = cl_format("%1\\%2\\%3\\%4\\", app_data, company_name, application_name, version);
if (create_dirs_if_missing)
{
CL_String::size_type prevPos = 0;
while (true)
{
CL_String::size_type pos = configuration_path.find_first_of("\\/", prevPos);
if (pos == CL_String::npos)
break;
CL_StringRef folder = configuration_path.substr(0, pos);
CreateDirectory(CL_StringHelp::utf8_to_ucs2(folder).c_str(), 0);
prevPos = pos + 1;
}
}
return configuration_path;
#elif defined(__APPLE__)
throw CL_Exception("Congratulations, you got the task to implement CL_Directory::get_appdata on this platform.");
#else
const char *home_dir = getenv("HOME");
if (home_dir == NULL)
throw CL_Exception("Cannot object $HOME environment variable");
if (!create_dirs_if_missing)
{
return cl_format("%1/.%2/%3/%4/", home_dir, company_name, application_name, version);
}
struct stat stFileInfo;
CL_String name( cl_format("%1/.%2", home_dir, company_name) );
if (stat(name.c_str(), &stFileInfo))
{
if (::mkdir(name.c_str(), 0755))
throw CL_Exception(cl_format("Cannot create %1 directory", name));
}
name = cl_format("%1/%2", name, application_name);
if (stat(name.c_str(), &stFileInfo))
{
if (::mkdir(name.c_str(), 0755))
throw CL_Exception(cl_format("Cannot create %1 directory", name));
}
name = cl_format("%1/%2", name, version);
if (stat(name.c_str(), &stFileInfo))
{
if (::mkdir(name.c_str(), 0755))
throw CL_Exception(cl_format("Cannot create %1 directory", name));
}
name = cl_format("%1/", name);
return name;
#endif
}