Exemplo n.º 1
0
 private void RefreshSearchPathButton_Click(object sender, System.EventArgs e)
 {
     // Clear ths listbox if it contains any items
     SearchPathList.Items.Clear();
     // Add the items to the list
     SearchPathList.Items.AddRange(PhysFS.GetSearchPath());
 }
Exemplo n.º 2
0
        public void FileManipulation()
        {
            using var pfs = new PhysFS("");
            pfs.SetWriteDir("./");
            pfs.Mount("./", "/", true);

            using (var sw = new StreamWriter(pfs.OpenWrite("foo")))
            {
                sw.Write("hello, world! èòàùã こんにちは世界 你好世界");
            }

            Assert.True(File.Exists("./foo"));

            var fileContent = File.ReadAllText("./foo");

            using (var sr = new StreamReader(pfs.OpenRead("foo")))
            {
                sr.ReadToEnd().Should().BeEquivalentTo(fileContent);
            }

            using (var sw = new StreamWriter(pfs.OpenAppend("foo")))
            {
                sw.Write("foo");
            }
            File.ReadAllText("./foo").Should().BeEquivalentTo(fileContent + "foo");

            pfs.Delete("foo");
            Assert.False(File.Exists("./foo"));
        }
Exemplo n.º 3
0
 public static IntPtr OpenRead(string filename, PhysFS physFS)
 {
   var val = physFS.interop.PHYSFS_openRead(filename);
   if (val == null)
     throw new PhysFSException(physFS);
   return val;
 }
Exemplo n.º 4
0
 private void RefreshCDsButton_Click(object sender, System.EventArgs e)
 {
     // Clear ths listbox if it contains any items
     CDDrivesList.Items.Clear();
     // Add the items to the list
     CDDrivesList.Items.AddRange(PhysFS.GetCDROMDrives());
 }
Exemplo n.º 5
0
 public void VersionCheck(byte major, byte minor, byte patch)
 {
     using var pfs = new PhysFS("");
     new MoonTools.NETPhysFS.Version()
     {
         major = major, minor = minor, patch = patch
     }.Should().BeEquivalentTo(pfs.GetLinkedVersion());
 }
Exemplo n.º 6
0
        public void UserDirectory()
        {
            using var pfs = new PhysFS("");
            var userDirectory    = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            var pfsUserDirectory = pfs.GetUserDir();

            Path.GetPathRoot(pfsUserDirectory).Should().Be(Path.GetPathRoot(userDirectory));
        }
 void DirSeparator()
 {
     using (var pfs = new PhysFS(""))
     {
         Assert.NotNull(pfs.GetDirSeparator());
         Assert.NotEqual("", pfs.GetDirSeparator());
     }
 }
 void VersionCheck(byte major, byte minor, byte patch)
 {
     using (var pfs = new PhysFS(""))
         Assert.Equal(new SharpPhysFS.Version()
         {
             major = major, minor = minor, patch = patch
         }, pfs.GetLinkedVersion());
 }
Exemplo n.º 9
0
 private void AddSearchPathButton_Click(object sender, System.EventArgs e)
 {
     // Add search path
     PhysFS.AddToSearchPath(NewSearchPathText.Text, false);
     // Clear ths listbox if it contains any items
     SearchPathList.Items.Clear();
     // Add the items to the list
     SearchPathList.Items.AddRange(PhysFS.GetSearchPath());
 }
Exemplo n.º 10
0
 public void PermitSymbolicLinks()
 {
     using var pfs = new PhysFS("");
     pfs.SymbolicLinksPermitted().Should().BeFalse();
     pfs.PermitSymbolicLinks(true);
     pfs.SymbolicLinksPermitted().Should().BeTrue();
     pfs.PermitSymbolicLinks(false);
     pfs.SymbolicLinksPermitted().Should().BeFalse();
 }
Exemplo n.º 11
0
 void UserDirectory()
 {
     using (var pfs = new PhysFS(""))
     {
         var userDirectory    = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
         var pfsUserDirectory = pfs.GetUserDir();
         Assert.Equal(Path.GetPathRoot(userDirectory), Path.GetPathRoot(pfsUserDirectory));
     }
 }
Exemplo n.º 12
0
 public static long Write(IntPtr file, byte[] buffer, uint objSize, uint objCount, PhysFS physFS)
 {
   unsafe
   {
     fixed (void* ptr = buffer)
     {
       return physFS.interop.PHYSFS_write(file, (IntPtr)ptr, objSize, objCount);
     }
   }
 }
