Exemple #1
0
        public static bool Test_GetDirs()
        {
            PhysFS.Initialize();

            string[] cdromDirs = PhysFS.Instance.CdRomDirectories;

#if PRINT_INFO
            Debug.WriteLine($"  CdRom available dirs: {string.Join(", ", cdromDirs)}");
#endif

            string baseDir = PhysFS.Instance.BaseDirectory;

#if PRINT_INFO
            Debug.WriteLine($"  Base Dir: {baseDir}");
#endif

            string userDir = PhysFS.Instance.UserDirectory;

#if PRINT_INFO
            Debug.WriteLine($"  User Dir: {userDir}");
#endif

            PhysFS.Deinitialize();

            return(true);
        }
Exemple #2
0
        public static bool Test_PhysFSStreamWrite()
        {
            PhysFS.Initialize();

            PhysFS.Instance.WriteDirectory = TestWriteDir;
            Debug.WriteLine($"  Write Dir: {PhysFS.Instance.WriteDirectory}");

            PhysFSFile file = PhysFSFile.OpenWrite("test-write-stream.txt");

            using (PhysFSStream stream = new PhysFSStream(file)) {
                string text      = "Just a PhysFSFileWrite test...";
                byte[] textBytes = Encoding.UTF8.GetBytes(text);

                Debug.WriteLine($"  Before writing, file length: {stream.Length}");

                Debug.WriteLine("  Writing to file");
                stream.Write(textBytes, 0, textBytes.Length);

                Debug.WriteLine($"  After writing, file length: {stream.Length}");
            }

            PhysFS.Deinitialize();

            return(true);
        }
Exemple #3
0
        public static bool Test_Archiver()
        {
            PhysFS.Initialize();

            TestArchiver archiver = new TestArchiver();

            PhysFS.Instance.RegisterArchiver(archiver);

            PHYSFS_ArchiveInfo[] supportedArchiveTypes = PhysFS.Instance.SupportedArchiveTypes;

            #if PRINT_INFO
            foreach (PHYSFS_ArchiveInfo archiveInfo in supportedArchiveTypes)
            {
                Debug.WriteLine($"  ext: {archiveInfo.Extension} |  desc: {archiveInfo.Description} |  author: {archiveInfo.Author} |  url: {archiveInfo.Url} |  sym links: {archiveInfo.SupportsSymlinks == 1}");
            }
#endif

            PhysFS.Instance.Mount("folder/hue file.xyz", mountPoint: "", appendToPath: true);

            ShowAllFilesAt("/");
            ShowSearchPaths();

            using (PhysFSStream stream = new PhysFSStream(PhysFSFile.OpenRead("file a"))) {
                byte[] buffer    = new byte[stream.Length];
                int    bytesRead = stream.Read(buffer, 0, buffer.Length);

                string text = Encoding.UTF8.GetString(buffer);

                Debug.WriteLine($"  File contents:\n{text}");
                Debug.WriteLine($"  Bytes Read: {bytesRead}");
            }

            PhysFS.Deinitialize();
            return(true);
        }
Exemple #4
0
        public static bool Test_Mount()
        {
            PhysFS.Initialize();

            bool ret = PhysFS.Instance.Mount(TestArchiveFilePath, mountPoint: "", appendToPath: true);

            PhysFS.Deinitialize();

            return(ret);
        }
Exemple #5
0
        public static bool Test_MountIOStream()
        {
            PhysFS.Initialize();

            TestStream stream = new TestStream("folder.zip");

            PhysFS.Instance.MountIOStream(stream, "file-from-iostream.zip", mountPoint: "/", appendToPath: true);

            ShowAllFilesAt("/");
            ShowSearchPaths();

            PhysFS.Deinitialize();
            return(true);
        }
