diff --git a/.vs/MemcardRex/v16/.suo b/.vs/MemcardRex/v16/.suo index aa6839b..205a21c 100644 Binary files a/.vs/MemcardRex/v16/.suo and b/.vs/MemcardRex/v16/.suo differ diff --git a/MemcardRex/GUI/mainWindow.cs b/MemcardRex/GUI/mainWindow.cs index 52884a8..8463edb 100644 --- a/MemcardRex/GUI/mainWindow.cs +++ b/MemcardRex/GUI/mainWindow.cs @@ -72,6 +72,7 @@ public struct programSettings public int backupMemcards; //Backup Memory Card settings public int warningMessage; //Warning message settings public int restoreWindowPosition; //Restore window position + public int fixCorruptedCards; //Try to fix corrupted memory cards public int glassStatusBar; //Vista glass status bar public int formatType; //Type of formatting for hardware interfaces public string listFont; //List font @@ -207,6 +208,9 @@ private void loadProgramSettings() //Load format type mainSettings.formatType = xmlAppSettings.readXmlEntryInt("HardwareFormatType", 0, 1); + //Load fix corrupted cards value + mainSettings.fixCorruptedCards = xmlAppSettings.readXmlEntryInt("FixCorruptedCards", 0, 1); + //Check if window position should be read if (mainSettings.restoreWindowPosition == 1) { @@ -266,6 +270,9 @@ private void saveProgramSettings() //Set format type xmlAppSettings.writeXmlEntry("HardwareFormatType", mainSettings.formatType.ToString()); + //Set fix corrupted cards value + xmlAppSettings.writeXmlEntry("FixCorruptedCards", mainSettings.fixCorruptedCards.ToString()); + //Set window X coordinate xmlAppSettings.writeXmlEntry("WindowX", this.Location.X.ToString()); @@ -276,6 +283,12 @@ private void saveProgramSettings() xmlAppSettings.closeXmlWriter(); } + //Quick and dirty settings bool converter + private bool getSettingsBool(int intValue) + { + return (intValue == 1) ? true : false; + } + //Backup a Memory Card private void backupMemcard(string fileName) { @@ -356,7 +369,7 @@ private void openCard(string fileName) PScard.Add(new ps1card()); //Try to open card - errorMsg = PScard[PScard.Count - 1].openMemoryCard(fileName); + errorMsg = PScard[PScard.Count - 1].openMemoryCard(fileName, getSettingsBool(mainSettings.fixCorruptedCards)); //If card is sucesfully opened proceed further, else destroy it if (errorMsg == null) @@ -449,7 +462,7 @@ private void saveCardDialog(int listIndex) //Save a Memory Card to a given filename private void saveMemoryCard(int listIndex, string fileName, byte memoryCardType) { - if (PScard[listIndex].saveMemoryCard(fileName, memoryCardType)) + if (PScard[listIndex].saveMemoryCard(fileName, memoryCardType, getSettingsBool(mainSettings.fixCorruptedCards))) { refreshListView(listIndex, cardList[listIndex].SelectedIndices[0]); refreshStatusStrip(); @@ -1660,7 +1673,7 @@ private void cardReaderRead(byte[] readData) PScard.Add(new ps1card()); //Fill the card with the new data - PScard[PScard.Count - 1].openMemoryCardStream(readData); + PScard[PScard.Count - 1].openMemoryCardStream(readData, getSettingsBool(mainSettings.fixCorruptedCards)); //Temporary set a bogus file location (to fool filterNullCard function) PScard[PScard.Count - 1].cardLocation = "\0"; @@ -2054,7 +2067,7 @@ private void dexDriveMenuWrite_Click(object sender, EventArgs e) if (PScard.Count > 0) { //Open a DexDrive communication window - new cardReaderWindow().writeMemoryCardDexDrive(this, appName, mainSettings.communicationPort, PScard[listIndex].saveMemoryCardStream(), 1024); + new cardReaderWindow().writeMemoryCardDexDrive(this, appName, mainSettings.communicationPort, PScard[listIndex].saveMemoryCardStream(getSettingsBool(mainSettings.fixCorruptedCards)), 1024); } } @@ -2087,7 +2100,7 @@ private void memCARDuinoMenuWrite_Click(object sender, EventArgs e) if (PScard.Count > 0) { //Open a DexDrive communication window - new cardReaderWindow().writeMemoryCardCARDuino(this, appName, mainSettings.communicationPort, PScard[listIndex].saveMemoryCardStream(), 1024); + new cardReaderWindow().writeMemoryCardCARDuino(this, appName, mainSettings.communicationPort, PScard[listIndex].saveMemoryCardStream(getSettingsBool(mainSettings.fixCorruptedCards)), 1024); } } @@ -2108,7 +2121,7 @@ private void pS1CardLinkMenuWrite_Click(object sender, EventArgs e) if (PScard.Count > 0) { //Open a DexDrive communication window - new cardReaderWindow().writeMemoryCardPS1CLnk(this, appName, mainSettings.communicationPort, PScard[listIndex].saveMemoryCardStream(), 1024); + new cardReaderWindow().writeMemoryCardPS1CLnk(this, appName, mainSettings.communicationPort, PScard[listIndex].saveMemoryCardStream(getSettingsBool(mainSettings.fixCorruptedCards)), 1024); } } @@ -2143,21 +2156,21 @@ private void formatHardwareCard(int hardDevice) if (mainSettings.formatType == 0) frameNumber = 64; //Create a new card by giving a null path - blankCard.openMemoryCard(null); + blankCard.openMemoryCard(null, true); //Check what device to use switch (hardDevice) { case 0: //DexDrive - new cardReaderWindow().writeMemoryCardDexDrive(this, appName, mainSettings.communicationPort, blankCard.saveMemoryCardStream(), frameNumber); + new cardReaderWindow().writeMemoryCardDexDrive(this, appName, mainSettings.communicationPort, blankCard.saveMemoryCardStream(true), frameNumber); break; case 1: //MemCARDuino - new cardReaderWindow().writeMemoryCardCARDuino(this, appName, mainSettings.communicationPort, blankCard.saveMemoryCardStream(), frameNumber); + new cardReaderWindow().writeMemoryCardCARDuino(this, appName, mainSettings.communicationPort, blankCard.saveMemoryCardStream(true), frameNumber); break; case 2: //PS1CardLink - new cardReaderWindow().writeMemoryCardPS1CLnk(this, appName, mainSettings.communicationPort, blankCard.saveMemoryCardStream(), frameNumber); + new cardReaderWindow().writeMemoryCardPS1CLnk(this, appName, mainSettings.communicationPort, blankCard.saveMemoryCardStream(true), frameNumber); break; } } diff --git a/MemcardRex/GUI/preferencesWindow.Designer.cs b/MemcardRex/GUI/preferencesWindow.Designer.cs index dd50f84..28215d1 100644 --- a/MemcardRex/GUI/preferencesWindow.Designer.cs +++ b/MemcardRex/GUI/preferencesWindow.Designer.cs @@ -51,6 +51,7 @@ private void InitializeComponent() this.formatLabel = new System.Windows.Forms.Label(); this.backgroundCombo = new System.Windows.Forms.ComboBox(); this.backgroundLabel = new System.Windows.Forms.Label(); + this.fixCorruptedCardsCheckbox = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // okButton @@ -288,11 +289,22 @@ private void InitializeComponent() this.backgroundLabel.TabIndex = 102; this.backgroundLabel.Text = "Icon background color:"; // + // fixCorruptedCardsCheckbox + // + this.fixCorruptedCardsCheckbox.AutoSize = true; + this.fixCorruptedCardsCheckbox.Location = new System.Drawing.Point(248, 132); + this.fixCorruptedCardsCheckbox.Name = "fixCorruptedCardsCheckbox"; + this.fixCorruptedCardsCheckbox.Size = new System.Drawing.Size(184, 17); + this.fixCorruptedCardsCheckbox.TabIndex = 103; + this.fixCorruptedCardsCheckbox.Text = "Try to fix corrupted Memory Cards"; + this.fixCorruptedCardsCheckbox.UseVisualStyleBackColor = true; + // // preferencesWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(463, 212); + this.Controls.Add(this.fixCorruptedCardsCheckbox); this.Controls.Add(this.backgroundCombo); this.Controls.Add(this.backgroundLabel); this.Controls.Add(this.formatLabel); @@ -353,5 +365,6 @@ private void InitializeComponent() private System.Windows.Forms.Label formatLabel; private System.Windows.Forms.ComboBox backgroundCombo; private System.Windows.Forms.Label backgroundLabel; + private System.Windows.Forms.CheckBox fixCorruptedCardsCheckbox; } } \ No newline at end of file diff --git a/MemcardRex/GUI/preferencesWindow.cs b/MemcardRex/GUI/preferencesWindow.cs index 36ca457..4b4c921 100644 --- a/MemcardRex/GUI/preferencesWindow.cs +++ b/MemcardRex/GUI/preferencesWindow.cs @@ -36,6 +36,7 @@ public void initializeDialog(mainWindow.programSettings progSettings) if (progSettings.glassStatusBar == 1) glassCheckbox.Checked = true; else glassCheckbox.Checked = false; if (progSettings.warningMessage == 1) backupWarningCheckBox.Checked = true; else backupWarningCheckBox.Checked = false; if (progSettings.restoreWindowPosition == 1) restorePositionCheckbox.Checked = true; else restorePositionCheckbox.Checked = false; + if (progSettings.fixCorruptedCards == 1) fixCorruptedCardsCheckbox.Checked = true; else fixCorruptedCardsCheckbox.Checked = false; //Load all COM ports found on the system foreach (string port in SerialPort.GetPortNames()) @@ -77,6 +78,7 @@ private void applySettings() if (glassCheckbox.Checked == true) progSettings.glassStatusBar = 1; else progSettings.glassStatusBar = 0; if (backupWarningCheckBox.Checked == true) progSettings.warningMessage = 1; else progSettings.warningMessage = 0; if (restorePositionCheckbox.Checked == true) progSettings.restoreWindowPosition = 1; else progSettings.restoreWindowPosition = 0; + if (fixCorruptedCardsCheckbox.Checked == true) progSettings.fixCorruptedCards = 1; else progSettings.fixCorruptedCards = 0; if (fontCombo.SelectedIndex != -1) progSettings.listFont = fontCombo.SelectedItem.ToString(); hostWindow.applyProgramSettings(progSettings); diff --git a/MemcardRex/GUI/preferencesWindow.resx b/MemcardRex/GUI/preferencesWindow.resx index 19dc0dd..d58980a 100644 --- a/MemcardRex/GUI/preferencesWindow.resx +++ b/MemcardRex/GUI/preferencesWindow.resx @@ -112,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file diff --git a/MemcardRex/ps1card.cs b/MemcardRex/ps1card.cs index d13d451..8c414fb 100644 --- a/MemcardRex/ps1card.cs +++ b/MemcardRex/ps1card.cs @@ -1,5 +1,5 @@ //PS1 Memory Card class -//Shendo 2009-2013 +//Shendo 2009-2021 using System; using System.Collections.Generic; @@ -88,20 +88,25 @@ private void loadDataFromRawCard() } //Recreate raw Memory Card - private void loadDataToRawCard() + private void loadDataToRawCard(bool fixData) { - //Clear existing data - rawMemoryCard = new byte[131072]; + //Check if data needs to be fixed or left as is (mandatory for FreePSXBoot) + if (fixData) + { + //Clear existing data + rawMemoryCard = new byte[131072]; - //Recreate the signature - rawMemoryCard[0] = 0x4D; //M - rawMemoryCard[1] = 0x43; //C - rawMemoryCard[127] = 0x0E; //XOR (precalculated) + //Recreate the signature + rawMemoryCard[0] = 0x4D; //M + rawMemoryCard[1] = 0x43; //C + rawMemoryCard[127] = 0x0E; //XOR (precalculated) - rawMemoryCard[8064] = 0x4D; //M - rawMemoryCard[8065] = 0x43; //C - rawMemoryCard[8191] = 0x0E; //XOR (precalculated) + rawMemoryCard[8064] = 0x4D; //M + rawMemoryCard[8065] = 0x43; //C + rawMemoryCard[8191] = 0x0E; //XOR (precalculated) + } + //This can be copied freely without fixing for (int slotNumber = 0; slotNumber < 15; slotNumber++) { //Load header data @@ -117,6 +122,10 @@ private void loadDataToRawCard() } } + + //Skip fixing data if it's not needed + if (!fixData) return; + //Create authentic data (just for completeness) for (int i = 0; i < 20; i++) { @@ -901,7 +910,7 @@ public bool openSingleSave(string fileName, int slotNumber, out int requiredSlot } //Save Memory Card to the given filename - public bool saveMemoryCard(string fileName, int memoryCardType) + public bool saveMemoryCard(string fileName, int memoryCardType, bool fixData) { BinaryWriter binWriter = null; @@ -916,7 +925,7 @@ public bool saveMemoryCard(string fileName, int memoryCardType) } //Prepare data for saving - loadDataToRawCard(); + loadDataToRawCard(fixData); //Check what kind of file to output according to memoryCardType switch (memoryCardType) @@ -953,10 +962,10 @@ public bool saveMemoryCard(string fileName, int memoryCardType) } //Save (export) Memory Card to a given byte stream - public byte[] saveMemoryCardStream() + public byte[] saveMemoryCardStream(bool fixData) { //Prepare data for saving - loadDataToRawCard(); + loadDataToRawCard(fixData); //Return complete Memory Card data return rawMemoryCard; @@ -964,7 +973,7 @@ public byte[] saveMemoryCardStream() //Open memory card from the given byte stream - public void openMemoryCardStream(byte[] memCardData) + public void openMemoryCardStream(byte[] memCardData, bool fixData) { //Set the reference for the recieved data rawMemoryCard = memCardData; @@ -974,7 +983,7 @@ public void openMemoryCardStream(byte[] memCardData) cardName = "Untitled"; - calculateXOR(); + if(fixData) calculateXOR(); loadStringData(); loadGMEComments(); loadSlotTypes(); @@ -989,7 +998,7 @@ public void openMemoryCardStream(byte[] memCardData) } //Open Memory Card from the given filename (return error message if operation is not sucessfull) - public string openMemoryCard(string fileName) + public string openMemoryCard(string fileName, bool fixData) { //Check if the Memory Card should be opened or created if (fileName != null) @@ -1070,7 +1079,7 @@ public string openMemoryCard(string fileName) } //Calculate XOR checksum (in case if any of the saveHeaders have corrputed XOR) - calculateXOR(); + if(fixData) calculateXOR(); //Convert various Memory Card data to strings loadStringData();