/** * OpenDVD * * Function to load a DVD directory and display to user. */ int OpenDVD () { int romsdiroffset = 0; loadtype = LOAD_DVD; if (!getpvd()) { ShowAction((char*) "Mounting DVD ... Wait"); DVD_Mount(); /* mount the DVD unit again */ havedir = 0; /* this may be a new DVD: content need to be parsed again */ if (!getpvd()) return 0; /* no correct ISO9660 DVD */ } if (havedir == 0) { offset = selection = 0; /* reset file selector */ haveSDdir = 0; /* prevent conflicts with SDCARD, USB file selector */ haveUSBdir = 0; if ((maxfiles = parsedirectory ())) { if ( romsdiroffset = SNESROMSOffset() ) { rootdir = filelist[romsdiroffset].offset; rootdirlength = filelist[romsdiroffset].length; offset = selection = 0; maxfiles = parsedirectory (); } int ret = FileSelector (); havedir = 1; return ret; } } else return FileSelector (); return 0; }
static int parsedirectory (const char *dir, dki_t ** listp) { dki_t *dkp; DIR *dirp; struct dirent *dentp; char path[MAX_PATHSIZE + 1]; if (dirflag) return 0; dbg_val ("directory: opendir(%s)\n", dir); if ((dirp = opendir (dir)) == NULL) return 0; while ((dentp = readdir (dirp)) != NULL) { if (is_dotfilename (dentp->d_name)) continue; dbg_val ("directory: check %s\n", dentp->d_name); pathname (path, sizeof (path), dir, dentp->d_name, NULL); if (is_directory (path) && recflag) { dbg_val ("directory: recursive %s\n", path); parsedirectory (path, listp); } else if (is_keyfilename (dentp->d_name)) if ((dkp = dki_read (dir, dentp->d_name))) { // fprintf (stderr, "parsedir: tssearch (%d %s)\n", dkp, dkp->name); #if defined (USE_TREE) && USE_TREE dki_tadd (listp, dkp, 1); #else dki_add (listp, dkp); #endif } } closedir (dirp); return 1; }
int main (int argc, char *argv[]) { dki_t *data = NULL; int c; int opt_index; int action; const char *file; const char *defconfname = NULL; char *p; char str[254+1]; zconf_t *config; progname = *argv; if ( (p = strrchr (progname, '/')) ) progname = ++p; view = getnameappendix (progname, "zkt-ls"); defconfname = getdefconfname (view); config = loadconfig ("", (zconf_t *)NULL); /* load built in config */ if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); opterr = 0; opt_index = 0; action = 0; #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 ) #else while ( (c = getopt (argc, argv, short_options)) != -1 ) #endif { switch ( c ) { #if defined(COLOR_MODE) && COLOR_MODE case 'C': /* color mode on; optional with terminal name */ if ( optarg ) term = optarg; else term = getenv ("TERM"); break; #endif case 'M': managedkeyflag = 1; subdomain_before_parent = 0; zskflag = pathflag = 0; action = c; break; case 'T': trustedkeyflag = 1; subdomain_before_parent = 0; zskflag = pathflag = 0; /* fall through */ case 'H': case 'K': case 'Z': action = c; break; case 'a': /* age */ ageflag = !ageflag; break; case 'f': /* key lifetime */ lifetimeflag = !lifetimeflag; break; case 'V': /* view name */ view = optarg; defconfname = getdefconfname (view); if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); break; case 'c': config = loadconfig (optarg, config); setglobalflags (config); checkconfig (config); break; case 'O': /* read option from commandline */ config = loadconfig_fromstr (optarg, config); setglobalflags (config); checkconfig (config); break; case 'd': /* ignore directory arg */ dirflag = 1; break; case 'h': /* print no headline */ headerflag = 0; break; case 'k': /* ksk only */ zskflag = 0; break; case 'L': /* ljust */ ljustflag = !ljustflag; break; case 'l': /* label list */ labellist = prepstrlist (optarg, LISTDELIM); if ( labellist == NULL ) fatal ("Out of memory\n"); break; case 'p': /* print path */ pathflag = 1; break; case 'r': /* switch recursive flag */ recflag = !recflag; break; case 's': /* switch subdomain sorting flag */ subdomain_before_parent = !subdomain_before_parent; break; case 't': /* time */ timeflag = !timeflag; break; case 'e': /* expire time */ exptimeflag = !exptimeflag; break; case 'z': /* zsk only */ kskflag = 0; break; case ':': snprintf (str, sizeof(str), "option \"-%c\" requires an argument.\n", optopt); usage (str, config); break; case '?': if ( isprint (optopt) ) snprintf (str, sizeof(str), "Unknown option \"-%c\".\n", optopt); else snprintf (str, sizeof (str), "Unknown option char \\x%x.\n", optopt); usage (str, config); break; default: abort(); } } if ( kskflag == 0 && zskflag == 0 ) kskflag = zskflag = 1; tc_init (stdout, term); c = optind; do { if ( c >= argc ) /* no args left */ file = config->zonedir; /* use default directory */ else file = argv[c++]; if ( is_directory (file) ) parsedirectory (file, &data, subdomain_before_parent); else parsefile (file, &data, subdomain_before_parent); } while ( c < argc ); /* for all arguments */ switch ( action ) { case 'H': usage ("", config); case 'K': zkt_list_dnskeys (data); break; case 'T': zkt_list_trustedkeys (data); break; case 'M': zkt_list_managedkeys (data); break; default: zkt_list_keys (data); } tc_end (stdout, term); return 0; }
int FileSelector () { int p, wp; signed char a; int haverom = 0; int redraw = 1; int selectit = 0; while (haverom == 0) { if (redraw) ShowFiles (offset, selection); redraw = 0; p = PAD_ButtonsDown (0); wp = WPAD_ButtonsDown (0); a = PAD_StickY (0); if ( (p & PAD_BUTTON_A) || (wp & WPAD_BUTTON_A) || selectit ) { if ( selectit ) selectit = 0; if (filelist[selection].flags) /*** This is directory ***/ { if (loadtype == LOAD_SDC) { /* memorize last entries list, actual root directory and selection for next access */ haveSDdir = 1; /* update current directory and set new entry list if directory has changed */ int status = updateSDdirname(); if (status == 1) // ok, open directory { maxfiles = parseSDdirectory(); if (!maxfiles) { WaitPrompt ((char*) "Error reading directory !"); haverom = 1; // quit SD menu haveSDdir = 0; // reset everything at next access } } else if (status == -1) // directory name too long { haverom = 1; // quit SD menu haveSDdir = 0; // reset everything at next access } } else { if ( (strcmp (filelist[selection].filename, "..") == 0) && ((unsigned int)rootdir == filelist[selection].offset) ) return 0; else { rootdir = filelist[selection].offset; rootdirlength = filelist[selection].length; offset = selection = 0; maxfiles = parsedirectory (); } } } else // this is a file { rootdir = filelist[selection].offset; rootdirlength = filelist[selection].length; switch (loadtype) { case LOAD_DVD: /*** Now load the DVD file to it's offset ***/ ARAM_ROMSIZE = LoadDVDFile (Memory.ROM); break; case LOAD_SMB: /*** Load from SMB ***/ ARAM_ROMSIZE = LoadSMBFile (filelist[selection].filename, filelist[selection].length); break; case LOAD_SDC: /*** Load from SD Card ***/ /* memorize last entries list, actual root directory and selection for next access */ haveSDdir = 1; ARAM_ROMSIZE = LoadSDFile (filelist[selection].filename, filelist[selection].length); break; } if (ARAM_ROMSIZE > 0) { hasloaded = 1; Memory.LoadROM ("BLANK.SMC"); Memory.LoadSRAM ("BLANK"); haverom = 1; return 1; } else { WaitPrompt((char*) "Error loading ROM!"); } } redraw = 1; } // End of A if ( (p & PAD_BUTTON_B) || (wp & WPAD_BUTTON_B) ) { while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) || (PAD_ButtonsDown(0) & WPAD_BUTTON_B) ) VIDEO_WaitVSync(); //if ((strcmp(filelist[1].filename,"..") == 0) && (strlen (filelist[0].filename) != 0)) if ( strcmp(filelist[0].filename,"..") == 0 ) { selection = 0; selectit = 1; } else if ( strcmp(filelist[1].filename,"..") == 0 ) { selection = selectit = 1; } else { return 0; } } // End of B if ( (p & PAD_BUTTON_DOWN) || (wp & WPAD_BUTTON_DOWN) || (a < -PADCAL) ) { selection++; if (selection == maxfiles) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; redraw = 1; } // End of down if ( (p & PAD_BUTTON_UP) || (wp & WPAD_BUTTON_UP) || (a > PADCAL) ) { selection--; if (selection < 0) { selection = maxfiles - 1; offset = selection - PAGESIZE + 1; } if (selection < offset) offset -= PAGESIZE; if (offset < 0) offset = 0; redraw = 1; } // End of Up if ( (PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT) || (WPAD_ButtonsHeld(0) & WPAD_BUTTON_LEFT) ) { /*** Go back a page ***/ selection -= PAGESIZE; if (selection < 0) { selection = maxfiles - 1; offset = selection - PAGESIZE + 1; } if (selection < offset) offset -= PAGESIZE; if (offset < 0) offset = 0; redraw = 1; } if ( (PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT) || (WPAD_ButtonsHeld(0) & WPAD_BUTTON_RIGHT) ) { /*** Go forward a page ***/ selection += PAGESIZE; if (selection > maxfiles - 1) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; redraw = 1; } } return 0; }
int FileSelector () { u32 p, wp, ph, wh; signed char a, c; int haverom = 0; int redraw = 1; int selectit = 0; float mag = 0; float mag2 = 0; u16 ang = 0; u16 ang2 = 0; int scroll_delay = 0; bool move_selection = 0; #define SCROLL_INITIAL_DELAY 15 #define SCROLL_LOOP_DELAY 4 while (haverom == 0) { if (redraw) ShowFiles (offset, selection); redraw = 0; VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads p = PAD_ButtonsDown (0); ph = PAD_ButtonsHeld (0); #ifdef HW_RVL wp = WPAD_ButtonsDown (0); wh = WPAD_ButtonsHeld (0); wpad_get_analogues(0, &mag, &ang, &mag2, &ang2); // get joystick info from wii expansions #else wp = 0; wh = 0; #endif a = PAD_StickY (0); c = PAD_SubStickX (0); /*** Check for exit combo ***/ if ( (c < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) ) return 0; /*** Check buttons, perform actions ***/ if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) { if ( selectit ) selectit = 0; if (filelist[selection].flags) /*** This is directory ***/ { if (loadtype == LOAD_SDC || loadtype == LOAD_USB) { /* memorize last entries list, actual root directory and selection for next access */ if (loadtype == LOAD_SDC) haveSDdir = 1; else haveUSBdir = 1; /* update current directory and set new entry list if directory has changed */ int status = updateFATdirname(); if (status == 1) // ok, open directory { maxfiles = parseFATdirectory(); if (!maxfiles) { WaitPrompt ((char*) "Error reading directory !"); haverom = 1; // quit SD menu if (loadtype == LOAD_SDC) // reset everything at next access haveSDdir = 0; else haveUSBdir = 0; } } else if (status == -1) // directory name too long { haverom = 1; // quit SD menu if (loadtype == LOAD_SDC) // reset everything at next access haveSDdir = 0; else haveUSBdir = 0; } } else { if ( (strcmp (filelist[selection].filename, "..") == 0) && ((unsigned int)rootdir == filelist[selection].offset) ) return 0; else { rootdir = filelist[selection].offset; rootdirlength = filelist[selection].length; offset = selection = 0; maxfiles = parsedirectory (); } } } else // this is a file { rootdir = filelist[selection].offset; rootdirlength = filelist[selection].length; /*** store the filename (used for sram/freeze naming) ***/ strip_ext(filelist[selection].filename, Memory.ROMFilename); // store stripped filename in Memory.ROMFilename switch (loadtype) { case LOAD_DVD: /*** Now load the DVD file to it's offset ***/ ARAM_ROMSIZE = LoadDVDFile (Memory.ROM); break; case LOAD_SMB: /*** Load from SMB ***/ ARAM_ROMSIZE = LoadSMBFile (filelist[selection].filename, filelist[selection].length); break; case LOAD_USB: case LOAD_SDC: /*** Load from SD Card ***/ /* memorize last entries list, actual root directory and selection for next access */ haveSDdir = 1; ARAM_ROMSIZE = LoadSDFile (filelist[selection].filename, filelist[selection].length); break; } if (ARAM_ROMSIZE > 0) { hasloaded = 1; Memory.LoadROM ("BLANK.SMC"); Memory.LoadSRAM ("BLANK"); haverom = 1; return 1; } else { WaitPrompt((char*) "Error loading ROM!"); } } redraw = 1; } // End of A if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) { while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) #ifdef HW_RVL || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) #endif ) VIDEO_WaitVSync(); //if ((strcmp(filelist[1].filename,"..") == 0) && (strlen (filelist[0].filename) != 0)) if ( strcmp(filelist[0].filename,"..") == 0 ) { selection = 0; selectit = 1; } else if ( strcmp(filelist[1].filename,"..") == 0 ) { selection = selectit = 1; } else { return 0; } } // End of B if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -PADCAL) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) ) { if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/ scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. move_selection = 1; //continue (move selection) } else if (scroll_delay == 0) { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; move_selection = 1; //continue (move selection) } else { scroll_delay--; // wait } if (move_selection) { selection++; if (selection == maxfiles) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; redraw = 1; move_selection = 0; } } // End of down if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > PADCAL) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) ) { if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/ scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. move_selection = 1; //continue (move selection) } else if (scroll_delay == 0) { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; move_selection = 1; //continue (move selection) } else { scroll_delay--; // wait } if (move_selection) { selection--; if (selection < 0) { selection = maxfiles - 1; offset = selection - PAGESIZE + 1; } if (selection < offset) offset -= PAGESIZE; if (offset < 0) offset = 0; redraw = 1; move_selection = 0; } } // End of Up if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) ) { /*** Go back a page ***/ selection -= PAGESIZE; if (selection < 0) { selection = maxfiles - 1; offset = selection - PAGESIZE + 1; } if (selection < offset) offset -= PAGESIZE; if (offset < 0) offset = 0; redraw = 1; } if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) ) { /*** Go forward a page ***/ selection += PAGESIZE; if (selection > maxfiles - 1) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; redraw = 1; } } return 0; }
int main (int argc, char *argv[]) { dki_t *data = NULL; dki_t *dkp; int c; int opt_index; int action; const char *file; const char *defconfname = NULL; char *p; char str[254+1]; const char *keyname = NULL; int searchtag; zconf_t *config; progname = *argv; if ( (p = strrchr (progname, '/')) ) progname = ++p; view = getnameappendix (progname, "dnssec-zkt"); defconfname = getdefconfname (view); config = loadconfig ("", (zconf_t *)NULL); /* load built in config */ if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); opterr = 0; opt_index = 0; action = 0; #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 ) #else while ( (c = getopt (argc, argv, short_options)) != -1 ) #endif { switch ( c ) { case '9': /* ksk rollover help */ ksk_roll ("help", c - '0', NULL, NULL); exit (1); case '1': /* ksk rollover: create new key */ case '2': /* ksk rollover: publish DS */ case '3': /* ksk rollover: delete old key */ case '0': /* ksk rollover: show current status */ action = c; if ( !optarg ) usage ("ksk rollover requires an domain argument", config); kskdomain = domain_canonicdup (optarg); break; case 'h': case 'K': case 'Z': action = c; break; case 'C': pathflag = !pathflag; /* fall through */ case 'P': case 'S': case 'A': case 'D': case 'R': case 's': case 19: case 20: if ( (keyname = parsetag (optarg, &searchtag)) != NULL ) keyname = domain_canonicdup (keyname); action = c; break; case 'F': /* set key lifetime */ lifetime = atoi (optarg); action = c; break; case 'V': /* view name */ view = optarg; defconfname = getdefconfname (view); if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); break; case 'c': config = loadconfig (optarg, config); setglobalflags (config); checkconfig (config); break; case 'O': /* read option from commandline */ config = loadconfig_fromstr (optarg, config); setglobalflags (config); checkconfig (config); break; case 'd': /* ignore directory arg */ dirflag = 1; break; case 'k': /* ksk only */ zskflag = 0; break; case 'r': /* switch recursive flag */ recflag = !recflag; break; case 'z': /* zsk only */ kskflag = 0; break; case ':': snprintf (str, sizeof(str), "option \"-%c\" requires an argument.\n", optopt); usage (str, config); break; case '?': if ( isprint (optopt) ) snprintf (str, sizeof(str), "Unknown option \"-%c\".\n", optopt); else snprintf (str, sizeof (str), "Unknown option char \\x%x.\n", optopt); usage (str, config); break; default: abort(); } } if ( kskflag == 0 && zskflag == 0 ) kskflag = zskflag = 1; c = optind; do { if ( c >= argc ) /* no args left */ file = config->zonedir; /* use default directory */ else file = argv[c++]; if ( is_directory (file) ) parsedirectory (file, &data); else parsefile (file, &data); } while ( c < argc ); /* for all arguments */ switch ( action ) { case 'h': usage ("", config); case 'C': createkey (keyname, data, config); break; case 'P': case 'S': case 'A': case 'D': if ( (dkp = (dki_t*)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); if ( (c = dki_setstatus_preservetime (dkp, action)) != 0 ) fatal ("Couldn't change status of key %u: %d\n", searchtag, c); break; case 19: /* remove (rename) key file */ if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); dki_remove (dkp); break; case 20: /* destroy the key (remove the files!) */ if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); dki_destroy (dkp); break; case 'R': if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL ) fatal ("Key with tag %u not found\n", searchtag); else if ( dkp == (void *) 01 ) fatal ("Key with tag %u found multiple times\n", searchtag); if ( (c = dki_setstatus (dkp, action)) != 0 ) fatal ("Couldn't change status of key %u: %d\n", searchtag, c); break; case '1': /* ksk rollover new key */ case '2': /* ksk rollover publish DS */ case '3': /* ksk rollover delete old key */ case '0': /* ksk rollover status */ ksk_roll (kskdomain, action - '0', data, config); break; case 'F': zkt_setkeylifetime (data); /* fall through */ default: zkt_list_keys (data); } return 0; }