예제 #1
0
        public void RefreshFileView()
        {
            int offset = 0;

            if (listFiles.TopItem != null)
            {
                offset = listFiles.TopItem.Index;
            }
            var origSelections = new List <int>();

            foreach (int entry in listFiles.SelectedIndices)
            {
                origSelections.Add(entry);
            }

            listFiles.BeginUpdate();
            listFiles.Items.Clear();

            List <Types.FileInfo> files = null;

            if (m_Media != null)
            {
                labelMediaTitle.Text = Util.PETSCIIToUnicode(m_Media.Title);
                files = m_Media.Files();
            }
            else
            {
                labelMediaTitle.Text = "";
            }
            if (files != null)
            {
                foreach (Types.FileInfo file in files)
                {
                    ByteBuffer displayFilename = new ByteBuffer(file.Filename);

                    // map to PETSCII range
                    byte previousByte = 0;
                    for (int i = 0; i < displayFilename.Length; ++i)
                    {
                        byte singleByte = displayFilename.ByteAt(i);
                        var  c64Char    = ConstantData.FindC64KeyByPETSCII(singleByte);
                        if (c64Char == null)
                        {
                            // re-use the previous byte?
                            c64Char = ConstantData.FindC64KeyByPETSCII(0x9d);
                        }
                        else
                        {
                            previousByte = singleByte;
                        }
                        if (c64Char != null)
                        {
                            displayFilename.SetU8At(i, c64Char.PetSCIIValue);
                        }
                        else
                        {
                            Debug.Log("Unsupported PETSCII value " + singleByte);
                        }
                    }
                    string filename = Util.FilenameToUnicode(displayFilename);

                    ListViewItem item = new ListViewItem(filename);
                    item.SubItems.Add(file.Blocks.ToString());
                    string fileType = "";

                    if ((file.Type & Types.FileType.CLOSED) != 0)
                    {
                        switch ((Types.FileType)((byte)file.Type & (0x0f | (byte)Types.FileType.CLOSED)))
                        {
                        case Types.FileType.DEL:
                            fileType = "DEL";
                            break;

                        case Types.FileType.PRG:
                            fileType = "PRG";
                            break;

                        case Types.FileType.REL:
                            fileType = "REL";
                            break;

                        case Types.FileType.SEQ:
                            fileType = "SEQ";
                            break;

                        case Types.FileType.USR:
                            fileType = "USR";
                            break;
                        }
                    }


                    if ((file.Type & RetroDevStudio.Types.FileType.CLOSED) == 0)
                    {
                        fileType += "*";
                    }
                    if ((file.Type & RetroDevStudio.Types.FileType.LOCKED) != 0)
                    {
                        fileType += "<";
                    }
                    item.SubItems.Add(fileType);
                    item.SubItems.Add(file.StartTrack.ToString());
                    item.SubItems.Add(file.StartSector.ToString());
                    item.Tag = file;

                    listFiles.Items.Add(item);
                }

                foreach (int entry in origSelections)
                {
                    listFiles.SelectedIndices.Add(entry);
                }
            }
            listFiles.EndUpdate();
            if (offset < listFiles.Items.Count)
            {
                listFiles.TopItem = listFiles.Items[offset];
            }
        }