extras/PhysFS.NET/PhysFS.cs
author Ryan C. Gordon <icculus@icculus.org>
Mon, 23 Mar 2009 01:43:05 -0400
branchstable-1.0
changeset 966 816a83f04a27
parent 532 748f518a6d76
permissions -rwxr-xr-x
Updated version to 1.0.2 in configure.in ...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
532
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     1
/* PhysFS.cs - (c)2003 Gregory S. Read
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     2
 * Provides access to PhysFS API calls not specific to file handle access.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     3
 */
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     4
using System;
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     5
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     6
namespace PhysFS_NET
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     7
{
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     8
   public class PhysFS
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
     9
   {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    10
      /* Initialize
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    11
       * Inits the PhysFS API.  This normally does not need to be called unless
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    12
       * the API has been manually deinitialized since the PhysFS_DLL class
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    13
       * initializes just before the first call is made into the DLL.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    14
       * Parameters
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    15
       *    none
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    16
       * Returns
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    17
       *    none
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    18
       * Exceptions
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    19
       *    PhysFSException - An error occured in the PhysFS API
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    20
       */
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    21
      public static void Initialize()
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    22
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    23
         // Initialize the physfs library, raise an exception if error
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    24
         if(PhysFS_DLL.PHYSFS_init("") == 0)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    25
            throw new PhysFSException();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    26
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    27
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    28
      /* Deinitialize
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    29
       * Deinits the PhysFS API.  It is recommended that this method be called
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    30
       * by the application before exiting in order to gracefully deallocate
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    31
       * resources and close all filehandles, etc.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    32
       * Parameters
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    33
       *    none
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    34
       * Returns
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    35
       *    none
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    36
       * Exceptions
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    37
       *    PhysFSException - An error occured in the PhysFS API
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    38
       */
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    39
      public static void Deinitialize()
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    40
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    41
         // Deinit, raise an exception if an error occured
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    42
         if(PhysFS_DLL.PHYSFS_deinit() == 0)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    43
            throw new PhysFSException();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    44
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    45
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    46
      /* BaseDir
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    47
       * Gets the base directory configured for PhysFS.  See the PhysFS API
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    48
       * documentation for more information.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    49
       * Parameters
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    50
       *    none
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    51
       * Returns
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    52
       *    A string value representing the Base Directory
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    53
       * Exceptions
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    54
       *    none
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    55
       */
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    56
      public static string BaseDir
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    57
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    58
         get
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    59
         {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    60
            // Return the current base directory
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    61
            return PhysFS_DLL.PHYSFS_getBaseDir();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    62
         }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    63
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    64
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    65
      /* WriteDir
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    66
       * Gets or sets the write directory configured for PhysFS.  See the PhysFS API
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    67
       * documentation for more information.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    68
       * Parameters
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    69
       *    set - Path to set the WriteDir property to
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    70
       * Returns
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    71
       *    A string value representing the Write Directory
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    72
       * Exceptions
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    73
       *    PhysFSException - An error occured in the PhysFS API when
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    74
       *       settings the write directory.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    75
       */
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    76
      public static string WriteDir
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    77
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    78
         get
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    79
         {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    80
            // Return the current write directory
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    81
            return PhysFS_DLL.PHYSFS_getWriteDir();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    82
         }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    83
         set
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    84
         {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    85
            // Set the write directory and raise an exception if an error occured
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    86
            if(PhysFS_DLL.PHYSFS_setWriteDir(value) == 0)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    87
               throw new PhysFSException();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    88
         }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    89
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    90
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    91
      /* UserDir
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    92
       * Gets or sets the write directory configured for PhysFS.  See the PhysFS API
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    93
       * documentation for more information.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    94
       * Parameters
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    95
       *    set - Path to set the WriteDir property to
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    96
       * Returns
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    97
       *    A string value representing the Write Directory
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    98
       * Exceptions
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
    99
       *    PhysFSException - An error occured in the PhysFS API when
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   100
       *       settings the write directory.
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   101
       */
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   102
      public static string UserDir
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   103
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   104
         get
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   105
         {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   106
            // Return the current user directory
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   107
            return PhysFS_DLL.PHYSFS_getUserDir();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   108
         }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   109
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   110
      public static void AddToSearchPath(string NewDir, bool Append)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   111
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   112
         if(PhysFS_DLL.PHYSFS_addToSearchPath(NewDir, Append?1:0) == 0)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   113
            throw new PhysFSException();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   114
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   115
      public static void RemoveFromSearchPath(string OldDir)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   116
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   117
         if(PhysFS_DLL.PHYSFS_removeFromSearchPath(OldDir) == 0)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   118
            throw new PhysFSException();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   119
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   120
      public unsafe static string[] GetSearchPath()
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   121
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   122
         byte** p;				// Searchpath list from PhysFS dll
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   123
         string[] pathlist;	// List converted to an array
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   124
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   125
         // Get the CDROM drive listing
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   126
         p = PhysFS_DLL.PHYSFS_getSearchPath();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   127
         // Convert the C-style array to a .NET style array
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   128
         pathlist = PhysFS_DLL.BytePPToArray(p);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   129
         // Free the original list since we're done with it
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   130
         PhysFS_DLL.PHYSFS_freeList(p);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   131
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   132
         return pathlist;
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   133
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   134
      public unsafe static string[] GetCDROMDrives()
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   135
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   136
         byte** p;				// CDROM list from PhysFS dll
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   137
         string[] cdromlist;	// List converted to an array
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   138
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   139
         // Get the CDROM drive listing
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   140
         p = PhysFS_DLL.PHYSFS_getCdRomDirs();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   141
         // Convert the C-style array to a .NET style array
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   142
         cdromlist = PhysFS_DLL.BytePPToArray(p);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   143
         // Free the original list since we're done with it
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   144
         PhysFS_DLL.PHYSFS_freeList(p);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   145
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   146
         return cdromlist;
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   147
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   148
      public static void MkDir(string Dirname)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   149
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   150
         if(PhysFS_DLL.PHYSFS_mkdir(Dirname) == 0)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   151
            throw new PhysFSException();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   152
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   153
      public static void Delete(string Filename)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   154
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   155
         if(PhysFS_DLL.PHYSFS_delete(Filename) == 0)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   156
            throw new PhysFSException();
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   157
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   158
      public static string GetRealDir(string Filename)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   159
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   160
         string RetValue;
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   161
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   162
         RetValue = PhysFS_DLL.PHYSFS_getRealDir(Filename);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   163
         if(RetValue == null)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   164
            throw new PhysFSException("File not found in search path.");
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   165
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   166
         // Return the real file path of the specified filename
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   167
         return RetValue;
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   168
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   169
      public unsafe static string[] EnumerateFiles(string Dirname)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   170
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   171
         byte** p;				// File list from PhysFS dll
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   172
         string[] filelist;	// List converted to an array
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   173
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   174
         // Get the CDROM drive listing
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   175
         p = PhysFS_DLL.PHYSFS_enumerateFiles(Dirname);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   176
         // Convert the C-style array to a .NET style array
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   177
         filelist = PhysFS_DLL.BytePPToArray(p);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   178
         // Free the original list since we're done with it
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   179
         PhysFS_DLL.PHYSFS_freeList(p);
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   180
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   181
         return filelist;
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   182
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   183
      public static bool IsDirectory(string Filename)
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   184
      {
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   185
         // Return true if non-zero, otherwise return false
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   186
         return (PhysFS_DLL.PHYSFS_isDirectory(Filename) == 0)?false:true;
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   187
      }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   188
   }
748f518a6d76 -First version of PhysFS.NET.
Gregory S. Read <zeph@clutteredmind.org>
parents:
diff changeset
   189
}