Example #1
0
 private void SetAllocateController()
 {
     AllocationController    = new DataController[2];
     AllocationController[0] = DiskImage.GetDataControllerForWrite(AllocationTableStart);
     if (DiskType.IsNot2D)
     {
         AllocationController[1] = DiskImage.GetDataControllerForWrite(AllocationTableStart + 1);
     }
 }
Example #2
0
        public void ReadOrFormat()
        {
            if (!DiskImage.Read())
            {
                FormatDisk();
                return;
            }

            SetParameter(false);
        }
Example #3
0
        public bool WriteStream(Stream fs, int StartCluster, int Filesize)
        {
            Log.Info("StartCluster:" + StartCluster.ToString());

            int Size = Filesize;
            int c    = StartCluster;

            while (true)
            {
                var s          = c * ClusterPerSector;
                var LastSector = 0;
                for (var sc = 0; sc < ClusterPerSector; sc++, s++)
                {
                    var Length = Size < DefaultSectorBytes ? Size : DefaultSectorBytes;
                    DiskImage.GetSector(s).Fill(0x00);
                    if (Size == 0)
                    {
                        continue;
                    }

                    var SectorBuffer = DiskImage.GetSectorDataForWrite(s);
                    fs.Read(SectorBuffer, 0, Length);
                    Size -= Length;
                    if (Length > 0)
                    {
                        LastSector = sc;
                    }
                }
                if (Size == 0)
                {
                    if (Setting.X1SMode && LastSector > 0)
                    {
                        LastSector--;
                        if ((Filesize & 0xff) == 0)
                        {
                            LastSector++;
                        }
                    }
                    SetClusterValue(c, LastSector, true);
                    break;
                }
                var next = GetNextFreeCluster(2);
                if (next < 0)
                {
                    Log.Error($"Too big filesize!: LastClaster={c}");
                    SetClusterValue(c, LastSector, true);
                    return(false);
                }
                SetClusterValue(c, next);
                c = next;
            }

            return(true);
        }
Example #4
0
        private HuFileEntry GetFileEntry(string Filename, int EntrySector)
        {
            int Sector = EntrySector;

            Filename = Filename.ToUpper();
            // 名前
            string Name = Path.GetFileNameWithoutExtension(Filename);

            if (Name.Length > HuFileEntry.MaxNameLength)
            {
                Name = Name.Substring(0, HuFileEntry.MaxNameLength);
            }

            // 拡張子
            string Extension = Path.GetExtension(Filename);

            if (Extension.Length > 0)
            {
                Extension = Extension.Substring(1);
            }
            if (Extension.Length > HuFileEntry.MaxExtensionLength)
            {
                Extension = Extension.Substring(0, HuFileEntry.MaxExtensionLength);
            }

            Filename = Name + "." + Extension;

            for (int i = 0; i < ClusterPerSector; i++, Sector++)
            {
                var dc = DiskImage.GetDataControllerForRead(Sector);

                for (var j = 0; j < EntriesInSector; j++)
                {
                    int pos  = (j * FileEntrySize);
                    var mode = dc.GetByte(pos);
                    if (mode == EntryEnd)
                    {
                        return(null);
                    }

                    string EntryName      = TextEncoding.GetString(dc.Copy(pos + 0x01, HuFileEntry.MaxNameLength)).TrimEnd((Char)0x20);
                    string EntryExtension = TextEncoding.GetString(dc.Copy(pos + 0x0e, HuFileEntry.MaxExtensionLength)).TrimEnd((Char)0x20);
                    string EntryFilename  = (EntryName + "." + EntryExtension).ToUpper();
                    if (Filename != EntryFilename)
                    {
                        continue;
                    }

                    return(GetEntry(dc, Sector, pos));
                }
            }
            return(null);
        }
Example #5
0
        // ファイルエントリ書き出し
        public void WriteFileEntry(HuFileEntry fe)
        {
            FileEntryNormalize(fe);
            var dc = DiskImage.GetDataControllerForWrite(fe.EntrySector);

            WriteEntry(dc, fe, fe.EntryPosition, fe.StartCluster, false);

            if (fe.IsIplEntry)
            {
                WriteIplEntry(fe);
            }
        }
Example #6
0
        public HuBasicDiskEntry(Context Context)
        {
            DiskImage = new DiskImage(Context);
            Setting   = Context.Setting;

            DiskType     = Setting.DiskType;
            ImageType    = Setting.DiskType.GetImageType();
            TextEncoding = Context.TextEncoding;

            Log = Context.Log;
            if (Setting.FormatImage)
            {
                FormatDisk();
            }
            else
            {
                ReadOrFormat();
            }
        }