Exemple #6
0
        public static bool Test_MountHandle()
        {
            PhysFS.Initialize();
            PhysFS.Instance.Mount("archive inside archive.zip", mountPoint: "", appendToPath: true);

            PhysFSFile file = PhysFSFile.OpenRead("inner archive.zip");

            PhysFS.Instance.MountHandle(file, "file-from-mountHandle.zip", mountPoint: "/inner archive things", appendToPath: true);

            ShowAllFilesAt("/");
            ShowSearchPaths();

            PhysFS.Deinitialize();
            return(true);
        }
Exemple #7
0
        public static bool Test_Stat()
        {
            PhysFS.Initialize();
            PhysFS.Instance.Mount(TestFolder, mountPoint: "", appendToPath: true);
            PHYSFS_Stat stat = PhysFS.Stat("test.txt");

            System.DateTimeOffset createTime = System.DateTimeOffset.FromUnixTimeSeconds(stat.CreateTime),
                                  modTime    = System.DateTimeOffset.FromUnixTimeSeconds(stat.ModTime),
                                  accessTime = System.DateTimeOffset.FromUnixTimeSeconds(stat.AccessTime);

            Debug.WriteLine($"  File Size: {stat.FileSize} bytes, ModTime: {modTime}, Create Time: {createTime}, Access Time: {accessTime}, File Type: {stat.FileType}, Is Readonly: {System.Convert.ToBoolean(stat.IsReadonly)}");

            PhysFS.Deinitialize();
            return(true);
        }
Exemple #8
0
        public static bool Test_WriteDir()
        {
            PhysFS.Initialize();

            Debug.WriteLine($"  Setting Write Dir to '{TestWriteDir}'");
            PhysFS.Instance.WriteDirectory = TestWriteDir;

            string writeDir = PhysFS.Instance.WriteDirectory;

            Debug.WriteLine($"  Getting Write Dir: {writeDir}");

            PhysFS.Deinitialize();

            return(writeDir == TestWriteDir);
        }
Exemple #9
0
        public static bool Test_Allocator()
        {
            TestAllocator allocator = new TestAllocator {
                ShowDebugInfo = false
            };

            PhysFS.Allocator = allocator;

            PhysFS.Initialize();
            Debug.WriteLine("  Testing Mount");
            PhysFS.Instance.Mount(TestFolder, mountPoint: "", appendToPath: true);
            Debug.WriteLine("  Testing Unmount");
            PhysFS.Instance.Unmount(TestFolder);
            PhysFS.Deinitialize();
            return(true);
        }
Exemple #10
0
        public static bool Test_MountMemory()
        {
            PhysFS.Initialize();

            byte[] folderBytes = System.IO.File.ReadAllBytes("folder.zip");
            Debug.WriteLine($"  Reading 'folder.zip', size: {folderBytes.Length} bytes");

            Debug.WriteLine("  Mounting file on memory");
            PhysFS.Instance.MountMemory(folderBytes, "memory-file.zip", "/memory-mount-test/", appendToPath: true);

            ShowAllFilesAt("/");
            ShowSearchPaths();

            PhysFS.Deinitialize();
            return(true);
        }
Exemple #11
0
        public static bool Test_SupportedArchiveTypes()
        {
            PhysFS.Initialize();

            PHYSFS_ArchiveInfo[] supportedArchiveTypes = PhysFS.Instance.SupportedArchiveTypes;

            #if PRINT_INFO
            foreach (PHYSFS_ArchiveInfo archiveInfo in supportedArchiveTypes)
            {
                Debug.WriteLine($"  ext: {archiveInfo.Extension} |  desc: {archiveInfo.Description} |  author: {archiveInfo.Author} |  url: {archiveInfo.Url} |  sym links: {archiveInfo.SupportsSymlinks == 1}");
            }
#endif

            PhysFS.Deinitialize();

            return(true);
        }
