paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/physfs/platform win32.c,1.1.1.1.6.1,1.1.1


From: Alexander Pipelka <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/physfs/platform win32.c,1.1.1.1.6.1,1.1.1.1.6.2
Date: Wed, 29 May 2002 11:34:12 -0400

Update of /cvsroot/paragui/paragui/src/physfs/platform
In directory subversions:/tmp/cvs-serv24542/src/physfs/platform

Modified Files:
      Tag: devel-1-0
        win32.c 
Log Message:
adapted VC++ workspace
fixed PhysFS for Win32 (Ryan messed this up really badly)
compilation fixes



Index: win32.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/win32.c,v
retrieving revision 1.1.1.1.6.1
retrieving revision 1.1.1.1.6.2
diff -C2 -r1.1.1.1.6.1 -r1.1.1.1.6.2
*** win32.c     3 May 2002 10:15:33 -0000       1.1.1.1.6.1
--- win32.c     29 May 2002 15:34:09 -0000      1.1.1.1.6.2
***************
*** 1,12 ****
  /*
!  * Win32 support routines for PhysicsFS.
   *
   * Please see the file LICENSE in the source's root directory.
   *
!  *  This file written by Ryan C. Gordon, and made sane by Gregory S. Read.
   */
  
  #include <windows.h>
! #include <userenv.h>
  #include <stdio.h>
  #include <stdlib.h>
--- 1,12 ----
  /*
!  * Skeleton platform-dependent support routines for PhysicsFS.
   *
   * Please see the file LICENSE in the source's root directory.
   *
!  *  This file written by Ryan C. Gordon.
   */
  
  #include <windows.h>
! #include <lm.h>
  #include <stdio.h>
  #include <stdlib.h>
***************
*** 16,32 ****
  #include "physfs_internal.h"
  
- #define LOWORDER_UINT64(pos)       (PHYSFS_uint32)(pos & 0x00000000FFFFFFFF)
- #define HIGHORDER_UINT64(pos)      (PHYSFS_uint32)(pos & 0xFFFFFFFF00000000)
  
  const char *__PHYSFS_platformDirSeparator = "\\";
  
! static HANDLE ProcessHandle = NULL;     /* Current process handle */
! static HANDLE AccessTokenHandle = NULL; /* Security handle to process */
! static DWORD ProcessID;                 /* ID assigned to current process */
! static int runningNT;                   /* TRUE if NT derived OS */
! static OSVERSIONINFO OSVersionInfo;     /* Information about the OS */
! 
! /* NT specific information */
! static char *ProfileDirectory = NULL;   /* User profile folder */
  
  static const char *win32strerror(void)
--- 16,25 ----
  #include "physfs_internal.h"
  
  
  const char *__PHYSFS_platformDirSeparator = "\\";
  
! #define LOWORDER_UINT64(pos)       (PHYSFS_uint32)(pos & 0x00000000FFFFFFFF)
! #define HIGHORDER_UINT64(pos)      (PHYSFS_uint32)(pos & 0xFFFFFFFF00000000)
! #define INVALID_SET_FILE_POINTER      ((DWORD)-1)
  
  static const char *win32strerror(void)
***************
*** 49,52 ****
--- 42,57 ----
  
  
+ int __PHYSFS_platformInit(void)
+ {
+     return(1);  /* always succeed. */
+ } /* __PHYSFS_platformInit */
+ 
+ 
+ int __PHYSFS_platformDeinit(void)
+ {
+     return(1);  /* always succeed. */
+ } /* __PHYSFS_platformDeinit */
+ 
+ 
  char **__PHYSFS_platformDetectAvailableCDs(void)
  {
***************
*** 59,65 ****
          if (GetDriveType(drive_str) == DRIVE_CDROM)
          {
- 
-             /* !!! FIXME: Make sure there's really a disc in the drive? */
- 
              char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
              if (tmp)
--- 64,67 ----
***************
*** 78,82 ****
      retval[cd_count - 1] = NULL;
      return(retval);
! } /* __PHYSFS_detectAvailableCDs */
  
  
--- 80,84 ----
      retval[cd_count - 1] = NULL;
      return(retval);
! } /* __PHYSFS_platformDetectAvailableCDs */
  
  
***************
*** 86,95 ****
      char *retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
      DWORD buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
      retval[buflen] = '\0';  /* does API always null-terminate the string? */
  