Exemplo n.º 13
0
 private void RemovePathButton_Click(object sender, System.EventArgs e)
 {
     if (SearchPathList.SelectedItem != null)
     {
         PhysFS.RemoveFromSearchPath(SearchPathList.SelectedItem.ToString());
         // Clear ths listbox if it contains any items
         SearchPathList.Items.Clear();
         // Add the items to the list
         SearchPathList.Items.AddRange(PhysFS.GetSearchPath());
     }
 }
Exemplo n.º 14
0
 void PermitSymbolicLinks()
 {
     using (var pfs = new PhysFS(""))
     {
         Assert.False(pfs.SymbolicLinksPermitted());
         pfs.PermitSymbolicLinks(true);
         Assert.True(pfs.SymbolicLinksPermitted());
         pfs.PermitSymbolicLinks(false);
         Assert.False(pfs.SymbolicLinksPermitted());
     }
 }
Exemplo n.º 15
0
        public void LoadResource <T>(String filenameToEnum, PhysFS physFSInstance, Dictionary <string, T> MapDictionary) where T : MainGameObject, new()
        {
            var FileList = physFSInstance.EnumerateFiles(filenameToEnum);

            foreach (var file in FileList)
            {
                var filepath     = filenameToEnum + "/" + file;
                var locationData = DeserializeJsonFile <T>(physFSInstance, filepath);
                MapDictionary.Add(locationData.Name.Replace(" ", "-"), locationData);
            }
        }
Exemplo n.º 16
0
        public void DirectoryManipulation()
        {
            using var pfs = new PhysFS("");
            pfs.SetWriteDir("./");
            pfs.GetWriteDir().Should().Be("./");

            pfs.CreateDirectory("hello");
            Directory.Exists("./hello").Should().BeTrue();

            pfs.Delete("hello");
            Directory.Exists("./hello").Should().BeFalse();
        }
Exemplo n.º 17
0
        public void DriveEnumeration()
        {
            using var pfs = new PhysFS("");
            var effectiveCdDrives = DriveInfo.GetDrives()
                                    .Where(x => x.DriveType == DriveType.CDRom)
                                    .Select(x => x.RootDirectory.FullName)
                                    .OrderBy(s => s)
                                    .ToArray();

            var enumeratedCdDrives = pfs.GetCdRomDirs().OrderBy(s => s);

            enumeratedCdDrives.Should().BeEquivalentTo(effectiveCdDrives);
        }
Exemplo n.º 18
0
        public T DeserializeJsonFile <T>(PhysFS physFSInstance, string filepath) where T : MainGameObject, new()
        {
            var filedata   = physFSInstance.OpenRead(filepath);
            var jsonObject = DeserializeJsonFileData <T>(filedata);

            if (jsonObject == null)
            {
                return(new T {
                    Name = "null"
                });
            }

            return(jsonObject);
        }
Exemplo n.º 19
0
        void DirectoryManipulation()
        {
            using (var pfs = new PhysFS(""))
            {
                pfs.SetWriteDir("./");
                Assert.Equal("./", pfs.GetWriteDir());

                pfs.Mkdir("hello");
                Assert.True(Directory.Exists("./hello"));

                pfs.Delete("hello");
                Assert.False(Directory.Exists("./hello"));
            }
        }
Exemplo n.º 20
0
        void FileEnumeration()
        {
            using (var pfs = new PhysFS(""))
            {
                pfs.Mount("./", "/", false);

                var effectiveFiles = Directory.GetFiles("./").Select(x => Path.GetFileName(x)).ToArray();
                Array.Sort(effectiveFiles);
                var enumeratedFiles = pfs.EnumerateFiles("/");
                Array.Sort(enumeratedFiles);

                Assert.Equal(effectiveFiles, enumeratedFiles);
            }
        }
Exemplo n.º 21
0
        public void FileEnumeration()
        {
            using var pfs = new PhysFS("");
            pfs.Mount("./", "/", false);

            var effectiveFiles = Directory.GetFiles("./").Select(Path.GetFileName).ToArray();

            Array.Sort(effectiveFiles);
            var enumeratedFiles = pfs.EnumerateFiles("/").ToArray();

            Array.Sort(enumeratedFiles);

            enumeratedFiles.Should().BeEquivalentTo(effectiveFiles);
        }
