// format a memory card static void OnMcd_Format(GtkWidget *widget, gpointer user_data) { GtkWidget *message_dialog; gint result; char *str; gint memcard = GPOINTER_TO_INT(user_data); message_dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Format this Memory Card?")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(message_dialog), _("If you format the memory card, the card will be empty, and any existing data overwritten.")); gtk_dialog_add_buttons(GTK_DIALOG(message_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("Format card"), GTK_RESPONSE_YES, NULL); result = gtk_dialog_run(GTK_DIALOG(message_dialog)); gtk_widget_destroy(message_dialog); if (result == GTK_RESPONSE_YES) { if (memcard == 1) str = Config.Mcd1; else str = Config.Mcd2; CreateMcd(str); LoadMcd(memcard, str); UpdateMcdDlg(widget); } }
void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; if (mcd != 1 && mcd != 2) return; if (mcd == 1) { data = Mcd1Data; cardh1[1] |= 8; // mark as new } if (mcd == 2) { data = Mcd2Data; cardh2[1] |= 8; } McdDisable[mcd - 1] = 0; if (str == NULL || strcmp(str, "none") == 0) { McdDisable[mcd - 1] = 1; return; } if (*str == 0) return; f = fopen(str, "rb"); if (f == NULL) { SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); CreateMcd(str); f = fopen(str, "rb"); if (f != NULL) { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } else SysMessage(_("Memory card %s failed to load!\n"), str); } else { struct stat buf; SysPrintf(_("Loading memory card %s\n"), str); if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } }
static void CreateMemcard(char *filename, char *conf_mcd) { gchar *mcd; struct stat buf; mcd = g_build_filename(getenv("HOME"), MEMCARD_DIR, filename, NULL); strcpy(conf_mcd, mcd); /* Only create a memory card if an existing one does not exist */ if (stat(mcd, &buf) == -1) { SysPrintf(_("Creating memory card: %s\n"), mcd); CreateMcd(mcd); } g_free (mcd); }
void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; if (mcd == 1) data = Mcd1Data; if (mcd == 2) data = Mcd2Data; if (*str == 0) { sprintf(str, "%s/.pcsxr/memcards/card%d.mcd", getenv("HOME"), mcd); // TODO: maybe just whine and quit.. SysPrintf(_("No memory card value was specified - using a default card %s\n"), str); } f = fopen(str, "rb"); if (f == NULL) { SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); CreateMcd(str); f = fopen(str, "rb"); if (f != NULL) { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } else SysMessage(_("Memory card %s failed to load!\n"), str); } else { struct stat buf; SysPrintf(_("Loading memory card %s\n"), str); if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } // flag indicating entries have not yet been read (i.e. new card plugged) cardh[1] |= MCDST_CHANGED; }
static void check_memcards(void) { char buf[MAXPATHLEN]; FILE *f; int i; for (i = 1; i <= 9; i++) { snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i); f = fopen(buf, "rb"); if (f == NULL) { SysPrintf("Creating memcard: %s\n", buf); CreateMcd(buf); } else fclose(f); } }
void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; if (mcd == 1) data = Mcd1Data; if (mcd == 2) data = Mcd2Data; if (*str == 0) { sprintf(str, "memcards/card%d.mcd", mcd); SysPrintf(_("No memory card value was specified - creating a default card %s\n"), str); } f = fopen(str, "rb"); if (f == NULL) { SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); CreateMcd(str); f = fopen(str, "rb"); if (f != NULL) { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } else SysMessage(_("Memory card %s failed to load!\n"), str); } else { struct stat buf; SysPrintf(_("Loading memory card %s\n"), str); if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } }
void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; if (mcd == 1) data = Mcd1Data; if (mcd == 2) data = Mcd2Data; //if (*str == 0) sprintf(str, "memcards/Mcd00%d.mcr", mcd); if (*str == 0) sprintf(str, "Mcd00%d.mcr", mcd); f = fopen(str, "rb"); if (f == NULL) { CreateMcd(str); f = fopen(str, "rb"); if (f != NULL) { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } else SysMessage("Failed loading MemCard %s\n", str); } else { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } }
// create a new, formatted memory card static void OnMcd_New(GtkWidget *widget, gpointer user_data) { GtkWidget *chooser; gchar *path; // Ask for name of new memory card chooser = gtk_file_chooser_dialog_new(_("Create a new Memory Card"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); // Card should be put into $HOME/.pcsxr/memcards path = g_build_filename(g_get_home_dir(), ".pcsxr", "memcards", NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), path); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser), _("New Memory Card.mcd")); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(chooser), TRUE); if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_OK) { gchar *name; gtk_widget_hide(chooser); name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)); CreateMcd(name); gint mcd = GPOINTER_TO_INT(user_data); if (mcd == 1) strncpy(Config.Mcd1, name, MAXPATHLEN); else strncpy(Config.Mcd2, name, MAXPATHLEN); LoadMcd(mcd, name); LoadMcdDlg(widget); g_free(name); } gtk_widget_destroy(chooser); g_free(path); }