!         /* make sure the string was not truncated. */
      if (__PHYSFS_platformStricmp(&retval[buflen - 4], ".exe") == 0)
      {
!         char *ptr = strrchr(retval, '\\');
          if (ptr != NULL)
          {
--- 88,99 ----
      char *retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
      DWORD buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
+       char *ptr;
+ 
      retval[buflen] = '\0';  /* does API always null-terminate the string? */
  
!       /* make sure the string was not truncated. */
      if (__PHYSFS_platformStricmp(&retval[buflen - 4], ".exe") == 0)
      {
!         ptr = strrchr(retval, '\\');
          if (ptr != NULL)
          {
***************
*** 142,159 ****
  
  
! char *__PHYSFS_platformGetUserDir(void)
  {
!     char *userdir = NULL;
  
!     if (runningNT)
!     {
!         userdir = ProfileDirectory;
!     }
!     else
      {
!         /*!!!TODO - Need to return something for Win9x/ME */
!     }
  
!     return userdir;
  } /* __PHYSFS_platformGetUserDir */
  
--- 146,196 ----
  
  
! static char *copyEnvironmentVariable(const char *varname)
  {
!     const char *envr = getenv(varname);
!     char *retval = NULL;
  
!     if (envr != NULL)
      {
!         retval = malloc(strlen(envr) + 1);
!         if (retval != NULL)
!             strcpy(retval, envr);
!     } /* if */
! 
!     return(retval);
! } /* copyEnvironmentVariable */
! 
! 
! char *__PHYSFS_platformGetUserDir(void)
! {
!     char *home = copyEnvironmentVariable("HOME");
!     const char *homedrive = getenv("HOMEDRIVE");
!     const char *homepath = getenv("HOMEPATH");
! 
!       if(getenv("USERPROFILE") != NULL) {
!               home = copyEnvironmentVariable("USERPROFILE");
!               return home;
!       }
! 
!     if (home != NULL)
!         return(home);
! 
!     if ((homedrive != NULL) && (homepath != NULL))
!     {
!         char *retval = (char *) malloc(strlen(homedrive)+strlen(homepath)+2);
!         if (retval != NULL)
!         {
!             strcpy(retval, homedrive);
!             if ((homepath[0] != '\\') &&
!                 (homedrive[strlen(homedrive)-1] != '\\'))
!             {
!                 strcat(retval, "\\");
!             } /* if */
!             strcat(retval, homepath);
!             return(retval);
!         } /* if */
!     } /* if */
  
!     return(NULL);
  } /* __PHYSFS_platformGetUserDir */
  
***************
*** 161,174 ****
  PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
  {
!     return((PHYSFS_uint64)GetCurrentThreadId());
  } /* __PHYSFS_platformGetThreadID */
  
  
- /* ...make this Cygwin AND Visual C friendly... */
  int __PHYSFS_platformStricmp(const char *x, const char *y)
  {
- #if (defined _MSC_VER)
-     return(stricmp(x, y));
- #else
      int ux, uy;
  
--- 198,207 ----
  PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
  {
!     return((int) GetCurrentThreadId());
  } /* __PHYSFS_platformGetThreadID */
  
  
  int __PHYSFS_platformStricmp(const char *x, const char *y)
  {
      int ux, uy;
  
***************
*** 186,190 ****
  
      return(0);
- #endif
  } /* __PHYSFS_platformStricmp */
  
--- 219,222 ----
***************
*** 237,241 ****
  
  
- /* Much like my college days, try to sleep for 10 milliseconds at a time... */
  void __PHYSFS_platformTimeslice(void)
  {
--- 269,272 ----
***************
*** 256,260 ****
      BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
  
!     while (FindNextFile(dir, &ent) != 0)
      {
          if (strcmp(ent.cFileName, ".") == 0)
--- 287,291 ----
      BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
  
!     for (; FindNextFile(dir, &ent) != 0; )
      {
          if (strcmp(ent.cFileName, ".") == 0)
***************
*** 308,312 ****
  
  
- /* this could probably use a cleanup. */
  char *__PHYSFS_platformRealPath(const char *path)
  {
--- 339,342 ----
***************
*** 325,329 ****
--- 355,362 ----
           */
      if ((path[0] == '\\') && (path[1] == '\\'))
+     {
+         BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
          strcpy(retval, path);
+     } /* if */
  
      else
***************
*** 436,557 ****
  } /* __PHYSFS_platformMkDir */
  
- /*
-  * Initialize any NT specific stuff.  This includes any OS based on NT.
-  *
-  * Return zero if there was a catastrophic failure and non-zero otherwise.
-  */
- static int doNTInit(void)
- {
-     DWORD pathsize = 0;
-     char TempProfileDirectory[1];
- 
-     /* Create a process access token handle */
-     if(!OpenProcessToken(ProcessHandle, TOKEN_QUERY, &AccessTokenHandle))
-     {
-         /* Access token is required by other win32 functions */
-         return 0;
-     }
- 
-     /* Should fail.  Will write the size of the profile path in pathsize*/
-     /*!!! Second parameter can't be NULL or the function fails??? */
-     if(!GetUserProfileDirectory(AccessTokenHandle, TempProfileDirectory, 
&pathsize))
-     {
-         /* Allocate memory for the profile directory */
-         ProfileDirectory = (char *)malloc(pathsize);
-         BAIL_IF_MACRO(ProfileDirectory == NULL, ERR_OUT_OF_MEMORY, 0);
-         /* Try to get the profile directory */
-         if(!GetUserProfileDirectory(AccessTokenHandle, ProfileDirectory, 
&pathsize))
-         {
-             free(ProfileDirectory);
-             return 0;
-         }
-     }
- 
-     /* Everything initialized okay */
-     return 1;
- }
- 
- /* 
-  * Get OS info and save it.
-  *
-  * Returns non-zero if successful, otherwise it returns zero on failure.
-  */
- int getOSInfo(void)
- {
-     /* Get OS info */
-     OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
-     if(!GetVersionEx(&OSVersionInfo))
-     {
-         return 0;
-     }
- 
-     /* Set to TRUE if we are runnign a WinNT based OS 4.0 or greater */
-     runningNT = (OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
-         (OSVersionInfo.dwMajorVersion > 3);
- 
-     return 1;
- }
- 
- int __PHYSFS_platformInit(void)
- {
-     if(!getOSInfo())
-     {
-         return 0;
-     }
- 
-     /* Get Windows ProcessID associated with the current process */
-     ProcessID = GetCurrentProcessId();
-     /* Create a process handle associated with the current process ID */
-     ProcessHandle = GetCurrentProcess();
- 
-     if(ProcessHandle == NULL)
-     {
-         /* Process handle is required by other win32 functions */
-         return 0;
-     }
- 
-     /* If running an NT system (NT/Win2k/XP, etc...) */
-     if(runningNT)
-     {
-         if(!doNTInit())
-         {
-             /* Error initializing NT stuff */
-             return 0;
-         }
-     }
- 
-     /* It's all good */
-     return 1;
- }
- 
- /*
-  * Uninitialize any NT specific stuff done in doNTInit().
-  *
-  * Return zero if there was a catastrophic failure and non-zero otherwise.
-  */
- static int doNTDeinit(void)
- {
-     if(CloseHandle(AccessTokenHandle) != S_OK)
-     {
-         return 0;
-     }
- 
-     free(ProfileDirectory);
- 
-     /* It's all good */
-     return 1;
- }
- 
- int __PHYSFS_platformDeinit(void)
- {
-     if(!doNTDeinit())
-         return 0;
- 
-     if(CloseHandle(ProcessHandle) != S_OK)
-         return 0;
- 
-     /* It's all good */
-     return 1;
- }
  
  void *__PHYSFS_platformOpenRead(const char *filename)
--- 469,472 ----
***************
*** 569,573 ****
  
      return (void *)FileHandle;
! }
  
  void *__PHYSFS_platformOpenWrite(const char *filename)
--- 484,489 ----
  
      return (void *)FileHandle;
! } /* __PHYSFS_platformOpenRead */
! 
  
  void *__PHYSFS_platformOpenWrite(const char *filename)
***************
*** 585,589 ****
  
      return (void *)FileHandle;
! }
  
  void *__PHYSFS_platformOpenAppend(const char *filename)
--- 501,506 ----
  
      return (void *)FileHandle;
! } /* __PHYSFS_platformOpenWrite */
! 
  
  void *__PHYSFS_platformOpenAppend(const char *filename)
***************
*** 603,607 ****
  
      return (void *)FileHandle;
! }
  
  PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
--- 520,525 ----
  
      return (void *)FileHandle;
! } /* __PHYSFS_platformOpenAppend */
! 
  
  PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
***************
*** 632,638 ****
  
      return retval;
! }
  
! PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, void *buffer,
                                       PHYSFS_uint32 size, PHYSFS_uint32 count)
  {
--- 550,557 ----
  
      return retval;
! } /* __PHYSFS_platformRead */
! 
  
! PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
                                       PHYSFS_uint32 size, PHYSFS_uint32 count)
  {
***************
*** 661,665 ****
  
      return retval;
! }
  
  int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
