/* * Load Train Data (Signatures and respective names) from a directory * Returns the number of signatures read * TODO: make this windows compatible */ TrainData *Database::loadTrainDataFromDir(string dir, int *n) { Sig sig; vector<string> files = vector<string>(); string fname, temp; char buf[1024]; unsigned int ii; TrainData *data; getFileList(dir, files); data = new TrainData [files.size()]; getcwd(buf, 1024); // save current dir // cout << "Changing CWD to " << dir << "." << endl; chdir(dir.c_str()); // change current dir to data dir for (ii = 0; ii < files.size(); ii++) { fname = files[ii]; // cout << "Reading " << fname << "." << endl; sig.load(fname); data[ii].name = filenameToName(files[ii]); // Get Name from sig file data[ii].sigArr = sig.toArray(); // convert sig to array data[ii].value = (double) tableLookup(data[ii].name); /* get value * (table index) */ } // cout << "Back to previous CWD." << endl; chdir(buf); // change back to original working dir // cout << "Read a total of " << ii << " files." << endl; *n = ii; return data; }
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; } } }