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()); }
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")); }
public static IntPtr OpenRead(string filename, PhysFS physFS) { var val = physFS.interop.PHYSFS_openRead(filename); if (val == null) throw new PhysFSException(physFS); return val; }
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()); }
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()); }
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()); }
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()); }
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(); }
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)); } }
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); } } }
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()); } }
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()); } }
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); } }
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(); }
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); }
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); }
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")); } }
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); } }
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); }
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); }
public static void Flush(IntPtr file, PhysFS physFS) { int err = physFS.interop.PHYSFS_flush(file); physFS.ThrowException(err); }
public static void SetBuffer(IntPtr file, ulong bufSize, PhysFS physFS) { int err = physFS.interop.PHYSFS_setBuffer(file, bufSize); physFS.ThrowException(err); }
public static long FileLength(IntPtr file, PhysFS physFS) { return physFS.interop.PHYSFS_fileLength(file); }
public static void Seek(IntPtr file, ulong pos, PhysFS physFS) { int err = physFS.interop.PHYSFS_seek(file, pos); physFS.ThrowException(err); }
public static long Tell(IntPtr file, PhysFS physFS) { return physFS.interop.PHYSFS_tell(file); }
public static bool EOF(IntPtr file, PhysFS physFS) { return physFS.interop.PHYSFS_eof(file) != 0; }
public static void Close(IntPtr file, PhysFS physFS) { int err = physFS.interop.PHYSFS_close(file); physFS.ThrowException(err); }
internal PhysFSStream(PhysFS pfs, IntPtr ptr, bool readOnly) { handle = ptr; this.readOnly = readOnly; physFS = pfs; }
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(); }