Exemplo n.º 1
0
    private void Load()
    {
        nn.fs.EntryType entryType = 0;
        nn.Result       result    = nn.fs.FileSystem.GetEntryType(ref entryType, filePath);
        if (nn.fs.FileSystem.ResultPathNotFound.Includes(result))
        {
            return;
        }
        result.abortUnlessSuccess();

        result = nn.fs.File.Open(ref fileHandle, filePath, nn.fs.OpenFileMode.Read);
        result.abortUnlessSuccess();

        long fileSize = 0;

        result = nn.fs.File.GetSize(ref fileSize, fileHandle);
        result.abortUnlessSuccess();

        byte[] data = new byte[fileSize];
        result = nn.fs.File.Read(fileHandle, 0, data, fileSize);
        result.abortUnlessSuccess();

        nn.fs.File.Close(fileHandle);

        using (MemoryStream stream = new MemoryStream(data))
        {
            BinaryReader reader  = new BinaryReader(stream);
            int          version = reader.ReadInt32();
            Debug.Assert(version == saveDataVersion); // Save data version up
            counter = reader.ReadInt32();
        }
    }
Exemplo n.º 2
0
    public RankingDeta Load()
    {
        nn.fs.EntryType entryType = 0;
        nn.Result       result    = nn.fs.FileSystem.GetEntryType(ref entryType, filePath);
        if (nn.fs.FileSystem.ResultPathNotFound.Includes(result))
        {
            return(null);
        }
        result.abortUnlessSuccess();

        result = nn.fs.File.Open(ref fileHandle, filePath, nn.fs.OpenFileMode.Read);
        result.abortUnlessSuccess();

        long fileSize = 0;

        result = nn.fs.File.GetSize(ref fileSize, fileHandle);
        result.abortUnlessSuccess();

        byte[] data = new byte[fileSize];
        result = nn.fs.File.Read(fileHandle, 0, data, fileSize);
        result.abortUnlessSuccess();

        nn.fs.File.Close(fileHandle);

        string loadDeta;

        using (MemoryStream stream = new MemoryStream(data))
        {
            BinaryReader reader = new BinaryReader(stream);
            loadDeta = reader.ReadString();
            int version = reader.ReadInt32();
            Debug.Assert(version == saveDataVersion);
        }
        RankingDeta ranking = new RankingDeta();

        char[]   Cut     = { '&', '_', };
        string[] CutDeta = new string[5];

        CutDeta = loadDeta.Split(new char[] { '%' }, System.StringSplitOptions.RemoveEmptyEntries);

        for (int i = 0; i < 5; i++)
        {
            string[] splitDeta = CutDeta[i].Split(Cut, System.StringSplitOptions.RemoveEmptyEntries);
            ranking.name1[i] = splitDeta[0];
            ranking.name2[i] = splitDeta[1];
            ranking.score[i] = int.Parse(splitDeta[2]);
        }

        return(ranking);
    }