0

I'm working on a Cosmos operatingsystem, and I'm wondering if there is some way to write a file with information in it? I'm trying to make CosmosOS remind the username and the password.

PS. I also wan't it to be able to read the file.

2 Answers2

4

Currently only FAT is supported, so you need at least one FAT partition. In your BeforeRun method, you need to initialize the VFS, like this:

var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);

Then you can use the System.IO APIs to read and write files. The root path for the first partition is 0:\.

Example

public override void BeforeRun()
{
    var fs = new Sys.FileSystem.CosmosVFS();
    Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
}

public override void Run()
{
    var usersFile = @"0:\users.dat";

    if (!File.Exists(usersFile))
    {
        File.Create(usersFile);
    }

    // now you can read or write to the file

    // example read methods: File.ReadAllText, File.ReadAllLines, File.ReadAllBytes
    // example write methods: File.WriteAllText, File.WriteAllLines, File.WriteAllBytes
}
José Pedro
  • 1,097
  • 3
  • 14
  • 24
4

I had the same issue this worked for me

    using Cosmos.System.FileSystem;
    var usersFile = @"0:\users.dat";
    public static CosmosVFS FAT = new CosmosVFS();
    FAT.CreateFile(usersFile );
kostas
  • 41
  • 1