private static void removeGuestProfile(Context context) { try { File guestDir = getGuestDir(context); if (guestDir.exists()) { delete(guestDir); } } catch (Exception ex) { Log.e(LOGTAG, "Error removing guest profile", ex); } }
private boolean remove() { try { File dir = getDir(); if (dir.exists()) delete(dir); File mozillaDir = ensureMozillaDirectory(mContext); mDir = findProfileDir(mozillaDir); if (mDir == null) { return false; } INIParser parser = getProfilesINI(mContext); Hashtable<String, INISection> sections = parser.getSections(); for (Enumeration<INISection> e = sections.elements(); e.hasMoreElements(); ) { INISection section = e.nextElement(); String name = section.getStringProperty("Name"); if (name == null || !name.equals(mName)) continue; if (section.getName().startsWith("Profile")) { // ok, we have stupid Profile#-named things. Rename backwards. try { int sectionNumber = Integer.parseInt(section.getName().substring("Profile".length())); String curSection = "Profile" + sectionNumber; String nextSection = "Profile" + (sectionNumber + 1); sections.remove(curSection); while (sections.containsKey(nextSection)) { parser.renameSection(nextSection, curSection); sectionNumber++; curSection = nextSection; nextSection = "Profile" + (sectionNumber + 1); } } catch (NumberFormatException nex) { // uhm, malformed Profile thing; we can't do much. Log.e(LOGTAG, "Malformed section name in profiles.ini: " + section.getName()); return false; } } else { // this really shouldn't be the case, but handle it anyway parser.removeSection(mName); return true; } } parser.write(); return true; } catch (IOException ex) { Log.w(LOGTAG, "Failed to remove profile.", ex); return false; } }
public static boolean delete(File file) throws IOException { // Try to do a quick initial delete if (file.delete()) return true; if (file.isDirectory()) { // If the quick delete failed and this is a dir, recursively delete the contents of the dir String files[] = file.list(); for (String temp : files) { File fileDelete = new File(file, temp); delete(fileDelete); } } // Even if this is a dir, it should now be empty and delete should work return file.delete(); }
private boolean remove() { try { synchronized (this) { final File dir = getDir(); if (dir.exists()) { delete(dir); } try { mProfileDir = findProfileDir(); } catch (NoSuchProfileException noSuchProfile) { // If the profile doesn't exist, there's nothing left for us to do. return false; } } final INIParser parser = GeckoProfileDirectories.getProfilesINI(mMozillaDir); final Hashtable<String, INISection> sections = parser.getSections(); for (Enumeration<INISection> e = sections.elements(); e.hasMoreElements(); ) { final INISection section = e.nextElement(); String name = section.getStringProperty("Name"); if (name == null || !name.equals(mName)) { continue; } if (section.getName().startsWith("Profile")) { // ok, we have stupid Profile#-named things. Rename backwards. try { int sectionNumber = Integer.parseInt(section.getName().substring("Profile".length())); String curSection = "Profile" + sectionNumber; String nextSection = "Profile" + (sectionNumber + 1); sections.remove(curSection); while (sections.containsKey(nextSection)) { parser.renameSection(nextSection, curSection); sectionNumber++; curSection = nextSection; nextSection = "Profile" + (sectionNumber + 1); } } catch (NumberFormatException nex) { // uhm, malformed Profile thing; we can't do much. Log.e(LOGTAG, "Malformed section name in profiles.ini: " + section.getName()); return false; } } else { // this really shouldn't be the case, but handle it anyway parser.removeSection(mName); } break; } parser.write(); return true; } catch (IOException ex) { Log.w(LOGTAG, "Failed to remove profile.", ex); return false; } }