Ejemplo n.º 1
0
        public void Add(short handle, DosStream stream, VirtualFileInfo fileInfo, bool overwrite = false)
        {
            stream.FileInfo = fileInfo;

            if (fileInfo != null)
            {
                unsafe
                {
                    if (stream.SFTIndex == -1)
                    {
                        if (this.sftFileCount >= this.maxFiles)
                        {
                            throw new InvalidOperationException("Maximum number of open files exceeded.");
                        }

                        stream.SFTIndex = this.sftFileCount;
                        var entry = &this.entries[this.sftFileCount];

                        this.sftFileCount++;

                        entry->RefCount                  = 1;
                        entry->FileOpenMode              = 0;
                        entry->FileAttribute             = fileInfo.DosAttributes;
                        entry->DeviceInfo                = 0;
                        entry->StartingCluster           = 0;
                        entry->FileTime                  = fileInfo.DosModifyTime;
                        entry->FileDate                  = fileInfo.DosModifyDate;
                        entry->FileSize                  = fileInfo.DosLength;
                        entry->CurrentOffset             = 0;
                        entry->RelativeClusterLastAccess = 0;
                        entry->DirectoryEntrySector      = 0;
                        entry->DirectoryEntry            = 0;

                        var fcbName = GetFCBName(fileInfo.Name);
                        for (int i = 0; i < 11; i++)
                        {
                            entry->FileName[i] = (byte)fcbName[i];
                        }
                    }
                    else
                    {
                        var entry = &this.entries[stream.SFTIndex];
                        entry->RefCount++;
                    }
                }
            }

            if (!overwrite)
            {
                this.fileHandles.Add(handle, stream);
            }
            else
            {
                this.fileHandles[handle] = stream;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds file handles for StdIn, StdOut, and StdErr.
        /// </summary>
        private void AddDefaultHandles()
        {
            var stdin  = new DosStream(vm.ConsoleIn, 0);
            var stdout = new DosStream(vm.ConsoleOut, 0);

            stdout.AddReference();

            var stdaux = new DosStream(NullStream.Instance, 0);

            stdaux.AddReference();

            this.fileHandles.AddSpecial(StdInHandle, stdin);
            this.fileHandles.AddSpecial(StdOutHandle, stdout);
            this.fileHandles.AddSpecial(StdErrHandle, stdout);
            this.fileHandles.AddSpecial(StdAuxHandle, stdaux);
            this.fileHandles.AddSpecial(StdPrnHandle, stdaux);
        }
Ejemplo n.º 3
0
 public void AddSpecial(short handle, DosStream stream)
 {
     this.fileHandles.Add(handle, stream);
 }
Ejemplo n.º 4
0
 public bool TryGetValue(short handle, out DosStream stream)
 {
     return(this.fileHandles.TryGetValue(handle, out stream));
 }