Example #7
0
        private HuFileEntry GetNewFileEntry(int Sector)
        {
            for (int i = 0; i < ClusterPerSector; i++)
            {
                var dc = DiskImage.GetDataControllerForRead(Sector + i);
                for (var j = 0; j < EntriesInSector; j++)
                {
                    int pos  = (j * FileEntrySize);
                    var mode = dc.GetByte(pos);
                    if (mode != EntryEnd && mode != EntryDelete)
                    {
                        continue;
                    }

                    return(new HuFileEntry {
                        EntrySector = Sector + i,
                        EntryPosition = pos
                    });
                }
            }
            return(null);
        }
Example #8
0
        private void FillAllocationTable()
        {
            var dc = DiskImage.GetDataControllerForWrite(AllocationTableStart);

            dc.Fill(0);
            dc.SetByte(0, 0x01);
            dc.SetByte(1, 0x8f);

            switch (ImageType)
            {
            case DiskTypeEnum.Disk2D:
                for (var i = 0x50; i < 0x80; i++)
                {
                    dc.SetByte(i, 0x8f);
                }
                break;

            case DiskTypeEnum.Disk2DD:
                dc.SetBuffer(DiskImage.GetSectorDataForWrite(AllocationTableStart + 1));
                dc.Fill(0);
                for (var i = 0x20; i < 0x80; i++)
                {
                    dc.SetByte(i, 0x8f);
                }
                break;

            case DiskTypeEnum.Disk2HD:
                dc.SetByte(2, 0x8f);
                dc.SetBuffer(DiskImage.GetSectorDataForWrite(AllocationTableStart + 1));
                dc.Fill(0);
                for (var i = 0x7a; i < 0x80; i++)
                {
                    dc.SetByte(i, 0x8f);
                }
                break;
            }
            FormatEntry(CurrentEntrySector);
        }
Example #9
0
        public List <HuFileEntry> GetEntriesFromSector(int Sector)
        {
            List <HuFileEntry> FileList = new List <HuFileEntry>();

            for (int i = 0; i < ClusterPerSector; i++, Sector++)
            {
                var dc = DiskImage.GetDataControllerForRead(Sector);
                for (var j = 0; j < 8; j++)
                {
                    int pos  = (j * 0x20);
                    var mode = dc.GetByte(pos);
                    if (mode == EntryEnd)
                    {
                        return(FileList);
                    }
                    if (mode == EntryDelete)
                    {
                        continue;
                    }
                    FileList.Add(GetEntry(dc, Sector, pos));
                }
            }
            return(FileList);
        }
Example #10
0
 public void FormatDisk()
 {
     DiskImage.Format();
     SetParameter(true);
 }
Example #11
0
 public void WriteImage()
 {
     DiskImage.Write();
 }
Example #12
0
        // IPLエントリ書き出し
        public void WriteIplEntry(HuFileEntry fe)
        {
            var dc = DiskImage.GetDataControllerForWrite(0);

            WriteEntry(dc, fe, 0x00, fe.StartCluster * ClusterPerSector, true);
        }
Example #13
0
        /// <summary>
        /// ファイル展開
        /// </summary>
        public void ExtractFile(Stream fs, HuFileEntry fe)
        {
            int StartCluster = fe.StartCluster;
            int Size         = fe.Size;

            bool AsciiMode = fe.IsAscii;

            int c        = StartCluster;
            int LeftSize = Size;

            int TotalOutputBytes = 0;

            bool SectorWriteMode = Size == 0;

            if (Setting.ForceAsciiMode)
            {
                AsciiMode = true;
            }
            if (Setting.ForceBinaryMode)
            {
                AsciiMode = false;
            }

            while (true)
            {
                var end  = IsEndCluster(c);
                var next = GetClusterValue(c);
                if (next == 0x00)
                {
                    Log.Warning("WARNING: Wrong cluster chain!!");
                    break;
                }
                // セクタ数
                var SectorCount = end ? (next & 0x0f) + 1 : ClusterPerSector;

                for (var i = 0; i < SectorCount; i++)
                {
                    var CurrentSector = (c * ClusterPerSector) + i;
                    var Sector        = DiskImage.GetSector(CurrentSector);

                    var Data = Sector.Data;
                    var Eof  = false;
                    if (AsciiMode)
                    {
                        var AsciiData = ConvertAscii(Sector.Data);
                        Eof  = AsciiData.Eof;
                        Data = AsciiData.Data;
                    }

                    Log.Verbose($"Cluster:{c} Sector:{CurrentSector} Position:0x{Sector.Position:X}");

                    var OutputBytes = Data.Length;

                    // セクタ書き込みモード
                    if (!SectorWriteMode)
                    {
                        // セクタサイズか残りのバイト数を書き出す
                        if (LeftSize < OutputBytes)
                        {
                            OutputBytes = LeftSize;
                        }
                        LeftSize -= OutputBytes;
                    }

                    fs.Write(Data, 0, OutputBytes);
                    TotalOutputBytes += OutputBytes;

                    // 次のクラスタに進む
                    if (Eof)
                    {
                        break;
                    }
                }
                if (end)
                {
                    break;
                }
                c = next;
            }
        }