Esempio n. 1
0
        void itemRename_Click(object sender, EventArgs e)
        {
            bool renamedFile = false;

            foreach (ListViewItem item in listFiles.SelectedItems)
            {
                C64Studio.Types.FileInfo fileToRename = (C64Studio.Types.FileInfo)item.Tag;

                FormRenameFile formRename = new FormRenameFile(Core, fileToRename.Filename);

                if (formRename.ShowDialog() == DialogResult.OK)
                {
                    if (m_Media.RenameFile(fileToRename.Filename, formRename.Filename))
                    {
                        renamedFile = true;
                    }
                }
            }
            if (renamedFile)
            {
                RefreshFileView();
                SetModified();
                UpdateStatusInfo();
            }
        }
Esempio n. 2
0
        public bool MoveFileDown(C64Studio.Types.FileInfo File)
        {
            _LastError = "";
            DirEntryLocation dirLocOrig = LocateDirEntry(File.DirEntryIndex);

            if (dirLocOrig == null)
            {
                return(false);
            }
            DirEntryLocation dirLocNext = LocateDirEntry(File.DirEntryIndex + 1);

            if (dirLocNext == null)
            {
                _LastError = "could not find next directory entry";
                return(false);
            }
            Sector secOrig = Tracks[dirLocOrig.Track - 1].Sectors[dirLocOrig.Sector];
            Sector secPrev = Tracks[dirLocNext.Track - 1].Sectors[dirLocNext.Sector];

            // exchange dir entry content
            GR.Memory.ByteBuffer tempData = secOrig.Data.SubBuffer(0x20 * dirLocOrig.DirEntry + 2, 30);
            secPrev.Data.CopyTo(secOrig.Data, 0x20 * dirLocNext.DirEntry + 2, 30, 0x20 * dirLocOrig.DirEntry + 2);
            tempData.CopyTo(secPrev.Data, 0, 30, 0x20 * dirLocNext.DirEntry + 2);
            return(true);
        }
