-
-/*
- * Function: __hscore_renameFile()
- *
- * Provide Haskell98's semantics for renaming files and directories.
- * It mirrors that of POSIX.1's behaviour for rename() by overwriting
- * the target if it exists (the MS CRT implementation of rename() returns
- * an error
- *
- */
-HsInt
-__hscore_renameFile( HsAddr src,
- HsAddr dest)
-{
-#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
- static int forNT = -1;
-
- /* ToDo: propagate error codes back */
- if (MoveFileA(src, dest)) {
- return 0;
- } else {
- ;
- }
-
- /* Failed...it could be because the target already existed. */
- if ( !GetFileAttributes(dest) ) {
- /* No, it's not there - just fail. */
- errno = toErrno(GetLastError());
- return (-1);
- }
-
- if (forNT == -1) {
- OSVERSIONINFO ovi;
- ovi.dwOSVersionInfoSize = sizeof(ovi);
- if ( !GetVersionEx(&ovi) ) {
- errno = toErrno(GetLastError());
- return (-1);
- }
- forNT = ((ovi.dwPlatformId & VER_PLATFORM_WIN32_NT) != 0);
- }
-
- if (forNT) {
- /* Easy, go for MoveFileEx() */
- if ( MoveFileExA(src, dest, MOVEFILE_REPLACE_EXISTING) ) {
- return 0;
- } else {
- errno = toErrno(GetLastError());
- return (-1);
- }
- }
-
- /* No MoveFileEx() for Win9x, try deleting the target. */
- /* Similarly, if the MoveFile*() ops didn't work out under NT */
- if (DeleteFileA(dest)) {
- if (MoveFileA(src,dest)) {
- return 0;
- } else {
- errno = toErrno(GetLastError());
- return (-1);
- }
- } else {
- errno = toErrno(GetLastError());
- return (-1);
- }
-#else
- return rename(src,dest);
-#endif
-}
-
-/*
- * Function: __hscore_getFolderPath()
- *
- * Late-bound version of SHGetFolderPath(), coping with OS versions
- * that have shell32's lacking that particular API.
- *
- */
-#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
-typedef HRESULT (*HSCORE_GETAPPFOLDERFUNTY)(HWND,int,HANDLE,DWORD,char*);
-int
-__hscore_getFolderPath(HWND hwndOwner,
- int nFolder,
- HANDLE hToken,
- DWORD dwFlags,
- char* pszPath)
-{
- static int loaded_dll = 0;
- static HMODULE hMod = (HMODULE)NULL;
- static HSCORE_GETAPPFOLDERFUNTY funcPtr = NULL;
- /* The DLLs to try loading entry point from */
- char* dlls[] = { "shell32.dll", "shfolder.dll" };
-
- if (loaded_dll < 0) {
- return (-1);
- } else if (loaded_dll == 0) {
- int i;
- for(i=0;i < sizeof(dlls); i++) {
- hMod = LoadLibrary(dlls[i]);
- if ( hMod != NULL &&
- (funcPtr = (HSCORE_GETAPPFOLDERFUNTY)GetProcAddress(hMod, "SHGetFolderPathA")) ) {
- loaded_dll = 1;
- break;
- }
- }
- if (loaded_dll == 0) {
- loaded_dll = (-1);
- return (-1);
- }
- }
- /* OK, if we got this far the function has been bound */
- return (int)funcPtr(hwndOwner,nFolder,hToken,dwFlags,pszPath);
- /* ToDo: unload the DLL on shutdown? */
-}
-#endif