Esempio n. 1
0
  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;
    }
  }
Esempio n. 2
0
  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;
    }
  }