Exemple #12
0
        public static bool Test_ReadWriteBytes()
        {
            PhysFS.Initialize();
            //PhysFS.Instance.WriteDirectory = TestFolder;
            PhysFS.Instance.Mount(TestFolder, mountPoint: "", appendToPath: true);

            string filename = "test.txt";

            Debug.WriteLine($"  Reading '{filename}' file");

            PhysFSFile file = PhysFSFile.OpenRead(filename);

            using (PhysFSStream stream = new PhysFSStream(file)) {
                uint value = 0;

                for (int i = 0; i < 5; i++)
                {
                    /*
                     * if (stream.WriteULE16(60)) {
                     *  Debug.WriteLine("  Write to file");
                     * } else {
                     *  Debug.WriteLine("  Can't write to file");
                     * }
                     */

                    if (stream.ReadULE32(ref value))
                    {
                        Debug.WriteLine($"  Read ULE 32: {value}");
                    }
                    else
                    {
                        Debug.WriteLine("  Can't Read ULE 32");
                    }
                }

                Debug.WriteLine($"  Current Stream Pos: {stream.Position}");
            }

            PhysFS.Deinitialize();
            return(true);
        }
Exemple #13
0
        public static bool Test_PhysFSStreamRead()
        {
            PhysFS.Initialize();
            PhysFS.Instance.Mount(TestFolder, mountPoint: "", appendToPath: true);

            Debug.WriteLine($"  Reading 'just a text.txt' file");

            PhysFSFile file = PhysFSFile.OpenRead("test.txt");

            using (PhysFSStream stream = new PhysFSStream(file)) {
                byte[] buffer    = new byte[stream.Length];
                int    bytesRead = stream.Read(buffer, 0, buffer.Length);

                string text = Encoding.UTF8.GetString(buffer);

                //Debug.WriteLine($"  File contents:\n{text}");
                Debug.WriteLine($"  Bytes Read: {bytesRead}");
            }

            PhysFS.Deinitialize();

            return(true);
        }
Exemple #14
0
        public static bool Test_Enumerate()
        {
            PhysFS.Initialize();
            PhysFS.Instance.Mount(TestFolder, mountPoint: "", appendToPath: true);

            Debug.WriteLine("  Enumerating all files (explicit callback result returning):");

            PhysFS.Instance.Enumerate(
                "/",
                FileCallbackExplicit
                );

            Debug.WriteLine("  Enumerating all files (using enumerator):");

            PhysFS.Instance.Enumerate(
                "/",
                FileCallbackEnumerator
                );

            PhysFS.Deinitialize();

            return(true);

            PHYSFS_EnumerateCallbackResult FileCallbackExplicit(string dir, string filename)
            {
                /*
                 * To stop enumerating:
                 *
                 * if (filename.Contains("test")) {
                 *  Debug.WriteLine("    > stopping...");
                 *  return PHYSFS_EnumerateCallbackResult.PHYSFS_ENUM_STOP;
                 * }
                 *
                 *
                 * To signaling an error to PhysFS:
                 *
                 * if (filename.Contains("test")) {
                 *  Debug.WriteLine("    > some error has happened!");
                 *  return PHYSFS_EnumerateCallbackResult.PHYSFS_ENUM_ERROR;
                 * }
                 */

                Debug.WriteLine($"    dir: {dir}, filename: {filename}");
                return(PHYSFS_EnumerateCallbackResult.PHYSFS_ENUM_OK);
            }

            IEnumerator FileCallbackEnumerator(string dir, string filename)
            {
                /*
                 * To stop enumerating:
                 *
                 * if (filename.Contains("test")) {
                 *  Debug.WriteLine("    > stopping...");
                 *  yield false;
                 * }
                 *
                 *
                 * To signaling an error to PhysFS:
                 *
                 * if (filename.Contains("test")) {
                 *  Debug.WriteLine("    > some error has happened!");
                 *  yield break;
                 * }
                 */

                Debug.WriteLine($"    dir: {dir}, filename: {filename}");
                yield return(true);
            }
        }