All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.intellij.ide.browsers.impl.BrowserConfigurationHelper Maven / Gradle / Ivy

Go to download

A packaging of the IntelliJ Community Edition xml library. This is release number 1 of trunk branch 142.

The newest version!
/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.ide.browsers.impl;

import com.intellij.ide.browsers.BrowserFamily;
import com.intellij.openapi.util.io.WindowsRegistryUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.EnumMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class BrowserConfigurationHelper {
  private static final String START_MENU_KEY = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Clients\\StartMenuInternet";

  /**
   * Read data from Windows registry (may take some time to run).
   */
  @NotNull
  public static Map getBrowserPathsFromRegistry() {
    Map map =
      new EnumMap(BrowserFamily.class);

    List sections = WindowsRegistryUtil.readRegistryBranch(START_MENU_KEY);
    for (String section : sections) {
      BrowserFamily family = getFamily(section);
      if (family != null) {
        String pathToExe = WindowsRegistryUtil.readRegistryDefault(START_MENU_KEY + "\\" + section + "\\shell\\open\\command");
        if (pathToExe != null) {
          map.put(family, pathToExe);
        }
      }
    }

    return map;
  }

  @Nullable
  private static BrowserFamily getFamily(String registryName) {
    registryName = registryName.toLowerCase();
    for (BrowserFamily family : BrowserFamily.values()) {
      if (registryName.contains(family.getName().toLowerCase(Locale.US))) {
        return family;
      }
    }

    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy