static WatchedFile* NewWatchedFile(const WCHAR* filePath, const std::function<void()>& onFileChangedCb) { bool isManualCheck = PathIsNetworkPath(filePath); AutoFreeW dirPath(path::GetDir(filePath)); WatchedDir* wd = nullptr; bool newDir = false; if (!isManualCheck) { wd = FindExistingWatchedDir(dirPath); if (!wd) { wd = NewWatchedDir(dirPath); if (!wd) return nullptr; newDir = true; } } WatchedFile* wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->onFileChangedCb = onFileChangedCb; wf->watchedDir = wd; wf->isManualCheck = isManualCheck; ListInsert(&g_watchedFiles, wf); if (wf->isManualCheck) { GetFileState(filePath, &wf->fileState); AwakeWatcherThread(); } else { if (newDir) StartMonitoringDirForChanges(wf->watchedDir); } return wf; }
static WatchedFile *NewWatchedFile(const WCHAR *filePath, FileChangeObserver *observer) { bool isManualCheck = PathIsNetworkPath(filePath); ScopedMem<WCHAR> dirPath(path::GetDir(filePath)); WatchedDir *wd = nullptr; bool newDir = false; if (!isManualCheck) { wd = FindExistingWatchedDir(dirPath); if (!wd) { wd = NewWatchedDir(dirPath); if (!wd) return nullptr; newDir = true; } } WatchedFile *wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->observer = observer; wf->watchedDir = wd; wf->isManualCheck = isManualCheck; ListInsert(&g_watchedFiles, wf); if (wf->isManualCheck) { GetFileState(filePath, &wf->fileState); AwakeWatcherThread(); } else { if (newDir) StartMonitoringDirForChanges(wf->watchedDir); } return wf; }
void CFileSystemMonitor::InitMonitor() { _scraper_directory_on_a_network_drive = false; // http://msdn.microsoft.com/de-de/library/windows/desktop/bb773640%28v=vs.85%29.aspx if (PathIsNetworkPath(absolute_path_to_scraper_directory)) { // Network mapped drives are unsupported // and can lead to crashes. // http://www.maxinmontreal.com/forums/viewtopic.php?f=114&t=17677&p=122925#p122925 write_log(Preferences()->debug_filesystem_monitor(), "[CFileSystemMonitor] Unsupported network mapped drive\n"); _scraper_directory_on_a_network_drive = true; return; } int changes_to_monitor = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE; // Since OpenHoldem 13.0 we support a nested scraper-directory, // even with some "official" maps for real-world-casinos. const bool watch_subtree = TRUE; dwChangeHandle = FindFirstChangeNotification( absolute_path_to_scraper_directory, watch_subtree, changes_to_monitor); if ((dwChangeHandle == INVALID_HANDLE_VALUE) || (dwChangeHandle == NULL)) { write_log(Preferences()->debug_filesystem_monitor(), "[CFileSystemMonitor] InitMonitor() failed.\n"); write_log(Preferences()->debug_filesystem_monitor(), "[CFileSystemMonitor] Going to terminate...\n"); ExitProcess(GetLastError()); } }
BOOL CFileIterator::IsNetworkPath() { // return FALSE if nothing found if (!m_bFoundFile) return FALSE; CString strPath = GetPath(); return PathIsNetworkPath(strPath); }
bool IsOnFixedDrive(const WCHAR *path) { if (PathIsNetworkPath(path)) return false; UINT type; WCHAR root[MAX_PATH]; if (GetVolumePathName(path, root, dimof(root))) type = GetDriveType(root); else type = GetDriveType(path); return DRIVE_FIXED == type; }
BOOL CMakerSetupResultPage::_IsFilterFile(LPCTSTR pszFilePath) { BOOL bRet = FALSE; if (!bRet) { bRet = PathIsRoot(pszFilePath); } if (!bRet) { bRet = PathIsNetworkPath(pszFilePath); } if (!bRet) { bRet = PathIsTempPath(pszFilePath); } return bRet; }
DWORD NetWorkOpenConnect(LPCTSTR networkPath) { if (!PathIsNetworkPath(networkPath)) return 0; LPTSTR path = new TCHAR[lstrlen(networkPath)+1]; lstrcpy(path, networkPath); NETRESOURCE nr; ZeroMemory(&nr, sizeof(nr)); nr.dwType = RESOURCETYPE_ANY; nr.dwScope = RESOURCE_GLOBALNET; nr.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC; nr.dwUsage = RESOURCEUSAGE_CONNECTABLE; nr.lpRemoteName = path; DWORD dwRet = ::WNetAddConnection2(&nr, NULL, NULL, 0); delete []path; return dwRet; }
/** Iterate to next file object * * @returns TRUE if a next file was found, otherwise FALSE */ BOOL CFileIterator::Next(void) { // just return if there's no more files or we weren't successfully initialized if (m_bNoMoreFiles) { m_bFoundFile = FALSE; return FALSE; } BOOL bFound = FALSE; BOOL bMoreFiles; do { bMoreFiles = (0 != m_ff.FindNextFile()); if (m_ff.IsDots()) continue; // if we know this isn't a shortcut, or we're not following shortcuts, then // see if we have a filespec match if (!m_bFollowShortcuts || m_ff.IsDirectory() || !PathMatchSpec(m_ff.GetFileName(), _T("*.lnk")) ) { if (m_bFollowNetworkPaths || !PathIsNetworkPath(m_ff.GetFilePath())) { if (PathMatchSpec(m_ff.GetFileName(), m_strFilespec)) { bFound = TRUE; m_bIsShortcut = FALSE; } } } else { // this may be shortcut. Try following it... WIN32_FIND_DATA fd; CString strTargetPath; if (SUCCEEDED(GetShortcutInfo(m_ff.GetFilePath(), strTargetPath.GetBuffer(MAX_SHORTCUT_PATH), MAX_SHORTCUT_PATH, &fd))) { // this is a shortcut. If we're ignoring shortcuts to remote // files/folders, then verify it's not a network path. if (m_bFollowNetworkPaths || !PathIsNetworkPath(strTargetPath)) { // okay, try to match the filespec to it if (PathMatchSpec(fd.cFileName, m_strFilespec)) { bFound = TRUE; m_bIsShortcut = TRUE; m_strPath = strTargetPath; m_sFd = fd; } } } m_strPath.ReleaseBuffer(); } } while (bFound == FALSE && bMoreFiles == TRUE); m_bFoundFile = bFound; m_bNoMoreFiles = !bMoreFiles; return bFound; }
HANDLE WINAPI Bio_CreateFileW( LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile ) { if((dwDesiredAccess == (GENERIC_WRITE | GENERIC_READ)) || (dwDesiredAccess == GENERIC_WRITE)){ char tDestPath[1024]; memset(tDestPath, 0, sizeof(tDestPath)); wsprintfA(tDestPath, "%S", lpFileName); if(0 == dwShareMode){ return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } if((dwFlagsAndAttributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY){ return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } if((dwFlagsAndAttributes & FILE_ATTRIBUTE_COMPRESSED) == FILE_ATTRIBUTE_COMPRESSED){ return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } if((dwFlagsAndAttributes & FILE_FLAG_DELETE_ON_CLOSE) == FILE_FLAG_DELETE_ON_CLOSE){ return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } string stDp(tDestPath); if(PathIsNetworkPath(tDestPath) || PathIsUNC(tDestPath) || PathIsRelative(tDestPath) || string::npos != stDp.find(".zip")){ return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } string sWcPath; string sDestPath(tDestPath); int pos = sDestPath.find(":\\"); if(1 == pos && (CREATE_ALWAYS == dwCreationDisposition || OPEN_ALWAYS == dwCreationDisposition) && IsWorkCopy(tDestPath, sWcPath)){ if(PathFileExists(tDestPath) && (GetFileAttributes(tDestPath) != FILE_ATTRIBUTE_DIRECTORY)){ if(IsReadOnly(tDestPath)){ CopyCreateFileW(NULL, dwDesiredAccess,dwShareMode, lpSecurityAttributes,dwCreationDisposition, dwFlagsAndAttributes,hTemplateFile); return INVALID_HANDLE_VALUE; } } } } return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); }
DWORD NetWorkCloseConnection(LPCTSTR path) { if (!PathIsNetworkPath(path)) return 0; return WNetCancelConnection2(path, CONNECT_UPDATE_PROFILE, FALSE); }