Exemplo n.º 1
0
        private void tvwFileList_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode selectedNode = tvwFileList.SelectedNode;

            if ((e.Button != MouseButtons.Left) || (selectedNode == null || selectedNode.Tag == null))
            {
                return;
            }

            // is selected node is a tape, launch the tape in emulator
            if (selectedNode.Tag.GetType() == typeof(TapeInfo))
            {
                mMainForm.LoadTapeInEmulator(Configuration.Persistent.DefaultMachineForTape);
            }
            // is selected node is a disk, launch it in emulator
            else if (selectedNode.Tag.GetType() == typeof(OricDiskInfo))
            {
                // determine the disk type to select the machine for emulator
                OricDiskInfo diskInfo = (OricDiskInfo)selectedNode.Tag;

                switch (diskInfo.DOSFormat)
                {
                case OricDisk.DOSFormats.Unknown:
                    mMainForm.DisplayUnknownDisk(diskInfo);
                    break;

                default:
                    mMainForm.LoadDiskInEmulator();
                    break;
                }
            }
            else if (selectedNode.Tag.GetType() == typeof(OricFileInfo))
            {
                OricProgram.SpecialMode specialMode = OricProgram.SpecialMode.None;
                if (selectedNode.Parent.Tag.GetType() == typeof(OricDiskInfo))
                {
                    OricDiskInfo diskInfo = (OricDiskInfo)(selectedNode.Parent.Tag);
                    specialMode = (diskInfo.DOSFormat == OricDisk.DOSFormats.StratSed ? OricProgram.SpecialMode.Telestrat : OricProgram.SpecialMode.None);
                }

                mMainForm.DisplayFileContents((OricFileInfo)selectedNode.Tag, specialMode);
            }
            else if (selectedNode.Tag.GetType() == typeof(RomInfo))
            {
                mMainForm.DisplayROMContents((RomInfo)selectedNode.Tag);
            }
            else if (selectedNode.Tag.GetType() == typeof(OtherFileInfo))
            {
                mMainForm.DisplayOtherFileContents((OtherFileInfo)selectedNode.Tag);
            }
        }
