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);
            commands.Add("getmountpoint", GetMountPoint);

            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();
        }
示例#2
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();
    }