mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2025-02-24 14:51:59 -05:00
Add mempak_insert_note
This commit is contained in:
parent
c2944732ff
commit
d15e46b2b1
@ -6,13 +6,16 @@ LDFLAGS=-g
|
|||||||
|
|
||||||
PREFIX=/usr/local
|
PREFIX=/usr/local
|
||||||
|
|
||||||
PROGRAMS=mempak_ls mempak_format mempak_extract_note
|
PROGRAMS=mempak_ls mempak_format mempak_extract_note mempak_insert_note
|
||||||
MEMPAKLIB_OBJS=mempak.o mempak_fs.o
|
MEMPAKLIB_OBJS=mempak.o mempak_fs.o
|
||||||
|
|
||||||
.PHONY : clean install
|
.PHONY : clean install
|
||||||
|
|
||||||
all: $(PROGRAMS)
|
all: $(PROGRAMS)
|
||||||
|
|
||||||
|
mempak_insert_note: mempak_insert_note.o $(MEMPAKLIB_OBJS)
|
||||||
|
$(LD) $^ $(LDFLAGS) -o $@
|
||||||
|
|
||||||
mempak_extract_note: mempak_extract_note.o $(MEMPAKLIB_OBJS)
|
mempak_extract_note: mempak_extract_note.o $(MEMPAKLIB_OBJS)
|
||||||
$(LD) $^ $(LDFLAGS) -o $@
|
$(LD) $^ $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
83
tool/n64savetool/mempak_insert_note.c
Normal file
83
tool/n64savetool/mempak_insert_note.c
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include "mempak.h"
|
||||||
|
|
||||||
|
static void print_usage(void)
|
||||||
|
{
|
||||||
|
printf("Usage: ./mempak_insert_note pakfile notefile\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Options:\n");
|
||||||
|
printf(" -h, --help Display help\n");
|
||||||
|
printf(" -c, --comment Comment Note comment (only works for .N64 files)\n");
|
||||||
|
printf(" -d, --dst id Overwrite a specific note slot (0-15)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
const char *pakfile;
|
||||||
|
const char *notefile;
|
||||||
|
mempak_structure_t *mpk;
|
||||||
|
struct option long_options[] = {
|
||||||
|
{ "help", no_argument, 0, 'h' },
|
||||||
|
{ "comment", required_argument, 0, 'c' },
|
||||||
|
{ "dst", required_argument, 0, 'd' },
|
||||||
|
{ }, // terminator
|
||||||
|
};
|
||||||
|
const char *comment = "";
|
||||||
|
int used_note_id = -1;
|
||||||
|
int dst_id = -1;
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
print_usage();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = getopt_long(argc, argv, "f:h", long_options, NULL);
|
||||||
|
if (c==-1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch(c)
|
||||||
|
{
|
||||||
|
case 'h':
|
||||||
|
print_usage();
|
||||||
|
return 0;
|
||||||
|
case 'c':
|
||||||
|
comment = optarg;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
dst_id = atoi(optarg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pakfile = argv[optind];
|
||||||
|
notefile = argv[optind+1];
|
||||||
|
|
||||||
|
mpk = mempak_loadFromFile(pakfile);
|
||||||
|
if (!mpk) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("Loaded pakfile in %s format.\n", mempak_format2string(mpk->file_format));
|
||||||
|
|
||||||
|
if (mempak_importNote(mpk, notefile, dst_id, &used_note_id)) {
|
||||||
|
fprintf(stderr, "could not export note\n");
|
||||||
|
mempak_free(mpk);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Note imported and written to slot %d\n", used_note_id);
|
||||||
|
|
||||||
|
if (0 != mempak_saveToFile(mpk, pakfile, mpk->file_format)) {
|
||||||
|
fprintf(stderr, "could not write to memory pak file\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
mempak_free(mpk);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user