How to save data in CosmosOS?

半城伤御伤魂 提交于 2021-01-29 08:36:17

问题


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.


回答1:


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
}



回答2:


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 );


来源:https://stackoverflow.com/questions/50100827/how-to-save-data-in-cosmosos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!