Package net.sphene.goim.rcp.extensionpoints

Source Code of net.sphene.goim.rcp.extensionpoints.GameAdapterWithRegistryAutoDetection

/*
* File    : GameAdapterWithRegistryAutoDetection.java
* Created : 27.12.2005
* By      : kahless
*
* Gamer's Own Instant Messenger
* Copyright (C) 2005 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package net.sphene.goim.rcp.extensionpoints;

import java.io.File;
import java.io.IOException;

import net.sphene.goim.rcp.beans.GOIMGameItem;
import net.sphene.goim.rcp.beans.GOIMGameList;
import net.sphene.goim.rcp.extensionpoints.GameExtensionPoint.GameExtensionProxy;
import ca.beq.util.win32.registry.RegistryException;
import ca.beq.util.win32.registry.RegistryKey;
import ca.beq.util.win32.registry.RegistryValue;
import ca.beq.util.win32.registry.RootKey;

public abstract class GameAdapterWithRegistryAutoDetection extends GameAdapter implements IGameWithRegistryAutoDetection {
  protected RegistryKey autoDetectGetRegistryKey(String registryKey) {
    try {
      RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE, registryKey);
      return r;
    } catch(RegistryException e) {
      try {
        RegistryKey r = new RegistryKey(RootKey.HKEY_CURRENT_USER, registryKey);
        return r;
      } catch(RegistryException ex) {
        // Not found
      }
    }
    return null;
  }
  protected String autoDetectGetRegistryKeyValue(String registryKey,String registryValue) {
    try {
      RegistryKey r = autoDetectGetRegistryKey(registryKey);
      if(r.hasValue(registryValue)) {
        RegistryValue v = r.getValue(registryValue);
        return (String)v.getData();
      }
    } catch (RegistryException e) {
      // Not found
    }
    return null;
  }
  protected GOIMGameItem autoDetect(GameExtensionProxy proxy,String registryKey,String registryValue,String appendToFileName) {
    String path = autoDetectGetRegistryKeyValue(registryKey,registryValue);
    if(path == null) return null;
    File file = (appendToFileName == null ||
        appendToFileName.equals("") ? new File(path) :
          new File(path,appendToFileName));
    if(!file.exists())
      return null;
    GOIMGameItem item = new GOIMGameItem();
    item.gameId = proxy.id;
    try {
      item.path = file.getCanonicalPath();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return item;
  }






  public abstract GOIMGameItem autoDetect(GameExtensionProxy proxy);

  public GOIMGameItem autoDetect(GameExtensionProxy proxy, GOIMGameList gameList) {
    GOIMGameItem item = autoDetect(proxy);
    if(item != null) {
      boolean isInList = false;
      for(GOIMGameItem gameItem : gameList) {
        if(gameItem.gameId.equals(item.gameId) && new File(gameItem.path).equals(new File(item.path))) {
          isInList = true;
          break;
        }
      }
      if(!isInList)
        gameList.add(item);
    }
    return item;
  }

}
TOP

Related Classes of net.sphene.goim.rcp.extensionpoints.GameAdapterWithRegistryAutoDetection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.