--- 580,585 ----
  
      return retval;
! } /* __PHYSFS_platformWrite */
! 
  
  int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
***************
*** 692,702 ****
  
      return retval;
! }
  
  PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
  {
      HANDLE FileHandle;
-     DWORD HighOrderPos = 0; 
-     DWORD LowOrderPos;
      PHYSFS_sint64 retval;
  
--- 612,621 ----
  
      return retval;
! } /* __PHYSFS_platformSeek */
! 
  
  PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
  {
      HANDLE FileHandle;
      PHYSFS_sint64 retval;
  
***************
*** 705,733 ****
  
      /* Get current position */
!     if(((LowOrderPos = SetFilePointer(FileHandle, 0, &HighOrderPos, 
FILE_CURRENT))
!         == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
!     {
!         /* Combine the high/low order to create the 64-bit position value */
!         retval = HighOrderPos;
!         retval = retval << 32;
!         retval |= LowOrderPos;
!     }
!     else
!     {
          /* Set the error to GetLastError */
!         __PHYSFS_setError(win32strerror());
          /* We errored out */
!         retval = 0;
!     }
  
-     /*!!! Can't find a file pointer routine?!?!?!!?!?*/
      return retval;
! }
  
  PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle)
  {
      HANDLE FileHandle;
-     DWORD FileSizeHigh;
-     DWORD FileSizeLow;
      PHYSFS_sint64 retval;
  
--- 624,643 ----
  
      /* Get current position */
!     retval = SetFilePointer(FileHandle, 0, NULL, FILE_CURRENT);
!     //if(GetLastError() != NO_ERROR)
!     //{
          /* Set the error to GetLastError */
!         //__PHYSFS_setError(win32strerror());
          /* We errored out */
!         //retval = 0;
!     //}
  
      return retval;
! } /* __PHYSFS_platformTell */
! 
  
  PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle)
  {
      HANDLE FileHandle;
      PHYSFS_sint64 retval;
  
***************
*** 735,747 ****
      FileHandle = (HANDLE)handle;
      
!     if(((FileSizeLow = GetFileSize(FileHandle, &FileSizeHigh))
!         == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
!     {
!         /* Combine the high/low order to create the 64-bit position value */
!         retval = FileSizeHigh;
!         retval = retval << 32;
!         retval |= FileSizeLow;
!     }
!     else
      {
          /* Set the error to GetLastError */
--- 645,651 ----
      FileHandle = (HANDLE)handle;
      
!     retval = GetFileSize(FileHandle, NULL);
! 
!     if(GetLastError() != NO_ERROR)
      {
          /* Set the error to GetLastError */
***************
*** 752,756 ****
  
      return retval;
! }
  
  int __PHYSFS_platformEOF(void *opaque)
--- 656,661 ----
  
      return retval;
! } /* __PHYSFS_platformFileLength */
! 
  
  int __PHYSFS_platformEOF(void *opaque)
***************
*** 767,775 ****
      {
          /* Non-zero if EOF is equal to the file length - 1 */
!         retval = FilePosition == __PHYSFS_platformFileLength(opaque) - 1;
      }
  
      return retval;
! }
  
  int __PHYSFS_platformFlush(void *opaque)
--- 672,681 ----
      {
          /* Non-zero if EOF is equal to the file length - 1 */
!         retval = (FilePosition >= (__PHYSFS_platformFileLength(opaque) - 1));
      }
  
      return retval;
! } /* __PHYSFS_platformEOF */
! 
  
  int __PHYSFS_platformFlush(void *opaque)
***************
*** 789,793 ****
  
      return retval;
! }
  
  int __PHYSFS_platformClose(void *opaque)