Esempio n. 3
0
        private void DeleteSelectedItems()
        {
            if (listFiles.SelectedItems.Count > 0)
            {
                if (System.Windows.Forms.MessageBox.Show("Do you really want to delete the selected files?", "Delete Files?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    bool deletedFile = false;
                    foreach (ListViewItem item in listFiles.SelectedItems)
                    {
                        C64Studio.Types.FileInfo fileToDelete = (C64Studio.Types.FileInfo)item.Tag;

                        if (m_Media != null)
                        {
                            if (m_Media.DeleteFile(fileToDelete.Filename))
                            {
                                deletedFile = true;
                            }
                        }
                    }
                    if (deletedFile)
                    {
                        RefreshFileView();
                        SetModified();
                        UpdateStatusInfo();
                    }
                }
            }
        }
Esempio n. 4
0
        void ExportSelectedItemsToBASIC()
        {
            foreach (ListViewItem item in listFiles.SelectedItems)
            {
                C64Studio.Types.FileInfo fileToExport = (C64Studio.Types.FileInfo)item.Tag;

                ExportToBASIC(fileToExport);
            }
        }
Esempio n. 5
0
        void OpenSelectedItemsInHexEditor()
        {
            foreach (ListViewItem item in listFiles.SelectedItems)
            {
                C64Studio.Types.FileInfo fileToExport = (C64Studio.Types.FileInfo)item.Tag;

                OpenInHexEditor(fileToExport);
            }
        }
Esempio n. 6
0
        private void listFiles_MouseClick(object sender, MouseEventArgs e)
        {
            if ((e.Button != MouseButtons.Right) ||
                (listFiles.SelectedItems.Count == 0))
            {
                return;
            }
            System.Windows.Forms.ContextMenuStrip contextMenu = new System.Windows.Forms.ContextMenuStrip();

            System.Windows.Forms.ToolStripMenuItem item = new System.Windows.Forms.ToolStripMenuItem("Export");
            item.Tag = 0;
            contextMenu.Items.Add(item);

            System.Windows.Forms.ToolStripMenuItem subItem = new System.Windows.Forms.ToolStripMenuItem("Export to file");
            subItem.Tag    = 0;
            subItem.Click += new EventHandler(itemExport_Click);
            item.DropDownItems.Add(subItem);

            bool exportToBasicPossible = true;

            foreach (ListViewItem listItem in listFiles.SelectedItems)
            {
                C64Studio.Types.FileInfo fileInfo = (C64Studio.Types.FileInfo)listItem.Tag;
                if (fileInfo.Type != C64Studio.Types.FileType.PRG)
                {
                    exportToBasicPossible = false;
                }
            }
            if (exportToBasicPossible)
            {
                subItem        = new System.Windows.Forms.ToolStripMenuItem("Export to Basic code");
                subItem.Tag    = 0;
                subItem.Click += new EventHandler(itemExportToBasic_Click);
                item.DropDownItems.Add(subItem);
            }

            // view in Hex display
            item        = new System.Windows.Forms.ToolStripMenuItem("View in Hex Editor");
            item.Tag    = 2;
            item.Click += new EventHandler(itemViewInHexEditor_Click);
            contextMenu.Items.Add(item);

            item        = new System.Windows.Forms.ToolStripMenuItem("Rename");
            item.Tag    = 2;
            item.Click += new EventHandler(itemRename_Click);
            contextMenu.Items.Add(item);

            item        = new System.Windows.Forms.ToolStripMenuItem("Delete");
            item.Tag    = 1;
            item.Click += new EventHandler(itemDelete_Click);
            contextMenu.Items.Add(item);

            contextMenu.Show(listFiles.PointToScreen(e.Location));
        }
Esempio n. 7
0
        public override List <C64Studio.Types.FileInfo> Files()
        {
            _LastError = "";

            List <C64Studio.Types.FileInfo> files = new List <C64Studio.Types.FileInfo>();

            int  curTrack      = TRACK_DIRECTORY;
            int  curSector     = SECTOR_DIRECTORY;
            bool endFound      = false;
            int  dirEntryIndex = 0;

            if (Tracks.Count < curTrack - 1)
            {
                return(files);
            }

            while (!endFound)
            {
                Sector sec = Tracks[curTrack - 1].Sectors[curSector];

                for (int i = 0; i < 8; ++i)
                {
                    int fileTrack  = sec.Data.ByteAt(0x20 * i + 3);
                    int fileSector = sec.Data.ByteAt(0x20 * i + 4);
                    if (sec.Data.ByteAt(0x20 * i + 2) != (byte)C64Studio.Types.FileType.SCRATCHED)
                    {
                        // valid entry?
                        C64Studio.Types.FileInfo info = new C64Studio.Types.FileInfo();

                        info.Filename      = sec.Data.SubBuffer(0x20 * i + 5, 16);
                        info.StartSector   = fileSector;
                        info.StartTrack    = fileTrack;
                        info.Type          = (C64Studio.Types.FileType)sec.Data.ByteAt(0x20 * i + 2);
                        info.Blocks        = sec.Data.ByteAt(0x20 * i + 30) + 256 * sec.Data.ByteAt(0x20 * i + 31);
                        info.DirEntryIndex = dirEntryIndex;
                        ++dirEntryIndex;
                        files.Add(info);
                    }
                }

                curTrack  = sec.Data.ByteAt(0);
                curSector = sec.Data.ByteAt(1);

                if (curTrack == 0)
                {
                    // track = 0 marks last directory entry
                    endFound = true;
                }
            }
            return(files);
        }
Esempio n. 8
0
        void OpenInHexEditor(C64Studio.Types.FileInfo FileToImport)
        {
            C64Studio.Types.FileInfo fileInfo = null;

            if (m_Media != null)
            {
                fileInfo = m_Media.LoadFile(FileToImport.Filename);
            }
            if (fileInfo != null)
            {
                BinaryDisplay display = new BinaryDisplay(Core, fileInfo.Data, false, true);
                display.Show(Core.MainForm.panelMain, DockState.Float);
            }
        }
Esempio n. 9
0
        bool LocateFile(GR.Memory.ByteBuffer Filename, out Location FileLocation, out Types.FileInfo FileInfo)
        {
            _LastError   = "";
            FileLocation = null;
            FileInfo     = null;

            Location curLoc = new Location(TRACK_DIRECTORY, SECTOR_DIRECTORY);

            bool endFound = false;

            while (!endFound)
            {
                Sector sec = Tracks[curLoc.Track - 1].Sectors[curLoc.Sector];

                for (int i = 0; i < 8; ++i)
                {
                    int fileTrack  = sec.Data.ByteAt(0x20 * i + 3);
                    int fileSector = sec.Data.ByteAt(0x20 * i + 4);
                    if (fileTrack != 0)
                    {
                        // valid entry?
                        if (sec.Data.ByteAt(0x20 * i + 2) != (byte)C64Studio.Types.FileType.SCRATCHED)
                        {
                            GR.Memory.ByteBuffer filename = sec.Data.SubBuffer(0x20 * i + 5, 16);
                            if (Filename.Compare(filename) == 0)
                            {
                                FileLocation = new Location(fileTrack, fileSector);

                                FileInfo             = new C64Studio.Types.FileInfo();
                                FileInfo.Filename    = new GR.Memory.ByteBuffer(filename);
                                FileInfo.StartSector = fileSector;
                                FileInfo.StartTrack  = fileTrack;
                                FileInfo.Type        = (C64Studio.Types.FileType)sec.Data.ByteAt(0x20 * i + 2);
                                FileInfo.Blocks      = 0;
                                return(true);
                            }
                        }
                    }
                }

                curLoc = sec.NextLocation;
                if (curLoc == null)
                {
                    // track = 0 marks last directory entry
                    break;
                }
            }
            _LastError = "Could not locate directory entry for file";
            return(false);
        }
Esempio n. 10
0
        private void ExportToBASIC(Types.FileInfo fileToExport, C64Models.BASIC.Dialect Dialect)
        {
            C64Studio.Types.FileInfo fileInfo = null;

            if (m_Media != null)
            {
                fileInfo = m_Media.LoadFile(fileToExport.Filename);
            }
            if (fileInfo != null)
            {
                if (fileInfo.Data.Length >= 2)
                {
                    //if ( startAddress == 0x0801 )
                    {
                        // can only load from that address

                        List <string> lines;

                        // trunc load address
                        var parser = new Parser.BasicFileParser(new Parser.BasicFileParser.ParserSettings());
                        parser.SetBasicDialect(Dialect);
                        if (parser.Disassemble(fileInfo.Data.SubBuffer(2), out lines))
                        {
                            var document = new SourceBasicEx(Core);
                            document.ShowHint = DockState.Document;

                            document.Core = Core;
                            document.Show(Core.MainForm.panelMain);
                            document.SetBASICDialect(Dialect);

                            StringBuilder sb = new StringBuilder();
                            foreach (string line in lines)
                            {
                                sb.AppendLine(line);
                            }
                            document.FillContent(sb.ToString(), false);
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        private void ChangeFileType(FileType NewFileType)
        {
            bool changedType = false;

            foreach (ListViewItem item in listFiles.SelectedItems)
            {
                C64Studio.Types.FileInfo fileToChange = (C64Studio.Types.FileInfo)item.Tag;
                if (fileToChange.Type != NewFileType)
                {
                    m_Media.ChangeFileType(fileToChange, NewFileType);
                    changedType = true;
                }
            }

            if (changedType)
            {
                RefreshFileView();
                SetModified();
                UpdateStatusInfo();
            }
        }
Esempio n. 12
0
        public List <string> CheckForErrors()
        {
            List <string> errors = new List <string>();

            GR.Collections.Map <GR.Generic.Tupel <int, int>, GR.Memory.ByteBuffer> usedSectors = new GR.Collections.Map <GR.Generic.Tupel <int, int>, GR.Memory.ByteBuffer>();

            int  curTrack  = TRACK_DIRECTORY;
            int  curSector = SECTOR_DIRECTORY;
            bool endFound  = false;

            while (!endFound)
            {
                Sector sec = Tracks[curTrack - 1].Sectors[curSector];

                for (int i = 0; i < 8; ++i)
                {
                    int fileTrack  = sec.Data.ByteAt(0x20 * i + 3);
                    int fileSector = sec.Data.ByteAt(0x20 * i + 4);
                    if (sec.Data.ByteAt(0x20 * i + 2) != (byte)C64Studio.Types.FileType.SCRATCHED)
                    {
                        // valid entry?
                        C64Studio.Types.FileInfo info = new C64Studio.Types.FileInfo();

                        FollowChain(fileTrack, fileSector, usedSectors, info.Filename, errors);
                    }
                }

                curTrack  = sec.Data.ByteAt(0);
                curSector = sec.Data.ByteAt(1);

                if (curTrack == 0)
                {
                    // track = 0 marks last directory entry
                    endFound = true;
                }
            }

            return(errors);
        }
Esempio n. 13
0
        private void UpdateStatusInfo()
        {
            if (m_Media == null)
            {
                saveToolStripMenuItem.Enabled           = false;
                saveasToolStripMenuItem.Enabled         = false;
                validateMediumToolStripMenuItem.Enabled = false;
            }
            else
            {
                saveToolStripMenuItem.Enabled           = Modified;
                saveasToolStripMenuItem.Enabled         = true;
                validateMediumToolStripMenuItem.Enabled = true;
            }

            if (listFiles.SelectedItems.Count == 0)
            {
                if ((m_Media is Formats.D64) ||
                    (m_Media is Formats.D71) ||
                    (m_Media is Formats.D81))
                {
                    statusFileManager.Text = m_Media.FreeSlots.ToString() + "/" + m_Media.Slots.ToString() + " blocks free"
                                             + "  " + listFiles.Items.Count + " files";
                    return;
                }
                if (m_Media != null)
                {
                    statusFileManager.Text = m_Media.FreeSlots.ToString() + "/" + m_Media.Slots.ToString() + " files free"
                                             + "  " + listFiles.Items.Count + " files";
                    return;
                }
                statusFileManager.Text = "No media opened";
                return;
            }
            C64Studio.Types.FileInfo file = (C64Studio.Types.FileInfo)listFiles.SelectedItems[0].Tag;

            statusFileManager.Text = Util.FilenameToUnicode(file.Filename) + " " + file.Blocks.ToString() + " blocks";
        }
Esempio n. 14
0
        private void ExportSelectedItems()
        {
            foreach (ListViewItem item in listFiles.SelectedItems)
            {
                C64Studio.Types.FileInfo fileToExport = (C64Studio.Types.FileInfo)item.Tag;
                C64Studio.Types.FileInfo fileInfo     = null;

                if (m_Media != null)
                {
                    fileInfo = m_Media.LoadFile(fileToExport.Filename);
                }
                if (fileInfo != null)
                {
                    System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog();

                    string readableFilename = Util.FilenameToReadableUnicode(fileToExport.Filename).TrimEnd();

                    char[] invalidChars = System.IO.Path.GetInvalidFileNameChars();
                    foreach (char invChar in invalidChars)
                    {
                        readableFilename = readableFilename.Replace(invChar, '_');
                    }

                    saveDlg.Title    = "Select target file name for " + readableFilename;
                    saveDlg.Filter   = "All Files|*.*";
                    saveDlg.FileName = readableFilename;
                    if (fileToExport.Type == C64Studio.Types.FileType.PRG)
                    {
                        saveDlg.FileName += ".prg";
                    }
                    if (saveDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        GR.IO.File.WriteAllBytes(saveDlg.FileName, fileInfo.Data);
                    }
                }
            }
        }