/// <summary> /// Override this method to define the status query action /// </summary> /// <param name="mc"></param> protected override void OnQueryStatus(OleMenuCommand mc) { base.OnQueryStatus(mc); if (!mc.Visible) { return; } if (!(Package.MachineViewModel.SpectrumVm.FloppyDevice is FloppyDevice floppyDevice)) { mc.Visible = false; return; } mc.Visible = string.Compare(floppyDevice.DriveAFloppy?.Filename, ItemPath, StringComparison.InvariantCultureIgnoreCase) != 0 && string.Compare(floppyDevice.DriveBFloppy?.Filename, ItemPath, StringComparison.InvariantCultureIgnoreCase) != 0; if (!mc.Visible) { return; } mc.Text = VirtualFloppyFile.CheckWriteProtection(ItemPath) ? "Remove write protection" : "Make write protected"; }
/// <summary> /// Override this method to define the async command body te execute on the /// background thread /// </summary> protected override Task ExecuteAsync() { var currentProtection = VirtualFloppyFile.CheckWriteProtection(ItemPath); VirtualFloppyFile.SetWriteProtection(ItemPath, !currentProtection); return(Task.FromResult(0)); }
public void OpeningANonExistingFloppyFileFails() { // --- Arrange File.Delete(TestFile); // --- Act VirtualFloppyFile.OpenFloppyFile(TestFile); }
public void InvalidReadParameterRaisesError(int head, int track, int sector, int length) { // --- Arrange var floppy = VirtualFloppyFile.CreateSpectrumFloppyFile(TestFile); // --- Act floppy.ReadData(head, track, sector, length); }
public void CreatingAFloppyFileWorksAsExpected() { // --- Act VirtualFloppyFile.CreateSpectrumFloppyFile(TestFile); // --- Assert VirtualFloppyFile.OpenFloppyFile(TestFile); }
public void InvalidWriteParameterRaisesError(int head, int track, int sector, int length) { // --- Arrange var floppy = VirtualFloppyFile.CreateSpectrumFloppyFile(TestFile); var data = new byte[length]; // --- Act floppy.WriteData(head, track, sector, data); }
public void OpenOrCreateCreatesANewFile() { // --- Arrange File.Delete(TestFile); // --- Act VirtualFloppyFile.OpenOrCreateFloppyFile(TestFile); // --- Assert VirtualFloppyFile.OpenFloppyFile(TestFile); }
public void OpenOrCreateOpensAnExistingNewFile() { // --- Arrange var floppy = VirtualFloppyFile.CreateSpectrumFloppyFile(TestFile); var data = new byte[] { 0x01, 0x02, 0x03, 0x04 }; floppy.WriteData(1, 3, 5, data); // --- Act floppy = VirtualFloppyFile.OpenOrCreateFloppyFile(TestFile); // --- Assert var dataBack = floppy.ReadData(1, 3, 5, data.Length); dataBack.SequenceEqual(data).ShouldBeTrue(); }
/// <summary> /// Sets the active project to the current project file /// </summary> protected async override Task ExecuteAsync() { // --- Collect export parameters from the UI await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (DisplayCreateVfddDialog(out var vm)) { return; } // --- Create a temporary file string fullPath; try { var filename = Path.ChangeExtension(Path.GetFileName(vm.Filename), ".vfdd"); var userPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); fullPath = Path.Combine(Path.Combine(userPath, "SpectNetFloppies"), filename); VirtualFloppyFile.CreateSpectrumFloppyFile(fullPath, vm.Format); } catch (Exception ex) { VsxDialogs.Show($"Error: {ex.Message}", "Error creating virtual floppy disk file"); return; } // --- Add the temp file to the project SpectrumProject.AddFileToProject(SpectNetPackage.Default.Options.VfddFolder, fullPath, INVALID_FOLDER_MESSAGE, FILE_EXISTS_MESSAGE); // --- Remove the temp file try { File.Delete(fullPath); } catch (Exception) { // --- This exception is intentionally ignored } }
/// <summary> /// Execute loading and processing the file /// </summary> /// <param name="fileName"></param> protected override void LoadFile(string fileName) { _loadPath = fileName; _vm = new VfddEditorViewModel(); try { var floppyFile = VirtualFloppyFile.OpenFloppyFile(fileName); _vm.IsValidFormat = true; switch (floppyFile.DiskFormat) { case FloppyFormat.SpectrumP3: _vm.DiskFormat = "Spectrum +3"; break; case FloppyFormat.CpcData: _vm.DiskFormat = "Amstrad CPC data only"; break; case FloppyFormat.CpcSystem: _vm.DiskFormat = "Amstrad CPC system"; break; case FloppyFormat.Pcw: _vm.DiskFormat = "Standard PCW range"; break; default: _vm.DiskFormat = "Unknown"; break; } switch (floppyFile.FormatSpec[1] & 0xFF) { case 0: _vm.Sideness = "Single sided"; break; case 1: _vm.Sideness = "Double sided (alternating sides)"; break; default: _vm.Sideness = "Double sided (successive sides)"; break; } _vm.TracksPerSide = floppyFile.Tracks; _vm.SectorsPerTrack = floppyFile.SectorsPerTrack; _vm.SectorSize = 1 << (floppyFile.FormatSpec[4] + 7); _vm.ReservedTracks = floppyFile.FormatSpec[5]; _vm.BlockSize = 1 << (floppyFile.FormatSpec[6] + 7); _vm.DirectoryBlocks = floppyFile.FormatSpec[7]; _vm.ReadWriteGapLength = floppyFile.FormatSpec[8]; _vm.FormatGapLength = floppyFile.FormatSpec[9]; var capacity = floppyFile.Tracks * (floppyFile.IsDoubleSided ? 2 : 1) * floppyFile.SectorsPerTrack * _vm.SectorSize / 1024; _vm.Capacity = $"{capacity} KBytes"; } catch (Exception) { _vm.IsValidFormat = false; } }