Exemplo n.º 2
0
        /*private void treeFileList_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
         * {
         *  if (e.Label != null)
         *  {
         *      if (e.Label.Length > 0)
         *      {
         *          if (e.Label.IndexOfAny(new char[] { '@', ',', '!' }) == -1)
         *          {
         *              TreeNode selectedNode = treeFileList.SelectedNode;
         *
         *              if (selectedNode.Tag.GetType().ToString().Equals("OricExplorer.TapeInfo"))
         *              {
         *                  TapeInfo tapeInfo = (TapeInfo)selectedNode.Tag;
         *                  String strFolder = tapeInfo.Folder;
         *
         *                  String sourceFileName = String.Format("{0}\\{1}", strFolder, tapeInfo.Name);
         *                  String destFileName = String.Format("{0}\\{1}", strFolder, e.Label);
         *
         *                  try
         *                  {
         *                      File.Move(sourceFileName, destFileName);
         *
         *                      // Stop editing without canceling the label change.
         *                      e.Node.EndEdit(false);
         *
         *                      // Remove branch
         *                      selectedNode.Remove();
         *
         *                      // Update branch
         *                      FileInfo fiNewFile = new FileInfo(destFileName);
         *                      //TreeNode tapeNode = AddTapeToTree(fiNewFile);
         *
         *                      //treeFileList.SelectedNode = tapeNode;
         *                  }
         *                  catch (Exception ex)
         *                  {
         *                      // Cancel the label edit action, inform the user and place the node in edit mode again.
         *                      e.CancelEdit = true;
         *
         *                      String errorMessage = String.Format("Failed to rename tape\n\n{0}", ex.Message);
         *
         *                      MessageBox.Show(errorMessage, "Tape Rename");
         *                      e.Node.BeginEdit();
         *                  }
         *              }
         *              else if (selectedNode.Tag.GetType().ToString().Equals("OricExplorer.Catalog"))
         *              {
         *                  // Renaming a file. Check if it's a disk or tape file
         *                  Catalog tempFile = (Catalog)selectedNode.Tag;
         *
         *                  if (tempFile.MediaType == OricExplorer.MediaType.TapeFile)
         *                  {
         *                      // Rename Tape file
         *                      // e.Label
         *                  }
         *                  else
         *                  {
         *                      e.CancelEdit = true;
         *                  }
         *              }
         *          }
         *          else
         *          {
         *              // Cancel the label edit action, inform the user and place the node in edit mode again.
         *              e.CancelEdit = true;
         *
         *              MessageBox.Show("Invalid tree node label.\n" + "The invalid characters are: '@','.', ',', '!'", "Node Label Edit");
         *              e.Node.BeginEdit();
         *          }
         *      }
         *      else
         *      {
         *          // Cancel the label edit action, inform the user and place the node in edit mode again.
         *          e.CancelEdit = true;
         *
         *          MessageBox.Show("Invalid tree node label.\nThe label cannot be blank", "Node Label Edit");
         *          e.Node.BeginEdit();
         *      }
         *
         *      treeFileList.LabelEdit = false;
         *  }
         * }*/

        private void treeFileList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode selectedNode = e.Node;

            treeFileList.SelectedNode = selectedNode;

            if ((e.Button != MouseButtons.Left) || (selectedNode == null || selectedNode.Tag == null))
            {
                return;
            }

            String nodeTag = selectedNode.Tag.GetType().ToString();

            switch (nodeTag)
            {
            // Program has been selected so display the hex view/source code
            case "OricExplorer.OricFileInfo":
                pParent.DisplayFileContents((OricFileInfo)selectedNode.Tag);
                break;

            // Disk of Unknown format selected, display file contents
            case "OricExplorer.OricDiskInfo":
                OricDiskInfo diskInfo = (OricDiskInfo)selectedNode.Tag;

                if (diskInfo.DOSFormat == OricDisk.DOSFormats.Unknown)
                {
                    pParent.DisplayUnknownDisk(diskInfo);
                }
                break;

            case "System.String":
                pParent.DisplayROMContents((String)selectedNode.Tag);
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        public bool SaveFile(string diskName, string fileName, OricProgram program, OricDisk disk)
        {
            bool fileSaved = false;

            LoadDisk(diskName);

            // Check if disk has been loaded
            if (DiskLoaded())
            {
                diskInfo = new OricDiskInfo(diskName);

                //ArrayList dir<String, OricFileInfo>
                // Check if file already exists
                OricFileInfo[] diskDirectory = ReadOricDosDirectory();

                int  dirIndex    = 0;
                bool fileMatched = false;

                while (dirIndex < diskDirectory.Length && !fileMatched)
                {
                    if (diskDirectory[dirIndex].ProgramName.Equals(fileName))
                    {
                        fileMatched = true;
                    }

                    dirIndex++;
                }

                if (!fileMatched)
                {
                    nextAvailableTrack  = diskInfo.nextAvailableTrack;
                    nextAvailableSector = diskInfo.nextAvailableSector;

                    int noOfSectors;

                    if (program.ProgramLength < 245)
                    {
                        noOfSectors = 1;
                    }
                    else
                    {
                        int remaining = program.ProgramLength - 245;
                        noOfSectors = remaining / 253;
                    }

                    sectorsFree = (ushort)(diskInfo.SectorsFree - noOfSectors);
                    sectorsUsed = (ushort)(diskInfo.SectorsUsed + noOfSectors);

                    // Write program data
                    WriteProgramData(program);

                    // Update disk directory
                    AddDirectoryEntry(fileName, (ushort)noOfSectors, (byte)nextAvailableTrack, (byte)nextAvailableSector, program.Protection);

                    // Update System sector (free sectors etc)
                    UpdateSystemSector();

                    if (WriteDisk())
                    {
                        MessageBox.Show("Program saved.");
                    }
                    else
                    {
                        MessageBox.Show("Failed to save program");
                    }
                }
            }

            return(fileSaved);
        }