Exemplo n.º 22
0
        public List <T> LoadSingleResource <T>(String filenameToEnum, PhysFS physFSInstance) where T : MainGameObject, new()
        {
            var dataset  = new List <T>();
            var FileList = physFSInstance.EnumerateFiles(filenameToEnum);

            foreach (var file in FileList)
            {
                var filepath     = filenameToEnum + "/" + file;
                var locationData = DeserializeJsonFile <T>(physFSInstance, filepath);
                dataset.Add(locationData);
            }

            return(dataset);
        }
Exemplo n.º 23
0
 public static void Flush(IntPtr file, PhysFS physFS)
 {
   int err = physFS.interop.PHYSFS_flush(file);
   physFS.ThrowException(err);
 }
Exemplo n.º 24
0
 public static void SetBuffer(IntPtr file, ulong bufSize, PhysFS physFS)
 {
   int err = physFS.interop.PHYSFS_setBuffer(file, bufSize);
   physFS.ThrowException(err);
 }
Exemplo n.º 25
0
 public static long FileLength(IntPtr file, PhysFS physFS)
 {
   return physFS.interop.PHYSFS_fileLength(file);
 }
Exemplo n.º 26
0
 public static void Seek(IntPtr file, ulong pos, PhysFS physFS)
 {
   int err = physFS.interop.PHYSFS_seek(file, pos);
   physFS.ThrowException(err);
 }
Exemplo n.º 27
0
 public static long Tell(IntPtr file, PhysFS physFS)
 {
   return physFS.interop.PHYSFS_tell(file);
 }
Exemplo n.º 28
0
 public static bool EOF(IntPtr file, PhysFS physFS)
 {
   return physFS.interop.PHYSFS_eof(file) != 0;
 }
Exemplo n.º 29
0
 public static void Close(IntPtr file, PhysFS physFS)
 {
   int err = physFS.interop.PHYSFS_close(file);
   physFS.ThrowException(err);
 }
Exemplo n.º 30
0
 internal PhysFSStream(PhysFS pfs, IntPtr ptr, bool readOnly)
 {
   handle = ptr;
   this.readOnly = readOnly;
   physFS = pfs;
 }
Exemplo n.º 31
0
    static void Main(string[] args)
    {
      try
      {
        physFS = new PhysFS("");
      }
      catch (PhysFSLibNotFound)
      {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Error.WriteLine("ERROR: PhysFS could not be loaded. Are you sure it is installed or a suitable module is in your working directory?");
        return;
      }

      var version = physFS.GetLinkedVersion();

      Console.WriteLine("SharpPhysFS Test console");
      Console.WriteLine("Loaded PhysFS version: {0}.{1}.{2}", version.major, version.minor, version.patch);
      PrintSupportedArchives();

      Console.WriteLine("Type 'help' for a list of commands");

      commands.Add("help", Help);
      commands.Add("mount", Mount);
      commands.Add("enumerate", Enumerate);
      commands.Add("ls", Enumerate);
      commands.Add("getdirsep", GetDirSeparator);
      commands.Add("getcdromdirs", GetCdRomDirectories);
      commands.Add("getsearchpath", GetSearchPath);
      commands.Add("getbasedir", GetBaseDirectory);
      commands.Add("getuserdir", GetUserDirectory);
      commands.Add("getwritedir", GetWriteDirectory);
      commands.Add("setwritedir", SetWriteDirectory);
      commands.Add("permitsymlinks", PermitSymlinks);
      commands.Add("setsaneconfig", SetSaneConfig);
      commands.Add("mkdir", MkDir);
      commands.Add("delete", Delete);
      commands.Add("getrealdir", GetRealDir);
      commands.Add("exists", Exists);
      commands.Add("isdir", IsDir);
      commands.Add("issymlink", IsSymlink);
      commands.Add("cat", Cat);
      commands.Add("filelength", FileLength);

      while (true)
      {
        Console.Write("> ");
        var input = Console.ReadLine();
        var split = ParseInput(input);
        if (split.Count() == 0)
        {
          continue;
        }

        if (split.First() == "quit")
        {
          break;
        }
        else
        {
          Func<string[], bool> cmd;
          if (commands.TryGetValue(split.First(), out cmd))
          {
            try
            {
              if(cmd(split.Skip(1).ToArray()))
              {
                Console.WriteLine("Done.");
              }
            }
            catch (PhysFS.PhysFSException e)
            {
              Console.ForegroundColor = ConsoleColor.Red;
              Console.Error.WriteLine("ERROR: {0}", e.Message);
              Console.ForegroundColor = ConsoleColor.Gray;
            }
          }
          else
          {
            Console.Error.WriteLine("Invalid command");
          }
        }
      }

      physFS.Dispose();
    }