stringT pws_os::getuserprefsdir() { /** * Returns LOCAL_APPDATA\PasswordSafe (or ...\PasswordSafeD) * (Creating if necessary) * If can't figure out LOCAL_APPDATA, then return an empty string * to have Windows punt to exec dir, which is the historical behaviour */ #ifndef _DEBUG const stringT sPWSDir(_T("\\PasswordSafe\\")); #else const stringT sPWSDir(_T("\\PasswordSafeD\\")); #endif stringT sDrive, sDir, sName, sExt, retval; pws_os::splitpath(getexecdir(), sDrive, sDir, sName, sExt); sDrive += _T("\\"); // Trailing slash required. const UINT uiDT = ::GetDriveType(sDrive.c_str()); if (uiDT == DRIVE_FIXED || uiDT == DRIVE_REMOTE) { stringT sLocalAppDataPath; if (GetLocalDir(CSIDL_LOCAL_APPDATA, sLocalAppDataPath)) retval = sLocalAppDataPath + sPWSDir; if (PathFileExists(retval.c_str()) == FALSE) if (_tmkdir(retval.c_str()) != 0) retval = _T(""); // couldn't create dir!? } else if (uiDT == DRIVE_REMOVABLE) { stringT::size_type index = sDir.rfind(_T("Program\\")); if (index != stringT::npos) retval = getexecdir().substr(0, getexecdir().length() - 8); } return retval; }
stringT pws_os::getsafedir(void) { stringT sDrive, sDir, sName, sExt, retval; pws_os::splitpath(getexecdir(), sDrive, sDir, sName, sExt); const stringT sDriveT = sDrive + _T("\\"); // Trailing slash required. const UINT uiDT = ::GetDriveType(sDriveT.c_str()); if (uiDT == DRIVE_REMOVABLE) { stringT::size_type index = sDir.rfind(_T("Program\\")); if (index != stringT::npos) { sDir.replace(index, 8, stringT(_T("Safes\\"))); retval = sDrive + sDir; if (PathFileExists(retval.c_str()) == TRUE) return retval; } } stringT sLocalSafePath; if (GetLocalDir(CSIDL_PERSONAL, sLocalSafePath)) { retval = sLocalSafePath + _T("\\My Safes"); if (PathFileExists(retval.c_str()) == FALSE) if (_tmkdir(retval.c_str()) != 0) retval = _T(""); // couldn't create dir!? } return retval; }
stringT pws_os::getxmldir(void) { stringT sDrive, sDir, sName, sExt; pws_os::splitpath(getexecdir(), sDrive, sDir, sName, sExt); const stringT sDriveT = sDrive + _T("\\"); // Trailing slash required. const UINT uiDT = ::GetDriveType(sDriveT.c_str()); if (uiDT == DRIVE_REMOVABLE) { stringT::size_type index = sDir.rfind(_T("Program\\")); if (index != stringT::npos) { sDir.replace(index, 8, stringT(_T("xml\\"))); stringT retval = sDrive + sDir; if (PathFileExists(retval.c_str()) == TRUE) return retval; } } return getexecdir(); }
int main (int argc, char **argv) { char prog_name[MAX_PATH]; char exec_dir[MAX_PATH]; char exec_parent[MAX_PATH]; fprintf(stderr, "Argv0: %s\n", argv[0]); fprintf(stderr, "Prog: %s\n", getprogname(prog_name)); fprintf(stderr, "Progdir: %s\n", getexecdir(exec_dir)); fprintf(stderr, "Prog_parent: %s\n", getexecparent(exec_parent)); }
stringT pws_os::gethelpdir(void) { return getexecdir(); }