Beispiel #1
0
void run_script(char* filename) {
  unsigned short pFile[MAX_FILENAME_SIZE+1];
  Bfile_StrToName_ncpy(pFile, (unsigned char*)filename, strlen(filename)+1); 
  int hFile = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle
  
  // Check for file existence
  if(hFile >= 0) // Check if it opened
  {
    // Returned no error, file exists, open it
    int size = Bfile_GetFileSize_OS(hFile);
    // File exists and has size 'size'
    // Read file into a buffer
    if ((unsigned int)size > MAX_TEXTVIEWER_FILESIZE) {
      Bfile_CloseFile_OS(hFile);
      printf("Stop: script too big\n");
      return; //file too big, return
    }
    unsigned char* asrc = (unsigned char*)alloca(size*sizeof(unsigned char)+5); // 5 more bytes to make sure it fits...
    memset(asrc, size+5, 0); //alloca does not clear the allocated space. Make sure the string is null-terminated this way.
    int rsize = Bfile_ReadFile_OS(hFile, asrc, size, 0);
    Bfile_CloseFile_OS(hFile); //we got file contents, close it
    asrc[rsize]='\0';
    execution_in_progress = 1;
    run((char*)asrc);
    execution_in_progress = 0;
  }
}
Beispiel #2
0
int remove(const char *name) {
    uint16_t *widepath = alloca(2 * strlen(name) + 1);
    Bfile_StrToName_ncpy(widepath, name, strlen(name));

    int ret = Bfile_DeleteEntry(widepath);
    if (ret >= 0) {
        return 0;
    } else {
        switch (ret) {
        case -1:
        case -3:
        case -5:
            errno = ENOENT;
            break;
        default:
            errno = EIO;
        }
        return 1;
    }
}
Beispiel #3
0
int stat(const char *path, struct stat *buf){
	//Emulate unix paths convert slashes to backslashes and add \\fls0\ to filename
	char found[266];
	int plen = strlen(path);
	plen+=7;
	char * fpath=alloca(plen+1);
	strcpy(fpath,"\\\\fls0\\");
	strcpy(fpath+7,path);
	int i;
	for(i=7;i<plen;++i){
		if(fpath[i]=='/')
			fpath[i]='\\';
	}
	printf("stat %s\n",fpath);
	unsigned short * strC=(unsigned short *)alloca(plen*2+2);
	Bfile_StrToName_ncpy(strC,fpath,plen+1);
	struct file_type info;
	int handle,ret;
	ret = Bfile_FindFirst(strC, &handle, found, &info);
	if(!ret){
		printf("found %d %d %d %d %d %d\n",info.id,info.type,info.fsize,info.dsize,info.property,info.address);
		memset(buf,0,sizeof(struct stat));
		buf->st_size=info.fsize;
		buf->st_blocks=info.fsize/512;
		if(info.fsize)
			buf->st_mode=S_IFREG;
		else
			buf->st_mode=S_IFDIR;
		return 0;
	}else if(ret==-16){
		fputs("not found",stderr);
		errno=ENOENT;
	}else{
		fprintf(stderr,"error %d\n",ret);
		errno=EIO;
	}
	Bfile_FindClose(handle);
	return (ret==0)?0:-1;
}
Beispiel #4
0
int open(const char * name,int flags,...){
	if(strcmp(name,"/dev/urandom")==0){
		sys_srand(RTC_GetTicks());
		return urandom_FD;
	}else if(strcmp(name,"/dev/fb0")==0){
		LCDstatefd=(unsigned char *)0xA8000000;
		return frameBuf_FD;
	}else{
		//Display message on screen informing user that file does not exists
		int sysmode = 0;
		if (flags==O_RDONLY) {
			sysmode = SYSFILE_MODE_READ;
		/*} else if (flags==O_WRONLY) {
			sysmode = SYSFILE_MODE_WRITE;
		} else if (flags==O_RDWR) {
			sysmode = SYSFILE_MODE_READWRITE;*/
		} else {
			fprintf(stderr,"Flag combination %d not yet supported\n",flags);
			return -1;
		}
		// Convert string to system native
		size_t plen = strlen(name);
		// We have several potential exits, so alloca simplifies ensuring this
		// gets freed (an early revision of the following logic had memory leaks).
		unsigned short *chars16 = alloca(2 * (plen + 1));
		if (chars16 == NULL) {
			errno = ENOMEM;
			return -1;
		}
		// Get a handle from the system
		Bfile_StrToName_ncpy(chars16, name, plen);
		int syshandle = Bfile_OpenFile_OS(chars16, sysmode, 0);
		if(syshandle>0)
			return fromNativeFD(syshandle);
		else
			return -1;
	}
}
Beispiel #5
0
FILE *fopen(const char *path, const char *mode) {
    // Resolve mode
    int sysmode = 0;
    if (mode[0] == 'r') {
        sysmode = SYSFILE_MODE_READ;
    } else if (mode[0] == 'w' || mode[0] == 'a') { 
        sysmode = SYSFILE_MODE_WRITE;
    } else if (strchr(mode, '+')) {
        sysmode = SYSFILE_MODE_READWRITE;
    } else {
        errno = EINVAL;
        return NULL;
    }

    // Convert string to system native
    size_t plen = strlen(path);
    // We have several potential exits, so alloca simplifies ensuring this
    // gets freed (an early revision of the following logic had memory leaks).
    unsigned short *chars16 = alloca(2 * (plen + 1));
    if (chars16 == NULL) {
        errno = ENOMEM;
        return NULL;
    }

    // Get a handle from the system
    Bfile_StrToName_ncpy(chars16, path, plen+1);
    int syshandle = Bfile_OpenFile_OS(chars16, sysmode, 0);

    if (syshandle < 0) {
        if (sysmode == SYSFILE_MODE_WRITE ||
            sysmode == SYSFILE_MODE_READWRITE) {
            // Doesn't exist, want to write. Create.
            // FIXME Size 0 doesn't work?
            size_t size = 10;
            switch (Bfile_CreateEntry_OS(chars16, CREATEMODE_FILE, &size)) {
            case 0:
                // Success. Open file.
                syshandle = Bfile_OpenFile_OS(chars16, sysmode, 0);
                break;
            case -13:
                errno = EEXIST;
                return NULL;
            case -3:
                errno = ENOENT;
                return NULL;
            default:
                errno = EIO;
                return NULL;
            }
        } else {
            // Doesn't exist for reading.
            errno = ENOENT;
            return NULL;
        }
    }

    if (mode[0] == 'a') {
        // TODO Need to seek to end and do some junk.
        errno = ENOTIMPL;
        return NULL;
    }

    // Create a FILE and fill it in
    FILE *f = sys_malloc(sizeof(FILE));
    if (f == NULL) {
        errno = ENOMEM;
        return NULL;
    }
    memset(f, 0, sizeof(FILE));
    f->fileno = syshandle + 3;
    return f;
}
Beispiel #6
0
void input_eval_loop(int isRecording) {
  char** recHistory = NULL; int curRecHistEntry = 0;
  if(isRecording) recHistory = (char**)alloca(200); // space for 200 pointers to history entries
  while (1) {
    DefineStatusMessage((char*)"", 1, 0, 0);
    strcpy(expr, (char*)"");
    printf("\x1e");
    dConsoleRedraw();
    int res = gets(expr,INPUTBUFLEN);
    if(res == 2) {
      dConsolePut("\n");
      select_script_and_run();
      continue;
    }
    if(res == 4) {
      dConsolePut("\n");
      select_strip_script();
      continue;
    }
    if(res == 3) {
      dConsolePut("\n");
      char buf[100] = "";
      sprintf(buf, "prizmUIkeyHandler(%d,%d)", custom_key_to_handle, custom_key_to_handle_modifier);
      strcpy(expr, (char*)buf);
      execution_in_progress = 1;
      run(buf);
      execution_in_progress = 0;
      check_do_graph();
      if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); }
      continue;
    }
    puts(expr);
    update_cmd_history(expr);
    dConsoleRedraw();
    if(strcmp(expr, "testmode") == 0) {
      TestMode(1);
    } else if(strcmp(expr, "meminfo") == 0) {
      print_mem_info();
    } else if(strcmp(expr, "memgc") == 0) {
      gc();
    } else if(strcmp(expr, "record") == 0) {
      if(!isRecording) script_recorder();
      else {
        // create and save a script. this must be done here, because we used alloca
        // the "clean" way would be using malloc&free, but on the Prizm the heap is already being heavily used by the Eigenmath core.
        if(curRecHistEntry == 0) {
          printf("Nothing to record.\n");
          return;
        }
        printf("Recording stopped.\n");
        printf("Type a name for the script, or\n");
        printf("leave empty to discard.\n:");
        char inputname[MAX_FILENAME_SIZE+1] = "";
        gets(inputname,MAX_FILENAME_SIZE-50);
        puts(inputname);
        if(!strlen(inputname)) {
          // user aborted
          printf("Recording discarded.\n");
          return;
        }
        if (aborttimer > 0) {
          Timer_Stop(aborttimer);
          Timer_Deinstall(aborttimer);
        }
        char filename[MAX_FILENAME_SIZE+1] = "";
        sprintf(filename, "\\\\fls0\\%s.txt", inputname);
        unsigned short pFile[MAX_FILENAME_SIZE+1];
        Bfile_StrToName_ncpy(pFile, (unsigned char*)filename, strlen(filename)+1);
        // calculate size
        int size = 0;
        int maxHistory = curRecHistEntry - 1; //because we ++'ed at the end of last addition
        for(int i=0; i <= maxHistory; i++) {
          size = size + strlen(recHistory[i]) + 1; // 1 byte for \n. we will use unix line termination
        }
        int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size);
        if(BCEres >= 0) // Did it create?
        {
          BCEres = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle
          for(int i=0; i <= maxHistory; i++) {
            char* buf = (char*)alloca(strlen(recHistory[i])+5);
            strcpy(buf, recHistory[i]);
            strcat(buf, (char*)"\n");
            Bfile_WriteFile_OS(BCEres, buf, strlen(recHistory[i])+1);
          }
          Bfile_CloseFile_OS(BCEres);
          printf("Script created.\n");
        } else {
          printf("An error occurred when creating the script for recording.\n");
        }
        aborttimer = Timer_Install(0, check_execution_abort, 100);
        if (aborttimer > 0) Timer_Start(aborttimer);
        return;
      }
    } else {
      execution_in_progress = 1;
      has_drawn_graph = 0;
      run(expr);
      // run_startup_script cannot run from inside eval_clear because then it would be a run() inside a run()
      if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); }
      execution_in_progress = 0;
      
      // if recording, add input to record
      if(isRecording && curRecHistEntry <= 200) {
        recHistory[curRecHistEntry] = (char*)alloca(strlen(expr)+2); // 2 bytes for security
        strcpy(recHistory[curRecHistEntry], expr);
        curRecHistEntry++;
      }
      check_do_graph();
    }
  }
}
Beispiel #7
0
void select_strip_script() {
  if(!is_running_in_strip()) {
    printf("This function is only available\n");
    printf("when running as an eActivity\n");
    printf("strip.\n");
    return;
  }
  
  textArea text;

  textElement elem[10];
  text.elements = elem;
  
  elem[0].text = (char*)"This function lets you run a script when this eActivity strip is opened.";
  elem[1].newLine = 1;
  elem[1].text = (char*)"When sharing the eActivity file, it will not be necessary to share any other files - the script is included in the eActivity.";
  elem[2].newLine = 1;
  elem[2].text = (char*)"You will be informed if the script is too big to fit inside the eActivity file.";
  elem[3].newLine = 1;
  elem[3].text = (char*)"Press EXIT now to continue and select a script.";
  text.numelements = 4;
  doTextArea(&text);
  
  char filename[MAX_FILENAME_SIZE+1] = "";
  if(fileBrowser(filename, (unsigned char*)"*.txt", "Scripts")) {
    // get the size of the selected script on SMEM.
    // get free size on the "MCS" of the strip we're running on and see if the script fits
    unsigned short pFile[MAX_FILENAME_SIZE+1];
    Bfile_StrToName_ncpy(pFile, (unsigned char*)filename, strlen(filename)+1); 
    int hFile = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle
    if(hFile >= 0) // Check if it opened
    { //opened
      unsigned int filesize = Bfile_GetFileSize_OS(hFile);  
      //get free size of MCS
      int MCSmaxspace; int MCScurrentload; int MCSfreespace;  
      MCS_GetState( &MCSmaxspace, &MCScurrentload, &MCSfreespace );
      if((int)filesize < MCSfreespace - 50) { // 50 bytes for any headers and the like
        // fits, copy selected script to MCS
        unsigned char* scontents = (unsigned char*)alloca(filesize);
        memset(scontents, filesize, 0);
        int rsize = Bfile_ReadFile_OS(hFile, scontents, filesize, 0);
        scontents[rsize]='\0';
        // script is now in buffer scontents
        // write it to the "MCS"
        int createResult = MCS_CreateDirectory( DIRNAME );
        if(createResult != 0) // Check directory existence
        { // directory already exists, so delete the exiting file that may be there
          MCSDelVar2(DIRNAME, SCRIPTFILE);
        }
        MCSPutVar2(DIRNAME, SCRIPTFILE, rsize, scontents);
        printf("Script set successfully.\n");
      } else {
        printf("The script is too big to be\n");
        printf("included in the eActivity.\n");
      }
      Bfile_CloseFile_OS(hFile);
      return; // don't get to the error message
    }
  }
  printf("There was a problem setting the script for this strip.\n");
}
Beispiel #8
0
void textfileEditor(char* filename, char* basefolder) {
  int newfile = (filename == NULL);
  char sText[TEXT_BUFFER_SIZE] = "";
  if(!newfile) {
    newfile = 0;
    int openerror = 0;
    int hFile = fileOpen(filename); // Get handle
    if(hFile >= 0) // Check if it opened
    { //opened
      unsigned int filesize = Bfile_GetFileSize_OS(hFile);
      if(!filesize || filesize > TEXT_BUFFER_SIZE) {
        openerror = 1;
      } else {
        Bfile_ReadFile_OS(hFile, sText, TEXT_BUFFER_SIZE, 0);
      }
      Bfile_CloseFile_OS(hFile);
    } else {
      openerror = 1;
    }
    if(openerror) {
      //Error opening file, abort
      AUX_DisplayErrorMessage(0x2B); // Data ERROR
      return;
    }
  }
  textEdit input;
  //input.forcetext=1;
  input.charlimit=TEXT_BUFFER_SIZE;
  input.buffer = (char*)sText;

  // calculate checksum so we can check for changes
  unsigned char origHash[20] = "";
  sha1((unsigned char*)sText, strlen(sText), origHash);
  while(1) {
    input.key=0;
    int res = doTextEdit(&input);
    int exit = 0;
    switch(res) {
      case TEXTEDIT_RETURN_EXIT:
      {
        exit = 1;
        unsigned char newHash[20] = "";
        sha1((unsigned char*)sText, strlen(sText), newHash);
        if(!memcmp(origHash, newHash, 20)) return;
        else {
          mMsgBoxPush(4);
          mPrintXY(3, 2, "Save this file?", TEXT_MODE_TRANSPARENT_BACKGROUND,
                   TEXT_COLOR_BLACK);
          if(closeMsgBox(1, 4)) {
            // fall through
          } else {
            return;
          }
        }
      }
      case TEXTEDIT_RETURN_CONFIRM:
      {
        char newfilename[MAX_FILENAME_SIZE];
        unsigned short newfilenameshort[0x10A];
        if(newfile) {
          int backToEditor = 0;
          SetBackGround(13);
          drawScreenTitle("Text Editor", "Save file as:");
          drawFkeyLabels(0x036F); // <
          textInput ninput;
          ninput.forcetext=1;
          ninput.charlimit=MAX_NAME_SIZE;
          char nfilename[MAX_NAME_SIZE];
          nfilename[0] = 0;
          ninput.buffer = (char*)nfilename;
          while(1) {
            ninput.key = 0;
            int nres = doTextInput(&ninput);
            if (nres==INPUT_RETURN_EXIT || (nres==INPUT_RETURN_KEYCODE && ninput.key==KEY_CTRL_F1)) {
              // user aborted
              backToEditor = 1;
              break;
            } else if (nres==INPUT_RETURN_CONFIRM) {
              if(stringEndsInG3A(nfilename)) {
                mMsgBoxPush(4);
                multiPrintXY(3, 2, "g3a files can't\nbe created by\nan add-in.",
                             TEXT_MODE_TRANSPARENT_BACKGROUND, TEXT_COLOR_BLACK);
                closeMsgBox();
              } else {
                // create and save file
                strcpy(newfilename, basefolder);
                strcat(newfilename, nfilename);
                Bfile_StrToName_ncpy(newfilenameshort, newfilename, 0x10A);
                break;
              }
            }
          }
          if(backToEditor) continue;
        } else {
          // delete, then create and save file
          Bfile_StrToName_ncpy(newfilenameshort, filename, 0x10A);
          Bfile_DeleteEntry(newfilenameshort);
        }
        size_t size = strlen(sText);
        if(Bfile_CreateEntry_OS(newfilenameshort, CREATEMODE_FILE, &size) < 0) { //create the file
          // it appears file exists, overwrite?
          if(overwriteFilePrompt(newfilename)) {
            Bfile_DeleteEntry(newfilenameshort);
            Bfile_CreateEntry_OS(newfilenameshort, CREATEMODE_FILE, &size);
          }
          else continue; // abort file save so user can discard the file, or type another filename.
        }
        
        int h = Bfile_OpenFile_OS(newfilenameshort, READWRITE, 0);
        if(h >= 0) { // Still failing?
          //Write file contents
          Bfile_WriteFile_OS(h, sText, size);
          Bfile_CloseFile_OS(h);
          // clear unsaved changes "flag":
          sha1((unsigned char*)sText, strlen(sText), origHash);
        }
        if(exit) return;
      }
      break;
    }
  }
}
void passwordGenerator() {
  Menu menu;
  menu.type = MENUTYPE_FKEYS;
  menu.title = (char*)"Password Generator";
  menu.height = 7;
  MenuItem items[6];
  int length = 10;
  int seed = RTC_GetTicks() * (GetMainBatteryVoltage(1) % 100);
  char lstr[10];
  items[1].text = (char*)"Include symbols";
  items[1].type = MENUITEM_CHECKBOX;
  items[2].text = (char*)"Include numbers";
  items[2].type = MENUITEM_CHECKBOX;
  items[2].value = MENUITEM_VALUE_CHECKED;
  items[3].text = (char*)"Include uppercase";
  items[3].type = MENUITEM_CHECKBOX;
  items[3].value = MENUITEM_VALUE_CHECKED;
  items[4].text = (char*)"Include confusable";
  items[4].type = MENUITEM_CHECKBOX;
  items[4].value = MENUITEM_VALUE_CHECKED;
  items[5].text = (char*)"Memorable vowel mix";
  items[5].type = MENUITEM_CHECKBOX;
  menu.numitems = 6;
  menu.items = items;
  while(1) {
    drawFkeyLabels(0x03B3, 0, 0, 0, 0, 0x0184); // FILE, EXE (white)
    itoa(length, (unsigned char*)lstr);
    char t[20];
    strcpy(t, "Length: ");
    strcat(t, lstr);
    items[0].text = t;
    switch(doMenu(&menu)) {
      case MENU_RETURN_EXIT:
        return;
      case MENU_RETURN_SELECTION:
        if(menu.selection > 1) items[menu.selection-1].value = !items[menu.selection-1].value;
        else {
          Selector sel;
          sel.min = 6;
          sel.value = length;
          sel.max = 30;
          sel.cycle = 1;
          sel.title = (char*)"Password Generator";
          sel.subtitle = (char*)"Length";
          if(doSelector(&sel) == SELECTOR_RETURN_SELECTION) {
            length = sel.value;
          }
        }
        break;
      case KEY_CTRL_F1:
      {
        Selector sel;
        sel.min = 1;
        sel.value = 10;
        sel.max = 1000;
        sel.cycle = 1;
        sel.title = (char*)"Generate to file";
        sel.subtitle = (char*)"Number of passwords";
        if(doSelector(&sel) != SELECTOR_RETURN_SELECTION) break;

        SetBackGround(10);
        drawScreenTitle("Generate to file", "Filename:");
        char newname[MAX_NAME_SIZE];
        newname[0] = 0;
        textInput input;
        input.forcetext=1;
        input.symbols = 0;
        input.charlimit=MAX_NAME_SIZE;
        input.buffer = (char*)newname;
        int inscreen = 1;
        while(inscreen) {
          input.key=0;
          int res = doTextInput(&input);
          if (res==INPUT_RETURN_EXIT) break; // user aborted
          else if (res==INPUT_RETURN_CONFIRM) {
            inscreen = 0;
          }
        }
        if(inscreen) break;
        char newfilename[MAX_FILENAME_SIZE];
        strcpy(newfilename, SMEM_PREFIX);
        strcat(newfilename, newname);
        strcat(newfilename, ".txt");
        unsigned short pFile[0x10A];
        Bfile_StrToName_ncpy(pFile, newfilename, 0x10A);
        unsigned int size = 1;
        int ntry = 0;
        while(ntry < 2) {
          ntry++;
          int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size);
          if(BCEres >= 0) {
            int hFile = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle
            if(hFile >= 0) {
              char password[35];
              char line[37];
              for(int i = 0; i < sel.value; i++) {
                generateRandomString(password, length, items[1].value, items[2].value,
                                     items[3].value, items[4].value, items[5].value, &seed);
                sprintf(line, "%s\r\n", password);
                Bfile_WriteFile_OS(hFile, line, length+2);
              }
              Bfile_CloseFile_OS(hFile);
            } else AUX_DisplayErrorMessage(0x2B);
            break;
          } else if(ntry < 2) {
            // File creation probably failed due to the presence of a file with the same name
            if(overwriteFilePrompt(newfilename))
              Bfile_DeleteEntry(pFile);
            else
              break;
          } else AUX_DisplayErrorMessage(0x2B);
        }
        break;
      }
      case KEY_CTRL_F6:
        int inscreen = 1;
        while(inscreen) {
          Bdisp_AllClr_VRAM();
          drawScreenTitle("Password Generator", "Generated passwords:");
          textArea text;
          text.type = TEXTAREATYPE_INSTANT_RETURN;
          text.scrollbar = 0;
          text.y = 48+3;
          text.lineHeight = 20;
          textElement e[5];
          char passwords[5][35];
          for(int i = 0; i < 5; i++) {
            generateRandomString(passwords[i], length, items[1].value, items[2].value,
                                 items[3].value, items[4].value, items[5].value, &seed);
            e[i].text = passwords[i];
            if(i) e[i].newLine = 1;
          }
          text.elements = e;
          text.numelements = 5;
          doTextArea(&text);
          drawFkeyLabels(0x036F, 0, 0, 0, 0, 0x02B9); // <, REPEAT (white)
          while(1) {
            int key;
            mGetKey(&key);
            if(key == KEY_CTRL_F6) break;
            if(key == KEY_CTRL_F1 || key == KEY_CTRL_EXIT) {
              inscreen = 0;
              break;
            }
          }
        }
        break;
    }
  }
}
Beispiel #10
0
int changeWalletScreen(char* currentWallet) {
  // returns 1 if user changes to another wallet
  char* currentWalletNice = filenameToName(currentWallet);
  Menu menu;
  menu.title = (char*)"Wallet List";
  menu.scrollout=1;
  menu.type=MENUTYPE_FKEYS;
  menu.height = 7;
  MenuItem items[MAX_WALLETS];
  int mustRefresh = 0;
  while(1) {
    char wallets[MAX_WALLETS][MAX_WALLETNAME_SIZE];
    // build wallet list:
    unsigned short path[MAX_FILENAME_SIZE+1], found[MAX_FILENAME_SIZE+1];
    char buffer[MAX_FILENAME_SIZE+1];

    // make the buffer
    strcpy(buffer, BALANCEFOLDER"\\*");
    
    file_type_t fileinfo;
    int findhandle;
    Bfile_StrToName_ncpy(path, buffer, MAX_FILENAME_SIZE+1);
    int ret = Bfile_FindFirst_NON_SMEM((const char*)path, &findhandle, (char*)found, &fileinfo);
    int i = 0;
    while(!ret) {
      Bfile_NameToStr_ncpy(buffer, found, MAX_FILENAME_SIZE+1);
      if(fileinfo.fsize == 0 &&
         !(strcmp((char*)buffer, "..") == 0 || strcmp((char*)buffer, ".") == 0)) { // find folders
        strcpy(wallets[i], buffer);
        items[i].text = wallets[i];
        i++;
        if(!strcmp(buffer, currentWalletNice)) menu.selection = i;
        if(i == MAX_WALLETS) break;
      }
      ret = Bfile_FindNext_NON_SMEM(findhandle, (char*)found, (char*)&fileinfo);
    }
    menu.items = items;
    menu.numitems = i;
    Bfile_FindClose(findhandle);
    drawFkeyLabels(0x000F, 0x0186, 0x0188, 0x0038, 0, 0); // SELECT, NEW, RENAME, DELETE
    int res = doMenu(&menu);
    switch(res) {
      case MENU_RETURN_EXIT:
        return mustRefresh;
        break;
      case KEY_CTRL_F1:
      case MENU_RETURN_SELECTION:
        if(strcmp(currentWalletNice, wallets[menu.selection-1])) {
          walletNameToPath(buffer, wallets[menu.selection-1]);
          setCurrentWallet(buffer);
          return 1;
        } return mustRefresh;
        break;
      case KEY_CTRL_F2:
        if(menu.numitems >= MAX_WALLETS) {
          AUX_DisplayErrorMessage( 0x2E );
        } else {
          createWalletWizard(0);
        }
        break;
      case KEY_CTRL_F3:
        char newWallet[MAX_FILENAME_SIZE];
        if(renameWalletScreen(wallets[menu.selection-1], newWallet)) {
          walletNameToPath(buffer, wallets[menu.selection-1]);
          if(!strcmp(currentWallet, buffer)) {
            // if the renamed wallet was the current one, we must set the current wallet to the
            // new name.
            setCurrentWallet(newWallet);
            mustRefresh = 1;
          }
        }
        break;
      case KEY_CTRL_F4:
      case KEY_CTRL_DEL:
        walletNameToPath(buffer, wallets[menu.selection-1]);
        if(deleteWalletPrompt(buffer)) {
          if(menu.numitems <= 1) {
            // this was the only wallet: delete pointer file too, so that user is prompted to create
            // a new wallet.
            unsigned short path[MAX_FILENAME_SIZE+1];
            strcpy(buffer, BALANCEFOLDER"\\Wallet");
            Bfile_StrToName_ncpy(path, buffer, MAX_FILENAME_SIZE);
            Bfile_DeleteEntry(path);
            return 1;
          }
          if(!strcmp(currentWallet, buffer)) {
            // if the deleted wallet was the current one, we must set the current wallet to the
            // first one on the list that is not the deleted one.
            // (by now we know there is more than one wallet in the list)
            for(int i = 0; i < menu.numitems; i++) {
              walletNameToPath(buffer, wallets[i]);
              if(strcmp(currentWallet, buffer)) break;
            }
            setCurrentWallet(buffer);
            mustRefresh = 1;
          }
        }
        break;
    }
  }
}