//Read a Memory Card from DexDrive (return null if there was an error) public static async Task <byte[]> readMemoryCardDexDrive(Window hostWindow, string applicationName, string comPort) { //Initialize DexDrive string errorString = dexDevice.StartDexDrive(comPort); //Check if there were any errors if (errorString != null) { //Display an error message and cleanly close DexDrive communication var messageBoxCustomWindow = MessageBox.Avalonia.MessageBoxManager .GetMessageBoxCustomWindow(new MessageBoxCustomParams { Style = Style.DarkMode, CanResize = true, MaxWidth = 800, ContentTitle = applicationName, ContentMessage = errorString, ButtonDefinitions = new [] { new ButtonDefinition { Name = "OK" }, }, WindowStartupLocation = WindowStartupLocation.CenterOwner }); await messageBoxCustomWindow.ShowDialog(hostWindow); dexDevice.StopDexDrive(); return(null); } var vm = new CardReaderWindowViewModel() { //Set scale for progress bar Maximum = 1024, //Set current device to DexDrive currentDeviceIdentifier = 0, //Set window title and information Title = "DexDrive communication", Info = "Reading data from DexDrive (ver. " + dexDevice.GetFirmwareVersion() + ")..." }; //Start reading data vm.backgroundReader = new BackgroundWorker(); vm.backgroundReader.ProgressChanged += vm.backgroundReader_ProgressChanged; vm.backgroundReader.DoWork += vm.backgroundReader_DoWork; vm.backgroundReader.RunWorkerCompleted += vm.backgroundReader_RunWorkerCompleted; vm.backgroundWriter = new BackgroundWorker(); vm.backgroundWriter.ProgressChanged += vm.backgroundWriter_ProgressChanged; vm.backgroundWriter.DoWork += vm.backgroundWriter_DoWork; vm.backgroundWriter.RunWorkerCompleted += vm.backgroundWriter_RunWorkerCompleted; vm.backgroundReader.RunWorkerAsync(); window = new CardReaderWindow(); window.DataContext = vm; await window.ShowDialog(hostWindow); //Stop working with DexDrive dexDevice.StopDexDrive(); //Check the final status (return data if all is ok, otherwise return null) if (vm.sucessfullRead == true) { return(vm.completeMemoryCard); } else { return(null); } }
//Write a Memory Card to PS1CardLink public static async Task writeMemoryCardPS1CLnk(Window hostWindow, string applicationName, string comPort, byte[] memoryCardData, int frameNumber) { //Initialize PS1CardLink string errorString = PS1CLnk.StartPS1CardLink(comPort); //Check if there were any errors if (errorString != null) { //Display an error message and cleanly close PS1CardLink communication //Display an error message and cleanly close DexDrive communication var messageBoxCustomWindow = MessageBox.Avalonia.MessageBoxManager .GetMessageBoxCustomWindow(new MessageBoxCustomParams { Style = Style.DarkMode, CanResize = true, MaxWidth = 800, ContentTitle = applicationName, ContentMessage = errorString, ButtonDefinitions = new [] { new ButtonDefinition { Name = "OK" }, }, WindowStartupLocation = WindowStartupLocation.CenterOwner }); await messageBoxCustomWindow.ShowDialog(hostWindow); PS1CLnk.StopPS1CardLink(); return; } var vm = new CardReaderWindowViewModel() { //Set maximum number of frames to write maxWritingFrames = frameNumber, //Set scale for progress bar Maximum = frameNumber, //Set current device to PS1CardLink currentDeviceIdentifier = 2, //Set window title and information Title = "PS1CardLink communication", Info = "Writing data to PS1CardLink (ver. " + PS1CLnk.GetSoftwareVersion() + ")...", //Set reference to the Memory Card data completeMemoryCard = memoryCardData, }; //Start reading data vm.backgroundReader = new BackgroundWorker(); vm.backgroundReader.ProgressChanged += vm.backgroundReader_ProgressChanged; vm.backgroundReader.DoWork += vm.backgroundReader_DoWork; vm.backgroundReader.RunWorkerCompleted += vm.backgroundReader_RunWorkerCompleted; vm.backgroundWriter = new BackgroundWorker(); vm.backgroundWriter.ProgressChanged += vm.backgroundWriter_ProgressChanged; vm.backgroundWriter.DoWork += vm.backgroundWriter_DoWork; vm.backgroundWriter.RunWorkerCompleted += vm.backgroundWriter_RunWorkerCompleted; vm.backgroundReader.RunWorkerAsync(); window = new CardReaderWindow(); window.DataContext = vm; await window.ShowDialog(hostWindow); //Stop working with PS1CardLink PS1CLnk.StopPS1CardLink(); }