⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keepassmidlet.java

📁 KeePass for J2ME is a J2ME port of KeePass Password Safe, a free, open source, light-weight and easy
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		System.out.println ("InputStream is null ... file probably not found");		throw new PhoneIDException("InputStream is null.  Database.kdb is not found or not readable");	    }	    byte buf[] = new byte[is.available()];	    is.read(buf);	    storeKDBInRecordStore(buf, buf.length);	}	        }    protected void storeKDBInRecordStore(byte[] content, int length)	throws RecordStoreException    {	// delete record store 	try {	    RecordStore.deleteRecordStore(Definition.KDBRecordStoreName);	} catch (RecordStoreNotFoundException e) {	    // if it doesn't exist, it's OK	}		// create record store	RecordStore rs = RecordStore.openRecordStore(Definition.KDBRecordStoreName, true);		rs.addRecord(content, 0, length);	rs.closeRecordStore();    }        public void startApp()    {	mDisplay = Display.getDisplay(this);		if (firstTime) {            try {                // load the images		mIcon = new Image[Definition.NUM_ICONS];                for (int i=0; i<Definition.NUM_ICONS; i++) {		    mIcon[i] = Image.createImage("/images/" + i + "_gt.png");		}	    } catch (IOException e) {                // ignore the image loading failure the application can recover.		doAlert(e.toString());            }	    try {		// TODO: check if kdb is loaded.  If so, skip		while (true) {		    obtainKDB();		    int rv = openDatabaseAndDisplay();		    if (rv == 0) {			// usual return code			break;		    } else {			// reload KDB		    }		}		firstTime = false;		System.out.println ("startApp() done");	    } catch (Exception e) {		doAlert(e.toString());		return;	    }        }    }        public void pauseApp() {}        public void destroyApp(boolean unconditional) {}        public void log(String str) {	//mMainForm.append(new StringItem(null, str + "\r\n"));    }        static public void logS(String str) {	myself.log(str);    }        public void doAlert(String msg) {	Alert alert = new Alert( Definition.TITLE );	alert.setString( msg );	alert.setTimeout( Alert.FOREVER );	alert.addCommand(CMD_EXIT);	alert.setCommandListener(this);	mDisplay.setCurrent( alert );	return;    }    /**     * Alert based message     * show message with specified title, msg, image, and     * whether it has yes/no buttons or only OK button     */    /*    public void doMessage(String title, String msg, Image image, boolean yesno) {	Displayable dspBACK;	Alert alert = new Alert( title, msg, image, AlertType.INFO);	alert.setTimeout( Alert.FOREVER );	if (yesno == true) {	    alert.addCommand(new Command("Yes", Command.OK, 1));	    alert.addCommand(new Command("No", Command.CANCEL, 2));	} else {	    alert.addCommand(new Command("OK", Command.OK, 1));	    // addCommand(new Command("Cancel", Command.CANCEL, 2));	}	dspBACK = Display.getDisplay(this).getCurrent();	Display.getDisplay(this).setCurrent( alert );		return;    }    */    /**     * Return a list of child groups and entries under the specified group     * If argument "group" is empty, return the root group list     */    List makeList(PwGroup group)    {	boolean isRoot;	System.out.println ("makeList (1)");			if (group == mPwManager.rootGroup) {	    System.out.println ("isRoot is true");	    isRoot = true;	} else {	    System.out.println ("isRoot is false");	    isRoot = false;	}		List resultList = null;	String[] stringArray = null;	Image[] imageArray = null;		// get child groups	Vector childGroups = group.childGroups;	Vector childEntries = group.childEntries;	int childGroupSize = childGroups.size();	int childEntriesSize = childEntries.size();	// size of string and image array is	// # child groups + # child entries + 1 (for "go up 1" entry)	stringArray = new String[childGroupSize + childEntriesSize + (isRoot ? 0 : 1)];	imageArray = new Image[childGroupSize + childEntriesSize + (isRoot ? 0 : 1)];	for (int i=0; i<childGroupSize; i++) {	    PwGroup childGroup = (PwGroup)childGroups.elementAt(i);	    stringArray[i] = childGroup.name + "/";	    imageArray[i] = mIcon[childGroup.imageId]; // TODO: change this	}	if (childEntries == null)	    System.out.println ("childEntries is null");	for (int i=0; i<childEntriesSize; i++) {	    PwEntry childEntry = (PwEntry)childEntries.elementAt(i);	    stringArray[childGroupSize + i] = childEntry.title;	    imageArray[childGroupSize + i] = mIcon[childEntry.imageId]; // TODO: change this	}	if (isRoot == false) {	    stringArray[stringArray.length - 1] = ".. go up one";	    imageArray[imageArray.length - 1] = null;	}	System.out.println ("makeList (2)");	return new List(Definition.TITLE, List.IMPLICIT, stringArray, imageArray);    }      /**     * Command Listener implementation     */    public void commandAction(Command c, Displayable d)    {	// reset timer	mTimer.cancel();	mTimerTask = new KeePassTimerTask(this);	mTimer = new Timer();	mTimer.schedule(mTimerTask, TIMER_DELAY);	if (c == List.SELECT_COMMAND) {	    System.out.println ("Select Command");	    int i = ((List)d).getSelectedIndex();	    if (i < mCurrentGroup.childGroups.size()) {		// if group is selected, move to that group		mCurrentGroup = (PwGroup)mCurrentGroup.childGroups.elementAt(i);		mainList = makeList(mCurrentGroup);		mainList.addCommand(CMD_EXIT);		mainList.setCommandListener(this);		mDisplay.setCurrent(mainList);	    } else if (i < mCurrentGroup.childGroups.size() + mCurrentGroup.childEntries.size()) {		// if entry is selected, show it		PwEntry entry = (PwEntry)mCurrentGroup.childEntries.elementAt(i - mCurrentGroup.childGroups.size());				 		try {		MessageBox box = new MessageBox (entry.title,			 "URL  : " + entry.url + "\r\n" +			 "user : " + entry.username + "\r\n" +						 			 "pass : " + new String(entry.getPassword(), "UTF-8") + "\r\n" +			 "notes: " + entry.additional,			AlertType.INFO, this, false, mIcon[entry.imageId]);		} catch (UnsupportedEncodingException e) {		    doAlert (e.toString());		}						 	    } else {		// go up one		mCurrentGroup = mCurrentGroup.parent;		mainList = makeList(mCurrentGroup);		mainList.addCommand(CMD_EXIT);		mainList.setCommandListener(this);		mDisplay.setCurrent(mainList);	    }	    	    	    //display.setCurrent(exclusiveList);	} else if (c == CMD_EXIT) {            destroyApp(false);            notifyDestroyed();	}    }    public void exit()    {	System.out.println ("Exit!");		destroyApp(true);	notifyDestroyed();    }        private String findFile(String filename) {    	Enumeration rootsEnum = FileSystemRegistry.listRoots();    	while (rootsEnum.hasMoreElements()) {    		String root = (String)rootsEnum.nextElement();    		String foundPath = findFile("file:///"+root, filename);    		if (foundPath != null) {    			return foundPath;    		}    	}    	    	return null;    }        private String findFile(String path, String filename) {    	// open the directory    	FileConnection fc;		try {			fc = (FileConnection)Connector.open(path);	    	if (fc.exists()) {	    		// list the directory	    		Enumeration dirEnum = fc.list();	    		fc.close();	    		while (dirEnum.hasMoreElements()) {	    			String object = (String)dirEnum.nextElement();	    			if (object.endsWith("/")) {	    				// it's a directory, search it	    				String foundPath = findFile(path+object, filename);	    				if (foundPath != null) {	    					return foundPath;	    				}	    			} else {	    				// it's a file, is it the one we're looking for?				    if (object.equals(filename)) {	    					return path+object;	    				}	    			}	    		}	    	}		} catch (IOException e) {			// TODO Auto-generated catch block			e.printStackTrace();		}    	    	return null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -