/*
* DevicesAutoRegister.java
* Copyright (C) 2009 <JustinLei@gmail.com>
*
* 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.
*
*/
package org.lambdasoft.device.jmf;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.lambdasoft.ui.dialog.BubbleDialog;
import com.sun.media.util.Registry;
/**
* @author lei.tang (justinlei@gmail.com)
* @date
* @version
*/
public class DevicesAutoRegister {
private static DevicesAutoRegister autoRegister;
private DevicesAutoRegister() {
}
public static final DevicesAutoRegister getRegister() {
if(autoRegister == null)
autoRegister = new DevicesAutoRegister();
return autoRegister;
}
public boolean regist(String args[]) throws IOException {
//查找设备注册文件在jmf.jar同级目录
File jarFile = new File(Registry.class.getProtectionDomain().getCodeSource().getLocation().getFile());
File confFile = new File(jarFile.getParent() + File.separator + "jmf.properties");
if(confFile.exists()) {
return true;
}
writeConfigOrig(confFile);
return _regist(args == null ? new String[0] : args);
}
private boolean _regist(String args[]){
BubbleDialog.getBubble().display("没有找到设备,开始注册视频采集设备",false,false);
JMFInit jmfInit = new JMFInit(args);
boolean flag = jmfInit.isInitialError();
jmfInit.dispose();
if(flag != true)
BubbleDialog.getBubble().display("视频采集设备注册完毕",false,true);
else
BubbleDialog.getBubble().display("视频采集设备注册失败,程序将退出",true,true);
return !flag;
}
//写入空的注册文件(JMF Configure Serializable Object)
private void writeConfigOrig(File file) throws IOException{
InputStream is = DevicesAutoRegister.class.getResourceAsStream("jmf.properties.orig");
byte[] buff = new byte[1024];
FileOutputStream os = new FileOutputStream(file);
while(is.read(buff) != -1) {
os.write(buff);
}
os.flush();
os.close();
is.close();
}
}