Ejemplo n.º 1
0
        private void WriteEntry(DataController dc, HuFileEntry fe, int pos, int start, bool ipl)
        {
            dc.Fill(0x20, pos + 0x01, HuFileEntry.MaxNameLength);
            dc.Fill(0x20, pos + 0x0e, HuFileEntry.MaxExtensionLength);

            if (ipl)
            {
                WriteIplName(dc, pos);
            }
            else
            {
                WriteEntryName(dc, fe, pos);
            }
            dc.SetByte(pos + 0x11, fe.Password);

            dc.SetWord(pos + 0x12, fe.Size);
            dc.SetWord(pos + 0x14, fe.LoadAddress);
            dc.SetWord(pos + 0x16, fe.ExecuteAddress);
            dc.SetCopy(pos + 0x18, fe.DateTimeData);

            // 最上位は未調査
            dc.SetByte(pos + 0x1d, (start >> 14) & 0x7f);
            dc.SetByte(pos + 0x1e, start & 0x7f);
            dc.SetByte(pos + 0x1f, (start >> 7) & 0x7f);
        }
Ejemplo n.º 2
0
        private HuFileEntry AddEntry(string EntryFilename, int Size, DateTime FileDate)
        {
            HuFileEntry fe = MakeFileEntry(EntryFilename, Size, FileDate);

            if (fe == null)
            {
                Log.Error("ERROR:No entry space!");
                return(null);
            }

            var fc = DiskEntry.GetFreeCluster(fe);

            if (fc < 0)
            {
                Log.Error("ERROR:No free cluster!");
                return(null);
            }
            fe.StartCluster = fc;
            fe.IsIplEntry   = IplEntry;

            DiskEntry.WriteFileEntry(fe);

            // ファイルをIPL設定する
            if (IplEntry)
            {
                Log.Info($"IPL Name:{Setting.IplName}");
                IplEntry = false;
            }

            return(fe);
        }
Ejemplo n.º 3
0
        public HuFileEntry GetEntry(DataController dc, int sector, int pos)
        {
            var    fe        = new HuFileEntry();
            string Name      = TextEncoding.GetString(dc.Copy(pos + 0x01, HuFileEntry.MaxNameLength)).TrimEnd((Char)0x20);
            string Extension = TextEncoding.GetString(dc.Copy(pos + 0x0e, HuFileEntry.MaxExtensionLength)).TrimEnd((Char)0x20);

            fe.SetEntryFromSector(dc, sector, pos, Name, Extension);
            return(fe);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ファイル展開
        /// </summary>
        /// <param name="OutputFilename"></param>
        /// <param name="fe"></param>
        private void ExtractFile(string OutputFilename, HuFileEntry fe)
        {
            // 出力ストリーム選択
            using (Stream fs = SelectOutputStream(OutputFilename)) {
                DiskEntry.ExtractFile(fs, fe);

                //Extract(fs, fe);
                fs.Close();
            }
        }
Ejemplo n.º 5
0
 public int GetFreeCluster(HuFileEntry fe)
 {
     if (Setting.IplMode)
     {
         int Cluster = (fe.Size / (ClusterPerSector * DefaultSectorBytes)) + 1;
         return(GetNextFreeSerialCluster(Cluster));
     }
     else
     {
         return(GetNextFreeCluster());
     }
 }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
 private void FileEntryNormalize(HuFileEntry fe)
 {
     if (fe.Name.Length > HuFileEntry.MaxNameLength)
     {
         fe.Name = fe.Name.Substring(0, HuFileEntry.MaxNameLength);
     }
     if (fe.Extension.StartsWith("."))
     {
         fe.Extension = fe.Extension.Substring(1);
     }
     if (fe.Extension.Length > HuFileEntry.MaxExtensionLength)
     {
         fe.Extension = fe.Extension.Substring(0, HuFileEntry.MaxExtensionLength);
     }
 }
Ejemplo n.º 8
0
 private void WriteEntryName(DataController dc, HuFileEntry fe, int pos)
 {
     dc.SetByte(pos, fe.FileMode);
     dc.SetCopy(pos + 0x01, TextEncoding.GetBytes(fe.Name));
     dc.SetCopy(pos + 0x0e, TextEncoding.GetBytes(fe.Extension));
 }
Ejemplo n.º 9
0
        // IPLエントリ書き出し
        public void WriteIplEntry(HuFileEntry fe)
        {
            var dc = DiskImage.GetDataControllerForWrite(0);

            WriteEntry(dc, fe, 0x00, fe.StartCluster * ClusterPerSector, true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// ファイルの削除
        /// </summary>

        public void Delete(HuFileEntry fe)
        {
            fe.SetDelete();
            WriteFileEntry(fe);
            RemoveAllocation(fe.StartCluster);
        }
Ejemplo n.º 11
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;
            }
        }