CStdString SystemFolderInfo::GetCommonAppDataPath() { CStdString sPath; switch (GetWindowsVersion()) { case WINDOWS_95: case WINDOWS_ME: case WINDOWS_98: sPath = GetWindowsPath() + _T("\\All Users\\Application Data"); break; case WINDOWS_NT: sPath = GetFolderPath(CSIDL_COMMON_APPDATA, NULL); // For some reason - if the user has restricted access to the folder // this will return an empty string - but we know we can // access it and it should exist! if (sPath.IsEmpty()) sPath = GetProfilesRoot() + _T("\\All Users\\Application Data"); break; case WINDOWS_2K: case WINDOWS_XP: case WINDOWS_2003SERVER: default: sPath = GetFolderPath(CSIDL_COMMON_APPDATA, NULL); break; } ValidatePath(sPath, CSIDL_COMMON_APPDATA); return sPath; }
static void GetDirectories() { WinScopedPreserveLastError s; // system directory { const UINT length = GetSystemDirectoryW(0, 0); ENSURE(length != 0); std::wstring path(length, '\0'); const UINT charsWritten = GetSystemDirectoryW(&path[0], length); ENSURE(charsWritten == length-1); systemPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path); } // executable's directory executablePath = new(wutil_Allocate(sizeof(OsPath))) OsPath(sys_ExecutablePathname().Parent()); // roaming application data roamingAppdataPath = GetFolderPath(CSIDL_APPDATA); // local application data localAppdataPath = GetFolderPath(CSIDL_LOCAL_APPDATA); // my documents personalPath = GetFolderPath(CSIDL_PERSONAL); }
CStdString SystemFolderInfo::GetSystemX86Path() { if (CGeneral::Is64BitProcess()) { CStdString result = GetFolderPath(CSIDL_SYSTEMX86, NULL); if (CGeneral::Is64BitOS() && result.find(L"system32") != -1) result.Replace(L"system32", L"SysWOW64"); return result; } return GetFolderPath(CSIDL_SYSTEM, NULL); }
void CDirDialog::OnFolderChange() { CWnd *pp; // Parent window = the dialog itself VERIFY(pp = GetParent()); ASSERT(::IsWindow(pp->m_hWnd)); ASSERT(pp->GetDlgItem(IDC_DIR) != NULL); m_strPath = GetFolderPath(); int len = m_strPath.GetLength(); if (len > 0 && m_strPath[len-1] != '\\') { m_strPath += "\\"; ++len; } pp->GetDlgItem(IDC_DIR)->SetWindowText(m_strPath); if (m_first_time) { // Initially select whole name so user can remove by just typing m_Edit.SetSel(0, -1); m_first_time = FALSE; } else m_Edit.SetSel(len, len); // Move caret to end of name CFileDialog::OnFolderChange(); m_Edit.SetFocus(); }
int GetTempFileName(wchar_t *path,unsigned int pathsize) { int iReturnCode = RETURN_OK; //Get the temp folder TCHAR wzTempPath[MAX_PATH]; if(RETURN_OK != (iReturnCode=GetFolderPath(FOLDER_TEMP, wzTempPath, MAX_PATH))) { iReturnCode = RETURN_ERR_INTERNAL; } else { if(pathsize<wcslen(wzTempPath)+14) { LOG(L" --> ERROR - GetTempFileName - Buffer too small\n"); iReturnCode = RETURN_ERR_INTERNAL; } // Create a temporary file. if (0 == ::GetTempFileName(wzTempPath,L"",0,path)) { LOG(L" --> ERROR - GetTempFileName failed (LastError=%d)\n", GetLastError()); iReturnCode = RETURN_ERR_INTERNAL; } } return iReturnCode; }
CStdString SystemFolderInfo::GetLocalUserAppDataPath() { CStdString sPath; switch (GetWindowsVersion()) { case WINDOWS_95: case WINDOWS_ME: case WINDOWS_98: { if (HasWin98UserGotProfile()) sPath = GetProfilePath() + _T("\\Application Data"); else sPath = GetWindowsPath() + _T("\\Local Settings\\Application Data"); } break; case WINDOWS_NT: case WINDOWS_2K: case WINDOWS_XP: case WINDOWS_2003SERVER: default: sPath = GetFolderPath(CSIDL_APPDATA, NULL); break; } ValidatePath(sPath, CSIDL_APPDATA); return sPath; }
CStdString SystemFolderInfo::GetCommonStartMenu() { CStdString sPath; switch (GetWindowsVersion()) { case WINDOWS_95: case WINDOWS_ME: case WINDOWS_98: { if (HasWin98UserGotProfile()) sPath = GetProfilePath(); else sPath = GetWindowsPath(); sPath += _T("\\Local Settings\\Start Menu"); } break; case WINDOWS_NT: case WINDOWS_2K: case WINDOWS_XP: case WINDOWS_2003SERVER: default: sPath = GetFolderPath(CSIDL_COMMON_STARTMENU, NULL); break; } ValidatePath(sPath, CSIDL_COMMON_STARTMENU); return sPath; }
BOOL CFileSaveAsGraphicDlg::OnFileNameOK () { UpdateData(TRUE); ASSERT (m_ofn.nFilterIndex > 0); m_nGraphicIndex = m_ofn.nFilterIndex; CString strFolder = GetFolderPath(); CString strFile = GetFileName(); CString strExt = GetFileExt(); if (strFolder.GetLength() + strFile.GetLength() + strExt.GetLength() >= (_MAX_PATH - 10)) { AfxMessageBox(IDS_PATH_TOO_LONG); CEdit* pEdit = (CEdit*)GetParent()->GetDlgItem(edt1); if (pEdit) { pEdit->SetFocus(); pEdit->SetSel(0, -1); } return TRUE; } return FALSE; }
void ReadProject(std::string const & filePath, std::function<void(std::string const & filePath, std::string && fileContent)> fn) { std::queue<std::string> q; q.push(filePath); while (!q.empty()) { std::string file = move(q.front()); q.pop(); std::string folder = GetFolderPath(file); std::ostringstream content; ForEachLine(file, [&](std::string & s) { std::string import_file; if (mapcss::IsImportDirective(s, import_file)) { import_file = folder + import_file; q.push(std::move(import_file)); } content << s << std::endl; }); fn(file, content.str()); } }
CStdString SystemFolderInfo::GetDefaultUserAppDataPath() { CStdString sPath; switch (GetWindowsVersion()) { case WINDOWS_95: case WINDOWS_ME: case WINDOWS_98: sPath = GetWindowsPath() + _T("\\Application Data"); break; case WINDOWS_NT: { sPath = GetLocalUserAppDataPath(); int nPos = sPath.Find(_T("\\"), GetProfilesRoot().size()+1); sPath = GetProfilesRoot() + _T("\\Default User\\") + sPath.Right(sPath.size() - nPos - 1); } break; case WINDOWS_2K: case WINDOWS_XP: case WINDOWS_2003SERVER: default: sPath = GetFolderPath(CSIDL_APPDATA, (HANDLE)-1); break; } ValidatePath(sPath, CSIDL_APPDATA); return sPath; }
CString CGetEnvPath::GetRealPath(LPCTSTR pszEnvPath) { CString strResult; if (pszEnvPath == NULL) { strResult = _T(""); goto Exit0; } int nFirstPos = 0; int nSecondPos = 0; BOOL bFind = FALSE; strResult = pszEnvPath; bFind = FindEnvironmentPos(strResult, nFirstPos, nSecondPos); if (bFind == TRUE) { CString strLeft ; CString strRight ; CString strEnvName ; CString strEnvVariable; strLeft = strResult.Left(nFirstPos); strRight = strResult.Mid (nSecondPos + 1); strEnvName = strResult.Mid(nFirstPos + 1, nSecondPos - nFirstPos - 1); strEnvVariable = GetEnvVariable(strEnvName); if (strEnvVariable.GetLength() <= 0) strEnvVariable = GetFolderPath( strEnvName ); if(strEnvVariable.Find(_T(';')) == -1) strResult = CombinationPath(strLeft, strEnvVariable, strRight); else { //SplitString() std::vector<CString> strvec; SplitString(strEnvVariable,_T(';'), strvec); strResult = _T(""); for(std::vector<CString>::iterator it = strvec.begin();it != strvec.end(); it++) { strResult += CombinationPath(strLeft, (*it), strRight); strResult += _T(";"); } } bFind = FindEnvironmentPos(strResult, nFirstPos, nSecondPos); } Exit0: return strResult; }
/*--------------------------------------------------------------------------------------------- Name : GetPath(BOOL bOriginal = FALSE) Purpose : Return the path contained in the object Parameters : BOOL bOriginal - If bOriginal is TRUE, the same string that was passed to SetPath or the constructor is returned. Return : CString - Path Object Globals Modified : None. --------------------------------------------------------------------------------------------*/ CString CPath::GetPath(BOOL /*bAppendArgs*/, BOOL bOriginal) { CString sPath; if (bOriginal) sPath = _strOriginalPath; else sPath = GetFolderPath() + GetFileName(); return sPath; }
/*--------------------------------------------------------------------------------------------- Name : ExistLocation(void) Purpose : Return TRUE if the location exists Parameters : None. Return : Return TRUE if the location exists Globals Modified : None. --------------------------------------------------------------------------------------------*/ BOOL CPath::ExistLocation() { if((_taccess(GetFolderPath(), 0)) == -1) { return(FALSE); } else { return(TRUE); } }
std::string GetFolderPath(SPECIAL_FOLDER folder) { switch (folder) { // We currently store everything under Documents/OpenRCT2 case SPECIAL_FOLDER::USER_CACHE: case SPECIAL_FOLDER::USER_CONFIG: case SPECIAL_FOLDER::USER_DATA: { # ifdef __USE_SHGETKNOWNFOLDERPATH__ auto path = WIN32_GetKnownFolderPath(FOLDERID_Documents); # else auto path = WIN32_GetFolderPath(CSIDL_PERSONAL); # endif if (path.empty()) { path = GetFolderPath(SPECIAL_FOLDER::USER_HOME); } return path; } case SPECIAL_FOLDER::USER_HOME: { # ifdef __USE_SHGETKNOWNFOLDERPATH__ auto path = WIN32_GetKnownFolderPath(FOLDERID_Profile); # else auto path = WIN32_GetFolderPath(CSIDL_PROFILE); # endif if (path.empty()) { path = GetHomePathViaEnvironment(); if (path.empty()) { path = "C:\\"; } } return path; } case SPECIAL_FOLDER::RCT2_DISCORD: { # ifdef __USE_SHGETKNOWNFOLDERPATH__ auto path = WIN32_GetKnownFolderPath(FOLDERID_LocalAppData); # else auto path = WIN32_GetFolderPath(CSIDL_LOCAL_APPDATA); # endif if (!path.empty()) { path = Path::Combine(path, "DiscordGames\\RollerCoaster Tycoon 2 Triple Thrill Pack\\content\\Game"); } return path; } default: return std::string(); } }
void MessageChangeListener::messageChanged (vmime::shared_ptr<vmime::net::events::messageChangedEvent> event) { if (!IsEnabled_) return; const auto& folder = event->getFolder (); QList<int> numsList; for (const auto num : event->getNumbers ()) numsList << num; emit messagesChanged (GetFolderPath (folder), numsList); }
int DeleteFile(FolderType folder, const wchar_t *file) { int nReturnCode = RETURN_OK; LOG(L"Ask for deleting file \"%s\"\n",file); TCHAR wzPath[MAX_PATH]; if(RETURN_OK == (nReturnCode=GetFolderPath(folder, wzPath,MAX_PATH))) { TCHAR wzFile[MAX_PATH]; if(-1==swprintf_s(wzFile,MAX_PATH,L"%s\\%s",wzPath,file)) { LOG(L" --> ERROR - Buffer too small\n"); nReturnCode = RETURN_ERR_INTERNAL; } else { if(::DeleteFile(wzFile)) { LOG(L" --> DELETED\n"); } else { DWORD err = GetLastError(); if(err==ERROR_FILE_NOT_FOUND || err==ERROR_PATH_NOT_FOUND) { LOG(L" --> NOT FOUND\n"); } else { LOG(L" --> ERROR - DeleteFile (return=%ld)\n",err); nReturnCode = RETURN_ERR_DELETEFILE_FAILED; } } } LOG(L"\n"); if(nReturnCode == RETURN_OK) nReturnCode = RemoveRegistryValue(HKEY_LOCAL_MACHINE,L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SharedDlls",wzFile); } else { if (nReturnCode == RETURN_SKIP_FOLDER) nReturnCode = RETURN_OK; else LOG(L"\n"); } return nReturnCode; }
std::vector<std::wstring> SkinRegistry::ValidateFavorites() { // Files should be marked correctly at this point, Folders are not int16_t count = 0; int16_t foundOnLevel = 0; std::vector<std::wstring> newFavorites; std::wstring favorite; Indexes indexes; auto& folder = m_Folders.rbegin(); for (; folder != m_Folders.rend(); ++folder) { (*folder).hasFavorite = false; auto& file = (*folder).files.rbegin(); for (; file != (*folder).files.rend(); ++file) { if ((*file).isFavorite) { ++count; foundOnLevel = (*folder).level; (*folder).hasFavorite = true; // to mark current folder indexes = FindIndexesForID((*folder).baseID); favorite = GetFolderPath(indexes.folder); favorite += L'\\'; favorite += (*file).filename; newFavorites.emplace(newFavorites.begin(), favorite); } } if (foundOnLevel > (*folder).level && count > 0) { (*folder).hasFavorite = true; --foundOnLevel; } if ((*folder).level == 1) { count = 0; foundOnLevel = 0; } } return newFavorites; }
Ptr<DocumentModel> DocumentModel_Constructor(const WString& path) { FileStream fileStream(path, FileStream::ReadOnly); if(!fileStream.IsAvailable()) return 0; BomDecoder decoder; DecoderStream decoderStream(fileStream, decoder); StreamReader reader(decoderStream); WString xmlText=reader.ReadToEnd(); Ptr<ParsingTable> table=XmlLoadTable(); Ptr<XmlDocument> xml=XmlParseDocument(xmlText, table); if(!xml) return 0; List<WString> errors; return DocumentModel::LoadFromXml(xml, GetFolderPath(path), errors); }
void CDirDialog::OnFolderChange() { CWnd *pp; // Parent window = the dialog itself VERIFY(pp = GetParent()); ASSERT(::IsWindow(pp->m_hWnd)); ASSERT(pp->GetDlgItem(IDC_DIR) != NULL); m_strPath = GetFolderPath(); int len = m_strPath.GetLength(); if (len > 0 && m_strPath[len-1] != '\\') { m_strPath += "\\"; ++len; } pp->GetDlgItem(IDC_DIR)->SetWindowText(m_strPath); m_Edit.SetSel(len, len); CFileDialog::OnFolderChange(); m_Edit.SetFocus(); }
/// <summary> /// Attempts to paste the contents of the clipboard to the desktop /// </summary> void TileGroup::DoPaste() { if (IsClipboardFormatAvailable(CF_HDROP)) { if (OpenClipboard(mWindow->GetWindowHandle())) { LPDROPFILES data = LPDROPFILES(GetClipboardData(CF_HDROP)); bool move = false; WCHAR target[MAX_PATH]; // Check if the file should be moved rather than copied. UINT cfDropEffect = RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT); if (IsClipboardFormatAvailable(cfDropEffect)) { move = (*(DWORD*)GetClipboardData(cfDropEffect) & DROPEFFECT_MOVE) == DROPEFFECT_MOVE; } GetFolderPath(target, _countof(target)); // TODO::Handle data->fWide == 0 SHFILEOPSTRUCTW shFileOp; ZeroMemory(&shFileOp, sizeof(shFileOp)); shFileOp.wFunc = move ? FO_MOVE : FO_COPY; shFileOp.hwnd = mWindow->GetWindowHandle(); shFileOp.pFrom = LPCWSTR((BYTE*)data + data->pFiles); shFileOp.pTo = target; shFileOp.fFlags = FOF_NOCONFIRMMKDIR; SHFileOperationW(&shFileOp); if (move && !shFileOp.fAnyOperationsAborted) { EmptyClipboard(); } CloseClipboard(); } } else if (IsClipboardFormatAvailable(CF_TEXT)) { } else if (IsClipboardFormatAvailable(CF_BITMAP)) { } else if (IsClipboardFormatAvailable(CF_WAVE)) { } }
std::string GetFolderPath(SPECIAL_FOLDER folder) { switch (folder) { case SPECIAL_FOLDER::USER_CACHE: case SPECIAL_FOLDER::USER_CONFIG: case SPECIAL_FOLDER::USER_DATA: { auto path = GetEnvironmentPath("XDG_CONFIG_HOME"); if (path.empty()) { auto home = GetFolderPath(SPECIAL_FOLDER::USER_HOME); path = Path::Combine(home, ".config"); } return path; } case SPECIAL_FOLDER::USER_HOME: return GetHomePath(); default: return std::string(); } }
CStdString SystemFolderInfo::GetProfilePath() { CStdString sPath; switch (GetWindowsVersion()) { case WINDOWS_95: case WINDOWS_ME: case WINDOWS_98: { if (HasWin98UserGotProfile()) { sPath = GetProfilesRoot() + _T("\\") + GetLoggedOnUser(); } else { sPath = GetProfilesRoot() + _T("\\All Users"); } } break; case WINDOWS_NT: sPath = GetProfilesRoot() + _T("\\") + GetLoggedOnUser(); break; case WINDOWS_2K: case WINDOWS_XP: case WINDOWS_2003SERVER: default: sPath = GetFolderPath(CSIDL_PROFILE, NULL); break; } ValidatePath(sPath, CSIDL_PROFILE); return sPath; }
CStdString SystemFolderInfo::GetWindowsPath() { switch (GetWindowsVersion()) { case WINDOWS_2K: case WINDOWS_XP: case WINDOWS_2003SERVER: case WINDOWS_VISTA_CLIENT: default: return GetFolderPath( CSIDL_WINDOWS, NULL ); case WINDOWS_95: case WINDOWS_ME: case WINDOWS_98: case WINDOWS_NT: { TCHAR szDir[_MAX_PATH] = {0}; GetWindowsDirectory(szDir, _MAX_PATH); return szDir; } } return _T(""); }
void TestStackFunctions::TestGetFolderPathWithBlankFileName() { TCHAR szFileName[] = _T(""); assertStringsEqual(_T(""), GetFolderPath(szFileName)); }
CStdString SystemFolderInfo::GetMyPoliciesPath() { CStdString sMyDocuments = GetFolderPath(CSIDL_PERSONAL, NULL); return sMyDocuments += _T("\\My Policies"); }
CStdString SystemFolderInfo::GetSendToPath() { return GetFolderPath(CSIDL_SENDTO, NULL); }
CStdString SystemFolderInfo::GetProgramFilesPath() { return GetFolderPath(CSIDL_PROGRAM_FILES, NULL); }
CStdString SystemFolderInfo::GetCommonPath() { return GetFolderPath(CSIDL_COMMON_DOCUMENTS, NULL); }
CStdString SystemFolderInfo::GetPersonalPath() { return GetFolderPath(CSIDL_PERSONAL, NULL); }
void TestStackFunctions::TestGetFolderPathWithDriveOnly() { TCHAR szFileName[] = _T("c:"); assertStringsEqual(_T("c:"), GetFolderPath(szFileName)); }