--- 695,700 ----
  
      return retval;
! } /* __PHYSFS_platformFlush */
! 
  
  int __PHYSFS_platformClose(void *opaque)
***************
*** 807,823 ****
  
      return retval;
! }
  
- /*
-  * Remove a file or directory entry in the actual filesystem. (path) is
-  *  specified in platform-dependent notation. Note that this deletes files
-  *  _and_ directories, so you might need to do some determination.
-  *  Non-empty directories should report an error and not delete themselves
-  *  or their contents.
-  *
-  * Deleting a symlink should remove the link, not what it points to.
-  *
-  * On error, return zero and set the error message. Return non-zero on 
success.
-  */
  int __PHYSFS_platformDelete(const char *path)
  {
--- 714,720 ----
  
      return retval;
! } /* __PHYSFS_platformClose */
! 
  
  int __PHYSFS_platformDelete(const char *path)
  {
***************
*** 841,878 ****
  
      return retval;
! }
  
  void *__PHYSFS_platformCreateMutex(void)
  {
!     return (void *)CreateMutex(NULL, FALSE, NULL);
! }
  
  void __PHYSFS_platformDestroyMutex(void *mutex)
  {
!     CloseHandle((HANDLE)mutex);
! }
  
  int __PHYSFS_platformGrabMutex(void *mutex)
  {
!     int retval;
  
!     if(WaitForSingleObject((HANDLE)mutex, INFINITE) == WAIT_FAILED)
!     {
          /* Our wait failed for some unknown reason */
!         retval = 1;
!     }
!     else
!     {
          /* Good to go */
!         retval = 0;
!     }
  
-     return retval;
- }
  
  void __PHYSFS_platformReleaseMutex(void *mutex)
  {
!     ReleaseMutex((HANDLE)mutex);
! }
  
  /* end of win32.c ... */
--- 738,782 ----
  
      return retval;
! } /* __PHYSFS_platformDelete */
! 
  
  void *__PHYSFS_platformCreateMutex(void)
  {
!     return (void *)0x1;
!     //return (void *)CreateMutex(NULL, FALSE, NULL);
! } /* __PHYSFS_platformCreateMutex */
! 
  
  void __PHYSFS_platformDestroyMutex(void *mutex)
  {
!     //CloseHandle((HANDLE)mutex);
! } /* __PHYSFS_platformDestroyMutex */
! 
  
  int __PHYSFS_platformGrabMutex(void *mutex)
  {
!       return 0;
  
! //    int retval;
! 
!     //if(WaitForSingleObject((HANDLE)mutex, INFINITE) == WAIT_FAILED)
!     //{
          /* Our wait failed for some unknown reason */
!         //retval = 1;
!     //}
!     //else
!     //{
          /* Good to go */
!         //retval = 0;
!     //}
! 
!     //return retval;
! } /* __PHYSFS_platformGrabMutex */
  
  
  void __PHYSFS_platformReleaseMutex(void *mutex)
  {
!     //ReleaseMutex((HANDLE)mutex);
! } /* __PHYSFS_platformReleaseMutex */
  
  /* end of win32.c ... */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]